Class: Firewall::DashboardController

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

Instance Method Summary collapse

Instance Method Details

#activate_blacklistingObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/firewall/dashboard_controller.rb', line 12

def activate_blacklisting
  @message = "Blacklisting is already enabled!"
  if(!DashboardHelper.blacklisting_active?)
    # creates a new chain, blacklistdrop, which will log, update ip in the BLACKLIST and drop
    IptablesHelper.add_rule('-N blacklistdrop')
    IptablesHelper.add_rule('-A blacklistdrop -j LOG --log-prefix "Adding to BLACKLIST: "')
    IptablesHelper.add_rule('blacklistdrop -m recent --name BLACKLIST --set -j DROP')

    # A packet is from a host that has been seen in BLACKLIST the last 120 seconds, updates the BLACKLIST and is dropped.
    IptablesHelper.add_rule('-A INPUT -m recent --name BLACKLIST --update --seconds 120 -j DROP')
    @message = "Blacklisting support is activated but not functional until you add some 'blacklisting' rule. If you have already such rules ignore this message."
  end

  render 'firewall/dashboard/index'
end

#dump_rulesObject



28
29
30
31
32
# File 'app/controllers/firewall/dashboard_controller.rb', line 28

def dump_rules
  date = Time.now.to_formatted_s(:number)
  headers['Content-Disposition'] = "attachment; filename=firewall_config_#{date}"
  render :text => IptablesHelper.get_rules(), :content_type => Mime::TEXT
end

#helpObject



9
10
# File 'app/controllers/firewall/dashboard_controller.rb', line 9

def help
end

#indexObject



6
7
# File 'app/controllers/firewall/dashboard_controller.rb', line 6

def index
end

#restore_rulesObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/firewall/dashboard_controller.rb', line 34

def restore_rules
  uploaded_file = params[:file]

  if (uploaded_file.nil?)
    @message = "No file given!"
    render 'firewall/dashboard/index'
    return
  end

  file_content = uploaded_file.read
  
  if (file_content.nil? || file_content.strip == '')
    @message = "Empty file, no rule applied!"
    render 'firewall/dashboard/index'
    return
  end

  p file_content
  @message = IptablesHelper.apply_rules(file_content)
  render 'firewall/dashboard/index'
end