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 |
#
|
oliver@240
|
11 |
# Copyright 2013-2014 X-Net and AIT Austrian Institute of Technology
|
om@13
|
12 |
#
|
om@13
|
13 |
#
|
oliver@240
|
14 |
# X-Net Services GmbH
|
oliver@240
|
15 |
# Elisabethstrasse 1
|
oliver@240
|
16 |
# 4020 Linz
|
oliver@240
|
17 |
# AUSTRIA
|
oliver@240
|
18 |
# https://www.x-net.at
|
oliver@240
|
19 |
#
|
oliver@240
|
20 |
# AIT Austrian Institute of Technology
|
oliver@240
|
21 |
# Donau City Strasse 1
|
oliver@240
|
22 |
# 1220 Wien
|
oliver@240
|
23 |
# AUSTRIA
|
oliver@240
|
24 |
# http://www.ait.ac.at
|
oliver@240
|
25 |
#
|
oliver@240
|
26 |
#
|
oliver@240
|
27 |
# Licensed under the Apache License, Version 2.0 (the "License");
|
oliver@240
|
28 |
# you may not use this file except in compliance with the License.
|
oliver@240
|
29 |
# You may obtain a copy of the License at
|
oliver@240
|
30 |
#
|
oliver@240
|
31 |
# http://www.apache.org/licenses/LICENSE-2.0
|
oliver@240
|
32 |
#
|
oliver@240
|
33 |
# Unless required by applicable law or agreed to in writing, software
|
oliver@240
|
34 |
# distributed under the License is distributed on an "AS IS" BASIS,
|
oliver@240
|
35 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
oliver@240
|
36 |
# See the License for the specific language governing permissions and
|
oliver@240
|
37 |
# limitations under the License.
|
om@13
|
38 |
# ------------------------------------------------------------
|
om@13
|
39 |
|
om@13
|
40 |
|
om@13
|
41 |
# ------------------------------------------------------------
|
om@13
|
42 |
# imports
|
om@13
|
43 |
|
om@13
|
44 |
import argparse
|
om@13
|
45 |
import os
|
om@13
|
46 |
import sys
|
om@13
|
47 |
|
om@13
|
48 |
from PyQt4 import QtCore
|
om@13
|
49 |
from PyQt4 import QtGui
|
om@13
|
50 |
|
om@13
|
51 |
# local
|
oliver@104
|
52 |
from ui import *
|
om@13
|
53 |
|
om@13
|
54 |
|
om@13
|
55 |
# ------------------------------------------------------------
|
om@13
|
56 |
# code
|
om@13
|
57 |
|
om@13
|
58 |
|
om@13
|
59 |
def main():
|
om@13
|
60 |
|
om@13
|
61 |
# parse command line
|
om@13
|
62 |
parser = argparse.ArgumentParser(description = 'OpenSecurity Dialog.')
|
oliver@134
|
63 |
parser.add_argument('mode', metavar='MODE', help='dialog mode: \'password\', \'credentials\', \'keyfile\', \'notification-information\', \'notification-warning\' or \'notification-critical\'')
|
om@13
|
64 |
parser.add_argument('text', metavar='TEXT', help='text to show')
|
om@13
|
65 |
args = parser.parse_args()
|
om@13
|
66 |
|
oliver@104
|
67 |
a = QtGui.QApplication(sys.argv)
|
om@13
|
68 |
|
om@13
|
69 |
if args.mode == 'password':
|
oliver@104
|
70 |
d = PasswordDialog(args.text)
|
om@13
|
71 |
|
om@13
|
72 |
if args.mode == 'credentials':
|
oliver@104
|
73 |
d = CredentialsDialog(args.text)
|
om@13
|
74 |
|
oliver@134
|
75 |
if args.mode == 'keyfile':
|
oliver@134
|
76 |
d = KeyfileDialog(args.text)
|
oliver@134
|
77 |
|
om@29
|
78 |
if args.mode == 'notification-information':
|
oliver@104
|
79 |
d = NotificationDialog('OpenSecurity Information', args.text)
|
om@29
|
80 |
|
om@29
|
81 |
if args.mode == 'notification-warning':
|
oliver@104
|
82 |
d = NotificationDialog('OpenSecurity Warning', args.text)
|
om@29
|
83 |
|
om@29
|
84 |
if args.mode == 'notification-critical':
|
oliver@134
|
85 |
d = NotificationDialog('OpenSecurity Critical Message', args.text)
|
om@29
|
86 |
|
oliver@104
|
87 |
if not 'd' in locals():
|
oliver@104
|
88 |
sys.stderr.write('unknown mode. type --help for help\n')
|
oliver@104
|
89 |
sys.exit(1)
|
om@29
|
90 |
|
om@13
|
91 |
# pop up the dialog
|
oliver@104
|
92 |
d.show()
|
oliver@104
|
93 |
a.exec_()
|
om@13
|
94 |
|
om@13
|
95 |
# give proper result code
|
oliver@104
|
96 |
if d.result() == QtGui.QDialog.Accepted:
|
om@13
|
97 |
res = 0
|
om@13
|
98 |
else:
|
om@13
|
99 |
res = 1
|
om@13
|
100 |
sys.exit(res)
|
om@13
|
101 |
|
om@13
|
102 |
|
om@13
|
103 |
# start
|
om@13
|
104 |
if __name__ == "__main__":
|
om@13
|
105 |
main()
|
om@13
|
106 |
|