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,25 +1,23 @@
|
|
|
1
|
-
#.
|
|
2
|
-
# transparent.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
|
-
module Watobo#:nodoc: all
|
|
12
|
-
module Interceptor
|
|
13
|
-
module Transparent
|
|
14
|
-
@nfq_drb = nil
|
|
15
|
-
def self.start
|
|
16
|
-
DRb.start_service
|
|
17
|
-
@nfq_drb = DRbObject.new nil, "druby://127.0.0.1:9090"
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def self.info(data)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
2
|
+
module Watobo#:nodoc: all
|
|
3
|
+
module Interceptor
|
|
4
|
+
module Transparent
|
|
5
|
+
@nfq_drb = nil
|
|
6
|
+
def self.start
|
|
7
|
+
DRb.start_service
|
|
8
|
+
@nfq_drb = DRbObject.new nil, "druby://127.0.0.1:9090"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.info(data)
|
|
12
|
+
nfo = nil
|
|
13
|
+
begin
|
|
14
|
+
nfo = @nfq_drb.info(data)
|
|
15
|
+
rescue => bang
|
|
16
|
+
puts "! could not query nfq_server"
|
|
17
|
+
puts bang
|
|
18
|
+
end
|
|
19
|
+
nfo
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
data/lib/watobo/mixins.rb
CHANGED
|
@@ -1,21 +1,12 @@
|
|
|
1
|
-
#.
|
|
2
|
-
# mixins.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
|
-
module Watobo#:nodoc: all
|
|
12
|
-
module Mixins
|
|
13
|
-
mixins_path = File.expand_path(File.join(File.dirname(__FILE__), "mixins"))
|
|
14
|
-
# puts "* loading mixins #{mixins_path}"
|
|
15
|
-
Dir.glob("#{mixins_path}/*.rb").each do |cf|
|
|
16
|
-
puts "+ #{File.basename(cf)}" if $DEBUG
|
|
17
|
-
require File.join("watobo","mixins", File.basename(cf))
|
|
18
|
-
|
|
19
|
-
end
|
|
20
|
-
end
|
|
2
|
+
module Watobo#:nodoc: all
|
|
3
|
+
module Mixins
|
|
4
|
+
mixins_path = File.expand_path(File.join(File.dirname(__FILE__), "mixins"))
|
|
5
|
+
# puts "* loading mixins #{mixins_path}"
|
|
6
|
+
Dir.glob("#{mixins_path}/*.rb").each do |cf|
|
|
7
|
+
puts "+ #{File.basename(cf)}" if $DEBUG
|
|
8
|
+
require File.join("watobo","mixins", File.basename(cf))
|
|
9
|
+
|
|
10
|
+
end
|
|
11
|
+
end
|
|
21
12
|
end
|
|
@@ -1,38 +1,29 @@
|
|
|
1
|
-
#.
|
|
2
|
-
# check_info.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
|
-
module Watobo#:nodoc: all
|
|
12
|
-
module CheckInfoMixin
|
|
13
|
-
module InfoMethods
|
|
14
|
-
def check_name
|
|
15
|
-
|
|
16
|
-
#puts self.methods.sort
|
|
17
|
-
info = instance_variable_get("@info")
|
|
18
|
-
return nil if info.nil?
|
|
19
|
-
return info[:check_name]
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def check_group
|
|
23
|
-
info = instance_variable_get("@info")
|
|
24
|
-
return nil if info.nil?
|
|
25
|
-
return info[:check_group]
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
extend InfoMethods
|
|
31
|
-
|
|
32
|
-
def self.included( other )
|
|
33
|
-
other.extend InfoMethods
|
|
34
|
-
end
|
|
35
|
-
#:name => "#{check.info[:check_group]}|#{check.info[:check_name]}",
|
|
36
|
-
|
|
37
|
-
end
|
|
2
|
+
module Watobo#:nodoc: all
|
|
3
|
+
module CheckInfoMixin
|
|
4
|
+
module InfoMethods
|
|
5
|
+
def check_name
|
|
6
|
+
|
|
7
|
+
#puts self.methods.sort
|
|
8
|
+
info = instance_variable_get("@info")
|
|
9
|
+
return nil if info.nil?
|
|
10
|
+
return info[:check_name]
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def check_group
|
|
14
|
+
info = instance_variable_get("@info")
|
|
15
|
+
return nil if info.nil?
|
|
16
|
+
return info[:check_group]
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
extend InfoMethods
|
|
22
|
+
|
|
23
|
+
def self.included( other )
|
|
24
|
+
other.extend InfoMethods
|
|
25
|
+
end
|
|
26
|
+
#:name => "#{check.info[:check_group]}|#{check.info[:check_name]}",
|
|
27
|
+
|
|
28
|
+
end
|
|
38
29
|
end
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
#.
|
|
2
|
-
# httpparser.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
|
# http://www.ietf.org/rfc/rfc2396.txt
|
|
11
2
|
# http://en.wikipedia.org/wiki/URI_scheme
|
|
12
3
|
|
|
@@ -25,749 +16,734 @@
|
|
|
25
16
|
# path_ext = "my/path/show.php?p=aaa&debug=true"
|
|
26
17
|
|
|
27
18
|
# @private
|
|
28
|
-
module Watobo#:nodoc: all
|
|
19
|
+
module Watobo #:nodoc: all
|
|
29
20
|
module Mixin
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
module Url
|
|
40
|
-
include Watobo::Constants
|
|
41
|
-
def file
|
|
42
|
-
#@file ||= nil
|
|
43
|
-
#return @file unless @file.nil?
|
|
44
|
-
if self.first =~ /^[^[:space:]]{1,} [a-zA-Z]+:\/\/[\-0-9a-zA-Z.]*[:0-9]{0,6}[^\?]*\/(.*) HTTP.*/
|
|
45
|
-
tmp = $1
|
|
46
|
-
end_of_file_index = tmp.index(/\?/)
|
|
47
|
-
|
|
48
|
-
if end_of_file_index.nil?
|
|
49
|
-
@file = tmp
|
|
50
|
-
elsif end_of_file_index == 0
|
|
51
|
-
@file = ""
|
|
52
|
-
else
|
|
53
|
-
@file = tmp[0..end_of_file_index-1]
|
|
54
|
-
end
|
|
21
|
+
module Parser
|
|
22
|
+
|
|
23
|
+
module Parameters
|
|
24
|
+
def each(prefs, &block)
|
|
25
|
+
|
|
55
26
|
|
|
56
|
-
else
|
|
57
|
-
@file = ""
|
|
58
27
|
end
|
|
59
28
|
end
|
|
60
29
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
30
|
+
module Url
|
|
31
|
+
include Watobo::Constants
|
|
32
|
+
|
|
33
|
+
def file
|
|
34
|
+
#@file ||= nil
|
|
35
|
+
#return @file unless @file.nil?
|
|
36
|
+
if self.first =~ /^[^[:space:]]{1,} [a-zA-Z]+:\/\/[\-0-9a-zA-Z.]*[:0-9]{0,6}[^\?]*\/(.*) HTTP.*/
|
|
37
|
+
tmp = $1
|
|
38
|
+
end_of_file_index = tmp.index(/\?/)
|
|
39
|
+
|
|
40
|
+
if end_of_file_index.nil?
|
|
41
|
+
@file = tmp
|
|
42
|
+
elsif end_of_file_index == 0
|
|
43
|
+
@file = ""
|
|
44
|
+
else
|
|
45
|
+
@file = tmp[0..end_of_file_index-1]
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
else
|
|
49
|
+
@file = ""
|
|
50
|
+
end
|
|
68
51
|
end
|
|
69
|
-
end
|
|
70
52
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
return parms
|
|
81
|
-
rescue => bang
|
|
82
|
-
puts bang
|
|
83
|
-
puts bang.backtrace if $DEBUG
|
|
84
|
-
end
|
|
85
|
-
return nil
|
|
86
|
-
end
|
|
53
|
+
def file_ext
|
|
54
|
+
#@file_ext ||= nil
|
|
55
|
+
#return @file_ext unless @file_ext.nil?
|
|
56
|
+
if self.first =~ /^[^[:space:]]{1,} [a-zA-Z]+:\/\/[\-0-9a-zA-Z.]*[:0-9]{0,6}[^\?]*\/(.*) HTTP.*/
|
|
57
|
+
@file_ext = $1
|
|
58
|
+
else
|
|
59
|
+
@file_ext = ''
|
|
60
|
+
end
|
|
61
|
+
end
|
|
87
62
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
63
|
+
# returns a string containing all urlparms
|
|
64
|
+
# e.g. "parm1=first&parm2=second"
|
|
65
|
+
def urlparms
|
|
66
|
+
begin
|
|
67
|
+
off = self.first.index('?')
|
|
68
|
+
return nil if off.nil?
|
|
69
|
+
eop = self.first.index(' HTTP/')
|
|
70
|
+
return nil if eop.nil?
|
|
71
|
+
parms = self.first[off+1..eop-1]
|
|
72
|
+
return parms
|
|
73
|
+
rescue => bang
|
|
74
|
+
puts bang
|
|
75
|
+
puts bang.backtrace if $DEBUG
|
|
76
|
+
end
|
|
92
77
|
return nil
|
|
93
78
|
end
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
def method_get?
|
|
97
|
-
return false if method.nil?
|
|
98
|
-
return true if method =~ /^get$/i
|
|
99
|
-
return false
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
def method_post?
|
|
103
|
-
return false if method.nil?
|
|
104
|
-
return true if method =~ /^post$/i
|
|
105
|
-
return false
|
|
106
|
-
end
|
|
107
79
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
#
|
|
116
|
-
# http://www.mysite.com:80/my/path/show.php?p=aaa&debug=true
|
|
117
|
-
# path = "my/path/show.php"
|
|
118
|
-
def path
|
|
119
|
-
if self.first =~ /^[^[:space:]]{1,} [a-zA-Z]+:\/\/[\-0-9a-zA-Z.]*[:0-9]{0,6}\/([^\?]*).* HTTP/i then
|
|
120
|
-
return $1
|
|
121
|
-
else
|
|
122
|
-
return ""
|
|
80
|
+
def method
|
|
81
|
+
if self.first =~ /(^[^[:space:]]{1,}) /i then
|
|
82
|
+
return $1
|
|
83
|
+
else
|
|
84
|
+
return nil
|
|
85
|
+
end
|
|
123
86
|
end
|
|
124
|
-
end
|
|
125
87
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
return
|
|
130
|
-
else
|
|
131
|
-
return ""
|
|
88
|
+
def method_get?
|
|
89
|
+
return false if method.nil?
|
|
90
|
+
return true if method =~ /^get$/i
|
|
91
|
+
return false
|
|
132
92
|
end
|
|
133
|
-
end
|
|
134
93
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
return
|
|
138
|
-
|
|
139
|
-
return ""
|
|
94
|
+
def method_post?
|
|
95
|
+
return false if method.nil?
|
|
96
|
+
return true if method =~ /^post$/i
|
|
97
|
+
return false
|
|
140
98
|
end
|
|
141
|
-
end
|
|
142
99
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
100
|
+
#The path may consist of a sequence of path segments separated by a
|
|
101
|
+
#single slash "/" character. Within a path segment, the characters
|
|
102
|
+
#"/", ";", "=", and "?" are reserved. Each path segment may include a
|
|
103
|
+
#sequence of parameters, indicated by the semicolon ";" character.
|
|
104
|
+
#The parameters are not significant to the parsing of relative
|
|
105
|
+
#references.
|
|
106
|
+
|
|
107
|
+
#
|
|
108
|
+
# http://www.mysite.com:80/my/path/show.php?p=aaa&debug=true
|
|
109
|
+
# path = "my/path/show.php"
|
|
110
|
+
def path
|
|
111
|
+
if self.first =~ /^[^[:space:]]{1,} [a-zA-Z]+:\/\/[\-0-9a-zA-Z.]*[:0-9]{0,6}\/([^\?]*).* HTTP/i then
|
|
112
|
+
return $1
|
|
113
|
+
else
|
|
114
|
+
return ""
|
|
148
115
|
end
|
|
149
|
-
off = uri.index('?')
|
|
150
|
-
#parts.shift
|
|
151
|
-
# puts "HTTPParser.query: #{parts.join('?')}"
|
|
152
|
-
return "" if off.nil?
|
|
153
|
-
return uri[off+1..-1]
|
|
154
|
-
rescue => bang
|
|
155
|
-
puts "!!! Could not parse query !!!"
|
|
156
|
-
puts bang
|
|
157
|
-
puts bang.backtrace if $DEBUG
|
|
158
116
|
end
|
|
159
|
-
return ''
|
|
160
117
|
|
|
161
|
-
|
|
118
|
+
# path_ext = "my/path/show.php?p=aaa&debug=true"
|
|
119
|
+
def path_ext
|
|
120
|
+
if self.first =~ /^[^[:space:]]{1,} [a-zA-Z]+:\/\/[\-0-9a-zA-Z.]*[:0-9]{0,6}\/(.*) HTTP\//i then
|
|
121
|
+
return $1
|
|
122
|
+
else
|
|
123
|
+
return ""
|
|
124
|
+
end
|
|
125
|
+
end
|
|
162
126
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
else
|
|
170
|
-
return ""
|
|
127
|
+
def dir
|
|
128
|
+
if self.first =~ /^[^[:space:]]{1,} [a-zA-Z]+:\/\/[\-0-9a-zA-Z.]*[:0-9]{0,6}\/([^\?]*)\/.* HTTP/i then
|
|
129
|
+
return $1
|
|
130
|
+
else
|
|
131
|
+
return ""
|
|
132
|
+
end
|
|
171
133
|
end
|
|
172
|
-
end
|
|
173
134
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
135
|
+
def query
|
|
136
|
+
begin
|
|
137
|
+
q = nil
|
|
138
|
+
if self.first =~ /^[^[:space:]]{1,} (.*) HTTP.*/ then
|
|
139
|
+
uri = $1
|
|
140
|
+
end
|
|
141
|
+
off = uri.index('?')
|
|
142
|
+
#parts.shift
|
|
143
|
+
# puts "HTTPParser.query: #{parts.join('?')}"
|
|
144
|
+
return "" if off.nil?
|
|
145
|
+
return uri[off+1..-1]
|
|
146
|
+
rescue => bang
|
|
147
|
+
puts "!!! Could not parse query !!!"
|
|
148
|
+
puts bang
|
|
149
|
+
puts bang.backtrace if $DEBUG
|
|
150
|
+
end
|
|
151
|
+
return ''
|
|
188
152
|
|
|
189
|
-
def proto
|
|
190
|
-
proto = "unknown"
|
|
191
|
-
if self.first =~ /^[^[:space:]]{1,} ([a-zA-Z]+):\/\//i
|
|
192
|
-
proto = $1
|
|
193
153
|
end
|
|
194
|
-
proto
|
|
195
|
-
end
|
|
196
154
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
155
|
+
def element
|
|
156
|
+
cl = self.first.gsub(/\?+/, "?")
|
|
157
|
+
cl.gsub!(/ HTTP.*/, '')
|
|
158
|
+
dummy = cl.split('?').first
|
|
159
|
+
if dummy =~ /^[^[:space:]]{1,} ([a-zA-Z]+:\/\/[\-0-9a-zA-Z.]*[:0-9]{0,6}).*\/(.*)/i then
|
|
160
|
+
return $2
|
|
161
|
+
else
|
|
162
|
+
return ""
|
|
163
|
+
end
|
|
206
164
|
end
|
|
207
|
-
return false
|
|
208
|
-
end
|
|
209
165
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
166
|
+
def doctype
|
|
167
|
+
/.*\/.*?\.(\w{2,4})(\?| )/.match(self.first)
|
|
168
|
+
# puts $1
|
|
169
|
+
return $1 unless $1.nil?
|
|
170
|
+
return ''
|
|
171
|
+
#dummy = self.first.gsub(/\?+/,"?")
|
|
172
|
+
#parts = dummy.split('?')
|
|
173
|
+
#parts[0].gsub!(/ HTTP\/(.*)/i,"")
|
|
174
|
+
#if parts[0] =~ /(.*\.)(\w{2,3})$/i then
|
|
175
|
+
# return $2
|
|
176
|
+
#else
|
|
177
|
+
# return ''
|
|
178
|
+
#end
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
def proto
|
|
182
|
+
proto = "unknown"
|
|
183
|
+
if self.first =~ /^[^[:space:]]{1,} ([a-zA-Z]+):\/\//i
|
|
184
|
+
proto = $1
|
|
185
|
+
end
|
|
186
|
+
proto
|
|
215
187
|
end
|
|
216
|
-
url
|
|
217
|
-
end
|
|
218
|
-
# alias :url :url_string
|
|
219
|
-
|
|
220
|
-
def site
|
|
221
|
-
#@site ||= nil
|
|
222
|
-
#return @site unless @site.nil?
|
|
223
|
-
if self.first =~ /^[^[:space:]]{1,} ([a-zA-Z]+):\/\/([\-0-9a-zA-Z.]*)([:0-9]{0,6})/i then
|
|
224
|
-
host = $2
|
|
225
|
-
port_extension = $3
|
|
226
|
-
proto = $1
|
|
227
|
-
s = host + port_extension
|
|
228
|
-
if port_extension == ''
|
|
229
|
-
s = host + ":" + DEFAULT_PORT_HTTPS.to_s if proto =~ /^https$/i
|
|
230
|
-
s = host + ":" + DEFAULT_PORT_HTTP.to_s if proto =~ /^http$/i
|
|
231
|
-
end
|
|
232
|
-
@site = s
|
|
233
|
-
else
|
|
234
|
-
@site = nil
|
|
235
|
-
end
|
|
236
|
-
@site
|
|
237
|
-
end
|
|
238
188
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
#if self.first =~ /^[^[:space:]]{1,} https?:\/\/([\-0-9a-zA-Z.]*)[:0-9]{0,6}/i then
|
|
243
|
-
if self.first =~ /^[^[:space:]]{1,} [a-zA-Z]+:\/\/([\-0-9a-zA-Z.]*)[:0-9]{0,6}/i then
|
|
244
|
-
@host = $1
|
|
245
|
-
else
|
|
246
|
-
@host = ''
|
|
189
|
+
def is_ssl?
|
|
190
|
+
return true if self.first =~ /^[^[:space:]]{1,} https/i
|
|
191
|
+
return false
|
|
247
192
|
end
|
|
248
|
-
@host
|
|
249
|
-
end
|
|
250
193
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
sub_dirs.map! do |d| dir += "/" + d ; end
|
|
259
|
-
return sub_dirs
|
|
260
|
-
end
|
|
194
|
+
def is_chunked?
|
|
195
|
+
self.each do |h|
|
|
196
|
+
return true if h =~ /^Transfer-Encoding.*chunked/i
|
|
197
|
+
break if h.strip.empty?
|
|
198
|
+
end
|
|
199
|
+
return false
|
|
200
|
+
end
|
|
261
201
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
202
|
+
def url_string
|
|
203
|
+
url = ''
|
|
204
|
+
#return @url unless @url.nil?
|
|
205
|
+
if self.first =~ /^[^[:space:]]{1,} ([a-zA-Z]+:\/\/[\-0-9a-zA-Z.]*[:0-9]{0,6}.*) HTTP\//i then
|
|
206
|
+
url = $1
|
|
207
|
+
end
|
|
208
|
+
url
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
# alias :url :url_string
|
|
212
|
+
|
|
213
|
+
def site
|
|
214
|
+
#@site ||= nil
|
|
215
|
+
#return @site unless @site.nil?
|
|
216
|
+
if self.first =~ /^[^[:space:]]{1,} ([a-zA-Z]+):\/\/([\-0-9a-zA-Z.]*)([:0-9]{0,6})/i then
|
|
217
|
+
host = $2
|
|
218
|
+
port_extension = $3
|
|
219
|
+
proto = $1
|
|
220
|
+
s = host + port_extension
|
|
221
|
+
if port_extension == ''
|
|
222
|
+
s = host + ":" + DEFAULT_PORT_HTTPS.to_s if proto =~ /^https$/i
|
|
223
|
+
s = host + ":" + DEFAULT_PORT_HTTP.to_s if proto =~ /^http$/i
|
|
224
|
+
end
|
|
225
|
+
@site = s
|
|
226
|
+
else
|
|
227
|
+
@site = nil
|
|
228
|
+
end
|
|
229
|
+
@site
|
|
230
|
+
end
|
|
267
231
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
232
|
+
def host
|
|
233
|
+
#@host ||= nil
|
|
234
|
+
#return @host unless @host.nil?
|
|
235
|
+
#if self.first =~ /^[^[:space:]]{1,} https?:\/\/([\-0-9a-zA-Z.]*)[:0-9]{0,6}/i then
|
|
236
|
+
if self.first =~ /^[^[:space:]]{1,} [a-zA-Z]+:\/\/([\-0-9a-zA-Z.]*)[:0-9]{0,6}/i then
|
|
237
|
+
@host = $1
|
|
238
|
+
else
|
|
239
|
+
@host = ''
|
|
240
|
+
end
|
|
241
|
+
@host
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
# returns all subdir combinations
|
|
245
|
+
# www.company.com/this/is/my/path.php
|
|
246
|
+
# returns:
|
|
247
|
+
# [ "/this", "/this/is", "/this/is/my" ]
|
|
248
|
+
def subDirs
|
|
249
|
+
sub_dirs = self.dir.split(/\//)
|
|
250
|
+
dir = ""
|
|
251
|
+
sub_dirs.map! do |d|
|
|
252
|
+
dir += "/" + d;
|
|
253
|
+
end
|
|
254
|
+
return sub_dirs
|
|
272
255
|
end
|
|
273
|
-
|
|
274
|
-
|
|
256
|
+
|
|
257
|
+
def port
|
|
258
|
+
return nil if self.first.nil?
|
|
259
|
+
dummy = self.first
|
|
260
|
+
portnum = nil
|
|
261
|
+
parts = dummy.split('?')
|
|
262
|
+
|
|
263
|
+
if parts[0] =~ /^[^[:space:]]{1,} https:\/\//i then
|
|
264
|
+
portnum = 443
|
|
265
|
+
elsif parts[0] =~ /^[^[:space:]]{1,} http:\/\//i
|
|
266
|
+
portnum = 80
|
|
267
|
+
end
|
|
268
|
+
if parts[0] =~ /^[^[:space:]]{1,} https?:\/\/[\-0-9a-zA-Z.]*:([0-9]{0,6})/i then
|
|
269
|
+
portnum = $1
|
|
270
|
+
end
|
|
271
|
+
return portnum
|
|
275
272
|
end
|
|
276
|
-
return portnum
|
|
277
|
-
end
|
|
278
273
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
# parmlist=dummy.join.split(/\&/)
|
|
301
|
-
#end
|
|
302
|
-
#return parmlist
|
|
274
|
+
# get_parms returns an array of parm=value
|
|
275
|
+
def get_parms
|
|
276
|
+
begin
|
|
277
|
+
off = self.first.index('?')
|
|
278
|
+
return [] if off.nil?
|
|
279
|
+
eop = self.first.index(' HTTP/')
|
|
280
|
+
return [] if eop.nil?
|
|
281
|
+
parms = self.first[off+1..eop-1].split('&').select { |x| x =~ /=/ }
|
|
282
|
+
# puts parms
|
|
283
|
+
return parms
|
|
284
|
+
rescue => bang
|
|
285
|
+
puts bang
|
|
286
|
+
puts bang.backtrace if $DEBUG
|
|
287
|
+
end
|
|
288
|
+
return []
|
|
289
|
+
#parmlist=[]
|
|
290
|
+
#if self.first =~ /^[^[:space:]]{1,} (https?:\/\/[\-0-9a-zA-Z.]*[:0-9]{0,6}).*\/.*(\?.*=.*) HTTP/i then
|
|
291
|
+
# dummy = $2.gsub!(/\?+/,"?").split('?')
|
|
292
|
+
# remove left part of ? from url
|
|
293
|
+
# dummy.shift
|
|
303
294
|
|
|
304
|
-
|
|
295
|
+
# parmlist=dummy.join.split(/\&/)
|
|
296
|
+
#end
|
|
297
|
+
#return parmlist
|
|
305
298
|
|
|
306
|
-
|
|
299
|
+
end
|
|
300
|
+
|
|
301
|
+
#################### doubles
|
|
307
302
|
|
|
308
|
-
|
|
303
|
+
def get_parm_names(&block)
|
|
309
304
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
305
|
+
parm_names=[]
|
|
306
|
+
parmlist=[]
|
|
307
|
+
parmlist.concat(get_parms)
|
|
313
308
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
309
|
+
parmlist.each do |p|
|
|
310
|
+
if p then
|
|
311
|
+
p.gsub!(/=.*/, '')
|
|
312
|
+
yield p if block_given?
|
|
313
|
+
parm_names.push p
|
|
314
|
+
end
|
|
319
315
|
end
|
|
320
|
-
end
|
|
321
316
|
|
|
322
|
-
|
|
317
|
+
return parm_names
|
|
323
318
|
|
|
324
|
-
|
|
319
|
+
end
|
|
325
320
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
321
|
+
def get_parm_value(parm_name)
|
|
322
|
+
parm_value = ""
|
|
323
|
+
self.get_parms.each do |parm|
|
|
324
|
+
if parm =~ /^#{Regexp.quote(parm_name)}=/i then
|
|
325
|
+
dummy = parm.split(/=/)
|
|
326
|
+
if dummy.length > 1 then
|
|
327
|
+
# parm_value=dummy[1].gsub(/^[ ]*/,"")
|
|
328
|
+
parm_value=dummy[1].strip
|
|
329
|
+
end
|
|
334
330
|
end
|
|
335
331
|
end
|
|
332
|
+
return parm_value
|
|
333
|
+
end
|
|
334
|
+
|
|
335
|
+
def post_parm_value(parm_name)
|
|
336
|
+
parm_value=""
|
|
337
|
+
self.post_parms.each do |parm|
|
|
338
|
+
if parm =~ /#{Regexp.quote(parm_name)}/i then
|
|
339
|
+
dummy = parm.split(/=/)
|
|
340
|
+
if dummy.length > 1 then
|
|
341
|
+
parm_value = dummy[1].strip
|
|
342
|
+
else
|
|
343
|
+
# puts "Uhhhh ... need parameter value from '#{parm}''"
|
|
344
|
+
end
|
|
345
|
+
end
|
|
346
|
+
end
|
|
347
|
+
return parm_value
|
|
336
348
|
end
|
|
337
|
-
|
|
349
|
+
|
|
338
350
|
end
|
|
339
351
|
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
352
|
+
module Web10
|
|
353
|
+
include Watobo::Constants
|
|
354
|
+
|
|
355
|
+
def post_parms
|
|
356
|
+
parmlist=[]
|
|
357
|
+
return parmlist unless has_body?
|
|
358
|
+
begin
|
|
359
|
+
if self.last =~ /\=.*\&?/i
|
|
360
|
+
parmlist = self.last.split(/\&/)
|
|
361
|
+
parmlist.map! { |p| x = p.strip.empty? ? nil : p }
|
|
362
|
+
parmlist.compact!
|
|
363
|
+
end
|
|
364
|
+
rescue => bang
|
|
365
|
+
# puts self.last.unpack("C*").pack("C*").gsub(/[^[:print:]]/,".")
|
|
366
|
+
if $DEBUG
|
|
367
|
+
puts bang
|
|
368
|
+
puts bang.backtrace
|
|
369
|
+
|
|
349
370
|
end
|
|
350
371
|
end
|
|
372
|
+
return parmlist
|
|
351
373
|
end
|
|
352
|
-
return parm_value
|
|
353
|
-
end
|
|
354
374
|
|
|
355
|
-
|
|
375
|
+
def parms
|
|
376
|
+
parmlist=[]
|
|
377
|
+
parmlist.concat(get_parms)
|
|
378
|
+
parmlist.concat(post_parms)
|
|
356
379
|
|
|
357
|
-
|
|
358
|
-
include Watobo::Constants
|
|
359
|
-
def post_parms
|
|
360
|
-
parmlist=[]
|
|
361
|
-
return parmlist unless has_body?
|
|
362
|
-
begin
|
|
363
|
-
if self.last =~ /\=.*\&?/i
|
|
364
|
-
parmlist = self.last.split(/\&/)
|
|
365
|
-
parmlist.map!{|p| x = p.strip.empty? ? nil : p }
|
|
366
|
-
parmlist.compact!
|
|
367
|
-
end
|
|
368
|
-
rescue => bang
|
|
369
|
-
# puts self.last.unpack("C*").pack("C*").gsub(/[^[:print:]]/,".")
|
|
370
|
-
if $DEBUG
|
|
371
|
-
puts bang
|
|
372
|
-
puts bang.backtrace
|
|
373
|
-
|
|
374
|
-
end
|
|
380
|
+
return parmlist
|
|
375
381
|
end
|
|
376
|
-
return parmlist
|
|
377
|
-
end
|
|
378
382
|
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
+
def parm_names
|
|
384
|
+
parm_names=[]
|
|
385
|
+
parmlist=[]
|
|
386
|
+
parmlist.concat(get_parms)
|
|
387
|
+
parmlist.concat(post_parms)
|
|
388
|
+
parmlist.each do |p|
|
|
389
|
+
p.gsub!(/=.*/, '')
|
|
390
|
+
parm_names.push p
|
|
391
|
+
end
|
|
383
392
|
|
|
384
|
-
|
|
385
|
-
end
|
|
393
|
+
return parm_names
|
|
386
394
|
|
|
387
|
-
def parm_names
|
|
388
|
-
parm_names=[]
|
|
389
|
-
parmlist=[]
|
|
390
|
-
parmlist.concat(get_parms)
|
|
391
|
-
parmlist.concat(post_parms)
|
|
392
|
-
parmlist.each do |p|
|
|
393
|
-
p.gsub!(/=.*/,'')
|
|
394
|
-
parm_names.push p
|
|
395
395
|
end
|
|
396
396
|
|
|
397
|
-
|
|
397
|
+
def post_parm_names(&block)
|
|
398
398
|
|
|
399
|
-
|
|
399
|
+
parm_names=[]
|
|
400
|
+
parmlist=[]
|
|
400
401
|
|
|
401
|
-
|
|
402
|
+
parmlist.concat(post_parms)
|
|
403
|
+
parmlist.each do |p|
|
|
404
|
+
if p then
|
|
405
|
+
p.gsub!(/=.*/, '')
|
|
406
|
+
p.strip!
|
|
407
|
+
yield p if block_given?
|
|
408
|
+
parm_names << p
|
|
409
|
+
end
|
|
410
|
+
end
|
|
402
411
|
|
|
403
|
-
|
|
404
|
-
parmlist=[]
|
|
412
|
+
return parm_names
|
|
405
413
|
|
|
406
|
-
parmlist.concat(post_parms)
|
|
407
|
-
parmlist.each do |p|
|
|
408
|
-
if p then
|
|
409
|
-
p.gsub!(/=.*/,'')
|
|
410
|
-
p.strip!
|
|
411
|
-
yield p if block_given?
|
|
412
|
-
parm_names << p
|
|
413
|
-
end
|
|
414
414
|
end
|
|
415
415
|
|
|
416
|
-
return parm_names
|
|
417
416
|
|
|
418
|
-
|
|
417
|
+
def header_value(header_name)
|
|
418
|
+
header_values =[]
|
|
419
|
+
self.headers.each do |header|
|
|
420
|
+
begin
|
|
421
|
+
if header =~ /^#{header_name}/i then
|
|
422
|
+
vstart = header.index ':'
|
|
423
|
+
unless vstart.nil?
|
|
424
|
+
header_values.push header[vstart+1..-1].strip
|
|
425
|
+
end
|
|
426
|
+
end
|
|
427
|
+
rescue => bang
|
|
428
|
+
puts bang
|
|
429
|
+
puts bang.backtrace if $DEBUG
|
|
430
|
+
end
|
|
431
|
+
end
|
|
432
|
+
return header_values
|
|
433
|
+
end
|
|
434
|
+
|
|
435
|
+
def content_type(default_ct='undefined')
|
|
436
|
+
ct = default_ct
|
|
437
|
+
self.each do |line|
|
|
438
|
+
begin
|
|
439
|
+
break if line.strip.empty?
|
|
440
|
+
#cl = line.encode('ASCII', :invalid => :replace, :undef => :replace)
|
|
441
|
+
cl = line.force_encoding('ASCII-8BIT')
|
|
442
|
+
if cl =~ /^Content-Type:([^;]*);?/i then
|
|
443
|
+
ct = $1
|
|
444
|
+
break
|
|
445
|
+
end
|
|
446
|
+
rescue => bang
|
|
447
|
+
puts "! could not parse content_type !"
|
|
448
|
+
puts bang
|
|
449
|
+
puts cl
|
|
450
|
+
# puts cl.gsub(/[^[:print:]]/, '.')
|
|
419
451
|
|
|
420
|
-
|
|
421
|
-
def header_value(header_name)
|
|
422
|
-
header_values =[]
|
|
423
|
-
self.headers.each do |header|
|
|
424
|
-
begin
|
|
425
|
-
if header =~ /^#{header_name}/i then
|
|
426
|
-
vstart = header.index ':'
|
|
427
|
-
unless vstart.nil?
|
|
428
|
-
header_values.push header[vstart+1..-1].strip
|
|
429
452
|
end
|
|
430
453
|
end
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
454
|
+
return ct.strip
|
|
455
|
+
end
|
|
456
|
+
|
|
457
|
+
def content_type_ex(default_ct='undefined')
|
|
458
|
+
ct = default_ct
|
|
459
|
+
self.each do |line|
|
|
460
|
+
break if line.strip.empty?
|
|
461
|
+
# cl = line.encode('ASCII', :invalid => :replace, :undef => :replace)
|
|
462
|
+
cl = line.force_encoding('ASCII-8BIT')
|
|
463
|
+
if cl =~ /^Content-Type:(.*)/i then
|
|
464
|
+
ct = $1.strip
|
|
465
|
+
break
|
|
466
|
+
end
|
|
467
|
+
end
|
|
468
|
+
return ct.strip
|
|
469
|
+
end
|
|
470
|
+
|
|
471
|
+
def content_length
|
|
472
|
+
# Note: Calculate Chunk-Encoded Content-Length
|
|
473
|
+
# this is only possible if the whole body is loaded???
|
|
474
|
+
ct = -1
|
|
475
|
+
self.each do |line|
|
|
476
|
+
break if line.strip.empty?
|
|
477
|
+
if line =~ /^Content-Length:(.*)/i then
|
|
478
|
+
ct = $1.strip.to_i
|
|
479
|
+
break
|
|
480
|
+
end
|
|
434
481
|
end
|
|
482
|
+
return ct
|
|
483
|
+
end
|
|
484
|
+
|
|
485
|
+
def content_encoding
|
|
486
|
+
te = TE_NONE
|
|
487
|
+
self.each do |line|
|
|
488
|
+
break if line.strip.empty?
|
|
489
|
+
if line =~ /^Content-Encoding:(.*)/i then
|
|
490
|
+
dummy = $1.strip
|
|
491
|
+
# puts "Content-Encoding => #{dummy}"
|
|
492
|
+
te = case dummy
|
|
493
|
+
when /chunked/i
|
|
494
|
+
TE_CHUNKED
|
|
495
|
+
when /compress/i
|
|
496
|
+
TE_COMPRESS
|
|
497
|
+
when /zip/i
|
|
498
|
+
TE_GZIP
|
|
499
|
+
when /deflate/i
|
|
500
|
+
TE_DEFLATE
|
|
501
|
+
when /identity/i
|
|
502
|
+
TE_IDENTITY
|
|
503
|
+
else
|
|
504
|
+
TE_NONE
|
|
505
|
+
end
|
|
506
|
+
break
|
|
507
|
+
end
|
|
508
|
+
end
|
|
509
|
+
return te
|
|
510
|
+
end
|
|
511
|
+
|
|
512
|
+
def transferEncoding
|
|
513
|
+
te = TE_NONE
|
|
514
|
+
self.each do |line|
|
|
515
|
+
break if line.strip.empty?
|
|
516
|
+
if line =~ /^Transfer-Encoding:(.*)/i then
|
|
517
|
+
dummy = $1.strip
|
|
518
|
+
# puts dummy
|
|
519
|
+
te = case dummy
|
|
520
|
+
when 'chunked'
|
|
521
|
+
TE_CHUNKED
|
|
522
|
+
when 'compress'
|
|
523
|
+
TE_COMPRESS
|
|
524
|
+
when 'zip'
|
|
525
|
+
TE_GZIP
|
|
526
|
+
when 'deflate'
|
|
527
|
+
TE_DEFLATE
|
|
528
|
+
when 'identity'
|
|
529
|
+
TE_IDENTITY
|
|
530
|
+
else
|
|
531
|
+
TE_NONE
|
|
532
|
+
end
|
|
533
|
+
break
|
|
534
|
+
end
|
|
535
|
+
end
|
|
536
|
+
return te
|
|
537
|
+
end
|
|
538
|
+
|
|
539
|
+
alias :transfer_encoding :transferEncoding
|
|
540
|
+
|
|
541
|
+
def contentMD5
|
|
542
|
+
b = self.body.nil? ? "" : self.body
|
|
543
|
+
hash = Digest::MD5.hexdigest(b)
|
|
544
|
+
return hash
|
|
545
|
+
end
|
|
546
|
+
|
|
547
|
+
# def get_parm_value(parm_name)
|
|
548
|
+
# parm_value = ""
|
|
549
|
+
# self.get_parms.each do |parm|
|
|
550
|
+
# if parm =~ /^#{Regexp.quote(parm_name)}=/i then
|
|
551
|
+
# dummy = parm.split(/=/)
|
|
552
|
+
# if dummy.length > 1 then
|
|
553
|
+
# # parm_value=dummy[1].gsub(/^[ ]*/,"")
|
|
554
|
+
# parm_value=dummy[1].strip
|
|
555
|
+
# end
|
|
556
|
+
# end
|
|
557
|
+
# end
|
|
558
|
+
# return parm_value
|
|
559
|
+
# end
|
|
560
|
+
|
|
561
|
+
def post_parm_value(parm_name)
|
|
562
|
+
parm_value=""
|
|
563
|
+
self.post_parms.each do |parm|
|
|
564
|
+
if parm =~ /#{Regexp.quote(parm_name)}/i then
|
|
565
|
+
dummy = parm.split(/=/)
|
|
566
|
+
if dummy.length > 1 then
|
|
567
|
+
parm_value = dummy[1].strip
|
|
568
|
+
else
|
|
569
|
+
# puts "Uhhhh ... need parameter value from '#{parm}''"
|
|
570
|
+
end
|
|
571
|
+
end
|
|
572
|
+
end
|
|
573
|
+
return parm_value
|
|
435
574
|
end
|
|
436
|
-
return header_values
|
|
437
|
-
end
|
|
438
575
|
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
begin
|
|
443
|
-
break if line.strip.empty?
|
|
444
|
-
#cl = line.encode('ASCII', :invalid => :replace, :undef => :replace)
|
|
445
|
-
cl = line.force_encoding('ASCII-8BIT')
|
|
446
|
-
if cl =~ /^Content-Type:([^;]*);?/i then
|
|
447
|
-
ct = $1
|
|
448
|
-
break
|
|
449
|
-
end
|
|
450
|
-
rescue => bang
|
|
451
|
-
puts "! could not parse content_type !"
|
|
452
|
-
puts bang
|
|
453
|
-
puts cl
|
|
454
|
-
# puts cl.gsub(/[^[:print:]]/, '.')
|
|
576
|
+
def has_body?
|
|
577
|
+
self.body.nil? ? false : true
|
|
578
|
+
end
|
|
455
579
|
|
|
580
|
+
def __connection_close?
|
|
581
|
+
headers("Connection") do |h|
|
|
582
|
+
return true if h =~ /close/i
|
|
456
583
|
end
|
|
584
|
+
return false
|
|
457
585
|
end
|
|
458
|
-
return ct.strip
|
|
459
|
-
end
|
|
460
|
-
|
|
461
|
-
def content_type_ex(default_ct='undefined')
|
|
462
|
-
ct = default_ct
|
|
463
|
-
self.each do |line|
|
|
464
|
-
break if line.strip.empty?
|
|
465
|
-
# cl = line.encode('ASCII', :invalid => :replace, :undef => :replace)
|
|
466
|
-
cl = line.force_encoding('ASCII-8BIT')
|
|
467
|
-
if cl =~ /^Content-Type:(.*)/i then
|
|
468
|
-
ct = $1.strip
|
|
469
|
-
break
|
|
470
|
-
end
|
|
471
|
-
end
|
|
472
|
-
return ct.strip
|
|
473
|
-
end
|
|
474
586
|
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
ct = -1
|
|
479
|
-
self.each do |line|
|
|
480
|
-
break if line.strip.empty?
|
|
481
|
-
if line =~ /^Content-Length:(.*)/i then
|
|
482
|
-
ct = $1.strip.to_i
|
|
483
|
-
break
|
|
587
|
+
def connection_close?
|
|
588
|
+
headers("Connection") do |h|
|
|
589
|
+
return false if h =~ /keep\-alive/i
|
|
484
590
|
end
|
|
591
|
+
return true
|
|
485
592
|
end
|
|
486
|
-
return ct
|
|
487
|
-
end
|
|
488
593
|
|
|
489
|
-
def
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
if line =~ /^Content-Encoding:(.*)/i then
|
|
494
|
-
dummy = $1.strip
|
|
495
|
-
# puts "Content-Encoding => #{dummy}"
|
|
496
|
-
te = case dummy
|
|
497
|
-
when /chunked/i
|
|
498
|
-
TE_CHUNKED
|
|
499
|
-
when /compress/i
|
|
500
|
-
TE_COMPRESS
|
|
501
|
-
when /zip/i
|
|
502
|
-
TE_GZIP
|
|
503
|
-
when /deflate/i
|
|
504
|
-
TE_DEFLATE
|
|
505
|
-
when /identity/i
|
|
506
|
-
TE_IDENTITY
|
|
507
|
-
else
|
|
508
|
-
TE_NONE
|
|
509
|
-
end
|
|
510
|
-
break
|
|
594
|
+
def has_header?(name)
|
|
595
|
+
self.each do |l|
|
|
596
|
+
return false if l.strip.empty?
|
|
597
|
+
return true if l =~ /^#{name}:/i
|
|
511
598
|
end
|
|
599
|
+
return false
|
|
512
600
|
end
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
if line =~ /^Transfer-Encoding:(.*)/i then
|
|
521
|
-
dummy = $1.strip
|
|
522
|
-
# puts dummy
|
|
523
|
-
te = case dummy
|
|
524
|
-
when 'chunked'
|
|
525
|
-
TE_CHUNKED
|
|
526
|
-
when 'compress'
|
|
527
|
-
TE_COMPRESS
|
|
528
|
-
when 'zip'
|
|
529
|
-
TE_GZIP
|
|
530
|
-
when 'deflate'
|
|
531
|
-
TE_DEFLATE
|
|
532
|
-
when 'identity'
|
|
533
|
-
TE_IDENTITY
|
|
534
|
-
else
|
|
535
|
-
TE_NONE
|
|
536
|
-
end
|
|
537
|
-
break
|
|
601
|
+
|
|
602
|
+
def body
|
|
603
|
+
begin
|
|
604
|
+
return nil if self.nil? or self.length < 3
|
|
605
|
+
return "#{self.last}" if self[-2].strip.empty?
|
|
606
|
+
rescue
|
|
607
|
+
return nil
|
|
538
608
|
end
|
|
609
|
+
nil
|
|
539
610
|
end
|
|
540
|
-
return te
|
|
541
|
-
end
|
|
542
|
-
|
|
543
|
-
alias :transfer_encoding :transferEncoding
|
|
544
611
|
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
# self.get_parms.each do |parm|
|
|
554
|
-
# if parm =~ /^#{Regexp.quote(parm_name)}=/i then
|
|
555
|
-
# dummy = parm.split(/=/)
|
|
556
|
-
# if dummy.length > 1 then
|
|
557
|
-
# # parm_value=dummy[1].gsub(/^[ ]*/,"")
|
|
558
|
-
# parm_value=dummy[1].strip
|
|
559
|
-
# end
|
|
560
|
-
# end
|
|
561
|
-
# end
|
|
562
|
-
# return parm_value
|
|
563
|
-
# end
|
|
564
|
-
|
|
565
|
-
def post_parm_value(parm_name)
|
|
566
|
-
parm_value=""
|
|
567
|
-
self.post_parms.each do |parm|
|
|
568
|
-
if parm =~ /#{Regexp.quote(parm_name)}/i then
|
|
569
|
-
dummy = parm.split(/=/)
|
|
570
|
-
if dummy.length > 1 then
|
|
571
|
-
parm_value = dummy[1].strip
|
|
572
|
-
else
|
|
573
|
-
# puts "Uhhhh ... need parameter value from '#{parm}''"
|
|
574
|
-
end
|
|
612
|
+
def is_text?
|
|
613
|
+
ct = self.content_type(nil)
|
|
614
|
+
if ct.nil?
|
|
615
|
+
return true if self.body_encoded.ascii_only?
|
|
616
|
+
return false
|
|
617
|
+
else
|
|
618
|
+
return true if ct =~ /text/i
|
|
619
|
+
return false
|
|
575
620
|
end
|
|
576
621
|
end
|
|
577
|
-
return parm_value
|
|
578
|
-
end
|
|
579
622
|
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
def __connection_close?
|
|
585
|
-
headers("Connection") do |h|
|
|
586
|
-
return true if h =~ /close/i
|
|
587
|
-
end
|
|
588
|
-
return false
|
|
589
|
-
end
|
|
590
|
-
|
|
591
|
-
def connection_close?
|
|
592
|
-
headers("Connection") do |h|
|
|
593
|
-
return false if h =~ /keep\-alive/i
|
|
623
|
+
def is_wwwform?
|
|
624
|
+
ct = self.content_type
|
|
625
|
+
return true if ct =~ /form/i
|
|
626
|
+
return false
|
|
594
627
|
end
|
|
595
|
-
return true
|
|
596
|
-
end
|
|
597
628
|
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
return
|
|
601
|
-
return
|
|
629
|
+
def is_json?
|
|
630
|
+
ct = self.content_type
|
|
631
|
+
return true if ct =~ /\/json/i
|
|
632
|
+
return false
|
|
602
633
|
end
|
|
603
|
-
return false
|
|
604
|
-
end
|
|
605
634
|
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
return
|
|
609
|
-
return "#{self.last}" if self[-2].strip.empty?
|
|
610
|
-
rescue
|
|
611
|
-
return nil
|
|
612
|
-
end
|
|
613
|
-
nil
|
|
614
|
-
end
|
|
615
|
-
|
|
616
|
-
def is_text?
|
|
617
|
-
ct = self.content_type(nil)
|
|
618
|
-
if ct.nil?
|
|
619
|
-
return true if self.body_encoded.ascii_only?
|
|
620
|
-
return false
|
|
621
|
-
else
|
|
622
|
-
return true if ct =~ /text/i
|
|
635
|
+
def is_xml?
|
|
636
|
+
ct = self.content_type
|
|
637
|
+
return true if ct =~ /xml/i
|
|
623
638
|
return false
|
|
624
639
|
end
|
|
625
|
-
end
|
|
626
|
-
|
|
627
|
-
def is_wwwform?
|
|
628
|
-
ct = self.content_type
|
|
629
|
-
return true if ct =~ /form/i
|
|
630
|
-
return false
|
|
631
|
-
end
|
|
632
|
-
|
|
633
|
-
def is_json?
|
|
634
|
-
ct = self.content_type
|
|
635
|
-
return true if ct =~ /\/json/i
|
|
636
|
-
return false
|
|
637
|
-
end
|
|
638
|
-
|
|
639
|
-
def is_xml?
|
|
640
|
-
ct = self.content_type
|
|
641
|
-
return true if ct =~ /xml/i
|
|
642
|
-
return false
|
|
643
|
-
end
|
|
644
|
-
|
|
645
|
-
def is_multipart?
|
|
646
|
-
ct = self.content_type
|
|
647
|
-
return true if ct =~ /^multipart/i
|
|
648
|
-
return false
|
|
649
|
-
end
|
|
650
|
-
|
|
651
|
-
def body_encoded
|
|
652
|
-
b = self.body
|
|
653
|
-
return nil if b.nil?
|
|
654
|
-
|
|
655
|
-
cs = self.charset
|
|
656
|
-
return b.unpack("C*").pack("C*") if cs.nil?
|
|
657
|
-
|
|
658
|
-
begin
|
|
659
|
-
# not sure if this is a good idea???
|
|
660
|
-
#return b.encode(cs, :invalid => :replace, :undef => :replace, :replace => '').unpack("C*").pack("C*")
|
|
661
|
-
rescue => bang
|
|
662
|
-
if $DEBUG
|
|
663
|
-
puts bang
|
|
664
|
-
puts bang.backtrace
|
|
665
|
-
end
|
|
666
|
-
end
|
|
667
|
-
return b.unpack("C*").pack("C*")
|
|
668
|
-
end
|
|
669
640
|
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
return
|
|
673
|
-
|
|
674
|
-
return nil
|
|
641
|
+
def is_multipart?
|
|
642
|
+
ct = self.content_type
|
|
643
|
+
return true if ct =~ /^multipart/i
|
|
644
|
+
return false
|
|
675
645
|
end
|
|
676
|
-
end
|
|
677
|
-
|
|
678
|
-
alias :responseCode :status_code
|
|
679
|
-
|
|
680
|
-
# returns array of new cookies
|
|
681
|
-
# Set-Cookie: mycookie=b41dc9e55d6163f78321996b10c940edcec1b4e55a76464c4e9d25e160ac0ec5b769806b; Path=/
|
|
682
|
-
def new_cookies(&b)
|
|
683
|
-
nc = []
|
|
684
|
-
headers("Set-Cookie") do |h|
|
|
685
|
-
cookie = Watobo::Cookie.new(h)
|
|
686
|
-
yield cookie if block_given?
|
|
687
|
-
nc << cookie
|
|
688
|
-
end
|
|
689
|
-
nc
|
|
690
|
-
end
|
|
691
646
|
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
dummy = self.first.unpack("C*").pack("C*")
|
|
647
|
+
def body_encoded
|
|
648
|
+
b = self.body
|
|
649
|
+
return nil if b.nil?
|
|
696
650
|
|
|
697
|
-
|
|
698
|
-
return
|
|
699
|
-
|
|
700
|
-
|
|
651
|
+
cs = self.charset
|
|
652
|
+
return b.unpack("C*").pack("C*") if cs.nil?
|
|
653
|
+
|
|
654
|
+
begin
|
|
655
|
+
# not sure if this is a good idea???
|
|
656
|
+
#return b.encode(cs, :invalid => :replace, :undef => :replace, :replace => '').unpack("C*").pack("C*")
|
|
657
|
+
rescue => bang
|
|
658
|
+
if $DEBUG
|
|
659
|
+
puts bang
|
|
660
|
+
puts bang.backtrace
|
|
661
|
+
end
|
|
662
|
+
end
|
|
663
|
+
return b.unpack("C*").pack("C*")
|
|
701
664
|
end
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
665
|
+
|
|
666
|
+
def status_code
|
|
667
|
+
if self.first =~ /^HTTP\/... (\d+) /
|
|
668
|
+
return $1
|
|
669
|
+
else
|
|
670
|
+
return nil
|
|
671
|
+
end
|
|
709
672
|
end
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
673
|
+
|
|
674
|
+
alias :responseCode :status_code
|
|
675
|
+
|
|
676
|
+
# returns array of new cookies
|
|
677
|
+
# Set-Cookie: mycookie=b41dc9e55d6163f78321996b10c940edcec1b4e55a76464c4e9d25e160ac0ec5b769806b; Path=/
|
|
678
|
+
def new_cookies(&b)
|
|
679
|
+
nc = []
|
|
680
|
+
headers("Set-Cookie") do |h|
|
|
681
|
+
cookie = Watobo::Cookie.new(h)
|
|
682
|
+
yield cookie if block_given?
|
|
683
|
+
nc << cookie
|
|
719
684
|
end
|
|
685
|
+
nc
|
|
720
686
|
end
|
|
721
|
-
return cs
|
|
722
|
-
end
|
|
723
687
|
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
puts bang.backtrace
|
|
742
|
-
puts self.to_yaml
|
|
688
|
+
def status
|
|
689
|
+
begin
|
|
690
|
+
# Filter bad utf-8 chars
|
|
691
|
+
dummy = self.first.nil? ? '' : self.first.unpack("C*").pack("C*")
|
|
692
|
+
|
|
693
|
+
if dummy =~ /^HTTP\/1\.\d{1,2} (.*)/i then
|
|
694
|
+
return $1.chomp
|
|
695
|
+
else
|
|
696
|
+
return ''
|
|
697
|
+
end
|
|
698
|
+
rescue => bang
|
|
699
|
+
if $DEBUG
|
|
700
|
+
puts "! No Status Available !".upcase
|
|
701
|
+
puts bang
|
|
702
|
+
puts bang.backtrace
|
|
703
|
+
end
|
|
704
|
+
return nil
|
|
743
705
|
end
|
|
744
|
-
return nil
|
|
745
706
|
end
|
|
746
|
-
end
|
|
747
707
|
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
# c.chomp!
|
|
756
|
-
cookie_list.push c.strip
|
|
708
|
+
def charset
|
|
709
|
+
cs = nil
|
|
710
|
+
self.each do |line|
|
|
711
|
+
break if line.strip.empty?
|
|
712
|
+
if line =~ /^Content-Type: .*charset=([^;]*)/i then
|
|
713
|
+
cs = $1.strip
|
|
714
|
+
break
|
|
757
715
|
end
|
|
758
716
|
end
|
|
717
|
+
return cs
|
|
718
|
+
end
|
|
719
|
+
|
|
720
|
+
def headers(filter=nil, &b)
|
|
721
|
+
begin
|
|
722
|
+
filter = '.*' if filter.nil?
|
|
723
|
+
header_list=[]
|
|
724
|
+
self.each do |line|
|
|
725
|
+
cl = line.force_encoding('ASCII-8BIT')
|
|
726
|
+
return header_list if cl.strip.empty?
|
|
727
|
+
if cl =~ /#{filter}/
|
|
728
|
+
yield line if block_given?
|
|
729
|
+
header_list.push line
|
|
730
|
+
end
|
|
731
|
+
end
|
|
732
|
+
return header_list
|
|
733
|
+
rescue => bang
|
|
734
|
+
puts bang
|
|
735
|
+
puts bang.backtrace
|
|
736
|
+
if $DEBUG
|
|
737
|
+
puts bang.backtrace
|
|
738
|
+
puts self.to_yaml
|
|
739
|
+
end
|
|
740
|
+
return nil
|
|
741
|
+
end
|
|
759
742
|
end
|
|
760
|
-
return cookie_list
|
|
761
|
-
end
|
|
762
743
|
|
|
763
|
-
def data_UNUSED
|
|
764
|
-
return self.last.strip if self.last =~ /\=.*\&?/i
|
|
765
|
-
return ""
|
|
766
744
|
end
|
|
767
745
|
|
|
768
|
-
end
|
|
769
746
|
|
|
770
|
-
|
|
771
747
|
end
|
|
772
748
|
end
|
|
773
749
|
end
|