#! /usr/local/bin/perl # # テキストファイルのデータをフォーム画面から更新する  # # id=msgmtn.cgi # # update. 97.10.3 # # &ReadParse命令で、$in{ }の変数にフォーム入力データが格納される require 'cgi-lib.pl'; require 'jcode.pl'; &ReadParse; $file = "/dialup/chichibu/cgi-bin/msg.txt"; $reload = 'http://www0.kumagaya.or.jp/cgi-bin/users/chichibu/msgmtn.cgi'; $bkhmpg = "http://www.kumagaya.or.jp/~chichibu/cgi.html"; # パスワード $password = "password"; #################################### # # # メインルーチン(処理の分岐) # # # #################################### # 全体の流れを決定する(actionやpwdはフォーム入力されたデータを格納する名前) # action=check --> フォーム入力データのチェック処理へ # その他 --> フォーム入力画面へ if ($in{'action'} eq 'check') { ✓ &html; } else { &html; } #################################### # # # フォーム入力画面出力ルーチン # # # #################################### sub html { # ファイルから登録データを読む if (!open(DATA,"$file")) { &error(0); } @msg = ; close(DATA); # 変数$msgに改行コード付きで連結する $msg=""; foreach $key (@msg) { $msg=$msg.$key; } # HTML出力時はタグの無効化 $msg =~ s//>/ig; $msg =~ s///ig; # CGIで出力されたデータをHTMLとして認識させるヘッダの出力 print "Content-type: text/html\n\n"; print 'メッセージファイルの保守 9/30' . "\n"; print ''."\n"; print 'メッセージファイルの保守

' . "\n"; print '

' . "\n"; print '' . "\n"; print ''."\n"; #print '

'; print '

'; print 'パスワード:
' . "\n"; print '
'; print '

' . "\n"; print '

' . "\n"; print '
'; print '戻る

'; print '' . "\n"; } ### sub html end ### ########################################## # # # 入力されたデータのチェックルーチン # # # ########################################## sub check { $msg = $in{'msg'}; # コメントの改行のみをカットする @disp = split(/\n/,$msg); $msg=""; foreach (@disp) { if (length($_) > 1) { $msg=$msg.$_."\n"; } # end of if } # end of foreach # タグの復活 $msg =~ s/<//ig; # パスワードが合わないと更新しません ##if ($in{'pwd'} ne $password) { &error(1) } # チェック通過 &update; # 更新後、再読み込みする print "Location: $reload" . '?' . "\n\n"; exit; } ############################################# # # # チェックエラー表示画面ルーチン    # # # ############################################# sub error { # &error(xx); で呼び出されたルーチンは、()内の数字が $error に代入される。 $error = $_[0]; if ($error eq "0") { $error_msg = 'ファイルがない、またはOPENできない。'; } elsif ($error eq "1") { $error_msg = 'パスワードが合わないと更新しません。'; } print "Content-type: text/html\n\n"; print 'メッセージファイルの保守' . "\n"; print '' . "\n"; print '

メッセージファイルの保守の入力で下記のエラーが発生しました

' . "\n"; print "$error_msg\n"; print '

'; # リロードでもどると入力データが消えてしまうので print 'ブラウザ画面の戻るをクリックする'."\n";; print '
'; print '

' . "\n"; exit; } ########################################## # # # ファイル更新処理           # # # ########################################## sub update { # ファイル登録(書き換え) if (!open(DATA,">$file")) { &error(0); } print DATA $msg; close (DATA); ### sub update end ### } ################### end of script ################