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,145 +1,153 @@
1
- # .
1
+ #.
2
2
  # request.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
- def self.create_request(url, prefs={})
25
- unless url =~ /^https?:\/\//
26
- u = "http://#{url}"
27
- else
28
- u = url
29
- 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
30
9
 
31
- uri = URI.parse u
32
- r = "GET #{uri.to_s} HTTP/1.0\r\n"
33
- r << "Host: #{uri.host}\r\n"
34
- r.extend Watobo::Mixins::RequestParser
35
- r.to_request
36
- end
10
+ # @private
11
+ module Watobo#:nodoc: all
12
+ def self.create_request(url, prefs={})
13
+ unless url =~ /^https?:\/\//
14
+ u = "http://#{url}"
15
+ else
16
+ u = url
17
+ end
18
+
19
+ uri = URI.parse u
20
+ r = "GET #{uri.to_s} HTTP/1.1\n"
21
+ r << "Host: #{uri.host}\n"
22
+ r << "User-Agent: WATOBO\n"
23
+ r << "Accept: */*\n"
24
+ r.extend Watobo::Mixins::RequestParser
25
+ r.to_request
26
+ end
37
27
 
38
- class Request < Array
39
-
40
- attr :data
41
- attr :url
42
- attr :header
43
- # attr :cookies
44
-
45
- include Watobo::HTTP::Cookies::Mixin
46
- include Watobo::HTTP::Xml::Mixin
47
-
48
- def self.create request
49
- request.extend Watobo::Mixin::Parser::Url
50
- request.extend Watobo::Mixin::Parser::Web10
51
- request.extend Watobo::Mixin::Shaper::Web10
52
- # request = Request.new(request)
53
-
54
- end
55
-
56
- def copy
57
- c = Watobo::Utils.copyObject self
58
- Watobo::Request.new c
59
- end
60
-
61
- def uniq_hash()
62
- begin
63
- settings = Watobo::Conf::Scanner.to_h
64
- hashbase = site + method + path
65
-
66
- get_parm_names.sort.each do |p|
67
- hashbase << p
68
- hashbase << get_parm_value(p) if settings[:non_unique_parms].include?(p)
69
- end
28
+ class Request < Array
29
+
30
+ attr :data
31
+ attr :url
32
+ attr :header
33
+ # attr :cookies
34
+
35
+ include Watobo::HTTP::Cookies::Mixin
36
+ include Watobo::HTTP::Xml::Mixin
37
+ def self.create request
38
+ request.extend Watobo::Mixin::Parser::Url
39
+ request.extend Watobo::Mixin::Parser::Web10
40
+ request.extend Watobo::Mixin::Shaper::Web10
41
+ # request = Request.new(request)
42
+ end
43
+
44
+ def copy
45
+ c = Watobo::Utils.copyObject self
46
+ Watobo::Request.new c
47
+ end
48
+
49
+ def uniq_hash()
50
+ begin
51
+ settings = Watobo::Conf::Scanner.to_h
52
+ hashbase = site + method + path
53
+
54
+ get_parm_names.sort.each do |p|
55
+ hashbase << p
56
+ hashbase << get_parm_value(p) if settings[:non_unique_parms].include?(p)
57
+ end
58
+
59
+ post_parm_names.sort.each do |p|
60
+
61
+ hashbase << p
62
+ hashbase << post_parm_value(p) if settings[:non_unique_parms].include?(p)
63
+ end
64
+ # puts hashbase
65
+ return Digest::MD5.hexdigest(hashbase)
66
+ rescue => bang
67
+ puts bang
68
+ puts bang.backtrace if $DEBUG
69
+ return nil
70
+ end
71
+ end
70
72
 
71
- post_parm_names.sort.each do |p|
72
-
73
- hashbase << p
74
- hashbase << post_parm_value(p) if settings[:non_unique_parms].include?(p)
75
- end
76
- # puts hashbase
77
- return Digest::MD5.hexdigest(hashbase)
78
- rescue => bang
79
- puts bang
80
- puts bang.backtrace if $DEBUG
81
- return nil
82
- end
83
- end
84
-
85
73
  def parameters(*locations, &block)
86
- param_locations = [ :url, :data, :wwwform, :xml, :cookies ]
74
+ param_locations = [ :url, :data, :wwwform, :xml, :cookies, :json ]
87
75
  unless locations.empty?
88
76
  param_locations.select!{ |loc| locations.include? loc }
89
77
  end
90
-
78
+
91
79
  parms = []
92
80
  parms.concat @url.parameters if param_locations.include?(:url)
