#!/usr/bin/perl
#───── bookmark Ver.3 ─────
# 個人で使用する場合の改造は構いませんが、再配布する場合は連絡をして下さい。
# バグ等、何かありましたら、サイト内にあるサポート掲示板までお願いします。
# lockフォルダはお手数ですが、各自で作成して一緒にアップして下さい。
# 設置に関してはHPで説明していますので、そちらを参照して下さい。
#───── パーミッション ─────
# 必ずプロバイダーの指示に従って下さい。
# 特に指定がなければ下の通りにして下さい。
# bookmark.cgi [755]
# bookmark2.cgi [666]
# jcode.pl [644]
# lock [777]←排他制御用フォルダ。mkdir関数使用時のみ必要です
# ───── 初期設定 ─────
# CGIファイル
$cgifile = './link.cgi';
# 記録ファイル
$logfile = './bookmark2.cgi';
# 戻り先のURL
$home='../index.html';
# タイトル
$title = 'リンク集';
# タイトルの文字の大きさ(単位なし)
$size = "6";
# タイトルの文字色
$color = "#9999ff";
# タイトル画像のURL
# 使わない場合は「$title_img = '';」と設定して下さい
$title_img = '';
# 登録サイト表示欄の横幅(単位は%)
$width = '99%';
# 登録サイト表示欄の背景色
$t_bgcolor = '#ffffff';
# カテゴリーの表示方法
# セレクトボックスで表示=1、横1列で表示=0
$c_select = '1';
# bodyタグ
$body = '
';
# 最大記事保存数(超過すると「登録出来ません」というメッセージが出ます)
$max = '1000';
# 最大記事表示数(管理モードで反映されます)
$pagemax = '100';
# 管理用パス(必ず設定して下さい)
$adpass = 'gvq6mwh6';
# 排他制御(ファイルロック)の設定
# flock関数を使う=2、mkdir関数を使う=1、使わない場合=0
# flock関数でエラーが発生した場合は、mkdir関数を御使用下さい。
# 「混雑しています」が度々表示される場合は外して下さい
# mkdir関数を使う場合は必ずlockフォルダを一緒にアップして下さい
$filelock = '2';
# ファイルロックの名称(mkdir関数を使う場合に必要。変更の必要なし)
$lockdir = './lock/bookmark.lock';
# アクセスを制限したいIP、またはホストを記述して下さい
# IPの場合、"123.456.78.90"を"123.456.78.*"と変えて記述します
# ホストの場合、"popxx.garden.ne.jp"を"*.garden.ne.jp"と変えて記述します
# 例→@stop = ("123.456.78.*","*.garden.ne.jp");
@stop = ("");
# スタイルシート(判る方は自由に変更して下さい)
# 「h1」はカテゴリー表示欄の部分(背景色、文字の大きさ、文字色等)、
# 「h2」は新規投稿画面、エラー表示画面、管理モード等の見出しの部分、
# 「ts」は枠線、「bs」はボタン、記入欄等を設定しています。
$style = '';
# 日本語コード変換ライブラリ(変更の必要なし)
require './jcode.pl';
# ───── 初期設定ここまで! ─────
$hos = $ENV{'REMOTE_HOST'};
$addr = $ENV{'REMOTE_ADDR'};
if ($gethostbyaddr) {
if ($hos eq "" || $hos eq "$addr") {
$hos = gethostbyaddr(pack("C4", split(/\./, $addr)), 2);
}
}
if ($hos eq "") { $hos = $addr; }
foreach $ipline (@stop) {
if ($ipline eq "") { next;}
s/\*/\.\*/g;
if ($hos =~ /$ipline/i) { &error("アクセスが制限されています");}
if ($addr =~ /$ipline/i) { &error("アクセスが制限されています");}
}
&get_time;
if ($ENV{'REQUEST_METHOD'} eq "POST") {
read(STDIN, $buf, $ENV{'CONTENT_LENGTH'});
} else { $buf = $ENV{'QUERY_STRING'}; }
@buf = split(/&/, $buf);
foreach (@buf) {
($key, $val) = split(/=/);
$val =~ tr/+/ /;
$val =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
&jcode'convert(*val, "sjis");
$val =~ s/</g;
$val =~ s/>/>/g;
$val =~ s/"/"/g;
$val =~ s/,/,/g;
$in{$key} = $val;
}
$header2 = "
\n";
print "$category\n";
print "\n";
foreach $newline(@data) {
local($site,$url,$name,$comment,$date,$no) = split(/<>/,$newline);
if ($g_flag == $no ) {
$site = " $site";
print "$site\n";
print " $comment $name \n";
}
}
print " \n";
}
#print " \n";
print "$fotter\n";
exit;
sub header {
print <<"EOM";
Content-type: text/html
セレスホームソウワ
かすみがうら市の地域密着型の工務店。注文住宅からローコスト住宅まで丁寧に対応します
リンク
$body
EOM
if ($title_img ne "") {
print " \n";
} else {
# print " $title\n";
}
# print " \n";
}
sub check {
if ($in{'site'} eq "") { &error("サイト名が記入されていません"); }
if ($in{'url'} eq "http://") { &error("URLが記入されていません"); }
if (($in{'url'} eq "") || ($in{'url'}!~ /http:\/\/.+\..+/)) { &error("URLが正しく入力されていません"); }
$in{'comment'} =~ s/\r\n/ /g;
$in{'comment'} =~ s/\r/ /g;
$in{'comment'} =~ s/\n/ /g;
}
sub regist {
local($site,$url,$name,$comment,$date,$no,$data2,@data,@new);
if (($in{'adpass'} ne $adpass) || ($in{'adpass'} eq "")) { &error("パスワードが違います"); }
✓
if ($filelock == 1){ &lock;}
&input;
&get_time;
$max ++;
while ($max <= @data) { &error("登録の出来る限度数を超えているため、登録が出来ません"); }
$data2 = ();
@new = ();
for ($i = 0; $i < @data; $i++) {
if ($i == 0 ) { $data2 = $data[0];}
else { push(@new,$data[$i]);}
}
unshift(@new,"$in{'site'}<>$in{'url'}<>$in{'name'}<>$in{'comment'}<>$date<>$in{'no'}<>\n");
unshift(@new,"$data2");
if ($filelock ==2 ) {
open(OUT, "+< $logfile");
flock(OUT, 2);
truncate(OUT, 0);
seek(OUT, 0, 0);
print OUT @new;
close(OUT);
} else {
open(OUT,">$logfile") || &error ('ファイルオープンエラー');
print OUT @new;
close(OUT);
}
if ($filelock == 1){ &unlock;}
&password("サイトの登録が完了しました");
}
sub regist2 {
local($site,$url,$name,$comment,$date,$no,@data);
if (($in{'adpass'} ne $adpass) || ($in{'adpass'} eq "")) { &error("パスワードが違います");}
✓
if ($filelock == 1){ &lock;}
&input;
$r_cnt = 0;
for ($i = 1; $i < @data; $i++) {
local($site,$url,$banner,$comment,$date,$no) = split(/<>/,$data[$i]);
$r_cnt ++;
if ($in{'e_cnt'} == $r_cnt) {
$data[$i] = "$in{'site'}<>$in{'url'}<>$in{'name'}<>$in{'comment'}<>$in{'date'}<>$in{'no'}<>\n";
}
}
&output;
if ($filelock == 1){ &unlock;}
&password("修正処理が完了しました");
}
sub regist3 {
local($site,$url,$banner,$comment,$date,$no,$s_cnt,$newline,$genre,@data,@new);
if (($in{'adpass'} ne $adpass) || ($in{'adpass'} eq "")) { &error("パスワードが違います"); }
if ($in{'genre'} eq "") { &error("カテゴリーが設定されていません"); }
if ($filelock == 1){ &lock;}
&input;
$in{'genre'} =~ s/ / /g;
$in{'genre'} =~ s/ /<>/g;
for ($i = 1; $i < @data; $i++) { push(@new,$data[$i]);}
@data = ();
unshift(@new,"$in{'genre'}\n");
&output2;
if ($filelock == 1){ &unlock;}
&password("カテゴリーの編集が完了しました");
}
sub delete {
local($site,$url,$name,$comment,$date,$no,@data);
if (($in{'adpass'} ne $adpass) || ($in{'adpass'} eq "")) { &error("パスワードが違います");}
if ($in{'e_cnt'} eq "") { &change;}
if ($filelock == 1){ &lock;}
&input;
$d_cnt = 0;
foreach $lines (@data) {
local($site,$url,$name,$comment,$date,$no) = split(/<>/,$lines);
if ($d_cnt != $in{'e_cnt'}) { push(@new,$lines); }
$d_cnt ++ ;
}
unshift(@new,$genre2);
&output2;
if ($filelock == 1) { &unlock;}
&password("削除処理が完了しました");
}
sub change {
local($site,$url,$name,$comment,$date,$no,$e_cnt,$end,@data);
if (($in{'adpass'} ne $adpass) || ($in{'adpass'} eq "")) { &error("パスワードが違います");}
if ($filelock == 1){ &lock;}
&input;
if ($filelock == 1){ &unlock;}
for ($i = 0; $i < @data; $i++) {
chomp $data[0];
@genre = split(/<>/,$data[0]);
}
print <<"EOM";
Content-type: text/html
$header2
サイト情報の編集
EOM
if ($in{'start'} eq '') { $in{'start'} = 1; }
$end = $in{'start'} + $pagemax;
$pre = $in{'start'} - $pagemax;
if ($end > @data) { $end = @data; }
$e_cnt = 0;
for ($i = $in{'start'}; $i < $end; $i++) {
local($site,$url,$name,$comment,$date,$no) = split(/<>/,$data[$i]);
$e_cnt ++;
$comment =~ s/ /\r\n/g;
$comment =~ s/ /\r/g;
$comment =~ s/ /\n/g;
print "\n";
print "
\n";
}
print " \n";
if (($in{'start'} != 1) || ($end < @data)) {
print "\n";
}
print " | \n";
print " $fotter\n";
exit;
}
sub form {
if (($in{'adpass'} ne $adpass) || ($in{'adpass'} eq "")) { &error("パスワードが違います"); }
if ($filelock == 1){ &lock;}
&input;
if ($filelock == 1){ &unlock;}
for ($i = 0; $i < @data; $i++) {
chomp $data[0];
@genre = split(/<>/,$data[0]);
last;
}
print <<"EOM";
Content-type: text/html
$header2
\n";
print "$fotter\n";
exit;
}
sub password {
print <<"EOM";
Content-type: text/html
$header2
\n";
print "$fotter\n";
exit;
}
sub category {
local($cate,@data);
if (($in{'adpass'} ne $adpass) || ($in{'adpass'} eq "")) { &error("正しい管理用パスワードを入力して下さい"); }
if ($filelock == 1){ &lock;}
&input;
if ($filelock == 1){ &unlock;}
for ($i = 0; $i < @data; $i++) {
chomp $data[0];
@cate = split(/<>/,$data[0]);
last;
}
$cate = ~s/<>/ /g;
print <<"EOM";
Content-type: text/html
$header2
$fotter
EOM
exit;
}
sub search {
local($site,$url,$banner,$comment,$date,$no,$s_top,$s_flag,@data,@s_data,@newdata);
if ($in{'word'} eq "" ) { &error('検索したい語句を入力して下さい');}
if (length($in{'word'}) >= 200 ) { &error('これ以上長い語句は検索出来ません'); }
$in{'word'} =~ s/ / /g;
@words = split(/\s+/, $in{'word'});
if ($filelock == 1){ &lock;}
@s_data=();
open(IN,"$logfile") || &error ('ファイルオープンエラー');
if ($filelock ==2 ) {
eval{ flock(IN2, 1);};
if ($@) { &error('flock関数は使用出来ません。mkdir関数に設定して下さい');}
}
$top = ;
while () {
$s_flag=0;
foreach $s_line (@words) {
if (index($_,$s_line) >= 0) {
$s_flag=1;
if ($in{'s_flag1'} == 1) { last; }
} else {
if ($in{'s_flag1'} == 0) { $s_flag = 0; last; }
}
}
if ($s_flag == 1) { push(@s_data,$_); }
}
close(IN);
$s_top = 1;
&header;
print "
\n";
print "\n";
$count2 = @s_data;
if ($count2 == 0 ) {
print "\n";
print "該当するサイトは見つかりませんでした\n";
print " |
---|
\n";
print "
\n";
print " $fotter\n";
} else {
print "\n";
print "該当するサイトは$count2件です\n";
print " | \n \n | \n";
print "\n";
foreach (@s_data) {
local($site,$url,$name,$comment,$date,$no) = split(/<>/,$_);
$site = "$site";
if ($name ne "") {$name = "[管理人:$name 様]";}
print "$site | \n";
print "$comment $name | \n";
}
print " \n | \n";
print " \n";
print " $fotter\n";
}
exit;
}
sub input {
if ($filelock ==2 ) {
open(IN,"$logfile") || &error ('ファイルオープンエラー');
eval{ flock(IN, 1);};
if ($@) { &error('flock関数は使用出来ません。mkdir関数に設定して下さい');}
@data = ;
close(IN);
} else {
open(IN,"$logfile") || &error ('ファイルオープンエラー');
@data = ;
close(IN);
}
}
sub output {
if ($filelock ==2 ) {
open(OUT, "+< $logfile");
flock(OUT, 2);
truncate(OUT, 0);
seek(OUT, 0, 0);
print OUT @data;
close(OUT);
} else {
open(OUT,">$logfile") || &error ('ファイルオープンエラー');
print OUT @data;
close(OUT);
}
}
sub output2 {
if ($filelock ==2 ) {
open(OUT, "+< $logfile");
flock(OUT, 2);
truncate(OUT, 0);
seek(OUT, 0, 0);
print OUT @new;
close(OUT);
} else {
open(OUT,">$logfile") || &error ('ファイルオープンエラー');
print OUT @new;
close(OUT);
}
}
sub get_time {
$ENV{'TZ'} = "JST-9";
local($sec,$min,$hour,$mday,$mon,$year,$wday) = localtime(time);
local(@week) = ('sun','mon','tue','wed','thu','fri','sat');
$wday = $week[$wday];
$date = sprintf("%04d/%02d/%02d (%s) %02d:%02d", $year+1900,$mon+1,$mday, $wday,$hour,$min);
}
sub lock {
if (-e $lockdir ) {
local($checktime) = (stat($lockdir))[9];
if (($date - $checktime ) > 120) { rmdir($lockdir); }
}
$retry = 5;
while (!mkdir($lockdir, 0755)) {
if (--$retry <= 0) { &error("混雑しています。時間をあけてアクセスして下さい"); }
sleep(1);
}
}
sub unlock {
rmdir($lockdir);
}
sub error {
print <<"EOM";
Content-type: text/html
$header2
$fotter
EOM
exit;
}
|