summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Kozak <spag@golwen.net>2013-02-10 08:09:05 +0000
committerPeter Kozak <spag@golwen.net>2013-02-10 08:09:05 +0000
commit4c9cc92c0a49ec34c8bf00e31d1710450fb533fa (patch)
tree938c21ad5fece8a5b36c2689e5f7f8b50ca72e29
parent5fba89e83722e11232b1130a1a939d55aed94387 (diff)
firewall blacklist model added
-rw-r--r--app/controllers/intruders_controller.rb41
-rw-r--r--app/helpers/intruders_helper.rb2
-rw-r--r--app/models/intruder.rb3
-rw-r--r--app/views/intruders/_form.html.haml7
-rw-r--r--app/views/intruders/_form_core.html.haml16
-rw-r--r--app/views/intruders/_index_core.html.haml37
-rw-r--r--app/views/intruders/edit.html.haml3
-rw-r--r--app/views/intruders/index.html.haml6
-rw-r--r--app/views/intruders/new.html.haml3
-rw-r--r--app/views/intruders/show.html.haml49
-rw-r--r--config/locales/views/intruders/de.yml110
-rw-r--r--config/locales/views/intruders/en.yml110
-rw-r--r--config/routes.rb2
-rw-r--r--db/migrate/20130210075617_create_intruders.rb26
-rw-r--r--test/functional/intruders_controller_test.rb49
-rw-r--r--test/unit/intruder_test.rb7
16 files changed, 471 insertions, 0 deletions
diff --git a/app/controllers/intruders_controller.rb b/app/controllers/intruders_controller.rb
new file mode 100644
index 0000000..eb34f2b
--- /dev/null
+++ b/app/controllers/intruders_controller.rb
@@ -0,0 +1,41 @@
+class IntrudersController < ApplicationController
+ def index
+ @intruders = Intruder.all
+ end
+
+ def show
+ @intruder = Intruder.find(params[:id])
+ end
+
+ def new
+ @intruder = Intruder.new
+ end
+
+ def create
+ @intruder = Intruder.new(params[:intruder])
+ if @intruder.save
+ redirect_to @intruder, :notice => t('intruders.controller.successfuly_created')
+ else
+ render :new
+ end
+ end
+
+ def edit
+ @intruder = Intruder.find(params[:id])
+ end
+
+ def update
+ @intruder = Intruder.find(params[:id])
+ if @intruder.update_attributes(params[:intruder])
+ redirect_to @intruder, :notice => t('intruders.controller.successfuly_updated')
+ else
+ render :edit
+ end
+ end
+
+ def destroy
+ @intruder = Intruder.find(params[:id])
+ @intruder.destroy
+ redirect_to intruders_url, :notice => t('intruders.controller.successfuly_destroyed')
+ end
+end
diff --git a/app/helpers/intruders_helper.rb b/app/helpers/intruders_helper.rb
new file mode 100644
index 0000000..7243cf3
--- /dev/null
+++ b/app/helpers/intruders_helper.rb
@@ -0,0 +1,2 @@
+module IntrudersHelper
+end
diff --git a/app/models/intruder.rb b/app/models/intruder.rb
new file mode 100644
index 0000000..192d64d
--- /dev/null
+++ b/app/models/intruder.rb
@@ -0,0 +1,3 @@
+class Intruder < ActiveRecord::Base
+ attr_accessible :list_type, :key, :points, :bans, :ban_last, :ban_end, :contact_ip, :contact_port, :contact_count, :contact_last, :contacts_per_second, :contacts_per_second_max, :user_agent, :to_user, :comment
+end
diff --git a/app/views/intruders/_form.html.haml b/app/views/intruders/_form.html.haml
new file mode 100644
index 0000000..26aab1c
--- /dev/null
+++ b/app/views/intruders/_form.html.haml
@@ -0,0 +1,7 @@
+= simple_form_for(@intruder) do |f|
+ = f.error_notification
+
+ = render "form_core", :f => f
+
+ .actions
+ = f.button :submit, conditional_t('intruders.form.submit') \ No newline at end of file
diff --git a/app/views/intruders/_form_core.html.haml b/app/views/intruders/_form_core.html.haml
new file mode 100644
index 0000000..ae2da39
--- /dev/null
+++ b/app/views/intruders/_form_core.html.haml
@@ -0,0 +1,16 @@
+.inputs
+ = f.input :list_type, :label => t('intruders.form.list_type.label'), :hint => conditional_hint('intruders.form.list_type.hint')
+ = f.input :key, :label => t('intruders.form.key.label'), :hint => conditional_hint('intruders.form.key.hint')
+ = f.input :points, :label => t('intruders.form.points.label'), :hint => conditional_hint('intruders.form.points.hint')
+ = f.input :bans, :label => t('intruders.form.bans.label'), :hint => conditional_hint('intruders.form.bans.hint')
+ = f.input :ban_last, :label => t('intruders.form.ban_last.label'), :hint => conditional_hint('intruders.form.ban_last.hint')
+ = f.input :ban_end, :label => t('intruders.form.ban_end.label'), :hint => conditional_hint('intruders.form.ban_end.hint')
+ = f.input :contact_ip, :label => t('intruders.form.contact_ip.label'), :hint => conditional_hint('intruders.form.contact_ip.hint')
+ = f.input :contact_port, :label => t('intruders.form.contact_port.label'), :hint => conditional_hint('intruders.form.contact_port.hint')
+ = f.input :contact_count, :label => t('intruders.form.contact_count.label'), :hint => conditional_hint('intruders.form.contact_count.hint')
+ = f.input :contact_last, :label => t('intruders.form.contact_last.label'), :hint => conditional_hint('intruders.form.contact_last.hint')
+ = f.input :contacts_per_second, :label => t('intruders.form.contacts_per_second.label'), :hint => conditional_hint('intruders.form.contacts_per_second.hint')
+ = f.input :contacts_per_second_max, :label => t('intruders.form.contacts_per_second_max.label'), :hint => conditional_hint('intruders.form.contacts_per_second_max.hint')
+ = f.input :user_agent, :label => t('intruders.form.user_agent.label'), :hint => conditional_hint('intruders.form.user_agent.hint')
+ = f.input :to_user, :label => t('intruders.form.to_user.label'), :hint => conditional_hint('intruders.form.to_user.hint')
+ = f.input :comment, :label => t('intruders.form.comment.label'), :hint => conditional_hint('intruders.form.comment.hint')
diff --git a/app/views/intruders/_index_core.html.haml b/app/views/intruders/_index_core.html.haml
new file mode 100644
index 0000000..0070c4d
--- /dev/null
+++ b/app/views/intruders/_index_core.html.haml
@@ -0,0 +1,37 @@
+%table.table.table-striped
+ %tr
+ %th= t('intruders.index.list_type')
+ %th= t('intruders.index.key')
+ %th= t('intruders.index.points')
+ %th= t('intruders.index.bans')
+ %th= t('intruders.index.ban_last')
+ %th= t('intruders.index.ban_end')
+ %th= t('intruders.index.contact_ip')
+ %th= t('intruders.index.contact_port')
+ %th= t('intruders.index.contact_count')
+ %th= t('intruders.index.contact_last')
+ %th= t('intruders.index.contacts_per_second')
+ %th= t('intruders.index.contacts_per_second_max')
+ %th= t('intruders.index.user_agent')
+ %th= t('intruders.index.to_user')
+ %th= t('intruders.index.comment')
+
+
+ - for intruder in intruders
+ %tr
+ %td= intruder.list_type
+ %td= intruder.key
+ %td= intruder.points
+ %td= intruder.bans
+ %td= intruder.ban_last
+ %td= intruder.ban_end
+ %td= intruder.contact_ip
+ %td= intruder.contact_port
+ %td= intruder.contact_count
+ %td= intruder.contact_last
+ %td= intruder.contacts_per_second
+ %td= intruder.contacts_per_second_max
+ %td= intruder.user_agent
+ %td= intruder.to_user
+ %td= intruder.comment
+ =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:child => intruder} \ No newline at end of file
diff --git a/app/views/intruders/edit.html.haml b/app/views/intruders/edit.html.haml
new file mode 100644
index 0000000..1b5a31b
--- /dev/null
+++ b/app/views/intruders/edit.html.haml
@@ -0,0 +1,3 @@
+- content_for :title, t("intruders.edit.page_title")
+
+= render "form" \ No newline at end of file
diff --git a/app/views/intruders/index.html.haml b/app/views/intruders/index.html.haml
new file mode 100644
index 0000000..72b8882
--- /dev/null
+++ b/app/views/intruders/index.html.haml
@@ -0,0 +1,6 @@
+- content_for :title, t("intruders.index.page_title")
+
+- if @intruders && @intruders.count > 0
+ = render "index_core", :intruders => @intruders
+
+= render :partial => 'shared/create_link', :locals => {:child_class => Intruder} \ No newline at end of file
diff --git a/app/views/intruders/new.html.haml b/app/views/intruders/new.html.haml
new file mode 100644
index 0000000..a24b55f
--- /dev/null
+++ b/app/views/intruders/new.html.haml
@@ -0,0 +1,3 @@
+- content_for :title, t("intruders.new.page_title")
+
+= render "form" \ No newline at end of file
diff --git a/app/views/intruders/show.html.haml b/app/views/intruders/show.html.haml
new file mode 100644
index 0000000..fa5f59b
--- /dev/null
+++ b/app/views/intruders/show.html.haml
@@ -0,0 +1,49 @@
+- content_for :title, t("intruders.show.page_title")
+
+%p
+ %strong= t('intruders.show.list_type') + ":"
+ = @intruder.list_type
+%p
+ %strong= t('intruders.show.key') + ":"
+ = @intruder.key
+%p
+ %strong= t('intruders.show.points') + ":"
+ = @intruder.points
+%p
+ %strong= t('intruders.show.bans') + ":"
+ = @intruder.bans
+%p
+ %strong= t('intruders.show.ban_last') + ":"
+ = @intruder.ban_last
+%p
+ %strong= t('intruders.show.ban_end') + ":"
+ = @intruder.ban_end
+%p
+ %strong= t('intruders.show.contact_ip') + ":"
+ = @intruder.contact_ip
+%p
+ %strong= t('intruders.show.contact_port') + ":"
+ = @intruder.contact_port
+%p
+ %strong= t('intruders.show.contact_count') + ":"
+ = @intruder.contact_count
+%p
+ %strong= t('intruders.show.contact_last') + ":"
+ = @intruder.contact_last
+%p
+ %strong= t('intruders.show.contacts_per_second') + ":"
+ = @intruder.contacts_per_second
+%p
+ %strong= t('intruders.show.contacts_per_second_max') + ":"
+ = @intruder.contacts_per_second_max
+%p
+ %strong= t('intruders.show.user_agent') + ":"
+ = @intruder.user_agent
+%p
+ %strong= t('intruders.show.to_user') + ":"
+ = @intruder.to_user
+%p
+ %strong= t('intruders.show.comment') + ":"
+ = @intruder.comment
+
+= render :partial => 'shared/show_edit_destroy_part', :locals => { :child => @intruder } \ No newline at end of file
diff --git a/config/locales/views/intruders/de.yml b/config/locales/views/intruders/de.yml
new file mode 100644
index 0000000..42ece4b
--- /dev/null
+++ b/config/locales/views/intruders/de.yml
@@ -0,0 +1,110 @@
+de:
+ intruders:
+ name: 'Intruder'
+ controller:
+ successfuly_created: 'Intruder wurde angelegt.'
+ successfuly_updated: 'Intruder wurde aktualisiert.'
+ successfuly_destroyed: 'Intruder wurde gelöscht.'
+ index:
+ page_title: 'Übersicht von Intruder'
+ list_type: 'List type'
+ key: 'Key'
+ points: 'Points'
+ bans: 'Bans'
+ ban_last: 'Ban last'
+ ban_end: 'Ban end'
+ contact_ip: 'Contact ip'
+ contact_port: 'Contact port'
+ contact_count: 'Contact count'
+ contact_last: 'Contact last'
+ contacts_per_second: 'Contacts per second'
+ contacts_per_second_max: 'Contacts per second max'
+ user_agent: 'User agent'
+ to_user: 'To user'
+ comment: 'Comment'
+ actions:
+ confirm_destroy: 'Sind Sie sicher, dass Sie folgendes löschen möchten: Intruder'
+ destroy: 'Löschen'
+ edit: 'Bearbeiten'
+ show: 'Anzeigen'
+ create: 'Neu anlegen'
+ create_for: 'Intruder neu anlegen für %{resource}'
+ show:
+ page_title: 'Intruder bearbeiten'
+ list_type: 'List type'
+ key: 'Key'
+ points: 'Points'
+ bans: 'Bans'
+ ban_last: 'Ban last'
+ ban_end: 'Ban end'
+ contact_ip: 'Contact ip'
+ contact_port: 'Contact port'
+ contact_count: 'Contact count'
+ contact_last: 'Contact last'
+ contacts_per_second: 'Contacts per second'
+ contacts_per_second_max: 'Contacts per second max'
+ user_agent: 'User agent'
+ to_user: 'To user'
+ comment: 'Comment'
+ actions:
+ confirm_destroy: 'Sind Sie sicher, dass die dieses Element löschen möchten?'
+ destroy: 'Löschen'
+ edit: 'Bearbeiten'
+ view_all: 'Alle anzeigen'
+ new:
+ page_title: 'Intruder neu anlegen'
+ actions:
+ back_to_list: 'Zurück zur Übersicht'
+ edit:
+ page_title: 'Intruder bearbeiten'
+ actions:
+ back_to_list: 'Zurück zur Übersicht'
+ edit: 'Bearbeiten'
+ view_all: 'Alle anzeigen'
+ form:
+ list_type:
+ label: 'List type'
+ hint: ''
+ key:
+ label: 'Key'
+ hint: ''
+ points:
+ label: 'Points'
+ hint: ''
+ bans:
+ label: 'Bans'
+ hint: ''
+ ban_last:
+ label: 'Ban last'
+ hint: ''
+ ban_end:
+ label: 'Ban end'
+ hint: ''
+ contact_ip:
+ label: 'Contact ip'
+ hint: ''
+ contact_port:
+ label: 'Contact port'
+ hint: ''
+ contact_count:
+ label: 'Contact count'
+ hint: ''
+ contact_last:
+ label: 'Contact last'
+ hint: ''
+ contacts_per_second:
+ label: 'Contacts per second'
+ hint: ''
+ contacts_per_second_max:
+ label: 'Contacts per second max'
+ hint: ''
+ user_agent:
+ label: 'User agent'
+ hint: ''
+ to_user:
+ label: 'To user'
+ hint: ''
+ comment:
+ label: 'Comment'
+ hint: ''
+ submit: 'Absenden' \ No newline at end of file
diff --git a/config/locales/views/intruders/en.yml b/config/locales/views/intruders/en.yml
new file mode 100644
index 0000000..99c2dcb
--- /dev/null
+++ b/config/locales/views/intruders/en.yml
@@ -0,0 +1,110 @@
+en:
+ intruders:
+ name: 'Intruder'
+ controller:
+ successfuly_created: 'Successfully created Intruder.'
+ successfuly_updated: 'Successfully updated Intruder.'
+ successfuly_destroyed: 'Successfully destroyed Intruder.'
+ index:
+ page_title: 'Listing Intruder'
+ list_type: 'List type'
+ key: 'Key'
+ points: 'Points'
+ bans: 'Bans'
+ ban_last: 'Ban last'
+ ban_end: 'Ban end'
+ contact_ip: 'Contact ip'
+ contact_port: 'Contact port'
+ contact_count: 'Contact count'
+ contact_last: 'Contact last'
+ contacts_per_second: 'Contacts per second'
+ contacts_per_second_max: 'Contacts per second max'
+ user_agent: 'User agent'
+ to_user: 'To user'
+ comment: 'Comment'
+ actions:
+ confirm_destroy: 'Are you sure you want to delete this Intruder?'
+ destroy: 'Delete'
+ edit: 'Edit'
+ show: 'View'
+ create: 'New'
+ create_for: 'New Intruder for %{resource}'
+ show:
+ page_title: 'Show Intruder'
+ list_type: 'List type'
+ key: 'Key'
+ points: 'Points'
+ bans: 'Bans'
+ ban_last: 'Ban last'
+ ban_end: 'Ban end'
+ contact_ip: 'Contact ip'
+ contact_port: 'Contact port'
+ contact_count: 'Contact count'
+ contact_last: 'Contact last'
+ contacts_per_second: 'Contacts per second'
+ contacts_per_second_max: 'Contacts per second max'
+ user_agent: 'User agent'
+ to_user: 'To user'
+ comment: 'Comment'
+ actions:
+ confirm_destroy: 'Are you sure you want to delete this element?'
+ destroy: 'Delete'
+ edit: 'Edit'
+ view_all: 'View All'
+ new:
+ page_title: 'New Intruder'
+ actions:
+ back_to_list: 'Back to Index'
+ edit:
+ page_title: 'Editing Intruder'
+ actions:
+ back_to_list: 'Back to Index'
+ edit: 'Edit'
+ view_all: 'View All'
+ form:
+ list_type:
+ label: 'List type'
+ hint: ''
+ key:
+ label: 'Key'
+ hint: ''
+ points:
+ label: 'Points'
+ hint: ''
+ bans:
+ label: 'Bans'
+ hint: ''
+ ban_last:
+ label: 'Ban last'
+ hint: ''
+ ban_end:
+ label: 'Ban end'
+ hint: ''
+ contact_ip:
+ label: 'Contact ip'
+ hint: ''
+ contact_port:
+ label: 'Contact port'
+ hint: ''
+ contact_count:
+ label: 'Contact count'
+ hint: ''
+ contact_last:
+ label: 'Contact last'
+ hint: ''
+ contacts_per_second:
+ label: 'Contacts per second'
+ hint: ''
+ contacts_per_second_max:
+ label: 'Contacts per second max'
+ hint: ''
+ user_agent:
+ label: 'User agent'
+ hint: ''
+ to_user:
+ label: 'To user'
+ hint: ''
+ comment:
+ label: 'Comment'
+ hint: ''
+ submit: 'Submit' \ No newline at end of file
diff --git a/config/routes.rb b/config/routes.rb
index 653b811..05d09dc 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,5 +1,7 @@
Gemeinschaft42c::Application.routes.draw do
+ resources :intruders
+
resources :backup_jobs, :except => [:edit, :update]
scope :constraints => lambda{|req|%w(127.0.0.1).include? req.remote_addr} do
diff --git a/db/migrate/20130210075617_create_intruders.rb b/db/migrate/20130210075617_create_intruders.rb
new file mode 100644
index 0000000..bd4db0b
--- /dev/null
+++ b/db/migrate/20130210075617_create_intruders.rb
@@ -0,0 +1,26 @@
+class CreateIntruders < ActiveRecord::Migration
+ def self.up
+ create_table :intruders do |t|
+ t.string :list_type
+ t.string :key
+ t.integer :points
+ t.integer :bans
+ t.datetime :ban_last
+ t.datetime :ban_end
+ t.string :contact_ip
+ t.integer :contact_port
+ t.integer :contact_count
+ t.datetime :contact_last
+ t.float :contacts_per_second
+ t.float :contacts_per_second_max
+ t.string :user_agent
+ t.string :to_user
+ t.string :comment
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :intruders
+ end
+end
diff --git a/test/functional/intruders_controller_test.rb b/test/functional/intruders_controller_test.rb
new file mode 100644
index 0000000..0896022
--- /dev/null
+++ b/test/functional/intruders_controller_test.rb
@@ -0,0 +1,49 @@
+require 'test_helper'
+
+class IntrudersControllerTest < ActionController::TestCase
+ setup do
+ @intruder = intruders(:one)
+ end
+
+ test "should get index" do
+ get :index
+ assert_response :success
+ assert_not_nil assigns(:intruders)
+ end
+
+ test "should get new" do
+ get :new
+ assert_response :success
+ end
+
+ test "should create intruder" do
+ assert_difference('Intruder.count') do
+ post :create, intruder: @intruder.attributes
+ end
+
+ assert_redirected_to intruder_path(assigns(:intruder))
+ end
+
+ test "should show intruder" do
+ get :show, id: @intruder.to_param
+ assert_response :success
+ end
+
+ test "should get edit" do
+ get :edit, id: @intruder.to_param
+ assert_response :success
+ end
+
+ test "should update intruder" do
+ put :update, id: @intruder.to_param, intruder: @intruder.attributes
+ assert_redirected_to intruder_path(assigns(:intruder))
+ end
+
+ test "should destroy intruder" do
+ assert_difference('Intruder.count', -1) do
+ delete :destroy, id: @intruder.to_param
+ end
+
+ assert_redirected_to intruders_path
+ end
+end
diff --git a/test/unit/intruder_test.rb b/test/unit/intruder_test.rb
new file mode 100644
index 0000000..f1b7963
--- /dev/null
+++ b/test/unit/intruder_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class IntruderTest < ActiveSupport::TestCase
+ def test_should_be_valid
+ assert Intruder.new.valid?
+ end
+end