Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/integracion' into merge
Browse files Browse the repository at this point in the history
  • Loading branch information
dioh committed May 14, 2014
2 parents 77dcb07 + 1f0e6a4 commit 9dfa9ad
Show file tree
Hide file tree
Showing 32 changed files with 2,247 additions and 855 deletions.
26 changes: 26 additions & 0 deletions gui/customevents.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"""

import time

LOGEVENT_ID = 3131
SHOWDIALOG_ID = 3132
Expand All @@ -24,16 +25,23 @@
WORKSPACE_CHANGED = 3140
CONFLICT_UPDATE = 3141
RESOLVECONFLICTS_ID = 3142
ADDHOST = 4100
DELHOST = 4101
EDITHOST = 4102
UPDATEMODEL_ID = 54321


class CustomEvent(object):
def __init__(self, type):
self._type = type
self._time = time.time()

def type(self):
return self._type

def time(self):
return self._time


class LogCustomEvent(CustomEvent):
def __init__(self, text):
Expand Down Expand Up @@ -102,3 +110,21 @@ class ModelObjectUpdateEvent(CustomEvent):
def __init__(self, hosts):
CustomEvent.__init__(self, UPDATEMODEL_ID)
self.hosts = hosts


class AddHostCustomEvent(CustomEvent):
def __init__(self, host):
CustomEvent.__init__(self, ADDHOST)
self.host = host


class EditHostCustomEvent(CustomEvent):
def __init__(self, host):
CustomEvent.__init__(self, EDITHOST)
self.host = host


class DeleteHostCustomEvent(CustomEvent):
def __init__(self, host_id):
CustomEvent.__init__(self, DELHOST)
self.host_id = host_id
4 changes: 2 additions & 2 deletions gui/gui_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def create(model_controller, plugin_manager, workspace_manager, gui="gtk"):


class FaradayUi(object):
def __init__(self, model_controller, plugin_manager,
workspace_manager, gui="qt3"):
def __init__(self, model_controller=None, plugin_manager=None,
workspace_manager=None, gui="qt3"):
#self.main_app = main_app
self.model_controller = model_controller
self.plugin_manager = plugin_manager
Expand Down
70 changes: 70 additions & 0 deletions gui/notifier.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env python
'''
Faraday Penetration Test IDE - Community Version
Copyright (C) 2013 Infobyte LLC (http://www.infobytesec.com/)
See the file 'doc/LICENSE' for the license information
'''
import threading
from gui.gui_app import FaradayUi
import gui.customevents as events


class NotificationCenter():
def __init__(self, uiapp=FaradayUi()):
self.uiapp = uiapp
self._consumers = []
self._consumers_lock = threading.RLock()
self.last_events = {}

def setUiApp(self, uiapp):
self.uiapp = uiapp

def registerWidget(self, consumer):
self._consumers_lock.acquire()
if consumer not in self._consumers:
self._consumers.append(consumer)
self._consumers_lock.release()

def deregisterWidget(self, consumer):
self._consumers_lock.acquire()
if consumer in self._consumers:
self._consumers.remove(consumer)
self._consumers_lock.release()

def postCustomEvent(self, event, receiver=None):
if self.last_events.get(event.type(), None):
if self.last_events[event.type()] > event.time():
return
self.last_events[event.type()] = event.time()
self.uiapp.postEvent(receiver, event)

def _notifyWidgets(self, event):
self._consumers_lock.acquire()
for w in self._consumers:
self.postCustomEvent(event, w)
self._consumers_lock.release()

def showPopup(self, msg):
self._notifyWidgets(events.ShowPopupCustomEvent(msg))

def workspaceLoad(self, hosts):
self._notifyWidgets(events.ModelObjectUpdateEvent(hosts))

def workspaceChanged(self, workspace):
self._notifyWidgets(events.WorkspaceChangedCustomEvent(workspace))

def addHost(self, host):
self._notifyWidgets(events.AddHostCustomEvent(host))

def delHost(self, host_id):
self._notifyWidgets(events.DeleteHostCustomEvent(host_id))

def editHost(self, host):
self._notifyWidgets(events.EditHostCustomEvent(host))

def conflictUpdate(self, vulns_changed):
self._notifyWidgets(events.ConflictUpdatedCustomEvent(vulns_changed))

def conflictResolution(self, conflicts):
self._notifyWidgets(events.ResolveConflictsCustomEvent(conflicts))
3 changes: 3 additions & 0 deletions gui/qt3/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
'''

import os
import traceback

try:
import qt
Expand Down Expand Up @@ -92,6 +93,8 @@ def quit(self):
qt.QApplication.quit(self)

def postEvent(self, receiver, event):
if receiver is None:
receiver = self.getMainWindow()
qt.QApplication.postEvent(receiver, QtCustomEvent.create(event))

def createShellEnvironment(self, name=None):
Expand Down
30 changes: 24 additions & 6 deletions gui/qt3/customevents.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
EXCEPTION_ID, RENAMEHOSTSROOT_ID,
CLEARHOSTS_ID, DIFFHOSTS_ID, SYNCFAILED_ID,
CONFLICTS_ID, WORKSPACE_CHANGED, CONFLICT_UPDATE,
RESOLVECONFLICTS_ID, UPDATEMODEL_ID)
RESOLVECONFLICTS_ID, UPDATEMODEL_ID, ADDHOST,
EDITHOST, DELHOST)


class LogCustomEvent(qt.QCustomEvent):
Expand Down Expand Up @@ -87,6 +88,24 @@ def __init__(self, e):
self.hosts = e.hosts


class AddHostCustomEvent(qt.QCustomEvent):
def __init__(self, e):
qt.QCustomEvent.__init__(self, e.type())
self.host = e.host


class EditHostCustomEvent(qt.QCustomEvent):
def __init__(self, e):
qt.QCustomEvent.__init__(self, e.type())
self.host = e.host


class DeleteHostCustomEvent(qt.QCustomEvent):
def __init__(self, e):
qt.QCustomEvent.__init__(self, e.type())
self.host_id = e.host_id


class QtCustomEvent(qt.QCustomEvent):
events = {
LOGEVENT_ID: LogCustomEvent,
Expand All @@ -101,13 +120,12 @@ class QtCustomEvent(qt.QCustomEvent):
WORKSPACE_CHANGED: WorkspaceChangedCustomEvent,
CONFLICT_UPDATE: ConflictUpdatedCustomEvent,
RESOLVECONFLICTS_ID: ResolveConflictsCustomEvent,
UPDATEMODEL_ID: ModelObjectUpdateEvent
UPDATEMODEL_ID: ModelObjectUpdateEvent,
ADDHOST: AddHostCustomEvent,
DELHOST: DeleteHostCustomEvent,
EDITHOST: EditHostCustomEvent
}

@staticmethod
def create(custom_event):
return QtCustomEvent.events[custom_event.type()](custom_event)


# def create(custom_event):
# pass
61 changes: 36 additions & 25 deletions gui/qt3/hostsbrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,14 +410,7 @@ def load(self, workspace):
def update(self, hosts):
self.clearTree()
self.redrawTree(hosts)









def sizeHint(self):
"""Returns recommended size of dialog."""
return qt.QSize(70, 200)
Expand Down Expand Up @@ -457,26 +450,16 @@ def _clearBranch(self, root):
self._delHostFromCategory(i.object, category_item.name)

def redrawTree(self, hosts):




for host in hosts:

category = host.getCurrentCategory()
self._addCategory(category)
self._addHostToCategory(host, category)

for ci in self._category_items.values():
ci.setOpen(True)
self.createIndex(hosts)
self.filterTree(self._filter)








def filterTree(self, mfilter=""):
hosts=[]
viewall=False
Expand Down Expand Up @@ -603,9 +586,6 @@ def selectWord(self, word):
self.listview.setSelected(host_item, True)
self.listview.ensureItemVisible(host_item)
break




def workspaceChanged(self, workspace):
if self.rootitem:
Expand Down Expand Up @@ -677,13 +657,34 @@ def _addCategory(self, category):
ref = self._getCategoryListViewItem(category)
return ref

def _addHost(self, host):
category = host.getCurrentCategory()
self._addCategory(category)
self._addHostToCategory(host, category)

def _removeHost(self, host_id):
item = self._host_items.get(host_id, None)
if host_id in self._host_items:
del self._host_items[host_id]
for category in self._category_tree.keys():
if host_id in self._category_tree.get(category):
self._category_tree[category].remove(host_id)
category_item = self._getCategoryListViewItem(category)
try:
category_item.takeItem(item)
except Exception:
api.devlog("Exception taking item from category")

def _editHost(self, host):
self._removeHost(host.getID())
self._addHost(host)

def _addHostToCategory(self, host, category):
category_item = self._addCategory(category)
self._host_items[host.getID()] = HostListViewItem(category_item, host.name, host)
self._category_tree[category].append(host.getID())

def _delHostFromCategory(self, host, category):

id = host.getID()
item = self._host_items.get(id, None)
if id in self._host_items:
Expand Down Expand Up @@ -1064,7 +1065,7 @@ def _modelObjectViewUpdater(self):

def customEvent(self, event):
if event.type() == UPDATEMODEL_ID:
self.__pendingModelObjectRedraws.append(event)
self.__pendingModelObjectRedraws.append(event)

elif event.type() == RENAMEHOSTSROOT_ID:
self.renameRootItem(event.name)
Expand All @@ -1084,6 +1085,16 @@ def customEvent(self, event):
elif event.type() == RESOLVECONFLICTS_ID:
self.showResolveConflictDialog(event.conflicts)

elif event.type() == ADDHOST:
self._addHost(event.host)

elif event.type() == DELHOST:
self._removeHost(event.host_id)

elif event.type() == EDITHOST:
self._editHost(event.host)


def _setupContextPopups(self):
"""
Configures a context popup menu for each kind of item shown in the tree.
Expand Down
4 changes: 3 additions & 1 deletion gui/qt3/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from gui.qt3.configdialog import ConfigDialog
from gui.qt3.toolbars import *
from gui.qt3.customevents import *
from model.guiapi import notification_center as notifier
from managers.all import PersistenceManagerFactory, CouchdbManager


Expand Down Expand Up @@ -73,7 +74,8 @@ def __init__(self, title, main_app, model_controller, plugin_manager):


self._hosts_treeview = HostsBrowser(self._perspective_manager,"Hosts")
self._model_controller.registerWidget(self._hosts_treeview)
notifier.registerWidget(self._hosts_treeview)

self._perspective_manager.registerPerspective(self._hosts_treeview, default=True)


Expand Down
Loading

0 comments on commit 9dfa9ad

Please sign in to comment.