Module: Plugins::Attack::AttackHelper

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

Instance Method Summary collapse

Instance Method Details

#attack_app_before_loadObject



40
41
42
43
44
45
46
47
48
49
# File 'app/apps/plugins/attack/attack_helper.rb', line 40

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 html: cache_ban.html_safe, 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



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/apps/plugins/attack/attack_helper.rb', line 14

def attack_on_active(_plugin)
  current_site.set_meta('attack_config', { get: { sec: 20, max: 10 },
                                           post: { sec: 20, max: 5 },
                                           msg: I18n.t('plugin.attack.form.request_limit_exceeded').to_s,
                                           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



6
7
8
# File 'app/apps/plugins/attack/attack_helper.rb', line 6

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



36
37
38
# File 'app/apps/plugins/attack/attack_helper.rb', line 36

def attack_on_inactive(_plugin)
  current_site.attack.destroy_all
end