watobo 0.9.8.677

Sign up to get free protection for your applications and to get access to all the features.
Files changed (260) hide show
  1. data/bin/watobo_gui.rb +39 -0
  2. data/certificates/cert.pem +19 -0
  3. data/certificates/privkey.pem +15 -0
  4. data/certificates/watobo_dh.key +5 -0
  5. data/config/datastore.yml +5 -0
  6. data/config/forwarding_proxy.yml +12 -0
  7. data/config/general.yml +4 -0
  8. data/config/gui.yml +23 -0
  9. data/config/interceptor.yml +16 -0
  10. data/config/scan_policy.yml +13 -0
  11. data/config/scanner.yml +34 -0
  12. data/icons/Add.ico +0 -0
  13. data/icons/Add_24x24.ico +0 -0
  14. data/icons/Bandwidth.ico +0 -0
  15. data/icons/Bandwidth_24x24.ico +0 -0
  16. data/icons/Mr. Bomb.ico +0 -0
  17. data/icons/Mr. Bomb_16x16.ico +0 -0
  18. data/icons/Mr. Bomb_24x24.ico +0 -0
  19. data/icons/Orange Ball.ico +0 -0
  20. data/icons/Orange Ball_16x16.ico +0 -0
  21. data/icons/Orange Ball_24x24.ico +0 -0
  22. data/icons/Pause.ico +0 -0
  23. data/icons/Play.ico +0 -0
  24. data/icons/Play_24x24.ico +0 -0
  25. data/icons/Red Ball.ico +0 -0
  26. data/icons/Red Ball_16x16.ico +0 -0
  27. data/icons/Red Ball_24x24.ico +0 -0
  28. data/icons/Run.ico +0 -0
  29. data/icons/Stop.ico +0 -0
  30. data/icons/Stop_24x24.ico +0 -0
  31. data/icons/Terminal.ico +0 -0
  32. data/icons/Transfer.ico +0 -0
  33. data/icons/Transfer_16x16.ico +0 -0
  34. data/icons/User.ico +0 -0
  35. data/icons/User_16x16.ico +0 -0
  36. data/icons/User_24x24.ico +0 -0
  37. data/icons/Web Browser.ico +0 -0
  38. data/icons/Web Browser_16x16.ico +0 -0
  39. data/icons/Write Document.ico +0 -0
  40. data/icons/Yellow Ball.ico +0 -0
  41. data/icons/Yellow Ball_16x16.ico +0 -0
  42. data/icons/Yellow Ball_24x24.ico +0 -0
  43. data/icons/advanced.ico +0 -0
  44. data/icons/advanced_16x16.ico +0 -0
  45. data/icons/advanced_24x24.ico +0 -0
  46. data/icons/applications.ico +0 -0
  47. data/icons/applications_16x16.ico +0 -0
  48. data/icons/applications_24x24.ico +0 -0
  49. data/icons/browser_16x16.ico +0 -0
  50. data/icons/browser_24x24.ico +0 -0
  51. data/icons/burn.ico +0 -0
  52. data/icons/burn_16x16.ico +0 -0
  53. data/icons/burn_24x24.ico +0 -0
  54. data/icons/calculator.ico +0 -0
  55. data/icons/calculator_24x24.ico +0 -0
  56. data/icons/cb_checked.ico +0 -0
  57. data/icons/cb_checked_orange.ico +0 -0
  58. data/icons/cb_unchecked.ico +0 -0
  59. data/icons/coin_24x24.ico +0 -0
  60. data/icons/conversation.ico +0 -0
  61. data/icons/conversation_24x24.ico +0 -0
  62. data/icons/engine.ico +0 -0
  63. data/icons/filter.ico +0 -0
  64. data/icons/folder.ico +0 -0
  65. data/icons/folder_16x16.ico +0 -0
  66. data/icons/fuzzer_16x16.ico +0 -0
  67. data/icons/fuzzer_24x24.ico +0 -0
  68. data/icons/go-down_16x16.png +0 -0
  69. data/icons/go-up_16x16.png +0 -0
  70. data/icons/help.ico +0 -0
  71. data/icons/help_16x16.ico +0 -0
  72. data/icons/help_24x24.ico +0 -0
  73. data/icons/iChat.ico +0 -0
  74. data/icons/iChat_16x16.ico +0 -0
  75. data/icons/iChat_24x24.ico +0 -0
  76. data/icons/icons.txt +3 -0
  77. data/icons/info.ico +0 -0
  78. data/icons/info_16x16.ico +0 -0
  79. data/icons/info_24x24.ico +0 -0
  80. data/icons/interceptor_24x24.ico +0 -0
  81. data/icons/lock.ico +0 -0
  82. data/icons/lock_12x12.ico +0 -0
  83. data/icons/lock_16x16.ico +0 -0
  84. data/icons/monitor.ico +0 -0
  85. data/icons/plugin.ico +0 -0
  86. data/icons/plugin_24x24.ico +0 -0
  87. data/icons/scan_16x16.png +0 -0
  88. data/icons/send.ico +0 -0
  89. data/icons/server.ico +0 -0
  90. data/icons/server_16x16.ico +0 -0
  91. data/icons/siberas_logo_x24.gif +0 -0
  92. data/icons/tag_blue_32x32.ico +0 -0
  93. data/icons/watobo-48x48.png +0 -0
  94. data/icons/watobo-logo.png +0 -0
  95. data/icons/watobo.ico +0 -0
  96. data/lib/watobo/adapters/data_store.rb +38 -0
  97. data/lib/watobo/adapters/file/file_store.rb +211 -0
  98. data/lib/watobo/adapters/session_store.rb +27 -0
  99. data/lib/watobo/adapters.rb +26 -0
  100. data/lib/watobo/config.rb +143 -0
  101. data/lib/watobo/constants.rb +92 -0
  102. data/lib/watobo/core/active_check.rb +404 -0
  103. data/lib/watobo/core/cookie.rb +69 -0
  104. data/lib/watobo/core/fuzz_gen.rb +160 -0
  105. data/lib/watobo/core/http_socket.rb +142 -0
  106. data/lib/watobo/core/interceptor.rb +729 -0
  107. data/lib/watobo/core/passive_check.rb +141 -0
  108. data/lib/watobo/core/project.rb +1058 -0
  109. data/lib/watobo/core/scanner.rb +396 -0
  110. data/lib/watobo/core/session.rb +1320 -0
  111. data/lib/watobo/core/simple_ca.rb +393 -0
  112. data/lib/watobo/core.rb +34 -0
  113. data/lib/watobo/defaults.rb +40 -0
  114. data/lib/watobo/external/diff/lcs/array.rb +42 -0
  115. data/lib/watobo/external/diff/lcs/block.rb +72 -0
  116. data/lib/watobo/external/diff/lcs/callbacks.rb +343 -0
  117. data/lib/watobo/external/diff/lcs/change.rb +190 -0
  118. data/lib/watobo/external/diff/lcs/hunk.rb +279 -0
  119. data/lib/watobo/external/diff/lcs/ldiff.rb +247 -0
  120. data/lib/watobo/external/diff/lcs/string.rb +40 -0
  121. data/lib/watobo/external/diff/lcs.rb +1124 -0
  122. data/lib/watobo/external/ntlm/ntlm.rb +797 -0
  123. data/lib/watobo/externals.rb +28 -0
  124. data/lib/watobo/framework/create_project.rb +55 -0
  125. data/lib/watobo/framework/init.rb +149 -0
  126. data/lib/watobo/framework/init_modules.rb +116 -0
  127. data/lib/watobo/framework/license_text.rb +50 -0
  128. data/lib/watobo/framework.rb +26 -0
  129. data/lib/watobo/gui/about_watobo.rb +68 -0
  130. data/lib/watobo/gui/browser_preview.rb +460 -0
  131. data/lib/watobo/gui/certificate_dialog.rb +132 -0
  132. data/lib/watobo/gui/chat_diff.rb +415 -0
  133. data/lib/watobo/gui/chatviewer_frame.rb +427 -0
  134. data/lib/watobo/gui/checkboxtree.rb +221 -0
  135. data/lib/watobo/gui/checks_policy_frame.rb +123 -0
  136. data/lib/watobo/gui/client_cert_dialog.rb +227 -0
  137. data/lib/watobo/gui/confirm_scan_dialog.rb +67 -0
  138. data/lib/watobo/gui/conversation_table.rb +386 -0
  139. data/lib/watobo/gui/conversation_table_ctrl.rb +175 -0
  140. data/lib/watobo/gui/csrf_token_dialog.rb +446 -0
  141. data/lib/watobo/gui/dashboard.rb +341 -0
  142. data/lib/watobo/gui/define_scope_frame.rb +380 -0
  143. data/lib/watobo/gui/edit_comment.rb +70 -0
  144. data/lib/watobo/gui/edit_scope_dialog.rb +69 -0
  145. data/lib/watobo/gui/finding_info.rb +212 -0
  146. data/lib/watobo/gui/findings_tree.rb +459 -0
  147. data/lib/watobo/gui/full_scan_dialog.rb +269 -0
  148. data/lib/watobo/gui/fuzzer_gui.rb +1522 -0
  149. data/lib/watobo/gui/hex_viewer.rb +106 -0
  150. data/lib/watobo/gui/interceptor_gui.rb +994 -0
  151. data/lib/watobo/gui/interceptor_settings_dialog.rb +201 -0
  152. data/lib/watobo/gui/log_viewer.rb +97 -0
  153. data/lib/watobo/gui/login_wizzard.rb +301 -0
  154. data/lib/watobo/gui/main_window.rb +1815 -0
  155. data/lib/watobo/gui/manual_request_editor.rb +1105 -0
  156. data/lib/watobo/gui/master_pw_dialog.rb +142 -0
  157. data/lib/watobo/gui/password_policy_dialog.rb +98 -0
  158. data/lib/watobo/gui/plugin/base.rb +82 -0
  159. data/lib/watobo/gui/plugin_board.rb +95 -0
  160. data/lib/watobo/gui/preferences_dialog.rb +116 -0
  161. data/lib/watobo/gui/progress_window.rb +102 -0
  162. data/lib/watobo/gui/project_wizzard.rb +369 -0
  163. data/lib/watobo/gui/proxy_dialog.rb +550 -0
  164. data/lib/watobo/gui/quick_scan_dialog.rb +242 -0
  165. data/lib/watobo/gui/request_editor.rb +480 -0
  166. data/lib/watobo/gui/save_chat_dialog.rb +158 -0
  167. data/lib/watobo/gui/scanner_settings_dialog.rb +360 -0
  168. data/lib/watobo/gui/select_chat_dialog.rb +169 -0
  169. data/lib/watobo/gui/session_management_dialog.rb +688 -0
  170. data/lib/watobo/gui/sites_tree.rb +347 -0
  171. data/lib/watobo/gui/status_bar.rb +88 -0
  172. data/lib/watobo/gui/table_editor.rb +445 -0
  173. data/lib/watobo/gui/tagless_viewer.rb +62 -0
  174. data/lib/watobo/gui/templates/plugin.rb +80 -0
  175. data/lib/watobo/gui/templates/plugin2.rb +103 -0
  176. data/lib/watobo/gui/text_viewer.rb +247 -0
  177. data/lib/watobo/gui/transcoder_window.rb +215 -0
  178. data/lib/watobo/gui/utils/gui_utils.rb +129 -0
  179. data/lib/watobo/gui/utils/init_icons.rb +106 -0
  180. data/lib/watobo/gui/utils/load_icons.rb +54 -0
  181. data/lib/watobo/gui/utils/load_plugins.rb +94 -0
  182. data/lib/watobo/gui/utils/master_password.rb +90 -0
  183. data/lib/watobo/gui/utils/save_default_settings.rb +99 -0
  184. data/lib/watobo/gui/utils/save_project_settings.rb +21 -0
  185. data/lib/watobo/gui/utils/save_proxy_settings.rb +45 -0
  186. data/lib/watobo/gui/utils/save_session_settings.rb +21 -0
  187. data/lib/watobo/gui/utils/session_history.rb +134 -0
  188. data/lib/watobo/gui/workspace_dialog.rb +89 -0
  189. data/lib/watobo/gui/www_auth_dialog.rb +348 -0
  190. data/lib/watobo/gui/xml_viewer_frame.rb +114 -0
  191. data/lib/watobo/gui.rb +139 -0
  192. data/lib/watobo/mixins/httpparser.rb +664 -0
  193. data/lib/watobo/mixins/request_parser.rb +210 -0
  194. data/lib/watobo/mixins/shapers.rb +345 -0
  195. data/lib/watobo/mixins/transcoders.rb +88 -0
  196. data/lib/watobo/mixins.rb +32 -0
  197. data/lib/watobo/utils/check_regex.rb +36 -0
  198. data/lib/watobo/utils/copy_object.rb +29 -0
  199. data/lib/watobo/utils/crypto.rb +74 -0
  200. data/lib/watobo/utils/expand_range.rb +45 -0
  201. data/lib/watobo/utils/file_management.rb +73 -0
  202. data/lib/watobo/utils/load_chat.rb +219 -0
  203. data/lib/watobo/utils/load_icon.rb +47 -0
  204. data/lib/watobo/utils/print_debug.rb +34 -0
  205. data/lib/watobo/utils/response_hash.rb +143 -0
  206. data/lib/watobo/utils/secure_eval.rb +57 -0
  207. data/lib/watobo/utils/text2request.rb +96 -0
  208. data/lib/watobo/utils.rb +32 -0
  209. data/lib/watobo.rb +76 -0
  210. data/modules/active/Apache/mod_status.rb +123 -0
  211. data/modules/active/Flash/crossdomain.rb +102 -0
  212. data/modules/active/directories/dirwalker.rb +89 -0
  213. data/modules/active/discovery/fileextensions.rb +151 -0
  214. data/modules/active/discovery/http_methods.rb +135 -0
  215. data/modules/active/domino/domino_db.lst +164 -0
  216. data/modules/active/domino/domino_db.rb +128 -0
  217. data/modules/active/fileinclusion/lfi_simple.rb +134 -0
  218. data/modules/active/jboss/jboss_basic.rb +119 -0
  219. data/modules/active/sap/business_objects.rb +73 -0
  220. data/modules/active/sap/its_commands.rb +101 -0
  221. data/modules/active/sap/its_service_parameter.rb +105 -0
  222. data/modules/active/sap/its_services.rb +103 -0
  223. data/modules/active/sap/its_xss.rb +98 -0
  224. data/modules/active/sqlinjection/sql_boolean.rb +262 -0
  225. data/modules/active/sqlinjection/sqli_simple.rb +205 -0
  226. data/modules/active/xss/xss_simple.rb +179 -0
  227. data/modules/passive/cookie_options.rb +97 -0
  228. data/modules/passive/cookie_xss.rb +85 -0
  229. data/modules/passive/detect_code.rb +89 -0
  230. data/modules/passive/detect_fileupload.rb +80 -0
  231. data/modules/passive/detect_infrastructure.rb +98 -0
  232. data/modules/passive/detect_one_time_tokens.rb +86 -0
  233. data/modules/passive/dirindexing.rb +81 -0
  234. data/modules/passive/disclosure_emails.rb +82 -0
  235. data/modules/passive/disclosure_ipaddr.rb +87 -0
  236. data/modules/passive/filename_as_parameter.rb +85 -0
  237. data/modules/passive/form_spotter.rb +75 -0
  238. data/modules/passive/hotspots.rb +86 -0
  239. data/modules/passive/in_script_parameter.rb +92 -0
  240. data/modules/passive/multiple_server_headers.rb +98 -0
  241. data/modules/passive/possible_login.rb +134 -0
  242. data/modules/passive/redirect_url.rb +88 -0
  243. data/modules/passive/redirectionz.rb +96 -0
  244. data/modules/passive/xss_dom.rb +91 -0
  245. data/plugins/catalog/catalog.ico +0 -0
  246. data/plugins/catalog/catalog.rb +726 -0
  247. data/plugins/catalog/db_tests +6483 -0
  248. data/plugins/catalog/db_variables +29 -0
  249. data/plugins/filefinder/dbs/hbci.db +12 -0
  250. data/plugins/filefinder/filefinder.rb +602 -0
  251. data/plugins/sslchecker/cli/sslchecker_cli.rb +21 -0
  252. data/plugins/sslchecker/gui/cipher_table.rb +260 -0
  253. data/plugins/sslchecker/gui/gui.rb +245 -0
  254. data/plugins/sslchecker/gui/sslchecker.rb +26 -0
  255. data/plugins/sslchecker/icons/green_16x16.ico +0 -0
  256. data/plugins/sslchecker/icons/grey_16x16.ico +0 -0
  257. data/plugins/sslchecker/icons/red_16x16.ico +0 -0
  258. data/plugins/sslchecker/icons/sslchecker.ico +0 -0
  259. data/plugins/sslchecker/lib/check.rb +117 -0
  260. metadata +317 -0
