$ exit 1 $! FAXPAGE.COM $! 'f$verify(0)' $! $! FAX me the page that I was just on $! $! jms/970522 $! $!++++++++++++++++ $! Called with P1, P2, P3 and various other environment variables $! $! P1 = method (should be "POST", "GET", "HEAD") $! P2 = URL-ident (will probably be /htbin/faxpage, although do we care?) $! P3 = protocol (will probably be HTTP/1.0 or HTTP/1.1) $! $!---------------- $ set noon $! $! Never set global symbols in CGI scripts for the OSU $! server (i.e., *always* use '=' and *not* '==') so $! they won't persist into subsequent DECNET tasks. $! $! Set utility symbols for net_link writes and reads. $! $ say = "write net_link" $ get = "read net_link" $ put = "create net_link" ! Not used here (and requires ). $ crlf = f$fao("!/") $!---------------------------------------------------------------------------- $! $! If it's a HEAD request, just send the Content-type and exit. $! $ if P1 .eqs. "HEAD" $ then $ say "" $ say "Content-type: text/html", crlf, crlf ! CGI header $ say "" $ exit $ endif $!---------------------------------------------------------------------------- $! $!+++ $! $! We need to figure out if we're the button which got pressed or and $! we need to fill out a form for FAXing, or if we're getting called by $! that form and now must do the FAXing. $! $! If the content-length = 0 or if the method is not POST, then we $! must be just the button and we have to build the form. Otherwise, $! we are the form and we need to do the FAX thing. $! $!--- $! Read the header in. Grab anything we can get until there is no more. $! $ num = 0 $ HTTP_CONTENT_LENGTH = 0 $ HTTP_REFERER = "/dev/null" $ HTTP_HOST = "www.opus1.com" $ say "" $! $! Look in each header line to see if we've got something we care about. $! When we're done with this, if there was a Referer: or Content-length: $! header, we'll have the symbols HTTP_REFERER &/ HTTP_CONTENT_LENGTH set. $! $hdr_loop: $ num = num + 1 $ get hdr'num' $ if hdr'num' .eqs. "" then $ goto done_reading_headers $ header = f$edit(hdr'num',"LOWERCASE,TRIM") ! make it simple for ourselves $ if ("''f$extract(0,7,header)'" .eqs. "referer") then - $ HTTP_REFERER = "''f$element(1," ",header)'" $ if ("''f$extract(0,14,header)'" .eqs. "content-length") then - $ HTTP_CONTENT_LENGTH = "''f$element(1," ",header)'" $ if ("''f$extract(0,4,header)'" .eqs. "host") then - $ HTTP_HOST = "''f$element(1," ",header)'" $ goto hdr_loop $! $done_reading_headers: $! $!+++ $! $! Now we can decide whether we're in 'button' or 'fax' mode. In button $! mode, we build a form and send it back. In fax mode, we fax out the $! sucker. We're in button mode if content-length = 0 or request_method $! is not POST $! $!--- $! $ if (P1 .nes. "POST") then $ goto button_mode $ if (HTTP_CONTENT_LENGTH .eq. 0) then $ goto button_mode $ goto fax_mode $button_mode: $!+++ $! BUTTON_MODE $! $! Write out the form. $! $!--- $! Figure out what the filename is for the HTTP_REFERER (or if there $! was an HTTP_REFERER $! $ if (HTTP_REFERER .eqs. "") $ then $ say "" $ say "Content-Type: text/html",crlf $ say "Status: 200 Bad bad browser",crlf $ say "JMS-Header: Waste some bits",crlf,crlf $! $ say "",crlf $ say "Opus One HTML-to-FAX Gateway Error",crlf $ say "

Error in FAX Gateway

",crlf $! $ say "We are happy to FAX you any WWW page on this server.",crlf $ say "However, your browser did not tell us what page you just",crlf $ say "left, so we cannot figure out what page to FAX you!",crlf $ say "


",crlf $ exit $ endif $! $! If we're here, there must have been a referer. Strip off the $! method and initial domain name. htr = http_referer $! $ htr_m = http_referer - "http://" ! htr - method $ htr_d = f$element(0,"/",htr_m) ! htr domain $ htr = htr_m - htr_d ! final htr - parts $ say "" $ say htr $ get htf ! htf = http_filename $ call make_file_from_www "''htf'" ! /conv/from/slash/to/vms $ http_referer_filename = filename $! jms/980105 $! - if this is an "Opus One" page (i.e., referer has "opus1.com" in it $! somewhere, then we put in the standard Opus One headers. $ opuspage = 0 $ htr_d_lc = f$edit(htr_d, "COLLAPSE,LOWERCASE") $ if ( f$locate("opus1.com",htr_d_lc) .ne. f$length(htr_d_lc) ) then - $ opuspage = 1 $ sho sym htr_d_lc $ sho sym htr_d $! $! $ say "" $ say "" $ say "Content-Type: text/html" $ say "Status: 200 Sending form for FAXing" $ say "JMS-Header: Waste some bits",crlf $! $ say "" $ say "" $ say "Opus One HTML-to-FAX Gateway" $ say "" $! $ say "" $! $ if (opuspage .ne. 0) $ then $ say "" $ say " " $ say " " $ say " " $ say " " $ say " " $ say "" $ say "
" $ say " " $ say "