93
- parms.concat cookies.parameters if param_locations.include?(:cookies)
94
- parms.concat @data.parameters if self.is_wwwform? and ( param_locations.include?(:data) or param_locations.include?(:wwwform) )
95
-
81
+ parms.concat cookies.parameters if param_locations.include?(:cookies)
82
+ parms.concat @data.parameters if !@data.nil? and self.is_wwwform? and ( param_locations.include?(:data) or param_locations.include?(:wwwform) )
83
+ parms.concat @json.parameters if !@json.nil? and self.is_json? and ( param_locations.include?(:data) or param_locations.include?(:json) )
84
+
96
85
  parms.concat xml.parameters if self.is_xml? and param_locations.include?(:xml)
97
86
  if block_given?
98
87
  parms.each do |p|
99
88
  yield p
100
89
  end
101
- end
102
- parms
103
- end
104
-
105
- def set(parm)
106
- case parm.location
107
- when :data
108
- #
109
- # replace_post_parm(parm.name, parm.value)
110
- @data.set parm
111
- when :url
90
+ end
91
+ parms
92
+ end
93
+
94
+ def set(parm)
95
+ case parm.location
96
+ when :data
97
+ #
98
+ # replace_post_parm(parm.name, parm.value)
99
+ @data.set parm
100
+ when :url
112
101
  @url.set parm
113
102
  when :xml
114
103
  xml.set parm
115
104
  when :cookie
116
105
  cookies.set parm
117
- end
118
- true
106
+ when :json
107
+ @json.set parm
108
+ end
109
+ true
119
110
  end
120
111
 
121
- def initialize(r)
122
- if r.respond_to? :concat
123
- #puts "Create REQUEST from ARRAY"
124
- self.concat r
125
- elsif r.is_a? String
126
- if r =~ /^http/
127
- uri = URI.parse r
128
- self << "GET #{uri.to_s} HTTP/1.0\r\n"
129
- self << "Host: #{uri.host}\r\n"
130
- else
131
- r.extend Watobo::Mixins::RequestParser
132
- self.concat r.to_request
133
- end
134
-
112
+ def to_s
113
+ data = self.join
114
+ unless has_body?
115
+ data << "\r\n" unless data =~ /\r\n\r\n$/
135
116
  end
136
- self.extend Watobo::Mixin::Parser::Url
137
- self.extend Watobo::Mixin::Parser::Web10
138
- self.extend Watobo::Mixin::Shaper::Web10
139
-
140
- @url = Watobo::HTTP::Url.new(self)
117
+ data
118
+ end
119
+
120
+ def initialize(r)
121
+ if r.respond_to? :concat
122
+ #puts "Create REQUEST from ARRAY"
123
+ self.concat r
124
+ elsif r.is_a? String
125
+ if r =~ /^http/
126
+ uri = URI.parse r
127
+ self << "GET #{uri.to_s} HTTP/1.0\r\n"
128
+ self << "Host: #{uri.host}\r\n"
129
+ else
130
+ r.extend Watobo::Mixins::RequestParser
131
+ self.concat r.to_request
132
+ end
133
+
134
+ end
135
+ self.extend Watobo::Mixin::Parser::Url
136
+ self.extend Watobo::Mixin::Parser::Web10
137
+ self.extend Watobo::Mixin::Shaper::Web10
138
+
139
+ @url = Watobo::HTTP::Url.new(self)
140
+ case self.content_type
141
+ when /www-form/i
142
+ @data = Watobo::HTTPData::WWW_Form.new(self)
143
+ when /application\/json/i
144
+ @json = Watobo::HTTPData::JSONData.new(self)
145
+ else
146
+ #puts "UNKONWN CONTENT-TYPE"
141
147
  @data = Watobo::HTTPData::WWW_Form.new(self)
142
- @cookies = Watobo::HTTP::Cookies.new(self)
143
- end
144
- end
148
+ end
149
+
150
+ @cookies = Watobo::HTTP::Cookies.new(self)
151
+ end
152
+ end
145
153
  end
@@ -1,71 +1,69 @@
1
- # .
1
+ #.
2
2
  # response.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
- class Response < Array
25
- def self.is_html?
26
-
27
- end
28
-
29
- def self.is_json?
30
-
31
- end
32
-
33
-
34
-
35
-
36
- def self.create( response )
37
- raise ArgumentError, "Array Expected." unless response.is_a? Array
38
- response.extend Watobo::Mixin::Parser::Url
39
- response.extend Watobo::Mixin::Parser::Web10
40
- response.extend Watobo::Mixin::Shaper::Web10
41
- response.extend Watobo::Mixin::Shaper::HttpResponse
11
+ module Watobo#:nodoc: all
12
+ class Response < Array
13
+ def self.is_html?
14
+
15
+ end
16
+
17
+ def self.is_json?
18
+
42
19
  end
43
20
 
44
- def data
45
- @data
46
- end
47
-
48
- def copy
49
- c = Watobo::Utils.copyObject self
50
- Watobo::Request.new c
21
+
22
+ def self.create( response )
23
+ raise ArgumentError, "Array Expected." unless response.is_a? Array
24
+ response.extend Watobo::Mixin::Parser::Url
25
+ response.extend Watobo::Mixin::Parser::Web10
26
+ response.extend Watobo::Mixin::Shaper::Web10
27
+ response.extend Watobo::Mixin::Shaper::HttpResponse
51
28
  end
