def regist
error("不正なアクセスです") if $postonly == 1 && $post_flag == 0
refCheck if $baseUrl != ''
no_wd if $no_wd != ''
jp_wd if $jp_wd == 1
urlnum if $urlnum > 0
err = ''
err = err + "名前が入力されていません<br>" if $in['name'] == ""
err = err + "コメントが入力されていません<br>" if $in['comment'] == ""
err = err + "Eメールの入力内容が不正です<br>" if $in['email'] != '' && $in['email'] !~ /^[\w\.\-]+\@[\w\.\-]+\.[a-zA-Z]{2,6}$/
error(err) if err != ''
$in['url'] = '' if $in['url'] == "http://"
$in['sub'] = '無題' if $in['sub'] == ""
io = open($logfile, "r+")
log = io.readlines
(no,dat,nam,eml,sub,com,url,hos,pw,tim) = log[0].split(/<>/)
if $in['name'] == nam && $in['comment'] == com
io.close
error("二重投稿は禁止です");
end
t = Time.now
time = t.to_i
flg = 0
if $regCtl == 1
flg = 1 if $host == hos && time - tim.to_i < $wait
elsif $regCtl == 2
flg = 1 if time - tim.to_i < $wait
end
if flg == 1
io.close
error("現在投稿制限中です。もうしばらくたってから投稿をお願いします");
end
no = no.to_i + 1
wk = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat']
date = sprintf("%04d/%02d/%02d(%s) %02d:%02d:%02d", t.year, t.month, t.day, wk[t.wday], t.hour, t.min, t.sec)
log.pop while log.size >= $max
io.rewind
io.print "#{no}<>#{date}<>#{$in['name']}<>#{$in['email']}<>#{$in['sub']}<>#{$in['comment']}<>#{$in['url']}<>#{$host}<>#{$pwd}<>#{time}<>\n"
io.print log
io.truncate(io.pos)
io.close
end
def refCheck
ref = ENV['HTTP_REFERER']
ref = ref.gsub(/((?:%[0-9a-fA-F]{2})+)/n) do
[$1.delete('%')].pack('H*')
end
end
def no_wd
flg = 0
$no_wd.split(/,/).each {|l|
flg = 1 if $in['name'].index(l)
flg = 1 if $in['comment'].index(l)
}
error("禁止ワードが含まれています") if flg == 1
end
def jp_wd
if $in['comment'] !~ /[\x81-\x9F\xE0-\xFC][\x40-\x7E\x80-\xFC]/
error("コメントに日本語が含まれていません")
end
end
def urlnum
if $urlnum < $in['comment'].scan("http").length
error("コメント中のURLアドレスは最大#{$urlnum}個までです")
end
end