om@13
|
1 |
#!/bin/env python
|
om@13
|
2 |
# -*- coding: utf-8 -*-
|
om@13
|
3 |
|
om@13
|
4 |
# ------------------------------------------------------------
|
om@13
|
5 |
# opensecurity-dialog
|
om@13
|
6 |
#
|
om@13
|
7 |
# an opensecurity dialog
|
om@13
|
8 |
#
|
om@13
|
9 |
# Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
|
om@13
|
10 |
#
|
om@13
|
11 |
# Copyright (C) 2013 AIT Austrian Institute of Technology
|
om@13
|
12 |
# AIT Austrian Institute of Technology GmbH
|
om@13
|
13 |
# Donau-City-Strasse 1 | 1220 Vienna | Austria
|
om@13
|
14 |
# http://www.ait.ac.at
|
om@13
|
15 |
#
|
om@13
|
16 |
# This program is free software; you can redistribute it and/or
|
om@13
|
17 |
# modify it under the terms of the GNU General Public License
|
om@13
|
18 |
# as published by the Free Software Foundation version 2.
|
om@13
|
19 |
#
|
om@13
|
20 |
# This program is distributed in the hope that it will be useful,
|
om@13
|
21 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
om@13
|
22 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
om@13
|
23 |
# GNU General Public License for more details.
|
om@13
|
24 |
#
|
om@13
|
25 |
# You should have received a copy of the GNU General Public License
|
om@13
|
26 |
# along with this program; if not, write to the Free Software
|
om@13
|
27 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
om@13
|
28 |
# Boston, MA 02110-1301, USA.
|
om@13
|
29 |
# ------------------------------------------------------------
|
om@13
|
30 |
|
om@13
|
31 |
|
om@13
|
32 |
# ------------------------------------------------------------
|
om@13
|
33 |
# imports
|
om@13
|
34 |
|
om@13
|
35 |
import argparse
|
om@13
|
36 |
import os
|
om@13
|
37 |
import subprocess
|
om@13
|
38 |
import sys
|
om@13
|
39 |
|
om@13
|
40 |
from PyQt4 import QtCore
|
om@13
|
41 |
from PyQt4 import QtGui
|
om@13
|
42 |
|
om@13
|
43 |
# local
|
om@13
|
44 |
from about import About
|
om@13
|
45 |
from environment import Environment
|
om@13
|
46 |
|
om@13
|
47 |
|
om@13
|
48 |
# ------------------------------------------------------------
|
om@13
|
49 |
# code
|
om@13
|
50 |
|
om@13
|
51 |
|
om@13
|
52 |
class OpenSecurityTrayIcon(QtGui.QSystemTrayIcon):
|
om@13
|
53 |
|
om@13
|
54 |
"""This is the OpenSecuirty Tray Icon"""
|
om@13
|
55 |
|
om@13
|
56 |
def __init__(self, icon, parent=None):
|
om@13
|
57 |
|
om@13
|
58 |
super(OpenSecurityTrayIcon, self).__init__(icon, parent)
|
om@13
|
59 |
self.setup_ui()
|
om@13
|
60 |
|
om@13
|
61 |
|
om@13
|
62 |
def clicked_about(self):
|
om@13
|
63 |
"""clicked about"""
|
om@13
|
64 |
dlgAbout = About()
|
om@13
|
65 |
dlgAbout.exec_()
|
om@13
|
66 |
|
om@13
|
67 |
|
om@37
|
68 |
def clicked_browser(self):
|
om@37
|
69 |
"""wish for safe internet browsing"""
|
om@37
|
70 |
dlg_launch_image = os.path.join(sys.path[0], 'launch.pyw')
|
om@37
|
71 |
process_command = [sys.executable, dlg_launch_image, '192.168.56.101', '/usr/bin/iceweasel']
|
om@37
|
72 |
print(process_command)
|
om@37
|
73 |
process = subprocess.Popen(process_command, shell = False)
|
om@37
|
74 |
process.communicate()
|
om@37
|
75 |
|
om@37
|
76 |
|
om@13
|
77 |
def clicked_exit(self):
|
om@13
|
78 |
"""clicked exit"""
|
om@13
|
79 |
sys.exit(0)
|
om@13
|
80 |
|
om@13
|
81 |
|
om@13
|
82 |
def clicked_launch_application(self):
|
om@13
|
83 |
"""clicked the launch an application"""
|
om@13
|
84 |
dlg_launch_image = os.path.join(sys.path[0], 'launch.pyw')
|
om@13
|
85 |
process_command = [sys.executable, dlg_launch_image]
|
om@13
|
86 |
print(process_command)
|
om@13
|
87 |
process = subprocess.Popen(process_command, shell = False)
|
om@13
|
88 |
process.communicate()
|
om@13
|
89 |
|
om@13
|
90 |
|
om@13
|
91 |
def clicked_refresh(self):
|
om@13
|
92 |
"""clicked refresh"""
|
om@13
|
93 |
self.setup_ui()
|
om@13
|
94 |
|
om@13
|
95 |
|
om@13
|
96 |
def setup_ui(self):
|
om@13
|
97 |
"""create the user interface
|
om@13
|
98 |
As for the system tray this is 'just' the context menu.
|
om@13
|
99 |
"""
|
om@13
|
100 |
|
om@13
|
101 |
# define the tray icon menu
|
om@13
|
102 |
menu = QtGui.QMenu(self.parent())
|
om@13
|
103 |
self.setContextMenu(menu)
|
om@13
|
104 |
|
om@13
|
105 |
# add known apps
|
om@37
|
106 |
cAcBrowser = menu.addAction(QtGui.QIcon(QtGui.QPixmapCache.find('opensecurity_icon_64')), 'Safe Internet Browsing')
|
om@37
|
107 |
menu.addSeparator()
|
om@13
|
108 |
|
om@13
|
109 |
# add standard menu items
|
om@13
|
110 |
cAcLaunch = menu.addAction(QtGui.QIcon(QtGui.QPixmapCache.find('opensecurity_icon_64')), 'Lauch Application')
|
om@13
|
111 |
menu.addSeparator()
|
om@13
|
112 |
cAcRefresh = menu.addAction('Refresh')
|
om@13
|
113 |
cAcAbout = menu.addAction("About")
|
om@13
|
114 |
cAcExit = menu.addAction("Exit")
|
om@13
|
115 |
|
om@37
|
116 |
cAcBrowser.triggered.connect(self.clicked_browser)
|
om@13
|
117 |
cAcLaunch.triggered.connect(self.clicked_launch_application)
|
om@13
|
118 |
cAcRefresh.triggered.connect(self.clicked_refresh)
|
om@13
|
119 |
cAcAbout.triggered.connect(self.clicked_about)
|
om@13
|
120 |
cAcExit.triggered.connect(self.clicked_exit)
|
om@13
|
121 |
|
om@13
|
122 |
|
om@13
|
123 |
def main():
|
om@13
|
124 |
|
om@13
|
125 |
app = QtGui.QApplication(sys.argv)
|
om@13
|
126 |
|
om@13
|
127 |
# prebuild the pixmap cache: fetch all jpg, png and jpeg images and load them
|
om@13
|
128 |
image_path = os.path.join(Environment("OpenSecurity").data_path, '..', 'gfx')
|
om@13
|
129 |
for file in os.listdir(image_path):
|
om@13
|
130 |
if file.lower().rpartition('.')[2] in ('jpg', 'png', 'jpeg'):
|
om@13
|
131 |
QtGui.QPixmapCache.insert(file.lower().rpartition('.')[0], QtGui.QPixmap(os.path.join(image_path, file)))
|
om@13
|
132 |
|
om@13
|
133 |
w = QtGui.QWidget()
|
om@13
|
134 |
trayIcon = OpenSecurityTrayIcon(QtGui.QIcon(QtGui.QPixmapCache.find('opensecurity_icon_64')), w)
|
om@13
|
135 |
|
om@13
|
136 |
trayIcon.show()
|
om@13
|
137 |
sys.exit(app.exec_())
|
om@13
|
138 |
|
om@13
|
139 |
|
om@13
|
140 |
# start
|
om@13
|
141 |
if __name__ == "__main__":
|
om@13
|
142 |
main()
|
om@13
|
143 |
|