52
29
 
53
- def initialize(r)
54
- if r.respond_to? :concat
55
- #puts "Create REQUEST from ARRAY"
56
- self.concat r
57
- elsif r.is_a? String
58
- raise ArgumentError, "Need Array"
59
- end
60
- self.extend Watobo::Mixin::Parser::Url
61
- self.extend Watobo::Mixin::Parser::Web10
62
- self.extend Watobo::Mixin::Shaper::Web10
63
- self.extend Watobo::Mixin::Shaper::HttpResponse
30
+ def to_s
31
+ data = self.join
64
32
 
65
- if content_type =~ /(html|text)/
66
- self.extend Watobo::Parser::HTML
67
- end
68
33
 
34
+
35
+ unless has_body?
36
+ data << "\r\n" unless data =~ /\r\n\r\n$/
37
+ end
38
+ data
69
39
  end
70
- end
40
+
41
+
42
+ def data
43
+ @data
44
+ end
45
+
46
+ def copy
47
+ c = Watobo::Utils.copyObject self
48
+ Watobo::Request.new c
49
+ end
50
+
51
+ def initialize(r)
52
+ if r.respond_to? :concat
53
+ #puts "Create REQUEST from ARRAY"
54
+ self.concat r
55
+ elsif r.is_a? String
56
+ raise ArgumentError, "Need Array"
57
+ end
58
+ self.extend Watobo::Mixin::Parser::Url
59
+ self.extend Watobo::Mixin::Parser::Web10
60
+ self.extend Watobo::Mixin::Shaper::Web10
61
+ self.extend Watobo::Mixin::Shaper::HttpResponse
62
+
63
+ if content_type =~ /(html|text)/
64
+ self.extend Watobo::Parser::HTML
65
+ end
66
+
67
+ end
68
+ end
71
69
  end
@@ -1,24 +1,12 @@
1
- # .
1
+ #.
2
2
  # scanner.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
  class Scanner2
@@ -1,114 +1,102 @@
1
- # .
1
+ #.
2
2
  # scanner3.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
- class Scanner3
25
-
26
- include Watobo::Constants
27
- include Watobo::Subscriber
28
-
29
- SCANNER_READY = 0x0000
30
- SCANNER_RUNNING = 0x0001
31
-
32
- GENERATION_STARTED = 0x0100
33
- GENERATION_FINISHED = 0x0200
34
- class Worker
35
- include Watobo::Constants
36
- include Watobo::Subscriber
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
37
9
 
38
- attr :engine
39
-
40
- STATE_IDLE = 0x00
41
- STATE_RUNNING = 0x01
10
+ # @private
11
+ module Watobo#:nodoc: all
12
+ class Scanner3
13
+
14
+ include Watobo::Constants
15
+ include Watobo::Subscriber
16
+
17
+ SCANNER_READY = 0x0000
18
+ SCANNER_RUNNING = 0x0001
19
+
20
+ GENERATION_STARTED = 0x0100
21
+ GENERATION_FINISHED = 0x0200
22
+ class Worker
23
+ include Watobo::Constants
24
+ include Watobo::Subscriber
25
+
26
+ attr :engine
27
+
28
+ STATE_IDLE = 0x00
29
+ STATE_RUNNING = 0x01
42
30
  STATE_WAIT_FOR_LOGIN = 0x02
