#!/usr/bin/ruby -w
require "cgi"
require "cgi/session"
require "updategooglecalendar"
require "tempfile"
require "English"
# turn this on for debugging
RemoveDatebooks = false
cgi = CGI.new
sess = CGI::Session.new(cgi, "newsession" => true, "prefix" => "googlecalendar", "no_cookies" => true)
sess['status'] = '
#{sess.session_id}
" } $DEFAULT_OUTPUT.flush sessionID = sess.session_id sess.close pid = fork do newCGI = cgi.clone newSess = CGI::Session.new(newCGI, "session_id" => sessionID, "newsession" => false, "prefix" => "googlecalendar", "no_cookies" => true) params = newCGI.params $stdout.close begin # Security check - test PDB file size. If > 10M, exit with error. passedPDBFile = params['pdbFile'].first if (passedPDBFile.length > 10000000) raise "PDB file is too big" elsif (passedPDBFile.length == 0) raise "PDB file is zero-length or nonexistant" end # Save the .pdb file and process it. tempPDBFile = Tempfile.new('datebookpdb') tempPDBFileName = tempPDBFile.path tempPDBFile.close! pdb_file = File.new(tempPDBFileName, 'w+') pdb_file << passedPDBFile.read pdb_file.close params.delete("pdbFile") tempDatebookFile = Tempfile.new('datebookfile') datebookPath = tempDatebookFile.path tempDatebookFile.close! outputCommand = "/usr/bin/pilot-datebook -r pdb -f #{tempPDBFile.path} -w longtxt -f #{datebookPath} -q" success = system(outputCommand) if (success) then newSess['status'] = "