OpenSecurity/bin/opensecurity_client_restful_server.py added join to wait for netmount /umount thread finish
1 # -*- coding: utf-8 -*-
3 # ------------------------------------------------------------
6 # an opensecurity dialog
8 # Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
10 # Copyright (C) 2013 AIT Austrian Institute of Technology
11 # AIT Austrian Institute of Technology GmbH
12 # Donau-City-Strasse 1 | 1220 Vienna | Austria
13 # http://www.ait.ac.at
15 # This program is free software; you can redistribute it and/or
16 # modify it under the terms of the GNU General Public License
17 # as published by the Free Software Foundation version 2.
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the Free Software
26 # Foundation, Inc., 51 Franklin Street, Fifth Floor,
27 # Boston, MA 02110-1301, USA.
28 # ------------------------------------------------------------
31 # ------------------------------------------------------------
42 from PyQt4 import QtCore
43 from PyQt4 import QtGui
46 import __init__ as opensecurity
48 if sys.platform == 'win32' or sys.platform == 'cygwin':
49 from cygwin import Cygwin
51 import opensecurity_client_restful_server
52 from ui import AboutDialog
53 from ui import ConfigureDialog
54 from ui import opensecurity_rc
57 # ------------------------------------------------------------
61 class OpenSecurityWait(QtGui.QDialog):
63 """OpenSecurity: please wait ..."""
65 def __init__(self, parent = None, flags = QtCore.Qt.WindowFlags(0)):
66 super(OpenSecurityWait, self).__init__(parent, flags)
67 self.setWindowTitle('OpenSecurity')
72 """Create the widgets."""
74 lyMain = QtGui.QVBoxLayout(self)
75 lyMain.setContentsMargins(8, 8, 8, 8)
77 # content area: left pixmap, right text
78 lbTitle = QtGui.QLabel('Creating secure subsystem. Please stand by ...')
79 lyMain.addWidget(lbTitle)
81 self.setMinimumSize(400, 50)
82 self.resize(lyMain.minimumSize())
85 class OpenSecurityTrayIcon(QtGui.QSystemTrayIcon):
87 """This is the OpenSecuirty Tray Icon"""
89 def __init__(self, icon, parent=None):
91 super(OpenSecurityTrayIcon, self).__init__(icon, parent)
95 def clicked_about(self):
101 def clicked_browser(self):
102 """wish for safe internet browsing"""
104 if not (sys.platform == 'win32' or sys.platform == 'cygwin'):
105 QtGui.QMessageBox.critical(self.parent(), 'OpenSecurity Error', 'This action is not supported on this platform.\nSorry.')
108 # tell the user to wait
109 d = OpenSecurityWait()
111 QtGui.QApplication.instance().processEvents()
115 # get a proper browsing VM
118 # TODO: HARDCODED ADDRESS OF OPENSECURITYD
119 browsing_vm = urllib2.urlopen('http://127.0.0.1:8080/browsing').readline()
123 QtGui.QApplication.instance().processEvents()
124 QtGui.QMessageBox.critical(None, 'Failed to invoke Safe Internet Browsing', 'OpenSecurity Error')
127 QtGui.QApplication.instance().processEvents()
130 def clicked_configure(self):
131 """clicked configure"""
132 d = ConfigureDialog()
136 def clicked_exit(self):
138 opensecurity_client_restful_server.stop()
142 def clicked_launch_application(self):
143 """clicked the launch an application"""
144 dlg_launch_image = os.path.join(sys.path[0], 'ui', 'launch_dialog.py')
145 process_command = [sys.executable, dlg_launch_image]
146 print(process_command)
147 process = subprocess.Popen(process_command, shell = False)
150 def clicked_mail(self):
153 address = 'feedback@opensecurity.at'
154 subject = 'Feedback zu OpenSecurity V' + opensecurity.__version__
156 if sys.platform == 'linux2':
157 subprocess.Popen(['xdg-email', '--subject', subject, address])
158 elif sys.platform == 'win32' or sys.platform == 'cygwin':
159 mail_url = 'mailto:' + urllib.quote(address, '@') + '?' + urllib.quote('subject=' + subject)
160 subprocess.Popen(['cmd', '/C', 'start', mail_url])
164 """create the user interface
165 As for the system tray this is 'just' the context menu.
168 # define the tray icon menu
169 menu = QtGui.QMenu(self.parent())
170 self.setContextMenu(menu)
173 self.acBrowser = QtGui.QAction('Secure Browsing', self.parent())
175 icon.addPixmap(QtGui.QPixmap(QtCore.QString.fromUtf8(':/opensecurity/gfx/opensecurity_browsing_64.png')), QtGui.QIcon.Normal, QtGui.QIcon.Off)
176 self.acBrowser.setIcon(icon)
177 menu.addAction(self.acBrowser)
180 # add standard menu items
181 self.acLaunch = QtGui.QAction('Launch Application', self.parent())
183 icon.addPixmap(QtGui.QPixmap(QtCore.QString.fromUtf8(':/opensecurity/gfx/opensecurity_launch_64.png')), QtGui.QIcon.Normal, QtGui.QIcon.Off)
184 self.acLaunch.setIcon(icon)
185 menu.addAction(self.acLaunch)
186 self.acConfigure = QtGui.QAction('Configuration', self.parent())
188 icon.addPixmap(QtGui.QPixmap(QtCore.QString.fromUtf8(':/opensecurity/gfx/opensecurity_configure_64.png')), QtGui.QIcon.Normal, QtGui.QIcon.Off)
189 self.acConfigure.setIcon(icon)
190 menu.addAction(self.acConfigure)
193 self.acMail = menu.addAction('Send feedback mail')
195 icon.addPixmap(QtGui.QPixmap(QtCore.QString.fromUtf8(':/opensecurity/gfx/opensecurity_mail_64.png')), QtGui.QIcon.Normal, QtGui.QIcon.Off)
196 self.acMail.setIcon(icon)
197 self.acAbout = menu.addAction('About')
198 self.acExit = menu.addAction('Exit')
200 self.acBrowser.triggered.connect(self.clicked_browser)
201 self.acLaunch.triggered.connect(self.clicked_launch_application)
202 self.acConfigure.triggered.connect(self.clicked_configure)
203 self.acAbout.triggered.connect(self.clicked_about)
204 self.acExit.triggered.connect(self.clicked_exit)
205 self.acMail.triggered.connect(self.clicked_mail)
211 parser = argparse.ArgumentParser(description = 'OpenSecurity Tray Icon.')
212 parser.add_argument('-p', '--port', type=int, default=8090, help='port number of the REST API this instance will listen on.')
213 args = parser.parse_args()
216 a = QtGui.QApplication(sys.argv)
218 # enforce singelton process
219 if opensecurity_client_restful_server.is_already_running(args.port):
220 QtGui.QMessageBox.critical(None, 'OpenSecurity Error', 'OpenSecurity Tray Instance already launched.\nClose previous instance first.')
224 opensecurity_client_restful_server.serve(args.port, True)
226 # init tray icon widget
229 icon.addPixmap(QtGui.QPixmap(QtCore.QString.fromUtf8(":/opensecurity/gfx/opensecurity_icon_64.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
230 trayIcon = OpenSecurityTrayIcon(icon)
234 a.setQuitOnLastWindowClosed(False)
239 if __name__ == "__main__":