]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/WWW/Vandelay.pm
mod_perl stub for uploading vandelay files
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / WWW / Vandelay.pm
1 package OpenILS::WWW::Vandelay;
2 use strict;
3 use warnings;
4 use bytes;
5
6 use Apache2::Log;
7 use Apache2::Const -compile => qw(OK REDIRECT DECLINED NOT_FOUND :log);
8 use APR::Const    -compile => qw(:error SUCCESS);
9 use APR::Table;
10
11 use Apache2::RequestRec ();
12 use Apache2::RequestIO ();
13 use Apache2::RequestUtil;
14 use CGI;
15 use Data::Dumper;
16 use Text::CSV;
17
18 use OpenSRF::EX qw(:try);
19 use OpenSRF::Utils qw/:datetime/;
20 use OpenSRF::Utils::Cache;
21 use OpenSRF::System;
22 use OpenSRF::AppSession;
23 use XML::LibXML;
24 use XML::LibXSLT;
25
26 use Encode;
27 use Unicode::Normalize;
28 use OpenILS::Utils::Fieldmapper;
29 use OpenSRF::Utils::Logger qw/$logger/;
30
31 use MARC::Record;
32 use MARC::File::XML;
33
34 use MIME::Base64;
35 use Digest::MD5 qw/md5_hex/;
36
37 use UNIVERSAL::require;
38
39 our @formats = qw/USMARC UNIMARC XML BRE/;
40
41 # set the bootstrap config and template include directory when
42 # this module is loaded
43 my $bootstrap;
44
45 sub import {
46         my $self = shift;
47         $bootstrap = shift;
48 }
49
50
51 sub child_init {
52         OpenSRF::System->bootstrap_client( config_file => $bootstrap );
53 }
54
55 sub spool_marc {
56         my $r = shift;
57         my $cgi = new CGI;
58
59         my $auth = $cgi->param('ses') || $cgi->cookie('ses');
60
61         return Apache2::Const::FORBIDDEN unless verify_login($auth);
62
63         my $cache = new OpenSRF::Utils::Cache();
64         my $file = $cgi->param('marc_upload');
65         my $filename = "$file";
66
67         my $data = join '', (<$file>);
68         $data = encode_base64($data);
69
70         my $data_fingerprint = md5_hex($data);
71
72         $cache->put_cache('vandelay_import_spool_' . $data_fingerprint, $data);
73
74         print "Content-type: text/plain; charset=utf-8\n\n$data_fingerprint";
75
76         return Apache2::Const::OK;
77
78 }
79
80 sub verify_login {
81         my $auth_token = shift;
82         return undef unless $auth_token;
83
84         my $user = OpenSRF::AppSession
85                 ->create("open-ils.auth")
86                 ->request( "open-ils.auth.session.retrieve", $auth_token )
87                 ->gather(1);
88
89         if (ref($user) eq 'HASH' && $user->{ilsevent} == 1001) {
90                 return undef;
91         }
92
93         return $user if ref($user);
94         return undef;
95 }
96
97 1;