43
- def state
44
- state = nil
45
- @state_mutex.synchronize do
46
- state = @state
47
- end
48
- state
49
- end
50
-
51
- def run
52
- @state_mutex.synchronize do @state = STATE_RUNNING; end
53
- Thread.new{ @engine.run }
54
- end
55
-
56
- def start
57
- @engine = Thread.new(@prefs){ |prefs|
58
- relogin_count = 0
31
+ def state
32
+ state = nil
33
+ @state_mutex.synchronize do
34
+ state = @state
35
+ end
36
+ state
37
+ end
38
+
39
+ def run
40
+ @state_mutex.synchronize do @state = STATE_RUNNING; end
41
+ Thread.new{ @engine.run }
42
+ end
43
+
44
+ def start
45
+ @engine = Thread.new(@prefs){ |prefs|
46
+ relogin_count = 0
59
47
  loop do
60
- Thread.current[:pos] = "wait for task"
61
- task = @tasks.deq
62
- begin
63
- #puts "RUNNING #{task[:module]}"
64
- request, response = task[:check].call()
65
-
48
+ Thread.current[:pos] = "wait for task"
49
+ task = @tasks.deq
50
+ begin
51
+ #puts "RUNNING #{task[:module]}"
52
+ request, response = task[:check].call()
53
+
66
54
  next if response.nil?
67
-
68
- unless prefs[:logout_signatures].empty? or prefs[:auto_login] == false
69
- logged_out = false
70
- prefs[:logout_signatures].each do |sig|
71
- logged_out = true if response.join =~ /#{sig}/
72
- end
73
-
55
+
56
+ unless prefs[:logout_signatures].empty? or prefs[:auto_login] == false
57
+ logged_out = false
58
+ prefs[:logout_signatures].each do |sig|
59
+ logged_out = true if response.join =~ /#{sig}/
60
+ end
61
+
74
62
  if logged_out
75
- Thread.current[:pos] = "logged out"
76
- @state_mutex.synchronize do @state = STATE_WAIT_FOR_LOGIN; end
77
- @logged_out_queue.push self
78
- # stop current thread, will be waked-up by scanner
79
- Thread.stop
63
+ Thread.current[:pos] = "logged out"
64
+ @state_mutex.synchronize do @state = STATE_WAIT_FOR_LOGIN; end
65
+ @logged_out_queue.push self
66
+ # stop current thread, will be waked-up by scanner
67
+ Thread.stop
80
68
  relogin_count += 1
81
- Thread.current[:pos] = "set state"
82
- @state_mutex.synchronize do @state = STATE_RUNNING; end
83
- unless relogin_count > 5
84
- request, response = task[:check].call()
85
- end
86
- end
87
- end
88
-
89
- unless prefs[:scanlog_name].nil? or prefs[:scanlog_name].empty?
90
- chat = Chat.new(request, response, :id => 0, :chat_source => prefs[:chat_source])
91
- Watobo::DataStore.add_scan_log(chat, prefs[:scanlog_name])
92
- end
93
- rescue => bang
94
- puts "!!! #{task[:module]} !!!"
95
- puts bang
96
- puts bang.backtrace if $DEBUG
97
- ensure
69
+ Thread.current[:pos] = "set state"
70
+ @state_mutex.synchronize do @state = STATE_RUNNING; end
71
+ unless relogin_count > 5
72
+ request, response = task[:check].call()
73
+ end
74
+ end
75
+ end
76
+
77
+ unless prefs[:scanlog_name].nil? or prefs[:scanlog_name].empty?
78
+ chat = Chat.new(request, response, :id => 0, :chat_source => prefs[:chat_source])
79
+ Watobo::DataStore.add_scan_log(chat, prefs[:scanlog_name])
80
+ end
81
+ rescue => bang
82
+ puts "!!! #{task[:module]} !!!"
83
+ puts bang
84
+ puts bang.backtrace if $DEBUG
85
+ ensure
98
86
  #puts "FINISHED #{task[:module]}"
99
- Thread.current[:pos] = "scan_finished"
100
- notify(:task_finished, task[:module])
101
- end
102
- Thread.exit if relogin_count > 5
103
- relogin_count = 0
104
- end
105
- }
106
- end
107
-
108
- def stop
87
+ Thread.current[:pos] = "scan_finished"
88
+ notify(:task_finished, task[:module])
89
+ end
90
+ Thread.exit if relogin_count > 5
91
+ relogin_count = 0
92
+ end
93
+ }
94
+ end
95
+
96
+ def stop
109
97
  @state_mutex.synchronize{ @state = STATE_IDLE }
110
98
  begin
111
- return false if @engine.nil?
99
+ return false if @engine.nil?
112
100
  if @engine.alive?
113
101
  puts "[#{self}] got stopped"
114
102
  Thread.kill @engine
@@ -118,83 +106,83 @@ module Watobo#:nodoc: all
118
106
  puts "!!! could not stop worker !!!"
119
107
  puts bang
120
108
  puts bang.backtrace
