最終更新: 2014-12-05T17:23+0900
送信元が限られてるのかワンパタ
フ
コメントフ
tDiary-2.3.3.20091124にインスト
連投対策。同じ IPアドレスからの連続する投稿をはじく。30分につき 3件までしか許可しない、など。
# coding: utf-8 # # limit_freq.rb: # # a spam-filtering plugin of tDiary # rejects frequent comments posted from an IP address. module TDiary::Filter class LimitFreqFilter < Filter def comment_filter( diary, comment ) now = Time.now.to_i comment_i = Comment_t.new( now, @cgi.remote_addr ) # 数値形式の日時と文字列形式の IPアドレスの二要素 # 配列の配列を、日時をもとに昇順にソートしたもの。 # log = [[123456, "1.2.3.4"], [234567, "5.6.7.8"],...] log = [] require 'pstore' ps = PStore.new( cache_path ) ps.transaction( false ) { |db| log = db.fetch( DBRoot, log ) # 新しいコメントを logに追加する。 log.insert( ArrayExtension.lower_bound(log){|pair| pair.first - comment_i.time }, [comment_i.time, comment_i.ipaddr] ) # 古い logを捨てる。 oldest = now - time_span log.slice!( 0 ... ArrayExtension.lower_bound(log){|pair| pair.first - oldest } ) db[DBRoot] = log db.commit } # 残った logに投稿者の IPアドレスがいくつ含まれるか数え、 # その数が閾値を超えていないか確かめる。 count = 0 if log.all?{|pair| count += 1 if pair.last == comment_i.ipaddr count < threshold } then return this_is_not_a_spam( comment ) else debug("limit_freq.rb: spam: the # of comments posted from #{comment_i.ipaddr} exceeds threshold:#{threshold} within the last #{time_span.to_i}seconds.") return this_is_a_spam( comment ) end rescue debug("limit_freq.rb: BUG: #{$!}") return this_is_not_a_spam( comment ) end private DBRoot = 'LimitFreqLog' Comment_t = Struct.new(:time, :ipaddr) def cache_path return File.join( (@conf.cache_path || "#{@conf.data_path}cache"), 'limit_freq.data' ) end # どれだけの期間(秒単位)、コメントの投稿頻度の判定に # 利用するログ(日時とIPアドレスのペア)を保存するか。 def time_span 30 * 60 end # time_span当たり、何件目の投稿からを拒否するか。 def threshold 4 end module ArrayExtension # ソート済みだという前提を活かしていない! def lower_bound( arr, &block ) index = 0 arr.length.times{ return index if 0 <= yield( arr[index] ) index += 1 } return index end module_function :lower_bound end end end
やめればいいのに本体もち
Index: core/tdiary.rb =================================================================== --- core/tdiary.rb (リビジョン 44436) +++ core/tdiary.rb (作業コピー) @@ -342,6 +342,22 @@ @logger.info("#{@cgi.remote_addr}->#{(@cgi.params['date'][0] || 'no date').dump}: #{msg}") end + + private + # config: hide or drop spam comment + def hide_spam? + return @conf.options.include?('spamfilter.filter_mode') && @conf.options['spamfilter.filter_mode'] + end + + def this_is_a_spam( comment ) + comment.show = false + return hide_spam? + rescue + return false # comment could be a String(@cgi.referer). + end + def this_is_not_a_spam( comment ) + return true + end end end @@ -1303,7 +1319,7 @@ filter_path = @conf.filter_path || "#{PATH}/tdiary/filter" Dir::glob( "#{filter_path}/*.rb" ).sort.each do |file| require file.untaint - @filters << TDiary::Filter::const_get( "#{File::basename( file, '.rb' ).capitalize}Filter" )::new( @cgi, @conf, @logger ) + @filters << TDiary::Filter::const_get( "#{File::basename( file, '.rb' ).split(/[-_]+/).map{|x|x.capitalize}.join('')}Filter" )::new( @cgi, @conf, @logger ) end end Index: core/plugin/60sf.rb =================================================================== --- core/plugin/60sf.rb (リビジョン 44436) +++ core/plugin/60sf.rb (作業コピー) @@ -4,10 +4,9 @@ # Modified by KURODA Hiraku. SF_PREFIX = 'sf' -@sf_path = ( @conf["#{SF_PREFIX}.path"] || "#{::TDiary::PATH}/misc/filter" ).to_a -@sf_path = @sf_path.collect do |path| - /\/$/ =~ path ? path.chop : path -end +@sf_path = ( @conf["#{SF_PREFIX}.path"] || "#{::TDiary::PATH}/misc/filter" ).to_a.map{|path| + path.chomp('/') +} # get plugin option def sf_option( key ) @@ -128,7 +127,7 @@ if File.readable?( path ) then begin require path - @sf_filters << TDiary::Filter::const_get("#{File::basename(filename, ".rb").capitalize}Filter")::new(@cgi, @conf, @logger) + @sf_filters << ::TDiary::Filter::const_get("#{File::basename(filename, ".rb").split(/[-_]+/).map{|x|x.capitalize}.join('')}Filter")::new(@cgi, @conf, @logger) plugin_path = "#{dir}/plugin/#{filename}" load_plugin(plugin_path) if File.readable?(plugin_path) rescue Exception
一件二件すり抜けるぐらいはいいかと思
spamコメントがくる月
spamコメントの目的が特定の URLへの誘導であるかぎりは、コメントに含まれる URLのドメインが白か黒かを判定する方法が有効でし
ここで上記の comment-keyフ
plugin/00default.rbに含まれるメソ
def navi_item( link, label, rel = nil ) rel = "nofollow" if rel == true # backward compatibility
スパムコメント一掃のために YYYYMM.tdcを削除したけど日記の編集画面からコメントが消えない。YYYYMM.parserを開くとコメントが含まれていたし、これを削除すると編集画面からもコメントが消えた。原因はデ
最終更新: 2010-03-08T01:18+0900
や
っぱり、全画面表示にしていてもエクスプロ ーラ ーが隠れてしまわない、 っていうのが一番便利な点だと思います。 基本的にフ
http://www.haijin-boys.com/weblog/index.php?fuseaction=discussions.replies&discussion_id=4b7556ba877cd8.90673501ァイルをいろいろ開きまくるタチですから、タブとエクスプロ ーラ ー的なものは結構重要だ ったりしますw
自分もエクスプロ
それでも反論はある。
例えば、Vistaのフ
アドレス欄 > 検索欄 > 状況に応じて変化するツールバー > リストビュー > カラム > (アドレス欄に戻る)
肝心要のリストビ
キ
脱線。カラムクリ
最終更新: 2010-03-08T20:41+0900
長
「親機のボタンを押すことでも設定できます(という意味のメ
それでも問題はあるわけで。
既存の設定済みの Buffaloの無線ル
現実には 1と 2の間には「あれ、おかしいな」という疑問のぐるぐるする時間があり、2の行動に根拠はなく、問題が起こ
タスクマネ
子機のセキ
最終更新: 2010-02-26T20:42+0900
いやはや、数字を数えるのも難しいものですよ。 {}の次が{{}}で、その次が{{},{{}}}で、次に{{},{{}},{{}, {{}}}}くらいまでは、すぐに分かりますが、 数学が苦手な私には、その次の{{},{{}},{{},{{}}},{{},{{}}, {{},{{}}}}}はなかなか出てこないですねぇ。
こういう話をかみ砕いて順々に展開してい
1、2週間前の大雨の日に乗
最終更新: 2010-02-26T19:22+0900
当たり前のことを書こう。1) const int* と int* const. ポインタが constなのは後者でポインタの指す対象が constなのが前者。2) const char* と char*はどちらもポインタ型だけど、int*と char*ぐらい違う型だと認識すべき。const_castや reinterpret_castが使えるという点で、関数ポインタやメンバ関数ポインタとその他のポインタを比べたときほど違いはしないようだが。ついでに、関数ポインタのサイズ以上の落とし穴を最近知
constで検索したら建設関係ば
Vistaで Media Player Classicが Windows Updateのあとエラ
Alt+Spaceでシステムメニ
水を差す。これまでにためたポイントを使
恨みがあるわけじ
レジ袋に関して。断
最終更新: 2010-02-12T00:42+0900
一級と特級はや