#! /usr/bin/perl # # jl3.cgi # # 3.003 : 6/15/08 : タグ機能を修正、削除機能を修正 # 3.002 : 3/12/08 : Locationタグを修正 # 3.001 : 10/10/05 : Added option to attach numbers to the attendees # 3.0 : 10/9/05 : Created as a non-SSI version # # $Id: jl3.cgi,v 1.11 2008/06/14 18:12:17 Hideki Kanayama Exp $ # Copyright(c) 2005-2008, Hideki Kanayama, All rights reserved. use CGI qw(:cgi-lib); use CGI::Carp qw(fatalsToBrowser); use File::Basename; use strict; my $version='3.003'; my $lastupdatedyear='2008'; my $script = basename($0); my $setupfile = "jl_setpu.pl"; my $tmpfile = "tmp.$$"; my $admindat = "adminpwd.dat"; my $charset = "Shift_JIS"; my $lang = 0; ##################################### our $datafile = "joinlist.dat"; our $lockfile = "lockfile.dat"; our $backlink_en = 1; our $backlink = ".."; our $backlink_name = ('戻る','Back')[$lang]; our $bgimage_en = 0; our $bgcolor = 'white'; our $bgimage_file = ''; our $title = ('パーティー参加表明表3','Party signup board 3')[$lang]; our $logo = "."; our $logo_style = ''; our $logo_color = 'black'; our $logo_size = '+1'; our $logo_face = ''; our $logo_sel = 0; # 0:default, 1:text, 2:logo, 3:style sheet our $logo_loc=1; # 0:left, 1:center, 2:right our $attendee = ('参加者名','attendee')[$lang]; our $comment = ('意気込み/コメント','Comment')[$lang]; our $password = ('パスワード','Password')[$lang]; our $register = ('登録','Register')[$lang]; our $attendee_color = 'black'; our $comment_color = 'black'; our $password_color = 'black'; our $register_color = 'black'; our $attendee_bgcolor = 'white'; our $comment_bgcolor = 'white'; our $password_bgcolor = 'white'; our $register_bgcolor = 'white'; our $body_width = 100; our $name_width = 20; our $comment_width = 60; our $pwd_width = 10; our $button_width = 10; our $name_text_width = 20; our $comment_text_width = 50; our $pwd_text_width = 10; our $setup_en = 1; our $setup_name = ('管理用','admin')[$lang]; our $tag_en = 0; our $number_en = 0; our $style_sheet_en = 1; our $style_sheet = ' A:link {text-decoration: none} A:visited {text-decoration: none} A:active {text-decoration: none} '; our $head_insert_en = 0; our $head_insert = ''; our $body_insert1_en = 0; our $body_insert1 = ''; our $body_insert2_en = 0; our $body_insert2 = ''; our $body_insert3_en = 0; our $body_insert3 = ''; ########################################## require "$setupfile" if (-e "$setupfile"); my $q = CGI->new; my $cgierror = $q->cgi_error; &error($cgierror) if ($cgierror); my %in = $q->Vars; &postprocess; if (! -e "$admindat"){ if ($in{mode} eq 'wradminpwd'){ &wradminpwd($in{pwd}); } else { &setadminpwd; } } if ($in{mode} eq 'write') { &write; } elsif ($in{mode} eq 'setup') { &setup; } elsif ($in{mode} eq 'setupwrite') { &setupwrite; } else { &display; } sub write { my @allline; my $finnum; my @rest; if (open(DAT,"< $datafile")){ @allline=; close(DAT); ($finnum,@rest) = split(/,/,$allline[$#allline]); } else { $finnum = 0; } my $num; my $pwd; if ($in{reg} ne ''){ &error(('パスワードを入力してください','Enter password')[$lang]) if ($in{pwd} eq ''); if ($in{name} ne ''){ open(WR,">> $datafile"); $num = $finnum + 1; $pwd = &makecrypt($in{pwd}); print WR "$num,$in{name},,$in{comment},$pwd\n"; close(WR); } } else { open(DAT,"< $datafile"); open(WR,"> $tmpfile"); while(){ chomp; my ($num,$name,$join,$comment,$pwd)=split(/,/); my $cancel = 'cancel' . $num; my $pwdnum = 'pwd' . $num; if($in{$cancel} ne ''){ unless (&checkcrypt($in{$pwdnum},$pwd) && ($pwd ne '')){ close(DAT); close(WR); &error(('パスワードが違います。','Wrong Password')[$lang]); } } else { print WR "$num,$name,$join,$comment,$pwd\n"; } } close(DAT); close(WR); rename("$tmpfile","$datafile"); } chmod(0666,"$datafile"); # print $q->redirect(-url=>"$script"); print "Location: $script\n\n"; } sub display { my $titleprint=&titleprint("$title","$logo","$logo_style","$logo_color","$logo_size","$logo_face","$logo_sel","$logo_loc"); &htmlhead($title); print "$body_insert1\n" if ($body_insert1_en); print "$titleprint\n"; print "$body_insert2\n" if ($body_insert2_en); print "
\n"; if ($backlink_en or $setup_en){ print "\n"; print "\n"; print "
\n"; print "$backlink_name\n" if ($backlink_en); print "\n"; print "$setup_name\n" if ($setup_en == 1); print "
\n"; } print "\n"; my $cols; if ($number_en){ $cols = 5; } else { $cols = 4; } print ""; print "\n"; print "\n" if ($number_en); print "\n"; print "\n"; print "\n"; print "\n"; my $delete_name = ('取り消し','delete')[$lang]; if (open(DAT,"< $datafile")){ my $i=1; while(){ chomp; my ($num,$name,$join,$comment,$pwd)=split(/,/); $comment =~ s/^$/\ /; $comment =~ s/<//ig if ($tag_en); if ($join eq 'off' or $name =~ /^\s*$/ or $comment =~ /^\s*$/){ next; } print ""; print "\n" if ($number_en); print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; $i++; } } print "\n"; print "\n" if ($number_en); print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
 "; print "$attendee"; print ""; print "$comment"; print ""; print "$password"; print " 
 $i $name$comment
 
