#!/usr/bin/perl ############################################################ # # ID Manager「秘密の花園」 v1.0 (Jul-17-2003) # # グループ管理プログラム(ベータ版) # # Copyright (c) 2002-3 Kan-chan # Web site: http://kan-chan.stbbs.net/download/ # ############################################################ # idmancfg.pl(環境設定ファイル)のパス require './idmancfg.pl'; # jcode.pl(日本語コードコンバータ)のパス require './jcode.pl'; # mimew.pl(MIMEエンコーダ)のパス require './mimew.pl'; ############################################################ if ($ENV{'REQUEST_METHOD'} eq "POST"){ read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); } else{ $buffer = $ENV{'QUERY_STRING'}; } @params = split(/&/,$buffer); foreach (@params) { ($name,$value) = split(/=/,$_); $name =~ tr/+/ /; $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; &jcode'convert(*name,'sjis'); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; &jcode'convert(*value,'sjis'); $value =~ s/\t//; $value =~ s/\n//; $value =~ s/\r//; if ($name eq 'check'){ $check{$value} = 1; } else{ $in{$name} = $value; } } if (!open(IN,"$passfile")) { &error("エラー","パスワードファイルを開くことができません."); } @PASSFILE = ; close(IN); if (!open(IN,"$profile")) { &error("エラー","利用者データファイルを開くことができません."); } @PROFILE = ; close(IN); if (!open(IN,"$groupfile")) { &error("エラー","グループファイルを開くことができません."); } @GROUPFILE = ; close(IN); if (!open(IN,"$gplistfile")) { &error("エラー","グループリストファイルを開くことができません."); } @GPLISTFILE = ; close(IN); if (!open(IN,"$gpuserfile")) { &error("エラー","グループ利用者ファイルを開くことができません."); } @GPUSERFILE = ; close(IN); if (($in{'action'} eq '') || ($in{'action'} eq 'form_login')) { &form_login; } $admin_pass = ''; foreach $line(@PASSFILE){ ($id, $password) = split(/:/, $line); $password =~ s/\n$//; if ($id eq $admin_id) { $admin_pass = $password; } } if ($in{'action'} eq 'list_groups') { &list_groups; } elsif ($in{'action'} eq 'form_group') { &form_group; } elsif ($in{'action'} eq 'form_group_user') { &form_group_user; } elsif ($in{'action'} eq 'gp_addnew') { &gp_addnew; } elsif ($in{'action'} eq 'gp_edit') { &gp_edit; } elsif ($in{'action'} eq 'gp_delete') { &gp_delete; } #elsif ($in{'action'} eq 'gpuser_addnew') { &gpuser_addnew; } elsif ($in{'action'} eq 'gpuser_edit') { &gpuser_edit; } #elsif ($in{'action'} eq 'gpuser_delete') { &gpuser_delete; } &form_login; exit; ############################################################ # HTMLヘッダ・フッタ部分の出力 ############################################################ sub print_html_header{ local($title); $title = $_[0]; print <<"EOF"; Content-type: text/html; charset=shift_jis $title EOF } sub print_html_footer{ print <<"EOF";

終了 | ログイン・諸手続

EOF } ############################################################ # ログイン画面 ############################################################ sub form_login{ &print_html_header('グループ管理 ログイン'); print <<"EOF";

グループ管理 ログイン

管理者IDとパスワードを入力してください。

ID
パスワード
EOF &print_html_footer; exit; } ############################################################ # 処理終了画面 ############################################################ sub done{ $msg = $_[0]; $next_action = $_[1]; $login_id = $_[2]; $password = $_[3]; $gp_id = $_[4]; &print_html_header('処理完了'); print <<"EOF";

処理完了

$msg

