1 | #!**PERLBIN** -w
|
---|
2 | # Need to specify the full path of Perl above
|
---|
3 |
|
---|
4 |
|
---|
5 | use strict;
|
---|
6 | use File::Basename;
|
---|
7 |
|
---|
8 | no strict 'subs';
|
---|
9 | no strict 'refs'; # allow filehandles to be variables and viceversa
|
---|
10 |
|
---|
11 |
|
---|
12 | # Set this to 1 to work around IIS 6 craziness
|
---|
13 | my $iis6_mode = 0;
|
---|
14 |
|
---|
15 |
|
---|
16 | # IIS 6: for some reason, IIS runs this script with the working directory set to the Greenstone
|
---|
17 | # directory rather than the cgi-bin directory, causing lots of stuff to fail
|
---|
18 | if ($iis6_mode)
|
---|
19 | {
|
---|
20 | # Change into cgi-bin directory
|
---|
21 | chdir("cgi");
|
---|
22 | }
|
---|
23 |
|
---|
24 |
|
---|
25 | # We use require and an eval here (instead of "use") to catch any errors loading the module (for IIS)
|
---|
26 | eval("require \"rbCGI.pm\"");
|
---|
27 | if ($@)
|
---|
28 | {
|
---|
29 | print STDOUT "Content-type:text/plain\n\n";
|
---|
30 | print STDOUT "ERROR: $@\n";
|
---|
31 | exit 0;
|
---|
32 | }
|
---|
33 |
|
---|
34 |
|
---|
35 |
|
---|
36 | sub main
|
---|
37 | {
|
---|
38 | my $rb_cgi = new rbCGI();
|
---|
39 |
|
---|
40 | $rb_cgi->{'xml'} = 0;
|
---|
41 |
|
---|
42 | $rb_cgi->setup_rb();
|
---|
43 |
|
---|
44 | my $rbhome = $ENV{'REALISTIC_BOOKS_HOME'};
|
---|
45 | $rb_cgi->checked_chdir($rbhome);
|
---|
46 |
|
---|
47 |
|
---|
48 | my $action = $rb_cgi->param("a");
|
---|
49 |
|
---|
50 | my $pdf_filename = $rb_cgi->param("upload");
|
---|
51 | #$rb_cgi->generate_message("action = $action, pdf file = $pdf_filename");
|
---|
52 | #exit 0;
|
---|
53 |
|
---|
54 |
|
---|
55 | if ($action eq "import-pdf") {
|
---|
56 | my $pdf_filename = $rb_cgi->param("upload");
|
---|
57 |
|
---|
58 | my ($fname, $fpath, $ext) = fileparse ( $pdf_filename, '\..*' );
|
---|
59 | $pdf_filename = "$fname$ext";
|
---|
60 | $pdf_filename =~ tr/ /_/;
|
---|
61 |
|
---|
62 | my $full_pdf_filename = &util::filename_cat($rbhome,"pdfs",$pdf_filename);
|
---|
63 |
|
---|
64 | my $upload_filehandle = $rb_cgi->upload("upload");
|
---|
65 |
|
---|
66 | ##open (UPLOADFILE, ">$rbhome/pdfs/$pdf_filename")
|
---|
67 | open (UPLOADFILE, ">full_pdf_filename")
|
---|
68 | || $rb_cgi->generate_error("$!");
|
---|
69 | binmode UPLOADFILE;
|
---|
70 |
|
---|
71 | while ( <$upload_filehandle> ){
|
---|
72 | print UPLOADFILE;
|
---|
73 | }
|
---|
74 |
|
---|
75 | close UPLOADFILE;
|
---|
76 |
|
---|
77 | my $old_handle = select (STDOUT);
|
---|
78 | $| = 1; # perform flush after each write to STDOUT
|
---|
79 |
|
---|
80 | ##my $cmd = "perl -S pdf2realbook.pl \"$rbhome/pdfs/$pdf_filename\"";
|
---|
81 | my $cmd = "perl -S pdf2realbook.pl \"$full_pdf_filename\"";
|
---|
82 | if (open(PIN,"$cmd|")) {
|
---|
83 |
|
---|
84 | print STDOUT "Content-type:text/html\n\n";
|
---|
85 | print STDOUT "<p>Processing ...</p>";
|
---|
86 |
|
---|
87 | my $line;
|
---|
88 | while (defined ($line=<PIN>)) {
|
---|
89 | next if ($line =~ m/^Realistic book generated/);
|
---|
90 | chomp $line;
|
---|
91 | print STDOUT "$line<br>\n";
|
---|
92 | }
|
---|
93 |
|
---|
94 | close(PIN);
|
---|
95 | }
|
---|
96 | else {
|
---|
97 | $rb_cgi->generate_error("Failed to cmd: $cmd");
|
---|
98 | }
|
---|
99 |
|
---|
100 | select ($old_handle);
|
---|
101 |
|
---|
102 | print STDOUT "Done\n";
|
---|
103 | my $viewbookurl = $rb_cgi->param("viewbookurl");
|
---|
104 | my $viewthisbookurl = "$viewbookurl/$fname/index.html";
|
---|
105 |
|
---|
106 | print STDOUT "<p><a href=\"$viewthisbookurl\">View this Realistic Book</a></p>\n";
|
---|
107 | print STDOUT "<p><a href=\"$viewbookurl\">View Realistic Library</a></p>\n";
|
---|
108 |
|
---|
109 |
|
---|
110 | ##$rb_cgi->generate_message("Success: $output");
|
---|
111 |
|
---|
112 | }
|
---|
113 | else {
|
---|
114 | $rb_cgi->generate_error("Unrecognized action");
|
---|
115 | }
|
---|
116 | }
|
---|
117 |
|
---|
118 |
|
---|
119 |
|
---|
120 |
|
---|
121 | &main();
|
---|