module EhcReport
EhcReport โ IRC card formatting for CTF website recon results. Public: TAG, TITLE, format_success, format_usage, format_unsafe_url, format_fetch_error, format_ai_error, format_denial Depends: EhcUrl, IrcReply Tests: test/lib/ehc_report_test.rb
Constants
- FOOTER_HINT
- MAX_TOOLKIT_BODY_LINES
- TAG
- TITLE
- TOOLKIT_TITLE
Public Instance Methods
Source
# File lib/ehc_report.rb, line 94 def challenge_label(challenge) data = challenge.is_a?(Hash) ? challenge : {} index = data[:index] || data["index"] title = (data[:title] || data["title"]).to_s.strip return nil if index.nil? || title.empty? "##{index} #{title}" end
Source
# File lib/ehc_report.rb, line 90 def focus_label(focus) "focus: #{focus.to_s.strip}" end
Source
# File lib/ehc_report.rb, line 67 def format_ai_error(message) IrcReply.error(tag: TAG, message: message.to_s.strip) end
Source
# File lib/ehc_report.rb, line 103 def format_denial(message) IrcReply.error(tag: TAG, message: message.to_s.strip) end
Source
# File lib/ehc_report.rb, line 83 def format_eh_fetch_error IrcReply.error( tag: TAG, message: "Could not load !eh challenge list โ CTFtime unavailable. Try again later or use a direct URL." ) end
Source
# File lib/ehc_report.rb, line 71 def format_eh_not_found(index:, listed:) IrcReply.card( tag: TAG, title: TITLE, body_lines: [ "Challenge ##{index} not found.", "Pick a number from 1 to #{listed} after !eh list." ], footer_parts: [FOOTER_HINT] ) end
Source
# File lib/ehc_report.rb, line 52 def format_fetch_error(url, detail: nil) message = "Could not fetch #{url} โ check the URL and try again." detail_text = detail.to_s.strip if detail_text.empty? IrcReply.error(tag: TAG, message: message) else IrcReply.card( tag: TAG, title: "error", body_lines: [message, detail_text] ) end end
Source
# File lib/ehc_report.rb, line 21 def format_success(host:, probe_lines:, ai_lines:, model:, duration_s:, focus: nil, challenge: nil) body_lines = [] body_lines.concat(Array(probe_lines).first(3)) body_lines.concat(Array(ai_lines).first(3)) footer_parts = [host, model, "#{duration_s}s"] footer_parts << focus_label(focus) if focus && !focus.to_s.strip.empty? footer_parts << challenge_label(challenge) if challenge footer_parts << FOOTER_HINT IrcReply.card( tag: TAG, title: TITLE, body_lines: body_lines, footer_parts: footer_parts ) end
Source
# File lib/ehc_report.rb, line 107 def format_toolkit(audit:, install_cmd: nil, pacman_ok: true) rows = Array(audit) total = rows.length installed_count = rows.count { |row| row[:installed] == true } missing = rows.select { |row| row[:installed] == false } installed = rows.select { |row| row[:installed] == true } body_lines = if !pacman_ok [ "pacman status unknown โ run recommended installs manually.", install_cmd.to_s.strip ].reject(&:empty?) elsif missing.empty? ["All toolkit packages installed on this host."] else max = MAX_TOOLKIT_BODY_LINES installed_slots = installed.empty? ? 0 : [installed.length, max].min missing_slots = max - installed_slots lines = missing.first(missing_slots).map do |row| "#{row[:name]} โ missing ยท pacman -S #{row[:name]}" end installed.first(installed_slots).each do |row| lines << "#{row[:name]} โ installed" end lines end footer_parts = [] footer_parts << if pacman_ok "#{installed_count}/#{total} installed" else "status unknown" end footer_parts << "CachyOS pacman" footer_parts << install_cmd if install_cmd && !install_cmd.to_s.strip.empty? && pacman_ok && missing.any? footer_parts << FOOTER_HINT IrcReply.card( tag: TAG, title: TOOLKIT_TITLE, body_lines: body_lines, footer_parts: footer_parts ) end
Source
# File lib/ehc_report.rb, line 48 def format_unsafe_url IrcReply.error(tag: TAG, message: EhcUrl.unsafe_message) end
Source
# File lib/ehc_report.rb, line 39 def format_usage IrcReply.card( tag: TAG, title: TITLE, body_lines: [EhcUrl.usage_message], footer_parts: [FOOTER_HINT] ) end