firewall 0.0.3

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 (110) hide show
  1. checksums.yaml +7 -0
  2. data/GPL +674 -0
  3. data/LICENSE +181 -0
  4. data/README.md +31 -0
  5. data/Rakefile +34 -0
  6. data/app/assets/javascripts/firewall/application.js +14 -0
  7. data/app/assets/javascripts/firewall/bootstrap.js +6 -0
  8. data/app/assets/javascripts/firewall/dashboard.js +2 -0
  9. data/app/assets/javascripts/firewall/rule.js +2 -0
  10. data/app/assets/stylesheets/firewall/application.css +13 -0
  11. data/app/assets/stylesheets/firewall/bootstrap.css +9 -0
  12. data/app/assets/stylesheets/firewall/dashboard.css +23 -0
  13. data/app/assets/stylesheets/firewall/rule.css +4 -0
  14. data/app/controllers/firewall/application_controller.rb +4 -0
  15. data/app/controllers/firewall/custom_rules_controller.rb +9 -0
  16. data/app/controllers/firewall/dashboard_controller.rb +57 -0
  17. data/app/controllers/firewall/rules_controller.rb +46 -0
  18. data/app/controllers/firewall/url_protections_controller.rb +9 -0
  19. data/app/helpers/firewall/application_helper.rb +11 -0
  20. data/app/helpers/firewall/custom_rules_helper.rb +4 -0
  21. data/app/helpers/firewall/dashboard_helper.rb +11 -0
  22. data/app/helpers/firewall/iptables_helper.rb +97 -0
  23. data/app/helpers/firewall/rule_helper.rb +4 -0
  24. data/app/helpers/firewall/url_protections_helper.rb +19 -0
  25. data/app/views/firewall/custom_rules/index.html.erb +36 -0
  26. data/app/views/firewall/dashboard/help.html.erb +8 -0
  27. data/app/views/firewall/dashboard/index.html.erb +83 -0
  28. data/app/views/firewall/partials/_protected_urls.html.erb +7 -0
  29. data/app/views/firewall/partials/_remove_rule.html.erb +18 -0
  30. data/app/views/firewall/url_protections/index.html.erb +52 -0
  31. data/app/views/layouts/firewall/application.html.erb +33 -0
  32. data/config/routes.rb +19 -0
  33. data/lib/firewall.rb +14 -0
  34. data/lib/firewall/config.rb +9 -0
  35. data/lib/firewall/engine.rb +5 -0
  36. data/lib/firewall/version.rb +3 -0
  37. data/lib/tasks/firewall_tasks.rake +4 -0
  38. data/test/controllers/firewall/custom_rules_controller_test.rb +51 -0
  39. data/test/controllers/firewall/dashboard_controller_test.rb +9 -0
  40. data/test/controllers/firewall/rule_controller_test.rb +9 -0
  41. data/test/controllers/firewall/url_protections_controller_test.rb +51 -0
  42. data/test/dummy/README.rdoc +28 -0
  43. data/test/dummy/Rakefile +6 -0
  44. data/test/dummy/app/assets/javascripts/application.js +13 -0
  45. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  46. data/test/dummy/app/controllers/application_controller.rb +5 -0
  47. data/test/dummy/app/helpers/application_helper.rb +2 -0
  48. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  49. data/test/dummy/bin/bundle +3 -0
  50. data/test/dummy/bin/rails +4 -0
  51. data/test/dummy/bin/rake +4 -0
  52. data/test/dummy/config.ru +4 -0
  53. data/test/dummy/config/application.rb +23 -0
  54. data/test/dummy/config/boot.rb +5 -0
  55. data/test/dummy/config/database.yml +25 -0
  56. data/test/dummy/config/environment.rb +5 -0
  57. data/test/dummy/config/environments/development.rb +29 -0
  58. data/test/dummy/config/environments/production.rb +80 -0
  59. data/test/dummy/config/environments/test.rb +36 -0
  60. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  61. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  62. data/test/dummy/config/initializers/firewall.rb +3 -0
  63. data/test/dummy/config/initializers/inflections.rb +16 -0
  64. data/test/dummy/config/initializers/mime_types.rb +5 -0
  65. data/test/dummy/config/initializers/secret_token.rb +12 -0
  66. data/test/dummy/config/initializers/session_store.rb +3 -0
  67. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  68. data/test/dummy/config/locales/en.yml +23 -0
  69. data/test/dummy/config/routes.rb +4 -0
  70. data/test/dummy/db/development.sqlite3 +0 -0
  71. data/test/dummy/log/development.log +23618 -0
  72. data/test/dummy/public/404.html +58 -0
  73. data/test/dummy/public/422.html +58 -0
  74. data/test/dummy/public/500.html +57 -0
  75. data/test/dummy/public/favicon.ico +0 -0
  76. data/test/dummy/tmp/cache/assets/development/sprockets/0a60283fc12e6a9bd48e5ae36976b921 +0 -0
  77. data/test/dummy/tmp/cache/assets/development/sprockets/0b5306e754a01c768bedaab8f9509bda +0 -0
  78. data/test/dummy/tmp/cache/assets/development/sprockets/11d2fdda99fea82ab092863982d9ea88 +0 -0
  79. data/test/dummy/tmp/cache/assets/development/sprockets/15acff277a318653bb345c6105a11be0 +0 -0
  80. data/test/dummy/tmp/cache/assets/development/sprockets/1c8a32213677fddf0e98f8e722f58228 +0 -0
  81. data/test/dummy/tmp/cache/assets/development/sprockets/1de8c4ba0815ec306901a1ed7756d565 +0 -0
  82. data/test/dummy/tmp/cache/assets/development/sprockets/227ebf10932ed925cef9e9c703d197c9 +0 -0
  83. data/test/dummy/tmp/cache/assets/development/sprockets/237ee2113aea8583a392b736e80e204a +0 -0
  84. data/test/dummy/tmp/cache/assets/development/sprockets/23b14ed1b8b016c3198e840f467bebf6 +0 -0
  85. data/test/dummy/tmp/cache/assets/development/sprockets/2ecb23dbb882d38e6bce979f7f70488d +0 -0
  86. data/test/dummy/tmp/cache/assets/development/sprockets/30eeb74962b27ca7dc0356e565e9693a +0 -0
  87. data/test/dummy/tmp/cache/assets/development/sprockets/3bc2babdfd45f2ec56fe2492de7adc93 +0 -0
  88. data/test/dummy/tmp/cache/assets/development/sprockets/4125b5c9076f4270f3cc3b8193df1c50 +0 -0
  89. data/test/dummy/tmp/cache/assets/development/sprockets/463438fe2a759d1f0df8aa2c4e835ef2 +0 -0
  90. data/test/dummy/tmp/cache/assets/development/sprockets/580b7b5aa22cc1a628750dc446a18f3f +0 -0
  91. data/test/dummy/tmp/cache/assets/development/sprockets/5ae89014c01446af1f08021111d354df +0 -0
  92. data/test/dummy/tmp/cache/assets/development/sprockets/85fe0cf9f5c7dbef5ddfb8f952503b80 +0 -0
  93. data/test/dummy/tmp/cache/assets/development/sprockets/8905ce142a7b5b6077760d59d74a5797 +0 -0
  94. data/test/dummy/tmp/cache/assets/development/sprockets/96dce60b88d88b21bc34a9edad7643b5 +0 -0
  95. data/test/dummy/tmp/cache/assets/development/sprockets/a6446969577a74e1375c7108b5c0b83e +0 -0
  96. data/test/dummy/tmp/cache/assets/development/sprockets/ace5df6ec174fdbab1591b51ee30c92e +0 -0
  97. data/test/dummy/tmp/cache/assets/development/sprockets/ad12ebad88d4b05d703b26661982b547 +0 -0
  98. data/test/dummy/tmp/cache/assets/development/sprockets/b1db88f1eb887fe39f9742ef821b5f93 +0 -0
  99. data/test/dummy/tmp/cache/assets/development/sprockets/bb8d98821d6ae6b9ef68985046b58399 +0 -0
  100. data/test/dummy/tmp/cache/assets/development/sprockets/dbda6078e4658cb01c856f93cbf3e70b +0 -0
  101. data/test/dummy/tmp/cache/assets/development/sprockets/ea548cf2f63b30dff7f2378aee3bfd4d +0 -0
  102. data/test/dummy/tmp/cache/assets/development/sprockets/ecf0963ce7995a24c9ebb1e9b035711c +0 -0
  103. data/test/firewall_test.rb +7 -0
  104. data/test/helpers/firewall/custom_rules_helper_test.rb +6 -0
  105. data/test/helpers/firewall/dashboard_helper_test.rb +6 -0
  106. data/test/helpers/firewall/rule_helper_test.rb +6 -0
  107. data/test/helpers/firewall/url_protections_helper_test.rb +6 -0
  108. data/test/integration/navigation_test.rb +10 -0
  109. data/test/test_helper.rb +15 -0
  110. metadata +254 -0
