om@3
|
1 |
#!/bin/env python
|
om@3
|
2 |
# -*- coding: utf-8 -*-
|
om@3
|
3 |
|
om@3
|
4 |
# ------------------------------------------------------------
|
om@3
|
5 |
# opensecurity-dialog
|
om@3
|
6 |
#
|
om@3
|
7 |
# an opensecurity dialog
|
om@3
|
8 |
#
|
om@3
|
9 |
# Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
|
om@3
|
10 |
#
|
om@3
|
11 |
# Copyright (C) 2013 AIT Austrian Institute of Technology
|
om@3
|
12 |
# AIT Austrian Institute of Technology GmbH
|
om@3
|
13 |
# Donau-City-Strasse 1 | 1220 Vienna | Austria
|
om@3
|
14 |
# http://www.ait.ac.at
|
om@3
|
15 |
#
|
om@3
|
16 |
# This program is free software; you can redistribute it and/or
|
om@3
|
17 |
# modify it under the terms of the GNU General Public License
|
om@3
|
18 |
# as published by the Free Software Foundation version 2.
|
om@3
|
19 |
#
|
om@3
|
20 |
# This program is distributed in the hope that it will be useful,
|
om@3
|
21 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
om@3
|
22 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
om@3
|
23 |
# GNU General Public License for more details.
|
om@3
|
24 |
#
|
om@3
|
25 |
# You should have received a copy of the GNU General Public License
|
om@3
|
26 |
# along with this program; if not, write to the Free Software
|
om@3
|
27 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
om@3
|
28 |
# Boston, MA 02110-1301, USA.
|
om@3
|
29 |
# ------------------------------------------------------------
|
om@3
|
30 |
|
om@3
|
31 |
|
om@3
|
32 |
# ------------------------------------------------------------
|
om@3
|
33 |
# imports
|
om@3
|
34 |
|
om@3
|
35 |
import argparse
|
om@3
|
36 |
import os
|
om@3
|
37 |
import sys
|
om@3
|
38 |
|
om@3
|
39 |
from PyQt4 import QtCore
|
om@3
|
40 |
from PyQt4 import QtGui
|
om@3
|
41 |
|
om@3
|
42 |
# local
|
om@3
|
43 |
from credentials import Credentials
|
om@3
|
44 |
from environment import Environment
|
om@3
|
45 |
from password import Password
|
om@3
|
46 |
|
om@3
|
47 |
|
om@3
|
48 |
# ------------------------------------------------------------
|
om@3
|
49 |
# code
|
om@3
|
50 |
|
om@3
|
51 |
|
om@3
|
52 |
def main():
|
om@3
|
53 |
|
om@3
|
54 |
# parse command line
|
om@3
|
55 |
parser = argparse.ArgumentParser(description = 'OpenSecurity Dialog.')
|
om@3
|
56 |
parser.add_argument('mode', metavar='MODE', help='dialog mode: \'password\' or \'credentials\'')
|
om@3
|
57 |
parser.add_argument('text', metavar='TEXT', help='text to show')
|
om@3
|
58 |
args = parser.parse_args()
|
om@3
|
59 |
|
om@3
|
60 |
app = QtGui.QApplication(sys.argv)
|
om@3
|
61 |
|
om@3
|
62 |
# prebuild the pixmap cache: fetch all jpg, png and jpeg images and load them
|
om@3
|
63 |
data_path = Environment("OpenSecurity").data_path
|
om@3
|
64 |
image_path = os.path.join(data_path, '..', 'gfx')
|
om@3
|
65 |
for file in os.listdir(image_path):
|
om@3
|
66 |
if file.lower().rpartition('.')[2] in ('jpg', 'png', 'jpeg'):
|
om@3
|
67 |
QtGui.QPixmapCache.insert(file.lower().rpartition('.')[0], QtGui.QPixmap(os.path.join(image_path, file)))
|
om@3
|
68 |
|
om@3
|
69 |
# we should have now our application icon
|
om@3
|
70 |
app.setWindowIcon(QtGui.QIcon(QtGui.QPixmapCache.find('opensecurity_icon_64')))
|
om@3
|
71 |
|
om@3
|
72 |
if args.mode == 'password':
|
om@3
|
73 |
dlg = Password(args.text)
|
om@3
|
74 |
|
om@3
|
75 |
if args.mode == 'credentials':
|
om@3
|
76 |
dlg = Credentials(args.text)
|
om@3
|
77 |
|
om@3
|
78 |
# pop up the dialog
|
om@3
|
79 |
dlg.show()
|
om@3
|
80 |
app.exec_()
|
om@3
|
81 |
|
om@3
|
82 |
# give proper result code
|
om@3
|
83 |
if dlg.result() == QtGui.QDialog.Accepted:
|
om@3
|
84 |
res = 0
|
om@3
|
85 |
else:
|
om@3
|
86 |
res = 1
|
om@3
|
87 |
sys.exit(res)
|
om@3
|
88 |
|
om@3
|
89 |
|
om@3
|
90 |
# start
|
om@3
|
91 |
if __name__ == "__main__":
|
om@3
|
92 |
main()
|
om@3
|
93 |
|