~ubuntu-branches/ubuntu/saucy/tdiary/saucy-proposed

« back to all changes in this revision

Viewing changes to tdiary/filter/spamlinkcheck.rb

  • Committer: Bazaar Package Importer
  • Author(s): Daigo Moriwaki
  • Date: 2011-04-11 21:53:16 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20110411215316-ih4gt4q8p29d2wf8
Tags: 3.0.1-1
* New upstream release (Closes: #542801, #594947)
* debian/control:
 - Bumped up Standards-Version to 3.9.1.
 - Updated version dependency.
* debian/tdiary-setup.rb: Followed the upstream changes, incorporating js and
  index.fcgi

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#
2
 
# linkcheck.rb: tDiary filter for checking link to my site in TrackBack source site.
3
 
#
4
 
# specification:
5
 
#    * if source site has no URI of my site of top page, it's spam!
6
 
#    * reading only top of 100KB of source site.
7
 
#    * no response over 10 sec, it's mybe spam.
8
 
#
9
 
# Copyright (C) 2007 by TADA Tadashi <sho@spc.gr.jp>
10
 
# Distributed under GPL2.
11
 
#
12
 
 
13
 
require 'open-uri'
14
 
require 'timeout'
15
 
 
16
 
module TDiary::Filter
17
 
        class SpamlinkcheckFilter < Filter
18
 
                def initialize( *args )
19
 
                        super( *args )
20
 
                        @filter_mode = @conf['spamfilter.filter_mode']
21
 
                        @filter_mode = true if @filter_mode == nil
22
 
                end
23
 
 
24
 
                def comment_filter( diary, comment )
25
 
                        if @conf['spamfilter.linkcheck'] == 0 then
26
 
                                debug( "No linkcheck to TrackBacks.", DEBUG_FULL )
27
 
                                return true
28
 
                        end
29
 
                
30
 
                        # check only TrackBack
31
 
                        return true unless comment.name == 'TrackBack'
32
 
 
33
 
                        dest_uri = @conf.index.dup
34
 
                        dest_uri[0, 0] = @conf.base_url if %r|^https?://|i !~ @conf.index
35
 
                        dest_uri.gsub!( %r|/\./|, '/' )
36
 
 
37
 
                        # TrackBack URI is the 1st line of comment.body.
38
 
                        src_uri, = comment.body.split( /\n/ )
39
 
                        unless %r|^https?://|i =~ src_uri then
40
 
                                debug( "TrackBack has bad source URI." )
41
 
                                comment.show = false
42
 
                                return @filter_mode
43
 
                        end
44
 
                        if src_uri.index( dest_uri ) == 0 then
45
 
                                debug( "TrackBack was sent to myself.", DEBUG_FULL )
46
 
                                return true
47
 
                        end
48
 
 
49
 
                        begin
50
 
                                Timeout::timeout( 10 ) do
51
 
                        open( src_uri ) do |f|
52
 
                                                if f.read( 100 * 1024 ).include?( dest_uri ) then
53
 
                                                        debug( "TrackBack has links to me.", DEBUG_FULL )
54
 
                                                        return true
55
 
                                                else
56
 
                                                        debug( "TrackBack dose not have links to me." )
57
 
                                                        comment.show = false
58
 
                                                        return @filter_mode
59
 
                                                end
60
 
                                        end
61
 
                                end
62
 
                        rescue Timeout::Error
63
 
                                debug( "TrackBack source was no response." )
64
 
                                comment.show = false
65
 
                                return @filter_mode
66
 
                        rescue 
67
 
                                debug( "Cannot access to TrackBack source (#{$!})." )
68
 
                                comment.show = false
69
 
                                return @filter_mode
70
 
                        end
71
 
                end
72
 
        end
73
 
end