18
18
Output = Concurrent ::Map . new
19
19
20
20
class DeadFinderRunner
21
+ def default_options
22
+ {
23
+ 'concurrency' => 50 ,
24
+ 'timeout' => 10 ,
25
+ 'output' => '' ,
26
+ 'headers' => [ ] ,
27
+ 'silent' => true
28
+ }
29
+ end
30
+
21
31
def run ( target , options )
32
+ Logger . set_silent if options [ 'silent' ]
22
33
headers = options [ 'headers' ] . each_with_object ( { } ) do |header , hash |
23
34
kv = header . split ( ': ' )
24
35
hash [ kv [ 0 ] ] = kv [ 1 ]
@@ -96,35 +107,49 @@ def extract_links(page)
96
107
end
97
108
98
109
def run_pipe ( options )
110
+ Logger . set_silent if options [ 'silent' ]
111
+
112
+ Logger . info 'Reading from STDIN'
99
113
app = DeadFinderRunner . new
100
114
while $stdin. gets
101
115
target = $LAST_READ_LINE. chomp
116
+ Logger . target "Checking: #{ target } "
102
117
app . run target , options
103
118
end
104
119
gen_output ( options )
105
120
end
106
121
107
122
def run_file ( filename , options )
123
+ Logger . set_silent if options [ 'silent' ]
124
+
125
+ Logger . info "Reading: #{ filename } "
108
126
app = DeadFinderRunner . new
109
127
File . foreach ( filename ) do |line |
110
128
target = line . chomp
129
+ Logger . target "Checking: #{ target } "
111
130
app . run target , options
112
131
end
113
132
gen_output ( options )
114
133
end
115
134
116
135
def run_url ( url , options )
136
+ Logger . set_silent if options [ 'silent' ]
137
+
138
+ Logger . target "Checking: #{ url } "
117
139
app = DeadFinderRunner . new
118
140
app . run url , options
119
141
gen_output ( options )
120
142
end
121
143
122
144
def run_sitemap ( sitemap_url , options )
145
+ Logger . set_silent if options [ 'silent' ]
146
+ Logger . info "Parsing sitemap: #{ sitemap_url } "
123
147
app = DeadFinderRunner . new
124
148
base_uri = URI ( sitemap_url )
125
149
sitemap = SitemapParser . new sitemap_url , { recurse : true }
126
150
sitemap . to_a . each do |url |
127
151
turl = generate_url url , base_uri
152
+ Logger . target "Checking: #{ turl } "
128
153
app . run turl , options
129
154
end
130
155
gen_output ( options )
@@ -139,28 +164,25 @@ class DeadFinder < Thor
139
164
class_option :timeout , aliases : :t , default : 10 , type : :numeric , desc : 'Timeout in seconds'
140
165
class_option :output , aliases : :o , default : '' , type : :string , desc : 'File to write JSON result'
141
166
class_option :headers , aliases : :H , default : [ ] , type : :array , desc : 'Custom HTTP headers to send with request'
167
+ class_option :silent , aliases : :s , default : false , type : :boolean , desc : 'Silent mode'
142
168
143
169
desc 'pipe' , 'Scan the URLs from STDIN. (e.g cat urls.txt | deadfinder pipe)'
144
170
def pipe
145
- Logger . info 'Pipe mode'
146
171
run_pipe options
147
172
end
148
173
149
174
desc 'file <FILE>' , 'Scan the URLs from File. (e.g deadfinder file urls.txt)'
150
175
def file ( filename )
151
- Logger . info 'File mode'
152
176
run_file filename , options
153
177
end
154
178
155
179
desc 'url <URL>' , 'Scan the Single URL.'
156
180
def url ( url )
157
- Logger . info 'Single URL mode'
158
181
run_url url , options
159
182
end
160
183
161
184
desc 'sitemap <SITEMAP-URL>' , 'Scan the URLs from sitemap.'
162
185
def sitemap ( sitemap )
163
- Logger . info 'Sitemap mode'
164
186
run_sitemap sitemap , options
165
187
end
166
188
0 commit comments