Module: Plugins::Attack::AttackHelper

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

Instance Method Summary collapse

Instance Method Details

#attack_app_before_loadObject



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

def attack_app_before_load
  cache_ban = Rails.cache.read(attack_ban_cache_key)
  if cache_ban.present? # render banned message if it was banned
    render html: cache_ban.to_s, 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
# 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.zone.now.iso8601 })

  ActiveRecord::Base.connection.create_table :plugins_attacks, if_not_exists: true do |t|
    t.string :path, index: true
    t.string :browser_key, index: true
    t.belongs_to :site, index: true
    t.datetime 'created_at'
  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 the plugin are destroyed 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



34
35
36
# File 'app/apps/plugins/attack/attack_helper.rb', line 34

def attack_on_inactive(_plugin)
  current_site.attack.destroy_all
end