EOF if ($next_action eq ''){ print <<"EOF";

戻る

EOF } else{ print <<"EOF";
EOF } &print_html_footer; exit; } ############################################################ # グループ一覧画面 ############################################################ sub list_groups{ if ($in{'login_id'} eq ''){ &error("エラー", "IDが指定されていません。"); } if ($in{'login_id'} ne $admin_id){ &error("エラー", "管理者IDが間違っています。"); } if (!(&confirm_password($admin_pass, $in{'password'}) eq true)){ &error("パスワードエラー", "パスワードが間違っています"); } &print_html_header('グループ一覧'); print <<"EOF";

グループ一覧

EOF foreach $line(@GPLISTFILE){ ($gp_id, $gp_name, $gp_mode) = split(/\t/, $line); $gp_name =~ s/\n$//; print <<"EOF"; EOF } print <<"EOF";
選択 グループID グループ名称
$gp_id $gp_name
(新規) 新規グループ
EOF &print_html_footer; exit; } ############################################################ # グループ編集画面 ############################################################ sub form_group{ local($mygp_id, $mygp_name); local($next_action, $gp_id_text, $title); if ($in{'login_id'} eq ''){ &error("エラー", "管理者IDが指定されていません。"); } if ($in{'login_id'} ne $admin_id){ &error("エラー", "管理者IDが間違っています。"); } if (!(&confirm_password($admin_pass, $in{'password'}) eq true)){ &error("パスワードエラー", "パスワードが間違っています"); } $mygp_id = ''; $mygp_name = ''; if ($in{'gp_id'} ne ''){ # グループの存在チェック foreach $line(@GPLISTFILE){ ($gp_id, $gp_name, $gp_mode) = split(/\t/, $line); if ($in{'gp_id'} eq $gp_id){ $mygp_id = $gp_id; $mygp_name = $gp_name; $mygp_name =~ s/\n$//; } } if ($mygp_id eq ''){ &error('エラー', '指定されたグループIDは存在しません。'); } # 利用者一覧の読込み、フラグ初期化 foreach $line(@PROFILE){ ($id, $name, $email, $date, $public, $area, $msg) = split(/\t/, $line); $gp_user_checked{$id} = ''; } # グループ利用者ファイルより該当グループ、該当利用者の参加状態取得 foreach $line(@GPUSERFILE){ ($user_id, $gp_id, $name, $email, $flg) = split(/\t/, $line); if ($in{'gp_id'} eq $gp_id){ $gp_user_checked{$user_id} = 'checked'; } } } if ($mygp_id eq ''){ $next_action = 'gp_addnew'; $gp_id_text = ""; $title = 'グループ追加'; } else{ $next_action = 'gp_edit'; $gp_id_text = "$mygp_id"; $title = 'グループ編集'; } &print_html_header($title); print <<"EOF";

$title

EOF if ($in{'gp_id'} ne ''){ print <<"EOF";

グループ利用者一覧

左にチェックの付いている利用者が、このグループに登録された利用者です。
チェックを付ける、または外した後「登録」ボタンを押すことによって、グループへの登録および解除ができます。

EOF foreach $line(@PROFILE){ ($id, $name, $email, $date, $public, $area, $msg) = split(/\t/, $line); print <<"EOF"; EOF } print <<"EOF";
登録 利用者ID 名前 $name_of_area_field
$id $name $area
EOF } print <<"EOF";

グループ情報

