Class: ActionView::Helpers::InstanceTag
- Inherits:
-
Object
- Object
- ActionView::Helpers::InstanceTag
- Defined in:
- lib/bot-away/action_view/helpers/instance_tag.rb
Instance Attribute Summary collapse
- #honeypot_index ⇒ Object
-
#spinner ⇒ Object
readonly
Returns the value of attribute spinner.
Instance Method Summary collapse
- #assuming(object) ⇒ Object
- #content_tag_with_obfuscation(name, content_or_options_with_block = nil, options = nil, *args, &block) ⇒ Object
- #disguise(element) ⇒ Object
- #honeypot_options(options) ⇒ Object
- #honeypot_tag(name, options = nil, *args) ⇒ Object
- #honeypot_warning_message ⇒ Object
- #honeypot_warning_tag ⇒ Object
- #initialize_with_spinner(object_name, method_name, template_object, object = nil) ⇒ Object
- #obfuscate_options(options) ⇒ Object
- #obfuscated_tag(name, options = nil, *args) ⇒ Object
- #tag_with_honeypot(name, options = nil, *args) ⇒ Object
-
#to_label_tag_with_obfuscation(text = nil, options = {}, &block) ⇒ Object
Special case.
Instance Attribute Details
#honeypot_index ⇒ Object
113 114 115 |
# File 'lib/bot-away/action_view/helpers/instance_tag.rb', line 113 def honeypot_index @honeypot_index || rand(I18n.t("bot_away.number_of_honeypot_warning_messages").to_i) + 1 end |
#spinner ⇒ Object (readonly)
Returns the value of attribute spinner.
2 3 4 |
# File 'lib/bot-away/action_view/helpers/instance_tag.rb', line 2 def spinner @spinner end |
Instance Method Details
#assuming(object) ⇒ Object
33 34 35 36 |
# File 'lib/bot-away/action_view/helpers/instance_tag.rb', line 33 def assuming(object) yield if object object end |
#content_tag_with_obfuscation(name, content_or_options_with_block = nil, options = nil, *args, &block) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/bot-away/action_view/helpers/instance_tag.rb', line 76 def content_tag_with_obfuscation(name, = nil, = nil, *args, &block) if block_given? content_tag_without_obfuscation(name, , , *args, &block) else # this should cover all Rails selects. if spinner && && (.keys.include?('id') || .keys.include?('name')) if name == 'select' && !.empty? content = '<option selected value=""></option>'.html_safe else content = "" end disguise(content_tag_without_obfuscation(name, content, (), *args)) + content_tag_without_obfuscation(name, , (), *args) else content_tag_without_obfuscation(name, , , *args) end end end |
#disguise(element) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/bot-away/action_view/helpers/instance_tag.rb', line 100 def disguise(element) return element.replace("Honeypot(#{element})") if BotAway.show_honeypots # TODO a way to customize the hidden tags too case honeypot_index % 3 when 0 # Hidden element.replace "<div style='display:none;'>#{honeypot_warning_tag}#{element}</div>" when 1 # Off-screen element.replace "<div style='position:absolute;left:-1000px;top:-1000px;'>#{honeypot_warning_tag}#{element}</div>" else # Negligible size element.replace "<div style='position:absolute;width:0px;height:1px;z-index:-1;color:transparent;overflow:hidden;'>#{honeypot_warning_tag}#{element}</div>" end end |
#honeypot_options(options) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/bot-away/action_view/helpers/instance_tag.rb', line 24 def () add_default_name_and_id() assuming(spinner && ) do ['value'] &&= '' ['autocomplete'] = 'off' ['tabindex'] = -rand(10) - 1 end end |
#honeypot_tag(name, options = nil, *args) ⇒ Object
38 39 40 |
# File 'lib/bot-away/action_view/helpers/instance_tag.rb', line 38 def honeypot_tag(name, = nil, *args) disguise tag_without_honeypot(name, ( ? .dup : {}), *args) end |
#honeypot_warning_message ⇒ Object
117 118 119 120 121 122 123 124 |
# File 'lib/bot-away/action_view/helpers/instance_tag.rb', line 117 def warning = I18n.t "bot_away.honeypot_warning_#{honeypot_index}" if BotAway. warning.reverse.chars.collect { |b| "&#x#{b.ord.to_s(16)};" }.join else warning.html_safe end end |
#honeypot_warning_tag ⇒ Object
126 127 128 129 130 131 132 |
# File 'lib/bot-away/action_view/helpers/instance_tag.rb', line 126 def honeypot_warning_tag if BotAway. "<bdo dir=\"rtl\">#{}</bdo>".html_safe else end end |
#initialize_with_spinner(object_name, method_name, template_object, object = nil) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/bot-away/action_view/helpers/instance_tag.rb', line 5 def initialize_with_spinner(object_name, method_name, template_object, object = nil) initialize_without_spinner(object_name, method_name, template_object, object) if template_object.controller.send(:protect_against_forgery?) && !BotAway.excluded?(:object_name => object_name, :method_name => method_name) && !BotAway.excluded?(:controller => template_object.controller.controller_name, :action => template_object.controller.action_name) @spinner = BotAway::Spinner.new(template_object.request.ip, object_name, template_object.form_authenticity_token) end end |
#obfuscate_options(options) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/bot-away/action_view/helpers/instance_tag.rb', line 16 def () add_default_name_and_id() assuming(spinner && ) do ['name'] &&= spinner.encode(['name']) ['id'] &&= spinner.encode(['id']) end end |
#obfuscated_tag(name, options = nil, *args) ⇒ Object
42 43 44 |
# File 'lib/bot-away/action_view/helpers/instance_tag.rb', line 42 def (name, = nil, *args) tag_without_honeypot(name, ( ? .dup : {}), *args) end |
#tag_with_honeypot(name, options = nil, *args) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/bot-away/action_view/helpers/instance_tag.rb', line 46 def tag_with_honeypot(name, = nil, *args) if spinner (name, , *args) + honeypot_tag(name, , *args) else tag_without_honeypot(name, , *args) end end |
#to_label_tag_with_obfuscation(text = nil, options = {}, &block) ⇒ Object
Special case
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/bot-away/action_view/helpers/instance_tag.rb', line 55 def to_label_tag_with_obfuscation(text = nil, = {}, &block) # TODO: Can this be simplified? It's pretty similar to to_label_tag_without_obfuscation... = .stringify_keys tag_value = .delete("value") name_and_id = .dup if name_and_id["for"] name_and_id["id"] = name_and_id["for"] else name_and_id.delete("id") end add_default_name_and_id_for_value(tag_value, name_and_id) ["for"] ||= name_and_id["id"] ["for"] = spinner.encode(["for"]) if spinner && ["for"] # TODO ideas for future implementation, but they may break nested tags # escaped_reversed_text = text.to_s.reverse.chars.collect { |b| "&#x#{b.ord.to_s(16)};" }.join # text = '<bdo dir="rtl">'.html_safe + escaped_reversed_text + '</bdo>'.html_safe to_label_tag_without_obfuscation(text, ) end |