watobo 0.9.19 → 0.9.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (266) hide show
  1. data/CHANGELOG.md +104 -0
  2. data/bin/nfq_server.rb +8 -20
  3. data/bin/watobo_gui.rb +8 -20
  4. data/config/forwarding_proxy.yml +2 -2
  5. data/lib/watobo.rb +12 -22
  6. data/lib/watobo/adapters.rb +12 -24
  7. data/lib/watobo/adapters/data_store.rb +76 -66
  8. data/lib/watobo/adapters/file/file_store.rb +295 -307
  9. data/lib/watobo/adapters/session_store.rb +13 -25
  10. data/lib/watobo/ca.rb +9 -21
  11. data/lib/watobo/config.rb +205 -217
  12. data/lib/watobo/constants.rb +8 -20
  13. data/lib/watobo/core.rb +11 -23
  14. data/lib/watobo/core/active_check.rb +11 -21
  15. data/lib/watobo/core/active_checks.rb +57 -69
  16. data/lib/watobo/core/ca.rb +388 -398
  17. data/lib/watobo/core/cert_store.rb +42 -54
  18. data/lib/watobo/core/chat.rb +100 -112
  19. data/lib/watobo/core/chats.rb +271 -275
  20. data/lib/watobo/core/client_cert_store.rb +33 -45
  21. data/lib/watobo/core/conversation.rb +56 -68
  22. data/lib/watobo/core/cookie.rb +31 -43
  23. data/lib/watobo/core/finding.rb +74 -86
  24. data/lib/watobo/core/findings.rb +113 -125
  25. data/lib/watobo/core/forwarding_proxy.rb +44 -35
  26. data/lib/watobo/core/fuzz_gen.rb +8 -20
  27. data/lib/watobo/core/intercept_carver.rb +176 -188
  28. data/lib/watobo/core/intercept_filter.rb +243 -255
  29. data/lib/watobo/core/interceptor.rb +106 -118
  30. data/lib/watobo/core/min_class.rb +12 -24
  31. data/lib/watobo/core/netfilter_queue.rb +178 -190
  32. data/lib/watobo/core/ott_cache.rb +152 -148
  33. data/lib/watobo/core/parameter.rb +53 -58
  34. data/lib/watobo/core/passive_check.rb +8 -20
  35. data/lib/watobo/core/passive_checks.rb +56 -68
  36. data/lib/watobo/core/passive_scanner.rb +54 -66
  37. data/lib/watobo/core/plugin.rb +19 -31
  38. data/lib/watobo/core/project.rb +8 -20
  39. data/lib/watobo/core/proxy.rb +51 -63
  40. data/lib/watobo/core/request.rb +128 -120
  41. data/lib/watobo/core/response.rb +59 -61
  42. data/lib/watobo/core/scanner.rb +8 -20
  43. data/lib/watobo/core/scanner3.rb +413 -425
  44. data/lib/watobo/core/scope.rb +91 -103
  45. data/lib/watobo/core/session.rb +109 -87
  46. data/lib/watobo/core/sid_cache.rb +106 -118
  47. data/lib/watobo/core/subscriber.rb +33 -45
  48. data/lib/watobo/defaults.rb +29 -41
  49. data/lib/watobo/external/diff/lcs.rb +8 -20
  50. data/lib/watobo/external/diff/lcs/array.rb +8 -20
  51. data/lib/watobo/external/diff/lcs/block.rb +8 -20
  52. data/lib/watobo/external/diff/lcs/callbacks.rb +8 -20
  53. data/lib/watobo/external/diff/lcs/change.rb +8 -20
  54. data/lib/watobo/external/diff/lcs/hunk.rb +8 -20
  55. data/lib/watobo/external/diff/lcs/ldiff.rb +8 -20
  56. data/lib/watobo/external/diff/lcs/string.rb +8 -20
  57. data/lib/watobo/externals.rb +14 -26
  58. data/lib/watobo/framework.rb +12 -24
  59. data/lib/watobo/framework/create_project.rb +68 -80
  60. data/lib/watobo/framework/init.rb +8 -20
  61. data/lib/watobo/framework/init_modules.rb +8 -20
  62. data/lib/watobo/framework/license_text.rb +36 -48
  63. data/lib/watobo/framework/load_chat.rb +21 -33
  64. data/lib/watobo/gui.rb +121 -133
  65. data/lib/watobo/gui/about_watobo.rb +8 -20
  66. data/lib/watobo/gui/browser_preview.rb +8 -20
  67. data/lib/watobo/gui/certificate_dialog.rb +8 -20
  68. data/lib/watobo/gui/chat_diff.rb +11 -21
  69. data/lib/watobo/gui/chatviewer_frame.rb +10 -22
  70. data/lib/watobo/gui/checkboxtree.rb +8 -20
  71. data/lib/watobo/gui/checks_policy_frame.rb +8 -20
  72. data/lib/watobo/gui/client_cert_dialog.rb +10 -21
  73. data/lib/watobo/gui/confirm_scan_dialog.rb +8 -20
  74. data/lib/watobo/gui/conversation_table.rb +54 -44
  75. data/lib/watobo/gui/conversation_table_ctrl.rb +215 -227
  76. data/lib/watobo/gui/conversation_table_ctrl2.rb +385 -393
  77. data/lib/watobo/gui/csrf_token_dialog.rb +11 -25
  78. data/lib/watobo/gui/custom_viewer.rb +357 -369
  79. data/lib/watobo/gui/dashboard.rb +8 -20
  80. data/lib/watobo/gui/define_scope_frame.rb +8 -20
  81. data/lib/watobo/gui/differ_frame.rb +223 -235
  82. data/lib/watobo/gui/edit_comment.rb +8 -20
  83. data/lib/watobo/gui/edit_scope_dialog.rb +8 -20
  84. data/lib/watobo/gui/export_dialog.rb +114 -0
  85. data/lib/watobo/gui/finding_info.rb +9 -21
  86. data/lib/watobo/gui/findings_tree.rb +8 -20
  87. data/lib/watobo/gui/full_scan_dialog.rb +8 -20
  88. data/lib/watobo/gui/fuzzer_gui.rb +8 -20
  89. data/lib/watobo/gui/goto_url_dialog.rb +78 -90
  90. data/lib/watobo/gui/hex_viewer.rb +25 -27
  91. data/lib/watobo/gui/html_viewer.rb +295 -307
  92. data/lib/watobo/gui/intercept_filter_dialog.rb +196 -208
  93. data/lib/watobo/gui/interceptor_gui.rb +1046 -1041
  94. data/lib/watobo/gui/interceptor_settings_dialog.rb +8 -20
  95. data/lib/watobo/gui/list_box.rb +109 -121
  96. data/lib/watobo/gui/log_file_viewer.rb +40 -52
  97. data/lib/watobo/gui/log_viewer.rb +87 -99
  98. data/lib/watobo/gui/login_wizzard.rb +8 -20
  99. data/lib/watobo/gui/main_window.rb +34 -33
  100. data/lib/watobo/gui/manual_request_editor.rb +25 -35
  101. data/lib/watobo/gui/master_pw_dialog.rb +8 -20
  102. data/lib/watobo/gui/mixins/gui_settings.rb +37 -49
  103. data/lib/watobo/gui/page_tree.rb +225 -237
  104. data/lib/watobo/gui/password_policy_dialog.rb +8 -20
  105. data/lib/watobo/gui/plugin_board.rb +8 -20
  106. data/lib/watobo/gui/preferences_dialog.rb +8 -20
  107. data/lib/watobo/gui/progress_window.rb +8 -20
  108. data/lib/watobo/gui/project_wizzard.rb +8 -20
  109. data/lib/watobo/gui/proxy_dialog.rb +117 -85
  110. data/lib/watobo/gui/quick_scan_dialog.rb +8 -20
  111. data/lib/watobo/gui/request_builder_frame.rb +125 -122
  112. data/lib/watobo/gui/request_editor.rb +53 -28
  113. data/lib/watobo/gui/rewrite_filters_dialog.rb +402 -414
  114. data/lib/watobo/gui/rewrite_rules_dialog.rb +380 -392
  115. data/lib/watobo/gui/save_chat_dialog.rb +148 -160
  116. data/lib/watobo/gui/scanner_settings_dialog.rb +8 -20
  117. data/lib/watobo/gui/select_chat_dialog.rb +8 -20
  118. data/lib/watobo/gui/session_management_dialog.rb +8 -20
  119. data/lib/watobo/gui/sites_tree.rb +118 -22
  120. data/lib/watobo/gui/status_bar.rb +8 -20
  121. data/lib/watobo/gui/table_editor.rb +76 -53
  122. data/lib/watobo/gui/tagless_viewer.rb +10 -21
  123. data/lib/watobo/gui/templates/plugin.rb +8 -20
  124. data/lib/watobo/gui/templates/plugin2.rb +99 -111
  125. data/lib/watobo/gui/templates/plugin_base.rb +152 -164
  126. data/lib/watobo/gui/text_viewer.rb +8 -20
  127. data/lib/watobo/gui/transcoder_window.rb +15 -22
  128. data/lib/watobo/gui/utils/gui_utils.rb +8 -20
  129. data/lib/watobo/gui/utils/init_icons.rb +94 -106
  130. data/lib/watobo/gui/utils/load_icons.rb +41 -53
  131. data/lib/watobo/gui/utils/load_plugins.rb +118 -130
  132. data/lib/watobo/gui/utils/master_password.rb +76 -88
  133. data/lib/watobo/gui/utils/save_default_settings.rb +121 -133
  134. data/lib/watobo/gui/utils/save_project_settings.rb +8 -20
  135. data/lib/watobo/gui/utils/save_proxy_settings.rb +53 -21
  136. data/lib/watobo/gui/utils/save_scanner_settings.rb +26 -38
  137. data/lib/watobo/gui/utils/session_history.rb +120 -132
  138. data/lib/watobo/gui/workspace_dialog.rb +8 -20
  139. data/lib/watobo/gui/www_auth_dialog.rb +8 -20
  140. data/lib/watobo/gui/xml_viewer_frame.rb +8 -20
  141. data/lib/watobo/http.rb +12 -23
  142. data/lib/watobo/http/cookies/cookies.rb +63 -70
  143. data/lib/watobo/http/data/data.rb +56 -64
  144. data/lib/watobo/http/data/json.rb +51 -0
  145. data/lib/watobo/http/url/url.rb +46 -58
  146. data/lib/watobo/http/xml/xml.rb +129 -141
  147. data/lib/watobo/interceptor.rb +11 -23
  148. data/lib/watobo/interceptor/proxy.rb +624 -625
  149. data/lib/watobo/interceptor/transparent.rb +22 -34
  150. data/lib/watobo/mixins.rb +18 -30
  151. data/lib/watobo/mixins/check_info.rb +35 -47
  152. data/lib/watobo/mixins/httpparser.rb +42 -35
  153. data/lib/watobo/mixins/request_parser.rb +8 -20
  154. data/lib/watobo/mixins/shapers.rb +484 -477
  155. data/lib/watobo/mixins/transcoders.rb +8 -20
  156. data/lib/watobo/parser.rb +9 -21
  157. data/lib/watobo/parser/html.rb +91 -103
  158. data/lib/watobo/sockets.rb +11 -23
  159. data/lib/watobo/sockets/agent.rb +836 -848
  160. data/lib/watobo/sockets/client_socket.rb +283 -277
  161. data/lib/watobo/sockets/connection.rb +409 -421
  162. data/lib/watobo/sockets/http_socket.rb +16 -23
  163. data/lib/watobo/sockets/ntlm_auth.rb +137 -149
  164. data/lib/watobo/utils.rb +18 -30
  165. data/lib/watobo/utils/check_regex.rb +8 -20
  166. data/lib/watobo/utils/copy_object.rb +8 -20
  167. data/lib/watobo/utils/crypto.rb +8 -20
  168. data/lib/watobo/utils/expand_range.rb +31 -43
  169. data/lib/watobo/utils/export_xml.rb +108 -0
  170. data/lib/watobo/utils/file_management.rb +8 -20
  171. data/lib/watobo/utils/hexprint.rb +17 -29
  172. data/lib/watobo/utils/load_chat.rb +8 -20
  173. data/lib/watobo/utils/load_icon.rb +8 -20
  174. data/lib/watobo/{external/ntlm → utils}/ntlm.rb +874 -796
  175. data/lib/watobo/utils/print_debug.rb +20 -32
  176. data/lib/watobo/utils/response_builder.rb +98 -110
  177. data/lib/watobo/utils/response_hash.rb +9 -20
  178. data/lib/watobo/utils/secure_eval.rb +10 -22
  179. data/lib/watobo/utils/strings.rb +18 -30
  180. data/lib/watobo/utils/text2request.rb +12 -20
  181. data/lib/watobo/utils/url.rb +31 -43
  182. data/lib/watobo/utils/utf16.rb +22 -0
  183. data/modules/active/Apache/mod_status.rb +9 -0
  184. data/modules/active/Apache/multiview.rb +161 -0
  185. data/modules/active/Flash/crossdomain.rb +9 -0
  186. data/modules/active/directories/dirwalker.rb +8 -20
  187. data/modules/active/discovery/fileextensions.rb +10 -22
  188. data/modules/active/discovery/http_methods.rb +8 -20
  189. data/modules/active/domino/domino_db.rb +8 -20
  190. data/modules/active/dotNET/custom_errors.rb +110 -122
  191. data/modules/active/dotNET/dotnet_files.rb +98 -110
  192. data/modules/active/fileinclusion/lfi_simple.rb +8 -20
  193. data/modules/active/jboss/jboss_basic.rb +8 -20
  194. data/modules/active/sap/business_objects.rb +63 -0
  195. data/modules/active/sap/its_commands.rb +8 -20
  196. data/modules/active/sap/its_service_parameter.rb +8 -20
  197. data/modules/active/sap/its_services.rb +8 -20
  198. data/modules/active/sap/its_xss.rb +8 -20
  199. data/modules/active/shell_shock/shell_shock.rb +149 -0
  200. data/modules/active/siebel/siebel_apps.rb +168 -180
  201. data/modules/active/sqlinjection/sql_boolean.rb +9 -21
  202. data/modules/active/sqlinjection/sqli_error.rb +10 -22
  203. data/modules/active/sqlinjection/sqli_timing.rb +228 -240
  204. data/modules/active/struts2/default_handler_ognl.rb +114 -126
  205. data/modules/active/struts2/include_params_ognl.rb +113 -125
  206. data/modules/active/xml/xml_xxe.rb +122 -127
  207. data/modules/active/xss/xss_ng.rb +223 -234
  208. data/modules/active/xss/xss_simple.rb +8 -20
  209. data/modules/passive/ajax.rb +76 -84
  210. data/modules/passive/autocomplete.rb +64 -76
  211. data/modules/passive/cookie_options.rb +8 -20
  212. data/modules/passive/cookie_xss.rb +9 -21
  213. data/modules/passive/detect_code.rb +9 -21
  214. data/modules/passive/detect_fileupload.rb +11 -22
  215. data/modules/passive/detect_infrastructure.rb +23 -35
  216. data/modules/passive/detect_one_time_tokens.rb +8 -20
  217. data/modules/passive/dirindexing.rb +9 -21
  218. data/modules/passive/disclosure_domino.rb +66 -79
  219. data/modules/passive/disclosure_emails.rb +9 -21
  220. data/modules/passive/disclosure_ipaddr.rb +15 -23
  221. data/modules/passive/filename_as_parameter.rb +8 -20
  222. data/modules/passive/form_spotter.rb +15 -21
  223. data/modules/passive/hidden_fields.rb +64 -70
  224. data/modules/passive/hotspots.rb +13 -22
  225. data/modules/passive/in_script_parameter.rb +15 -24
  226. data/modules/passive/multiple_server_headers.rb +8 -20
  227. data/modules/passive/possible_login.rb +12 -23
  228. data/modules/passive/redirect_url.rb +10 -22
  229. data/modules/passive/redirectionz.rb +9 -21
  230. data/modules/passive/sap-headers.rb +64 -76
  231. data/modules/passive/xss_dom.rb +10 -21
  232. data/plugins/catalog/catalog.rb +17 -23
  233. data/plugins/crawler/crawler.rb +12 -24
  234. data/plugins/crawler/gui.rb +13 -25
  235. data/plugins/crawler/gui/auth_frame.rb +278 -290
  236. data/plugins/crawler/gui/crawler_gui.rb +302 -320
  237. data/plugins/crawler/gui/general_settings_frame.rb +104 -116
  238. data/plugins/crawler/gui/hooks_frame.rb +88 -100
  239. data/plugins/crawler/gui/scope_frame.rb +58 -70
  240. data/plugins/crawler/gui/settings_tabbook.rb +46 -58
  241. data/plugins/crawler/gui/status_frame.rb +67 -78
  242. data/plugins/crawler/lib/bags.rb +26 -38
  243. data/plugins/crawler/lib/constants.rb +19 -31
  244. data/plugins/crawler/lib/engine.rb +505 -508
  245. data/plugins/crawler/lib/grabber.rb +77 -87
  246. data/plugins/crawler/lib/status.rb +82 -0
  247. data/plugins/crawler/lib/uri_mp.rb +20 -32
  248. data/plugins/filefinder/dbs/siebel_paths.txt +1118 -0
  249. data/plugins/filefinder/dbs/subs-big.lst +31986 -0
  250. data/plugins/filefinder/filefinder.rb +13 -23
  251. data/plugins/sqlmap/bin/test.rb +86 -98
  252. data/plugins/sqlmap/gui.rb +12 -24
  253. data/plugins/sqlmap/gui/main.rb +226 -238
  254. data/plugins/sqlmap/gui/options_frame.rb +105 -117
  255. data/plugins/sqlmap/lib/sqlmap_ctrl.rb +103 -115
  256. data/plugins/sqlmap/sqlmap.rb +10 -22
  257. data/plugins/sslchecker/cli/sslchecker_cli.rb +8 -20
  258. data/plugins/sslchecker/gui/cipher_table.rb +252 -264
  259. data/plugins/sslchecker/gui/gui.rb +267 -276
  260. data/plugins/sslchecker/gui/sslchecker.rb +12 -24
  261. data/plugins/sslchecker/lib/check.rb +172 -80
  262. data/plugins/wshell/gui/main.rb +115 -127
  263. data/plugins/wshell/lib/core.rb +85 -97
  264. data/plugins/wshell/wshell.rb +19 -31
  265. metadata +14 -6
  266. data/.yardopts +0 -24
