#!/usr/bin/perl ######################################################### # mobile logic ######################################################### #if ($0=~m#^(.*)\\#){ $execDir = "$1"; } # Win/DOS #elsif ($0=~m#^(.*)/# ){ $execDir = "$1"; } # Unix #else {`pwd` =~ /(.*)/; $execDir = "$1"; } # Unix # Get DB Login Info #require "$execDir/info.pl"; $mySqlUsername = "xxxx"; $mySqlPassword = "xxxxx"; # Tell the browser what type of data to expect print "Content-type: text/html\n\n"; print "got here!"; # Use CGI Perl module to output any error msgs to browser use CGI::Carp qw(fatalsToBrowser); use Image::Magick; # Define the name of the script just for reference # $scriptName = "logic.pl"; # Obtain any variables submitted either in the URL string # or by an HTML form via the GET or POST method, and # place in the %INPUT_VARS hash array %INPUT_VARS = {}; &input_vars_receive; &input_vars_parse; ############## # Testing / Not Testing ############## #$live = 0; $live = 1; ######################################################### # Define our DB info ######################################################### use DBI(); $dbpath ="dbi:mysql:database=mobile;host=mysql.free4md.com"; ######################################################### # Connect to the database. ######################################################### # This only needs to be done once per script $dbh = DBI->connect($dbpath, "xxxxx", "xxxxxx", {'RaiseError' => 1, 'PrintError' => 1}); ############## # Input Shit $toLabel = "To:"; $toName = "to"; $to = $INPUT_VARS{"to"}; $fromLabel = "From:"; $fromName = "from"; $from = $INPUT_VARS{"from"}; $subjectLabel = "Subject:"; $subjectName = "subject"; $subject = $INPUT_VARS{"subject"}; $bodyLabel = "Body:"; $bodyName = "body"; $body = $INPUT_VARS{"body"}; $attachmentLabel = "Attachment:"; $attachmentName = "attachment"; $attachment= $INPUT_VARS{"file"}; $upload_dir = "/home/.fidel/catmindeye/www.freeformed.org/comments/"; ### Status variables ### $statusMsg = ""; # Gives response back to user (i.e. "Thank you for your ...") $hasErrors = 0; # Keeps track of whether there are input errors ######################################################### # Check our inputs and perform any DB updates ######################################################### # Error Checking $hasErrors = $noTo = $noFrom = $noSubject = $noBody = $noAttachment = 0; $to = &trim_it($to); $from = &trim_it($from); $subject = &trim_it($subject); $body = &trim_it($body); $attachment= &trim_it($attachment); # Start html - for error checking print qq^asdfasf^; print "

to: $to
"; print "from: $from
"; print "subject: $subject
"; print "body: $body
"; print "attach: $attachment

"; if ($to eq "") { $hasErrors = 0; $noTo = 0; $statusMsg = "There were errors in your to submission."; } if ($from eq "") { $hasErrors = 0; $noFrom = 0; $statusMsg = "There were errors in your from submission."; } if ($subject eq "") { $hasErrors = 0; $noSubject = 0; $statusMsg = "there were errors in your subject."; } if ($body eq "") { $hasErrors = 0; $noBody = 0; $statusMsg = "There were errors in your body submission."; } if ($attachment eq "") { $hasErrors = 1; $noAttachment = 1; $statusMsg = "There were errors in your attachment submission."; } if ($hasErrors == 0) { print qq^

no errors

^; ($phone, $host) = split(/\@/, $from); ($tag, $sent_message) = split(/\./, $body); #@bodySplit = split(/./, $body); ($at_name, $attachment_type) = split(/\./, $attachment); my $attachment_html = ""; for (my $i = 0; $i <= $#attachments; $i++) { my $attachment = $attachments[$i]; my $attachment_type = $attachments_type[$i]; my $attachment_relative = $attachments_relative[$i]; } if ($attachment_type eq "wav"){ $SqlStatement = "INSERT INTO phone (sound_wav) "; $SqlStatement .= "VALUES ('$attachment') "; $affected_rows = $dbh->do($SqlStatement); print "

sql statement: $SqlStatement

" } } print qq^^; ######################################################### # Disconnect from the database. ######################################################### # Always the last thing you do before exiting your script $dbh->disconnect(); exit; ######################################################### # Takes data from an HTML Form or URL string ######################################################### sub input_vars_receive { $formData = $ENV{'QUERY_STRING'}; if ($ENV{'REQUEST_METHOD'} eq 'POST') { read(STDIN, $formData, $ENV{'CONTENT_LENGTH'}); } } ######################################################### # Parses form info ######################################################### sub input_vars_parse { local($name,$value,$pair); local(@pairs) = split(/&/, $formData); # Get parameter names, their values and copy into $INPUT_VARS array foreach $pair (@pairs) { ($name,$value)=split(/=/,$pair); $value=~tr/+/ /s; $value=~s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg; $INPUT_VARS{$name}=$value; } } ######################################################### # Write To Log File ######################################################### sub write_to_log ######################################################### { # Write to log file local($msg) = @_; open INPTR, ">>$logFile"; print INPTR "$msg\n"; close INPTR; } ######################################################### # Trim whitespace ######################################################### sub trim_it { local($msg) = @_; while ($msg=~/^\s/i) { $msg=~s/^\s//i;} while ($msg =~/\s$/) { $msg =~s/\s$//; } return $msg; } ######################################################### # Escape single quotes for DB entry ######################################################### sub escape_quotes { local($msg) = @_; local($delim) = "'"; local($rep) = "''"; $msg =~s/$delim/$rep/eg; return $msg; }