module EhcUrl
EhcUrl — parse !ehc command arguments and normalize target URLs. Public: usage_message, parse_command, host_from_url, safe_url? Depends: AiUrlContext, UrlLink Tests: test/lib/ehc_url_test.rb
Public Instance Methods
Source
# File lib/ehc_url.rb, line 46 def host_from_url(url) host = URI.parse(url.to_s).host.to_s host.sub(/\Awww\./, "") rescue URI::InvalidURIError "" end
Source
# File lib/ehc_url.rb, line 28 def parse_command(text) stripped = text.to_s.strip return { error: usage_message } if stripped.empty? unless (match = stripped.match(%r{\A(https?://\S+)(?:\s+(.+))?\z}i)) return { error: usage_message } end url = UrlLink.normalize_url(match[1]) return { error: usage_message } unless UrlLink.valid_url?(url) return { error: unsafe_message } unless safe_url?(url) focus = match[2]&.strip focus = nil if focus&.empty? { url: url, focus: focus, host: host_from_url(url) } end
Source
# File lib/ehc_url.rb, line 24 def safe_url?(url) AiUrlContext.safe_url?(url) end
Source
# File lib/ehc_url.rb, line 20 def unsafe_message "That URL is not allowed — use http(s) public targets only." end
Source
# File lib/ehc_url.rb, line 16 def usage_message "Usage: !ehc <url|#|ip|nick> [focus] | !ehc toolkit | !ehc issue <n> — CTF recon (voice+) or server harden (admin+)" end