antispam 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +72 -0
  4. data/Rakefile +18 -0
  5. data/app/assets/config/antispam_manifest.js +1 -0
  6. data/app/assets/images/antispam/captcha/a.gif +0 -0
  7. data/app/assets/images/antispam/captcha/b.gif +0 -0
  8. data/app/assets/images/antispam/captcha/blank.gif +0 -0
  9. data/app/assets/images/antispam/captcha/c.gif +0 -0
  10. data/app/assets/images/antispam/captcha/d.gif +0 -0
  11. data/app/assets/images/antispam/captcha/e.gif +0 -0
  12. data/app/assets/images/antispam/captcha/f.gif +0 -0
  13. data/app/assets/images/antispam/captcha/g.gif +0 -0
  14. data/app/assets/images/antispam/captcha/h.gif +0 -0
  15. data/app/assets/images/antispam/captcha/i.gif +0 -0
  16. data/app/assets/images/antispam/captcha/j.gif +0 -0
  17. data/app/assets/images/antispam/captcha/k.gif +0 -0
  18. data/app/assets/images/antispam/captcha/l.gif +0 -0
  19. data/app/assets/stylesheets/antispam/application.css +15 -0
  20. data/app/assets/stylesheets/antispam/blocks.css +4 -0
  21. data/app/assets/stylesheets/antispam/challenges.css +4 -0
  22. data/app/assets/stylesheets/antispam/clears.css +4 -0
  23. data/app/assets/stylesheets/scaffold.css +80 -0
  24. data/app/controllers/antispam/application_controller.rb +4 -0
  25. data/app/controllers/antispam/blocks_controller.rb +70 -0
  26. data/app/controllers/antispam/challenges_controller.rb +49 -0
  27. data/app/controllers/antispam/clears_controller.rb +63 -0
  28. data/app/controllers/antispam/validate_controller.rb +12 -0
  29. data/app/helpers/antispam/application_helper.rb +4 -0
  30. data/app/helpers/antispam/blocks_helper.rb +4 -0
  31. data/app/helpers/antispam/challenges_helper.rb +4 -0
  32. data/app/helpers/antispam/clears_helper.rb +4 -0
  33. data/app/jobs/antispam/application_job.rb +4 -0
  34. data/app/mailers/antispam/application_mailer.rb +6 -0
  35. data/app/models/antispam/application_record.rb +5 -0
  36. data/app/models/antispam/block.rb +4 -0
  37. data/app/models/antispam/challenge.rb +26 -0
  38. data/app/models/antispam/clear.rb +4 -0
  39. data/app/models/antispam/ip.rb +7 -0
  40. data/app/views/antispam/blocks/_form.html.erb +37 -0
  41. data/app/views/antispam/blocks/edit.html.erb +6 -0
  42. data/app/views/antispam/blocks/index.html.erb +37 -0
  43. data/app/views/antispam/blocks/new.html.erb +5 -0
  44. data/app/views/antispam/blocks/show.html.erb +24 -0
  45. data/app/views/antispam/challenges/_form.html.erb +32 -0
  46. data/app/views/antispam/challenges/edit.html.erb +6 -0
  47. data/app/views/antispam/challenges/index.html.erb +31 -0
  48. data/app/views/antispam/challenges/new.html.erb +5 -0
  49. data/app/views/antispam/challenges/show.html.erb +19 -0
  50. data/app/views/antispam/clears/_form.html.erb +42 -0
  51. data/app/views/antispam/clears/edit.html.erb +6 -0
  52. data/app/views/antispam/clears/index.html.erb +32 -0
  53. data/app/views/antispam/clears/new.html.erb +5 -0
  54. data/app/views/antispam/clears/show.html.erb +29 -0
  55. data/app/views/antispam/validate/index.html.erb +14 -0
  56. data/app/views/layouts/antispam/application.html.erb +15 -0
  57. data/config/routes.rb +7 -0
  58. data/db/migrate/20210130213708_create_antispam_ips.rb +12 -0
  59. data/db/migrate/20210130214835_create_antispam_challenges.rb +11 -0
  60. data/db/migrate/20210130234107_create_antispam_blocks.rb +12 -0
  61. data/db/migrate/20210130235537_create_antispam_clears.rb +13 -0
  62. data/lib/antispam.rb +11 -0
  63. data/lib/antispam/blacklists/httpbl.rb +43 -0
  64. data/lib/antispam/engine.rb +5 -0
  65. data/lib/antispam/tools.rb +49 -0
  66. data/lib/antispam/version.rb +3 -0
  67. data/lib/tasks/antispam_tasks.rake +4 -0
  68. metadata +141 -0
