watobo 0.9.16 → 0.9.17
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +31 -0
- data/lib/watobo.rb +3 -5
- data/lib/watobo/core/ca.rb +27 -19
- data/lib/watobo/core/cookie.rb +10 -6
- data/lib/watobo/core/parameter.rb +13 -1
- data/lib/watobo/core/request.rb +24 -4
- data/lib/watobo/gui/chatviewer_frame.rb +9 -2
- data/lib/watobo/gui/conversation_table_ctrl2.rb +16 -1
- data/lib/watobo/gui/custom_viewer.rb +368 -0
- data/lib/watobo/gui/main_window.rb +1 -0
- data/lib/watobo/gui/manual_request_editor.rb +5 -11
- data/lib/watobo/gui/table_editor.rb +55 -48
- data/lib/watobo/http.rb +25 -0
- data/lib/watobo/http/cookies/cookies.rb +83 -20
- data/lib/watobo/http/url/url.rb +4 -1
- data/lib/watobo/http/xml/xml.rb +143 -0
- data/lib/watobo/interceptor/proxy.rb +1 -2
- data/lib/watobo/mixins/httpparser.rb +17 -5
- data/lib/watobo/mixins/shapers.rb +2 -11
- data/lib/watobo/{http_socket.rb → sockets.rb} +2 -2
- data/lib/watobo/{http_socket → sockets}/agent.rb +0 -0
- data/lib/watobo/{http_socket → sockets}/client_socket.rb +21 -7
- data/lib/watobo/{http_socket → sockets}/connection.rb +0 -0
- data/lib/watobo/{http_socket → sockets}/http_socket.rb +0 -0
- data/lib/watobo/{http_socket → sockets}/ntlm_auth.rb +0 -0
- data/modules/active/sqlinjection/sql_boolean.rb +29 -138
- data/modules/active/sqlinjection/sqli_error.rb +13 -67
- data/modules/passive/cookie_xss.rb +16 -26
- data/modules/passive/possible_login.rb +5 -8
- data/plugins/filefinder/dbs/sap.db +157 -0
- data/plugins/wshell/lib/core.rb +4 -2
- metadata +11 -8
@@ -572,16 +572,8 @@ module Watobo#:nodoc: all
|
|
572
572
|
|
573
573
|
csrf_requests = []
|
574
574
|
|
575
|
-
# if @updateCSRF.checked?
|
576
|
-
# csrf_requests = Watobo::OTTCache.requests(new_request)
|
577
|
-
# end
|
578
|
-
|
579
575
|
prefs = Watobo::Conf::Scanner.to_h
|
580
|
-
|
581
|
-
# puts prefs[:csrf_patterns]
|
582
|
-
puts prefs.to_yaml
|
583
|
-
|
584
|
-
|
576
|
+
|
585
577
|
current_prefs = {:run_login => @updateSession.checked? ? @runLogin.checked? : false,
|
586
578
|
:update_session => @updateSession.checked?,
|
587
579
|
:update_contentlength => @updateContentLength.checked?,
|
@@ -612,9 +604,10 @@ module Watobo#:nodoc: all
|
|
612
604
|
return nil if request.nil?
|
613
605
|
request = Watobo::Request.new request
|
614
606
|
|
615
|
-
if request.method =~ /POST/i
|
607
|
+
if request.method =~ /POST/i and request.content_type =~ /www\-form/i
|
616
608
|
request.setMethod("GET")
|
617
609
|
request.removeHeader("Content-Length")
|
610
|
+
request.removeHeader("Content-Type")
|
618
611
|
data = request.data.to_s
|
619
612
|
# puts "Data: "
|
620
613
|
# puts data
|
@@ -631,7 +624,8 @@ module Watobo#:nodoc: all
|
|
631
624
|
|
632
625
|
if request.method =~ /GET/i
|
633
626
|
request.setMethod("POST")
|
634
|
-
request.
|
627
|
+
request.set_header("Content-Length", "0")
|
628
|
+
request.set_header("Content-Type", "application/x-www-form-urlencoded")
|
635
629
|
data = request.query
|
636
630
|
request.setData(data)
|
637
631
|
request.removeUrlParms()
|
@@ -23,6 +23,8 @@
|
|
23
23
|
module Watobo#:nodoc: all
|
24
24
|
module Gui
|
25
25
|
class AddTableParmDialog < FXDialogBox
|
26
|
+
attr :param
|
27
|
+
|
26
28
|
def location()
|
27
29
|
@location_combo.getItemData(@location_combo.currentItem)
|
28
30
|
end
|
@@ -42,6 +44,7 @@ module Watobo#:nodoc: all
|
|
42
44
|
@location = nil
|
43
45
|
@pname = nil
|
44
46
|
@pval = nil
|
47
|
+
@param = nil
|
45
48
|
|
46
49
|
base_frame = FXVerticalFrame.new(self, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y)
|
47
50
|
frame = FXHorizontalFrame.new(base_frame, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y)
|
@@ -77,10 +80,11 @@ module Watobo#:nodoc: all
|
|
77
80
|
buttons_frame = FXHorizontalFrame.new(base_frame,
|
78
81
|
:opts => LAYOUT_FILL_X|LAYOUT_SIDE_TOP)
|
79
82
|
|
80
|
-
@finishButton = FXButton.new(buttons_frame, "
|
83
|
+
@finishButton = FXButton.new(buttons_frame, "Add" , nil, nil, :opts => BUTTON_NORMAL|LAYOUT_RIGHT)
|
81
84
|
@finishButton.enable
|
82
85
|
@finishButton.connect(SEL_COMMAND) do |sender, sel, item|
|
83
86
|
#self.handle(self, FXSEL(SEL_COMMAND, ID_CANCEL), nil)
|
87
|
+
create_param
|
84
88
|
self.handle(self, FXSEL(SEL_COMMAND, ID_ACCEPT), nil)
|
85
89
|
end
|
86
90
|
|
@@ -89,6 +93,21 @@ module Watobo#:nodoc: all
|
|
89
93
|
:opts => BUTTON_NORMAL|LAYOUT_RIGHT)
|
90
94
|
|
91
95
|
end
|
96
|
+
|
97
|
+
private
|
98
|
+
|
99
|
+
def create_param
|
100
|
+
@param = case @location_combo.getItemData(@location_combo.currentItem)
|
101
|
+
when /Post/i
|
102
|
+
Watobo::WWWFormParameter.new(:name => @parm_name_dt.value, :value => @parm_value_dt.value)
|
103
|
+
when /Url/i
|
104
|
+
Watobo::UrlParameter.new(:name => @parm_name_dt.value, :value => @parm_value_dt.value)
|
105
|
+
when /Cookie/i
|
106
|
+
Watobo::CookieParameter.new(:name => @parm_name_dt.value, :value => @parm_value_dt.value)
|
107
|
+
else
|
108
|
+
nil
|
109
|
+
end
|
110
|
+
end
|
92
111
|
|
93
112
|
end
|
94
113
|
|
@@ -99,55 +118,32 @@ module Watobo#:nodoc: all
|
|
99
118
|
end
|
100
119
|
|
101
120
|
def parseRequest
|
102
|
-
|
103
|
-
url = ""
|
121
|
+
request = @request.copy
|
104
122
|
|
105
|
-
parms = []
|
106
123
|
self.numRows.times do |i|
|
107
124
|
name = CGI.escape(self.getItemText(i, 1))
|
108
|
-
value = self.getItemText(i, 2).strip
|
109
125
|
location = self.getItemText(i, 0)
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
when /post/i
|
114
|
-
@request.set Watobo::WWWFormParameter.new( :name => name, :value => value)
|
115
|
-
when /url/i
|
116
|
-
@request.set Watobo::UrlParameter.new( :name => name, :value => value)
|
117
|
-
when /cookie2?/i
|
118
|
-
cookies << "#{name}=#{value}"
|
119
|
-
end
|
126
|
+
parm = self.getItemData(i, 0)
|
127
|
+
parm.value = self.getItemText(i, 2).unpack("C*").pack("C*").strip
|
128
|
+
request.set parm
|
120
129
|
end
|
121
130
|
|
122
|
-
request = @request.copy
|
123
|
-
|
124
|
-
unless cookies.empty?
|
125
|
-
# puts cookies
|
126
|
-
request.removeHeader("Cookie")
|
127
|
-
request.addHeader("Cookie", cookies.join("; "))
|
128
|
-
end
|
129
131
|
request
|
130
132
|
end
|
131
133
|
|
132
134
|
def setRequest(request)
|
135
|
+
initTable()
|
136
|
+
return false if request.empty?
|
133
137
|
@request = request.copy
|
134
138
|
|
135
|
-
return false if @request.content_type =~ /(multipart|
|
139
|
+
return false if @request.content_type =~ /(multipart|json)/
|
136
140
|
|
137
|
-
|
141
|
+
|
138
142
|
@request = Watobo::Utils.text2request(request) if request.is_a? String
|
139
143
|
# addParmList("REQ", ["URL=#{request.url}"])
|
140
144
|
|
141
|
-
|
142
|
-
|
143
|
-
end
|
144
|
-
|
145
|
-
if @request.post_parms.length > 0
|
146
|
-
addParmList("Post", @request.post_parms)
|
147
|
-
end
|
148
|
-
|
149
|
-
if @request.cookies.length > 0
|
150
|
-
addParmList("Cookie", @request.cookies)
|
145
|
+
@request.parameters.each do |parm|
|
146
|
+
add_parm parm
|
151
147
|
end
|
152
148
|
|
153
149
|
true
|
@@ -264,15 +260,29 @@ module Watobo#:nodoc: all
|
|
264
260
|
end
|
265
261
|
|
266
262
|
private
|
263
|
+
|
264
|
+
def add_parm(parm)
|
265
|
+
lastRowIndex = self.getNumRows
|
266
|
+
self.appendRows(1)
|
267
|
+
self.setItemText(lastRowIndex, 0, parm.location.to_s)
|
268
|
+
self.setItemData(lastRowIndex, 0, parm)
|
269
|
+
self.setItemText(lastRowIndex, 1, CGI.unescape(parm.name))
|
270
|
+
self.setItemText(lastRowIndex, 2, parm.value)
|
271
|
+
|
272
|
+
3.times do |i|
|
273
|
+
self.getItem(lastRowIndex, i).justify = FXTableItem::LEFT
|
274
|
+
end
|
275
|
+
end
|
267
276
|
|
268
277
|
def addNewParm()
|
269
278
|
|
270
279
|
dlg = AddTableParmDialog.new(self)
|
271
280
|
if dlg.execute != 0 then
|
272
|
-
loc = dlg.location
|
273
|
-
pname = dlg.parmName
|
274
|
-
pval = dlg.parmValue
|
275
|
-
|
281
|
+
#loc = dlg.location
|
282
|
+
#pname = dlg.parmName
|
283
|
+
#pval = dlg.parmValue
|
284
|
+
parm = dlg.param
|
285
|
+
add_parm parm unless parm.nil?
|
276
286
|
end
|
277
287
|
end
|
278
288
|
|
@@ -322,19 +332,18 @@ module Watobo#:nodoc: all
|
|
322
332
|
else
|
323
333
|
notify(:hotkey_ctrl_f) if event.code == KEY_f
|
324
334
|
notify(:hotkey_ctrl_s) if event.code == KEY_s
|
335
|
+
|
336
|
+
text = self.getItemText(cr, 2).unpack("C*").pack("C*")
|
325
337
|
|
326
338
|
if event.code == KEY_u
|
327
|
-
text = self.getItemText(cr, 2)
|
328
|
-
#puts "* Encode URL: #{text}"
|
329
339
|
cgi = CGI::escape(text)
|
330
340
|
self.acceptInput(true)
|
331
341
|
self.setItemText(cr, 2, cgi.strip, true)
|
332
342
|
end
|
333
343
|
|
334
344
|
if event.code == KEY_b
|
335
|
-
text = self.getItemText(cr, 2)
|
336
345
|
#puts "* Encode B64: #{text}"
|
337
|
-
b64 = Base64.
|
346
|
+
b64 = Base64.strict_encode64(text)
|
338
347
|
self.acceptInput(true)
|
339
348
|
self.setItemText(cr, 2, b64.strip, true)
|
340
349
|
puts b64.class
|
@@ -342,15 +351,11 @@ module Watobo#:nodoc: all
|
|
342
351
|
|
343
352
|
# puts "CTRL-SHIFT-U" if event.code == KEY_U
|
344
353
|
if event.code == KEY_U
|
345
|
-
text = self.getItemText(cr, 2)
|
346
|
-
#puts "* Encode URL: #{text}"
|
347
354
|
uncgi = CGI::unescape(text)
|
348
355
|
self.acceptInput(true)
|
349
356
|
self.setItemText(cr, 2, uncgi.strip, true)
|
350
357
|
end
|
351
358
|
if event.code == KEY_B
|
352
|
-
text = self.getItemText(cr, 2)
|
353
|
-
#puts "* Encode B64: #{text}"
|
354
359
|
b64 = Base64.decode64(text)
|
355
360
|
self.acceptInput(true)
|
356
361
|
self.setItemText(cr, 2, b64.strip, true)
|
@@ -375,7 +380,7 @@ module Watobo#:nodoc: all
|
|
375
380
|
end
|
376
381
|
end
|
377
382
|
|
378
|
-
def
|
383
|
+
def addParmList_UNUSED(parm_origin, parm_list)
|
379
384
|
parm_list.each do |parm|
|
380
385
|
p,v = parm.split("=")
|
381
386
|
lastRowIndex = self.getNumRows
|
@@ -428,9 +433,11 @@ module Watobo#:nodoc: all
|
|
428
433
|
|
429
434
|
|
430
435
|
@editor.setRequest request
|
431
|
-
@req_line.text = request.first.strip
|
436
|
+
@req_line.text = request.first.strip unless request.empty?
|
432
437
|
|
433
438
|
end
|
439
|
+
|
440
|
+
alias :setText :setRequest
|
434
441
|
|
435
442
|
def initialize(owner, opts)
|
436
443
|
super(owner, :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_SUNKEN|FRAME_THICK, :padding => 0)
|
data/lib/watobo/http.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# .
|
2
|
+
# http.rb
|
3
|
+
#
|
4
|
+
# Copyright 2013 by siberas, http://www.siberas.de
|
5
|
+
#
|
6
|
+
# This file is part of WATOBO (Web Application Tool Box)
|
7
|
+
# http://watobo.sourceforge.com
|
8
|
+
#
|
9
|
+
# WATOBO is free software; you can redistribute it and/or modify
|
10
|
+
# it under the terms of the GNU General Public License as published by
|
11
|
+
# the Free Software Foundation version 2 of the License.
|
12
|
+
#
|
13
|
+
# WATOBO is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
# GNU General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU General Public License
|
19
|
+
# along with WATOBO; if not, write to the Free Software
|
20
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
21
|
+
# .
|
22
|
+
require 'watobo/http/data/data'
|
23
|
+
require 'watobo/http/url/url'
|
24
|
+
require 'watobo/http/cookies/cookies'
|
25
|
+
require 'watobo/http/xml/xml'
|
@@ -19,49 +19,112 @@
|
|
19
19
|
# along with WATOBO; if not, write to the Free Software
|
20
20
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
21
21
|
# .
|
22
|
-
# @private
|
22
|
+
# @private
|
23
23
|
module Watobo#:nodoc: all
|
24
24
|
module HTTP
|
25
25
|
class Cookies
|
26
26
|
def to_s
|
27
|
-
s =
|
27
|
+
s = []
|
28
|
+
@cookies.each_value do |v|
|
29
|
+
s << "#{v.name}=#{v.value}"
|
30
|
+
end
|
31
|
+
s.join("; ")
|
32
|
+
end
|
33
|
+
|
34
|
+
def inspect
|
35
|
+
self.to_a
|
36
|
+
end
|
37
|
+
|
38
|
+
def to_a
|
39
|
+
cookies = []
|
40
|
+
raw_cookies do |c|
|
41
|
+
cookies << Watobo::Cookie.new(c)
|
42
|
+
end
|
43
|
+
cookies
|
28
44
|
end
|
29
45
|
|
30
|
-
|
46
|
+
|
47
|
+
def each(&block)
|
48
|
+
@cookies.each_value do |cookie|
|
49
|
+
yield cookie if block_given?
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
31
53
|
def set(parm)
|
32
|
-
|
54
|
+
@cookies[parm.name.to_sym] = parm
|
55
|
+
@root.set_header("Cookie", self.to_s)
|
33
56
|
end
|
34
57
|
|
35
58
|
def has_parm?(parm_name)
|
36
59
|
false
|
37
60
|
end
|
38
61
|
|
62
|
+
#def
|
63
|
+
|
39
64
|
def parameters(&block)
|
40
|
-
|
41
|
-
|
42
|
-
|
65
|
+
params = []
|
66
|
+
raw_cookies do |cprefs|
|
67
|
+
cookie = Watobo::CookieParameter.new(cprefs)
|
68
|
+
yield cookie if block_given?
|
69
|
+
params << cookie
|
70
|
+
|
71
|
+
end
|
72
|
+
params
|
73
|
+
end
|
74
|
+
|
75
|
+
def initialize(root)
|
76
|
+
@root = root
|
77
|
+
@cookies = {}
|
78
|
+
|
79
|
+
init_cookies
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def init_cookies
|
86
|
+
raw_cookies do |rc|
|
87
|
+
if rc.has_key? :name
|
88
|
+
@cookies[rc[:name].to_sym] = Watobo::Cookie.new(rc)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def raw_cookies(&block)
|
94
|
+
rcs = []
|
95
|
+
|
43
96
|
@root.headers.each do |line|
|
44
97
|
if line =~ /^(Set\-)?Cookie2?: (.*)/i then
|
45
|
-
cookie_prefs[:secure] = true if line =~ /secure/i
|
46
|
-
cookie_prefs[:http_only] = true if line =~ /httponly/i
|
47
98
|
clist = $2.split(";")
|
99
|
+
cookie_prefs = { :secure => false, :http_only => false }
|
100
|
+
cookie_prefs[:secure] = true if line =~ /secure/i
|
101
|
+
cookie_prefs[:http_only] = true if line =~ /httponly/i
|
102
|
+
|
48
103
|
clist.each do |c|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
104
|
+
c.strip!
|
105
|
+
i = c.index("=")
|
106
|
+
|
107
|
+
# skip cookie options
|
108
|
+
next if i.nil?
|
109
|
+
|
110
|
+
name = c[0..i-1]
|
111
|
+
value = i < c.length ? c[i+1..-1] : ""
|
112
|
+
cookie_prefs[:name] = name.strip
|
113
|
+
cookie_prefs[:value] = value.strip
|
114
|
+
#cookie = Watobo::CookieParameter.new(cookie_prefs)
|
115
|
+
yield cookie_prefs if block_given?
|
116
|
+
rcs << cookie_prefs
|
56
117
|
end
|
57
118
|
end
|
58
119
|
end
|
59
|
-
return
|
60
|
-
end
|
120
|
+
return rcs
|
61
121
|
|
62
|
-
|
63
|
-
@root = root
|
122
|
+
end
|
64
123
|
|
124
|
+
module Mixin
|
125
|
+
def cookies
|
126
|
+
@cookies ||= Cookies.new(self)
|
127
|
+
end
|
65
128
|
end
|
66
129
|
end
|
67
130
|
end
|
data/lib/watobo/http/url/url.rb
CHANGED
@@ -46,7 +46,10 @@ module Watobo#:nodoc: all
|
|
46
46
|
def parameters(&block)
|
47
47
|
parms = []
|
48
48
|
@root.get_parms.each do |p|
|
49
|
-
|
49
|
+
p.strip!
|
50
|
+
i = p.index("=")
|
51
|
+
name = p[0..i-1]
|
52
|
+
val = i < p.length ? p[i+1..-1] : ""
|
50
53
|
parms << Watobo::UrlParameter.new( :name => name, :value => val )
|
51
54
|
end
|
52
55
|
parms
|
@@ -0,0 +1,143 @@
|
|
1
|
+
# .
|
2
|
+
# xml.rb
|
3
|
+
#
|
4
|
+
# Copyright 2013 by siberas, http://www.siberas.de
|
5
|
+
#
|
6
|
+
# This file is part of WATOBO (Web Application Tool Box)
|
7
|
+
# http://watobo.sourceforge.com
|
8
|
+
#
|
9
|
+
# WATOBO is free software; you can redistribute it and/or modify
|
10
|
+
# it under the terms of the GNU General Public License as published by
|
11
|
+
# the Free Software Foundation version 2 of the License.
|
12
|
+
#
|
13
|
+
# WATOBO is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
# GNU General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU General Public License
|
19
|
+
# along with WATOBO; if not, write to the Free Software
|
20
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
21
|
+
# .
|
22
|
+
# @private
|
23
|
+
module Watobo#:nodoc: all
|
24
|
+
module HTTP
|
25
|
+
class Xml
|
26
|
+
|
27
|
+
module Mixin
|
28
|
+
def xml
|
29
|
+
@xml ||= Watobo::HTTP::Xml.new(self)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_s
|
34
|
+
s = @root.body.to_s
|
35
|
+
end
|
36
|
+
|
37
|
+
def set(parm)
|
38
|
+
return false unless parm.location == :xml
|
39
|
+
# puts "= set "
|
40
|
+
# puts parm.to_yaml
|
41
|
+
|
42
|
+
doc = Nokogiri::XML(@root.body.strip)
|
43
|
+
namespaces = doc.collect_namespaces
|
44
|
+
parent = doc.xpath("//#{parm.parent}", namespaces).first
|
45
|
+
if parent.nil?
|
46
|
+
puts "* could not find parent node #{parm.parent}"
|
47
|
+
return false
|
48
|
+
end
|
49
|
+
|
50
|
+
parm_name = parm.namespace.nil? ? "" : parm.namespace
|
51
|
+
parm_name << parm.name
|
52
|
+
# find node
|
53
|
+
node = parent.xpath("//#{parm_name}", namespaces).first
|
54
|
+
if node.nil?
|
55
|
+
puts "* node does not exist #{parm_name}"
|
56
|
+
end
|
57
|
+
|
58
|
+
child = node.children.first
|
59
|
+
if child.nil?
|
60
|
+
child = Nokogiri::XML::Text.new(parm.value, node)
|
61
|
+
node.add_child child
|
62
|
+
else
|
63
|
+
child.content = parm.value
|
64
|
+
end
|
65
|
+
|
66
|
+
@root.set_body doc.to_s
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
def has_parm?(parm_name)
|
71
|
+
false
|
72
|
+
end
|
73
|
+
|
74
|
+
def parameters(&block)
|
75
|
+
params = []
|
76
|
+
|
77
|
+
return params unless @root.is_xml?
|
78
|
+
leaf_nodes do |n|
|
79
|
+
p = { :name => n.name }
|
80
|
+
val = n.children.size == 0 ? "" : n.children.first.to_s
|
81
|
+
|
82
|
+
p[:value] = val
|
83
|
+
parent_name = ""
|
84
|
+
unless n.parent.namespace.nil?
|
85
|
+
parent_name << n.parent.namespace.prefix
|
86
|
+
parent_name << ":"
|
87
|
+
end
|
88
|
+
parent_name << n.parent.name
|
89
|
+
p[:parent] = "#{parent_name}"
|
90
|
+
|
91
|
+
unless n.namespace.nil?
|
92
|
+
p[:namespace] = n.namespace.prefix
|
93
|
+
end
|
94
|
+
param = XmlParameter.new(p)
|
95
|
+
yield param if block_given?
|
96
|
+
params << param
|
97
|
+
end
|
98
|
+
|
99
|
+
return params
|
100
|
+
end
|
101
|
+
|
102
|
+
def initialize(root)
|
103
|
+
@root = root
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
private
|
108
|
+
|
109
|
+
def leaf_nodes(&block)
|
110
|
+
|
111
|
+
nodes = []
|
112
|
+
begin
|
113
|
+
doc = Nokogiri::XML(@root.body.strip)
|
114
|
+
prefix = doc.children.first.namespace.prefix
|
115
|
+
# check if doc has a body element
|
116
|
+
start = doc
|
117
|
+
doc.traverse { |node|
|
118
|
+
if node.name =~ /^body$/i
|
119
|
+
start = node
|
120
|
+
end
|
121
|
+
}
|
122
|
+
start.traverse { |node|
|
123
|
+
if node.children.size == 0 and node.is_a? Nokogiri::XML::Element
|
124
|
+
yield node if block_given?
|
125
|
+
nodes << node
|
126
|
+
end
|
127
|
+
if node.children.size == 1
|
128
|
+
if node.children.first.is_a? Nokogiri::XML::Text
|
129
|
+
yield node if block_given?
|
130
|
+
nodes << node
|
131
|
+
end
|
132
|
+
end
|
133
|
+
}
|
134
|
+
rescue => bang
|
135
|
+
puts bang
|
136
|
+
puts bang.backtrace if $DEBUG
|
137
|
+
end
|
138
|
+
nodes
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|