121
- end
122
- end
123
-
124
- def wait_for_login?
125
- state = false
126
- @state_mutex.synchronize do
127
- state = ( @state == STATE_WAIT_FOR_LOGIN )
128
- end
129
- state
130
- end
131
-
132
- def running?
133
- @state_mutex.synchronize do
134
- running = ( @state == STATE_RUNNING )
135
- end
136
- running
137
- end
138
-
139
- def initialize(task_queue, logged_out_queue, prefs)
140
- @engine = nil
141
- @tasks = task_queue
142
- @logged_out_queue = logged_out_queue
143
- @prefs = prefs
144
- @relogin_count = 0
145
- @state_mutex = Mutex.new
146
- @state = STATE_IDLE
147
-
148
- end
149
-
150
- end
151
- #
152
- # E N D O F W O R K E R
153
-
154
- def tasks
155
- @tasks
156
- end
157
-
158
- def status_running?
159
- ( status & SCANNER_RUNNING ) > 0
160
- end
161
-
162
- def generation_finished?
163
- ( status & GENERATION_FINISHED ) > 0
164
- end
109
+ end
110
+ end
111
+
112
+ def wait_for_login?
113
+ state = false
114
+ @state_mutex.synchronize do
115
+ state = ( @state == STATE_WAIT_FOR_LOGIN )
116
+ end
117
+ state
118
+ end
119
+
120
+ def running?
121
+ @state_mutex.synchronize do
122
+ running = ( @state == STATE_RUNNING )
123
+ end
124
+ running
125
+ end
126
+
127
+ def initialize(task_queue, logged_out_queue, prefs)
128
+ @engine = nil
129
+ @tasks = task_queue
130
+ @logged_out_queue = logged_out_queue
131
+ @prefs = prefs
132
+ @relogin_count = 0
133
+ @state_mutex = Mutex.new
134
+ @state = STATE_IDLE
135
+
136
+ end
137
+
138
+ end
139
+ #
140
+ # E N D O F W O R K E R
141
+
142
+ def tasks
143
+ @tasks
144
+ end
145
+
146
+ def status_running?
147
+ ( status & SCANNER_RUNNING ) > 0
148
+ end
149
+
150
+ def generation_finished?
151
+ ( status & GENERATION_FINISHED ) > 0
152
+ end
165
153
 
166
154
  def finished?
167
155
  # puts "num_waiting: #{@tasks.num_waiting}"
168
156
  # puts "workers: #{@workers.length}"
169
157
  # puts "generation finished? #{generation_finished?.class}"
170
158
  # puts "num tasks: #{@tasks.size}"
171
- # puts "running workers: #{running_workers}"
172
- return true if (
173
- status_running? &&
174
- ( @tasks.num_waiting == @workers.length ) &&
175
- ( @tasks.size == 0 ) &&
176
- generation_finished?
177
- )
178
- false
179
- end
159
+ # puts "running workers: #{running_workers}"
160
+ return true if (
161
+ status_running? &&
162
+ ( @tasks.num_waiting == @workers.length ) &&
163
+ ( @tasks.size == 0 ) &&
164
+ generation_finished?
165
+ )
166
+ false
167
+ end
180
168
 
181
169
  def running?()
182
-
183
- return false if (
184
- status_running? &&
185
- ( @tasks.num_waiting == @workers.length ) &&
186
- ( @tasks.size == 0 ) &&
187
- generation_finished?
188
- )
189
- return true if status_running?
190
- return false
191
- end
170
+
171
+ return false if (
172
+ status_running? &&
173
+ ( @tasks.num_waiting == @workers.length ) &&
174
+ ( @tasks.size == 0 ) &&
175
+ generation_finished?
176
+ )
177
+ return true if status_running?
178
+ return false
179
+ end
192
180
 
193
181
  def stop()
194
- print "\n[#{self}] stopping ... "
195
- begin
196
- @workers.each do |w|
197
- w.stop
182
+ print "\n[#{self}] stopping ... "
183
+ begin
184
+ @workers.each do |w|
185
+ w.stop
198
186
  end
199
187
  unless @ctrl_thread.nil?
200
188
  if @ctrl_thread.alive?
@@ -202,274 +190,274 @@ module Watobo#:nodoc: all
202
190
  Thread.kill @ctrl_thread
203
191
  end
204
192
  end
205
- print "[OK]\n"
193
+ print "[OK]\n"
206
194
  rescue => bang
