Class: Wiki2Go::SpamFilter
- Inherits:
-
Object
- Object
- Wiki2Go::SpamFilter
- Defined in:
- lib/Wiki2Go/SpamFilter.rb
Instance Method Summary collapse
- #added_urls(original_content, modified_content) ⇒ Object
- #blacklist_url(url) ⇒ Object
- #blacklist_urls(urls) ⇒ Object
- #blacklist_user(author) ⇒ Object
-
#cleared_page?(content) ⇒ Boolean
Detect when a non-authenticated user tries to clear a page.
- #edit_by_banned_user?(author) ⇒ Boolean
- #edit_contains_banned_url?(content) ⇒ Boolean
-
#empty_urls_in(content) ⇒ Object
Some idiot spams the xp.be wiki with loads of <a href=“ ”> tags.
- #greylist_new_urls(author, original, new_content) ⇒ Object
- #greylist_suspects ⇒ Object
- #greylist_urls(author, new_urls) ⇒ Object
- #greylisted_url?(url) ⇒ Boolean
-
#hidden_text_in(content) ⇒ Object
Verify if a spammer tries to obfuscate his crap by using inline hidden styles content = HTML text to examine.
-
#initialize(config) ⇒ SpamFilter
constructor
A new instance of SpamFilter.
- #remove_from_greylist(author, url) ⇒ Object
- #stopped_by_spam_engine(url, content, user_ip, author_alias) ⇒ Object
- #too_many_new_urls?(original_content, modified_content, max_new_urls) ⇒ Boolean
- #update_chongqed ⇒ Object
- #use_akismet(api_key, blog) ⇒ Object
Constructor Details
#initialize(config) ⇒ SpamFilter
Returns a new instance of SpamFilter.
11 12 13 14 15 16 |
# File 'lib/Wiki2Go/SpamFilter.rb', line 11 def initialize(config) @config = config @akismet = nil @akismet_api_key = nil @akismet_blog = nil end |
Instance Method Details
#added_urls(original_content, modified_content) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/Wiki2Go/SpamFilter.rb', line 40 def added_urls(original_content, modified_content) url_finder = Wiki2Go::UrlFinder.new old_urls = url_finder.urls_in(original_content) new_urls = url_finder.urls_in(modified_content) urls = new_urls - old_urls urls end |
#blacklist_url(url) ⇒ Object
55 56 57 58 |
# File 'lib/Wiki2Go/SpamFilter.rb', line 55 def blacklist_url(url) @config.banned_urls.add(url) @config.storage.save_list(@config.banned_urls) end |
#blacklist_urls(urls) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/Wiki2Go/SpamFilter.rb', line 60 def blacklist_urls(urls) urls.each do |url| @config.banned_urls.add(url) end @config.storage.save_list(@config.banned_urls) end |
#blacklist_user(author) ⇒ Object
49 50 51 52 53 |
# File 'lib/Wiki2Go/SpamFilter.rb', line 49 def blacklist_user() bad_users = @config.banned_users bad_users.add() @config.storage.save_list(bad_users) end |
#cleared_page?(content) ⇒ Boolean
Detect when a non-authenticated user tries to clear a page
114 115 116 |
# File 'lib/Wiki2Go/SpamFilter.rb', line 114 def cleared_page?(content) content !~ /\S/ end |
#edit_by_banned_user?(author) ⇒ Boolean
18 19 20 21 22 |
# File 'lib/Wiki2Go/SpamFilter.rb', line 18 def edit_by_banned_user?() banned = @config.banned_users.contains() @config.log("Checking if '#{}' is banned=> #{banned}") banned end |
#edit_contains_banned_url?(content) ⇒ Boolean
24 25 26 27 28 |
# File 'lib/Wiki2Go/SpamFilter.rb', line 24 def edit_contains_banned_url?(content) banned = @config.banned_urls.found_in(content) || @config.chonqed_urls.found_in(content) @config.log("Checking if '#{content}' is banned => #{banned}") banned end |
#empty_urls_in(content) ⇒ Object
Some idiot spams the xp.be wiki with loads of <a href=“ ”> tags
35 36 37 38 |
# File 'lib/Wiki2Go/SpamFilter.rb', line 35 def empty_urls_in(content) refs = content.scan(/href="(\s+)"/) refs.length > 0 end |
#greylist_new_urls(author, original, new_content) ⇒ Object
67 68 69 70 |
# File 'lib/Wiki2Go/SpamFilter.rb', line 67 def greylist_new_urls(,original,new_content) new_urls = added_urls(original,new_content) greylist_urls(,new_urls) end |
#greylist_suspects ⇒ Object
86 87 88 |
# File 'lib/Wiki2Go/SpamFilter.rb', line 86 def greylist_suspects @config.greylist.suspects end |
#greylist_urls(author, new_urls) ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/Wiki2Go/SpamFilter.rb', line 72 def greylist_urls(,new_urls) if new_urls.length > 0 then list = @config.greylist new_urls.each do |url| list.add(,url) end @config.storage.save_list(list) end end |
#greylisted_url?(url) ⇒ Boolean
82 83 84 |
# File 'lib/Wiki2Go/SpamFilter.rb', line 82 def greylisted_url?(url) @config.greylist.contains_url?(url) end |
#hidden_text_in(content) ⇒ Object
Verify if a spammer tries to obfuscate his crap by using inline hidden styles content = HTML text to examine
109 110 111 |
# File 'lib/Wiki2Go/SpamFilter.rb', line 109 def hidden_text_in(content) content =~ /<(\S[^>]*style\s*=\s*"[^"]*display\s*:\s*none[^>]*)>/i end |
#remove_from_greylist(author, url) ⇒ Object
90 91 92 93 |
# File 'lib/Wiki2Go/SpamFilter.rb', line 90 def remove_from_greylist(,url) @config.greylist.remove(,url) @config.storage.save_list(@config.greylist) end |
#stopped_by_spam_engine(url, content, user_ip, author_alias) ⇒ Object
123 124 125 126 127 128 |
# File 'lib/Wiki2Go/SpamFilter.rb', line 123 def stopped_by_spam_engine(url,content,user_ip,) engine = return false if engine.nil? return engine.check_comment(user_ip, "","", url, "wiki page", , "", "", content, {}) end |
#too_many_new_urls?(original_content, modified_content, max_new_urls) ⇒ Boolean
30 31 32 |
# File 'lib/Wiki2Go/SpamFilter.rb', line 30 def too_many_new_urls?(original_content, modified_content,max_new_urls) return added_urls(original_content,modified_content).size > max_new_urls end |
#update_chongqed ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/Wiki2Go/SpamFilter.rb', line 95 def update_chongqed output = 'Updating blacklist' response = Net::HTTP.get_response('blacklist.chongqed.org','/index.html') if response.code == '200' then output = response.body @config.storage.update_chongqed_spamlist(output) else output = "Error code #{response.code}: #{response.}" end output end |
#use_akismet(api_key, blog) ⇒ Object
118 119 120 121 |
# File 'lib/Wiki2Go/SpamFilter.rb', line 118 def (api_key,blog) @akismet_api_key = api_key @akismet_blog = blog end |