" $ say " " $ say "

" $ say " " $ say "

" $ say " " $ say "

" $ say " " $ say "

" $ say "

" $ say "
" $ say "" $ endif $ say "

" $ say "HTML to FAX Gateway" $ say "

" $! $ say "We are happy to FAX you any WWW page on this server." $ say "Make sure that the URL below is correct, fill in your " $ say "FAX telephone number, and we'll send it to you right away." $ say "

" $! $ say "


" $ say "
" $! $ hrlen = f$length(http_referer) $ say "Page to FAX:" $ say "" $ say "

" $! $! FOR DEBUGGING ONLY! $! say "Real filename:" $! say "" $! say "

" $! FOR DEBUGGING ONLY! $ say "" $! $ say "FAX telephone number:" $ say "" $ say "

" $! $ say "


" $ say "The following information is for the FAX cover sheet" $ say "and is optional." $ say "

" $! $ say "FAX recipient's name:" $ say "" $ say "

" $! $ say "FAX recipient's company:" $ say "" $ say "

" $! $ say "" $ say "

" $! $ say "
" $ if (opuspage .ne. 0) $ then $ say "
" $ say " " $ say " " $ say "


" $ say "Home . " $ say "" $ say "Consulting . " $ say "Library" $ say " . Internet " $ say "Services . " $ say "About Us" $ say "

© 1997 Opus One
" $ say "

" $ say "
" $ say "" $ say "
" $ endif $ say "" $ say "" $! $ say "
" $! $ exit $fax_mode: $!+++ $! FAX_MODE $! $! FAX that sucker $! $!--- $ on error then $ goto fax_error_out $!+++ $! Find the relevant commands $!--- $ ARCH = "VAX" $ if f$getsyi("HW_MODEL") .ge. 1024 then ARCH = "ALPHA" $ Perl :== $lib_source:[perl]'arch'_perl $ assign/trans=conc lib_source:[html_tools.html2ps] html2ps$dir $ HTML2PSDIR = F$TRNLNM("HTML2PS$DIR") $ HTML2PS == "''PERL' ''HTML2PSDIR'HTML2PS.PL" $! $! Null out some symbols we expect to be there so that we $! don't have a meltdown if they don't exist $! $ x_company = "" $ x_fax = "" $ x_name = "" $ x_url = "" ! not that we care $ x_file = "" $! $ say "" $ mcr 'f$parse("SET_DCL_ENV.EXE;",f$environment("PROCEDURE")) "WWW_" "X_" $! $! We expect to get our data back this way: $! X_COMPANY = "" $! X_FAX = "324-0494" $! X_FIELDS = "URL,FAX,NAME,COMPANY" $! X_FIELDS_COUNT = "4" $! X_FLD_COUNT = "4" $! X_NAME = "Joel Snyder" $! X_URL = "http://www.opus1.com/www/testfax.html" $! X_FILE = "disk$ebony:[httpd.documents]testfax.html" $! $!++++ $! $! Do a little parsing $! $!---- $! $! must have filename & FAX number; file must be available $! $ if (x_fax .eqs. "") $ then $ error = "You did not provide a FAX number" $ goto fax_error_out $ endif $ if (x_file .eqs. "") $ then $ error = "We were unable to look up the file for your URL" $ goto fax_error_out $ endif $ if (f$search(x_file) .eqs. "") $ then $ error = "The file corresponding to your WWW page is protected" $ goto fax_error_out $ endif $! $! Normalize some fields $! $ if (x_company .eqs. "") then $ x_company = "(no company name)" $ if (x_name .eqs. "") then $ x_name = "(no personal name)" $ if (x_url .eqs. "") then $ x_url = "/dev/null" $!++++ $! $! Make sure that the phone number is legit $! $!----- $ if ("''f$extract(0,11,www_remote_host)'" .eqs. "192.245.12.") then - $ goto fax_is_ok $ x_fax = x_fax - "-" ! take out any dashes $ x_fax = x_fax - " " ! and up to one space $ if (f$type(x_fax) .nes. "INTEGER") $ then $ error = "Your FAX number must be exactly seven digits" $ goto fax_error_out $ endif $ if (f$length(x_fax) .gt. 7) ! 011 855 12 4 123456 $ then $ error = "Your FAX phone number must be in Tucson, Arizona" $ goto fax_error_out $ endif $ if (f$length(x_fax) .lt. 7) ! 911? $ then $ error = "Your FAX phone number is in an illegal format" $ goto fax_error_out $ endif $fax_is_ok: $!+++ $! $! Convert the HTML to PS, unless there's a .PS there already. $! - if there's a .PS already, use that since it's probably better looking $! $!--- $ delete_ps = "TRUE" $ psfile = f$parse(".PS",,x_file,,) ! figure out the filename $ if (f$search(psfile) .nes. "") ! if it exists $ then $ pidfile = psfile ! save the filename $ delete_ps = "FALSE" $ goto send_ps_file ! and skip over the conversion step $ endif $! If we're here, we must have to convert it. $ error = "We were unable to convert that web page for FAXing" $ pidfile = "SYS$SCRATCH:" + f$getjpi(0,"PID") + ".PS;" $ define/user sys$output 'pidfile' $ html2ps 'x_file' $! $ send_ps_file: ! file exists; send it $! $ error = "We were unable to queue the Postscript file to the FAX machine" $ pmdf send - /abort - ! abort on error /comments="Web-based FAX service" - ! comments: header /errors_to="web-to-fax@bitbucket.opus1.com" - ! errors_to: header /extra=("X-Requesting-Host: ''www_remote_host'", - "X-User-Agent: ''www_http_user_agent'") - /from="web-to-fax@bitbucket.opus1.com" - /organization="Opus One, +1 520 324 0494, Tucson, Arizona" - /references="''x_url'" - ! URL they asked for /return_address="web-to-fax@bitbucket.opus1.com" - /subject="Web to FAX delivery" - 'pidfile' - "/FN=''x_fax'/AT=''x_name'/O=''x_company'/@ps-fax.opus1.com" $ on error then $ continue ! no point now... $ if (delete_ps) then $ delete 'pidfile' $! $! jms/980105 $! - if this is an "Opus One" page (i.e., referer has "opus1.com" in it $! somewhere, then we put in the standard Opus One headers. $ opuspage = 0 $ x_url_lc = f$edit(x_url, "COLLAPSE,LOWERCASE") $ if ( f$locate("opus1.com",x_url_lc) .ne. f$length(x_url_lc) ) then - $ opuspage = 1 $! $ say "Content-Type: text/html" $ say "Status: 200 Giving status of FAX request" $ say "JMS-Header: Waste lots of bits",crlf $! $ say "" $ say "" $ say "FAX status report" $ say "" $! $ say "" $ if (opuspage .ne. 0) $ then $ say "" $ say " " $ say " " $ say " " $ say " " $ say " " $ say "" $ say "
" $ say " " $ say "

