Class: Firewall::RulesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/firewall/rules_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



6
7
8
9
10
# File 'app/controllers/firewall/rules_controller.rb', line 6

def create
  @message = IptablesHelper.add_rule(params[:rule])
  p "message: #{@message}"
  render 'firewall/dashboard/index'
end

#protect_urlObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/firewall/rules_controller.rb', line 25

def protect_url
  url = params[:url]
  interval = params[:interval]
  hitcount = params[:hitcount]
  url_list_name = url.gsub(/[^a-zA-Z0-9]/,'') + '_URL_LIST'

  # If a packet is from a host that is in the list and exceeding limits then forward to blacklistdrop to be blacklisted and then dropped
  send_to_blacklist_rule = "-A INPUT -p tcp --dport 80 --match string --string #{url} --algo kmp  --match recent --update --name #{url_list_name} --seconds #{interval} --hitcount #{hitcount} -j blacklistdrop"

  # If a packet is from a host playing good so far, add to "xscores" list and accept 
  add_to_list_and_accept_rule = "-A INPUT -p tcp --dport 80 --match string --string #{url} --algo kmp  --match recent --set --name #{url_list_name} -j ACCEPT"
  
  r1 = IptablesHelper.add_rule(send_to_blacklist_rule)
  r2 = IptablesHelper.add_rule(add_to_list_and_accept_rule)
  @message = r1 + r2

  @message = @message.strip == '' ? "Success" : @message

  render 'firewall/dashboard/index'
end

#removeObject



12
13
14
15
16
17
# File 'app/controllers/firewall/rules_controller.rb', line 12

def remove
  @message = IptablesHelper.remove_rule(params[:index])
  p "message: #{@message}"
  @message = "#{@message}<br>Check if url is really removed. Note that if the url is removed the rule indexes have been shifted!"
  render 'firewall/dashboard/index'
end

#resetObject



19
20
21
22
23
# File 'app/controllers/firewall/rules_controller.rb', line 19

def reset
  @message = IptablesHelper.reset_rules
  p "message: #{@message}"
  render 'firewall/dashboard/index'
end