#!/usr/local/bin/perl # ###################################################################### ### ### ### CGI簡易チャット TchaT Ver.2.10 ### [1/1] 本体 (tchat.cgi) ### (c) 1996-2000 Takahiro Nishida ### http://www.mytools.net/ ### ### ###################################################################### # ### 変数設定部 (詳細は上記ページをご覧下さい) ###################### # データファイルの入っているディレクトリ $basedir = "."; # 拡張子 $ext = "cgi"; # 文字コード $code = "sjis"; # フォームの送信方法 $method = "post"; # 管理パスワード $password = "fsefseawdfweaqw"; # 管理者メールアドレス $admin_email = "your\@email.address"; ##### 以下は表示のカスタマイズ ##### # 仮ログ最大保存行数 $maxlines = 100; # 最初の表示行数 $defaultlines = 20; # URLを入力したときリンクになる文字 $linkcharacter = "★"; # 選択可能な表示行数(1以上$maxlines未満) @lines_list = (10, 20, 30, 50 ,$maxlines); # 入力欄を複数行にするか $multirow_input_form = 1; # フォームの横サイズ $input_form_size = 60; # クッキーにURLも覚えさせるか $enable_cook_url = 0; ### 名前色リスト # $CT[x] ... 実際の色 # $CN[x] ... リストに表示する色の名前 $CT[0] = '#000000'; $CN[0] = "くろ"; $CT[1] = '#FF0000'; $CN[1] = "あか"; $CT[2] = '#0000FF'; $CN[2] = "あお"; $CT[3] = '#A52A2A'; $CN[3] = "ちゃいろ"; $CT[4] = '#008000'; $CN[4] = "みどり"; $CT[5] = '#800080'; $CN[5] = "むらさき"; $CT[6] = '#00008B'; $CN[6] = "こん"; $CT[7] = '#696969'; $CN[7] = "グレイ"; # 標準時とのズレ(時間) $time_fix = 0; # 標準のROOM名 $default_room = ""; # スクリプトの名前 $script_name = "tchat"; # クッキーのPATHの設定/非設定 $enable_cookiepath = 1; # クッキーの有効期限(日) $cookie_valid = 30; # ログ保存先ディレクトリ $logdir = ""; # ログのURL $logurl = ""; ###(変数設定部)ここまで######################################### require './jcode.pl'; $lockfile = "$basedir/lockdir/tc.lock"; $verno="2.10"; &main; sub main{ &lock; &init_variables; &check_input; &open_datafile; &check_password; &add_newdata; &update_datafile; &deal_cookie; &show_html; &unlock; } ##### 大域変数の初期化 sub init_variables{ $date_now = &get_time(time); $remote_host = $ENV{'REMOTE_HOST'}; $update_flag = 0; } ##### 入力のチェック sub check_input{ if ($ENV{'REQUEST_METHOD'} eq "POST"){ read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); } else{ $buffer = $ENV{'QUERY_STRING'}; } @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($vn, $value) = split(/=/, $pair); $F{$vn} .= $value; } $room = $F{'room'} || $default_room || &error(4); $lines = $F{'lines'}; $cname = &decode($F{'cname'}); $clrno = $F{'clrno'}; $chat = &decode($F{'chat'}); $url = &decode($F{'url'}); $pwd = $F{'pwd'}; ($room =~ /^\w+$/) || &error(4); ($lines =~ /^\d+$/) || ($lines = $defaultlines); ($clrno =~ /^\d+$/) || ($clrno = 0); (!$url) || ($url =~ /^http:\/\/.+$/) || ($url = "http://"); # ログを一切残したくない場合は、下の2行の頭の # を取ってください。 # $logselect = "CHECKED"; # $F{'nolog'} = 1; } ##### データファイルのオープン sub open_datafile{ $datafile = "$basedir/$room.txt"; (-f $datafile) || &error(5, $room); open(FILE, "$datafile") || &error(1, $datafile); @datas = ; close(FILE); if (@datas < 5){ $title = "<TITLE>〜</TITLE>の間に書くもの\n"; $mtitle = "

見出し。タグ使用可。

\n"; $colormap = "\n"; $comment = "見出しの下に書く説明文。タグ使用可。\n"; $backurl = "[戻る]を押したときどのページに戻るか\n"; $F{'admmode'} = 1; $admselect = "CHECKED"; &clear_log(); $update_flag = 1; } else{ ($title, $mtitle, $colormap, $comment, $backurl) = splice(@datas, 0, 5); } } ##### 管理モードの実行 sub check_password{ ($pwd eq $password) || return; $colormap = &decode($F{'newcolor'})."\n"; $title = &decode($F{'atitl'})."\n"; $mtitle = &decode($F{'amtit'}, 1)."\n"; $comment = &decode($F{'acomm'}, 1)."\n"; $backurl = &decode($F{'aback'})."\n"; ($F{'logclr'}) && &clear_log ; $update_flag = 1; } ##### 全ログのクリア sub clear_log{ $logfile = "$basedir/log-$room.html"; @cls = split(",", &decode($colormap)); $cback = $cls[0] || "#FFE4C4"; $cfont = $cls[1] || "#000000"; $clink = $cls[4] || "#3300CC"; open(FILE, ">$logfile") || &error(2, $logfile); print FILE "TchaT log file ($room)\n"; print FILE "\n"; print FILE "

$room ログファイル $date_now〜

\n"; print FILE "[Back]
\n"; close(FILE); @datas = (); } ##### 新しいデータの追加 sub add_newdata{ ($chat && $cname) || return; if($url && $url ne 'http://'){ $linkto="$linkcharacter"; } $newdata = "[$date_now] $cname : $linkto $chat
\n"; while(@datas > $maxlines - 1){ pop(@datas); } unshift(@datas, $newdata); $update_flag = 1; } ##### データファイルの更新 sub update_datafile{ return unless ($update_flag); open(FILE, ">$datafile") || &error(2, $datafile); print FILE $title.$mtitle.$colormap.$comment.$backurl; print FILE @datas; close(FILE); ### 「ログを残さない」がチェックされていたらここで終わり ($F{'nolog'}) && return; ($logdir) || ($logdir = $basedir); $logfile = "$logdir/log-$room.html"; open(FILE,">>$logfile") || &error(2, $logfile); print FILE $newdata; close(FILE); } ##### 表示 sub show_html{ local($htmlbuf); @cls = split(",", &decode($colormap)); $cback = $cls[0] || "#FFE4C4"; $cfont = $cls[1] || "#000000"; $ctbac = $cls[2] || "#FFCCFF"; $ctfon = $cls[3] || "#000000"; $clink = $cls[4] || "#3300CC"; ### 表示行の選択リスト for(0..$#lines_list){ $line_options .= "