\n"; close(DAT); ©right; print "$body_insert3\n" if ($body_insert3_en); &htmltail; } exit; sub makecrypt { my $plain = shift; my $salt = join "", ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]; my $result = crypt($plain,$salt) or crypt($plain,'$1$'.$salt.'$'); return $result; } sub setadminpwd { my $subname = 'setadminpwd'; my $msg = ('管理者用パスワードを入力してください','Please enter admin password')[$lang]; &htmlhead($msg); print "
\n"; print "
$msg
\n"; print "\n"; if ($in{mode} eq 'setup'){ print "\n"; print "\n"; } else { print "\n"; print "\n"; } print "

"; ©right; &htmltail; exit; } sub wradminpwd { my $plain = shift; my $passwd = &makecrypt($plain); if (open(FILE,"> $admindat")){ print FILE "$passwd"; close(FILE); } else { &error('パスワードファイル作成に失敗しました'); } } sub checkcrypt { my ($pwd,$encpwd)=@_; return(crypt($pwd,$encpwd) eq "$encpwd" or &checkadmin); } sub postprocess { my $key; foreach $key (keys %in){ my $br; if ($key !~ /insert/){ $in{$key} =~ s//>/g; } $br = "
"; if ($in{$key} =~ /\r\n/) { $in{$key} =~ s/\r\n/$br/g; } if ($in{$key} =~ /\n/) { $in{$key} =~ s/\n/$br/g; } if ($in{$key} =~ /\r/) { $in{$key} =~ s/\r/$br/g; } if ($in{$key} =~ /,/) { $in{$key} =~ s/,/&\#44;/g; } } } sub checkadmin { my $pwd = shift; if (open(FILE,"< $admindat")){ my $filepwd = ; close(FILE); my $inpwd = crypt($pwd,$filepwd); return ("$inpwd" eq "$filepwd"); } else { &error((('パスワードファイルが存在しません','Cannot find password file')[$lang])); } } sub error { my ($msg) = shift; &unlockfile; &htmlhead($msg); print "