グループID $gp_id_text
グループ名称
EOF if ($in{'gp_id'} ne ''){ print <<"EOF";

グループ削除

グループID $gp_id_text
管理者パスワード
EOF } &print_html_footer; exit; } ############################################################ # DB処理:グループ追加 ############################################################ sub gp_addnew{ local($exist); if ($in{'login_id'} eq ''){ &error("エラー", "管理者IDが指定されていません。"); } if ($in{'login_id'} ne $admin_id){ &error("エラー", "管理者IDが間違っています。"); } if (!(&confirm_password($admin_pass, $in{'password'}) eq true)){ &error("パスワードエラー", "パスワードが間違っています"); } if ($in{'gp_id'} eq ''){ &error("エラー", "グループIDが指定されていません。"); } $exist = false; foreach $line(@GPLISTFILE){ ($gp_id, $gp_name, $gp_mode) = split(/\t/, $line); if ($in{'gp_id'} eq $gp_id){ $exist = true; } } # もし既にデータが存在していればエラー終了 if ($exist eq true){ &error("エラー", "グループID '$in{'login_id'}'を追加できません。既に存在します。"); } $newrec = "$in{'gp_id'}\t$in{'gp_name'}\t1\n"; push(@GPLISTFILE, $newrec); # もしファイルロックされていればエラー終了 if (&is_locked eq true){ &error("エラー", "サーバが混雑しているため、データベースへの書込ができませんでした。時間をおいて再試行してください。"); } # ロックファイル作成 if (!open(OUT, ">$lockfile")){ &error("エラー", "ロックファイルの作成ができません。"); } open(OUT, ">$lockfile"); close(OUT); if (!open(OUT, ">$gplistfile")){ &error("エラー", "グループリストファイルを開けません。"); } print OUT @GPLISTFILE; close(OUT); &unlock; &done('グループが追加されました。', 'list_groups', $in{'login_id'}, $in{'password'}); exit; } ############################################################ # DB処理:グループ編集 ############################################################ sub gp_edit{ if ($in{'login_id'} eq ''){ &error("エラー", "管理者IDが指定されていません。"); } if ($in{'login_id'} ne $admin_id){ &error("エラー", "管理者IDが間違っています。"); } if (!(&confirm_password($admin_pass, $in{'password'}) eq true)){ &error("パスワードエラー", "パスワードが間違っています"); } if ($in{'gp_id'} eq ''){ &error("エラー", "グループIDが指定されていません。"); } foreach $line(@GPLISTFILE){ ($gp_id, $gp_name, $gp_mode) = split(/\t/, $line); if ($in{'gp_id'} eq $gp_id){ $newrec = "$gp_id\t$in{'gp_name'}\t1\n"; push(@NEW, $newrec); } else{ push(@NEW, $line); } } # もしファイルロックされていればエラー終了 if (&is_locked eq true){ &error("エラー", "サーバが混雑しているため、データベースへの書込ができませんでした。時間をおいて再試行してください。"); } # ロックファイル作成 if (!open(OUT, ">$lockfile")){ &error("エラー", "ロックファイルの作成ができません。"); } open(OUT, ">$lockfile"); close(OUT); if (!open(OUT, ">$gplistfile")){ &error("エラー", "グループリストファイルを開けません。"); } print OUT @NEW; close(OUT); &unlock; &done('グループ情報が変更されました。', 'list_groups', $in{'login_id'}, $in{'password'}); exit; } ############################################################ # DB処理:グループ削除 ############################################################ sub gp_delete{ if ($in{'login_id'} eq ''){ &error("エラー", "管理者IDが指定されていません。"); } if ($in{'login_id'} ne $admin_id){ &error("エラー", "管理者IDが間違っています。"); } if (!(&confirm_password($admin_pass, $in{'password'}) eq true)){ &error("パスワードエラー", "パスワードが間違っています"); } if ($in{'gp_id'} eq ''){ &error("エラー", "グループIDが指定されていません。"); } foreach $line(@GPLISTFILE){ ($gp_id, $gp_name, $gp_mode) = split(/\t/, $line); if ($in{'gp_id'} ne $gp_id){ push(@NEW, $line); } } # グループ利用者ファイルからも削除 foreach $line(@GPUSERFILE){ ($user_id, $gp_id, $name, $email, $flg) = split(/\t/, $line); if ($in{'gp_id'} ne $gp_id){ push(@NEW2, $line); $gp_users{$gp_id} .= "$user_id "; } } while (($name, $value) = each(%gp_users)) { $newrec = "$name: $value\n"; push(@NEW3, $newrec); } # もしファイルロックされていればエラー終了 if (&is_locked eq true){ &error("エラー", "サーバが混雑しているため、データベースへの書込ができませんでした。時間をおいて再試行してください。"); } # ロックファイル作成 if (!open(OUT, ">$lockfile")){ &error("エラー", "ロックファイルの作成ができません。"); } open(OUT, ">$lockfile"); close(OUT); if (!open(OUT, ">$gplistfile")){ &error("エラー", "グループリストファイルを開けません。"); } print OUT @NEW; close(OUT); if (!open(OUT, ">$gpuserfile")){ &error("エラー", "グループ利用者ファイルを開けません。"); } print OUT @NEW2; close(OUT); if (!open(OUT, ">$groupfile")){ &error("エラー", "グループファイルを開けません。"); } print OUT @NEW3; close(OUT); &unlock; &done('グループが削除されました。', 'list_groups', $in{'login_id'}, $in{'password'}); exit; } ############################################################ # DB処理:グループ利用者編集 ############################################################ sub gpuser_edit{ if ($in{'login_id'} eq ''){ &error("エラー", "管理者IDが指定されていません。"); } if ($in{'login_id'} ne $admin_id){ &error("エラー", "管理者IDが間違っています。"); } if (!(&confirm_password($admin_pass, $in{'password'}) eq true)){ &error("パスワードエラー", "パスワードが間違っています"); } if ($in{'gp_id'} eq ''){ &error("エラー", "グループIDが指定されていません。"); } # 他グループ分 foreach $line(@GPUSERFILE){ ($user_id, $gp_id, $name, $email, $flg) = split(/\t/, $line); if ($in{'gp_id'} ne $gp_id){ push(@NEW, $line); $gp_users{$gp_id} .= "$user_id "; } } # 自グループ分 foreach $line(@PROFILE){ ($id, $name, $email, $date, $public, $area, $msg) = split(/\t/, $line); if ($check{$id} == 1){ $newrec = "$id\t$in{'gp_id'}\t$name\t$email\t0\n"; push(@NEW, $newrec); $gp_users{$in{'gp_id'}} .= "$id "; } } while (($name, $value) = each(%gp_users)) { $newrec = "$name: $value\n"; push(@NEW2, $newrec); } # もしファイルロックされていればエラー終了 if (&is_locked eq true){ &error("エラー", "サーバが混雑しているため、データベースへの書込ができませんでした。時間をおいて再試行してください。"); } # ロックファイル作成 if (!open(OUT, ">$lockfile")){ &error("エラー", "ロックファイルの作成ができません。"); } open(OUT, ">$lockfile"); close(OUT); if (!open(OUT, ">$gpuserfile")){ &error("エラー", "グループ利用者ファイルを開けません。"); } print OUT @NEW; close(OUT); if (!open(OUT, ">$groupfile")){ &error("エラー", "グループファイルを開けません。"); } print OUT @NEW2; close(OUT); &unlock; &done('グループ利用者情報が変更されました。', 'form_group', $in{'login_id'}, $in{'password'}, $in{'gp_id'}); exit; } ############################################################ # パスワード照合 ############################################################ sub confirm_password{ local($crypted,$password,$p,$c); srand(); $crypted = $_[0]; $password = $_[1]; $p=0; if ($crypted =~ /^\$1\$/){ $p = 3; } if (!eval '$c = crypt($password, substr($crypted,$p,2));') { return false; } else{ if ($c eq $crypted){ return true; } else{ return false; } } } ############################################################ # エラー画面 ############################################################ sub error{ &print_html_header('エラー'); print <<"EOF";

$_[0]

$_[1]

[前の画面]

EOF &print_html_footer; &unlock; exit; } ############################################################ # ロックファイル削除 ############################################################ sub unlock { if (-e $lockfile) { unlink($lockfile); } } ############################################################ # ファイルロックのチェック ############################################################ sub is_locked{ local($i,$filetime); # ファイルロックが解除されるまで待つ for ($i=1;$i<=6;$i++){ if (!(-e $lockfile)) { last; } elsif ($i == 1){ $filetime = (stat($lockfile))[9]; if ($filetime < time() - 10 * 60){ &unlock(); } } elsif ($i >= 6){ return true; } sleep(1); } return false; }