@@ -1,37 +1,25 @@
1
- # .
1
+ #.
2
2
  # transparent.rb
3
- #
4
- # Copyright 2013 by siberas, http://www.siberas.de
5
- #
6
- # This file is part of WATOBO (Web Application Tool Box)
7
- # http://watobo.sourceforge.com
8
- #
9
- # WATOBO is free software; you can redistribute it and/or modify
10
- # it under the terms of the GNU General Public License as published by
11
- # the Free Software Foundation version 2 of the License.
12
- #
13
- # WATOBO is distributed in the hope that it will be useful,
14
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- # GNU General Public License for more details.
17
- #
18
- # You should have received a copy of the GNU General Public License
19
- # along with WATOBO; if not, write to the Free Software
20
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
- # .
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
+
22
10
  # @private
23
- module Watobo#:nodoc: all
24
- module Interceptor
25
- module Transparent
26
- @nfq_drb = nil
27
- def self.start
28
- DRb.start_service
29
- @nfq_drb = DRbObject.new nil, "druby://127.0.0.1:9090"
30
- end
31
-
32
- def self.info(data)
33
- @nfq_drb.info(data)
34
- end
35
- end
36
- end
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
+ @nfq_drb.info(data)
22
+ end
23
+ end
24
+ end
37
25
  end