207
- print "[OUTCH]\n"
208
- puts bang
209
- puts bang.backtrace if $DEBUG
210
- end
211
- end
212
-
213
- def cancel()
214
- begin
215
- @workers.each do |w|
216
- w.stop
217
- end
218
- rescue => bang
219
- puts bang
220
- puts bang.backtrace if $DEBUG
221
- end
222
- end
223
-
224
- def continue()
225
- # TODO
226
- end
227
-
228
- def progress
229
- @task_count_lock.synchronize do
230
- YAML.load(YAML.dump(@task_counter))
231
- end
232
- end
233
-
234
- def sum_total
235
- sum = 0
236
- @task_count_lock.synchronize do
237
- sum = @task_counter.values.inject(0){|i,v| i + v[:total] }
238
- end
239
- sum
240
- end
241
-
242
- def sum_progress
243
- sum = 0
244
- @task_count_lock.synchronize do
245
- sum = @task_counter.values.inject(0){|i,v| i + v[:progress] }
246
- end
247
- sum
248
- end
249
-
250
- def run( check_prefs={} )
251
- # @sites_online.clear
252
- @uniqueRequests = Hash.new
253
- set_status_running
254
-
255
- @login_count = 0
256
- @max_login_count = 20
257
-
258
- @ctrl_thread = Thread.new{
259
- size = -1
260
- loop do
195
+ print "[OUTCH]\n"
196
+ puts bang
197
+ puts bang.backtrace if $DEBUG
198
+ end
199
+ end
200
+
201
+ def cancel()
202
+ begin
203
+ @workers.each do |w|
204
+ w.stop
205
+ end
206
+ rescue => bang
207
+ puts bang
208
+ puts bang.backtrace if $DEBUG
209
+ end
210
+ end
211
+
212
+ def continue()
213
+ # TODO
214
+ end
215
+
216
+ def progress
217
+ @task_count_lock.synchronize do
218
+ YAML.load(YAML.dump(@task_counter))
219
+ end
220
+ end
221
+
222
+ def sum_total
223
+ sum = 0
224
+ @task_count_lock.synchronize do
225
+ sum = @task_counter.values.inject(0){|i,v| i + v[:total] }
226
+ end
227
+ sum
228
+ end
229
+
230
+ def sum_progress
231
+ sum = 0
232
+ @task_count_lock.synchronize do
233
+ sum = @task_counter.values.inject(0){|i,v| i + v[:progress] }
234
+ end
235
+ sum
236
+ end
237
+
238
+ def run( check_prefs={} )
239
+ # @sites_online.clear
240
+ @uniqueRequests = Hash.new
241
+ set_status_running
242
+
243
+ @login_count = 0
244
+ @max_login_count = 20
245
+
246
+ @ctrl_thread = Thread.new{
247
+ size = -1
248
+ loop do
261
249
  if @tasks.num_waiting == @workers.length and @tasks.size == 0 and generation_finished?
262
250
  begin
263
- puts "[#{self}] seems scan is finished. stopping workers now ..."
251
+ puts "[#{self}] seems scan is finished. stopping workers now ..."
264
252
  @workers.map{|w|
265
253
  #puts "[]#{self}] stopping worker #{w}"
266
254
  w.stop
267
- }
268
- # suizide!
255
+ }
256
+ # suizide!
269
257
  Thread.exit
270
258
  rescue => bang
271
259
  puts bang
272
260
  puts bang.backtrace
273
- end
274
- end
275
-
276
- if @logged_out.size == ( @workers.length - @tasks.num_waiting) or @tasks.num_waiting == @workers.size
277
- @logged_out.clear
278
- #puts "!LOGOUT DETECTED!\n#{@logged_out.size} - #{@workers.length} - #{@tasks.num_waiting}\n\n"
279
- begin
280
- puts "Run login ..."
281
- login
282
- @workers.each do |wrkr|
283
- # puts "State: #{wrkr.state}"
284
- if wrkr.wait_for_login?
285
- wrkr.engine.run
286
- end
287
- end
288
-
289
- rescue => bang
290
- puts bang
291
- puts bang.backtrace
292
- end
293
-
294
- end
295
-
296
- sleep 1
297
- end
298
- }
299
-
300
- @prefs.update check_prefs
301
- msg = "\n[Scanner] Starting Scan ..."
302
- notify(:logger, LOG_INFO, msg )
303
- puts msg
304
-
305
- # starting workers before check generation
306
- start_workers( @prefs)
307
- @max_tasks = 1000
308
-
309
- # start check generation in seperate thread
310
- Thread.new{
311
- begin
312
- set_status GENERATION_STARTED
313
- @chat_list.uniq.each do |chat|
314
- # puts chat.request.url.to_s
315
- @active_checks.uniq.each do |ac|
316
- ac.reset()
317
- if site_alive?(chat) then
318
- ac.generateChecks(chat){ |check|
319
- while @tasks.size > @max_tasks
320
- sleep 1
321
- end
322
- task = { :module => ac,
323
- :check => check
324
- }
325
- @tasks.push task
326
- }
327
- end
328
- end
329
- end
330
- rescue => bang
331
- puts bang
332
- puts bang.backtrace if $DEBUG
333
- ensure
334
- set_status GENERATION_FINISHED
335
- end
336
- }
337
-
338
- end
339
-
340
- def initialize(chat_list=[], active_checks=[], passive_checks=[], prefs={})
341
- @chat_list = chat_list
342
- @active_checks = []
343
- @passive_checks = passive_checks
344
-
345
- @tasks = Queue.new
346
- @logged_out = Queue.new
347
-
348
- @workers = []
349
-
350
- @status_lock = Mutex.new
351
-
352
- @task_count_lock = Mutex.new
261
+ end
262
+ end
263
+
264
+ if @logged_out.size == ( @workers.length - @tasks.num_waiting) or @tasks.num_waiting == @workers.size
265
+ @logged_out.clear
266
+ #puts "!LOGOUT DETECTED!\n#{@logged_out.size} - #{@workers.length} - #{@tasks.num_waiting}\n\n"
267
+ begin
268
+ puts "Run login ..."
269
+ login
270
+ @workers.each do |wrkr|
271
+ # puts "State: #{wrkr.state}"
272
+ if wrkr.wait_for_login?
273
+ wrkr.engine.run
274
+ end
275
+ end
276
+
277
+ rescue => bang
278
+ puts bang
279
+ puts bang.backtrace
280
+ end
281
+
282
+ end
283
+
284
+ sleep 1
285
+ end
286
+ }
287
+
288
+ @prefs.update check_prefs
289
+ msg = "\n[Scanner] Starting Scan ..."
290
+ notify(:logger, LOG_INFO, msg )
291
+ puts msg
292
+
293
+ # starting workers before check generation
294
+ start_workers( @prefs)
295
+ @max_tasks = 1000
296
+
297
+ # start check generation in seperate thread
298
+ Thread.new{
299
+ begin
300
+ set_status GENERATION_STARTED
301
+ @chat_list.uniq.each do |chat|
302
+ # puts chat.request.url.to_s
303
+ @active_checks.uniq.each do |ac|
304
+ ac.reset()
305
+ if site_alive?(chat) then
306
+ ac.generateChecks(chat){ |check|
307
+ while @tasks.size > @max_tasks
308
+ sleep 1
309
+ end
310
+ task = { :module => ac,
311
+ :check => check
312
+ }
313
+ @tasks.push task
314
+ }
315
+ end
316
+ end
317
+ end
318
+ rescue => bang
319
+ puts bang
320
+ puts bang.backtrace if $DEBUG
321
+ ensure
322
+ set_status GENERATION_FINISHED
323
+ end
324
+ }
325
+
326
+ end
327
+
328
+ def initialize(chat_list=[], active_checks=[], passive_checks=[], prefs={})
329
+ @chat_list = chat_list
330
+ @active_checks = []
331
+ @passive_checks = passive_checks
332
+
333
+ @tasks = Queue.new
334
+ @logged_out = Queue.new
335
+
336
+ @workers = []
337
+
338
+ @status_lock = Mutex.new
339
+
340
+ @task_count_lock = Mutex.new
353
341
  @task_counter = {}
