2 # -*- coding: utf-8 -*-
4 # ------------------------------------------------------------
7 # an opensecurity dialog
9 # Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
11 # Copyright (C) 2013 AIT Austrian Institute of Technology
12 # AIT Austrian Institute of Technology GmbH
13 # Donau-City-Strasse 1 | 1220 Vienna | Austria
14 # http://www.ait.ac.at
16 # This program is free software; you can redistribute it and/or
17 # modify it under the terms of the GNU General Public License
18 # as published by the Free Software Foundation version 2.
20 # This program is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 51 Franklin Street, Fifth Floor,
28 # Boston, MA 02110-1301, USA.
29 # ------------------------------------------------------------
32 # ------------------------------------------------------------
41 from PyQt4 import QtCore
42 from PyQt4 import QtGui
45 from about import About
46 from environment import Environment
49 # ------------------------------------------------------------
53 class OpenSecurityWait(QtGui.QDialog):
55 """OpenSecurity: please wait ..."""
57 def __init__(self, parent = None, flags = QtCore.Qt.WindowFlags(0)):
58 super(OpenSecurityWait, self).__init__(parent, flags)
59 self.setWindowTitle('OpenSecurity')
64 """Create the widgets."""
66 lyMain = QtGui.QVBoxLayout(self)
67 lyMain.setContentsMargins(8, 8, 8, 8)
69 # content area: left pixmap, right text
70 lbTitle = QtGui.QLabel('Creating secure subsystem. Please stand by ...')
71 lyMain.addWidget(lbTitle)
73 self.setMinimumSize(400, 50)
74 self.resize(lyMain.minimumSize())
77 class OpenSecurityTrayIcon(QtGui.QSystemTrayIcon):
79 """This is the OpenSecuirty Tray Icon"""
81 def __init__(self, icon, parent=None):
83 super(OpenSecurityTrayIcon, self).__init__(icon, parent)
87 def clicked_about(self):
93 def clicked_browser(self):
94 """wish for safe internet browsing"""
96 # TODO: HARDCODED ADDRESS OF OPENSECURITYD
98 # tell the user to wait
99 dlg = OpenSecurityWait()
101 QtGui.QApplication.instance().processEvents()
105 # get a proper browsing VM
106 browsing_vm = urllib2.urlopen('http://127.0.0.1:8080/browsing').readline()
107 dlg_launch_image = os.path.join(sys.path[0], 'launch.pyw')
108 process_command = [sys.executable, dlg_launch_image, browsing_vm, '/usr/bin/iceweasel']
109 print(process_command)
110 process = subprocess.Popen(process_command, shell = False)
114 QtGui.QApplication.instance().processEvents()
115 QtGui.QMessageBox.critical(None, 'Failed to invoke Safe Internet Browsing', 'OpenSecurity Error')
118 QtGui.QApplication.instance().processEvents()
121 def clicked_exit(self):
126 def clicked_launch_application(self):
127 """clicked the launch an application"""
128 dlg_launch_image = os.path.join(sys.path[0], 'launch.pyw')
129 process_command = [sys.executable, dlg_launch_image]
130 print(process_command)
131 process = subprocess.Popen(process_command, shell = False)
132 process.communicate()
135 def clicked_refresh(self):
136 """clicked refresh"""
141 """create the user interface
142 As for the system tray this is 'just' the context menu.
145 # define the tray icon menu
146 menu = QtGui.QMenu(self.parent())
147 self.setContextMenu(menu)
150 cAcBrowser = menu.addAction(QtGui.QIcon(QtGui.QPixmapCache.find('opensecurity_icon_64')), 'Safe Internet Browsing')
153 # add standard menu items
154 cAcLaunch = menu.addAction(QtGui.QIcon(QtGui.QPixmapCache.find('opensecurity_icon_64')), 'Lauch Application')
156 cAcRefresh = menu.addAction('Refresh')
157 cAcAbout = menu.addAction("About")
158 cAcExit = menu.addAction("Exit")
160 cAcBrowser.triggered.connect(self.clicked_browser)
161 cAcLaunch.triggered.connect(self.clicked_launch_application)
162 cAcRefresh.triggered.connect(self.clicked_refresh)
163 cAcAbout.triggered.connect(self.clicked_about)
164 cAcExit.triggered.connect(self.clicked_exit)
169 app = QtGui.QApplication(sys.argv)
171 # prebuild the pixmap cache: fetch all jpg, png and jpeg images and load them
172 image_path = os.path.join(Environment("OpenSecurity").data_path, '..', 'gfx')
173 for file in os.listdir(image_path):
174 if file.lower().rpartition('.')[2] in ('jpg', 'png', 'jpeg'):
175 QtGui.QPixmapCache.insert(file.lower().rpartition('.')[0], QtGui.QPixmap(os.path.join(image_path, file)))
178 trayIcon = OpenSecurityTrayIcon(QtGui.QIcon(QtGui.QPixmapCache.find('opensecurity_icon_64')), w)
181 app.setQuitOnLastWindowClosed(False)
182 sys.exit(app.exec_())
186 if __name__ == "__main__":