#! c:/perl/bin/perl # # chkbox.cgi # # 2.0 : 1/19/06 : Created. # # $Id: chkbox2.cgi,v 1.4 2006/01/19 05:44:34 Hideki Kanayama Exp $ # Copyright 2005-2006 Hideki Kanayama, All rights reserved use CGI qw(:cgi-lib); use strict; use CGI::Carp qw(fatalsToBrowser); use File::Basename; my $version = "2.0"; my $lastupdatedyear = "2006"; my $admindat = "adminpwd.dat"; my $setupfile = "chkbox2_setup.pl"; my $script = basename($0); my $lang = 1; #my $charset = ("Shift_JIS","ISO-8859-1")[$lang]; my $charset = "Shift_JIS"; ########## 環境設定 ここから ########################### our $datafile = "checkbox.dat"; our $items = "items.lst"; # lockfile our $lockfile = "lockfile.dat"; # Title our $title = 'チェックボックス2'; # Background our $bgimage_en = 0; our $bgimage_file = ''; our $bgcolor = "#ffffff"; # Back link our $backlink_en = 1; our $backlink = '..'; our $backlink_name = '戻る'; # Body width our $body_width = '100'; # option cell back ground color our $option_bg_color = "#ffcc33"; # option cell font color our $option_font_color = "black"; # item cell back ground color our $item_bg_color = "#66ff99"; # item cell font color our $item_font_color = "black"; #表示テーブルのカラム数 our $table_colms = 1; #参加者設定の初期登録可能人数 our $default_max = 15; #管理用リンク表示 1:有効 0:無効 our $setup_en = 1; #変更日表示 1:有効 0:無効 our $update_en = 0; #パスワード保護 1:有効 0:無効 our $password_en = 0; #カウント 1:有効 0:無効 our $count_en = 0; #管理人オンリーモード 1:有効 0:無効 our $adminonly_en = 1; #オプション オプション名,背景色 our $options = '日曜日,red 月曜日,blue 火曜日,green 水曜日,lightgreen 木曜日,black 金曜日,orange 土曜日,lightblue '; # body_head our $body_head = "
"; # body_tail our $body_tail = ' '; # Style Sheet our $style_sheet_en = 0; our $style_sheet = ' '; # Head insert our $head_insert_en = 0; our $head_insert = ' '; #時間設定 1:localtime, 0:offset from GMT our $localtime_en = 1; our $offset_from_gmt = 9; #予備のアップデートファイル # 1: on, 0: off our $update1_file_en = 0; our $update2_file_en = 0; our $update1_file = "update1.log"; our $update2_file = "update2.log"; ########## 環境設定 ここまで ########################### require "$setupfile" if (-e "$setupfile"); my $q = CGI->new; my $cgierror = $q->cgi_error; &error($cgierror) if ($cgierror); my %in = $q->Vars; if (-e "$setupfile") { require "$setupfile"; } if (! -e "$admindat"){ if ($in{mode} ne 'wradminpwd'){ &setadminpwd; } else { &wradminpwd($in{pwd}); } } my @option_list = grep !/^\s*$/, split /[\r\n]/, $options; if ($in{mode} eq 'atwrite'){ &atwrite; } elsif ($in{mode} eq 'setup'){ &setup; } elsif ($in{mode} eq 'setup_update'){ &setup_update; } else { &display; } ###################### 書き込み ############################ sub atwrite { &error('管理用パスワードが違います。') if (!&checkadmin($in{pwd}) and $adminonly_en == 1); &error('名前は必ず入れてください')if ($in{name} eq "" and $adminonly_en == 0); my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)= $localtime_en ? localtime(time) : gmtime(time + 3600 * $offset_from_gmt); my $update = sprintf("%s_%s_%s_%02s_%02s",$year+1900,$mon+1,$mday,$hour,$min); my @items = &get_items; my ($date, $lastname, $name, $status, $count, $eachpwd, $eachmod) = &get_data; my (@name, @status, @count, @eachpwd, @eachmod); @name = @{$name}; @status = @{$status}; @count = @{$count}; @eachpwd = @{$eachpwd}; @eachmod = @{$eachmod}; &lockfile; my $tmpfile = "tmp.$$"; open(WRDAT,">$tmpfile"); print WRDAT "0,$in{name},$update,\n"; my $endatt = $#items + 1; my $i; for ($i=1;$i<=$endatt;$i=$i+1){ my $pwdi = "pwd_$i"; chomp($items[$i-1]); my $incheck = join('-', map {$in{"${i}_$_"}} (0 .. $#option_list)); my $stcheck = join('-', map {$status[$i][$_]} (0 .. $#option_list)); if ($incheck ne $stcheck) { $eachmod[$i] = "$update"; if ($password_en == 1 && "$eachpwd[$i]" ne '' && !&checkcrypt("$in{$pwdi}","$eachpwd[$i]")) { close(WRDAT); unlink("$tmpfile"); &error("$name[$i]を変更しようとしていますが、そのパスワードが違います。"); } } if ($password_en == 1 && ("$in{$pwdi}" ne '' && "$eachpwd[$i]" eq '')){ $eachpwd[$i] = &makecrypt("$in{$pwdi}"); } print WRDAT "$i,$items[$i-1],$in{\"count_$i\"},$eachmod[$i],$eachpwd[$i],"; my $x; for ($x=0;$x<=$#option_list;$x++) { my $tmpix = "${i}_$x"; print WRDAT "$in{$tmpix}," ; } print WRDAT "\n"; } close(WRDAT); rename("$tmpfile","$datafile"); chmod(0666,"$datafile"); &unlockfile; &extraupdate; print "Location: $script\n\n"; } ###################### 表示 ############################ sub display { &htmlhead($title); my ($date, $lastname, $name, $status, $count, $eachpwd, $eachmod) = &get_data; my (@name, @status, @count, @eachpwd, @eachmod); @name = @{$name}; @status = @{$status}; @count = @{$count}; @eachpwd = @{$eachpwd}; @eachmod = @{$eachmod}; my @items_list = &get_items; print "$body_head"; print "
"; print "$body_tail"; &htmltail; } ###################### セットアップ ############################ sub setup { &setadminpwd if ($in{pwd} eq ''); &error('管理用パスワードが違います。') unless &checkadmin($in{pwd}); &htmlhead('管理用セットアップ'); print "\n"; print "| \n"; } sub copyright { my $mysite = ('http://www.hidekik.com/','http://www.hidekik.com/en/')[$lang]; print "$script Ver. $version\n"; print "Copyright(C) 2005-$lastupdatedyear, hidekik.com\n"; } sub htmltail { print " |