354
342
 
355
- @ctrl_thread = nil
356
-
357
- # @onlineCheck = OnlineCheck.new(@project)
358
- msg = "Initializing Scanner ..."
359
- notify(:logger, LOG_INFO, msg)
360
- puts msg
361
-
362
- @prefs = Watobo::Conf::Scanner.to_h
363
-
364
- @prefs.update prefs
365
-
366
- puts @prefs.to_yaml
367
-
368
- unique_checks = {}
369
- active_checks.each do |x|
370
- if x.respond_to? :new
371
- ac = x.new(self.object_id, @prefs)
372
- else
373
- ac = x
374
- end
375
- unique_checks[ac.class.to_s] = ac unless unique_checks.has_key?(ac.class.to_s)
376
- end
377
- unique_checks.each_value do |check|
378
- @active_checks << check
379
- end
380
-
381
- puts "#ActiveModules: #{@active_checks.length}"
382
-
383
- @active_checks.uniq.each do |check|
384
-
385
- check.resetCounters()
386
- @chat_list.each_with_index do |chat, index|
387
- #print "."
388
- check.updateCounters(chat, @prefs)
389
- puts "* [#{index}] CheckCounter #{chat.id}: #{check.check_name} - #{check.numChecks}"
390
- end
391
-
392
- # @numTotalChecks += check.numChecks
393
- # cn = check.info[:check_name]
394
- # puts "+ add check: #{cn}"
395
- # notify(:logger, LOG_INFO, "add check #{cn}")
396
- @task_counter[check.check_name] = { :total => check.numChecks,
397
- :progress => 0
398
- }
399
- end
400
- @status = SCANNER_READY
401
- msg = "Scanner Ready!"
402
- notify(:logger, LOG_INFO, msg)
403
- puts msg
404
- end
405
-
406
- private
407
-
408
- def set_status_running
409
- s = ( status | SCANNER_RUNNING )
410
- set_status( s )
411
- end
412
-
413
- def set_status(s)
414
- @status_lock.synchronize {
415
- @status |= s
416
- }
417
- end
418
-
419
- def status
420
- @status_lock.synchronize {
421
- return @status
422
- }
423
- end
424
-
425
- def start_workers(check_prefs)
426
- num_workers = @prefs.has_key?(:max_parallel_checks) ? @prefs[:max_parallel_checks] : Watobo::Conf::Scanner.max_parallel_checks
427
-
428
- puts "Starting #{num_workers} Workers ..."
429
-
430
- num_workers.times do |i|
431
- print "... #{i + 1}"
432
- w = Scanner3::Worker.new(@tasks, @logged_out, check_prefs)
433
-
434
- w.subscribe(:task_finished){ |m|
435
- @task_count_lock.synchronize do
436
- cn = m.check_name
437
- @task_counter[cn][:progress] += 1
438
- end
439
- }
440
-
441
- @logout_count ||= 0
442
- @logout_count_lock ||= Mutex.new
443
- @num_waiting = 0
444
-
445
- w.start
446
- @workers << w
447
- end
448
- print "\n"
449
-
450
- end
451
-
452
- def login
453
- puts "do relogin"
454
- login_chats = Watobo::Conf::Scanner.login_chat_ids.uniq.map{|id| Watobo::Chats.get_by_id(id) }
455
- # puts "running #{login_chats.length} login requests"
456
- # puts login_chats.first.class
457
-
458
- @active_checks.first.runLogin(login_chats, @prefs)
459
-
460
- end
461
-
462
- def site_alive?(chat)
463
- @sites_alive ||= Hash.new
464
- site = chat.request.site
465
- return true if @sites_alive.has_key? site
466
-
467
- if Watobo::HTTPSocket.siteAlive?(chat)
468
- @sites_alive[site] = true
469
- return true
470
- end
471
- return false
343
+ @ctrl_thread = nil
344
+
345
+ # @onlineCheck = OnlineCheck.new(@project)
346
+ msg = "Initializing Scanner ..."
347
+ notify(:logger, LOG_INFO, msg)
348
+ puts msg
349
+
350
+ @prefs = Watobo::Conf::Scanner.to_h
351
+
352
+ @prefs.update prefs
353
+
354
+ puts @prefs.to_yaml
355
+
356
+ unique_checks = {}
357
+ active_checks.each do |x|
358
+ if x.respond_to? :new
359
+ ac = x.new(self.object_id, @prefs)
360
+ else
361
+ ac = x
362
+ end
363
+ unique_checks[ac.class.to_s] = ac unless unique_checks.has_key?(ac.class.to_s)
364
+ end
365
+ unique_checks.each_value do |check|
366
+ @active_checks << check
367
+ end
368
+
369
+ puts "#ActiveModules: #{@active_checks.length}"
370
+
371
+ @active_checks.uniq.each do |check|
372
+
373
+ check.resetCounters()
374
+ @chat_list.each_with_index do |chat, index|
375
+ #print "."
376
+ check.updateCounters(chat, @prefs)
377
+ puts "* [#{index}] CheckCounter #{chat.id}: #{check.check_name} - #{check.numChecks}"
378
+ end
379
+
380
+ # @numTotalChecks += check.numChecks
381
+ # cn = check.info[:check_name]
382
+ # puts "+ add check: #{cn}"
383
+ # notify(:logger, LOG_INFO, "add check #{cn}")
384
+ @task_counter[check.check_name] = { :total => check.numChecks,
385
+ :progress => 0
386
+ }
387
+ end
388
+ @status = SCANNER_READY
389
+ msg = "Scanner Ready!"
390
+ notify(:logger, LOG_INFO, msg)
391
+ puts msg
392
+ end
393
+
394
+ private
395
+
396
+ def set_status_running
397
+ s = ( status | SCANNER_RUNNING )
398
+ set_status( s )
399
+ end
400
+
401
+ def set_status(s)
402
+ @status_lock.synchronize {
403
+ @status |= s
404
+ }
405
+ end
406
+
407
+ def status
408
+ @status_lock.synchronize {
409
+ return @status
410
+ }
472
411
  end
