ronin-web 0.3.0.rc1 → 1.0.0.beta2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +11 -0
  3. data/.github/workflows/ruby.yml +31 -0
  4. data/.gitignore +13 -0
  5. data/.mailmap +1 -0
  6. data/.ruby-version +1 -0
  7. data/COPYING.txt +3 -3
  8. data/ChangeLog.md +115 -70
  9. data/Gemfile +42 -37
  10. data/README.md +160 -145
  11. data/Rakefile +12 -3
  12. data/bin/ronin-web +9 -17
  13. data/data/new/nokogiri.rb.erb +12 -0
  14. data/data/new/server.rb.erb +22 -0
  15. data/data/new/spider.rb.erb +26 -0
  16. data/data/new/webapp/.gitignore +15 -0
  17. data/data/new/webapp/.ruby-version.erb +1 -0
  18. data/data/new/webapp/Dockerfile.erb +11 -0
  19. data/data/new/webapp/Gemfile +6 -0
  20. data/data/new/webapp/app.rb.erb +15 -0
  21. data/data/new/webapp/config.ru +4 -0
  22. data/data/new/webapp/docker-compose.yml.erb +9 -0
  23. data/gemspec.yml +38 -16
  24. data/lib/ronin/web/cli/command.rb +36 -0
  25. data/lib/ronin/web/cli/commands/diff.rb +106 -0
  26. data/lib/ronin/web/cli/commands/html.rb +174 -0
  27. data/lib/ronin/web/cli/commands/irb.rb +56 -0
  28. data/lib/ronin/web/cli/commands/new/nokogiri.rb +85 -0
  29. data/lib/ronin/web/cli/commands/new/server.rb +96 -0
  30. data/lib/ronin/web/cli/commands/new/spider.rb +315 -0
  31. data/lib/ronin/web/cli/commands/new/webapp.rb +123 -0
  32. data/lib/ronin/web/cli/commands/new.rb +64 -0
  33. data/lib/ronin/web/cli/commands/reverse_proxy.rb +215 -0
  34. data/lib/ronin/web/cli/commands/server.rb +155 -0
  35. data/lib/ronin/web/cli/commands/spider.rb +822 -0
  36. data/lib/ronin/web/cli/ruby_shell.rb +50 -0
  37. data/lib/ronin/web/cli.rb +49 -0
  38. data/lib/ronin/web/html.rb +85 -0
  39. data/lib/ronin/web/mechanize.rb +34 -36
  40. data/lib/ronin/web/root.rb +27 -0
  41. data/lib/ronin/web/version.rb +7 -10
  42. data/lib/ronin/web/xml.rb +85 -0
  43. data/lib/ronin/web.rb +372 -13
  44. data/man/ronin-web-diff.1 +41 -0
  45. data/man/ronin-web-diff.1.md +30 -0
  46. data/man/ronin-web-html.1 +89 -0
  47. data/man/ronin-web-html.1.md +66 -0
  48. data/man/ronin-web-irb.1 +31 -0
  49. data/man/ronin-web-irb.1.md +22 -0
  50. data/man/ronin-web-new-nokogiri.1 +41 -0
  51. data/man/ronin-web-new-nokogiri.1.md +30 -0
  52. data/man/ronin-web-new-server.1 +45 -0
  53. data/man/ronin-web-new-server.1.md +33 -0
  54. data/man/ronin-web-new-spider.1 +173 -0
  55. data/man/ronin-web-new-spider.1.md +129 -0
  56. data/man/ronin-web-new-webapp.1 +53 -0
  57. data/man/ronin-web-new-webapp.1.md +39 -0
  58. data/man/ronin-web-new.1 +59 -0
  59. data/man/ronin-web-new.1.md +44 -0
  60. data/man/ronin-web-reverse-proxy.1 +63 -0
  61. data/man/ronin-web-reverse-proxy.1.md +47 -0
  62. data/man/ronin-web-server.1 +59 -0
  63. data/man/ronin-web-server.1.md +43 -0
  64. data/man/ronin-web-spider.1 +225 -0
  65. data/man/ronin-web-spider.1.md +168 -0
  66. data/man/ronin-web.1 +41 -0
  67. data/man/ronin-web.1.md +30 -0
  68. data/ronin-web.gemspec +39 -109
  69. data/spec/cli/ruby_shell_spec.rb +14 -0
  70. data/spec/html_spec.rb +43 -0
  71. data/spec/mechanize_spec.rb +72 -0
  72. data/spec/spec_helper.rb +5 -3
  73. data/spec/web_spec.rb +97 -0
  74. data/spec/xml_spec.rb +42 -0
  75. metadata +236 -224
  76. data/.gemtest +0 -0
  77. data/data/ronin/web/user_agents.yml +0 -247
  78. data/lib/ronin/network/mixins/web.rb +0 -258
  79. data/lib/ronin/web/config.rb +0 -34
  80. data/lib/ronin/web/extensions/nokogiri/xml/attr.rb +0 -47
  81. data/lib/ronin/web/extensions/nokogiri/xml/document.rb +0 -48
  82. data/lib/ronin/web/extensions/nokogiri/xml/element.rb +0 -57
  83. data/lib/ronin/web/extensions/nokogiri/xml/node.rb +0 -86
  84. data/lib/ronin/web/extensions/nokogiri/xml/text.rb +0 -47
  85. data/lib/ronin/web/extensions/nokogiri/xml.rb +0 -27
  86. data/lib/ronin/web/extensions/nokogiri.rb +0 -23
  87. data/lib/ronin/web/extensions.rb +0 -23
  88. data/lib/ronin/web/middleware/base.rb +0 -144
  89. data/lib/ronin/web/middleware/directories.rb +0 -179
  90. data/lib/ronin/web/middleware/files.rb +0 -144
  91. data/lib/ronin/web/middleware/filters/campaign_filter.rb +0 -77
  92. data/lib/ronin/web/middleware/filters/ip_filter.rb +0 -73
  93. data/lib/ronin/web/middleware/filters/path_filter.rb +0 -73
  94. data/lib/ronin/web/middleware/filters/referer_filter.rb +0 -71
  95. data/lib/ronin/web/middleware/filters/user_agent_filter.rb +0 -71
  96. data/lib/ronin/web/middleware/filters/vhost_filter.rb +0 -71
  97. data/lib/ronin/web/middleware/filters.rb +0 -28
  98. data/lib/ronin/web/middleware/helpers.rb +0 -145
  99. data/lib/ronin/web/middleware/proxy.rb +0 -265
  100. data/lib/ronin/web/middleware/proxy_request.rb +0 -262
  101. data/lib/ronin/web/middleware/request.rb +0 -79
  102. data/lib/ronin/web/middleware/response.rb +0 -33
  103. data/lib/ronin/web/middleware/router.rb +0 -167
  104. data/lib/ronin/web/middleware/rule.rb +0 -103
  105. data/lib/ronin/web/middleware.rb +0 -27
  106. data/lib/ronin/web/proxy/app.rb +0 -32
  107. data/lib/ronin/web/proxy/base.rb +0 -46
  108. data/lib/ronin/web/proxy/web.rb +0 -46
  109. data/lib/ronin/web/proxy.rb +0 -25
  110. data/lib/ronin/web/server/app.rb +0 -32
  111. data/lib/ronin/web/server/base.rb +0 -461
  112. data/lib/ronin/web/server/web.rb +0 -66
  113. data/lib/ronin/web/server.rb +0 -25
  114. data/lib/ronin/web/spider.rb +0 -120
  115. data/lib/ronin/web/user_agents.rb +0 -196
  116. data/lib/ronin/web/web.rb +0 -560
  117. data/spec/helpers/output.rb +0 -3
  118. data/spec/web/extensions/nokogiri_spec.rb +0 -38
  119. data/spec/web/helpers/rack_app.rb +0 -24
  120. data/spec/web/helpers/root/test1/index.html +0 -1
  121. data/spec/web/helpers/root/test1/test1.txt +0 -1
  122. data/spec/web/helpers/root/test1.txt +0 -1
  123. data/spec/web/helpers/root/test2/test2.txt +0 -1
  124. data/spec/web/helpers/root/test2.txt +0 -1
  125. data/spec/web/helpers/root/test3/test3.txt +0 -1
  126. data/spec/web/helpers/root/test3.txt +0 -1
  127. data/spec/web/helpers/root.rb +0 -15
  128. data/spec/web/mechanize_spec.rb +0 -62
  129. data/spec/web/middleware/directories_spec.rb +0 -86
  130. data/spec/web/middleware/files_spec.rb +0 -57
  131. data/spec/web/middleware/filters/campaign_filter_spec.rb +0 -30
  132. data/spec/web/middleware/filters/ip_filter_spec.rb +0 -25
  133. data/spec/web/middleware/filters/path_filter_spec.rb +0 -29
  134. data/spec/web/middleware/filters/referer_filter_spec.rb +0 -25
  135. data/spec/web/middleware/filters/user_agent_filter_spec.rb +0 -25
  136. data/spec/web/middleware/filters/vhost_filter_spec.rb +0 -23
  137. data/spec/web/middleware/proxy_spec.rb +0 -67
  138. data/spec/web/middleware/response_spec.rb +0 -20
  139. data/spec/web/middleware/router_spec.rb +0 -65
  140. data/spec/web/middleware/rule_spec.rb +0 -37
  141. data/spec/web/proxy/base_spec.rb +0 -8
  142. data/spec/web/server/base_spec.rb +0 -77
  143. data/spec/web/server/classes/public1/static1.txt +0 -1
  144. data/spec/web/server/classes/public2/static2.txt +0 -1
  145. data/spec/web/server/classes/sub_app.rb +0 -13
  146. data/spec/web/server/classes/test_app.rb +0 -20
  147. data/spec/web/user_agents_spec.rb +0 -56
  148. data/spec/web/web_spec.rb +0 -101