data/lib/watobo/mixins.rb CHANGED
@@ -1,33 +1,21 @@
1
- # .
1
+ #.
2
2
  # mixins.rb
3
- #
4
- # Copyright 2013 by siberas, http://www.siberas.de
5
- #
6
- # This file is part of WATOBO (Web Application Tool Box)
7
- # http://watobo.sourceforge.com
8
- #
9
- # WATOBO is free software; you can redistribute it and/or modify
10
- # it under the terms of the GNU General Public License as published by
11
- # the Free Software Foundation version 2 of the License.
12
- #
13
- # WATOBO is distributed in the hope that it will be useful,
14
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- # GNU General Public License for more details.
17
- #
18
- # You should have received a copy of the GNU General Public License
19
- # along with WATOBO; if not, write to the Free Software
20
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
- # .
22
- # @private
23
- module Watobo#:nodoc: all
24
- module Mixins
25
- mixins_path = File.expand_path(File.join(File.dirname(__FILE__), "mixins"))
26
- # puts "* loading mixins #{mixins_path}"
27
- Dir.glob("#{mixins_path}/*.rb").each do |cf|
28
- puts "+ #{File.basename(cf)}" if $DEBUG
29
- require File.join("watobo","mixins", File.basename(cf))
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
30
9
 
31
- end
32
- end
10
+ # @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
33
21
  end
@@ -1,50 +1,38 @@
1
- # .
1
+ #.
2
2
  # check_info.rb
3
- #
4
- # Copyright 2013 by siberas, http://www.siberas.de
5
- #
6
- # This file is part of WATOBO (Web Application Tool Box)
7
- # http://watobo.sourceforge.com
8
- #
9
- # WATOBO is free software; you can redistribute it and/or modify
10
- # it under the terms of the GNU General Public License as published by
11
- # the Free Software Foundation version 2 of the License.
12
- #
13
- # WATOBO is distributed in the hope that it will be useful,
14
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- # GNU General Public License for more details.
17
- #
18
- # You should have received a copy of the GNU General Public License
19
- # along with WATOBO; if not, write to the Free Software
20
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
- # .
22
- # @private
23
- module Watobo#:nodoc: all
24
- module CheckInfoMixin
25
- module InfoMethods
26
- def check_name
27
-
28
- #puts self.methods.sort
29
- info = instance_variable_get("@info")
30
- return nil if info.nil?
31
- return info[:check_name]
32
- end
33
-
34
- def check_group
35
- info = instance_variable_get("@info")
36
- return nil if info.nil?
37
- return info[:check_group]
38
- end
39
-
40
- end
41
-
42
- extend InfoMethods
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
43
9
 
44
- def self.included( other )
45
- other.extend InfoMethods
46
- end
47
- #:name => "#{check.info[:check_group]}|#{check.info[:check_name]}",
48
-
49
- end
10
+ # @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
50
38
  end
@@ -1,24 +1,12 @@
1
- # .
1
+ #.
2
2
  # httpparser.rb