473
412
 
474
- end
475
- end
413
+ def start_workers(check_prefs)
414
+ num_workers = @prefs.has_key?(:max_parallel_checks) ? @prefs[:max_parallel_checks] : Watobo::Conf::Scanner.max_parallel_checks
415
+
416
+ puts "Starting #{num_workers} Workers ..."
417
+
418
+ num_workers.times do |i|
419
+ print "... #{i + 1}"
420
+ w = Scanner3::Worker.new(@tasks, @logged_out, check_prefs)
421
+
422
+ w.subscribe(:task_finished){ |m|
423
+ @task_count_lock.synchronize do
424
+ cn = m.check_name
425
+ @task_counter[cn][:progress] += 1
426
+ end
427
+ }
428
+
429
+ @logout_count ||= 0
430
+ @logout_count_lock ||= Mutex.new
431
+ @num_waiting = 0
432
+
433
+ w.start
434
+ @workers << w
435
+ end
436
+ print "\n"
437
+
438
+ end
439
+
440
+ def login
441
+ puts "do relogin"
442
+ login_chats = Watobo::Conf::Scanner.login_chat_ids.uniq.map{|id| Watobo::Chats.get_by_id(id) }
443
+ # puts "running #{login_chats.length} login requests"
444
+ # puts login_chats.first.class
445
+
446
+ @active_checks.first.runLogin(login_chats, @prefs)
447
+
448
+ end
449
+
450
+ def site_alive?(chat)
451
+ @sites_alive ||= Hash.new
452
+ site = chat.request.site
453
+ return true if @sites_alive.has_key? site
454
+
455
+ if Watobo::HTTPSocket.siteAlive?(chat)
456
+ @sites_alive[site] = true
457
+ return true
458
+ end
459
+ return false
460
+ end
461
+
462
+ end
463
+ end