Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl -w
- use strict;
- use CGI;
- use CGI::Carp qw ( fatalsToBrowser );
- use File::Basename;
- $CGI::POST_MAX = 1024 * 5000;
- my $safe_filename_characters = "0-9";
- my $upload_dir = "/usr/local/www/apache22/data/img/";
- my $query = new CGI; my $filename = $query->param("fax");
- my $fax_number = $query->param("fax_number");
- my $outgoing_dir = "/var/spool/asterisk/outgoing";
- #my $context_to = "Local/$fax_number@DLPN_DialPlan1";
- my $call_file = "Fax_$fax_number";
- if ( !$filename ) { print $query->header ( );
- print "There was a problem uploading your fax (try a smaller file).";
- exit;
- }
- my ( $name, $path, $extension ) = fileparse ( $filename, '\..*' );
- if ( $extension ne ".pdf") { die "File must be in PDF format only"; }
- $filename = $fax_number . $extension;
- $filename =~ tr/ /_/; $filename =~ s/[^$safe_filename_characters]//g;
- if ( $filename =~ /^([$safe_filename_characters]+)$/ ) { $filename = $1; } else { die "Phone number contains invalid characters"; }
- my $upload_filehandle = $query->upload("fax");
- open ( UPLOADFILE, ">$upload_dir/$filename.pdf" ) or die "$!";
- binmode UPLOADFILE;
- while ( <$upload_filehandle> ) { print UPLOADFILE; } close UPLOADFILE;
- print $query->header ( );
- system ("/usr/local/bin/gs -q -dNOPAUSE -dBATCH -sDEVICE=tiffg4 -sOutputFile=$upload_dir/$filename.tif $upload_dir/$filename.pdf");
- print '
- <html><head>
- <!--#include virtual="/dirlist_header.shtml" -->
- <title>Thats all folks!</title> <style type="text/css"> img {border: none;} </style> </head>
- <body>
- <h2>Fax uploaded successfully!</h2>
- <p>It will be delivered to: '.$fax_number.'</p>
- <a href="/iitc/faxes/sended/"> Last sended faxes</a>
- <br>
- <a href="/iitc/"> Back </a>
- </body> </html>
- ';
- open(FILE,">$upload_dir/$call_file") or die "Cannot write file: $!\n";
- print FILE 'Channel: Local/'.$fax_number.'@DLPN_DialPlan1'; #local call out dialplan
- print FILE "\nContext: fax-tx\n";
- print FILE "Extension: send\n";
- print FILE "MaxRetries: 2\n";
- print FILE "RetryTime: 600\n";
- print FILE "WaitTime: 25\n";
- print FILE "Set: PICTURE=$upload_dir/$filename.tif\n";
- close(FILE);
- sleep(1);
- 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