3
- #
4
- # Copyright 2013 by siberas, http://www.siberas.de
5
- #
6
- # This file is part of WATOBO (Web Application Tool Box)
7
- # http://watobo.sourceforge.com
8
- #
9
- # WATOBO is free software; you can redistribute it and/or modify
10
- # it under the terms of the GNU General Public License as published by
11
- # the Free Software Foundation version 2 of the License.
12
- #
13
- # WATOBO is distributed in the hope that it will be useful,
14
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- # GNU General Public License for more details.
17
- #
18
- # You should have received a copy of the GNU General Public License
19
- # along with WATOBO; if not, write to the Free Software
20
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
- # .
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
+
22
10
  # http://www.ietf.org/rfc/rfc2396.txt
23
11
  # http://en.wikipedia.org/wiki/URI_scheme
24
12
 
@@ -98,7 +86,7 @@ module Watobo#:nodoc: all
98
86
  end
99
87
 
100
88
  def method
101
- if self.first =~ /(^[^[:space:]]{1,}) [a-zA-Z]+:\/\//i then
89
+ if self.first =~ /(^[^[:space:]]{1,}) /i then
102
90
  return $1
103
91
  else
104
92
  return nil
@@ -373,6 +361,8 @@ module Watobo#:nodoc: all
373
361
  begin
374
362
  if self.last =~ /\=.*\&?/i
375
363
  parmlist = self.last.split(/\&/)
364
+ parmlist.map!{|p| x = p.strip.empty? ? nil : p }
365
+ parmlist.compact!
376
366
  end
377
367
  rescue => bang
378
368
  # puts self.last.unpack("C*").pack("C*").gsub(/[^[:print:]]/,".")
@@ -449,7 +439,7 @@ module Watobo#:nodoc: all
449
439
  ct = default_ct
450
440
  self.each do |line|
451
441
  break if line.strip.empty?
452
- if line =~ /^Content-Type: ([^;]*);?/i then
442
+ if line =~ /^Content-Type:([^;]*);?/i then
453
443
  ct = $1
454
444
  break
455
445
  end
@@ -461,7 +451,7 @@ module Watobo#:nodoc: all
461
451
  ct = default_ct
462
452
  self.each do |line|
463
453
  break if line.strip.empty?
464
- if line =~ /^Content-Type: (.*)/i then
454
+ if line =~ /^Content-Type:(.*)/i then
465
455
  ct = $1.strip
466
456
  break
467
457
  end
@@ -475,8 +465,8 @@ module Watobo#:nodoc: all
475
465
  ct = -1
476
466
  self.each do |line|
477
467
  break if line.strip.empty?
478
- if line =~ /^Content-Length: (.*)/i then
479
- ct = $1.to_i
468
+ if line =~ /^Content-Length:(.*)/i then
469
+ ct = $1.strip.to_i
480
470
  break
481
471
  end
482
472
  end
@@ -487,9 +477,9 @@ def content_encoding
487
477
  te = TE_NONE
488
478
  self.each do |line|
489
479
  break if line.strip.empty?
490
- if line =~ /^Content-Encoding: (.*)/i then
480
+ if line =~ /^Content-Encoding:(.*)/i then
491
481
  dummy = $1.strip
492
- puts "Content-Encoding => #{dummy}"
482
+ # puts "Content-Encoding => #{dummy}"
493
483
  te = case dummy
494
484
  when /chunked/i
495
485
  TE_CHUNKED
@@ -514,7 +504,7 @@ def content_encoding
514
504
  te = TE_NONE
515
505
  self.each do |line|
516
506
  break if line.strip.empty?
517
- if line =~ /^Transfer-Encoding: (.*)/i then
507
+ if line =~ /^Transfer-Encoding:(.*)/i then
518
508
  dummy = $1.strip
519
509
  # puts dummy
520
510
  te = case dummy
@@ -603,7 +593,7 @@ def content_encoding
603
593
  def body
604
594
  begin
605
595
  return nil if self.nil? or self.length < 3
606
- return self.last if self[-2].strip.empty?
596
+ return "#{self.last}" if self[-2].strip.empty?
607
597
  rescue
608
598
  return nil
609
599
  end
@@ -627,24 +617,41 @@ def content_encoding
627
617
  return false
628
618
  end
629
619
 
620
+ def is_json?
621
+ ct = self.content_type
622
+ return true if ct =~ /\/json/i
623
+ return false
624
+ end
625
+
630
626
  def is_xml?
631
627
  ct = self.content_type
632
628
  return true if ct =~ /xml/i
633
629
  return false
634
630
  end
635
631
 
632
+ def is_multipart?
633
+ ct = self.content_type
634
+ return true if ct =~ /^multipart/i
635
+ return false
636
+ end
637
+
636
638
  def body_encoded
637
639
  b = self.body
638
- cs = self.charset
639
640
  return nil if b.nil?
641
+
642
+ cs = self.charset
640
643
  return b.unpack("C*").pack("C*") if cs.nil?
644
+
641
645
  begin
642
- return b.encode(cs, :invalid => :replace, :undef => :replace, :replace => '').unpack("C*").pack("C*")
646
+ # not sure if this is a good idea???
647
+ #return b.encode(cs, :invalid => :replace, :undef => :replace, :replace => '').unpack("C*").pack("C*")
643
648
  rescue => bang
644
- puts bang
645
- puts bang.backtrace if $DEBUG
646
- return b.unpack("C*").pack("C*")
649
+ if $DEBUG
650
+ puts bang
651
+ puts bang.backtrace
652
+ end
647
653
  end
654
+ return b.unpack("C*").pack("C*")
648
655
  end
649
656
 
650
657
  def responseCode
@@ -692,7 +699,7 @@ end
692
699
  self.each do |line|
693
700
  break if line.strip.empty?
694
701
  if line =~ /^Content-Type: .*charset=([^;]*)/i then
695
- cs = $1
702
+ cs = $1.strip
696
703
  break
697
704
  end
698
705
  end
@@ -1,24 +1,12 @@
1
- # .
1
+ #.
2
2
  # request_parser.rb
3
- #
4
- # Copyright 2013 by siberas, http://www.siberas.de
5
- #
6
- # This file is part of WATOBO (Web Application Tool Box)
7
- # http://watobo.sourceforge.com
8
- #
9
- # WATOBO is free software; you can redistribute it and/or modify
10
- # it under the terms of the GNU General Public License as published by
11
- # the Free Software Foundation version 2 of the License.
12
- #
13
- # WATOBO is distributed in the hope that it will be useful,
14
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- # GNU General Public License for more details.
17
- #
18
- # You should have received a copy of the GNU General Public License
19
- # along with WATOBO; if not, write to the Free Software
20
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
- # .
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
+
22
10
  # @private
23
11
  module Watobo#:nodoc: all
24
12
  module Mixins
@@ -1,478 +1,485 @@
1
- # .
1
+ #.
2
2
  # shapers.rb
