#! /usr/bin/perl # # sdn.cgi # # 1.0 : 4/7/08 : Created # # Need Archive::Zip, File::Copy::Recursive # # http://www.hidekik.com # # Copyright(c) 2005-2008, Hideki Kanayama, All rights reserved. use Archive::Zip; use CGI::Carp qw(fatalsToBrowser); use Cwd; use File::Basename; use CGI qw(:cgi-lib); use strict; use File::Copy::Recursive qw(rmove); use Time::Local; my $script= basename($0); my $version = "1.0"; my $updatedyear = "2008"; my $adminpwd = "adminpwd.dat"; my $lang = 0; my $charset = ('Shift_JIS', 'ISO-8859-1')[$lang]; my $prefix = 'flist'; my $zipfile = "$prefix$$.zip"; my $setupfile = "sdn_setup.pl"; #### Environment setup from here #################### # リストファイル our $listfile = "listfile.lst"; # zipファイル格納ディレクトリ。CGIから見た相対パス。 our $zipdir = "."; # $zipdirにあるテンポラリ.zipファイルを削除するまでの時間(分) # Expiratoin time to delete zip files in the temporary file our $expire = 60; # タイトル # title our $title_en = 1; our $title = '連載ダウンロード'; our $title_color=""; our $title_size='+1'; our $title_face=''; # 1ページ表示行数 # number to be displayed in one page our $num_in_a_page = 20; # 戻るリンク # back link our $back_en = 1; our $back = ('戻る','Back')[$lang]; our $backlink = ".."; # 管理人リンク 0:off 1:on our $adminlink_en = 1; # background our $bgimage_en = 0; our $bgcolor = "#ffffff"; our $bgimagefile = ""; # 表\示幅 our $body_width = 100; # zipダウンロードページへ移動 1:有効 0:無効 our $goto_zippage = 0; # 期限を過ぎたファイルやディレクトリを別ディレクトリへ移動する 1:移動する 0:移動しない our $move_expired_files = 0; our $expired_dir = 'expired'; #スタイルシート 1:on 0:off our $style_sheet_en = 0; our $style_sheet = 'A:link {text-decoration: none} A:visited {text-decoration: none} A:active {text-decoration: none} '; #
〜内に挿入できる構\文 1:on, 0:off our $head_insert_en = 0; our $head_insert = ''; #### Environment setup till here #################### require "$setupfile" if (-e "$setupfile"); my $q = new CGI; my $cgierror = $q->cgi_error; &error($cgierror) if ($cgierror); my %in = $q->Vars; if (! -e "$adminpwd"){ if ($in{mode} eq 'wradminpwd'){ &wradminpwd; } else { &setadminpwd; } } if (! -d $zipdir){ mkdir "$zipdir"; } my $now = time; # $filelist[number][0] = title # $filelist[number][1] = filename my @filelist; my @file_or_dir; my $i = 1; my $maxnum; if ($in{mode} eq '' or $in{mode} eq 'download'){ if (open (LIST, "< $listfile")) { while (管理人設定","Cannot open directory:$filedir")[$lang]); my @tmp = sort grep !/^\./, readdir DLDIR; closedir(DLDIR); foreach my $thisfile (@tmp) { next if (-d "$filedir/$thisfile"); $filelist[$i][0] = "$filetitle/$thisfile"; $filelist[$i][1] = "$filedir/$thisfile"; $i++; } } elsif (-f "$filedir"){ $filelist[$i][0] = "$filetitle"; $filelist[$i][1] = "$filedir"; $i++; # Skip if no file or directory # } else { # &error(("ディレクトリ、またはファイル$filedirが存在しません。リストファイルを修正してください。
管理人設定","Cannot open directory or file:$filedir")[$lang]); } } # unshift(@filelist,'dummy'); close(LIST); } $maxnum = $i - 1; } if ($in{mode} eq 'setup'){ &setupform; } elsif ($in{mode} eq 'makesetup'){ &makesetup; } elsif ($in{mode} eq 'listfileform'){ &listfileform; } elsif ($in{mode} eq 'makelistfile'){ &makelistfile; } elsif ($in{mode} eq 'download'){ &makezip; } else { &display; } exit; sub check_file_time { my ($start,$end) = @_; my $startepoc; my $endepoc; my $startok = 0; my $endok = 0; my @starttime = split /:/, "$start"; if ($starttime[0] == 0){ $startok = 1; } else { if ($starttime[1] < 1){ $starttime[1] = 1; } if ($starttime[2] < 1){ $starttime[2] = 1; } @starttime = &fix_date(@starttime); $startepoc = timelocal(0,$starttime[4],$starttime[3],$starttime[2],$starttime[1]-1,$starttime[0]); } my @endtime = split /:/, "$end"; if ($endtime[0] == 0){ $endok = 1; } else { @endtime = &fix_date(@endtime); $endepoc = timelocal(0,$endtime[4],$endtime[3],$endtime[2],$endtime[1]-1,$endtime[0]); } return (($startepoc <= $now or $startok),($endepoc >= $now or $endok)); } sub fix_date { my ($year,$month,$day,$hour,$min) = @_; if ($month < 1 and $month ne ''){ $month = 1; } if ($day < 1 and $day ne ''){ $day = 1; } if ($year < 1971 and ($year ne '' and $year != 0)){ $year = 1971; } elsif ($year > 2037 and ($year ne '' and $year != 0)){ $year = 2037; } if ($hour < 0 and $hour ne ''){ $hour = 0; } elsif ($hour > 23 and $hour ne ''){ $hour = 23; } if ($min < 0 and $min ne ''){ $min = 0; } elsif ($min > 59 and $min ne ''){ $min = 59; } if ($year == 0){ $year = ''; $month = ''; $day = ''; $hour = ''; $min = ''; } else { my @monthdays = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); my $md = $monthdays[$month-1]; ++$md if ($month == 2 and $year % 4 == 0 and ($year % 100 != 0 or $year % 400 == 0)); $day = $md if ($day > $md and $day ne ''); } return ($year,$month,$day,$hour,$min); } sub makezip { my $zip = Archive::Zip->new(); my $member; my $i=0; my $eachfile; my $newfile; foreach (keys(%in)){ if ($in{$_} eq 'on'){ next if ($_ eq 'allon' || $_ eq 'alloff'); /check_(\d\d*)/; $eachfile = $filelist[$1][1]; $newfile = basename($eachfile); $member = $zip->addFile("$eachfile","$newfile"); } } my $status = $zip->writeToFileNamed("$zipfile"); if ($status != 'AZ_OK') { unlink("$zipfile") if (-e "$zipfile"); &error(("$zipfileが作成されません","Cannot create $zipfile")[$lang]) } rename "$zipfile", "$zipdir/$zipfile"; if ($goto_zippage){ &zippage($zipfile); } else { print "Location: $zipdir/$zipfile\n\n"; } } sub display { &cleanzip; my $from; if (! exists $in{from}) { $from = 1; } else { $from = $in{from}; } my $to; if (! exists $in{to}){ $to = $num_in_a_page; } else { $to = $in{to}; } &beginning($from,$to); print qq(
| \n";
}
sub ending {
my $mysite = ('http://www.hidekik.com/','http://www.hidekik.com/en/')[$lang];
print qq| sdn.cgi Ver. $version \n|;
print "Copyright(c) 2005-$updatedyear, hidekik.com |