" $ say " " $ say "

" $ say " " $ say "

" $ say " " $ say "

" $ say " " $ say "

" $ say "

" $ say "
" $ say "" $ endif $ say "

" $ say "FAX status report" $ say "

" $! $ say "Your FAX was queued and should be delivered shortly." $ say "

" $ say "Press the BACK button on your browser to get back" $ say "(if your browser has a BACK button)," $ say "or you may click on this link" $ say "to take you back to the page you asked to be FAXed to you." $ say "

" $! $ if (opuspage .ne. 0) $ then $ say "

" $ say " " $ say " " $ say "


" $ say "Home . " $ say "" $ say "Consulting . " $ say "Library" $ say " . Internet " $ say "Services . " $ say "About Us" $ say "

© 1997 Opus One
" $ say "

" $ say "
" $ say "" $ say "
" $ endif $ say "",crlf $ say "",crlf $ say "
" $! $ exit $! Come here on any error $fax_error_out: $ say "Content-Type: text/html" $ say "Status: 200 Giving status of FAX request and it's bad" $ say "JMS-Header: Waste lots of bits",crlf $! $ say "FAX status report" $! $ say "

FAX error status report

" $! $ say "Your FAX was not queued because:" $ say "


" $ say "''error'" $ say "

" $! $ say "" $ say "" $! $ exit $! - jms/960116 $! - fixed 970715 for zero-length problem $ make_file_from_www: subroutine $! P1 = www_filename $! OUTPUT symbol == filename $! $ disk = "" $ tmp = "" $ dirspec = "" $! $ i = 0 $ disk = f$element(i,"/",p1) $ if (disk .eqs. "") $ then ! there was no leading slash? $ i = i + 1 $ disk = f$element(i,"/",p1) $ endif $! $ i = i + 1 $ get_parts: $ tmp = f$element(i,"/",p1) $ if (tmp .eqs. "" .or. tmp .eqs. "/" .or. i .gt. 10) then $ goto no_more_parts $ if (f$locate(".",tmp) .nes. f$length(tmp)) then $ goto no_more_parts $ dirspec = dirspec + tmp + "." $ i = i+1 $ goto get_parts $no_more_parts: $! come here when there are no more parts to add $! lop off that final $ filename == disk + ":[" + f$extract(0,f$length(dirspec)-1,dirspec) + "]" + tmp $! $ return $ endsubroutine