1.1 --- a/OpenSecurity/bin/opensecurity_client_restful_server.py Thu Jun 12 12:47:43 2014 +0200
1.2 +++ b/OpenSecurity/bin/opensecurity_client_restful_server.py Thu Jun 12 14:08:36 2014 +0200
1.3 @@ -57,6 +57,8 @@
1.4 import itertools
1.5 import ctypes
1.6
1.7 +from PyQt4 import QtGui
1.8 +
1.9 from opensecurity_util import logger, setupLogger, OpenSecurityException
1.10 if sys.platform == 'win32' or sys.platform == 'cygwin':
1.11 from cygwin import Cygwin
1.12 @@ -75,6 +77,7 @@
1.13 '/credentials', 'os_credentials',
1.14 '/keyfile', 'os_keyfile',
1.15 '/log', 'os_log',
1.16 + '/message', 'os_message',
1.17 '/notification', 'os_notification',
1.18 '/password', 'os_password',
1.19 '/netmount', 'os_netmount',
1.20 @@ -94,11 +97,13 @@
1.21 """timer for the log file bouncer"""
1.22 log_file_bouncer = None
1.23
1.24 -
1.25 """The REST server object"""
1.26 server = None
1.27
1.28
1.29 +"""The System Tray Icon instance"""
1.30 +tray_icon = None
1.31 +
1.32 # ------------------------------------------------------------
1.33 # code
1.34
1.35 @@ -199,6 +204,40 @@
1.36 return "Ok"
1.37
1.38
1.39 +class os_message:
1.40 +
1.41 + """OpenSecurity '/message' handler.
1.42 +
1.43 + This is called on GET /message?text=TEXTi&timeout=TIMEOUT.
1.44 + This pops up the typical tray message (like a ballon on windows).
1.45 + """
1.46 +
1.47 + def POST(self):
1.48 + return self.GET()
1.49 +
1.50 + def GET(self):
1.51 +
1.52 + # pick the arguments
1.53 + args = web.input()
1.54 +
1.55 + # we _need_ a text
1.56 + if not "text" in args:
1.57 + raise web.badrequest('no text given')
1.58 +
1.59 + timeout = 5000
1.60 + if "timeout" in args:
1.61 + try:
1.62 + timeout=int(args.timeout)
1.63 + except:
1.64 + pass
1.65 +
1.66 + if tray_icon is None:
1.67 + raise web.badrequest('unable to access tray icon instance')
1.68 +
1.69 + tray_icon.showMessage('OpenSecurity', args.text, QtGui.QSystemTrayIcon.Information, timeout)
1.70 + return 'Shown: ' + args.text + ' timeout: ' + str(timeout) + ' ms'
1.71 +
1.72 +
1.73 class os_notification:
1.74
1.75 """OpenSecurity '/notification' handler.
1.76 @@ -266,6 +305,8 @@
1.77
1.78 return 'user queried for password'
1.79
1.80 +
1.81 +
1.82 def genNetworkDrive():
1.83 logical_drives = getLogicalDrives()
1.84 logger.info("Used logical drive letters: "+ str(logical_drives).strip('[]') )
2.1 --- a/OpenSecurity/bin/opensecurity_tray.pyw Thu Jun 12 12:47:43 2014 +0200
2.2 +++ b/OpenSecurity/bin/opensecurity_tray.pyw Thu Jun 12 14:08:36 2014 +0200
2.3 @@ -105,12 +105,7 @@
2.4 if not (sys.platform == 'win32' or sys.platform == 'cygwin'):
2.5 QtGui.QMessageBox.critical(self.parent(), 'OpenSecurity Error', 'This action is not supported on this platform.\nSorry.')
2.6 return
2.7 -
2.8 - # tell the user to wait
2.9 - d = OpenSecurityWait()
2.10 - d.show()
2.11 - QtGui.QApplication.instance().processEvents()
2.12 -
2.13 +
2.14 try:
2.15
2.16 # get a proper browsing VM
2.17 @@ -126,7 +121,6 @@
2.18 QtGui.QApplication.instance().processEvents()
2.19 QtGui.QMessageBox.critical(None, 'Failed to invoke Safe Internet Browsing', 'OpenSecurity Error')
2.20
2.21 - d.hide()
2.22 QtGui.QApplication.instance().processEvents()
2.23
2.24
2.25 @@ -247,6 +241,7 @@
2.26 icon = QtGui.QIcon()
2.27 icon.addPixmap(QtGui.QPixmap(QtCore.QString.fromUtf8(":/opensecurity/gfx/opensecurity_icon_64.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
2.28 trayIcon = OpenSecurityTrayIcon(icon)
2.29 + opensecurity_client_restful_server.tray_icon = trayIcon
2.30
2.31 # go!
2.32 trayIcon.show()
3.1 --- a/OpenSecurity/bin/opensecurity_util.py Thu Jun 12 12:47:43 2014 +0200
3.2 +++ b/OpenSecurity/bin/opensecurity_util.py Thu Jun 12 14:08:36 2014 +0200
3.3 @@ -3,6 +3,8 @@
3.4
3.5 import logging
3.6 import os
3.7 +import urllib
3.8 +import urllib2
3.9
3.10
3.11 # local
3.12 @@ -54,11 +56,29 @@
3.13
3.14 logger = setupLogger()
3.15
3.16 +
3.17 +def showTrayMessage(text, timeout):
3.18 + """show a message on the system tray
3.19 +
3.20 + On windows this is shown like a ballon message.
3.21 +
3.22 + @param text the text to show
3.23 + @param timeout timeout hint in millisecs for the message
3.24 +
3.25 + """
3.26 + try:
3.27 + d = { 'text': str(text), 'timeout': int(timeout) }
3.28 + urllib2.urlopen('http://127.0.0.1:8090/message?' + urllib.urlencode(d))
3.29 + except:
3.30 + pass
3.31 +
3.32 +
3.33 # test method
3.34 def test():
3.35
3.36 """Test: OpenSecurity logging"""
3.37 logger.info('test logging')
3.38 + showTrayMessage('tray message test\nwith mutliple lines', 1000)
3.39
3.40
3.41 # test the module
4.1 --- a/OpenSecurity/bin/opensecurityd.pyw Thu Jun 12 12:47:43 2014 +0200
4.2 +++ b/OpenSecurity/bin/opensecurityd.pyw Thu Jun 12 14:08:36 2014 +0200
4.3 @@ -46,7 +46,8 @@
4.4 import __init__ as opensecurity
4.5 from cygwin import Cygwin
4.6 from environment import Environment
4.7 -from opensecurity_util import logger
4.8 +from opensecurity_util import logger, showTrayMessage
4.9 +
4.10
4.11
4.12 # ------------------------------------------------------------
4.13 @@ -258,6 +259,7 @@
4.14 log_call(web.ctx.environ)
4.15 global gvm_mgr
4.16 command = '/' + command
4.17 + showTrayMessage('Launching application in isolated VM...', 7000)
4.18 result = Cygwin.sshExecuteX11(command, gvm_mgr.getHostOnlyIP(name), 'osecuser', Cygwin.cygPath(gvm_mgr.getMachineFolder()) + '/' + name + '/dvm_key' )
4.19 return 'Command ' + str(command) + ' started on VM "' + name + '" with IP ' + gvm_mgr.getHostOnlyIP(name)
4.20
5.1 --- a/OpenSecurity/bin/vmmanager.pyw Thu Jun 12 12:47:43 2014 +0200
5.2 +++ b/OpenSecurity/bin/vmmanager.pyw Thu Jun 12 14:08:36 2014 +0200
5.3 @@ -18,7 +18,7 @@
5.4 import shutil
5.5 import stat
5.6 import tempfile
5.7 -from opensecurity_util import logger, setupLogger, OpenSecurityException
5.8 +from opensecurity_util import logger, setupLogger, OpenSecurityException, showTrayMessage
5.9 import ctypes
5.10 import itertools
5.11 import win32api
5.12 @@ -636,6 +636,7 @@
5.13
5.14 # handles browsing request
5.15 def handleBrowsingRequest(self):
5.16 + showTrayMessage('Starting Secure Browsing...', 7000)
5.17 handler = BrowsingHandler(self)
5.18 handler.start()
5.19 return 'ok'
5.20 @@ -823,6 +824,7 @@
5.21 time.sleep(3)
5.22 continue
5.23
5.24 + showTrayMessage('System changed.\nEvaluating...', 7000)
5.25 logger.info("Something's changed")
5.26 tmp_attached = self.attachedRSDs
5.27 for vm_name in tmp_attached.keys():
5.28 @@ -848,6 +850,7 @@
5.29 #create new vms for new devices if any
5.30 new_ip = None
5.31 for new_device in tmp_rsds.values():
5.32 + showTrayMessage('Mounting device...', 7000)
5.33 if (self.attachedRSDs and False) or (new_device not in self.attachedRSDs.values()):
5.34 new_sdvm = self.vmm.newSDVM()
5.35 self.vmm.storageAttach(new_sdvm)