Module: Plugins::Attack::AttackHelper

Defined in:
app/apps/plugins/attack/attack_helper.rb

Overview

Camaleon CMS is a content management system

Copyright (C) 2015 by Owen Peredo Diaz
Email: [email protected]
This program is free software: you can redistribute it and/or modify   it under the terms of the GNU Affero General Public License as  published by the Free Software Foundation, either version 3 of the  License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,  but WITHOUT ANY WARRANTY; without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the  GNU Affero General Public License (GPLv3) for more details.

Instance Method Summary collapse

Instance Method Details

#attack_app_before_loadObject



48
49
50
51
52
53
54
55
56
57
# File 'app/apps/plugins/attack/attack_helper.rb', line 48

def attack_app_before_load()
  cache_ban = Rails.cache.read(cama_get_session_id)
  if cache_ban.present? # render banned message if it was banned
    render text: cache_ban, layout: false
    return
  end

  # save cache requests
  attack_check_request
end

#attack_on_active(plugin) ⇒ Object

here all actions on going to active you can run sql commands like this: results = ActiveRecord::Base.connection.execute(query); plugin: plugin model



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/apps/plugins/attack/attack_helper.rb', line 21

def attack_on_active(plugin)
  current_site.set_meta("attack_config", {get: {sec: 20, max: 10},
                                          post: {sec: 20, max: 5},
                                          msg: "#{t('plugin.attack.form.request_limit_exceeded')}",
                                          ban: 5,
                                          cleared: Time.now
                                        })

  unless ActiveRecord::Base.connection.table_exists? 'plugins_attacks'
    ActiveRecord::Base.connection.create_table :plugins_attacks do |t|
      t.string :path, index: true
      t.string :browser_key, index: true
      t.belongs_to :site, index: true
      t.datetime "created_at"
    end
  end
  CamaleonCms::Site.class_eval do
    has_many :attack, class_name: "Plugins::Attack::Models::Attack"
  end
end

#attack_on_destroy(plugin) ⇒ Object

here all actions on plugin destroying plugin: plugin model



13
14
15
# File 'app/apps/plugins/attack/attack_helper.rb', line 13

def attack_on_destroy(plugin)
  current_site.attack.destroy_all
end

#attack_on_inactive(plugin) ⇒ Object

here all actions on going to inactive plugin: plugin model



44
45
46
# File 'app/apps/plugins/attack/attack_helper.rb', line 44

def attack_on_inactive(plugin)
  current_site.attack.destroy_all
end