watobo 0.9.8.677

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,279 @@
1
+ # .
2
+ # hunk.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: hunk.rb,v 1.2 2004/08/08 20:33:09 austin Exp $
35
+ #++
36
+ # Contains Diff::LCS::Hunk for bin/ldiff.
37
+
38
+
39
+ # A Hunk is a group of Blocks which overlap because of the context
40
+ # surrounding each block. (So if we're not using context, every hunk will
41
+ # contain one block.) Used in the diff program (bin/diff).
42
+ class Diff::LCS::Hunk
43
+ attr_reader :blocks
44
+ attr_reader :start_old, :start_new
45
+ attr_reader :end_old, :end_new
46
+ attr_reader :file_length_difference
47
+
48
+ # Change the "start" and "end" fields to note that context should be added
49
+ # to this hunk
50
+ attr :flag_context
51
+
52
+ # Create a hunk using references to both the old and new data, as well as
53
+ # the piece of data
54
+ def initialize(data_old, data_new, piece, context, file_length_difference)
55
+ # At first, a hunk will have just one Block in it
56
+ @blocks = [ Diff::LCS::Block.new(piece) ]
57
+ @data_old = data_old
58
+ @data_new = data_new
59
+
60
+ before = after = file_length_difference
61
+ after += @blocks[0].diff_size
62
+ @file_length_difference = after # The caller must get this manually
63
+
64
+ # Save the start & end of each array. If the array doesn't exist
65
+ # (e.g., we're only adding items in this block), then figure out the
66
+ # line number based on the line number of the other file and the
67
+ # current difference in file lengths.
68
+ if @blocks[0].remove.empty?
69
+ a1 = a2 = nil
70
+ else
71
+ a1 = @blocks[0].remove[0].position
72
+ a2 = @blocks[0].remove[-1].position
73
+ end
74
+
75
+ if @blocks[0].insert.empty?
76
+ b1 = b2 = nil
77
+ else
78
+ b1 = @blocks[0].insert[0].position
79
+ b2 = @blocks[0].insert[-1].position
80
+ end
81
+
82
+ @start_old = a1 || (b1 - before)
83
+ @start_new = b1 || (a1 + before)
84
+ @end_old = a2 || (b2 - after)
85
+ @end_new = b2 || (a2 + after)
86
+
87
+ self.flag_context = context
88
+ end
89
+
90
+
91
+ def flag_context=(context) #:nodoc:
92
+ return if context.nil? or context.zero?
93
+
94
+ add_start = (context > @start_old) ? @start_old : context
95
+ @start_old -= add_start
96
+ @start_new -= add_start
97
+
98
+ if (@end_old + context) > @data_old.size
99
+ add_end = @data_old.size - @end_old
100
+ else
101
+ add_end = context
102
+ end
103
+ @end_old += add_end
104
+ @end_new += add_end
105
+ end
106
+
107
+ def unshift(hunk)
108
+ @start_old = hunk.start_old
109
+ @start_new = hunk.start_new
110
+ blocks.unshift(*hunk.blocks)
111
+ end
112
+
113
+ # Is there an overlap between hunk arg0 and old hunk arg1? Note: if end
114
+ # of old hunk is one less than beginning of second, they overlap
115
+ def overlaps?(hunk = nil)
116
+ return nil if hunk.nil?
117
+
118
+ a = (@start_old - hunk.end_old) <= 1
119
+ b = (@start_new - hunk.end_new) <= 1
120
+ return (a or b)
121
+ end
122
+
123
+ def diff(format)
124
+ case format
125
+ when :old
126
+ old_diff
127
+ when :unified
128
+ unified_diff
129
+ when :context
130
+ context_diff
131
+ when :ed
132
+ self
133
+ when :reverse_ed, :ed_finish
134
+ ed_diff(format)
135
+ else
136
+ raise "Unknown diff format #{format}."
137
+ end
138
+ end
139
+
140
+ def each_old(block)
141
+ @data_old[@start_old .. @end_old].each { |e| yield e }
142
+ end
143
+
144
+ private
145
+ # Note that an old diff can't have any context. Therefore, we know that
146
+ # there's only one block in the hunk.
147
+ def old_diff
148
+ warn "Expecting only one block in an old diff hunk!" if @blocks.size > 1
149
+ op_act = { "+" => 'a', "-" => 'd', "!" => "c" }
150
+
151
+ block = @blocks[0]
152
+
153
+ # Calculate item number range. Old diff range is just like a context
154
+ # diff range, except the ranges are on one line with the action between
155
+ # them.
156
+ s = "#{context_range(:old)}#{op_act[block.op]}#{context_range(:new)}\n"
157
+ # If removing anything, just print out all the remove lines in the hunk
158
+ # which is just all the remove lines in the block.
159
+ @data_old[@start_old .. @end_old].each { |e| s << "< #{e}\n" } unless block.remove.empty?
160
+ s << "---\n" if block.op == "!"
161
+ @data_new[@start_new .. @end_new].each { |e| s << "> #{e}\n" } unless block.insert.empty?
162
+ s
163
+ end
164
+
165
+ def unified_diff
166
+ # Calculate item number range.
167
+ s = "@@ -#{unified_range(:old)} +#{unified_range(:new)} @@\n"
168
+
169
+ # Outlist starts containing the hunk of the old file. Removing an item
170
+ # just means putting a '-' in front of it. Inserting an item requires
171
+ # getting it from the new file and splicing it in. We splice in
172
+ # +num_added+ items. Remove blocks use +num_added+ because splicing
173
+ # changed the length of outlist.
174
+ #
175
+ # We remove +num_removed+ items. Insert blocks use +num_removed+
176
+ # because their item numbers -- corresponding to positions in the NEW
177
+ # file -- don't take removed items into account.
178
+ lo, hi, num_added, num_removed = @start_old, @end_old, 0, 0
179
+
180
+ outlist = @data_old[lo .. hi].collect { |e| e.gsub(/^/, ' ') }
181
+
182
+ @blocks.each do |block|
183
+ block.remove.each do |item|
184
+ op = item.action.to_s # -
185
+ offset = item.position - lo + num_added
186
+ outlist[offset].gsub!(/^ /, op.to_s)
187
+ num_removed += 1
188
+ end
189
+ block.insert.each do |item|
190
+ op = item.action.to_s # +
191
+ offset = item.position - @start_new + num_removed
192
+ outlist[offset, 0] = "#{op}#{@data_new[item.position]}"
193
+ num_added += 1
194
+ end
195
+ end
196
+
197
+ s << outlist.join("\n")
198
+ end
199
+
200
+ def context_diff
201
+ s = "***************\n"
202
+ s << "*** #{context_range(:old)} ****\n"
203
+ r = context_range(:new)
204
+
205
+ # Print out file 1 part for each block in context diff format if there
206
+ # are any blocks that remove items
207
+ lo, hi = @start_old, @end_old
208
+ removes = @blocks.select { |e| not e.remove.empty? }
209
+ if removes
210
+ outlist = @data_old[lo .. hi].collect { |e| e.gsub(/^/, ' ') }
211
+ removes.each do |block|
212
+ block.remove.each do |item|
213
+ outlist[item.position - lo].gsub!(/^ /) { block.op } # - or !
214
+ end
215
+ end
216
+ s << outlist.join("\n")
217
+ end
218
+
219
+ s << "\n--- #{r} ----\n"
220
+ lo, hi = @start_new, @end_new
221
+ inserts = @blocks.select { |e| not e.insert.empty? }
222
+ if inserts
223
+ outlist = @data_new[lo .. hi].collect { |e| e.gsub(/^/, ' ') }
224
+ inserts.each do |block|
225
+ block.insert.each do |item|
226
+ outlist[item.position - lo].gsub!(/^ /) { block.op } # + or !
227
+ end
228
+ end
229
+ s << outlist.join("\n")
230
+ end
231
+ s
232
+ end
233
+
234
+ def ed_diff(format)
235
+ op_act = { "+" => 'a', "-" => 'd', "!" => "c" }
236
+ warn "Expecting only one block in an old diff hunk!" if @blocks.size > 1
237
+
238
+ if format == :reverse_ed
239
+ s = "#{op_act[@blocks[0].op]}#{context_range(:old)}\n"
240
+ else
241
+ s = "#{context_range(:old).gsub(/,/, ' ')}#{op_act[@blocks[0].op]}\n"
242
+ end
243
+
244
+ unless @blocks[0].insert.empty?
245
+ @data_new[@start_new .. @end_new].each { |e| s << "#{e}\n" }
246
+ s << ".\n"
247
+ end
248
+ s
249
+ end
250
+
251
+ # Generate a range of item numbers to print. Only print 1 number if the
252
+ # range has only one item in it. Otherwise, it's 'start,end'
253
+ def context_range(mode)
254
+ case mode
255
+ when :old
256
+ s, e = (@start_old + 1), (@end_old + 1)
257
+ when :new
258
+ s, e = (@start_new + 1), (@end_new + 1)
259
+ end
260
+
261
+ (s < e) ? "#{s},#{e}" : "#{e}"
262
+ end
263
+
264
+ # Generate a range of item numbers to print for unified diff. Print
265
+ # number where block starts, followed by number of lines in the block
266
+ # (don't print number of lines if it's 1)
267
+ def unified_range(mode)
268
+ case mode
269
+ when :old
270
+ s, e = (@start_old + 1), (@end_old + 1)
271
+ when :new
272
+ s, e = (@start_new + 1), (@end_new + 1)
273
+ end
274
+
275
+ length = e - s + 1
276
+ first = (length < 2) ? e : s # "strange, but correct"
277
+ (length == 1) ? "#{first}" : "#{first},#{length}"
278
+ end
279
+ end
@@ -0,0 +1,247 @@
1
+ # .
2
+ # ldiff.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/bin/env ruby
23
+
24
+ require 'optparse'
25
+ require 'ostruct'
26
+ require 'diff/lcs/hunk'
27
+
28
+ # == ldiff Usage
29
+ # ldiff [options] oldfile newfile
30
+ #
31
+ # -c:: Displays a context diff with 3 lines of context.
32
+ # -C [LINES], --context [LINES]:: Displays a context diff with LINES lines of context. Default 3 lines.
33
+ # -u:: Displays a unified diff with 3 lines of context.
34
+ # -U [LINES], --unified [LINES]:: Displays a unified diff with LINES lines of context. Default 3 lines.
35
+ # -e:: Creates an 'ed' script to change oldfile to newfile.
36
+ # -f:: Creates an 'ed' script to change oldfile to newfile in reverse order.
37
+ # -a, --text:: Treats the files as text and compares them line-by-line, even if they do not seem to be text.
38
+ # --binary:: Treats the files as binary.
39
+ # -q, --brief:: Reports only whether or not the files differ, not the details.
40
+ # --help:: Shows the command-line help.
41
+ # --version:: Shows the version of Diff::LCS.
42
+ #
43
+ # By default, runs produces an "old-style" diff, with output like UNIX diff.
44
+ #
45
+ # == Copyright
46
+ # Copyright &copy; 2004 Austin Ziegler
47
+ #
48
+ # Part of Diff::LCS <http://rubyforge.org/projects/ruwiki/>
49
+ # Austin Ziegler <diff-lcs@halostatue.ca>
50
+ #
51
+ # This program is free software. It may be redistributed and/or modified under
52
+ # the terms of the GPL version 2 (or later), the Perl Artistic licence, or the
53
+ # Ruby licence.
54
+ module Diff::LCS::Ldiff
55
+ BANNER = <<-COPYRIGHT
56
+ ldiff #{Diff::LCS::VERSION}
57
+ Copyright � 2004 Austin Ziegler
58
+
59
+ Part of Diff::LCS.
60
+ http://rubyforge.org/projects/ruwiki/
61
+
62
+ Austin Ziegler <diff-lcs@halostatue.ca>
63
+
64
+ This program is free software. It may be redistributed and/or modified under
65
+ the terms of the GPL version 2 (or later), the Perl Artistic licence, or the
66
+ Ruby licence.
67
+
68
+ $Id: ldiff.rb,v 1.1 2004/09/26 01:37:49 austin Exp $
69
+ COPYRIGHT
70
+
71
+ class << self
72
+ attr_reader :format, :lines #:nodoc:
73
+ attr_reader :file_old, :file_new #:nodoc:
74
+ attr_reader :data_old, :data_new #:nodoc:
75
+
76
+ def run(args, input = $stdin, output = $stdout, error = $stderr) #:nodoc:
77
+ args.options do |o|
78
+ o.banner = "Usage: #{File.basename($0)} [options] oldfile newfile"
79
+ o.separator ""
80
+ o.on('-c',
81
+ 'Displays a context diff with 3 lines of',
82
+ 'context.') do |ctx|
83
+ @format = :context
84
+ @lines = 3
85
+ end
86
+ o.on('-C', '--context [LINES]', Numeric,
87
+ 'Displays a context diff with LINES lines',
88
+ 'of context. Default 3 lines.') do |ctx|
89
+ @format = :context
90
+ @lines = ctx || 3
91
+ end
92
+ o.on('-u',
93
+ 'Displays a unified diff with 3 lines of',
94
+ 'context.') do |ctx|
95
+ @format = :unified
96
+ @lines = 3
97
+ end
98
+ o.on('-U', '--unified [LINES]', Numeric,
99
+ 'Displays a unified diff with LINES lines',
100
+ 'of context. Default 3 lines.') do |ctx|
101
+ @format = :unified
102
+ @lines = ctx || 3
103
+ end
104
+ o.on('-e',
105
+ 'Creates an \'ed\' script to change',
106
+ 'oldfile to newfile.') do |ctx|
107
+ @format = :ed
108
+ end
109
+ o.on('-f',
110
+ 'Creates an \'ed\' script to change',
111
+ 'oldfile to newfile in reverse order.') do |ctx|
112
+ @format = :reverse_ed
113
+ end
114
+ o.on('-a', '--text',
115
+ 'Treat the files as text and compare them',
116
+ 'line-by-line, even if they do not seem',
117
+ 'to be text.') do |txt|
118
+ @binary = false
119
+ end
120
+ o.on('--binary',
121
+ 'Treats the files as binary.') do |bin|
122
+ @binary = true
123
+ end
124
+ o.on('-q', '--brief',
125
+ 'Report only whether or not the files',
126
+ 'differ, not the details.') do |ctx|
127
+ @format = :report
128
+ end
129
+ o.on_tail('--help', 'Shows this text.') do
130
+ error << o
131
+ return 0
132
+ end
133
+ o.on_tail('--version', 'Shows the version of Diff::LCS.') do
134
+ error << BANNER
135
+ return 0
136
+ end
137
+ o.on_tail ""
138
+ o.on_tail 'By default, runs produces an "old-style" diff, with output like UNIX diff.'
139
+ o.parse!
140
+ end
141
+
142
+ unless args.size == 2
143
+ error << args.options
144
+ return 127
145
+ end
146
+
147
+ # Defaults are for old-style diff
148
+ @format ||= :old
149
+ @lines ||= 0
150
+
151
+ file_old, file_new = *ARGV
152
+
153
+ case @format
154
+ when :context
155
+ char_old = '*' * 3
156
+ char_new = '-' * 3
157
+ when :unified
158
+ char_old = '-' * 3
159
+ char_new = '+' * 3
160
+ end
161
+
162
+ # After we've read up to a certain point in each file, the number of
163
+ # items we've read from each file will differ by FLD (could be 0).
164
+ file_length_difference = 0
165
+
166
+ if @binary.nil? or @binary
167
+ data_old = IO::read(file_old)
168
+ data_new = IO::read(file_new)
169
+
170
+ # Test binary status
171
+ if @binary.nil?
172
+ old_txt = data_old[0...4096].grep(/\0/).empty?
173
+ new_txt = data_new[0...4096].grep(/\0/).empty?
174
+ @binary = (not old_txt) or (not new_txt)
175
+ old_txt = new_txt = nil
176
+ end
177
+
178
+ unless @binary
179
+ data_old = data_old.split(/\n/).map! { |e| e.chomp }
180
+ data_new = data_new.split(/\n/).map! { |e| e.chomp }
181
+ end
182
+ else
183
+ data_old = IO::readlines(file_old).map! { |e| e.chomp }
184
+ data_new = IO::readlines(file_new).map! { |e| e.chomp }
185
+ end
186
+
187
+ # diff yields lots of pieces, each of which is basically a Block object
188
+ if @binary
189
+ diffs = (data_old == data_new)
190
+ else
191
+ diffs = Diff::LCS.diff(data_old, data_new)
192
+ diffs = nil if diffs.empty?
193
+ end
194
+
195
+ return 0 unless diffs
196
+
197
+ if (@format == :report) and diffs
198
+ output << "Files #{file_old} and #{file_new} differ\n"
199
+ return 1
200
+ end
201
+
202
+ if (@format == :unified) or (@format == :context)
203
+ ft = File.stat(file_old).mtime.localtime.strftime('%Y-%m-%d %H:%M:%S %z')
204
+ puts "#{char_old} #{file_old}\t#{ft}"
205
+ ft = File.stat(file_new).mtime.localtime.strftime('%Y-%m-%d %H:%M:%S %z')
206
+ puts "#{char_new} #{file_new}\t#{ft}"
207
+ end
208
+
209
+ # Loop over hunks. If a hunk overlaps with the last hunk, join them.
210
+ # Otherwise, print out the old one.
211
+ oldhunk = hunk = nil
212
+
213
+ if @format == :ed
214
+ real_output = output
215
+ output = []
216
+ end
217
+
218
+ diffs.each do |piece|
219
+ begin
220
+ hunk = Diff::LCS::Hunk.new(data_old, data_new, piece, @lines,
221
+ file_length_difference)
222
+ file_length_difference = hunk.file_length_difference
223
+
224
+ next unless oldhunk
225
+
226
+ if (@lines > 0) and hunk.overlaps?(oldhunk)
227
+ hunk.unshift(oldhunk)
228
+ else
229
+ output << oldhunk.diff(@format)
230
+ end
231
+ ensure
232
+ oldhunk = hunk
233
+ output << "\n"
234
+ end
235
+ end
236
+
237
+ output << oldhunk.diff(@format)
238
+ output << "\n"
239
+
240
+ if @format == :ed
241
+ output.reverse_each { |e| real_output << e.diff(:ed_finish) }
242
+ end
243
+
244
+ return 1
245
+ end
246
+ end
247
+ end
@@ -0,0 +1,40 @@
1
+ # .
2
+ # string.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: string.rb,v 1.3 2004/08/08 20:33:09 austin Exp $
35
+ #++
36
+ # Includes Diff::LCS into String.
37
+
38
+ class String
39
+ include Diff::LCS
40
+ end