@@ -0,0 +1,9 @@
1
+ require_dependency "firewall/application_controller"
2
+
3
+ module Firewall
4
+ class UrlProtectionsController < ApplicationController
5
+ def index
6
+
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ module Firewall
2
+ module ApplicationHelper
3
+
4
+ class << self
5
+ def get_tab_active_class_for(tab)
6
+ p request.original_url
7
+ return 'active'
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,4 @@
1
+ module Firewall
2
+ module CustomRulesHelper
3
+ end
4
+ end
@@ -0,0 +1,11 @@
1
+ module Firewall
2
+ module DashboardHelper
3
+ class << self
4
+
5
+ def blacklisting_active?
6
+ return IptablesHelper.show_rules.include?("blacklistdrop")
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,97 @@
1
+ require 'firewall/config'
2
+
3
+ module Firewall
4
+ module IptablesHelper
5
+
6
+ class NotSudoException < StandardError
7
+ end
8
+
9
+ class << self
10
+
11
+ def gain_sudo
12
+ @password = Config.sudo_password
13
+ io = IO.popen(["sudo", "-S", 'pwd'], mode="a+")
14
+
15
+ io.write("#{@password}\n")
16
+ io.write("#{@password}\n")
17
+ io.write("#{@password}\n")
18
+
19
+ l = io.readlines
20
+
21
+ if(l.size == 0)
22
+ raise NotSudoException.new
23
+ end
24
+ end
25
+
26
+ def add_rule(rule)
27
+ gain_sudo()
28
+ puts "add_rule #{rule}"
29
+ rule_array = rule.split(' ')
30
+ f = IO.popen(['sudo', '-n', 'iptables'] + rule_array, :err=>[:child, :out])
31
+ return f.readlines.join
32
+ end
33
+
34
+ def remove_rule(linenumber, chain="INPUT")
35
+ gain_sudo()
36
+ f = IO.popen(['sudo', '-n', 'iptables', '-D', "#{chain}", "#{linenumber}"], :err=>[:child, :out])
37
+ return f.readlines.join
38
+ end
39
+
40
+ def blacklist_ip(ip, blacklist_name='blacklist')
41
+ gain_sudo()
42
+ #FIXME: check if ip only consists of numbers and '.'
43
+ #FIXME: check if blacklist_name only consists of alphanumerics and has no ';'
44
+ return system "sudo sh -c \'echo \"+#{ip}\" >> /proc/net/xt_recent/#{blacklist_name}\'"
45
+ end
46
+
47
+ def unblacklist_ip(ip, blacklist_name='blacklist')
48
+ gain_sudo()
49
+ #FIXME: check if ip only consists of numbers and '.'
50
+ #FIXME: check if blacklist_name only consists of alphanumerics and has no ';'
51
+ return system "sudo sh -c \'echo \"-#{ip}\" >> /proc/net/xt_recent/#{blacklist_name}\'"
52
+ end
53
+
54
+ def show_rules
55
+ gain_sudo()
56
+ f = IO.popen(['sudo', '-n', 'iptables', '-n', '-L', '--line-numbers'], :err=>[:child, :out])
57
+ result = f.readlines.join
58
+ return result
59
+ end
60
+
61
+ def blacklisted_ips(blacklist_name='blacklist')
62
+ f = IO.popen(['cat', "#{blacklist_name}"], :err=>[:child, :out])
63
+ return f.readlines.join
64
+ end
65
+
66
+ def reset_rules
67
+ gain_sudo
68
+
69
+ system("sudo iptables -F")
70
+ system("sudo iptables -X")
71
+ system("sudo iptables -t nat -F")
72
+ system("sudo iptables -t nat -X")
73
+ system("sudo iptables -t mangle -F")
74
+ system("sudo iptables -t mangle -X")
75
+ system("sudo iptables -P INPUT ACCEPT")
76
+ system("sudo iptables -P FORWARD ACCEPT")
77
+ system("sudo iptables -P OUTPUT ACCEPT")
78
+ end
79
+
80
+ def get_rules()
81
+ f = IO.popen(['sudo', 'iptables-save'], :err=>[:child, :out])
82
+ return f.readlines.join
83
+ end
84
+
85
+ # This method overrides all existing rules
86
+ def apply_rules(all_rules_as_string)
87
+ reset_rules()
88
+
89
+ #sudo already gained in reset
90
+ f = IO.popen(['sudo', 'iptables-restore'], mode="a+", :err=>[:child, :out])
91
+ f.write(all_rules_as_string)
92
+ f.close
93
+ end
94
+
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,4 @@
1
+ module Firewall
2
+ module RuleHelper
3
+ end
4
+ end
@@ -0,0 +1,19 @@
1
+ module Firewall
2
+ module UrlProtectionsHelper
3
+
4
+ class << self
5
+ def protected_urls
6
+ regex = /\d+\s+ACCEPT.*?dpt:80 STRING match "(.*?)" ALGO/
7
+ rules = IptablesHelper.show_rules.split(/\n/)
8
+
9
+ protected_urls = []
10
+ rules.each{ |line|
11
+ match = regex.match(line)
12
+ protected_urls.push(match[1]) unless match.nil?
13
+ }
14
+
15
+ return protected_urls
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,36 @@
1
+ <div id="main" class="row">
2
+ <div class="col-lg-10 col-lg-offset-1">
3
+
4
+ <% if !@message.nil? %>
5
+ <div class="alert fade in">
6
+ <button type="button" class="close" data-dismiss="alert">×</button>
7
+ <strong>Message: </strong><%= @message.html_safe %>
8
+ </div>
9
+ <% end %>
10
+
11
+ <!-- All Rules -->
12
+ <legend>All Rules <span class="toggle-button" data-toggle="collapse" data-target="#rules"></span></legend>
13
+ <div id="rules" class="collapse">
14
+ <pre><%= Firewall::IptablesHelper.show_rules() %></pre>
15
+ </div>
16
+
17
+ <!-- Add Custom Rule -->
18
+ <form action="<%= url_for :controller => 'rules', :action => 'create' %>" method="post">
19
+ <fieldset>
20
+ <legend>Add Custom rule</legend>
21
+ <div class="well">
22
+ <div class="form-group">
23
+ <label for="newRule">New rule</label>
24
+ <input type="text" name="rule" class="form-control" id="newRule" required placeholder="New iptables rule without iptables command">
25
+ </div>
26
+ <button type="submit" class="btn btn-success">Add rule</button>
27
+ </div>
28
+ </fieldset>
29
+ </form>
30
+
31
+ <br>
32
+
33
+ <%= render "firewall/partials/remove_rule" %>
34
+
35
+ </div>
36
+ </div>
@@ -0,0 +1,8 @@
1
+ <div id="main" class="row">
2
+ <div class="col-lg-10 col-lg-offset-1">
3
+
4
+ <legend>Help</legend>
5
+ <p>Help will be here in first beta version.</p>
6
+
7
+ </div>
8
+ </div>
@@ -0,0 +1,83 @@
1
+ <div id="main" class="row">
2
+ <div class="col-lg-10 col-lg-offset-1">
3
+
4
+ <% if !@message.nil? %>
5
+ <div class="alert fade in">
6
+ <button type="button" class="close" data-dismiss="alert">×</button>
7
+ <strong>Message: </strong><%= @message.to_s.html_safe %>
8
+ </div>
9
+ <% end %>
10
+
11
+ <legend>All Rules <span class="toggle-button" data-toggle="collapse" data-target="#rules"></span></legend>
12
+ <div id="rules" class="collapse in">
13
+ <pre><%= Firewall::IptablesHelper.show_rules() %></pre>
14
+
15
+ <form action="<%= url_for :controller => 'dashboard', :action => 'activate_blacklisting' %>" method="get">
16
+ <fieldset>
17
+ <button type="submit" class="btn btn-default" <%= Firewall::DashboardHelper.blacklisting_active? ? "disabled=\"disabled\"" : "" %>>Activate blacklisting</button>
18
+ <p class="help-block">Blacklisting is currently <%= Firewall::DashboardHelper.blacklisting_active? ? "active" : "NOT active" %></p>
19
+ </fieldset>
20
+ </form>
21
+ </div>
22
+
23
+ <br>
24
+
25
+ <%= render "firewall/partials/protected_urls" %>
26
+
27
+ <br>
28
+
29
+ <legend>Blacklisted IPs</legend>
30
+ <pre><%= Firewall::IptablesHelper.blacklisted_ips() %></pre>
31
+
32
+ <br>
33
+
34
+ <legend>Danger Area</legend>
35
+ <div class="well">
36
+ <a href="<%= url_for :controller => 'dashboard', :action => 'dump_rules' %>" class="btn btn-success">Download firewall rules</a>
37
+ <a data-toggle="modal" href="#fileUploadModal" class="btn btn-warning">Restore firewall rules</a>
38
+ <button type="button" id="resetButton" class="btn btn-danger">Reset firewall rules</button>
39
+ </div>
40
+
41
+ </div>
42
+ </div>
43
+
44
+ <script type="text/javascript">
45
+ $(function() {
46
+ $('#resetButton').click(function() {
47
+
48
+ if(confirm("Are you sure to reset all config?")){
49
+ $.ajax({
50
+ url: "<%= url_for :controller => 'rules', :action => 'reset' %>",
51
+ method: 'delete',
52
+ complete: function() {
53
+ window.location.href = "<%= url_for :controller => 'dashboard', :action => 'index' %>"
54
+ }
55
+ });
56
+
57
+ }
58
+
59
+ });
60
+ });
61
+
62
+ </script>
63
+
64
+ <div id="fileUploadModal" class="modal fade">
65
+ <div class="modal-dialog">
66
+ <div class="modal-content">
67
+ <form accept-charset="UTF-8" action="<%= url_for :controller => 'dashboard', :action => 'restore_rules' %>" enctype="multipart/form-data" method="post">
68
+ <div class="modal-header">
69
+ <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
70
+ <h4 class="modal-title">Upload a configuration file</h4>
71
+ </div>
72
+ <div class="modal-body">
73
+ <div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓">
74
+ <input id="file" name="file" type="file" required>
75
+ </div>
76
+ <div class="modal-footer">
77
+ <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
78
+ <button ame="commit" type="submit"class="btn btn-primary">Save changes</button>
79
+ </div>
80
+ </form>
81
+ </div><!-- /.modal-content -->
82
+ </div><!-- /.modal-dialog -->
83
+ </div><!-- /.modal -->
@@ -0,0 +1,7 @@
1
+ <!-- Already Protected URLs -->
2
+ <legend>Already Protected URLs <span class="toggle-button" data-toggle="collapse" data-target="#urls"></span></legend>
3
+ <div id="urls" class="collapse in">
4
+ <% Firewall::UrlProtectionsHelper.protected_urls.each do |url| %>
5
+ <span class="label label-success"><%= url %></span>
6
+ <% end %>
7
+ </div>
@@ -0,0 +1,18 @@
1
+ <!-- Remove Rule -->
2
+ <form action="<%= url_for :controller => 'rules', :action => 'remove' %>" method="post">
3
+ <fieldset>
4
+ <legend>Remove a rule</legend>
5
+ <div class="well">
6
+ <div class="row">
7
+ <div class="col-lg-3">
8
+ <div class="form-group">
9
+ <label for="ruleNumber">Rule index number</label>
10
+ <input type="number" min="1" name="index" class="form-control" id="ruleNumber" required placeholder="Rule index">
11
+ <p class="help-block">Use rule index number from above <strong>Rules</strong> table. </p>
12
+ </div>
13
+ </div>
14
+ </div>
15
+ <button type="submit" class="btn btn-danger">Remove rule</button>
16
+ </div>
17
+ </fieldset>
18
+ </form>
@@ -0,0 +1,52 @@
1
+ <div id="main" class="row">
2
+ <div class="col-lg-10 col-lg-offset-1">
3
+
4
+ <% if !@message.nil? %>
5
+ <div class="alert fade in">
6
+ <button type="button" class="close" data-dismiss="alert">×</button>
7
+ <strong>Message: </strong><%= @message.html_safe %>
8
+ </div>
9
+ <% end %>
10
+
11
+ <!-- All Rules -->
12
+ <legend>All Rules <span class="toggle-button" data-toggle="collapse" data-target="#rules"></span></legend>
13
+ <div id="rules" class="collapse">
14
+ <pre><%= Firewall::IptablesHelper.show_rules() %></pre>
15
+ </div>
16
+
17
+ <%= render "firewall/partials/protected_urls" %>
18
+
19
+ <br>
20
+
21
+ <!-- Protect a URL -->
22
+ <form class="form-inline" action="<%= url_for :controller => 'rules', :action => 'protect_url' %>" method="post">
23
+ <fieldset>
24
+ <legend>Protect a URL</legend>
25
+ <div class="well">
26
+ <div class="form-group">
27
+ <label for="newRule">URL pattern</label>
28
+ <input type="text" name="url" class="form-control" id="newRule" required placeholder="URL to be protected">
29
+ <p class="help-block">Not regex, simple sub-string matching with Case Sensitivity. <strong>Don't use white characters (eg. space) otherwise things will broke!</strong></p>
30
+ </div>
31
+
32
+ <div class="form-group">
33
+ If somebody makes
34
+ <input type="number" name="hitcount" class="form-control inline-input" min="1" max="20">
35
+ requests in
36
+ <input type="number" name="interval" class="form-control inline-input" min="1">
37
+ seconds, block his/her IP for
38
+ <input type="number" class="form-control inline-input" min="1" readonly value="120">
39
+ seconds.
40
+ </div>
41
+
42
+ <button type="submit" class="btn btn-success">Protect URL</button>
43
+ </div>
44
+ </fieldset>
45
+ </form>
46
+
47
+ <br>
48
+
49
+ <%= render "firewall/partials/remove_rule" %>
50
+
51
+ </div>
52
+ </div>
@@ -0,0 +1,33 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Firewall</title>
5
+ <%= stylesheet_link_tag "firewall/application", media: "all" %>
6
+ <%= javascript_include_tag "firewall/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <div class="navbar">
12
+ <div class="container">
13
+ <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
14
+ <span class="icon-bar"></span>
15
+ <span class="icon-bar"></span>
16
+ <span class="icon-bar"></span>
17
+ </button>
18
+ <a class="navbar-brand" href="<%= url_for :controller => 'dashboard', :action => 'index' %>">Rails Firewall</a>
19
+ <div class="nav-collapse collapse navbar-responsive-collapse">
20
+ <ul class="nav navbar-nav">
21
+ <li class="<%= current_page?(:controller => 'dashboard', :action => 'index') ? "active" : "" %>"><a href="<%= url_for :controller => 'dashboard', :action => 'index' %>">Dashboard</a></li>
22
+ <li class="<%= current_page?(:controller => 'url_protections', :action => 'index') ? "active" : "" %>"><a href="<%= url_for :controller => 'url_protections', :action => 'index' %>">URL Protection</a></li>
23
+ <li class="<%= current_page?(:controller => 'custom_rules', :action => 'index') ? "active" : "" %>"><a href="<%= url_for :controller => 'custom_rules', :action => 'index' %>">Custom Rules</a></li>
24
+ <li class="<%= current_page?(:controller => 'dashboard', :action => 'help') ? "active" : "" %>"><a href="<%= url_for :controller => 'dashboard', :action => 'help' %>">Help</a></li>
25
+ </ul>
26
+ </div><!-- /.nav-collapse -->
27
+ </div><!-- /.container -->
28
+ </div>
29
+
30
+ <%= yield %>
31
+
32
+ </body>
33
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,19 @@
1
+ Firewall::Engine.routes.draw do
2
+ root "dashboard#index"
3
+
4
+ match 'dashboard' => "dashboard#index", :via => [:get]
5
+ match 'help' => "dashboard#help", :via => [:get]
6
+ match 'dump' => "dashboard#dump_rules", :via => [:get]
7
+ match 'restore' => "dashboard#restore_rules", :via => [:post]
8
+ get "dashboard/activate_blacklisting"
9
+
10
+ match 'url_protection' => "url_protections#index", :via => [:get]
11
+
12
+ match 'custom_rules' => "custom_rules#index", :via => [:get]
13
+
14
+ resource :rule
15
+ delete "rules/reset"
16
+ post "rules/remove"
17
+ post "rules/protect_url"
18
+
19
+ end
data/lib/firewall.rb ADDED
@@ -0,0 +1,14 @@
1
+ require "firewall/engine"
2
+ require "firewall/config"
3
+
4
+ module Firewall
5
+
6
+ def self.config(&block)
7
+ if block_given?
8
+ block.call(Firewall::Config)
9
+ else
10
+ Firewall::Config
11
+ end
12
+ end
13
+
14
+ end