OSDN Git Service

CRLF 2 LF, chmox +x
authorLong.inus <long.inus@hotmail.co.jp>
Mon, 22 Apr 2013 13:27:03 +0000 (22:27 +0900)
committerLong.inus <long.inus@hotmail.co.jp>
Mon, 22 Apr 2013 13:27:03 +0000 (22:27 +0900)
pdfmanager.pl [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index bf2ae66..ffa8298
-#!/usr/bin/perl\r
-use utf8;\r
-use strict;\r
-use warnings;\r
-use CGI;\r
-use CGI::Carp qw(fatalsToBrowser);\r
-use DBD::SQLite;\r
-use DBI;\r
-use Data::Dumper;\r
-use Encode 'decode';\r
-use File::Slurp;\r
-use YAML::XS;\r
-\r
-#\r
-#   Libre10\r
-#\r
-#   Copyright 2013 yukikaze, long.inus\r
-#   Licensed under the Apache License, Version 2.0 (the "License");\r
-#   you may not use this file except in compliance with the License.\r
-#   You may obtain a copy of the License at\r
-#\r
-#       http://www.apache.org/licenses/LICENSE-2.0\r
-#\r
-#   Unless required by applicable law or agreed to in writing, software\r
-#   distributed under the License is distributed on an "AS IS" BASIS,\r
-#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-#   See the License for the specific language governing permissions and\r
-#   limitations under the License.\r
-#\r
-\r
-my $cgi      = new CGI;\r
-my $mode     = $cgi->param('mode');\r
-my $confpath = -e "libre10.conf" ? "libre10.conf" : "/etc/libre10.conf";\r
-my $confdata = YAML::XS::LoadFile($confpath);\r
-my $temppath = "/tmp/libre10/tmp" . generate_unique_key();\r
-my $dbh      = DBI->connect( "dbi:SQLite:dbname=$confdata->{dburl}", "", "", { RaiseError => 1, AutoCommit => 1 } );\r
-my $pdflist  = $dbh->selectall_hashref(\r
-       "SELECT id, path, page, title, part, genre, startpage, endpage, showpagediff, indexpage\r
-       FROM pdffile"\r
-       , 'id'\r
-);\r
-mkdir '/tmp/libre10' unless ( -e '/tmp/libre10' );\r
-\r
-if ( $mode eq 'partpdf' ) {\r
-       my $pdfid = $cgi->param('pdfid');\r
-       my $pdftk = $cgi->param('pdftk');\r
-\r
-       # sanitize\r
-       $pdftk =~ s/[^0-9\-]//;\r
-\r
-       my $pdfpath = $pdflist->{$pdfid}->{path};\r
-       exit unless ( -e $pdfpath );\r
-       system "pdftk '$pdfpath' cat '$pdftk' output '$temppath.pdf'";\r
-       my $length = -s "$temppath.pdf";\r
-       print "Content-Type: application/pdf\n";\r
-       print "Content-Length: $length\n";\r
-       print "\n";\r
-       print read_file("$temppath.pdf");\r
-       exit;\r
-}\r
-\r
-print $cgi->header( -charset => 'utf-8' );\r
-list_all_pdf();\r
-\r
-sub list_all_pdf {\r
-       print qq {Partial PDF = ./pdfmanager.pl?mode=partpdf&pdfid=68fc6a6a1cdd79227d0f2fe2f03dd510&pdftk=765-765\n};\r
-       my $ary_ref = $dbh->selectall_arrayref(\r
-               "SELECT id, path, page, title, part, genre, startpage, endpage, showpagediff, indexpage\r
-               FROM pdffile"\r
-               , { Slice => {} }\r
-       );\r
-       print qq {<table>\n};\r
-       print qq {<tr>\n};\r
-       print qq {<th>id</th>\n};\r
-       print qq {<th>path</th>\n};\r
-       print qq {<th>page</th>\n};\r
-       print qq {<th>title</th>\n};\r
-       print qq {<th>part</th>\n};\r
-       print qq {<th>genre</th>\n};\r
-       print qq {<th>start</th>\n};\r
-       print qq {<th>end</th>\n};\r
-       #print qq {<th>showpagediff</th>\n};\r
-       #print qq {<th>indexpage</th>\n};\r
-       print qq {</tr>\n};\r
-       foreach my $line ( @{$ary_ref} ) {\r
-               print qq {<tr>\n};\r
-               print qq {<td><a href="./htmlserver.pl?pdfpath=$line->{id}&amp;pagenum=1">$line->{id}</a></td>\n};\r
-               print qq {<td>$line->{path}</td>\n};\r
-               print qq {<td>$line->{page}</td>\n};\r
-               print qq {<td>$line->{title}</td>\n};\r
-               print qq {<td>$line->{part}</td>\n};\r
-               print qq {<td>$line->{genre}</td>\n};\r
-               print qq {<td>$line->{startpage}</td>\n};\r
-               print qq {<td>$line->{endpage}</td>\n};\r
-               #print qq {<td>$line->{showpagediff}</td>\n};\r
-               #print qq {<td>$line->{indexpage}</td>\n};\r
-               print qq {</tr>\n};\r
-       }\r
-       print qq {</table>\n};\r
-}\r
-\r
-sub generate_unique_key {\r
-       my $ukey;\r
-       my @str = ( 0 .. 9, 'A' .. 'Z', 'a' .. 'z' );\r
-\r
-       foreach ( 1 .. 8 ) {\r
-               $ukey .= $str[ int( rand(@str) ) ];\r
-       }\r
-       return $ukey;\r
-}\r
-\r
+#!/usr/bin/perl
+use utf8;
+use strict;
+use warnings;
+use CGI;
+use CGI::Carp qw(fatalsToBrowser);
+use DBD::SQLite;
+use DBI;
+use Data::Dumper;
+use Encode 'decode';
+use File::Slurp;
+use YAML::XS;
+
+#
+#   Libre10
+#
+#   Copyright 2013 yukikaze, long.inus
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+#
+
+my $cgi      = new CGI;
+my $mode     = $cgi->param('mode');
+my $confpath = -e "libre10.conf" ? "libre10.conf" : "/etc/libre10.conf";
+my $confdata = YAML::XS::LoadFile($confpath);
+my $temppath = "/tmp/libre10/tmp" . generate_unique_key();
+my $dbh      = DBI->connect( "dbi:SQLite:dbname=$confdata->{dburl}", "", "", { RaiseError => 1, AutoCommit => 1 } );
+my $pdflist  = $dbh->selectall_hashref(
+       "SELECT id, path, page, title, part, genre, startpage, endpage, showpagediff, indexpage
+       FROM pdffile"
+       , 'id'
+);
+mkdir '/tmp/libre10' unless ( -e '/tmp/libre10' );
+
+if ( $mode eq 'partpdf' ) {
+       my $pdfid = $cgi->param('pdfid');
+       my $pdftk = $cgi->param('pdftk');
+
+       # sanitize
+       $pdftk =~ s/[^0-9\-]//;
+
+       my $pdfpath = $pdflist->{$pdfid}->{path};
+       exit unless ( -e $pdfpath );
+       system "pdftk '$pdfpath' cat '$pdftk' output '$temppath.pdf'";
+       my $length = -s "$temppath.pdf";
+       print "Content-Type: application/pdf\n";
+       print "Content-Length: $length\n";
+       print "\n";
+       print read_file("$temppath.pdf");
+       exit;
+}
+
+print $cgi->header( -charset => 'utf-8' );
+list_all_pdf();
+
+sub list_all_pdf {
+       print qq {Partial PDF = ./pdfmanager.pl?mode=partpdf&pdfid=68fc6a6a1cdd79227d0f2fe2f03dd510&pdftk=765-765\n};
+       my $ary_ref = $dbh->selectall_arrayref(
+               "SELECT id, path, page, title, part, genre, startpage, endpage, showpagediff, indexpage
+               FROM pdffile"
+               , { Slice => {} }
+       );
+       print qq {<table>\n};
+       print qq {<tr>\n};
+       print qq {<th>id</th>\n};
+       print qq {<th>path</th>\n};
+       print qq {<th>page</th>\n};
+       print qq {<th>title</th>\n};
+       print qq {<th>part</th>\n};
+       print qq {<th>genre</th>\n};
+       print qq {<th>start</th>\n};
+       print qq {<th>end</th>\n};
+       #print qq {<th>showpagediff</th>\n};
+       #print qq {<th>indexpage</th>\n};
+       print qq {</tr>\n};
+       foreach my $line ( @{$ary_ref} ) {
+               print qq {<tr>\n};
+               print qq {<td><a href="./htmlserver.pl?pdfpath=$line->{id}&amp;pagenum=1">$line->{id}</a></td>\n};
+               print qq {<td>$line->{path}</td>\n};
+               print qq {<td>$line->{page}</td>\n};
+               print qq {<td>$line->{title}</td>\n};
+               print qq {<td>$line->{part}</td>\n};
+               print qq {<td>$line->{genre}</td>\n};
+               print qq {<td>$line->{startpage}</td>\n};
+               print qq {<td>$line->{endpage}</td>\n};
+               #print qq {<td>$line->{showpagediff}</td>\n};
+               #print qq {<td>$line->{indexpage}</td>\n};
+               print qq {</tr>\n};
+       }
+       print qq {</table>\n};
+}
+
+sub generate_unique_key {
+       my $ukey;
+       my @str = ( 0 .. 9, 'A' .. 'Z', 'a' .. 'z' );
+
+       foreach ( 1 .. 8 ) {
+               $ukey .= $str[ int( rand(@str) ) ];
+       }
+       return $ukey;
+}
+