@@ -0,0 +1,343 @@
1
+ # .
2
+ # callbacks.rb
3
+ #
4
+ # Copyright 2012 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
+ #! /usr/env/bin ruby
23
+ #--
24
+ # Copyright 2004 Austin Ziegler <diff-lcs@halostatue.ca>
25
+ # adapted from:
26
+ # Algorithm::Diff (Perl) by Ned Konz <perl@bike-nomad.com>
27
+ # Smalltalk by Mario I. Wolczko <mario@wolczko.com>
28
+ # implements McIlroy-Hunt diff algorithm
29
+ #
30
+ # This program is free software. It may be redistributed and/or modified under
31
+ # the terms of the GPL version 2 (or later), the Perl Artistic licence, or the
32
+ # Ruby licence.
33
+ #
34
+ # $Id: callbacks.rb,v 1.4 2004/09/14 18:51:26 austin Exp $
35
+ #++
36
+ # Contains definitions for all default callback objects.
37
+
38
+
39
+
40
+ module Diff::LCS
41
+ # This callback object implements the default set of callback events, which
42
+ # only returns the event itself. Note that #finished_a and #finished_b are
43
+ # not implemented -- I haven't yet figured out where they would be useful.
44
+ #
45
+ # Note that this is intended to be called as is, e.g.,
46
+ #
47
+ # Diff::LCS.LCS(seq1, seq2, Diff::LCS::DefaultCallbacks)
48
+ class DefaultCallbacks
49
+ class << self
50
+ # Called when two items match.
51
+ def match(event)
52
+ event
53
+ end
54
+ # Called when the old value is discarded in favour of the new value.
55
+ def discard_a(event)
56
+ event
57
+ end
58
+ # Called when the new value is discarded in favour of the old value.
59
+ def discard_b(event)
60
+ event
61
+ end
62
+ # Called when both the old and new values have changed.
63
+ def change(event)
64
+ event
65
+ end
66
+
67
+ private :new
68
+ end
69
+ end
70
+
71
+ # An alias for DefaultCallbacks that is used in Diff::LCS#traverse_sequences.
72
+ #
73
+ # Diff::LCS.LCS(seq1, seq2, Diff::LCS::SequenceCallbacks)
74
+ SequenceCallbacks = DefaultCallbacks
75
+ # An alias for DefaultCallbacks that is used in Diff::LCS#traverse_balanced.
76
+ #
77
+ # Diff::LCS.LCS(seq1, seq2, Diff::LCS::BalancedCallbacks)
78
+ BalancedCallbacks = DefaultCallbacks
79
+ end
80
+
81
+ # This will produce a compound array of simple diff change objects. Each
82
+ # element in the #diffs array is a +hunk+ or +hunk+ array, where each
83
+ # element in each +hunk+ array is a single Change object representing the
84
+ # addition or removal of a single element from one of the two tested
85
+ # sequences. The +hunk+ provides the full context for the changes.
86
+ #
87
+ # diffs = Diff::LCS.diff(seq1, seq2)
88
+ # # This example shows a simplified array format.
89
+ # # [ [ [ '-', 0, 'a' ] ], # 1
90
+ # # [ [ '+', 2, 'd' ] ], # 2
91
+ # # [ [ '-', 4, 'h' ], # 3
92
+ # # [ '+', 4, 'f' ] ],
93
+ # # [ [ '+', 6, 'k' ] ], # 4
94
+ # # [ [ '-', 8, 'n' ], # 5
95
+ # # [ '-', 9, 'p' ],
96
+ # # [ '+', 9, 'r' ],
97
+ # # [ '+', 10, 's' ],
98
+ # # [ '+', 11, 't' ] ] ]
99
+ #
100
+ # There are five hunks here. The first hunk says that the +a+ at position 0
101
+ # of the first sequence should be deleted (<tt>'-'</tt>). The second hunk
102
+ # says that the +d+ at position 2 of the second sequence should be inserted
103
+ # (<tt>'+'</tt>). The third hunk says that the +h+ at position 4 of the
104
+ # first sequence should be removed and replaced with the +f+ from position 4
105
+ # of the second sequence. The other two hunks are described similarly.
106
+ #
107
+ # === Use
108
+ # This callback object must be initialised and is used by the Diff::LCS#diff
109
+ # method.
110
+ #
111
+ # cbo = Diff::LCS::DiffCallbacks.new
112
+ # Diff::LCS.LCS(seq1, seq2, cbo)
113
+ # cbo.finish
114
+ #
115
+ # Note that the call to #finish is absolutely necessary, or the last set of
116
+ # changes will not be visible. Alternatively, can be used as:
117
+ #
118
+ # cbo = Diff::LCS::DiffCallbacks.new { |tcbo| Diff::LCS.LCS(seq1, seq2, tcbo) }
119
+ #
120
+ # The necessary #finish call will be made.
121
+ #
122
+ # === Simplified Array Format
123
+ # The simplified array format used in the example above can be obtained
124
+ # with:
125
+ #
126
+ # require 'pp'
127
+ # pp diffs.map { |e| e.map { |f| f.to_a } }
128
+ class Diff::LCS::DiffCallbacks
129
+ # Returns the difference set collected during the diff process.
130
+ attr_reader :diffs
131
+
132
+ def initialize # :yields self:
133
+ @hunk = []
134
+ @diffs = []
135
+
136
+ if block_given?
137
+ begin
138
+ yield self
139
+ ensure
140
+ self.finish
141
+ end
142
+ end
143
+ end
144
+
145
+ # Finalizes the diff process. If an unprocessed hunk still exists, then it
146
+ # is appended to the diff list.
147
+ def finish
148
+ add_nonempty_hunk
149
+ end
150
+
151
+ def match(event)
152
+ add_nonempty_hunk
153
+ end
154
+
155
+ def discard_a(event)
156
+ @hunk << Diff::LCS::Change.new('-', event.old_position, event.old_element)
157
+ end
158
+
159
+ def discard_b(event)
160
+ @hunk << Diff::LCS::Change.new('+', event.new_position, event.new_element)
161
+ end
162
+
163
+ private
164
+ def add_nonempty_hunk
165
+ @diffs << @hunk unless @hunk.empty?
166
+ @hunk = []
167
+ end
168
+ end
169
+
170
+ # This will produce a compound array of contextual diff change objects. Each
171
+ # element in the #diffs array is a "hunk" array, where each element in each
172
+ # "hunk" array is a single change. Each change is a Diff::LCS::ContextChange
173
+ # that contains both the old index and new index values for the change. The
174
+ # "hunk" provides the full context for the changes. Both old and new objects
175
+ # will be presented for changed objects. +nil+ will be substituted for a
176
+ # discarded object.
177
+ #
178
+ # seq1 = %w(a b c e h j l m n p)
179
+ # seq2 = %w(b c d e f j k l m r s t)
180
+ #
181
+ # diffs = Diff::LCS.diff(seq1, seq2, Diff::LCS::ContextDiffCallbacks)
182
+ # # This example shows a simplified array format.
183
+ # # [ [ [ '-', [ 0, 'a' ], [ 0, nil ] ] ], # 1
184
+ # # [ [ '+', [ 3, nil ], [ 2, 'd' ] ] ], # 2
185
+ # # [ [ '-', [ 4, 'h' ], [ 4, nil ] ], # 3
186
+ # # [ '+', [ 5, nil ], [ 4, 'f' ] ] ],
187
+ # # [ [ '+', [ 6, nil ], [ 6, 'k' ] ] ], # 4
188
+ # # [ [ '-', [ 8, 'n' ], [ 9, nil ] ], # 5
189
+ # # [ '+', [ 9, nil ], [ 9, 'r' ] ],
190
+ # # [ '-', [ 9, 'p' ], [ 10, nil ] ],
191
+ # # [ '+', [ 10, nil ], [ 10, 's' ] ],
192
+ # # [ '+', [ 10, nil ], [ 11, 't' ] ] ] ]
193
+ #
194
+ # The five hunks shown are comprised of individual changes; if there is a
195
+ # related set of changes, they are still shown individually.
196
+ #
197
+ # This callback can also be used with Diff::LCS#sdiff, which will produce
198
+ # results like:
199
+ #
200
+ # diffs = Diff::LCS.sdiff(seq1, seq2, Diff::LCS::ContextCallbacks)
201
+ # # This example shows a simplified array format.
202
+ # # [ [ [ "-", [ 0, "a" ], [ 0, nil ] ] ], # 1
203
+ # # [ [ "+", [ 3, nil ], [ 2, "d" ] ] ], # 2
204
+ # # [ [ "!", [ 4, "h" ], [ 4, "f" ] ] ], # 3
205
+ # # [ [ "+", [ 6, nil ], [ 6, "k" ] ] ], # 4
206
+ # # [ [ "!", [ 8, "n" ], [ 9, "r" ] ], # 5
207
+ # # [ "!", [ 9, "p" ], [ 10, "s" ] ],
208
+ # # [ "+", [ 10, nil ], [ 11, "t" ] ] ] ]
209
+ #
210
+ # The five hunks are still present, but are significantly shorter in total
211
+ # presentation, because changed items are shown as changes ("!") instead of
212
+ # potentially "mismatched" pairs of additions and deletions.
213
+ #
214
+ # The result of this operation is similar to that of
215
+ # Diff::LCS::SDiffCallbacks. They may be compared as:
216
+ #
217
+ # s = Diff::LCS.sdiff(seq1, seq2).reject { |e| e.action == "=" }
218
+ # c = Diff::LCS.sdiff(seq1, seq2, Diff::LCS::ContextDiffCallbacks).flatten
219
+ #
220
+ # s == c # -> true
221
+ #
222
+ # === Use
223
+ # This callback object must be initialised and can be used by the
224
+ # Diff::LCS#diff or Diff::LCS#sdiff methods.
225
+ #
226
+ # cbo = Diff::LCS::ContextDiffCallbacks.new
227
+ # Diff::LCS.LCS(seq1, seq2, cbo)
228
+ # cbo.finish
229
+ #
230
+ # Note that the call to #finish is absolutely necessary, or the last set of
231
+ # changes will not be visible. Alternatively, can be used as:
232
+ #
233
+ # cbo = Diff::LCS::ContextDiffCallbacks.new { |tcbo| Diff::LCS.LCS(seq1, seq2, tcbo) }
234
+ #
235
+ # The necessary #finish call will be made.
236
+ #
237
+ # === Simplified Array Format
238
+ # The simplified array format used in the example above can be obtained
239
+ # with:
240
+ #
241
+ # require 'pp'
242
+ # pp diffs.map { |e| e.map { |f| f.to_a } }
243
+ class Diff::LCS::ContextDiffCallbacks < Diff::LCS::DiffCallbacks
244
+ def discard_a(event)
245
+ @hunk << Diff::LCS::ContextChange.simplify(event)
246
+ end
247
+
248
+ def discard_b(event)
249
+ @hunk << Diff::LCS::ContextChange.simplify(event)
250
+ end
251
+
252
+ def change(event)
253
+ @hunk << Diff::LCS::ContextChange.simplify(event)
254
+ end
255
+ end
256
+
257
+ # This will produce a simple array of diff change objects. Each element in
258
+ # the #diffs array is a single ContextChange. In the set of #diffs provided
259
+ # by SDiffCallbacks, both old and new objects will be presented for both
260
+ # changed <strong>and unchanged</strong> objects. +nil+ will be substituted
261
+ # for a discarded object.
262
+ #
263
+ # The diffset produced by this callback, when provided to Diff::LCS#sdiff,
264
+ # will compute and display the necessary components to show two sequences
265
+ # and their minimized differences side by side, just like the Unix utility
266
+ # +sdiff+.
267
+ #
268
+ # same same
269
+ # before | after
270
+ # old < -
271
+ # - > new
272
+ #
273
+ # seq1 = %w(a b c e h j l m n p)
274
+ # seq2 = %w(b c d e f j k l m r s t)
275
+ #
276
+ # diffs = Diff::LCS.sdiff(seq1, seq2)
277
+ # # This example shows a simplified array format.
278
+ # # [ [ "-", [ 0, "a"], [ 0, nil ] ],
279
+ # # [ "=", [ 1, "b"], [ 0, "b" ] ],
280
+ # # [ "=", [ 2, "c"], [ 1, "c" ] ],
281
+ # # [ "+", [ 3, nil], [ 2, "d" ] ],
282
+ # # [ "=", [ 3, "e"], [ 3, "e" ] ],
283
+ # # [ "!", [ 4, "h"], [ 4, "f" ] ],
284
+ # # [ "=", [ 5, "j"], [ 5, "j" ] ],
285
+ # # [ "+", [ 6, nil], [ 6, "k" ] ],
286
+ # # [ "=", [ 6, "l"], [ 7, "l" ] ],
287
+ # # [ "=", [ 7, "m"], [ 8, "m" ] ],
288
+ # # [ "!", [ 8, "n"], [ 9, "r" ] ],
289
+ # # [ "!", [ 9, "p"], [ 10, "s" ] ],
290
+ # # [ "+", [ 10, nil], [ 11, "t" ] ] ]
291
+ #
292
+ # The result of this operation is similar to that of
293
+ # Diff::LCS::ContextDiffCallbacks. They may be compared as:
294
+ #
295
+ # s = Diff::LCS.sdiff(seq1, seq2).reject { |e| e.action == "=" }
296
+ # c = Diff::LCS.sdiff(seq1, seq2, Diff::LCS::ContextDiffCallbacks).flatten
297
+ #
298
+ # s == c # -> true
299
+ #
300
+ # === Use
301
+ # This callback object must be initialised and is used by the Diff::LCS#sdiff
302
+ # method.
303
+ #
304
+ # cbo = Diff::LCS::SDiffCallbacks.new
305
+ # Diff::LCS.LCS(seq1, seq2, cbo)
306
+ #
307
+ # As with the other initialisable callback objects, Diff::LCS::SDiffCallbacks
308
+ # can be initialised with a block. As there is no "fininishing" to be done,
309
+ # this has no effect on the state of the object.
310
+ #
311
+ # cbo = Diff::LCS::SDiffCallbacks.new { |tcbo| Diff::LCS.LCS(seq1, seq2, tcbo) }
312
+ #
313
+ # === Simplified Array Format
314
+ # The simplified array format used in the example above can be obtained
315
+ # with:
316
+ #
317
+ # require 'pp'
318
+ # pp diffs.map { |e| e.to_a }
319
+ class Diff::LCS::SDiffCallbacks
320
+ # Returns the difference set collected during the diff process.
321
+ attr_reader :diffs
322
+
323
+ def initialize #:yields self:
324
+ @diffs = []
325
+ yield self if block_given?
326
+ end
327
+
328
+ def match(event)
329
+ @diffs << Diff::LCS::ContextChange.simplify(event)
330
+ end
331
+
332
+ def discard_a(event)
333
+ @diffs << Diff::LCS::ContextChange.simplify(event)
334
+ end
335
+
336
+ def discard_b(event)
337
+ @diffs << Diff::LCS::ContextChange.simplify(event)
338
+ end
339
+
340
+ def change(event)
341
+ @diffs << Diff::LCS::ContextChange.simplify(event)
342
+ end
343
+ end
@@ -0,0 +1,190 @@
1
+ # .
2
+ # change.rb
3
+ #
4
+ # Copyright 2012 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
+ #! /usr/env/bin ruby
23
+ #--
24
+ # Copyright 2004 Austin Ziegler <diff-lcs@halostatue.ca>
25
+ # adapted from:
26
+ # Algorithm::Diff (Perl) by Ned Konz <perl@bike-nomad.com>
27
+ # Smalltalk by Mario I. Wolczko <mario@wolczko.com>
28
+ # implements McIlroy-Hunt diff algorithm
29
+ #
30
+ # This program is free software. It may be redistributed and/or modified under
31
+ # the terms of the GPL version 2 (or later), the Perl Artistic licence, or the
32
+ # Ruby licence.
33
+ #
34
+ # $Id: change.rb,v 1.4 2004/08/08 20:33:09 austin Exp $
35
+ #++
36
+ # Provides Diff::LCS::Change and Diff::LCS::ContextChange.
37
+
38
+ # Centralises the change test code in Diff::LCS::Change and
39
+ # Diff::LCS::ContextChange, since it's the same for both classes.
40
+ module Diff::LCS::ChangeTypeTests
41
+ def deleting?
42
+ @action == '-'
43
+ end
44
+
45
+ def adding?
46
+ @action == '+'
47
+ end
48
+
49
+ def unchanged?
50
+ @action == '='
51
+ end
52
+
53
+ def changed?
54
+ @changed == '!'
55
+ end
56
+
57
+ def finished_a?
58
+ @changed == '>'
59
+ end
60
+
61
+ def finished_b?
62
+ @changed == '<'
63
+ end
64
+ end
65
+
66
+ # Represents a simplistic (non-contextual) change. Represents the removal or
67
+ # addition of an element from either the old or the new sequenced enumerable.
68
+ class Diff::LCS::Change
69
+ # Returns the action this Change represents. Can be '+' (#adding?), '-'
70
+ # (#deleting?), '=' (#unchanged?), # or '!' (#changed?). When created by
71
+ # Diff::LCS#diff or Diff::LCS#sdiff, it may also be '>' (#finished_a?) or
72
+ # '<' (#finished_b?).
73
+ attr_reader :action
74
+ attr_reader :position
75
+ attr_reader :element
76
+
77
+ include Comparable
78
+ def ==(other)
79
+ (self.action == other.action) and
80
+ (self.position == other.position) and
81
+ (self.element == other.element)
82
+ end
83
+
84
+ def <=>(other)
85
+ r = self.action <=> other.action
86
+ r = self.position <=> other.position if r.zero?
87
+ r = self.element <=> other.element if r.zero?
88
+ r
89
+ end
90
+
91
+ def initialize(action, position, element)
92
+ @action = action
93
+ @position = position
94
+ @element = element
95
+ end
96
+
97
+ # Creates a Change from an array produced by Change#to_a.
98
+ def to_a
99
+ [@action, @position, @element]
100
+ end
101
+
102
+ def self.from_a(arr)
103
+ Diff::LCS::Change.new(arr[0], arr[1], arr[2])
104
+ end
105
+
106
+ include Diff::LCS::ChangeTypeTests
107
+ end
108
+
109
+ # Represents a contextual change. Contains the position and values of the
110
+ # elements in the old and the new sequenced enumerables as well as the action
111
+ # taken.
112
+ class Diff::LCS::ContextChange
113
+ # Returns the action this Change represents. Can be '+' (#adding?), '-'
114
+ # (#deleting?), '=' (#unchanged?), # or '!' (#changed?). When
115
+ # created by Diff::LCS#diff or Diff::LCS#sdiff, it may also be '>'
116
+ # (#finished_a?) or '<' (#finished_b?).
117
+ attr_reader :action
118
+ attr_reader :old_position
119
+ attr_reader :old_element
120
+ attr_reader :new_position
121
+ attr_reader :new_element
122
+
123
+ include Comparable
124
+
125
+ def ==(other)
126
+ (@action == other.action) and
127
+ (@old_position == other.old_position) and
128
+ (@new_position == other.new_position) and
129
+ (@old_element == other.old_element) and
130
+ (@new_element == other.new_element)
131
+ end
132
+
133
+ def inspect(*args)
134
+ %Q(#<#{self.class.name}:#{__id__} @action=#{action} positions=#{old_position},#{new_position} elements=#{old_element.inspect},#{new_element.inspect}>)
135
+ end
136
+
137
+ def <=>(other)
138
+ r = @action <=> other.action
139
+ r = @old_position <=> other.old_position if r.zero?
140
+ r = @new_position <=> other.new_position if r.zero?
141
+ r = @old_element <=> other.old_element if r.zero?
142
+ r = @new_element <=> other.new_element if r.zero?
143
+ r
144
+ end
145
+
146
+ def initialize(action, old_position, old_element, new_position, new_element)
147
+ @action = action
148
+ @old_position = old_position
149
+ @old_element = old_element
150
+ @new_position = new_position
151
+ @new_element = new_element
152
+ end
153
+
154
+ def to_a
155
+ [@action, [@old_position, @old_element], [@new_position, @new_element]]
156
+ end
157
+
158
+ # Creates a ContextChange from an array produced by ContextChange#to_a.
159
+ def self.from_a(arr)
160
+ if arr.size == 5
161
+ Diff::LCS::ContextChange.new(arr[0], arr[1], arr[2], arr[3], arr[4])
162
+ else
163
+ Diff::LCS::ContextChange.new(arr[0], arr[1][0], arr[1][1], arr[2][0],
164
+ arr[2][1])
165
+ end
166
+ end
167
+
168
+ # Simplifies a context change for use in some diff callbacks. '<' actions
169
+ # are converted to '-' and '>' actions are converted to '+'.
170
+ def self.simplify(event)
171
+ ea = event.to_a
172
+
173
+ case ea[0]
174
+ when '-'
175
+ ea[2][1] = nil
176
+ when '<'
177
+ ea[0] = '-'
178
+ ea[2][1] = nil
179
+ when '+'
180
+ ea[1][1] = nil
181
+ when '>'
182
+ ea[0] = '+'
183
+ ea[1][1] = nil
184
+ end
185
+
186
+ Diff::LCS::ContextChange.from_a(ea)
187
+ end
188
+
189
+ include Diff::LCS::ChangeTypeTests
190
+ end