#!/usr/local/bin/perl ######################################################## ######################################################## # Don't Edit This CGI Part # ######################################################## ######################################################## ############################################ #Gets the Current Date ############################################ ($sec,$min,$hr,$day,$month,$year,$day_of_week,$day_of_year,$some) = localtime(time); @months = ("January","February","March","April","May","June","July","August","September","October","November","December"); @hour = ("12","1","2","3","4","5","6","7","8","9","10","11","12","1","2","3","4","5","6","7","8","9","10","11"); if (length($min) == 1) { $min = "0" . $min; } if (length($sec) == 1) { $sec = "0" . $sec; } if($hr > '11'){$ampm = 'PM';} else{$ampm = 'AM';} $year = $year + 1900; $DATE = "$months[$month]-$day"; $SHORTDATE = "$months[$month] $day, $year at $hour[$hr]:$min:$sec $ampm"; use CGI; my $get = new CGI; if ($ENV{'QUERY_STRING'} =~ /^[0-9]/){ } else{ $i=0; read(STDIN,$buffer,$ENV{'QUERY_STRING'}); if ($ENV{'QUERY_STRING'}) {$buffer = "$buffer\&$ENV{'QUERY_STRING'}";} @pairs = split(/&/,$buffer); foreach $pair (@pairs){ ($name,$value) = split(/=/,$pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg; $VALUE{$name} = $value; } } ############################################ #Gets Picture Data and Moves on to Next Page ############################################ if (($get->param("action") eq 'preview') || ($VALUE{'action'} eq 'preview')){ ############################ #Checks the URL of the Page ############################ if (($ENV{'HTTP_REFERER'} =~ /$domain_name/i) || ($ENV{'HTTP_REFERER'} eq '')){ } else { &url; } ################################# #If User chooses to Upload Photo ################################# if ($VALUE{'type'} eq 'upload') { &check_space; sub check_space { $du = `du $basepicdir`; $du =~ s/\n/ /g; @terms = split(/\s+/,$du); $size = @terms; $used_space = ($terms[$size-2]/2); $free_space = ($allowed - $used_space); if ($free_space < 30 && $check eq 'second'){ $line = "  1.) The picture folder has $used_space Kb of uploaded pictures "; $line .= "and has been programmed not to exceed $allowed Kb.