$msg"; print "

"; &backbutton; print "

\n"; ©right; &htmltail; exit; } sub unlockfile { unlink("tmp.$$") if (-e "tmp.$$"); unlink("$lockfile") if (-e $lockfile); } sub lockfile { while(-e "$lockfile"){ sleep(1); } open(LOCK,"> $lockfile"); close(LOCK); } sub titleprint { my ($title,$logo,$style,$color,$size,$face,$sel,$loc)=@_; my @location = ('left','center','right'); my $titleline; if ($sel == 0) { $titleline = "

$title

"; } elsif ($sel == 1){ $titleline = "
$title

"; } elsif ($sel == 2){ $titleline = "
\"$title\"

"; } elsif ($sel == 3){ $titleline = "
$title

"; } elsif ($sel == 4){ $titleline = ""; } return($titleline); } sub htmlhead { my $title = shift; my $bgimage; if ($bgimage_en == 1){ $bgimage = "background=\"$bgimage_file\""; } else { $bgimage = "bgcolor=\"$bgcolor\""; } print $q->header(-type=>'text/html',-charset=>$charset); print "\n"; print "\n"; print "$title\n"; if ($head_insert_en == 1){ print "$head_insert\n"; } if ($style_sheet_en == 1){ print "\n"; } print "\n"; print "\n"; print "
\n"; } sub copyright { my $mysite = ('http://www.hidekik.com/','http://www.hidekik.com/en/')[$lang]; print "
jl3.cgi Ver. $version "; print "Copyright(C) 2002-$lastupdatedyear, hidekik.com
\n"; } sub htmltail { print "
\n"; } sub setup { my $subname = 'setup'; &setadminpwd if ($in{pwd} eq ''); &error(('管理用パスワードが違います。','Wrong admin password')[$lang]) unless &checkadmin($in{pwd}); &htmlhead($title); my %check; $check{backlink}[$backlink_en] = "checked"; $check{bgimage}[$bgimage_en] = "checked"; $check{logo_sel}[$logo_sel] = "checked"; $check{logo_loc}[$logo_loc] = "checked"; $check{setup}[$setup_en] = "checked"; $check{tag}[$tag_en] = "checked"; $check{number}[$number_en] = "checked"; $check{style_sheet}[$style_sheet_en] = "checked"; $check{head_insert}[$head_insert_en] = "checked"; $check{body_insert1}[$body_insert1_en] = "checked"; $check{body_insert2}[$body_insert2_en] = "checked"; $check{body_insert3}[$body_insert3_en] = "checked"; print "\n"; print "\n"; print "\n"; my $notice = ("
  • セットアップリンクを非表\示にしている場合は、$script?mode=setupからパスワードを入力してこのページに入ってください。
  • 数字やカラー指定は必ず半角で指定してください。全角やブランクだとCGIが起動しなくなります。万一間違って全角で書いてしまった場合は、$setupfileをエディタで開きその場所を半角に正しく修正してください。それで直ります。
  • ", "
  • If you disable to display admin setup link, you can open the page with $script?mode=setup and change the setting.
  • ")[$lang]; print <
      $notice
    END print (('データファイル','data file')[$lang]); print < END print (('ロックファイル','lock flie')[$lang]); print < END print (('バックグランド','background')[$lang]); print < END print (('画像を使う','image')[$lang]); print " "; print (('カラー設定にする','color')[$lang]); print < END print (('画像を使う場合の画像ファイル','image file')[$lang]); print < END print (('カラー設定の場合のカラー番号(白:#ffffff 又は white)','color code(white:white or #ffff)')[$lang]); print < END print (('タイトル名','title')[$lang]); my $none = ('無し','none')[$lang]; my $default = ('デフォルト','default')[$lang]; my $text = ('テキスト','text')[$lang]; my $logoimage = ('ロゴ画像','logo image')[$lang]; my $stylesheetname = ('スタイルシート','style sheet')[$lang]; my $left = ('左','left')[$lang]; my $center = ('中','center')[$lang]; my $right = ('右','right')[$lang]; my $location = ('位置:','location:')[$lang]; print <
    $none
    $default<H2></H2>
    $text color= size= face=
    $logoimage
    $stylesheetname
    $location $left $center $right END print (('ヘッダー名と色','header name and color')[$lang]); print < END print (('参加者名','attendee')[$lang]); print qq( color= bgcolor=
    \n); print (('コメント','comment')[$lang]); print qq( color= bgcolor=
    \n); print (('パスワード','password')[$lang]); print qq( color= bgcolor=
    \n); print (('登録ボタン','Button')[$lang]); print qq( color= bgcolor=
    \n); print " "; print (('トップへのリンク','link to top')[$lang]); my $disp = ('表示','display')[$lang]; my $nondisp = ('非表示','not display')[$lang]; my $linkname = ('リンク名','link name')[$lang]; print < $disp $nondisp
    $linkname
    URL
    END print (('表の表示幅','table width')[$lang]); print " "; print (('ブラウザ全体の','')[$lang]); print <% END print (('表のカラム幅','column width')[$lang]); print " "; print (('名前欄','name column')[$lang]); print qq(%
    \n); print (('コメント欄','comment column')[$lang]); print qq(%
    \n); print (('パスワード欄','password column')[$lang]); print qq(%
    \n); print (('ボタン欄','button column')[$lang]); print qq(%
    \n); print " "; print (('テキストボックスサイズ','text box width')[$lang]); print " "; print (('名前','name column')[$lang]); print qq(
    \n); print (('コメント','comment column')[$lang]); print qq(
    \n); print (('パスワード','password column')[$lang]); print qq(
    \n); print " "; print (('セットアップのリンク','link to setup')[$lang]); print < $disp $nondisp
    $linkname
    END print (('タグ使用','use of tags')[$lang]); my $valid = (('有効','valid')[$lang]); my $invalid = (('無効','invalid')[$lang]); print < $valid $invalid
    END print (('参加者番号','number of the attendees')[$lang]); print < $disp $nondisp
    END print (('<head>内挿入文','sentense in <head>')[$lang]); print < $valid $invalid
    END print ((' HTML書式
    ポップアップ広告やJavascript、<META>を挿入したい場合にここに記述する。
    以下の記述が<head>〜</head>内に挿入される。
    ','HTML format. Javascript, popup ads, <META> and so on can be inserted in here. ')[$lang]); print <$head_insert
    $stylesheetname $valid $invalid

    END print (('<body>内挿入文','sentense in <body>')[$lang]); print "\n"; print ((' 上部に表示される文をHTMLで記述。ここにイベントの予定や詳細等を記述することができます。その他リンク、画像なんでもHTMLで記述できます。タイトルを非表示にして凝ったタイトルをここに記述することもできます。
    タイトルの上 ','HTML format. You can discrive event detail here.
    Above the title ')[$lang]); print <$valid $invalid

    END print (('タイトルの下','below the title')[$lang]); print <$valid $invalid

    END print (('ページの一番下','bottom of the page')[$lang]); print <$valid $invalid

    END my $setting = (('設定','setting')[$lang]); print ""; print ""; ©right; &htmltail; } sub setupwrite { &error(('管理人パスワードが違います','Wrong admin password')[$lang]) unless ( &checkadmin($in{pwd})); $in{logo_size} =~ s/ /+/; foreach (keys(%in)){ $in{$_} =~ s/
    /\n/g; $in{$_} =~ s/&\#44;/,/g; $in{$_} =~ s/<//g; } open(SETUP,"> $setupfile"); print SETUP <\n"; }