Package vivisect :: Package qt :: Module remote
[hide private]
[frames] | no frames]

Source Code for Module vivisect.qt.remote

  1  from PyQt4 import Qt, QtCore, QtGui 
  2   
  3  import vqt.main as vq_main 
  4  import vqt.tree as vq_tree 
  5   
  6  import envi.threads as e_threads 
  7  import cobra.remoteapp as c_remoteapp 
  8  import vivisect.remote.server as viv_server 
  9   
 10  from vqt.basics import * 
11 12 -class WorkspaceListModel(vq_tree.VQTreeModel):
13 columns = ('Name',)
14
15 -class WorkspaceListView(vq_tree.VQTreeView):
16 - def __init__(self, workspaces, parent=None):
17 vq_tree.VQTreeView.__init__(self, parent=parent) 18 model = WorkspaceListModel(parent=self) 19 self.setModel(model) 20 for wsname in workspaces: 21 model.append((wsname,))
22
23 -class VivServerDialog(QtGui.QDialog):
24
25 - def __init__(self, workspaces, parent=None):
26 QtGui.QDialog.__init__(self, parent=parent) 27 self.setWindowTitle('Select a workspace...') 28 29 self.wsname = None 30 self.wslist = WorkspaceListView(workspaces, parent=self) 31 32 self.buttons = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Cancel) 33 self.buttons.accepted.connect( self.accept ) 34 self.buttons.rejected.connect( self.reject ) 35 36 layout = VBox() 37 layout.addWidget(self.wslist) 38 layout.addWidget(self.buttons) 39 self.setLayout(layout) 40 41 self.wslist.doubleClicked.connect( self.workspaceActivated )
42
43 - def getWorkspaceName(self):
44 self.exec_() 45 return self.wsname
46
47 - def workspaceActivated(self, idx):
48 self.accept()
49
50 - def accept(self):
51 for idx in self.wslist.selectedIndexes(): 52 row = idx.internalPointer() 53 if row: 54 self.wsname = row.rowdata[0] 55 break 56 57 return QtGui.QDialog.accept(self)
58
59 -class VivSaveServerDialog(QtGui.QDialog):
60
61 - def __init__(self, vw, parent=None):
62 QtGui.QDialog.__init__(self, parent=parent) 63 self.setWindowTitle('Save to Workspace Server...') 64 65 self.wsname = QtGui.QLineEdit(vw.getMeta('StorageName',''), parent=self) 66 self.wsserver = QtGui.QLineEdit('visi.kenshoto.com',parent=self) 67 68 self.buttons = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Cancel) 69 self.buttons.accepted.connect( self.accept ) 70 self.buttons.rejected.connect( self.reject ) 71 72 layout = QtGui.QFormLayout() 73 layout.addRow('Workspace Name', self.wsname) 74 layout.addRow('Workspace Server', self.wsserver) 75 layout.addWidget(self.buttons) 76 self.setLayout(layout)
77
78 - def getNameAndServer(self):
79 if not self.exec_(): 80 return (None,None) 81 wsname = str(self.wsname.text()) 82 wsserver = str(self.wsserver.text()) 83 return (wsname,wsserver)
84
85 @vq_main.idlethread 86 -def openServerAndWorkspace(vw, parent=None):
87 host, ok = QtGui.QInputDialog.getText(parent, 'Workspace Server...', 'hostname/ip', text='visi.kenshoto.com') 88 if not ok: 89 return 90 91 connServerAndWorkspace(vw, str(host), parent=parent)
92
93 @vq_main.workthread 94 -def connServerAndWorkspace(vw, host,parent=None):
95 # NOTE: do *not* touch parent (or qt) in here! 96 try: 97 server = viv_server.connectToServer(host) 98 wslist = server.listWorkspaces() 99 selectServerWorkspace(vw, server, wslist, parent=parent) 100 except Exception, e: 101 vw.vprint('Server Error: %s' % e) 102 return
103
104 @vq_main.idlethread 105 -def selectServerWorkspace(vw, server, workspaces, parent=None):
106 dia = VivServerDialog(workspaces, parent=parent) 107 workspace = dia.getWorkspaceName() 108 if workspace == None: 109 return 110 111 loadServerWorkspace(vw, server, workspace)
112
113 @vq_main.workthread 114 -def loadServerWorkspace(oldvw, server, workspace):
115 oldvw.vprint('Loading Workspace: %s' % workspace) 116 vw = viv_server.getServerWorkspace(server, workspace) 117 import vivisect.qt.main as viv_q_main 118 viv_q_main.runqt(vw, closeme=oldvw.getVivGui())
119
120 @vq_main.idlethread 121 -def saveToServer(vw, parent=None):
122 dia = VivSaveServerDialog(vw, parent=parent) 123 wsname,wsserver = dia.getNameAndServer() 124 vw.vprint('Saving to Workspace Server: %s (%s)' % (wsserver,wsname)) 125 sendServerWorkspace(vw, wsname, wsserver)
126
127 @e_threads.firethread 128 -def sendServerWorkspace(vw, wsname, wsserver):
129 try: 130 events = vw.exportWorkspace() 131 server = viv_server.connectToServer(wsserver) 132 server.addNewWorkspace(wsname, events) 133 except Exception, e: 134 vw.vprint('Workspace Server Error: %s' % e) 135 return 136 137 vw.setMeta('WorkspaceServer', wsserver)
138
139 -def openSharedWorkspace(vw, parent=None):
140 ''' 141 Open a workspace shared by a vivisect peer. 142 ''' 143 hostport, ok = QtGui.QInputDialog.getText(parent, 'Shared Workspace...', 'host:port') 144 if not ok: 145 return 146 147 uri = 'cobra://%s/vivisect.remote.client?msgpack=1' % hostport 148 c_remoteapp.execRemoteApp(uri)
149