3
- #
4
- # Copyright 2013 by siberas, http://www.siberas.de
5
- #
6
- # This file is part of WATOBO (Web Application Tool Box)
7
- # http://watobo.sourceforge.com
8
- #
9
- # WATOBO is free software; you can redistribute it and/or modify
10
- # it under the terms of the GNU General Public License as published by
11
- # the Free Software Foundation version 2 of the License.
12
- #
13
- # WATOBO is distributed in the hope that it will be useful,
14
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- # GNU General Public License for more details.
17
- #
18
- # You should have received a copy of the GNU General Public License
19
- # along with WATOBO; if not, write to the Free Software
20
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
- # .
22
- # @private
23
- module Watobo#:nodoc: all
24
- module Mixin
25
- module Shaper
26
- module Web10
27
- include Watobo::Constants
28
- def replace_post_parm(parm,value)
29
- parm_quoted = Regexp.quote(parm)
30
- self.last.gsub!(/([?&]{0,1})#{parm_quoted}=([^&]*)(&{0,1})/i, "\\1#{parm}=#{value}\\3")
31
- end
32
-
33
- def replace_get_parm(parm,value)
34
- parm_quoted = Regexp.quote(parm)
35
- self.first.gsub!(/([?&]{1})#{parm_quoted}=([^ &]*)(&{0,1})/i, "\\1#{parm}=#{value}\\3")
36
- end
37
-
38
- def replaceMethod(new_method)
39
- self.first.gsub!(/^[^[:space:]]{1,}/i, "#{new_method}")
40
- end
41
-
42
- def replaceFileExt(new_file)
43
- begin
44
- file = new_file.strip
45
- file.gsub!(/^\//, "")
46
- self.first.gsub!(/([^\?]*\/)(.*) (HTTP.*)/i,"\\1#{file} \\3")
47
- rescue => bang
48
- puts bang
49
- end
50
- end
51
-
52
- def replaceElement(new_element)
53
- new_element.gsub!(/^\//, "")
54
- self.first.gsub!(/([^\?]*\/)(.*) (HTTP.*)/i,"\\1#{new_element} \\3")
55
- end
56
-
57
- def replaceURL(new_url)
58
- self.first.gsub!(/(^[^[:space:]]{1,})(.*) (HTTP.*)/i,"\\1 #{new_url} \\3")
59
- end
60
-
61
- def replaceQuery(new_query)
62
- new_query.gsub!(/^\//, "")
63
- self.first.gsub!(/(.*\/)(.*) (HTTP.*)/i,"\\1#{new_query} \\3")
64
- end
65
-
66
- def strip_path()
67
- self.first.gsub!(/([^\?]*\/)(.*) (HTTP.*)/i,"\\1# \\3")
68
- end
69
-
70
- def setDir(dir)
71
- dir.strip!
72
- dir.gsub!(/^\/+/,"")
73
- dir.gsub!(/\/+$/,"")
74
- dir += "/" unless dir == ''
75
- self.first.gsub!(/(^[^[:space:]]{1,} https?:\/\/[\-0-9a-zA-Z.]*[:0-9]{0,6}\/)(.*)( HTTP\/.*)/, "\\1#{dir}\\3")
76
- end
77
-
78
- def appendDir(dir)
79
- dir.strip!
80
- dir.gsub!(/^\//,"")
81
- dir << "/" unless dir =~ /\/$/
82
- self.first.gsub!(/(^[^[:space:]]{1,} https?:\/\/[\-0-9a-zA-Z.]*[:0-9]{0,6}.*\/).*( HTTP\/.*)/, "\\1#{dir}\\2")
83
-
84
- end
85
-
86
- def add_post_parm(parm,value)
87
- line = self.last
88
- return false if line !~ /=/
89
- line += "&#{parm}=#{value}"
90
- self.pop
91
- self.push line
92
- end
93
-
94
- def add_get_parm(parm,value)
95
- line = self.shift
96
- new_p = "&"
97
- new_p = "?" if not self.element =~ /\?/
98
- new_p += parm
99
- line.gsub!(/( HTTP\/.*)/, "#{new_p}=#{value}\\1")
100
- self.unshift(line)
101
- end
102
-
103
- def addHeader(header, value)
104
- self_copy = []
105
- self_copy.concat(self.headers)
106
- self_copy.push "#{header}: #{value}\r\n"
107
-
108
- unless self.body.nil?
109
- self_copy.push "\r\n"
110
- #self_copy.concat(self.body)
111
- self_copy.push self.body
112
- end
113
-
114
- self.replace(self_copy)
115
-
116
- end
117
-
118
- alias_method :add_header, :addHeader
119
-
120
- def removeURI
121
- if self.first =~ /(^[^[:space:]]{1,}) (https?:\/\/[\-0-9a-zA-Z.]*[:0-9]{0,6}\/)/ then
122
- uri = $2
123
- self.first.gsub!(/(^[^[:space:]]{1,}) (#{Regexp.quote(uri)})/,"\\1 /")
124
- # puts "* Removed URI: #{uri}"
125
- # puts self.first
126
- return uri
127
- else
128
- return nil
129
- end
130
- #self.first.gsub!(/^(.*)(https?:\/\/[\-0-9a-zA-Z.]*[:0-9]{0,6}\/)/,"\\1/")
131
- end
132
-
133
- def removeBody
134
- self.pop if self[-2].strip.empty?
135
- end
136
-
137
- def set_header_UNUSED(header, value)
138
- self.each do |h|
139
- break if h.strip.empty?
140
- if h =~ /^#{header}:/
141
- h.replace "#{header}: #{value}\r\n"
142
- end
143
- end
144
- end
145
-
146
- def set_body(content)
147
- if self[-2].strip.empty?
148
- self.pop
149
- else
150
- self << "\r\n"
151
- end
152
- self << content
153
- end
154
-
155
- def rewrite_body(pattern, content)
156
- if self[-2].strip.empty?
157
- puts "rewrite_body ... #{pattern} - #{content}"
158
- b = self.pop
159
- b.gsub!(/#{pattern}/i, content)
160
- self << b
161
- end
162
- end
163
-
164
- def restoreURI(uri)
165
- if self.first =~ /(^[^[:space:]]{1,}) \/(.*) (HTTP\/.*)/ then
166
- method = $1
167
- rest = $2
168
- http = $3.strip
169
- #self.first.gsub!(/^\w*/, "#{method} #{uri}#{rest}")
170
- self.shift
171
- self.unshift "#{method} #{uri}#{rest} #{http}\r\n"
172
- return self.first
173
- else
174
- return nil
175
- end
176
- #self.first.gsub!(/^(.*)(https?:\/\/[\-0-9a-zA-Z.]*[:0-9]{0,6}\/)/,"\\1/")
177
- end
178
-
179
- #
180
- # R E M O V E _ H E A D E R
181
- #
182
-
183
- def removeHeader(header)
184
- begin
185
- matches = []
186
- headers.each_with_index do |h,i|
187
- next if i == 0
188
- matches << i if h =~ /#{header}/i
189
- end
190
- matches.map{ |m| self.delete_at(m) }
191
-
192
- rescue => bang
193
- puts bang
194
- puts bang.backtrace if $DEBUG
195
- puts self
196
- puts "====="
197
- end
198
- end
199
-
200
- alias_method :remove_header, :removeHeader
201
-
202
- # removeUrlParms
203
- # Function: Remove all parameter within the URL
204
- #
205
- def removeUrlParms
206
- line = self.shift
207
- new_line = "#{line}"
208
- # get end-of-path-index
209
- eop_index = line.rindex(/[^ HTTP]\//)
210
- # get start of parms
211
- sop_index = line.index(/(\?|&)/, eop_index)
212
- # find end-of-url
213
- eou_index = line.index(/ HTTP/)
214
-
215
- unless sop_index.nil?
216
- new_line = line[0..sop_index-1]
217
- new_line += line[eou_index..-1]
218
- end
219
-
220
- self.unshift new_line
221
- end
222
-
223
- def removeHeader_OLD(header)
224
- # p "REMOVE HEADER: #{header}"
225
- begin
226
- self_copy = []
227
- eoh = false
228
- self.each do |line|
229
- puts self if line.nil?
230
- if not eoh == true then
231
- if not line =~ /#{header}/i
232
- self_copy.push line unless line.nil?
233
- end
234
- else
235
- self_copy.push line unless line.nil?
236
- end
237
-
238
- if line and line.strip.empty? then
239
- eoh = true
240
- end
241
- end
242
- self.replace(self_copy)
243
-
244
- rescue => bang
245
- puts bang
246
- puts bang.backtrace if $DEBUG
247
- puts self
248
- puts "====="
249
- end
250
- end
251
-
252
- def replace_header(header, value)
253
-
254
- end
255
-
256
- def fix_session(pattern,value)
257
-
258
- end
259
-
260
- def fix_content_length
261
- return false if self.body.nil?
262
- set_header("Content-Length" , body.length.to_s )
263
- # eoh_index = self.length - 2
264
- # self.map!{ |x|
265
- # x.gsub!(/^(Content-Length: )(\d+)/, "\\1#{self.body.length.to_s}") if self.index(x) <= eoh_index
266
- # x
267
- # }
268
- end
269
-
270
- def fixupContentLength_UNUSED
271
- te = self.transferEncoding
272
- if te == TE_CHUNKED then
273
- # puts "Transfer-Encoding = TE_CHUNKED"
274
- # puts self.body
275
- self.removeHeader("Transfer-Encoding")
276
- self.addHeader("Content-Length", "0")
277
- new_r = []
278
- new_r.concat self.headers
279
- new_r.push "\r\n"
280
-
281
- bytes_to_read = 0
282
- body = []
283
- is_new_chunk = false
284
-
285
- off = 0
286
- new_body = ''
287
-
288
- body_orig = self.body
289
- puts body_orig.class
290
- while body_orig[off..-1] =~ /^([0-9a-fA-F]{1,6})\r\n/
291
- len_raw = "#{$1}"
292
-
293
- len = len_raw.hex
294
-
295
- chunk_start = off + len_raw.length + 2
296
- chunk_end = chunk_start + len
297
-
298
- break if len == 0
299
-
300
- new_body.chomp!
301
- new_body += "#{body_orig[chunk_start..chunk_end]}"
302
-
303
- off = chunk_end + 2
304
- end
305
-
306
- new_r.push new_body
307
- self.replace(new_r)
308
- self.fix_content_length
309
- # puts "= FIXED ="
310
- # puts self.headers
311
- elsif te == TE_NONE then
312
- self.fix_content_length
313
- end
314
-
315
- end
316
-
317
- def fixupContentLength
318
- self.unchunk
319
- self.fix_content_length
320
- end
321
-
322
- def setRawQueryParms(parm_string)
323
- return nil if parm_string.nil?
324
- return nil if parm_string == ''
325
- new_r = ""
326
- path = Regexp.quote(self.path)
327
- #puts path
328
- if self.first =~ /(.*#{path})/ then
329
- new_r = $1 << "?" << parm_string
330
- end
331
- self.first.gsub!(/(.*) (HTTP\/.*)/, "#{new_r} \\2")
332
- end
333
-
334
- def appendQueryParms(parms)
335
- return if parms.nil?
336
- return if parms == ''
337
-
338
- puts self.first
339
- puts self.file_ext
340
-
341
- pref = (self.file_ext =~ /\?/) ? '&' : '?'
342
- puts "append query parms"
343
- self.first.gsub!(/(.*) (HTTP\/.*)/, "\\1#{pref}#{parms} \\2")
344
-
345
- end
346
-
347
-
348
- def set_content_length(length)
349
- set_header("Content-Length", length)
350
- end
351
-
352
- def set_content_type(ctype)
353
- set_header("Content-Type", ctype)
354
- end
355
-
356
- def set_header(header, value)
357
- begin
358
- new_header = "#{header}: #{value}\r\n"
359
- self.each_with_index do |h, i|
360
- if h =~ /^#{Regexp.quote(header)}:/i
361
- h.replace(new_header)
362
- return true
363
- end
364
-
365
- if h.strip.empty? or i == self.length-1
366
- self.insert(i, new_header)
367
- return true
368
- end
369
- end
370
- rescue => bang
371
- puts bang
372
- end
373
- return false
374
- end
375
-
376
- # sets post data
377
- def setData(data)
378
- return if data.nil?
379
- if self.has_body?
380
- self.pop
381
- self.push data
382
- else
383
- self.push("\r\n")
384
- self.push data
385
- end
386
- end
387
-
388
- def setMethod(method)
389
- self.first.gsub!(/(^[^[:space:]]{1,}) /, "#{method} ")
390
- end
391
-
392
- alias_method :set_method, :setMethod
393
-
394
- def setHTTPVersion(version)
395
- self.first.gsub!(/HTTP\/(.*)$/, "HTTP\/#{version}")
396
- # puts "HTTPVersion fixed: #{self.first}"
397
- end
398
-
399
- alias :method= :setMethod
400
- end
401
-
402
- module HttpResponse
403
- include Watobo::Constants
404
- def unchunk
405
- if self.transfer_encoding == TE_CHUNKED then
406
- self.removeHeader("Transfer-Encoding")
407
- self.addHeader("Content-Length", "0")
408
- new_r = []
409
- new_r.concat self.headers
410
- new_r.push "\r\n"
411
-
412
- bytes_to_read = 20
413
- body = []
414
- is_new_chunk = false
415
-
416
- off = 0
417
- new_body = ''
418
-
419
- body_orig = self.body
420
- return true if body_orig.nil?
421
- # puts body_orig.class
422
- puts body_orig.length
423
- pattern = '[0-9a-fA-F]{1,6}\r?\n'
424
- while off >= 0 and off < body_orig.length
425
- chunk_pos = body_orig.index(/(#{pattern})/, off)
426
- len_raw = $1
427
- unless chunk_pos.nil?
428
- #len_raw = body_orig.match(/#{pattern}/, chunk_pos)[0]
429
- # puts "ChunkLen: #{len_raw} (#{len_raw.strip.hex})"
430
- len = len_raw.strip.hex
431
-
432
- chunk_start = chunk_pos + len_raw.length
433
- chunk_end = chunk_start + len
434
-
435
- break if len == 0
436
-
437
- #new_body.chomp!
438
- chunk = "#{body_orig[chunk_start..chunk_end]}"
439
- new_body += chunk.chomp!
440
-
441
- off = chunk_end
442
- end
443
- end
444
- new_r.push new_body
445
- self.replace(new_r)
446
- self.fix_content_length
447
- # puts "="
448
- # self.headers.each {|h| puts h}
449
- # puts "="
450
- end
451
-
452
- end
453
-
454
- def unzip
455
-
456
- if self.content_encoding == TE_GZIP or self.transfer_encoding == TE_GZIP
457
- begin
458
- if self.has_body?
459
- gziped = self.pop
460
- gz = Zlib::GzipReader.new( StringIO.new( gziped ) )
461
- data = gz.read
462
- #puts data
463
- self << data
464
- self.removeHeader("Transfer-Encoding") if self.transfer_encoding == TE_GZIP
465
- self.removeHeader("Content-Encoding") if self.content_encoding == TE_GZIP
466
- self.fix_content_length
467
- end
468
-
469
- rescue => bang
470
- puts bang
471
- end
472
- end
473
- end
474
-
475
- end
476
- end
477
- end
478
- end
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
+ # @private
11
+ module Watobo#:nodoc: all
12
+ module Mixin
13
+ module Shaper
14
+ module Web10
15
+ include Watobo::Constants
16
+ def replace_post_parm(parm,value)
17
+ parm_quoted = Regexp.quote(parm)
18
+ self.last.gsub!(/([?&]{1}|^)#{parm_quoted}=([^&]*)(&{0,1})/i, "\\1#{parm}=#{value}\\3")
19
+ end
20
+
21
+ def replace_get_parm(parm,value)
22
+ parm_quoted = Regexp.quote(parm)
23
+ self.first.gsub!(/([?&]{1})#{parm_quoted}=([^ &]*)(&{0,1})/i, "\\1#{parm}=#{value}\\3")
24
+ end
25
+
26
+ def replaceMethod(new_method)
27
+ self.first.gsub!(/^[^[:space:]]{1,}/i, "#{new_method}")
28
+ end
29
+
30
+ def replaceFileExt(new_file)
31
+ begin
32
+ file = new_file.strip
33
+ file.gsub!(/^\//, "")
34
+ self.first.gsub!(/([^\?]*\/)(.*) (HTTP.*)/i,"\\1#{file} \\3")
35
+ rescue => bang
36
+ puts bang
37
+ end
38
+ end
39
+
40
+ def replaceElement(new_element)
41
+ new_element.gsub!(/^\//, "")
42
+ self.first.gsub!(/([^\?]*\/)(.*) (HTTP.*)/i,"\\1#{new_element} \\3")
43
+ end
44
+
45
+ def replaceURL(new_url)
46
+ self.first.gsub!(/(^[^[:space:]]{1,})(.*) (HTTP.*)/i,"\\1 #{new_url} \\3")
47
+ end
48
+
49
+ def replaceQuery(new_query)
50
+ new_query.gsub!(/^\//, "")
51
+ self.first.gsub!(/(.*\/)(.*) (HTTP.*)/i,"\\1#{new_query} \\3")
52
+ end
53
+
54
+ def strip_path()
55
+ self.first.gsub!(/([^\?]*\/)(.*) (HTTP.*)/i,"\\1# \\3")
56
+ end
57
+
58
+ def setDir(dir)
59
+ dir.strip!
60
+ dir.gsub!(/^\/+/,"")
61
+ dir.gsub!(/\/+$/,"")
62
+ dir += "/" unless dir == ''
63
+ self.first.gsub!(/(^[^[:space:]]{1,} https?:\/\/[\-0-9a-zA-Z.]*[:0-9]{0,6}\/)(.*)( HTTP\/.*)/, "\\1#{dir}\\3")
64
+ end
65
+
66
+ def appendDir(dir)
67
+ dir.strip!
68
+ dir.gsub!(/^\//,"")
69
+ dir << "/" unless dir =~ /\/$/
70
+ self.first.gsub!(/(^[^[:space:]]{1,} https?:\/\/[\-0-9a-zA-Z.]*[:0-9]{0,6}.*\/).*( HTTP\/.*)/, "\\1#{dir}\\2")
71
+
72
+ end
73
+
74
+ def add_post_parm(parm,value)
75
+ line = self.last
76
+ return false if line !~ /=/
77
+ line += "&#{parm}=#{value}"
78
+ self.pop
79
+ self.push line
80
+ end
81
+
82
+ def add_get_parm(parm,value)
83
+ line = self.shift
84
+ new_p = "&"
85
+ new_p = "?" if not self.element =~ /\?/
86
+ new_p += parm
87
+ line.gsub!(/( HTTP\/.*)/, "#{new_p}=#{value}\\1")
88
+ self.unshift(line)
89
+ end
90
+
91
+ def addHeader(header, value)
92
+ self_copy = []
93
+ self_copy.concat(self.headers)
94
+ self_copy.push "#{header}: #{value}\r\n"
95
+
96
+ unless self.body.nil?
97
+ self_copy.push "\r\n"
98
+ #self_copy.concat(self.body)
99
+ self_copy.push self.body
100
+ end
101
+
102
+ self.replace(self_copy)
103
+
104
+ end
105
+
106
+ alias_method :add_header, :addHeader
107
+
108
+ def removeURI
109
+ if self.first =~ /(^[^[:space:]]{1,}) (https?:\/\/[\-0-9a-zA-Z.]*[:0-9]{0,6}\/)/ then
110
+ uri = $2
111
+ self.first.gsub!(/(^[^[:space:]]{1,}) (#{Regexp.quote(uri)})/,"\\1 /")
112
+ # puts "* Removed URI: #{uri}"
113
+ # puts self.first
114
+ return uri
115
+ else
116
+ return nil
117
+ end
118
+ #self.first.gsub!(/^(.*)(https?:\/\/[\-0-9a-zA-Z.]*[:0-9]{0,6}\/)/,"\\1/")
119
+ end
120
+
121
+ def removeBody
122
+ self.pop if self[-2].strip.empty?
123
+ end
124
+
125
+ def set_header_UNUSED(header, value)
126
+ self.each do |h|
127
+ break if h.strip.empty?
128
+ if h =~ /^#{header}:/
129
+ h.replace "#{header}: #{value}\r\n"
130
+ end
131
+ end
132
+ end
133
+
134
+ def set_body(content)
135
+ if self[-2].strip.empty?
136
+ self.pop
137
+ else
138
+ self << "\r\n"
139
+ end
140
+ self << content
141
+ end
142
+
143
+ def rewrite_body(pattern, content)
144
+ if self[-2].strip.empty?
145
+ puts "rewrite_body ... #{pattern} - #{content}"
146
+ b = self.pop
147
+ b.gsub!(/#{pattern}/i, content)
148
+ self << b
149
+ end
150
+ end
151
+
152
+ def restoreURI(uri)
153
+ if self.first =~ /(^[^[:space:]]{1,}) \/(.*) (HTTP\/.*)/ then
154
+ method = $1
155
+ rest = $2
156
+ http = $3.strip
157
+ #self.first.gsub!(/^\w*/, "#{method} #{uri}#{rest}")
158
+ self.shift
159
+ self.unshift "#{method} #{uri}#{rest} #{http}\r\n"
160
+ return self.first
161
+ else
162
+ return nil
163
+ end
164
+ #self.first.gsub!(/^(.*)(https?:\/\/[\-0-9a-zA-Z.]*[:0-9]{0,6}\/)/,"\\1/")
165
+ end
166
+
167
+ #
168
+ # R E M O V E _ H E A D E R
169
+ #
170
+
171
+ def removeHeader(header)
172
+ begin
173
+
174
+ while i = headers.index{|h| h =~ /#{header}/i }
175
+ self.delete_at i
176
+ end
177
+
178
+ rescue => bang
179
+ puts bang
180
+ puts bang.backtrace if $DEBUG
181
+ puts self
182
+ puts "====="
183
+ end
184
+ end
185
+
186
+ alias_method :remove_header, :removeHeader
187
+
188
+ # removeUrlParms
189
+ # Function: Remove all parameter within the URL
190
+ #
191
+ def removeUrlParms
192
+ line = self.shift
193
+ new_line = "#{line}"
194
+ # get end-of-path-index
195
+ eop_index = line.rindex(/[^ HTTP]\//)
196
+ # get start of parms
197
+ sop_index = line.index(/(\?|&)/, eop_index)
198
+ # find end-of-url
199
+ eou_index = line.index(/ HTTP/)
200
+
201
+ unless sop_index.nil?
202
+ new_line = line[0..sop_index-1]
203
+ new_line += line[eou_index..-1]
204
+ end
205
+
206
+ self.unshift new_line
207
+ end
208
+
209
+ def removeHeader_OLD(header)
210
+ # p "REMOVE HEADER: #{header}"
211
+ begin
212
+ self_copy = []
213
+ eoh = false
214
+ self.each do |line|
215
+ puts self if line.nil?
216
+ if not eoh == true then
217
+ if not line =~ /#{header}/i
218
+ self_copy.push line unless line.nil?
219
+ end
220
+ else
221
+ self_copy.push line unless line.nil?
222
+ end
223
+
224
+ if line and line.strip.empty? then
225
+ eoh = true
226
+ end
227
+ end
228
+ self.replace(self_copy)
229
+
230
+ rescue => bang
231
+ puts bang
232
+ puts bang.backtrace if $DEBUG
233
+ puts self
234
+ puts "====="
235
+ end
236
+ end
237
+
238
+ def replace_header(header, value)
239
+
240
+ end
241
+
242
+ def fix_session(pattern,value)
243
+
244
+ end
245
+
246
+ def fix_content_length
247
+ return false if self.body.nil?
248
+ #TODO: had trouble with length calculation of binary data in multipart request
249
+ # Workaround: toHex and then calculate length ... very time consuming :(
250
+ #
251
+ #blen = self.body.unpack("H*")[0].length / 2
252
+ blen = self.body.force_encoding("ASCII-8BIT").length
253
+ set_header("Content-Length" , blen)
254
+ end
255
+
256
+ def fixupContentLength_UNUSED
257
+ te = self.transferEncoding
258
+ if te == TE_CHUNKED then
259
+ # puts "Transfer-Encoding = TE_CHUNKED"
260
+ # puts self.body
261
+ self.removeHeader("Transfer-Encoding")
262
+ self.addHeader("Content-Length", "0")
263
+ new_r = []
264
+ new_r.concat self.headers
265
+ new_r.push "\r\n"
266
+
267
+ bytes_to_read = 0
268
+ body = []
269
+ is_new_chunk = false
270
+
271
+ off = 0
272
+ new_body = ''
273
+
274
+ body_orig = self.body
275
+ puts body_orig.class
276
+ while body_orig[off..-1] =~ /^([0-9a-fA-F]{1,6})\r\n/
277
+ len_raw = "#{$1}"
278
+
279
+ len = len_raw.hex
280
+
281
+ chunk_start = off + len_raw.length + 2
282
+ chunk_end = chunk_start + len
283
+
284
+ break if len == 0
285
+
286
+ new_body.chomp!
287
+ new_body += "#{body_orig[chunk_start..chunk_end]}"
288
+
289
+ off = chunk_end + 2
290
+ end
291
+
292
+ new_r.push new_body
293
+ self.replace(new_r)
294
+ self.fix_content_length
295
+ # puts "= FIXED ="
296
+ # puts self.headers
297
+ elsif te == TE_NONE then
298
+ self.fix_content_length
299
+ end
300
+
301
+ end
302
+
303
+ def fixupContentLength
304
+ self.unchunk
305
+ self.fix_content_length
306
+ end
307
+
308
+ def setRawQueryParms(parm_string)
309
+ return nil if parm_string.nil?
310
+ return nil if parm_string == ''
311
+ new_r = ""
312
+ path = Regexp.quote(self.path)
313
+ #puts path
314
+ if self.first =~ /(.*#{path})/ then
315
+ new_r = $1 << "?" << parm_string
316
+ end
317
+ self.first.gsub!(/(.*) (HTTP\/.*)/, "#{new_r} \\2")
318
+ end
319
+
320
+ def appendQueryParms(parms)
321
+ return if parms.nil?
322
+ return if parms == ''
323
+
324
+ puts self.first
325
+ puts self.file_ext
326
+
327
+ pref = (self.file_ext =~ /\?/) ? '&' : '?'
328
+ puts "append query parms"
329
+ self.first.gsub!(/(.*) (HTTP\/.*)/, "\\1#{pref}#{parms} \\2")
330
+
331
+ end
332
+
333
+ def set_content_length(length)
334
+ set_header("Content-Length", length)
335
+ end
336
+
337
+ def set_content_type(ctype)
338
+ set_header("Content-Type", ctype)
339
+ end
340
+
341
+ def set_header(header, value)
342
+ begin
343
+ new_header = "#{header}: #{value}\r\n"
344
+ self.each_with_index do |h, i|
345
+ if h =~ /^#{Regexp.quote(header)}:/i
346
+ self[i] = new_header
347
+ return true
348
+ end
349
+
350
+ if h.strip.empty? or i == self.length-1
351
+ self.insert(i, new_header)
352
+ return true
353
+ end
354
+ end
355
+ rescue => bang
356
+ puts bang
357
+ end
358
+ return false
359
+ end
360
+ alias :setHeader :set_header
361
+
362
+ # sets post data
363
+ def setData(data)
364
+ return if data.nil?
365
+ if self.has_body?
366
+ self.pop
367
+ self.push data
368
+ else
369
+ self.push("\r\n")
370
+ self.push data
371
+ end
372
+ end
373
+
374
+ def setMethod(method)
375
+ m = method.is_a?(Symbol) ? method.to_s.upcase : method
376
+ self.first.gsub!(/(^[^[:space:]]{1,}) /, "#{m} ")
377
+ end
378
+
379
+ alias_method :set_method, :setMethod
380
+ alias :method= :setMethod
381
+
382
+ def setHTTPVersion(version)
383
+ self.first.gsub!(/HTTP\/(.*)$/, "HTTP\/#{version}")
384
+ # puts "HTTPVersion fixed: #{self.first}"
385
+ end
386
+
387
+ end
388
+
389
+ module HttpResponse
390
+ include Watobo::Constants
391
+ def unchunk!
392
+ return false unless self.has_body?
393
+
394
+ unchunked = self.unchunk
395
+ self.replace(unchunked)
396
+ self.fix_content_length
397
+
398
+ end
399
+
400
+ def unchunk
401
+ return Response.new(self) unless self.has_body?
402
+
403
+ if self.transfer_encoding == TE_CHUNKED then
404
+ self.removeHeader("Transfer-Encoding")
405
+ self.addHeader("Content-Length", "0")
406
+ new_r = []
407
+ new_r.concat self.headers
408
+ new_r.push "\r\n"
409
+
410
+ bytes_to_read = 20
411
+ body = []
412
+ is_new_chunk = false
413
+
414
+ off = 0
415
+ new_body = ''
416
+
417
+ body_orig = self.body
418
+ pattern = '[0-9a-fA-F]+\r?\n'
419
+ while off >= 0 and off < body_orig.length
420
+ chunk_pos = body_orig.index(/(#{pattern})/, off)
421
+ len_raw = $1
422
+ unless chunk_pos.nil?
423
+ len = len_raw.strip.hex
424
+
425
+ chunk_start = chunk_pos + len_raw.length
426
+ chunk_end = chunk_start + len
427
+
428
+ break if len == 0
429
+ chunk = "#{body_orig[chunk_start..chunk_end]}"
430
+ new_body += chunk.chomp
431
+ off = chunk_end
432
+ end
433
+ end
434
+ new_r.push new_body
435
+ return Watobo::Response.new new_r
436
+
437
+ end
438
+ return Response.new(self)
439
+ end
440
+
441
+ def unzip!
442
+ if self.content_encoding == TE_GZIP or self.transfer_encoding == TE_GZIP
443
+ if self.has_body?
444
+ unziped = self.unzip_body
445
+
446
+ self[-1] = unziped
447
+ self.removeHeader("Transfer-Encoding") if self.transfer_encoding == TE_GZIP
448
+ self.removeHeader("Content-Encoding") if self.content_encoding == TE_GZIP
449
+ self.fix_content_length
450
+ end
451
+ end
452
+
453
+ end
454
+
455
+ def unzip
456
+ if self.content_encoding == TE_GZIP or self.transfer_encoding == TE_GZIP
457
+ if self.has_body?
458
+ unzipped = Response.new(self)
459
+ unzipped.unzip!
460
+ return unzipped
461
+ end
462
+ end
463
+
464
+ return Response.new(self)
465
+ end
466
+
467
+ def unzip_body
468
+ begin
469
+ if self.has_body?
470
+ gziped = self.last
471
+ gz = Zlib::GzipReader.new( StringIO.new( gziped ) )
472
+ data = gz.read
473
+ return data
474
+ end
475
+
476
+ rescue => bang
477
+ puts bang
478
+ end
479
+
480
+ end
481
+
482
+ end
483
+ end
484
+ end
485
+ end