#!/usr/bin/perl -T
# ms2pdf, Andrew Daviel, TRIUMF, 2008
#
$ENV{PATH} = '/bin:/usr/bin' ; # need wget, bash
use Time::Local ;
$sfx{HTML} = 'html' ; $sfx{Text} = 'txt' ; $sfx{PDF} = 'pdf' ;
$type{html} = 'text/html' ; $type{txt} = 'text/plain' ; $type{pdf} = 'application/pdf' ;
$oopython = "/opt/openoffice.org2.4/program/python" ;
$method = $ENV{'REQUEST_METHOD'} ;
$path = $ENV{'PATH_INFO'} ;
$agent = $ENV{'HTTP_USER_AGENT'} ;
$content_type = $ENV{'CONTENT_TYPE'} ;
$content_length = $ENV{'CONTENT_LENGTH'} ;
$cookie = $ENV{'HTTP_COOKIE'} ;
$query = $ENV{'QUERY_STRING'} ;
$referer = $ENV{'HTTP_REFERER'};
$len = $ENV{'CONTENT_LENGTH'};
$script = $ENV{'SCRIPT_NAME'};
$raddr = $ENV{'REMOTE_ADDR'} ;
$now = localtime() ;
#$nowt = &wtime(time()) ;
$pragma = $ENV{'HTTP_PRAGMA'} ; $pragma =~ tr/A-Z/a-z/ ;
$imsd = $ENV{'HTTP_IF_MODIFIED_SINCE'} ;
$ims = $imsd ; $ims =~ s/;.*// ; # for Netscape
$ims = &get_gmtime($ims) ;
open (LOG,">>logs/ms2pdf.log") ;
if ($method eq 'POST' and $len>0) {
read(STDIN, $buffer, $len) ;
} elsif ($method eq 'GET') {
$buffer = $query ;
} else {
print<
$url
EOT
print LOG "$now $raddr $method $url $err\n" ;
exit ;
}
if ($status == 401 and 0) {
print<
$url
EOT
print LOG "$now $raddr $method $url $status $reason\n" ;
exit ;
}
if ($ifile =~ /\.([a-z]{2,4})$/i) {
$suffix = $1 ; $suffix =~ tr/A-Z/a-z/ ;
#print "Suffix $suffix\n" ;
}
if (-f $ifile) {
@stat = stat($ifile) ;
$fmod1 = $stat[9] ;
$ofile = &escape($ifile) . '.' . $otype ;
} else {
$fmod1 = 0 ;
}
if ($ims and $fmod1 and $fmod1<=$ims) {
print "Status: 304 Not Modified\n\n" ;
print LOG "$now $raddr $method $url 304\n" ;
exit ;
}
if (-f $ofile) {
@stat = stat($ofile) ;
$fmod2 = $stat[9] ; $fsize2 = $stat[7] ;
} else {
$fmod2 = 0 ;
}
if ($fmod1 and $fmod2 and $fmod2 >= $fmod1 and $fsize2) {
$glmod = &wtime($fmod2);
print LOG "$now $raddr $method $url cached $ofile $glmod\n" ;
print<
$url
EOT
print LOG "$now $raddr $method $url convert error $err\n" ;
exit ;
}
system("touch -r \"$ifile\" $ofile") ;
if (-f $ofile) {
@stat = stat($ofile) ;
$fsize2 = $stat[7] ;
} else {
die "$0 create $ofile failed\n" ;
}
$glmod = &wtime($fmod1);
print LOG "$now $raddr $method $url created $ofile $glmod\n" ;
print<
Convert "office" documents to PDF or HTML using
OpenOffice server, including
Microsoft Word, Excel, PowerPoint, OpenOffice and StarOffice documents and
presentations.
N810 hint (Firefox 3): Make a new window for this page. Tap-and-hold the document link on the original page, then
copy the URL to the clipsheet. Switch to this page and paste the URL in the box above (Ctrl-V).
Derived from the OOONinja article by
Andrew Ziem.
Document Converter