watobo 0.9.21 → 0.9.23
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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +46 -1
- data/bin/nfq_server.rb +0 -9
- data/bin/watobo_gui.rb +3 -13
- data/custom-views/prettify-json.rb +9 -18
- data/icons/watobo.ico +0 -0
- data/icons/watobo.ico.old +0 -0
- data/lib/watobo.rb +10 -19
- data/lib/watobo/adapters.rb +5 -14
- data/lib/watobo/adapters/data_store.rb +50 -59
- data/lib/watobo/adapters/file/file_store.rb +287 -296
- data/lib/watobo/adapters/file/marshal_store.rb +293 -296
- data/lib/watobo/adapters/session_store.rb +5 -14
- data/lib/watobo/ca.rb +1 -10
- data/lib/watobo/config.rb +197 -206
- data/lib/watobo/constants.rb +0 -9
- data/lib/watobo/core.rb +3 -12
- data/lib/watobo/core/active_check.rb +72 -135
- data/lib/watobo/core/active_checks.rb +49 -58
- data/lib/watobo/core/ca.rb +369 -389
- data/lib/watobo/core/cert_store.rb +34 -43
- data/lib/watobo/core/chat.rb +92 -101
- data/lib/watobo/core/chats.rb +271 -280
- data/lib/watobo/core/client_cert_store.rb +106 -35
- data/lib/watobo/core/conversation.rb +48 -57
- data/lib/watobo/core/cookie.rb +23 -32
- data/lib/watobo/core/egress_handlers.rb +98 -0
- data/lib/watobo/core/finding.rb +66 -75
- data/lib/watobo/core/findings.rb +107 -114
- data/lib/watobo/core/forwarding_proxy.rb +13 -22
- data/lib/watobo/core/fuzz_gen.rb +0 -9
- data/lib/watobo/core/intercept_carver.rb +166 -177
- data/lib/watobo/core/intercept_filter.rb +235 -244
- data/lib/watobo/core/interceptor.rb +98 -107
- data/lib/watobo/core/min_class.rb +4 -13
- data/lib/watobo/core/netfilter_queue.rb +170 -179
- data/lib/watobo/core/ott_cache.rb +132 -141
- data/lib/watobo/core/parameter.rb +43 -52
- data/lib/watobo/core/passive_check.rb +103 -102
- data/lib/watobo/core/passive_checks.rb +48 -57
- data/lib/watobo/core/passive_scanner.rb +54 -55
- data/lib/watobo/core/plugin.rb +11 -20
- data/lib/watobo/core/project.rb +3 -9
- data/lib/watobo/core/proxy.rb +43 -52
- data/lib/watobo/core/request.rb +125 -123
- data/lib/watobo/core/response.rb +44 -53
- data/lib/watobo/core/scanner.rb +0 -9
- data/lib/watobo/core/scanner3.rb +405 -414
- data/lib/watobo/core/scope.rb +83 -92
- data/lib/watobo/core/session.rb +1043 -1026
- data/lib/watobo/core/sid_cache.rb +98 -107
- data/lib/watobo/core/subscriber.rb +25 -34
- data/lib/watobo/defaults.rb +21 -30
- data/lib/watobo/external/diff/lcs.rb +0 -9
- data/lib/watobo/external/diff/lcs/array.rb +0 -9
- data/lib/watobo/external/diff/lcs/block.rb +0 -9
- data/lib/watobo/external/diff/lcs/callbacks.rb +0 -9
- data/lib/watobo/external/diff/lcs/change.rb +0 -9
- data/lib/watobo/external/diff/lcs/hunk.rb +0 -9
- data/lib/watobo/external/diff/lcs/ldiff.rb +0 -9
- data/lib/watobo/external/diff/lcs/string.rb +0 -9
- data/lib/watobo/externals.rb +6 -15
- data/lib/watobo/framework.rb +4 -13
- data/lib/watobo/framework/create_project.rb +60 -69
- data/lib/watobo/framework/init.rb +0 -9
- data/lib/watobo/framework/init_modules.rb +0 -9
- data/lib/watobo/framework/license_text.rb +28 -37
- data/lib/watobo/framework/load_chat.rb +13 -22
- data/lib/watobo/gui.rb +132 -123
- data/lib/watobo/gui/about_watobo.rb +0 -9
- data/lib/watobo/gui/browser_preview.rb +0 -9
- data/lib/watobo/gui/certificate_dialog.rb +0 -9
- data/lib/watobo/gui/chat_diff.rb +0 -9
- data/lib/watobo/gui/chatviewer_frame.rb +73 -72
- data/lib/watobo/gui/checkboxtree.rb +0 -9
- data/lib/watobo/gui/checks_policy_frame.rb +0 -9
- data/lib/watobo/gui/client_cert_dialog.rb +96 -87
- data/lib/watobo/gui/confirm_scan_dialog.rb +0 -9
- data/lib/watobo/gui/conversation_table.rb +158 -164
- data/lib/watobo/gui/conversation_table_ctrl.rb +207 -216
- data/lib/watobo/gui/conversation_table_ctrl2.rb +373 -382
- data/lib/watobo/gui/csrf_token_dialog.rb +0 -9
- data/lib/watobo/gui/custom_viewer.rb +374 -383
- data/lib/watobo/gui/dashboard.rb +296 -303
- data/lib/watobo/gui/define_scope_frame.rb +0 -9
- data/lib/watobo/gui/differ_frame.rb +215 -224
- data/lib/watobo/gui/edit_comment.rb +0 -9
- data/lib/watobo/gui/edit_scope_dialog.rb +0 -9
- data/lib/watobo/gui/export_dialog.rb +104 -113
- data/lib/watobo/gui/finding_info.rb +0 -9
- data/lib/watobo/gui/findings_tree.rb +210 -217
- data/lib/watobo/gui/full_scan_dialog.rb +0 -9
- data/lib/watobo/gui/fuzzer_gui.rb +1295 -1313
- data/lib/watobo/gui/fxsave_thread.rb +14 -0
- data/lib/watobo/gui/goto_url_dialog.rb +70 -79
- data/lib/watobo/gui/hex_viewer.rb +0 -9
- data/lib/watobo/gui/html_viewer.rb +287 -296
- data/lib/watobo/gui/intercept_filter_dialog.rb +188 -197
- data/lib/watobo/gui/interceptor_gui.rb +1041 -1051
- data/lib/watobo/gui/interceptor_settings_dialog.rb +0 -9
- data/lib/watobo/gui/json_viewer.rb +287 -0
- data/lib/watobo/gui/list_box.rb +101 -110
- data/lib/watobo/gui/log_file_viewer.rb +32 -41
- data/lib/watobo/gui/log_viewer.rb +83 -88
- data/lib/watobo/gui/login_wizzard.rb +0 -9
- data/lib/watobo/gui/main_window.rb +587 -618
- data/lib/watobo/gui/manual_request_editor.rb +620 -565
- data/lib/watobo/gui/master_pw_dialog.rb +0 -9
- data/lib/watobo/gui/mixins/gui_settings.rb +29 -38
- data/lib/watobo/gui/page_tree.rb +217 -226
- data/lib/watobo/gui/password_policy_dialog.rb +0 -9
- data/lib/watobo/gui/plugin_board.rb +0 -9
- data/lib/watobo/gui/preferences_dialog.rb +0 -9
- data/lib/watobo/gui/progress_window.rb +17 -27
- data/lib/watobo/gui/project_wizzard.rb +0 -9
- data/lib/watobo/gui/proxy_dialog.rb +1 -10
- data/lib/watobo/gui/quick_scan_dialog.rb +0 -9
- data/lib/watobo/gui/request_builder_frame.rb +102 -111
- data/lib/watobo/gui/request_editor.rb +181 -137
- data/lib/watobo/gui/rewrite_filters_dialog.rb +394 -403
- data/lib/watobo/gui/rewrite_rules_dialog.rb +372 -381
- data/lib/watobo/gui/save_chat_dialog.rb +140 -149
- data/lib/watobo/gui/scanner_settings_dialog.rb +0 -9
- data/lib/watobo/gui/select_chat_dialog.rb +0 -9
- data/lib/watobo/gui/session_management_dialog.rb +0 -9
- data/lib/watobo/gui/sites_tree.rb +0 -9
- data/lib/watobo/gui/status_bar.rb +0 -9
- data/lib/watobo/gui/table_editor.rb +0 -9
- data/lib/watobo/gui/tagless_viewer.rb +0 -9
- data/lib/watobo/gui/templates/plugin.rb +0 -9
- data/lib/watobo/gui/templates/plugin2.rb +92 -100
- data/lib/watobo/gui/templates/plugin_base.rb +144 -153
- data/lib/watobo/gui/text_viewer.rb +0 -9
- data/lib/watobo/gui/transcoder_window.rb +0 -9
- data/lib/watobo/gui/utils/gui_utils.rb +0 -9
- data/lib/watobo/gui/utils/init_icons.rb +86 -95
- data/lib/watobo/gui/utils/load_icons.rb +33 -42
- data/lib/watobo/gui/utils/load_plugins.rb +116 -119
- data/lib/watobo/gui/utils/master_password.rb +68 -77
- data/lib/watobo/gui/utils/save_default_settings.rb +113 -122
- data/lib/watobo/gui/utils/save_project_settings.rb +0 -9
- data/lib/watobo/gui/utils/save_proxy_settings.rb +41 -50
- data/lib/watobo/gui/utils/save_scanner_settings.rb +18 -27
- data/lib/watobo/gui/utils/session_history.rb +112 -121
- data/lib/watobo/gui/workspace_dialog.rb +0 -9
- data/lib/watobo/gui/www_auth_dialog.rb +0 -9
- data/lib/watobo/gui/xml_viewer_frame.rb +0 -9
- data/lib/watobo/http.rb +4 -13
- data/lib/watobo/http/cookies/cookies.rb +26 -35
- data/lib/watobo/http/data/data.rb +45 -54
- data/lib/watobo/http/data/json.rb +47 -55
- data/lib/watobo/http/url/url.rb +38 -47
- data/lib/watobo/http/xml/xml.rb +124 -130
- data/lib/watobo/interceptor.rb +3 -12
- data/lib/watobo/interceptor/proxy.rb +742 -739
- data/lib/watobo/interceptor/transparent.rb +22 -24
- data/lib/watobo/mixins.rb +10 -19
- data/lib/watobo/mixins/check_info.rb +27 -36
- data/lib/watobo/mixins/httpparser.rb +613 -637
- data/lib/watobo/mixins/request_parser.rb +88 -97
- data/lib/watobo/mixins/shapers.rb +515 -529
- data/lib/watobo/mixins/transcoders.rb +3 -11
- data/lib/watobo/parser.rb +1 -10
- data/lib/watobo/parser/html.rb +83 -92
- data/lib/watobo/patch_fxruby_setfocus.rb +26 -0
- data/lib/watobo/sockets.rb +3 -12
- data/lib/watobo/sockets/agent.rb +828 -837
- data/lib/watobo/sockets/client_socket.rb +308 -312
- data/lib/watobo/sockets/connection.rb +401 -410
- data/lib/watobo/sockets/http_socket.rb +11 -13
- data/lib/watobo/sockets/ntlm_auth.rb +129 -138
- data/lib/watobo/utils.rb +10 -19
- data/lib/watobo/utils/check_regex.rb +0 -9
- data/lib/watobo/utils/copy_object.rb +0 -9
- data/lib/watobo/utils/crypto.rb +0 -9
- data/lib/watobo/utils/expand_range.rb +23 -32
- data/lib/watobo/utils/export_xml.rb +97 -106
- data/lib/watobo/utils/file_management.rb +9 -11
- data/lib/watobo/utils/hexprint.rb +9 -18
- data/lib/watobo/utils/load_chat.rb +0 -9
- data/lib/watobo/utils/load_icon.rb +0 -9
- data/lib/watobo/utils/ntlm.rb +866 -875
- data/lib/watobo/utils/print_debug.rb +12 -21
- data/lib/watobo/utils/response_builder.rb +90 -99
- data/lib/watobo/utils/response_hash.rb +0 -9
- data/lib/watobo/utils/secure_eval.rb +0 -9
- data/lib/watobo/utils/strings.rb +10 -19
- data/lib/watobo/utils/text2request.rb +0 -9
- data/lib/watobo/utils/url.rb +23 -32
- data/lib/watobo/utils/utf16.rb +11 -20
- data/modules/active/Apache/mod_status.rb +0 -9
- data/modules/active/Apache/multiview.rb +151 -160
- data/modules/active/Flash/crossdomain.rb +0 -9
- data/modules/active/JWT/jwt_oauth2_none.rb +111 -0
- data/modules/active/cq5/cq5_default_selectors.rb +106 -115
- data/modules/active/cq5/cqp_user_enumeration.rb +125 -134
- data/modules/active/directories/dirwalker.rb +0 -9
- data/modules/active/discovery/fileextensions.rb +0 -9
- data/modules/active/discovery/http_methods.rb +0 -9
- data/modules/active/discovery/jsmapfiles.rb +79 -0
- data/modules/active/domino/domino_db.rb +68 -76
- data/modules/active/dotNET/custom_errors.rb +102 -111
- data/modules/active/dotNET/dotnet_files.rb +90 -99
- data/modules/active/fileinclusion/lfi_simple.rb +0 -9
- data/modules/active/jboss/jboss_basic.rb +0 -9
- data/modules/active/sap/business_objects.rb +51 -60
- data/modules/active/sap/its_commands.rb +0 -9
- data/modules/active/sap/its_service_parameter.rb +0 -9
- data/modules/active/sap/its_services.rb +0 -9
- data/modules/active/sap/its_xss.rb +0 -9
- data/modules/active/shell_shock/shell_shock.rb +139 -148
- data/modules/active/siebel/siebel_apps.rb +160 -169
- data/modules/active/sqlinjection/sql_boolean.rb +0 -9
- data/modules/active/sqlinjection/sql_numerical.rb +198 -0
- data/modules/active/sqlinjection/sqli_error.rb +0 -9
- data/modules/active/sqlinjection/sqli_timing.rb +220 -229
- data/modules/active/struts2/default_handler_ognl.rb +106 -115
- data/modules/active/struts2/include_params_ognl.rb +105 -114
- data/modules/active/xml/xml_xxe.rb +112 -123
- data/modules/active/xss/xss_ng.rb +214 -223
- data/modules/active/xss/xss_simple.rb +0 -9
- data/modules/passive/ajax.rb +68 -77
- data/modules/passive/autocomplete.rb +56 -65
- data/modules/passive/cookie_options.rb +0 -9
- data/modules/passive/cookie_xss.rb +0 -9
- data/modules/passive/detect_code.rb +0 -9
- data/modules/passive/detect_fileupload.rb +0 -9
- data/modules/passive/detect_infrastructure.rb +0 -9
- data/modules/passive/detect_one_time_tokens.rb +0 -9
- data/modules/passive/dirindexing.rb +0 -9
- data/modules/passive/disclosure_domino.rb +55 -64
- data/modules/passive/disclosure_emails.rb +0 -9
- data/modules/passive/disclosure_ipaddr.rb +55 -53
- data/modules/passive/filename_as_parameter.rb +0 -9
- data/modules/passive/form_spotter.rb +0 -9
- data/modules/passive/hidden_fields.rb +50 -59
- data/modules/passive/hotspots.rb +0 -9
- data/modules/passive/in_script_parameter.rb +0 -9
- data/modules/passive/json_web_token.rb +93 -0
- data/modules/passive/multiple_server_headers.rb +0 -9
- data/modules/passive/possible_login.rb +0 -9
- data/modules/passive/redirect_url.rb +0 -9
- data/modules/passive/redirectionz.rb +0 -9
- data/modules/passive/sap-headers.rb +56 -65
- data/modules/passive/xss_dom.rb +0 -9
- data/plugins/aem/aem.rb +11 -20
- data/plugins/aem/gui/main.rb +118 -127
- data/plugins/aem/gui/tree_view.rb +171 -180
- data/plugins/aem/lib/agent.rb +130 -138
- data/plugins/aem/lib/dispatcher.rb +45 -51
- data/plugins/aem/lib/engine.rb +177 -186
- data/plugins/catalog/catalog.rb +345 -355
- data/plugins/crawler/crawler.rb +4 -13
- data/plugins/crawler/gui.rb +5 -14
- data/plugins/crawler/gui/auth_frame.rb +270 -279
- data/plugins/crawler/gui/crawler_gui.rb +271 -276
- data/plugins/crawler/gui/general_settings_frame.rb +96 -105
- data/plugins/crawler/gui/hooks_frame.rb +80 -89
- data/plugins/crawler/gui/scope_frame.rb +50 -59
- data/plugins/crawler/gui/settings_tabbook.rb +38 -47
- data/plugins/crawler/gui/status_frame.rb +59 -68
- data/plugins/crawler/lib/bags.rb +18 -27
- data/plugins/crawler/lib/constants.rb +11 -20
- data/plugins/crawler/lib/engine.rb +488 -497
- data/plugins/crawler/lib/grabber.rb +68 -77
- data/plugins/crawler/lib/status.rb +71 -80
- data/plugins/crawler/lib/uri_mp.rb +12 -21
- data/plugins/filefinder/filefinder.rb +326 -333
- data/plugins/sqlmap/bin/test.rb +78 -87
- data/plugins/sqlmap/gui.rb +4 -13
- data/plugins/sqlmap/gui/main.rb +218 -227
- data/plugins/sqlmap/gui/options_frame.rb +97 -106
- data/plugins/sqlmap/lib/sqlmap_ctrl.rb +90 -100
- data/plugins/sqlmap/sqlmap.rb +2 -11
- data/plugins/sslchecker/cli/sslchecker_cli.rb +0 -9
- data/plugins/sslchecker/gui/cipher_table.rb +246 -254
- data/plugins/sslchecker/gui/gui.rb +258 -264
- data/plugins/sslchecker/gui/sslchecker.rb +4 -13
- data/plugins/sslchecker/lib/check.rb +127 -133
- data/plugins/wshell/gui/main.rb +119 -117
- data/plugins/wshell/lib/core.rb +38 -88
- data/plugins/wshell/wshell.rb +11 -20
- metadata +170 -164
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
#.
|
|
2
|
-
# request_parser.rb
|
|
3
|
-
#.
|
|
4
|
-
# Copyright 2014 by siberas, http://www.siberas.de
|
|
5
|
-
# This file is part of WATOBO (Web Application Tool Box) http://watobo.sourceforge.com
|
|
6
|
-
# WATOBO is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation version 2 of the License.
|
|
7
|
-
# WATOBO is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
8
|
-
# You should have received a copy of the GNU General Public License along with WATOBO; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
9
|
-
|
|
10
1
|
# @private
|
|
11
2
|
module Watobo#:nodoc: all
|
|
12
3
|
module Mixins
|
|
@@ -19,7 +10,7 @@ module Watobo#:nodoc: all
|
|
|
19
10
|
# Possible prefs:
|
|
20
11
|
#
|
|
21
12
|
# :code_dlmtr [String] - set ruby code delimiter
|
|
22
|
-
|
|
13
|
+
|
|
23
14
|
def parse_code(prefs={})
|
|
24
15
|
cprefs = { :code_dlmtr => '%%' } # default delimiter for ruby code
|
|
25
16
|
cprefs.update(prefs)
|
|
@@ -32,81 +23,81 @@ module Watobo#:nodoc: all
|
|
|
32
23
|
begin
|
|
33
24
|
# puts new_request
|
|
34
25
|
expr = ''
|
|
35
|
-
|
|
26
|
+
|
|
36
27
|
pos = 0
|
|
37
28
|
off = 0
|
|
38
29
|
match = []
|
|
39
30
|
code_marks = []
|
|
40
31
|
while pos >= 0 and pos < request.length
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
32
|
+
code_offset = request.index(pattern, pos)
|
|
33
|
+
|
|
34
|
+
unless code_offset.nil?
|
|
35
|
+
new_line_index = request.index("\n", pos)
|
|
36
|
+
unless new_line_index.nil?
|
|
37
|
+
if new_line_index < code_offset
|
|
47
38
|
# new_request << request[match[0]..code_offset-1] unless match.empty?
|
|
48
|
-
|
|
39
|
+
match = []
|
|
49
40
|
# pos = code_offset
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
else
|
|
60
|
-
break
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
new_request = ''
|
|
65
|
-
unless code_marks.empty?
|
|
66
|
-
code_marks.each_with_index do |cm,i|
|
|
67
|
-
#puts cm.to_yaml
|
|
68
|
-
last = i > 0 ? ( code_marks[i-1][1] + pattern.length ) : 0
|
|
69
|
-
new_request << request[last..cm[0]-1] if cm[0] > 0
|
|
70
|
-
exp_start = cm[0] + pattern.length
|
|
71
|
-
exp_end = cm[1] - 1
|
|
72
|
-
|
|
73
|
-
expression = request[exp_start..exp_end]
|
|
74
|
-
expression.strip!
|
|
75
|
-
next if expression.empty?
|
|
76
|
-
puts "DEBUG: executing: #{expression}" if $DEBUG
|
|
77
|
-
#result = expression.empty? ? "" : eval("#{expression}")
|
|
78
|
-
result = eval(expression)
|
|
79
|
-
puts "DEBUG: got #{result.class}" if $DEBUG
|
|
80
|
-
if result.is_a? File
|
|
81
|
-
data = result.read
|
|
82
|
-
result.close
|
|
83
|
-
elsif result.is_a? String
|
|
84
|
-
data = result
|
|
85
|
-
elsif result.is_a? Array
|
|
86
|
-
data = result.join
|
|
87
|
-
else
|
|
88
|
-
puts "!!!WATOBO - expression must return String or File !!!"
|
|
89
|
-
end
|
|
90
|
-
new_request << data
|
|
91
|
-
end
|
|
92
|
-
new_request << request[code_marks.last[1]+pattern.length..-2] unless code_marks.last[1] >= request.length-1
|
|
93
|
-
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
match << code_offset
|
|
44
|
+
|
|
45
|
+
if match.length == 2
|
|
46
|
+
code_marks << match.dup
|
|
47
|
+
match = []
|
|
48
|
+
end
|
|
49
|
+
pos = code_offset + pattern.length
|
|
94
50
|
else
|
|
95
|
-
|
|
51
|
+
break
|
|
96
52
|
end
|
|
97
|
-
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
new_request = ''
|
|
56
|
+
unless code_marks.empty?
|
|
57
|
+
code_marks.each_with_index do |cm,i|
|
|
58
|
+
#puts cm.to_yaml
|
|
59
|
+
last = i > 0 ? ( code_marks[i-1][1] + pattern.length ) : 0
|
|
60
|
+
new_request << request[last..cm[0]-1] if cm[0] > 0
|
|
61
|
+
exp_start = cm[0] + pattern.length
|
|
62
|
+
exp_end = cm[1] - 1
|
|
63
|
+
|
|
64
|
+
expression = request[exp_start..exp_end]
|
|
65
|
+
expression.strip!
|
|
66
|
+
next if expression.empty?
|
|
67
|
+
puts "DEBUG: executing: #{expression}" if $DEBUG
|
|
68
|
+
#result = expression.empty? ? "" : eval("#{expression}")
|
|
69
|
+
result = eval(expression)
|
|
70
|
+
puts "DEBUG: got #{result.class}" if $DEBUG
|
|
71
|
+
if result.is_a? File
|
|
72
|
+
data = result.read
|
|
73
|
+
result.close
|
|
74
|
+
elsif result.is_a? String
|
|
75
|
+
data = result
|
|
76
|
+
elsif result.is_a? Array
|
|
77
|
+
data = result.join
|
|
78
|
+
else
|
|
79
|
+
puts "!!!WATOBO - expression must return String or File !!!"
|
|
80
|
+
end
|
|
81
|
+
new_request << data
|
|
82
|
+
end
|
|
83
|
+
new_request << request[code_marks.last[1]+pattern.length..-1] unless code_marks.last[1] >= request.length-1
|
|
84
|
+
|
|
85
|
+
else
|
|
86
|
+
new_request = request
|
|
87
|
+
end
|
|
88
|
+
|
|
98
89
|
return new_request
|
|
99
90
|
|
|
100
91
|
rescue SyntaxError, LocalJumpError, NameError => e
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
92
|
+
# raise SyntaxError, "SyntaxError in '#{expression}'"
|
|
93
|
+
puts e
|
|
94
|
+
puts e.backtrace
|
|
95
|
+
|
|
105
96
|
end
|
|
106
97
|
return nil
|
|
107
98
|
end
|
|
108
99
|
|
|
109
|
-
|
|
100
|
+
|
|
110
101
|
def to_request(opts={})
|
|
111
102
|
options = { :update_content_length => false }
|
|
112
103
|
options.update opts
|
|
@@ -114,25 +105,25 @@ module Watobo#:nodoc: all
|
|
|
114
105
|
begin
|
|
115
106
|
text = parse_code
|
|
116
107
|
request = []
|
|
117
|
-
|
|
108
|
+
|
|
118
109
|
eoh = nil
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
110
|
+
eoh = text.index("\n\n") unless text.nil?
|
|
111
|
+
|
|
112
|
+
unless eoh.nil?
|
|
113
|
+
header = text.slice(0, eoh).split("\n").map{|h| "#{h}\r\n"}
|
|
114
|
+
body = text.slice(eoh+2, text.length-1)
|
|
115
|
+
else
|
|
125
116
|
header = text.split(/\n/).map{|h| "#{h}\r\n"}
|
|
126
117
|
body = nil
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
request.concat header
|
|
121
|
+
|
|
122
|
+
#Watobo::Request.create request
|
|
123
|
+
request = Watobo::Request.new(request)
|
|
130
124
|
|
|
131
|
-
#Watobo::Request.create request
|
|
132
|
-
request = Watobo::Request.new(request)
|
|
133
|
-
|
|
134
125
|
ct = request.content_type_ex
|
|
135
|
-
|
|
126
|
+
# puts ct
|
|
136
127
|
# last line is without "\r\n" if text has a body
|
|
137
128
|
if ct =~ /multipart/ and body then
|
|
138
129
|
#Content-Type: multipart/form-data; boundary=---------------------------3035221901842
|
|
@@ -176,7 +167,7 @@ module Watobo#:nodoc: all
|
|
|
176
167
|
request.push "\r\n"
|
|
177
168
|
request.push body.strip
|
|
178
169
|
end
|
|
179
|
-
|
|
170
|
+
|
|
180
171
|
request.fixupContentLength() if options[:update_content_length] == true
|
|
181
172
|
return request
|
|
182
173
|
rescue => bang
|
|
@@ -186,7 +177,7 @@ module Watobo#:nodoc: all
|
|
|
186
177
|
end
|
|
187
178
|
#return nil
|
|
188
179
|
end
|
|
189
|
-
|
|
180
|
+
|
|
190
181
|
def to_response(opts={})
|
|
191
182
|
options = { :update_content_length => false }
|
|
192
183
|
options.update opts
|
|
@@ -208,14 +199,14 @@ module Watobo#:nodoc: all
|
|
|
208
199
|
end
|
|
209
200
|
|
|
210
201
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
202
|
+
#Watobo::Response.create result
|
|
203
|
+
result = Watobo::Response.new(result)
|
|
204
|
+
|
|
214
205
|
if body then
|
|
215
206
|
result.push "\r\n"
|
|
216
207
|
result.push body.strip
|
|
217
208
|
end
|
|
218
|
-
|
|
209
|
+
|
|
219
210
|
result.fixupContentLength() if options[:update_content_length] == true
|
|
220
211
|
puts ">>"
|
|
221
212
|
puts result
|
|
@@ -249,11 +240,11 @@ module Watobo#:nodoc: all
|
|
|
249
240
|
result.push "#{h}\r\n"
|
|
250
241
|
end
|
|
251
242
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
243
|
+
# result.extend Watobo::Mixin::Parser::Url
|
|
244
|
+
# result.extend Watobo::Mixin::Parser::Web10
|
|
245
|
+
# result.extend Watobo::Mixin::Shaper::Web10
|
|
246
|
+
#Watobo::Request.create result
|
|
247
|
+
result = Watobo::Request.new(result)
|
|
257
248
|
|
|
258
249
|
ct = result.content_type
|
|
259
250
|
# last line is without "\r\n" if text has a body
|
|
@@ -316,8 +307,8 @@ if $0 == __FILE__
|
|
|
316
307
|
$: << inc_path
|
|
317
308
|
|
|
318
309
|
require 'watobo'
|
|
319
|
-
|
|
320
|
-
text =<<'EOF'
|
|
310
|
+
|
|
311
|
+
text =<<'EOF'
|
|
321
312
|
%%"GET"%% http://www.siberas.de/ HTTP/1.1
|
|
322
313
|
Content-Type: text/html
|
|
323
314
|
%%"x"*10%%Vary: Accept-Encoding
|
|
@@ -339,4 +330,4 @@ puts
|
|
|
339
330
|
text.extend Watobo::Mixins::RequestParser
|
|
340
331
|
puts text.to_request
|
|
341
332
|
Watobo::Utils.hexprint text
|
|
342
|
-
end
|
|
333
|
+
end
|
|
@@ -1,529 +1,515 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
#
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
self.first.gsub!(/([
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
ns <<
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
def
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
self.
|
|
118
|
-
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
def
|
|
122
|
-
line = self.
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
self.
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
self_copy
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
self.
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
#
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
self_copy
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
self.
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
#
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
end
|
|
482
|
-
|
|
483
|
-
end
|
|
484
|
-
|
|
485
|
-
def unzip
|
|
486
|
-
if self.content_encoding == TE_GZIP or self.transfer_encoding == TE_GZIP
|
|
487
|
-
if self.has_body?
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
data = gz.read
|
|
517
|
-
return data
|
|
518
|
-
end
|
|
519
|
-
|
|
520
|
-
rescue => bang
|
|
521
|
-
puts bang
|
|
522
|
-
end
|
|
523
|
-
|
|
524
|
-
end
|
|
525
|
-
|
|
526
|
-
end
|
|
527
|
-
end
|
|
528
|
-
end
|
|
529
|
-
end
|
|
1
|
+
# @private
|
|
2
|
+
module Watobo #:nodoc: all
|
|
3
|
+
module Mixin
|
|
4
|
+
module Shaper
|
|
5
|
+
module Web10
|
|
6
|
+
include Watobo::Constants
|
|
7
|
+
|
|
8
|
+
def replace_post_parm(parm, value)
|
|
9
|
+
parm_quoted = Regexp.quote(parm)
|
|
10
|
+
self.last.gsub!(/([?&]{1}|^)#{parm_quoted}=([^&]*)(&{0,1})/i, "\\1#{parm}=#{value}\\3")
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def replace_get_parm(parm, value)
|
|
14
|
+
parm_quoted = Regexp.quote(parm)
|
|
15
|
+
self.first.gsub!(/([?&]{1})#{parm_quoted}=([^ &]*)(&{0,1})/i, "\\1#{parm}=#{value}\\3")
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def replaceMethod(new_method)
|
|
19
|
+
self.first.gsub!(/^[^[:space:]]{1,}/i, "#{new_method}")
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def replaceFileExt(new_file)
|
|
23
|
+
begin
|
|
24
|
+
file = new_file.strip
|
|
25
|
+
file.gsub!(/^\//, "")
|
|
26
|
+
self.first.gsub!(/([^\?]*\/)(.*) (HTTP.*)/i, "\\1#{file} \\3")
|
|
27
|
+
rescue => bang
|
|
28
|
+
puts bang
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def replaceElement(new_element)
|
|
33
|
+
new_element.gsub!(/^\//, "")
|
|
34
|
+
self.first.gsub!(/([^\?]*\/)(.*) (HTTP.*)/i, "\\1#{new_element} \\3")
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def replaceURL(new_url)
|
|
38
|
+
self.first.gsub!(/(^[^[:space:]]{1,}) (.*) (HTTP.*)/i, "\\1 #{new_url} \\3")
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def replaceQuery(new_query)
|
|
42
|
+
new_query.gsub!(/^\//, "")
|
|
43
|
+
self.first.gsub!(/(.*\/)(.*) (HTTP.*)/i, "\\1#{new_query} \\3")
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def strip_path()
|
|
47
|
+
self.first.gsub!(/([^\?]*\/)(.*) (HTTP.*)/i, "\\1# \\3")
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def setDir(dir)
|
|
51
|
+
dir.strip!
|
|
52
|
+
dir.gsub!(/^\/+/, "")
|
|
53
|
+
dir.gsub!(/\/+$/, "")
|
|
54
|
+
dir += "/" unless dir == ''
|
|
55
|
+
self.first.gsub!(/(^[^[:space:]]{1,} https?:\/\/[\-0-9a-zA-Z.]*[:0-9]{0,6}\/)(.*)( HTTP\/.*)/, "\\1#{dir}\\3")
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
#
|
|
59
|
+
# set a new file extension, e.g. mysite.html to mysite.php
|
|
60
|
+
# if no extension nor a file is given, the new extension will only be appended
|
|
61
|
+
# note: the first leading dot will be removed
|
|
62
|
+
# possible preferences are:
|
|
63
|
+
# :keep_query => keeps query parameters
|
|
64
|
+
# default-set is empty
|
|
65
|
+
def set_file_extension(nxt, *prefs)
|
|
66
|
+
return self.first if nxt.nil?
|
|
67
|
+
nxt.gsub!(/^\./, '')
|
|
68
|
+
s = "#{self.first}"
|
|
69
|
+
fend = nil
|
|
70
|
+
pend = nil
|
|
71
|
+
|
|
72
|
+
pstart = s.index('?')
|
|
73
|
+
pend = s.rindex(/ HTTP\//)
|
|
74
|
+
|
|
75
|
+
fend = (pstart - 1) unless pstart.nil?
|
|
76
|
+
fend = (pend - 1) if fend.nil?
|
|
77
|
+
|
|
78
|
+
return self.first if fend.nil?
|
|
79
|
+
|
|
80
|
+
fstart = s.rindex('/', fend)
|
|
81
|
+
unless s[fstart-1] == '/'
|
|
82
|
+
fstart += 1 unless fstart.nil?
|
|
83
|
+
else
|
|
84
|
+
fstart = fend
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
fname = s[fstart..fend]
|
|
88
|
+
fname.gsub!(/\..*/, '')
|
|
89
|
+
fname << ".#{nxt}"
|
|
90
|
+
|
|
91
|
+
ns = s[0..fstart-1]
|
|
92
|
+
ns << fname
|
|
93
|
+
|
|
94
|
+
if prefs.include? :keep_query
|
|
95
|
+
unless pstart.nil?
|
|
96
|
+
ns << s[pstart..pend]
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
ns << s[pend..-1]
|
|
101
|
+
|
|
102
|
+
self.first.replace ns
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def appendDir(dir)
|
|
106
|
+
dir.strip!
|
|
107
|
+
dir.gsub!(/^\//, "")
|
|
108
|
+
dir << "/" unless dir =~ /\/$/
|
|
109
|
+
self.first.gsub!(/(^[^[:space:]]{1,} https?:\/\/[\-0-9a-zA-Z.]*[:0-9]{0,6}.*\/).*( HTTP\/.*)/, "\\1#{dir}\\2")
|
|
110
|
+
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def add_post_parm(parm, value)
|
|
114
|
+
line = self.last
|
|
115
|
+
return false if line !~ /=/
|
|
116
|
+
line += "&#{parm}=#{value}"
|
|
117
|
+
self.pop
|
|
118
|
+
self.push line
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def add_get_parm(parm, value)
|
|
122
|
+
line = self.shift
|
|
123
|
+
new_p = "&"
|
|
124
|
+
new_p = "?" if not self.element =~ /\?/
|
|
125
|
+
new_p += parm
|
|
126
|
+
line.gsub!(/( HTTP\/.*)/, "#{new_p}=#{value}\\1")
|
|
127
|
+
self.unshift(line)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def addHeader(header, value)
|
|
131
|
+
self_copy = []
|
|
132
|
+
self_copy.concat(self.headers)
|
|
133
|
+
self_copy.push "#{header}: #{value}\r\n"
|
|
134
|
+
|
|
135
|
+
unless self.body.nil?
|
|
136
|
+
self_copy.push "\r\n"
|
|
137
|
+
#self_copy.concat(self.body)
|
|
138
|
+
self_copy.push self.body
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
self.replace(self_copy)
|
|
142
|
+
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
alias_method :add_header, :addHeader
|
|
146
|
+
|
|
147
|
+
def removeURI
|
|
148
|
+
if self.first =~ /(^[^[:space:]]{1,}) (https?:\/\/[\-0-9a-zA-Z.]*[:0-9]{0,6}\/)/ then
|
|
149
|
+
uri = $2
|
|
150
|
+
self.first.gsub!(/(^[^[:space:]]{1,}) (#{Regexp.quote(uri)})/, "\\1 /")
|
|
151
|
+
# puts "* Removed URI: #{uri}"
|
|
152
|
+
# puts self.first
|
|
153
|
+
return uri
|
|
154
|
+
else
|
|
155
|
+
return nil
|
|
156
|
+
end
|
|
157
|
+
#self.first.gsub!(/^(.*)(https?:\/\/[\-0-9a-zA-Z.]*[:0-9]{0,6}\/)/,"\\1/")
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
def removeBody
|
|
161
|
+
self.pop if self[-2].strip.empty?
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
def set_body(content)
|
|
165
|
+
if self[-2].strip.empty?
|
|
166
|
+
self.pop
|
|
167
|
+
else
|
|
168
|
+
self << "\r\n"
|
|
169
|
+
end
|
|
170
|
+
self << content
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
def rewrite_body(pattern, content)
|
|
174
|
+
if self.has_body?
|
|
175
|
+
#puts "rewrite_body ... #{pattern} - #{content}"
|
|
176
|
+
b = self.pop
|
|
177
|
+
b.gsub!(/#{pattern}/i, content)
|
|
178
|
+
self << b
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
def restoreURI(uri)
|
|
183
|
+
if self.first =~ /(^[^[:space:]]{1,}) \/(.*) (HTTP\/.*)/ then
|
|
184
|
+
method = $1
|
|
185
|
+
rest = $2
|
|
186
|
+
http = $3.strip
|
|
187
|
+
#self.first.gsub!(/^\w*/, "#{method} #{uri}#{rest}")
|
|
188
|
+
self.shift
|
|
189
|
+
self.unshift "#{method} #{uri}#{rest} #{http}\r\n"
|
|
190
|
+
return self.first
|
|
191
|
+
else
|
|
192
|
+
return nil
|
|
193
|
+
end
|
|
194
|
+
#self.first.gsub!(/^(.*)(https?:\/\/[\-0-9a-zA-Z.]*[:0-9]{0,6}\/)/,"\\1/")
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
#
|
|
198
|
+
# R E M O V E _ H E A D E R
|
|
199
|
+
#
|
|
200
|
+
|
|
201
|
+
def removeHeader(header)
|
|
202
|
+
begin
|
|
203
|
+
|
|
204
|
+
while i = headers.index { |h| h =~ /#{header}/i }
|
|
205
|
+
self.delete_at i
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
rescue => bang
|
|
209
|
+
puts bang
|
|
210
|
+
puts bang.backtrace if $DEBUG
|
|
211
|
+
puts self
|
|
212
|
+
puts "====="
|
|
213
|
+
end
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
alias_method :remove_header, :removeHeader
|
|
217
|
+
|
|
218
|
+
# removeUrlParms
|
|
219
|
+
# Function: Remove all parameter within the URL
|
|
220
|
+
#
|
|
221
|
+
def removeUrlParms
|
|
222
|
+
line = self.shift
|
|
223
|
+
return false if line.nil?
|
|
224
|
+
new_line = "#{line}"
|
|
225
|
+
# get end-of-path-index
|
|
226
|
+
eop_index = line.rindex(/[^ HTTP]\//)
|
|
227
|
+
# get start of parms
|
|
228
|
+
sop_index = line.index(/(\?|&)/, eop_index)
|
|
229
|
+
# find end-of-url
|
|
230
|
+
eou_index = line.index(/ HTTP/)
|
|
231
|
+
|
|
232
|
+
unless sop_index.nil? or eou_index.nil?
|
|
233
|
+
new_line = line[0..sop_index-1]
|
|
234
|
+
new_line += line[eou_index..-1]
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
self.unshift new_line
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
def removeHeader_OLD(header)
|
|
241
|
+
# p "REMOVE HEADER: #{header}"
|
|
242
|
+
begin
|
|
243
|
+
self_copy = []
|
|
244
|
+
eoh = false
|
|
245
|
+
self.each do |line|
|
|
246
|
+
puts self if line.nil?
|
|
247
|
+
if not eoh == true then
|
|
248
|
+
if not line =~ /#{header}/i
|
|
249
|
+
self_copy.push line unless line.nil?
|
|
250
|
+
end
|
|
251
|
+
else
|
|
252
|
+
self_copy.push line unless line.nil?
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
if line and line.strip.empty? then
|
|
256
|
+
eoh = true
|
|
257
|
+
end
|
|
258
|
+
end
|
|
259
|
+
self.replace(self_copy)
|
|
260
|
+
|
|
261
|
+
rescue => bang
|
|
262
|
+
puts bang
|
|
263
|
+
puts bang.backtrace if $DEBUG
|
|
264
|
+
puts self
|
|
265
|
+
puts "====="
|
|
266
|
+
end
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
def replace_header(header, value)
|
|
270
|
+
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
def fix_session(pattern, value)
|
|
274
|
+
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
def fix_content_length
|
|
278
|
+
return false if self.body.nil?
|
|
279
|
+
# had trouble with length calculation of binary data in multipart request
|
|
280
|
+
blen = self.body.force_encoding("ASCII-8BIT").length
|
|
281
|
+
set_header("Content-Length", blen)
|
|
282
|
+
end
|
|
283
|
+
|
|
284
|
+
def fixupContentLength_UNUSED
|
|
285
|
+
te = self.transferEncoding
|
|
286
|
+
if te == TE_CHUNKED then
|
|
287
|
+
# puts "Transfer-Encoding = TE_CHUNKED"
|
|
288
|
+
# puts self.body
|
|
289
|
+
self.removeHeader("Transfer-Encoding")
|
|
290
|
+
self.addHeader("Content-Length", "0")
|
|
291
|
+
new_r = []
|
|
292
|
+
new_r.concat self.headers
|
|
293
|
+
new_r.push "\r\n"
|
|
294
|
+
|
|
295
|
+
bytes_to_read = 0
|
|
296
|
+
body = []
|
|
297
|
+
is_new_chunk = false
|
|
298
|
+
|
|
299
|
+
off = 0
|
|
300
|
+
new_body = ''
|
|
301
|
+
|
|
302
|
+
body_orig = self.body
|
|
303
|
+
puts body_orig.class
|
|
304
|
+
while body_orig[off..-1] =~ /^([0-9a-fA-F]{1,6})\r\n/
|
|
305
|
+
len_raw = "#{$1}"
|
|
306
|
+
|
|
307
|
+
len = len_raw.hex
|
|
308
|
+
|
|
309
|
+
chunk_start = off + len_raw.length + 2
|
|
310
|
+
chunk_end = chunk_start + len
|
|
311
|
+
|
|
312
|
+
break if len == 0
|
|
313
|
+
|
|
314
|
+
new_body.chomp!
|
|
315
|
+
new_body += "#{body_orig[chunk_start..chunk_end]}"
|
|
316
|
+
|
|
317
|
+
off = chunk_end + 2
|
|
318
|
+
end
|
|
319
|
+
|
|
320
|
+
new_r.push new_body
|
|
321
|
+
self.replace(new_r)
|
|
322
|
+
self.fix_content_length
|
|
323
|
+
# puts "= FIXED ="
|
|
324
|
+
# puts self.headers
|
|
325
|
+
elsif te == TE_NONE then
|
|
326
|
+
self.fix_content_length
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
end
|
|
330
|
+
|
|
331
|
+
def fixupContentLength
|
|
332
|
+
self.unchunk
|
|
333
|
+
self.fix_content_length
|
|
334
|
+
end
|
|
335
|
+
|
|
336
|
+
def setRawQueryParms(parm_string)
|
|
337
|
+
return nil if parm_string.nil?
|
|
338
|
+
return nil if parm_string == ''
|
|
339
|
+
new_r = ""
|
|
340
|
+
path = Regexp.quote(self.path)
|
|
341
|
+
#puts path
|
|
342
|
+
if self.first =~ /(.*#{path})/ then
|
|
343
|
+
new_r = $1 << "?" << parm_string
|
|
344
|
+
end
|
|
345
|
+
self.first.gsub!(/(.*) (HTTP\/.*)/, "#{new_r} \\2")
|
|
346
|
+
end
|
|
347
|
+
|
|
348
|
+
def appendQueryParms(parms)
|
|
349
|
+
return if parms.nil?
|
|
350
|
+
return if parms == ''
|
|
351
|
+
|
|
352
|
+
puts self.first
|
|
353
|
+
puts self.file_ext
|
|
354
|
+
|
|
355
|
+
pref = (self.file_ext =~ /\?/) ? '&' : '?'
|
|
356
|
+
puts "append query parms"
|
|
357
|
+
self.first.gsub!(/(.*) (HTTP\/.*)/, "\\1#{pref}#{parms} \\2")
|
|
358
|
+
|
|
359
|
+
end
|
|
360
|
+
|
|
361
|
+
def set_content_length(length)
|
|
362
|
+
set_header("Content-Length", length)
|
|
363
|
+
end
|
|
364
|
+
|
|
365
|
+
def set_content_type(ctype)
|
|
366
|
+
set_header("Content-Type", ctype)
|
|
367
|
+
end
|
|
368
|
+
|
|
369
|
+
def set_header(header, value)
|
|
370
|
+
begin
|
|
371
|
+
new_header = "#{header}: #{value}\r\n"
|
|
372
|
+
self.each_with_index do |h, i|
|
|
373
|
+
if h =~ /^#{Regexp.quote(header)}:/i
|
|
374
|
+
self[i] = new_header
|
|
375
|
+
return true
|
|
376
|
+
end
|
|
377
|
+
|
|
378
|
+
if h.strip.empty? or i == self.length-1
|
|
379
|
+
self.insert(i, new_header)
|
|
380
|
+
return true
|
|
381
|
+
end
|
|
382
|
+
end
|
|
383
|
+
rescue => bang
|
|
384
|
+
puts bang
|
|
385
|
+
end
|
|
386
|
+
return false
|
|
387
|
+
end
|
|
388
|
+
|
|
389
|
+
alias :setHeader :set_header
|
|
390
|
+
|
|
391
|
+
# sets post data
|
|
392
|
+
def setData(data)
|
|
393
|
+
return if data.nil?
|
|
394
|
+
if self.has_body?
|
|
395
|
+
self.pop
|
|
396
|
+
self.push data
|
|
397
|
+
else
|
|
398
|
+
self.push("\r\n")
|
|
399
|
+
self.push data
|
|
400
|
+
end
|
|
401
|
+
end
|
|
402
|
+
|
|
403
|
+
def setMethod(method)
|
|
404
|
+
m = method.is_a?(Symbol) ? method.to_s.upcase : method
|
|
405
|
+
self.first.gsub!(/(^[^[:space:]]{1,}) /, "#{m} ")
|
|
406
|
+
end
|
|
407
|
+
|
|
408
|
+
alias_method :set_method, :setMethod
|
|
409
|
+
alias :method= :setMethod
|
|
410
|
+
|
|
411
|
+
def setHTTPVersion(version)
|
|
412
|
+
self.first.gsub!(/HTTP\/(.*)$/, "HTTP\/#{version}")
|
|
413
|
+
# puts "HTTPVersion fixed: #{self.first}"
|
|
414
|
+
end
|
|
415
|
+
|
|
416
|
+
end
|
|
417
|
+
|
|
418
|
+
module HttpResponse
|
|
419
|
+
include Watobo::Constants
|
|
420
|
+
|
|
421
|
+
def unchunk!
|
|
422
|
+
return false unless self.has_body?
|
|
423
|
+
|
|
424
|
+
unchunked = self.unchunk
|
|
425
|
+
self.replace(unchunked)
|
|
426
|
+
self.fix_content_length
|
|
427
|
+
|
|
428
|
+
end
|
|
429
|
+
|
|
430
|
+
def unchunk
|
|
431
|
+
return Response.new(self) unless self.has_body?
|
|
432
|
+
|
|
433
|
+
if self.transfer_encoding == TE_CHUNKED then
|
|
434
|
+
self.removeHeader("Transfer-Encoding")
|
|
435
|
+
self.addHeader("Content-Length", "0")
|
|
436
|
+
new_r = []
|
|
437
|
+
new_r.concat self.headers
|
|
438
|
+
new_r.push "\r\n"
|
|
439
|
+
|
|
440
|
+
bytes_to_read = 20
|
|
441
|
+
body = []
|
|
442
|
+
is_new_chunk = false
|
|
443
|
+
|
|
444
|
+
off = 0
|
|
445
|
+
new_body = ''
|
|
446
|
+
|
|
447
|
+
body_orig = self.body
|
|
448
|
+
pattern = '[0-9a-fA-F]+\r?\n'
|
|
449
|
+
while off >= 0 and off < body_orig.length
|
|
450
|
+
chunk_pos = body_orig.index(/(#{pattern})/, off)
|
|
451
|
+
len_raw = $1
|
|
452
|
+
unless chunk_pos.nil?
|
|
453
|
+
len = len_raw.strip.hex
|
|
454
|
+
|
|
455
|
+
chunk_start = chunk_pos + len_raw.length
|
|
456
|
+
chunk_end = chunk_start + len
|
|
457
|
+
|
|
458
|
+
break if len == 0
|
|
459
|
+
chunk = "#{body_orig[chunk_start..chunk_end]}"
|
|
460
|
+
new_body += chunk.chomp
|
|
461
|
+
off = chunk_end
|
|
462
|
+
end
|
|
463
|
+
end
|
|
464
|
+
new_r.push new_body
|
|
465
|
+
return Watobo::Response.new new_r
|
|
466
|
+
|
|
467
|
+
end
|
|
468
|
+
return Response.new(self)
|
|
469
|
+
end
|
|
470
|
+
|
|
471
|
+
def unzip!
|
|
472
|
+
if self.content_encoding == TE_GZIP or self.transfer_encoding == TE_GZIP
|
|
473
|
+
if self.has_body?
|
|
474
|
+
unziped = self.unzip_body
|
|
475
|
+
|
|
476
|
+
self[-1] = unziped
|
|
477
|
+
self.removeHeader("Transfer-Encoding") if self.transfer_encoding == TE_GZIP
|
|
478
|
+
self.removeHeader("Content-Encoding") if self.content_encoding == TE_GZIP
|
|
479
|
+
self.fix_content_length
|
|
480
|
+
end
|
|
481
|
+
end
|
|
482
|
+
|
|
483
|
+
end
|
|
484
|
+
|
|
485
|
+
def unzip
|
|
486
|
+
if self.content_encoding == TE_GZIP or self.transfer_encoding == TE_GZIP
|
|
487
|
+
if self.has_body?
|
|
488
|
+
unzipped = Response.new(self)
|
|
489
|
+
unzipped.unzip!
|
|
490
|
+
return unzipped
|
|
491
|
+
end
|
|
492
|
+
end
|
|
493
|
+
|
|
494
|
+
return Response.new(self)
|
|
495
|
+
end
|
|
496
|
+
|
|
497
|
+
def unzip_body
|
|
498
|
+
begin
|
|
499
|
+
if self.has_body?
|
|
500
|
+
gziped = self.last
|
|
501
|
+
gz = Zlib::GzipReader.new(StringIO.new(gziped))
|
|
502
|
+
data = gz.read
|
|
503
|
+
return data
|
|
504
|
+
end
|
|
505
|
+
|
|
506
|
+
rescue => bang
|
|
507
|
+
puts bang
|
|
508
|
+
end
|
|
509
|
+
|
|
510
|
+
end
|
|
511
|
+
|
|
512
|
+
end
|
|
513
|
+
end
|
|
514
|
+
end
|
|
515
|
+
end
|