module EhcHarden
EhcHarden — admin toolkit scans with numbered issue detail lookups. Public: dispatch_scan, dispatch_issue, scan, issue_detail, admin_denial_result Depends: EhcFetch, EhcHardenProbe, EhcHardenReport, EhcHardenRunner, EhcHardenStore, EhcHardenTarget Tests: test/lib/ehc_harden_test.rb, test/plugins/ehc_test.rb
Public Instance Methods
Source
# File lib/ehc_harden.rb, line 115 def admin_denial_result { success: false, reply: EhcHardenReport.format_denial } end
Source
# File lib/ehc_harden.rb, line 119 def assign_ids(issues) Array(issues).each_with_index.map do |row, index| row.merge(id: index + 1) end end
Source
# File lib/ehc_harden.rb, line 38 def dispatch_issue(args:, network:, channel:, admin_allowed: false, store: RabbotDb) return admin_denial_result unless admin_allowed match = args.to_s.strip.match(/\Aissue\s+(\d+)\z/i) return { success: false, reply: EhcReport.format_usage } unless match issue_detail( issue_id: match[1].to_i, network: network, channel: channel, store: store ) end
Source
# File lib/ehc_harden.rb, line 19 def dispatch_scan(args:, network:, channel:, channel_users: nil, admin_allowed: false, fetch: nil, pacman: nil, runner: nil, store: RabbotDb) return admin_denial_result unless admin_allowed target = EhcHardenTarget.resolve(args: args, channel_users: channel_users, admin: true) return admin_denial_result unless target[:harden_target] return { success: false, reply: EhcHardenReport.format_target_error(target[:error]) } if target[:error] scan( target: target, network: network, channel: channel, fetch: fetch, pacman: pacman, runner: runner, store: store ) end
Source
# File lib/ehc_harden.rb, line 125 def fetch_robots_body(url, fetch:) robots_url = EhcFetch.robots_url(url) return nil if robots_url.nil? response = EhcFetch.fetch(robots_url, fetch: fetch) return nil if response[:error] body = response[:body].to_s body.strip.empty? ? nil : body rescue StandardError nil end
Source
# File lib/ehc_harden.rb, line 94 def issue_detail(issue_id:, network:, channel:, store: RabbotDb) row = EhcHardenStore.find_issue( network: network, channel: channel, issue_id: issue_id, store: store ) unless row return { success: false, reply: EhcHardenReport.format_issue_not_found(issue_id: issue_id) } end data = EhcHardenStore.load_scan(network: network, channel: channel, store: store) { success: true, reply: EhcHardenReport.format_issue(issue: row, label: data["label"]) } end
Source
# File lib/ehc_harden.rb, line 52 def scan(target:, network:, channel:, fetch: nil, pacman: nil, runner: nil, store: RabbotDb) url = target[:url] host = target[:host] label = target[:label] http_fetch = fetch || EhcFetch.default_fetch page = EhcFetch.fetch(url, fetch: http_fetch) if page[:error] return { success: false, reply: EhcReport.format_fetch_error(url, detail: page[:error]) } end robots_body = fetch_robots_body(url, fetch: http_fetch) passive = EhcHardenProbe.analyze(page: page, url: url, robots_body: robots_body) active = EhcHardenRunner.run_active( host: host, url: url, https: url.to_s.match?(%r{\Ahttps://}i), pacman: pacman, runner: runner ) issues = assign_ids(passive + active) EhcHardenStore.save_scan( network: network, channel: channel, scan: { target: host, label: label, issues: issues }, store: store ) { success: true, reply: EhcHardenReport.format_summary(label: label, issues: issues) } end