Advertisement
mightyroot

Asterisk Send FAX form webform

Dec 1st, 2012
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 2.29 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2. use strict;
  3. use CGI;
  4. use CGI::Carp qw ( fatalsToBrowser );
  5. use File::Basename;
  6. $CGI::POST_MAX = 1024 * 5000;
  7. my $safe_filename_characters = "0-9";
  8. my $upload_dir = "/usr/local/www/apache22/data/img/";
  9. my $query = new CGI; my $filename = $query->param("fax");
  10. my $fax_number = $query->param("fax_number");
  11.  
  12. my $outgoing_dir        = "/var/spool/asterisk/outgoing";
  13. #my $context_to          = "Local/$fax_number@DLPN_DialPlan1";
  14. my $call_file           = "Fax_$fax_number";
  15.  
  16. if ( !$filename ) { print $query->header ( );
  17.     print "There was a problem uploading your fax (try a smaller file).";
  18.     exit;
  19.     }
  20.  
  21. my ( $name, $path, $extension ) = fileparse ( $filename, '\..*' );
  22. if ( $extension ne ".pdf") { die "File must be in PDF format only"; }
  23.  
  24. $filename = $fax_number . $extension;
  25. $filename =~ tr/ /_/; $filename =~ s/[^$safe_filename_characters]//g;
  26. if ( $filename =~ /^([$safe_filename_characters]+)$/ ) { $filename = $1; } else { die "Phone number contains invalid characters"; }
  27.  
  28. my $upload_filehandle = $query->upload("fax");
  29. open ( UPLOADFILE, ">$upload_dir/$filename.pdf" ) or die "$!";
  30. binmode UPLOADFILE;
  31. while ( <$upload_filehandle> ) { print UPLOADFILE; } close UPLOADFILE;
  32. print $query->header ( );
  33. system ("/usr/local/bin/gs -q -dNOPAUSE -dBATCH -sDEVICE=tiffg4 -sOutputFile=$upload_dir/$filename.tif $upload_dir/$filename.pdf");
  34.  
  35. print '
  36. <html><head>
  37. <!--#include virtual="/dirlist_header.shtml" -->
  38. <title>Thats all folks!</title> <style type="text/css"> img {border: none;} </style> </head>
  39. <body>
  40. <h2>Fax uploaded successfully!</h2>
  41. <p>It will be delivered to: '.$fax_number.'</p>
  42. <a href="/iitc/faxes/sended/"> Last sended faxes</a>
  43. <br>
  44. <a href="/iitc/"> Back </a>
  45. </body> </html>
  46. ';
  47.  
  48.  
  49. open(FILE,">$upload_dir/$call_file")  or die "Cannot write file: $!\n";
  50.  
  51.    print FILE 'Channel: Local/'.$fax_number.'@DLPN_DialPlan1'; #local call out dialplan
  52.    print FILE "\nContext: fax-tx\n";
  53.    print FILE "Extension: send\n";
  54.    print FILE "MaxRetries: 2\n";
  55.    print FILE "RetryTime: 600\n";
  56.    print FILE "WaitTime: 25\n";
  57.    print FILE "Set: PICTURE=$upload_dir/$filename.tif\n";
  58.  
  59. close(FILE);
  60.  
  61.  sleep(1);
  62.  system("/bin/mv $upload_dir/$call_file $outgoing_dir && chown asterisk:asterisk $outgoing_dir/$call_file");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement