#! /usr/bin/perl # # topdisp.cgi # トップページに更新情報やお知らせを表示させる。 # # 3/4/07 : firefox 2.0の&処理を修正。 # 12/29/05 : firefox 1.5の&処理を修正。cgi-lib.plを削除 # 9/4/05 : jcode.plを削除、クリプトを修正 # 4/24/05 : IE以外のブラウザでの&の処理を修正 # 12/17/04 : &の処理をブラウザごとに別な処理をするように追加 # 12/2/04 : + space変換を削除 # 8/28/04 : e を追加。 # 8/14/04 : editモードを追加。ウェブ上でデータファイルをエディットできるように修正。 # 表示非表示無視モードを追加。 # 8/8/04 : Initial Revision # # $Id: topdisp.cgi,v 1.18 2007/03/04 06:15:07 Hideki Kanayama Exp $ # Copyright(c) 2004-2005 Hideki Kanayama, all rights reserved # # SSIで呼び出す。 # # で起動できます。 # modeのパラメーターはデータファイルの第一カラムの文字列と一致するものであればなんでも # かまいません。 # 各行が
  • で始まる行として表示されます。 # # データファイルのフォーマット # 種類,表示非表示,内容,日付 # 種類の属性 : CGIのパラメータmodeで選択されます。 # event : イベント # notice : お知らせ # update : 更新情報 # admin : 管理人雑記 # 表示非表示の属性 : vin # v : 表示 # i : 非表示 # n : 完全非表示(表示非表示無視モードでも表示されない) # e : 表示打ち切り(display=allでは無視される) # ファイルが大きくなってしまった場合、実行時間を短縮するために「e」以下を # スキャンせずにここでプログラムを終了する。 # 空白行、#で始まる行は無視されます。 # # データファイルの例 # ------------------------------- ## お知らせ #notice,v,現在お知らせはありません。, # ## 更新情報 #update,v,メールアドレスが変更されました。,7/30/04 #update,v,リニューアルしました。,7/3/04 #update,i,住所録が変更されました。,6/20/04 #update,e #update,i,住所録が変更されました。,6/20/04 #update,i,メールアドレスが変更されました。,6/18/04 #update,i,掲示板が新しくなりました。,6/10/04 # ## イベント #event,v,来る15日に飲み会があります。,8/1/04 #event,n,現在更新はありません。 # #--------------------------------- # # エディットモード # topdisp.cgi?edit=onで起動。 # ファイルがそのままテキストで出るので自由にエディットし、「更新」ボタンをクリックすると # データファイルが更新される。同時にデータファイル名も指定できる。 # # 表示非表示無視モード # topdisp.cgi?mode=<[event|notice|update|admin]>&display=all # 指定された種類の内容を全て表示する。データファイル内の第2パラメータ、 # 「v」「i」を無視する。第2パラメータが「n」の行は表示されない。 # このモードはSSIではなく普通にCGIへのリンクで使う事を推奨します。 # use CGI qw(:cgi-lib); use strict; use CGI::Carp qw(fatalsToBrowser); my $admindat = "adminpwd.dat"; my $script = "topdisp.cgi"; my $setupfile = "topdisp_setup.pl"; my $charset = "Shift_JIS"; our $datafile = "topdisp.dat"; if (-e "$setupfile") { require "$setupfile"; } my $agent = $ENV{'HTTP_USER_AGENT'}; my $q = CGI->new; my $cgierror = $q->cgi_error; &error($cgierror) if ($cgierror); my %in = $q->Vars; my %all=&mbdecode(%in); if ($all{admin} eq 'on'){ &wradminpwd; } if (! -e "$admindat"){ &setadminpwd; } if ($all{edit} eq 'on'){ &dispedit; } elsif ($all{edit} eq 'write'){ &dispwrite; } else { &display; } sub dispedit { print $q->header({-type=>'text/html', -charset=>$charset}); my $referer; if ($all{referer} eq ''){ $referer = "$ENV{HTTP_REFERER}"; } else { $referer = $all{referer}; } if ($all{pwd} eq ''){ print <
    管理人パスワードを入力してください。
    END exit; } open(FILE,"< $admindat"); my $adminpwd = ; close(FILE); if (crypt($all{pwd},$adminpwd) ne "$adminpwd") { print <
    パスワードが違います。
    END exit; } print <

    データファイル編集

    データファイル名

    END if ($all{dironly} ne 'on'){ open(FILE,"< $datafile") || "

    $datafileが開けません
    \n"; print <
    \n"; close(FILE); } print < END2 } sub dispwrite { open (FILE, "> $setupfile") || "セットアップファイル$setupfileを作成できません。\n"; print FILE < $all{datafile}") || "データファイル$all{datafile}を作成できません。\n"; print FILE $all{contents}; close(FILE); } print "Content-Type: text/html\n\n"; print "
    データファイル$datafileを更新しました。
    元のページに戻る
    \n"; } sub display { print $q->header({-type=>'text/html',-charset=>$charset}); if (open(FILE,"< $datafile")) { if ($all{mode} eq ''){ print "SSIとして呼び出してmode=<event>を指定してください
    \n"; print "例:<!--#include virtual=\"$script?mode=event -->
    \n"; } else { while (){ s/[\n\r]*$//; /^[ ]*\#*$/ && next; my ($attribute,$visible,$main,$date)=split(/,/); if (("$attribute" eq "$all{mode}") && ("$visible" eq 'e')){ if ("$all{display}" eq 'all') {next;} else {last;} } if ((("$attribute" eq "$all{mode}") && (("$visible" eq 'v') || (("$all{display}" eq 'all') && ("$visible" ne 'n'))))){ my $dispdate = ''; if ($date ne ''){ $dispdate = "($date)"; } print "
  • $main$dispdate\n"; } } } close(FILE); exit; } else { print "
    $datafileが開けません
    \n"; print "データファイルを作成する
    \n"; print "データファイルを作成せずにファイル名のみを変更する
    \n"; } } sub mbdecode { my (%in) = @_; my ($key,$value); while (($key,$value)=each %in){ $value =~ s/\r\n/\n/g if ($key eq 'contents'); $in{"$key"}=$value; } return(%in); } 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 { print $q->header({-type=>'text/html',-charset=>$charset}); print "\n"; print "\n"; print "\n"; print "\n"; print "管理者用パスワード\n"; print "\n"; print "\n"; print "
    \n"; print "
    管理者用パスワードを設定してください。
    \n"; print "\n"; print "\n"; print "\n"; print "
    \n"; print "\n"; exit; } sub wradminpwd { my $passwd = &makecrypt($all{pwd}); if (open(FILE,"> $admindat")){ print FILE "$passwd"; close(FILE); } else { print $q->header({-type=>'text/html',-charset=>$charset}); print "\n"; print "\n"; print "\n"; print "\n"; print "パスワードファイル作成に失敗しました\n"; print "\n"; print "\n"; print "パスワードファイル作成に失敗しました。"; print "\n"; exit; } }