Changeset 3439
- Timestamp:
- 08/15/08 09:59:42 (5 years ago)
- Location:
- branch/PacketManipulator
- Files:
-
- 2 added
- 10 modified
-
Backend/PM/BaseContext/Static.py (modified) (4 diffs)
-
Backend/PM/BaseContext/Timed.py (modified) (1 diff)
-
Backend/Scapy/Context/Sniff.py (modified) (1 diff)
-
Backend/Scapy/Context/Static.py (modified) (2 diffs)
-
Icons.py (modified) (1 diff)
-
MainWindow.py (modified) (2 diffs)
-
PacketManipulator (modified) (1 diff)
-
Tabs/MainTab.py (modified) (6 diffs)
-
Tabs/OperationsTab.py (modified) (2 diffs)
-
share/pixmaps/umit/stock-close-16.png (added)
-
widgets/ClosableLabel.py (added)
-
widgets/Sniff.py (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branch/PacketManipulator/Backend/PM/BaseContext/Static.py
r3431 r3439 22 22 23 23 class BaseStaticContext(object): 24 def __init__(self, fname=None): 24 NOT_SAVED, SAVED = range(2) 25 26 def __init__(self, title, fname=None): 25 27 self._data = [] 28 self._title = title 29 self._status = self.NOT_SAVED 26 30 27 31 if fname: … … 33 37 34 38 def load(self): 35 pass39 self.status = self.SAVED 36 40 def save(self): 37 pass41 self.status = self.SAVED 38 42 39 43 def get_summary(self): … … 47 51 self._data = val 48 52 53 def get_title(self): 54 return self._title 55 def set_title(self, val): 56 self._title = val 57 58 def get_status(self): 59 return self._status 60 def set_status(self, val): 61 self._status = val 62 49 63 def get_cap_file(self): 50 64 return self._cap_file … … 53 67 54 68 data = property(get_data, set_data) 69 title = property(get_title, set_title) 55 70 summary = property(get_summary, set_summary) 71 status = property(get_status, set_status) 56 72 cap_file = property(get_cap_file, set_cap_file) 57 73 -
branch/PacketManipulator/Backend/PM/BaseContext/Timed.py
r3433 r3439 37 37 self._last = 0 38 38 39 StaticContext.__init__(self )39 StaticContext.__init__(self, '') 40 40 41 41 def _start(self): -
branch/PacketManipulator/Backend/Scapy/Context/Sniff.py
r3431 r3439 44 44 self.internal = True 45 45 46 self. summary = _('Sniffing on %s') % self.iface46 self.title = _('%s capture') % self.iface 47 47 self.thread = None 48 48 -
branch/PacketManipulator/Backend/Scapy/Context/Static.py
r3431 r3439 41 41 self.data.append(MetaPacket(packet)) 42 42 43 self.status = self.SAVED 43 44 self.summary = _('%d packets loaded.') % len(data) 44 45 return True … … 60 61 return False 61 62 63 self.status = self.SAVED 62 64 self.summary = _('%d packets written.') % len(data) 63 65 return True -
branch/PacketManipulator/Icons.py
r3416 r3439 36 36 'info', 37 37 'warning', 38 'error' 38 'error', 39 40 'stock-close' 39 41 ) 40 42 -
branch/PacketManipulator/MainWindow.py
r3428 r3439 20 20 21 21 import gtk 22 import Backend 22 23 23 24 from Manager.PreferenceManager import Prefs … … 290 291 291 292 def __on_quit(self, *args): 293 self.hide() 292 294 293 295 # We need to stop the pending sniff threads 294 296 maintab = self.get_tab("MainTab") 295 297 298 lst = [] 299 296 300 for page in maintab.session_notebook: 297 page.sniff_page.stop_sniffing() 298 299 for page in maintab.session_notebook: 300 if hasattr(page.sniff_page, 'context'): 301 page.sniff_page.context.join() 301 if isinstance(page.context, Backend.TimedContext): 302 lst.append(page.context) 303 304 for ctx in lst: 305 ctx.stop() 306 307 for ctx in lst: 308 ctx.join() 302 309 303 310 gtk.main_quit() -
branch/PacketManipulator/PacketManipulator
r3359 r3439 94 94 95 95 def main(args): 96 from App import PMApp97 96 from umitCore.Paths import Path 98 97 Path.set_umit_conf(os.path.split(args[0])[0]) 98 99 from App import PMApp 99 100 100 101 try: -
branch/PacketManipulator/Tabs/MainTab.py
r3431 r3439 25 25 from widgets.Expander import AnimatedExpander 26 26 from widgets.Sniff import SniffPage 27 from widgets.ClosableLabel import ClosableLabel 27 28 28 29 from views import UmitView … … 247 248 248 249 self.sniff_page = SniffPage(self) 249 self._label = gtk.Label(ctx.summary)250 self._label = ClosableLabel(ctx.title) 250 251 251 252 self.set_border_width(4) … … 289 290 290 291 def create_edit_session(self, packet): 291 ctx = Backend.StaticContext( )292 ctx = Backend.StaticContext(_('Unsaved')) 292 293 293 294 if isinstance(packet, basestring): … … 310 311 311 312 def create_offline_session(self, fname): 312 ctx = Backend.StaticContext(fname )313 ctx = Backend.StaticContext(fname, fname) 313 314 ctx.load() 314 315 … … 321 322 322 323 def __append_session(self, session): 324 session.label.connect('close-clicked', self.__on_close_page, session) 325 323 326 self.append_page(session, session.label) 324 327 self.set_tab_reorderable(session, True) 328 325 329 return session 330 331 def __remove_session(self, session): 332 from App import PMApp 333 tab = PMApp().main_window.get_tab("Operations") 334 335 tab.tree.remove_operation(session.context) 336 337 idx = self.page_num(session) 338 self.remove_page(idx) 326 339 327 340 def get_current_session(self): … … 339 352 340 353 return None 354 355 def __on_close_page(self, label, session): 356 # Check if are stopped 357 358 if isinstance(session.context, Backend.TimedContext) and \ 359 session.context.state != session.context.NOT_RUNNING: 360 dialog = gtk.MessageDialog(self.get_toplevel(), 361 gtk.DIALOG_DESTROY_WITH_PARENT, 362 gtk.MESSAGE_QUESTION, 363 gtk.BUTTONS_YES_NO, 364 _('The session is running.\nDo you want stop it?')) 365 id = dialog.run() 366 367 dialog.hide() 368 dialog.destroy() 369 370 if id == gtk.RESPONSE_YES: 371 session.context.stop() 372 373 return 374 375 if session.context.status == session.context.SAVED: 376 self.__remove_session(session) 377 else: 378 379 dialog = gtk.MessageDialog(self.get_toplevel(), 380 gtk.DIALOG_DESTROY_WITH_PARENT, 381 gtk.MESSAGE_QUESTION, 382 gtk.BUTTONS_YES_NO, 383 _('The session has unsaved changes.\nDo you want to save them?')) 384 385 id = dialog.run() 386 387 dialog.hide() 388 dialog.destroy() 389 390 if id == gtk.RESPONSE_NO or \ 391 (id == gtk.RESPONSE_YES and session.sniff_page.save()): 392 393 self.__remove_session(session) 341 394 342 395 class MainTab(UmitView): -
branch/PacketManipulator/Tabs/OperationsTab.py
r3431 r3439 274 274 operation.start() 275 275 276 def remove_operation(self, operation): 277 """ 278 Remove an operation from the store 279 280 @param operation the Operation to remove 281 """ 282 283 if not isinstance(operation, Operation): 284 return 285 286 def remove(model, path, iter, operation): 287 if model.get_value(iter, 0) is operation: 288 model.remove(iter) 289 return True 290 291 self.store.foreach(remove, operation) 292 276 293 # Callbacks section 277 294 … … 292 309 293 310 def __on_clear(self, action, operation): 294 pass 311 # TODO: try a better method 312 iter = self.store.get_iter_first() 313 314 while iter: 315 operation = self.store.get_value(iter, 0) 316 317 if operation.state == operation.NOT_RUNNING: 318 self.store.remove(iter) 319 320 iter = self.store.iter_next(iter) 295 321 296 322 class OperationsTab(UmitView): -
branch/PacketManipulator/widgets/Sniff.py
r3431 r3439 75 75 self.reload() 76 76 77 def clear(self):78 self.store.clear()79 80 def reload(self):81 for packet in self.session.context.get_data():82 self.store.append([packet])83 84 self.statusbar.label = "<b>%s</b>" % self.session.context.summary85 86 if self.timeout_id:87 gobject.source_remove(self.timeout_id)88 89 if isinstance(self.session.context, Backend.TimedContext):90 self.timeout_id = gobject.timeout_add(200, self.__update_tree)91 92 77 def __create_toolbar(self): 93 78 self.toolbar = gtk.Toolbar() … … 95 80 96 81 stocks = ( 82 gtk.STOCK_REFRESH, 97 83 gtk.STOCK_MEDIA_STOP, 98 84 gtk.STOCK_SAVE, … … 101 87 102 88 callbacks = ( 89 self.__on_restart, 103 90 self.__on_stop, 104 91 self.__on_save, … … 107 94 108 95 tooltips = ( 96 _('Restart capturing'), 109 97 _('Stop capturing'), 110 98 _('Save packets'), … … 182 170 for rend in col.get_cell_renderers(): 183 171 rend.set_property('font-desc', desc) 172 173 self.__redraw_rows() 184 174 except: 185 175 # Block change … … 190 180 self.use_colors = value 191 181 self.tree.set_rules_hint(not self.use_colors) 182 183 self.__redraw_rows() 184 185 def __redraw_rows(self): 186 def emit_row_changed(model, path, iter): 187 model.row_changed(path, iter) 188 189 self.store.foreach(emit_row_changed) 192 190 193 191 def __get_color(self, packet): … … 215 213 return alive 216 214 215 # Public functions 216 217 217 def populate(self, pktlist): 218 218 for packet in pktlist: 219 219 self.store.append([packet]) 220 220 221 def stop_sniffing(self): 222 self.session.context.stop() 221 def clear(self): 222 self.store.clear() 223 224 def reload(self): 225 for packet in self.session.context.get_data(): 226 self.store.append([packet]) 227 228 self.statusbar.label = "<b>%s</b>" % self.session.context.summary 229 230 if self.timeout_id: 231 gobject.source_remove(self.timeout_id) 232 233 if isinstance(self.session.context, Backend.TimedContext): 234 self.timeout_id = gobject.timeout_add(200, self.__update_tree) 235 236 def save(self): 237 return self.__on_save(None) 238 239 def save_as(self): 240 return self.__on_save_as(None) 223 241 224 242 # Signals callbacks … … 273 291 def __on_stop(self, action): 274 292 self.session.context.stop() 275 276 def __on_save(self, action, saveas_on_fail=True): 293 def __on_restart(self, action): 294 self.session.context.restart() 295 296 def __on_save(self, action): 277 297 if self.session.context.cap_file: 278 self.__save_packets(self.session.context.cap_file)298 return self.__save_packets(self.session.context.cap_file) 279 299 else: 280 self.__on_save_as(None)300 return self.__on_save_as(None) 281 301 282 302 def __on_save_as(self, action): … … 295 315 dialog.add_filter(filter) 296 316 317 ret = False 297 318 if dialog.run() == gtk.RESPONSE_ACCEPT: 298 self.__save_packets(dialog.get_filename())319 ret = self.__save_packets(dialog.get_filename()) 299 320 300 321 dialog.hide() 301 322 dialog.destroy() 302 323 324 return ret 325 303 326 def __save_packets(self, fname): 304 327 self.session.context.cap_file = fname 305 306 if self.session.context.save(): 328 ret = self.session.context.save() 329 330 if ret: 307 331 self.statusbar.image = gtk.STOCK_HARDDISK 308 332 else: … … 311 335 self.statusbar.label = "<b>%s</b>" % self.session.context.summary 312 336 self.statusbar.start_animation(True) 337 338 return ret 313 339 314 340 class SniffFilter(gtk.HBox):
