2 use strict; use warnings;
4 # --------------------------------------------------------------------
5 # Uploads offline action files
6 # pending files go into $base_dir/pending/<org>/<ws>.log
7 # completed transactions go into
8 # $base_dir/archive/<org>/YYYMMDDHHMM/<ws>.log
9 # --------------------------------------------------------------------
13 my $MAX_FILE_SIZE = 1000000000; # - roughly 1G upload file size max
14 require 'offline-lib.pl';
18 # --------------------------------------------------------------------
21 # --------------------------------------------------------------------
22 # If the file is present, load it up, otherwise prompt with a very
23 # basic HTML upload form
24 # --------------------------------------------------------------------
27 if( &offline_cgi->param('file') ) {
30 &handle_event(OpenILS::Event->new('SUCCESS', payload => &offline_seskey));
38 # --------------------------------------------------------------------
39 # Loads the POSTed file and writes the contents to disk
40 # --------------------------------------------------------------------
43 my $wsname = &offline_cgi->param('ws');
44 my $filehandle = &offline_cgi->upload('file');
46 # make sure we have upload priveleges
47 my $evt = $U->check_perms(&offline_requestor->id, &offline_org, 'OFFLINE_UPLOAD');
48 handle_event($evt) if $evt;
50 my $output = &offline_pending_dir(1) . '/' . "$wsname.log";
52 &handle_event(OpenILS::Event->new('OFFLINE_SESSION_ACTIVE')) if( -e &offline_lock_file );
53 &handle_event(OpenILS::Event->new('OFFLINE_SESSION_FILE_EXISTS')) if( -e $output );
55 $logger->debug("offline: Writing log file $output");
59 my $cs = &offline_cgi->param('checksum');
61 open(FILE, ">$output");
63 while( <$filehandle> ) {
64 $numbytes += length "$_";
65 $string .= "$_" if $cs;
67 if( $numbytes > $MAX_FILE_SIZE ) {
70 &handle_event('OFFLINE_FILE_ERROR');
78 my $md5 = md5_hex($string);
79 $logger->debug("offline: received checksum $cs, our data shows $md5");
80 &handle_event(OpenILS::Event->new('OFFLINE_CHECKSUM_FAILED')) if( $md5 ne $cs ) ;
84 # Append the metadata for this workstations upload
86 requestor => &offline_requestor->id,
88 workstation => $wsname,
90 delta => &offline_time_delta},
95 # --------------------------------------------------------------------
96 # Use this for testing manual uploads
97 # --------------------------------------------------------------------
100 my $ws = &offline_cgi->param('ws') || "";
101 my $cs = &offline_cgi->param('checksum') || "";
102 my $td = &offline_time_delta;
103 my $at = &offline_authtoken;
104 my $sk = &offline_seskey;
109 <form action='offline-upload.pl' method='post' enctype='multipart/form-data'>
110 <b> - Select an offline file to upload - </b><br/><br/>
114 <td>File to Upload: </td>
115 <td><input type='file' name='file'> </input></td>
118 <td>Workstation Name: </td>
119 <td><input type='text' name='ws' value='$ws'></input></td>
122 <td>Time Delta: </td>
123 <td><input type='text' name='delta' value='$td'> </input></td>
126 <td>Session Name: (only letters, numbers, or _'s)</td>
127 <td><input type='text' name='seskey' value='$sk'> </input></td>
130 <td colspan='2' align='center'><input type='submit' name='Submit' value='Upload'> </input></td>
134 <input type='hidden' name='ses' value='$at'> </input>
135 <input type='hidden' name='checksum' value='$cs'> </input>