Skip to content

Commit 6beab19

Browse files
committed
Extracted CLI::Text from CLI::Printing (closes #189).
1 parent 0715750 commit 6beab19

File tree

4 files changed

+405
-354
lines changed

4 files changed

+405
-354
lines changed

Diff for: lib/ronin/recon/cli/printing.rb

+2-65
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# along with ronin-recon. If not, see <https://www.gnu.org/licenses/>.
1919
#
2020

21-
require_relative '../values'
21+
require_relative 'text'
2222

2323
require 'ronin/core/cli/logging'
2424

@@ -29,72 +29,9 @@ class CLI
2929
# Helper methods for printing {Values Value} objects.
3030
#
3131
module Printing
32+
include Text
3233
include Core::CLI::Logging
3334

34-
# Mapping of {Value} classes to printable names.
35-
VALUE_CLASS_NAMES = {
36-
Values::Domain => 'domain',
37-
Values::Mailserver => 'mailserver',
38-
Values::Nameserver => 'nameserver',
39-
Values::Wildcard => 'wildcard host name',
40-
Values::Host => 'host',
41-
Values::IP => 'IP address',
42-
Values::IPRange => 'IP range',
43-
Values::OpenPort => 'open port',
44-
Values::Cert => 'SSL/TLS certificate',
45-
Values::Website => 'website',
46-
Values::URL => 'URL',
47-
Values::EmailAddress => 'email addresse'
48-
}
49-
50-
#
51-
# Converts the value class into a printable name.
52-
#
53-
# @param [Class<Value>] value_class
54-
# The value class.
55-
#
56-
# @return [String]
57-
# The descriptive name for the value class.
58-
#
59-
# @raise [NotImplementedError]
60-
#
61-
def value_class_name(value_class)
62-
VALUE_CLASS_NAMES.fetch(value_class) do
63-
raise(NotImplementedError,"unknown value class: #{value_class.inspect}")
64-
end
65-
end
66-
67-
#
68-
# Formats a value object into a human readable string.
69-
#
70-
# @param [Value] value
71-
# The value object to format.
72-
#
73-
# @return [String]
74-
# The formatted value.
75-
#
76-
# @raise [NotImplementedError]
77-
# The given value object was not supported.
78-
#
79-
def format_value(value)
80-
case value
81-
when Values::Domain then "domain #{value}"
82-
when Values::Mailserver then "mailserver #{value}"
83-
when Values::Nameserver then "nameserver #{value}"
84-
when Values::Wildcard then "wildcard host name #{value}"
85-
when Values::Host then "host #{value}"
86-
when Values::IP then "IP address #{value}"
87-
when Values::IPRange then "IP range #{value}"
88-
when Values::OpenPort then "open #{value.protocol.upcase} port #{value}"
89-
when Values::Cert then "SSL/TLS certificate #{value.subject}"
90-
when Values::Website then "website #{value}"
91-
when Values::URL then "URL #{value}"
92-
when Values::EmailAddress then "email address #{value}"
93-
else
94-
raise(NotImplementedError,"value class #{value.class} not supported")
95-
end
96-
end
97-
9835
#
9936
# Prints a newly discovered value.
10037
#

Diff for: lib/ronin/recon/cli/text.rb

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# frozen_string_literal: true
2+
#
3+
# ronin-recon - A micro-framework and tool for performing reconnaissance.
4+
#
5+
# Copyright (c) 2023-2025 Hal Brodigan ([email protected])
6+
#
7+
# ronin-recon is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU Lesser General Public License as published
9+
# by the Free Software Foundation, either version 3 of the License, or
10+
# (at your option) any later version.
11+
#
12+
# ronin-recon is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU Lesser General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU Lesser General Public License
18+
# along with ronin-recon. If not, see <https://www.gnu.org/licenses/>.
19+
#
20+
21+
require_relative '../values'
22+
23+
module Ronin
24+
module Recon
25+
class CLI
26+
#
27+
# Helper methods for generating display text.
28+
#
29+
# @since 0.2.0
30+
#
31+
module Text
32+
# Mapping of {Value} classes to printable names.
33+
VALUE_CLASS_NAMES = {
34+
Values::Domain => 'domain',
35+
Values::Mailserver => 'mailserver',
36+
Values::Nameserver => 'nameserver',
37+
Values::Wildcard => 'wildcard host name',
38+
Values::Host => 'host',
39+
Values::IP => 'IP address',
40+
Values::IPRange => 'IP range',
41+
Values::OpenPort => 'open port',
42+
Values::Cert => 'SSL/TLS certificate',
43+
Values::Website => 'website',
44+
Values::URL => 'URL',
45+
Values::EmailAddress => 'email addresse'
46+
}
47+
48+
#
49+
# Converts the value class into a printable name.
50+
#
51+
# @param [Class<Value>] value_class
52+
# The value class.
53+
#
54+
# @return [String]
55+
# The descriptive name for the value class.
56+
#
57+
# @raise [NotImplementedError]
58+
#
59+
def value_class_name(value_class)
60+
VALUE_CLASS_NAMES.fetch(value_class) do
61+
raise(NotImplementedError,"unknown value class: #{value_class.inspect}")
62+
end
63+
end
64+
65+
#
66+
# Formats a value object into a human readable string.
67+
#
68+
# @param [Value] value
69+
# The value object to format.
70+
#
71+
# @return [String]
72+
# The formatted value.
73+
#
74+
# @raise [NotImplementedError]
75+
# The given value object was not supported.
76+
#
77+
def format_value(value)
78+
case value
79+
when Values::Domain then "domain #{value}"
80+
when Values::Mailserver then "mailserver #{value}"
81+
when Values::Nameserver then "nameserver #{value}"
82+
when Values::Wildcard then "wildcard host name #{value}"
83+
when Values::Host then "host #{value}"
84+
when Values::IP then "IP address #{value}"
85+
when Values::IPRange then "IP range #{value}"
86+
when Values::OpenPort then "open #{value.protocol.upcase} port #{value}"
87+
when Values::Cert then "SSL/TLS certificate #{value.subject}"
88+
when Values::Website then "website #{value}"
89+
when Values::URL then "URL #{value}"
90+
when Values::EmailAddress then "email address #{value}"
91+
else
92+
raise(NotImplementedError,"value class #{value.class} not supported")
93+
end
94+
end
95+
end
96+
end
97+
end
98+
end

0 commit comments

Comments
 (0)