@@ -0,0 +1,12 @@
1
+ require_dependency "antispam/application_controller"
2
+
3
+ module Antispam
4
+ class ValidateController < ApplicationController
5
+ def index
6
+ respond_to do |format|
7
+ format.html
8
+ format.js { render js: 'window.location = "/antispam/validate"'}
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,4 @@
1
+ module Antispam
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Antispam
2
+ module BlocksHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Antispam
2
+ module ChallengesHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Antispam
2
+ module ClearsHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Antispam
2
+ class ApplicationJob < ActiveJob::Base
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module Antispam
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: 'from@example.com'
4
+ layout 'mailer'
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module Antispam
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ module Antispam
2
+ class Block < ApplicationRecord
3
+ end
4
+ end
@@ -0,0 +1,26 @@
1
+ module Antispam
2
+ class Challenge < ApplicationRecord
3
+ before_create :generate
4
+
5
+ def generate
6
+ self.question = create_string
7
+ self.answer = self.question
8
+ end
9
+ def create_string
10
+ o = [('a'..'z'), ('A'..'Z')].map(&:to_a).flatten
11
+ (0...8).map { o[rand(o.length)] }.join
12
+ end
13
+ def get_image
14
+ require "image_processing/vips"
15
+ image = Vips::Image.text(self.answer, dpi: 300)
16
+ image.draw_line(255, 5+rand(20).to_i, 5+rand(20).to_i, 150+rand(50).to_i, 10+rand(10).to_i)
17
+ end
18
+ def validate?(check)
19
+ return false if self.answer.nil?
20
+ result = false
21
+ result = true if self.answer.downcase == check.downcase
22
+ self.update_column(:answer,nil)
23
+ return result
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,4 @@
1
+ module Antispam
2
+ class Clear < ApplicationRecord
3
+ end
4
+ end
@@ -0,0 +1,7 @@
1
+ module Antispam
2
+ class Ip < ApplicationRecord
3
+ def expired?
4
+ self.expires_at < Time.now
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,37 @@
1
+ <%= form_with(model: block) do |form| %>
2
+ <% if block.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(block.errors.count, "error") %> prohibited this block from being saved:</h2>
5
+
6
+ <ul>
7
+ <% block.errors.each do |error| %>
8
+ <li><%= error.full_message %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <div class="field">
15
+ <%= form.label :ip %>
16
+ <%= form.text_field :ip %>
17
+ </div>
18
+
19
+ <div class="field">
20
+ <%= form.label :provider %>
21
+ <%= form.text_field :provider %>
22
+ </div>
23
+
24
+ <div class="field">
25
+ <%= form.label :controllername %>
26
+ <%= form.text_field :controllername %>
27
+ </div>
28
+
29
+ <div class="field">
30
+ <%= form.label :actionname %>
31
+ <%= form.text_field :actionname %>
32
+ </div>
33
+
34
+ <div class="actions">
35
+ <%= form.submit %>
36
+ </div>
37
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <h1>Editing Block</h1>
2
+
3
+ <%= render 'form', block: @block %>
4
+
5
+ <%= link_to 'Show', @block %> |
6
+ <%= link_to 'Back', blocks_path %>
@@ -0,0 +1,37 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <div class="row">
4
+ <div class="cx">
5
+ <h1>Blocks</h1>
6
+
7
+ <table>
8
+ <thead>
9
+ <tr>
10
+ <th>Ip</th>
11
+ <th>Provider</th>
12
+ <th>Controllername</th>
13
+ <th>Actionname</th>
14
+ <th colspan="3"></th>
15
+ </tr>
16
+ </thead>
17
+
18
+ <tbody>
19
+ <% Antispam::Block.all.order(create_at: :desc).limit(50).each do |block| %>
20
+ <tr>
21
+ <td><%= block.ip %></td>
22
+ <td><%= block.provider %></td>
23
+ <td><%= block.controllername %></td>
24
+ <td><%= block.actionname %></td>
25
+ <td><%= time_ago_in_words block.created_at %> ago</td>
26
+ <!-- <td><%#= link_to 'Show', block %></td>-->
27
+ <!-- <td><%#= link_to 'Edit', edit_block_path(block) %></td>-->
28
+ <!-- <td><%#= link_to 'Destroy', block, method: :delete, data: { confirm: 'Are you sure?' } %></td>-->
29
+ </tr>
30
+ <% end %>
31
+ </tbody>
32
+ </table>
33
+ </div>
34
+ <div class="cx">
35
+ <%= render template: '/antispam/clears/index.html' %>
36
+ </div>
37
+ </div>
@@ -0,0 +1,5 @@
1
+ <h1>New Block</h1>
2
+
3
+ <%= render 'form', block: @block %>
4
+
5
+ <%= link_to 'Back', blocks_path %>
@@ -0,0 +1,24 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <p>
4
+ <strong>Ip:</strong>
5
+ <%= @block.ip %>
6
+ </p>
7
+
8
+ <p>
9
+ <strong>Provider:</strong>
10
+ <%= @block.provider %>
11
+ </p>
12
+
13
+ <p>
14
+ <strong>Controllername:</strong>
15
+ <%= @block.controllername %>
16
+ </p>
17
+
18
+ <p>
19
+ <strong>Actionname:</strong>
20
+ <%= @block.actionname %>
21
+ </p>
22
+
23
+ <%= link_to 'Edit', edit_block_path(@block) %> |
24
+ <%= link_to 'Back', blocks_path %>
@@ -0,0 +1,32 @@
1
+ <%= form_with(model: challenge) do |form| %>
2
+ <% if challenge.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(challenge.errors.count, "error") %> prohibited this challenge from being saved:</h2>
5
+
6
+ <ul>
7
+ <% challenge.errors.each do |error| %>
8
+ <li><%= error.full_message %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <div class="field">
15
+ <%= form.label :question %>
16
+ <%= form.text_field :question %>
17
+ </div>
18
+
19
+ <div class="field">
20
+ <%= form.label :answer %>
21
+ <%= form.text_field :answer %>
22
+ </div>
23
+
24
+ <div class="field">
25
+ <%= form.label :code %>
26
+ <%= form.text_field :code %>
27
+ </div>
28
+
29
+ <div class="actions">
30
+ <%= form.submit %>
31
+ </div>
32
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <h1>Editing Challenge</h1>
2
+
3
+ <%= render 'form', challenge: @challenge %>
4
+
5
+ <%= link_to 'Show', @challenge %> |
6
+ <%= link_to 'Back', challenges_path %>
@@ -0,0 +1,31 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <h1>Challenges</h1>
4
+
5
+ <table>
6
+ <thead>
7
+ <tr>
8
+ <th>Question</th>
9
+ <th>Answer</th>
10
+ <th>Code</th>
11
+ <th colspan="3"></th>
12
+ </tr>
13
+ </thead>
14
+
15
+ <tbody>
16
+ <% @challenges.each do |challenge| %>
17
+ <tr>
18
+ <td><%= challenge.question %></td>
19
+ <td><%= challenge.answer %></td>
20
+ <td><%= challenge.code %></td>
21
+ <td><%= link_to 'Show', challenge %></td>
22
+ <td><%= link_to 'Edit', edit_challenge_path(challenge) %></td>
23
+ <td><%= link_to 'Destroy', challenge, method: :delete, data: { confirm: 'Are you sure?' } %></td>
24
+ </tr>
25
+ <% end %>
26
+ </tbody>
27
+ </table>
28
+
29
+ <br>
30
+
31
+ <%= link_to 'New Challenge', new_challenge_path %>
@@ -0,0 +1,5 @@
1
+ <h1>New Challenge</h1>
2
+
3
+ <%= render 'form', challenge: @challenge %>
4
+
5
+ <%= link_to 'Back', challenges_path %>
@@ -0,0 +1,19 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <p>
4
+ <strong>Question:</strong>
5
+ <%= @challenge.question %>
6
+ </p>
7
+
8
+ <p>
9
+ <strong>Answer:</strong>
10
+ <%= @challenge.answer %>
11
+ </p>
12
+
13
+ <p>
14
+ <strong>Code:</strong>
15
+ <%= @challenge.code %>
16
+ </p>
17
+
18
+ <%= link_to 'Edit', edit_challenge_path(@challenge) %> |
19
+ <%= link_to 'Back', challenges_path %>
@@ -0,0 +1,42 @@
1
+ <%= form_with(model: clear) do |form| %>
2
+ <% if clear.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(clear.errors.count, "error") %> prohibited this clear from being saved:</h2>
5
+
6
+ <ul>
7
+ <% clear.errors.each do |error| %>
8
+ <li><%= error.full_message %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <div class="field">
15
+ <%= form.label :ip %>
16
+ <%= form.text_field :ip %>
17
+ </div>
18
+
19
+ <div class="field">
20
+ <%= form.label :result %>
21
+ <%= form.text_field :result %>
22
+ </div>
23
+
24
+ <div class="field">
25
+ <%= form.label :answer %>
26
+ <%= form.text_field :answer %>
27
+ </div>
28
+
29
+ <div class="field">
30
+ <%= form.label :threat_before %>
31
+ <%= form.number_field :threat_before %>
32
+ </div>
33
+
34
+ <div class="field">
35
+ <%= form.label :threat_after %>
36
+ <%= form.number_field :threat_after %>
37
+ </div>
38
+
39
+ <div class="actions">
40
+ <%= form.submit %>
41
+ </div>
42
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <h1>Editing Clear</h1>
2
+
3
+ <%= render 'form', clear: @clear %>
4
+
5
+ <%= link_to 'Show', @clear %> |
6
+ <%= link_to 'Back', clears_path %>
@@ -0,0 +1,32 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <h1>Clears</h1>
4
+
5
+ <table>
6
+ <thead>
7
+ <tr>
8
+ <th>Ip</th>
9
+ <th>Result</th>
10
+ <th>Answer</th>
11
+ <th>Threat before</th>
12
+ <th>Threat after</th>
13
+ <th colspan="3"></th>
14
+ </tr>
15
+ </thead>
16
+
17
+ <tbody>
18
+ <% Antispam::Clear.all.order(create_at: :desc).limit(50).each do |clear| %>
19
+ <tr>
20
+ <td><%= clear.ip %></td>
21
+ <td><%= clear.result %></td>
22
+ <td><%= clear.answer %></td>
23
+ <td><%= clear.threat_before %></td>
24
+ <td><%= clear.threat_after %></td>
25
+ <td><%= time_ago_in_words clear.created_at %> ago</td>
26
+ <!-- <td><%#= link_to 'Show', clear %></td>-->
27
+ <!-- <td><%#= link_to 'Edit', edit_clear_path(clear) %></td>-->
28
+ <!-- <td><%#= link_to 'Destroy', clear, method: :delete, data: { confirm: 'Are you sure?' } %></td>-->
29
+ </tr>
30
+ <% end %>
31
+ </tbody>
32
+ </table>
@@ -0,0 +1,5 @@
1
+ <h1>New Clear</h1>
2
+
3
+ <%= render 'form', clear: @clear %>
4
+
5
+ <%= link_to 'Back', clears_path %>
@@ -0,0 +1,29 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <p>
4
+ <strong>Ip:</strong>
5
+ <%= @clear.ip %>
6
+ </p>
7
+
8
+ <p>
9
+ <strong>Result:</strong>
10
+ <%= @clear.result %>
11
+ </p>
12
+
13
+ <p>
14
+ <strong>Answer:</strong>
15
+ <%= @clear.answer %>
16
+ </p>
17
+
18
+ <p>
19
+ <strong>Threat before:</strong>
20
+ <%= @clear.threat_before %>
21
+ </p>
22
+
23
+ <p>
24
+ <strong>Threat after:</strong>
25
+ <%= @clear.threat_after %>
26
+ </p>
27
+
28
+ <%= link_to 'Edit', edit_clear_path(@clear) %> |
29
+ <%= link_to 'Back', clears_path %>