@@ -0,0 +1,106 @@
1
+ #
2
+ # ronin-web - A collection of useful web helper methods and commands.
3
+ #
4
+ # Copyright (c) 2006-2023 Hal Brodigan (postmodern.mod3 at gmail.com)
5
+ #
6
+ # ronin-web is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # ronin-web is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with ronin-web. If not, see <https://www.gnu.org/licenses/>.
18
+ #
19
+
20
+ require 'ronin/web/cli/command'
21
+ require 'ronin/support/network/http'
22
+
23
+ require 'command_kit/terminal'
24
+ require 'nokogiri/diff'
25
+
26
+ module Ronin
27
+ module Web
28
+ class CLI
29
+ module Commands
30
+ #
31
+ # Diffs two web pages.
32
+ #
33
+ # ## Usage
34
+ #
35
+ # ronin-web diff [options] {URL | FILE} {URL | FILE}
36
+ #
37
+ # ## Arguments
38
+ #
39
+ # URL | FILE The original URL or file
40
+ # URL | FILE The modified URL or file
41
+ #
42
+ # ## Options
43
+ #
44
+ # -h, --help Print help information
45
+ #
46
+ class Diff < Command
47
+
48
+ include CommandKit::Terminal
49
+
50
+ usage '[options] {URL | FILE} {URL | FILE}'
51
+
52
+ argument :page1, required: true,
53
+ usage: 'URL | FILE',
54
+ desc: 'The original URL or file'
55
+
56
+ argument :page2, required: true,
57
+ usage: 'URL | FILE',
58
+ desc: 'The modified URL or file'
59
+
60
+ description 'Diffs two web pges'
61
+
62
+ man_page 'ronin-web-diff.1'
63
+
64
+ #
65
+ # Runs the `ronin-web diff` command.
66
+ #
67
+ # @param [String] page1
68
+ # The URL or file path of the original page.
69
+ #
70
+ # @param [String] page2
71
+ # The URL or file path of the modified page.
72
+ #
73
+ def run(page1,page2)
74
+ doc1 = Nokogiri::HTML(read(page1))
75
+ doc2 = Nokogiri::HTML(read(page2))
76
+
77
+ doc1.diff(doc2) do |change,node|
78
+ unless change == ' '
79
+ puts "#{change} #{node}"
80
+ end
81
+ end
82
+ end
83
+
84
+ #
85
+ # Reads a web page.
86
+ #
87
+ # @param [String] source
88
+ # The URL or file path of the web page.
89
+ #
90
+ # @return [String, File]
91
+ # The contents of the web page.
92
+ #
93
+ def read(source)
94
+ if source.start_with?('https://') ||
95
+ source.start_with?('http://')
96
+ Support::Network::HTTP.get_body(source)
97
+ else
98
+ File.new(source)
99
+ end
100
+ end
101
+
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,174 @@
1
+ #
2
+ # ronin-web - A collection of useful web helper methods and commands.
3
+ #
4
+ # Copyright (c) 2006-2023 Hal Brodigan (postmodern.mod3 at gmail.com)
5
+ #
6
+ # ronin-web is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # ronin-web is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with ronin-web. If not, see <https://www.gnu.org/licenses/>.
18
+ #
19
+
20
+ require 'ronin/web/cli/command'
21
+ require 'ronin/support/network/http'
22
+
23
+ require 'nokogiri'
24
+
25
+ module Ronin
26
+ module Web
27
+ class CLI
28
+ module Commands
29
+ #
30
+ # Performs XPath/CSS-path queries on a URL or HTML file.
31
+ #
32
+ # ## Usage
33
+ #
34
+ # ronin-web html [options] {URL | FILE} [XPATH | CSS-path]
35
+ #
36
+ # ## Options
37
+ #
38
+ # -X, --xpath XPATH XPath query
39
+ # -C, --css-path CSSPath CSS-path query
40
+ # -M, --meta-tags Searches for all <meta ...> tags
41
+ # -l, --links Searches for all <a href="..."> URLs
42
+ # -S, --style Dumps all <style> tags
43
+ # -s, --stylesheet-urls Searches for all <link type="text/css" href="..."/> URLs
44
+ # -J, --javascript Dumps all javascript source code
45
+ # -j, --javascript-urls Searches for all <script src="..."> URLs
46
+ # -f, --form-urls Searches for all <form action="..."> URLS
47
+ # -u, --urls Dumps all URLs in the page
48
+ # -F, --first Only print the first match
49
+ # -h, --help Print help information
50
+ #
51
+ # ## Arguments
52
+ #
53
+ # URL | FILE The URL or FILE to search
54
+ # [XPATH | CSS-path] The XPath or CSS-path query
55
+ #
56
+ class Html < Command
57
+
58
+ usage '[options] {URL | FILE} [XPATH | CSS-path]'
59
+
60
+ option :xpath, short: '-X',
61
+ value: {type: String, usage: 'XPATH'},
62
+ desc: 'XPath query' do |xpath|
63
+ @query = xpath
64
+ end
65
+
66
+ option :css_path, short: '-C',
67
+ value: {type: String, usage: 'CSSPath'},
68
+ desc: 'CSS-path query' do |css_path|
69
+ @query = css_path
70
+ end
71
+
72
+ option :meta_tags, short: '-M',
73
+ desc: 'Searches for all <meta ...> tags' do
74
+ @query = '//meta'
75
+ end
76
+
77
+ option :links, short: '-l',
78
+ desc: 'Searches for all <a href="..."> URLs' do
79
+ @query = '//a/@href'
80
+ end
81
+
82
+ option :style, short: '-S',
83
+ desc: 'Dumps all <style> tags' do
84
+ @query = '//style/text()'
85
+ end
86
+
87
+ option :stylesheet_urls, short: '-s',
88
+ desc: 'Searches for all <link type="text/css" href="..."/> URLs' do
89
+ @query = '//link[@rel="stylesheet"]/@href'
90
+ end
91
+
92
+ option :javascript, short: '-J',
93
+ desc: 'Dumps all javascript source code' do
94
+ @query = '//script/text()'
95
+ end
96
+
97
+ option :javascript_urls, short: '-j',
98
+ desc: 'Searches for all <script src="..."> URLs' do
99
+ @query = '//script/@src'
100
+ end
101
+
102
+ option :form_urls, short: '-f',
103
+ desc: 'Searches for all <form action="..."> URLS' do
104
+ @query = '//form/@action'
105
+ end
106
+
107
+ option :urls, short: '-u',
108
+ desc: 'Dumps all URLs in the page' do
109
+ @query = '//a/@href | //link/@href | //script/@src | //form/@action'
110
+ end
111
+
112
+ option :first, short: '-F',
113
+ desc: 'Only print the first match'
114
+
115
+ argument :source, required: true,
116
+ usage: 'URL | FILE',
117
+ desc: 'The URL or FILE to search'
118
+
119
+ argument :query, required: false,
120
+ usage: 'XPATH | CSS-path',
121
+ desc: 'The XPath or CSS-path query'
122
+
123
+ description 'Performs XPath/CSS-path queries on a URL or HTML file'
124
+
125
+ man_page 'ronin-web-html.1'
126
+
127
+ #
128
+ # Runs the `ronin-web xpath` command.
129
+ #
130
+ # @param [String] source
131
+ # The `URL` or `FILE` argument.
132
+ #
133
+ # @param [String, nil] query
134
+ # The optional XPath or CSS-path argument.
135
+ #
136
+ def run(source,query=@query)
137
+ unless query
138
+ print_error "must specify --xpath, --css-path, or an XPath/CSS-path argument"
139
+ exit -1
140
+ end
141
+
142
+ doc = Nokogiri::HTML(read(source))
143
+ nodes = if options[:first] then [doc.at(query)]
144
+ else doc.search(query)
145
+ end
146
+
147
+ nodes.each do |node|
148
+ puts node
149
+ end
150
+ end
151
+
152
+ #
153
+ # Reads a URI or file.
154
+ #
155
+ # @param [String] source
156
+ # The URI or file path.
157
+ #
158
+ # @return [File, String]
159
+ # The contents of the URI or file.
160
+ #
161
+ def read(source)
162
+ if source.start_with?('https://') ||
163
+ source.start_with?('http://')
164
+ Support::Network::HTTP.get_body(source)
165
+ else
166
+ File.new(source)
167
+ end
168
+ end
169
+
170
+ end
171
+ end
172
+ end
173
+ end
174
+ end
@@ -0,0 +1,56 @@
1
+ #
2
+ # ronin-web - A collection of useful web helper methods and commands.
3
+ #
4
+ # Copyright (c) 2006-2023 Hal Brodigan (postmodern.mod3 at gmail.com)
5
+ #
6
+ # ronin-web is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # ronin-web is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with ronin-web. If not, see <https://www.gnu.org/licenses/>.
18
+ #
19
+
20
+ require 'ronin/web/cli/command'
21
+ require 'ronin/web/cli/ruby_shell'
22
+
23
+ module Ronin
24
+ module Web
25
+ class CLI
26
+ module Commands
27
+ #
28
+ # Starts an interactive Ruby shell with `ronin-web` loaded.
29
+ #
30
+ # ## Usage
31
+ #
32
+ # ronin-web irb [options]
33
+ #
34
+ # ## Options
35
+ #
36
+ # -h, --help Print help information
37
+ #
38
+ class Irb < Command
39
+
40
+ description "Starts an interactive Ruby shell with ronin-web loaded"
41
+
42
+ man_page 'ronin-web-irb.1'
43
+
44
+ #
45
+ # Runs the `ronin-web irb` command.
46
+ #
47
+ def run
48
+ require 'ronin/web'
49
+ CLI::RubyShell.start
50
+ end
51
+
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright (c) 2006-2023 Hal Brodigan (postmodern.mod3 at gmail.com)
4
+ #
5
+ # ronin-web is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # ronin-web is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with ronin-web. If not, see <https://www.gnu.org/licenses/>.
17
+ #
18
+
19
+ require 'ronin/web/cli/command'
20
+ require 'ronin/web/root'
21
+
22
+ require 'ronin/core/cli/generator'
23
+
24
+ module Ronin
25
+ module Web
26
+ class CLI
27
+ module Commands
28
+ class New < Command
29
+ #
30
+ # Generates a new nokogiri Ruby script.
31
+ #
32
+ # ## Usage
33
+ #
34
+ # ronin-web new nokogiri [options] FILE
35
+ #
36
+ # ## Options
37
+ #
38
+ # -U, --url URL Optional URL for the script
39
+ # -h, --help Print help information
40
+ #
41
+ # ## Arguments
42
+ #
43
+ # FILE The file to create
44
+ #
45
+ class Nokogiri < Command
46
+
47
+ include Core::CLI::Generator
48
+
49
+ template_dir File.join(ROOT,'data','new')
50
+
51
+ usage '[options] FILE'
52
+
53
+ option :url, short: '-U',
54
+ value: {
55
+ type: String,
56
+ usage: 'URL'
57
+ },
58
+ desc: 'Optional URL for the script'
59
+
60
+ argument :file, required: true,
61
+ desc: 'The file to create'
62
+
63
+ description 'Generates a new nokogiri Ruby script'
64
+
65
+ man_page 'ronin-web-new-nokogiri.1'
66
+
67
+ #
68
+ # Runs the `ronin-web new nokogiri` command.
69
+ #
70
+ # @param [String] path
71
+ # The path to the new script file to create.
72
+ #
73
+ def run(path)
74
+ @url = options[:url]
75
+
76
+ erb 'nokogiri.rb.erb', path
77
+ chmod '+x', path
78
+ end
79
+
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,96 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright (c) 2006-2023 Hal Brodigan (postmodern.mod3 at gmail.com)
4
+ #
5
+ # ronin-web is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # ronin-web is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with ronin-web. If not, see <https://www.gnu.org/licenses/>.
17
+ #
18
+
19
+ require 'ronin/web/cli/command'
20
+ require 'ronin/web/root'
21
+
22
+ require 'ronin/core/cli/generator'
23
+
24
+ module Ronin
25
+ module Web
26
+ class CLI
27
+ module Commands
28
+ class New < Command
29
+ #
30
+ # Creates a new [ronin-web-server] script.
31
+ #
32
+ # [ronin-web-server]: https://github.com/ronin-rb/ronin-web-server#readme
33
+ #
34
+ # ## Usage
35
+ #
36
+ # ronin-web server [options]
37
+ #
38
+ # ## Options
39
+ #
40
+ # -H, --host HOST|IP Optional host or IP interface to listen on. Defaults to 0.0.0.0.
41
+ # -p, --port PORT Optional port to listen on. Defaults to 8000.
42
+ # -h, --help Print help information
43
+ #
44
+ # ## Arguments
45
+ #
46
+ # FILE The file to create
47
+ #
48
+ class Server < Command
49
+
50
+ include Core::CLI::Generator
51
+
52
+ template_dir File.join(ROOT,'data','new')
53
+
54
+ usage '[options] FILE'
55
+
56
+ option :host, short: '-H',
57
+ value: {
58
+ type: String,
59
+ usage: 'HOST|IP'
60
+ },
61
+ desc: 'Optional host or IP interface to listen on. Defaults to 0.0.0.0.'
62
+
63
+ option :port, short: '-p',
64
+ value: {
65
+ type: Integer,
66
+ usage: 'PORT'
67
+ },
68
+ desc: 'Optional port to listen on. Defaults to 8000.'
69
+
70
+ argument :file, required: true,
71
+ desc: 'The file to create'
72
+
73
+ description 'Creates a new web server script'
74
+
75
+ man_page 'ronin-web-new-server.1'
76
+
77
+ #
78
+ # Runs the `ronin-web new server` command.
79
+ #
80
+ # @param [String] path
81
+ # The path to the new script file to create.
82
+ #
83
+ def run(path)
84
+ @host = options[:host]
85
+ @port = options[:port]
86
+
87
+ erb 'server.rb.erb', path
88
+ chmod '+x', path
89
+ end
90
+
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end