\n\n"; $line .= "Please check back in a few days when some of the pictures have been deleted.\n\n"; &error; } if ($free_space < 30){ $check = 'second'; &delete_pic; &check_space; } } ######################################## #Time to Upload Photo to the server ######################################## my $pic = $get->param("FILE"); if ($pic eq '') { $line = "  1.) Sorry, but you uploaded an empty file!
\n\n"; &error; } my $picname = $pic; $picname =~ s!^.*(\\|\/)!!; ($NAME, $EXTENSION) = split(/\./, $picname); foreach $ext (@picsallowed){ $list_ext .= ", $ext"; if ($EXTENSION eq $ext){ $upload_file = "yes"; } } if ($upload_file eq "yes") { $ext = "_zz"; $date = time; $rands = int (rand 10000); $name = "$date$rands$ext.$EXTENSION"; $picture = "$basepicurl$name"; $picturedir = "$basepicdir$name"; open (OUTFILE, ">$picturedir"); binmode (OUTFILE); while (my $bytesread = read($pic, my $buffer, 1024)) { print OUTFILE $buffer; } close (OUTFILE); `chmod 744 $picturedir`; } else{ $line = "  1.) Your extension $EXTENSION is not allowed, only $list_ext.
\n\n"; &error; } $filesize = -s $picturedir; if ($filesize > ($uploadmax * 1000)){ unlink("$picturedir"); $filesize = $filesize / 1000; $line = "  1.) The picture you uploaded is $filesize Kb, which exceeds the $uploadmax Kb max.
\n"; &error; } $VALUE{'PICTURES'} = "$picture"; $VALUE{'PICTURE'} = "$name"; } ########################################## #If User chooses to use one of your Photos ########################################## else{ $pic = $get->param("PICTURES"); $VALUE{'PICTURE'} = $get->param("PICTURES"); $VALUE{'PICTURES'} = "$basepicurl$pic"; } ######################### #Prints the Preview Page ######################### print "Content-type: text/html\n\n"; open(TEMPLATE,"$preview1"); &template; print $template; exit; } ######################### #The Preview Page ######################### if ($get->param("action") eq 'preview1') { ############################ #Checks the URL of the Page ############################ if (($ENV{'HTTP_REFERER'} =~ /$domain_name/i) || ($ENV{'HTTP_REFERER'} eq '')){ } else { &url; } $VALUE{'PICTURE'} = $get->param("PICTURE"); $VALUE{'PICTURES'} = "$basepicurl$VALUE{'PICTURE'}"; $VALUE{'MESSAGE'} = $get->param("MESSAGE"); $VALUE{'MESSAGE_SAVE'} = $get->param("MESSAGE"); $VALUE{'SENDER'} = $get->param("SENDER"); $VALUE{'MAILFROM'} = $get->param("MAILFROM"); $VALUE{'RECIPIENT'} = $get->param("RECIPIENT"); $VALUE{'MAILTO'} = $get->param("MAILTO"); $VALUE{'MESSAGE'} =~ tr/\\\`\+\/\;\|/_/; $VALUE{'SENDER'} =~ tr/\\\`\+\/\;\!\|/_/; $VALUE{'MAILFROM'} =~ tr/\\\`\+\/\;\!\|/_/; $VALUE{'RECIPIENT'} =~ tr/\\\`\+\/\;\!\|/_/; $VALUE{'MAILTO'} =~ tr/\\\`\+\/\;\!\|/_/; $VALUE{'MESSAGE'} =~ s/\r//g; $VALUE{'MESSAGE'} =~ s/\<[^\>]*\>//ig; $VALUE{'MESSAGE'} =~ s/"/'/g; $VALUE{'MESSAGE'} =~ s/\n/
/g; if (($get->param("MAILFROM") !~ /^.+\@\[?(\w|[a-zA-Z0-9\-\.])+\.[a-zA-Z]{2,3}|[0-9]{1,3}\]?$/) || ($get->param("MAILTO") !~ /^.+\@\[?(\w|[a-zA-Z0-9\-\.])+\.[a-zA-Z]{2,3}|[0-9]{1,3}\]?$/)){ &no_email; } print "Content-type: text/html\n\n"; open(TEMPLATE,"$preview2"); &template; print $template; exit; } ########## #Send Card ########## if ($get->param("action") eq 'send') { ############################ #Checks the URL of the Page ############################ if (($ENV{'HTTP_REFERER'} =~ /$domain_name/i) || ($ENV{'HTTP_REFERER'} eq '')){ } else { &url; } ###################### #Save the Data ###################### $VALUE{'MESSAGE'} = $get->param("MESSAGE"); $VALUE{'SENDER'} = $get->param("SENDER"); $VALUE{'MAILFROM'} = $get->param("MAILFROM"); $VALUE{'RECIPIENT'} = $get->param("RECIPIENT"); $VALUE{'MAILTO'} = $get->param("MAILTO"); $VALUE{'PICTURE'} = $get->param("PICTURE"); $VALUE{'MESSAGE'} =~ tr/\\\`\+\/\;\|/_/; $VALUE{'SENDER'} =~ tr/\\\`\+\/\;\!\|/_/; $VALUE{'MAILFROM'} =~ tr/\\\`\+\/\;\!\|/_/; $VALUE{'RECIPIENT'} =~ tr/\\\`\+\/\;\!\|/_/; $VALUE{'MAILTO'} =~ tr/\\\`\+\/\;\!\|/_/; $VALUE{'MESSAGE'} =~ s/\r//g; $VALUE{'MESSAGE'} =~ s/\<[^\>]*\>//ig; $VALUE{'MESSAGE'} =~ s/"/'/g; $VALUE{'MESSAGE'} =~ s/\n/
/g; if (($get->param("MAILFROM") !~ /^.+\@\[?(\w|[a-zA-Z0-9\-\.])+\.[a-zA-Z]{2,3}|[0-9]{1,3}\]?$/) || ($get->param("MAILTO") !~ /^.+\@\[?(\w|[a-zA-Z0-9\-\.])+\.[a-zA-Z]{2,3}|[0-9]{1,3}\]?$/)){ &no_email; } $date = time; $rand = int (rand 10000); $create_card = "$cards$date$rand.dat"; open(DATA, ">>$create_card"); print DATA "$VALUE{'SENDER'}|$VALUE{'MAILFROM'}|$VALUE{'RECIPIENT'}|$VALUE{'MAILTO'}|$VALUE{'MESSAGE'}|$VALUE{'PICTURE'}|0\n"; close(DATA); $url_of_card = "$cgi?$date$rand"; ########################## #Print Thank You HTML ########################## print "Content-type: text/html\n\n"; open(TEMPLATE,"$thank_you"); &template; print $template; $template = ''; ########################## #Send E-mail to Recipient ########################## open (MAIL, "|$mailprog -t") || die "Can't open $mailprog!\n"; print MAIL "To: $VALUE{'MAILTO'} ($VALUE{'RECIPIENT'})\n"; print MAIL "From: $VALUE{'MAILFROM'} ($VALUE{'SENDER'})\n"; print MAIL "Subject: $VALUE{'RECIPIENT'}, $subject1\n\n"; open(TEMPLATE,"$email1"); &template; print MAIL $template; print MAIL ".\n" ; close(MAIL); $deletes = "$cards$DATE.dat"; if(-e $deletes){ } else{ open(DATA, ">>$deletes"); close(DATA); &delete; &delete_pic; } exit; } ######################## #No E-Mail Addresses ######################## sub no_email { print "Content-type: text/html\n\n"; print "\nError! Bad E-Mail\n"; print "\n"; print "Could not Continue!
\n"; print "[Possible Reasons:]
\n"; print "  1.) Please make sure that you filled in both E-Mail Addresses.
"; print "  2.) Make sure that both E-Mail Addresses have the correct form, user\@company.com"; exit; } ######################## #Possible Error ######################## sub error { print "Content-Type: text/html\n\n"; print "\nError!\n"; print "\n"; print "Could not upload the picture!
\n"; print "[Possible Reasons:]
\n"; print $line; print ""; exit; } ######################## #URL don't match ######################## sub url { print "Content-Type: text/html\n\n"; print "\nError!\n"; print "\n"; print "Could Not Continue!
\n"; print "[Possible Reasons:]
\n"; print "  1.) The URL does not match the one located on the server!
\n"; print "    -- Please Click Here to Re-Load the Page
\n"; print ""; exit; } ####################################### #Creates the Postcard ####################################### if ($ENV{'QUERY_STRING'}) { ############################################ #Makes Postcards and Sends Thank You E-mail ############################################ $create_card = "$cards$ENV{'QUERY_STRING'}.dat"; if(-e $create_card){ open(DATA, "$create_card"); @data = ; close(DATA); foreach $temp (@data){ chop($temp); ($SENDER, $MAILFROM, $RECIPIENT, $MAILTO, $MESSAGE, $PICTURES, $COUNT) = split(/\|/, $temp); $VALUE{'SENDER'} = $SENDER; $VALUE{'MAILFROM'} = $MAILFROM; $VALUE{'RECIPIENT'} = $RECIPIENT; $VALUE{'MAILTO'} = $MAILTO; $VALUE{'MESSAGE'} = $MESSAGE; $VALUE{'MESSAGE'} =~ s/ /  /g; $VALUE{'PICTURES'} = "$basepicurl$PICTURES"; $VALUE{'LINK'} = "$link$LINK"; $VALUE{'PICTURE'} = "$basepicurl$PICTURES"; } unlink("$create_card"); open(DATA, ">>$create_card"); $COUNT++; print DATA "$SENDER|$MAILFROM|$RECIPIENT|$MAILTO|$MESSAGE|$PICTURES|$COUNT\n"; close(DATA); print "Content-type: text/html\n\n"; open(TEMPLATE,"$makecard"); &template; print $template; $template = ''; if($COUNT eq '1'){ open (MAIL, "|$mailprog -t") || die "Can't open $mailprog!\n"; print MAIL "To: $VALUE{'MAILFROM'} ($VALUE{'SENDER'})\n"; print MAIL "From: $VALUE{'MAILTO'} ($VALUE{'RECIPIENT'})\n"; print MAIL "Subject: $subject2\n\n"; open(TEMPLATE,"$email2"); &template; print MAIL $template; print MAIL ".\n" ; close(MAIL); } } else { print "Content-type: text/html\n\n"; open(TEMPLATE,"$error"); &template; print $template; } exit; } ####################################### #DELETES the information ####################################### sub delete { local(@items, $pair); opendir(DELETE, "$cards"); @items = grep(/.dat/,readdir(DELETE)); closedir(DELETE); foreach $pair (@items){ if (-M "$cards$pair" > $MAX_DAYS){ unlink("$cards$pair"); } } } ########################## #Delete Old Pictures! ########################## sub delete_pic { local(@pictures, $pair); opendir(PIC_DIR, "$basepicdir"); @pictures = grep(/_zz./,readdir(PIC_DIR)); closedir(PIC_DIR); foreach $pair (@pictures){ if (-M "$basepicdir$pair" > $MAX_DAYS){ unlink("$basepicdir$pair"); } } } ##################### #Calls the Template ##################### sub template { while (