renamed "client" to "bin"
authorom
Fri, 06 Dec 2013 12:10:30 +0100
changeset 14c187aaceca32
parent 12 11dc05750aea
child 15 2e4cb1ebcbed
renamed "client" to "bin"
OpenSecurity/bin/about.py
OpenSecurity/bin/credentials.py
OpenSecurity/bin/cygwin.py
OpenSecurity/bin/environment.py
OpenSecurity/bin/launch.py
OpenSecurity/bin/opensecurity_client_restful_server.py
OpenSecurity/bin/opensecurity_dialog.py
OpenSecurity/bin/opensecurity_server.py
OpenSecurity/bin/opensecurity_tray.py
OpenSecurity/bin/password.py
OpenSecurity/client/about.py
OpenSecurity/client/credentials.py
OpenSecurity/client/cygwin.py
OpenSecurity/client/environment.py
OpenSecurity/client/launch.py
OpenSecurity/client/opensecurity_client_restful_server.py
OpenSecurity/client/opensecurity_dialog.py
OpenSecurity/client/opensecurity_server.py
OpenSecurity/client/opensecurity_tray.py
OpenSecurity/client/password.py
OpenSecurity/cygwin64/Cygwin.vbs
OpenSecurity/cygwin64/content.txt
OpenSecurity/cygwin64/setup-x86_64.exe
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/OpenSecurity/bin/about.py	Fri Dec 06 12:10:30 2013 +0100
     1.3 @@ -0,0 +1,126 @@
     1.4 +#!/bin/env python
     1.5 +# -*- coding: utf-8 -*-
     1.6 +
     1.7 +# ------------------------------------------------------------
     1.8 +# about-dialog
     1.9 +# 
    1.10 +# tell the user about the project
    1.11 +#
    1.12 +# Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
    1.13 +#
    1.14 +# Copyright (C) 2013 AIT Austrian Institute of Technology
    1.15 +# AIT Austrian Institute of Technology GmbH
    1.16 +# Donau-City-Strasse 1 | 1220 Vienna | Austria
    1.17 +# http://www.ait.ac.at
    1.18 +#
    1.19 +# This program is free software; you can redistribute it and/or
    1.20 +# modify it under the terms of the GNU General Public License
    1.21 +# as published by the Free Software Foundation version 2.
    1.22 +# 
    1.23 +# This program is distributed in the hope that it will be useful,
    1.24 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.25 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.26 +# GNU General Public License for more details.
    1.27 +# 
    1.28 +# You should have received a copy of the GNU General Public License
    1.29 +# along with this program; if not, write to the Free Software
    1.30 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, 
    1.31 +# Boston, MA  02110-1301, USA.
    1.32 +# ------------------------------------------------------------
    1.33 +
    1.34 +
    1.35 +# ------------------------------------------------------------
    1.36 +# imports
    1.37 +
    1.38 +import os
    1.39 +
    1.40 +from PyQt4 import QtCore
    1.41 +from PyQt4 import QtGui
    1.42 +
    1.43 +# local
    1.44 +from environment import Environment
    1.45 +
    1.46 +# ------------------------------------------------------------
    1.47 +# vars
    1.48 +
    1.49 +
    1.50 +ABOUT_TEXT = """
    1.51 +<html>
    1.52 +<body bgcolor="#FFFFFF">
    1.53 +
    1.54 +<div align="center">
    1.55 +<p/>
    1.56 +<img src="image:ait_logo_no_claim.png"/>
    1.57 +<p/>
    1.58 +<h1>OpenSecurity</h1>
    1.59 +<p/>
    1.60 +</div>
    1.61 +<p/>
    1.62 +Blah ...<br/>
    1.63 +
    1.64 +<p>
    1.65 +Copyright (C) 2013, AIT Austrian Institute of Technology<br/>
    1.66 +AIT Austrian Institute of Technology GmbH<br/>
    1.67 +Donau-City-Strasse 1 | 1220 Vienna | Austria<br/>
    1.68 +<a href="http://www.ait.ac.at">http://www.ait.ac.at</a>
    1.69 +</p>
    1.70 +</div>
    1.71 +
    1.72 +</body>
    1.73 +</html>
    1.74 +""";
    1.75 +
    1.76 +
    1.77 +# ------------------------------------------------------------
    1.78 +# code
    1.79 +
    1.80 +
    1.81 +class About(QtGui.QDialog):
    1.82 +    
    1.83 +    """Show some about stuff."""
    1.84 +    
    1.85 +    def __init__(self, parent = None, flags = QtCore.Qt.WindowFlags(0)):
    1.86 +        
    1.87 +        # super call and widget init
    1.88 +        super(About, self).__init__(parent, flags)
    1.89 +        
    1.90 +        # setup image search path
    1.91 +        QtCore.QDir.setSearchPaths("image", QtCore.QStringList(os.path.join(Environment('opensecurity').data_path, '..', 'gfx')));
    1.92 +        
    1.93 +        self.setWindowTitle('About OpenSecuirty ...')
    1.94 +        self.setup_ui()
    1.95 +        
    1.96 +
    1.97 +    def setup_ui(self):
    1.98 +        
    1.99 +        """Create the widgets."""
   1.100 +        
   1.101 +        lyMain = QtGui.QVBoxLayout(self)
   1.102 +        lyMain.setContentsMargins(8, 8, 8, 8)
   1.103 +        
   1.104 +        lbAbout = QtGui.QLabel()
   1.105 +        lbAbout.setStyleSheet("QWidget { background: white; color: black; };")
   1.106 +        lbAbout.setText(ABOUT_TEXT)
   1.107 +        lbAbout.setContentsMargins(12, 12, 12, 12)
   1.108 +        
   1.109 +        scAbout = QtGui.QScrollArea()
   1.110 +        scAbout.setWidget(lbAbout)
   1.111 +        scAbout.viewport().setStyleSheet("QWidget { background: white; color: black; };")
   1.112 +        lyMain.addWidget(scAbout)
   1.113 +        
   1.114 +        # buttons
   1.115 +        lyButton = QtGui.QHBoxLayout()
   1.116 +        lyMain.addLayout(lyButton)
   1.117 +        
   1.118 +        lyButton.addStretch(1)
   1.119 +        btnOk = QtGui.QPushButton('&Ok', self)
   1.120 +        btnOk.setMinimumWidth(100)
   1.121 +        lyButton.addWidget(btnOk)
   1.122 +        
   1.123 +        # connectors
   1.124 +        btnOk.clicked.connect(self.accept)
   1.125 +        
   1.126 +        # reduce to the max
   1.127 +        self.setMinimumSize(400, 200)
   1.128 +        self.resize(lyMain.minimumSize())
   1.129 +
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/OpenSecurity/bin/credentials.py	Fri Dec 06 12:10:30 2013 +0100
     2.3 @@ -0,0 +1,160 @@
     2.4 +#!/bin/env python
     2.5 +# -*- coding: utf-8 -*-
     2.6 +
     2.7 +# ------------------------------------------------------------
     2.8 +# credentials-dialog
     2.9 +# 
    2.10 +# ask the user credentials
    2.11 +#
    2.12 +# Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
    2.13 +#
    2.14 +# Copyright (C) 2013 AIT Austrian Institute of Technology
    2.15 +# AIT Austrian Institute of Technology GmbH
    2.16 +# Donau-City-Strasse 1 | 1220 Vienna | Austria
    2.17 +# http://www.ait.ac.at
    2.18 +#
    2.19 +# This program is free software; you can redistribute it and/or
    2.20 +# modify it under the terms of the GNU General Public License
    2.21 +# as published by the Free Software Foundation version 2.
    2.22 +# 
    2.23 +# This program is distributed in the hope that it will be useful,
    2.24 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.25 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    2.26 +# GNU General Public License for more details.
    2.27 +# 
    2.28 +# You should have received a copy of the GNU General Public License
    2.29 +# along with this program; if not, write to the Free Software
    2.30 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, 
    2.31 +# Boston, MA  02110-1301, USA.
    2.32 +# ------------------------------------------------------------
    2.33 +
    2.34 +
    2.35 +# ------------------------------------------------------------
    2.36 +# imports
    2.37 +
    2.38 +import sys
    2.39 +
    2.40 +from PyQt4 import QtCore
    2.41 +from PyQt4 import QtGui
    2.42 +
    2.43 +# local
    2.44 +from about import About
    2.45 +
    2.46 +# ------------------------------------------------------------
    2.47 +# code
    2.48 +
    2.49 +
    2.50 +class Credentials(QtGui.QDialog):
    2.51 +    
    2.52 +    """Ask the user for credentials."""
    2.53 +    
    2.54 +    def __init__(self, text, parent = None, flags = QtCore.Qt.WindowFlags(0)):
    2.55 +        
    2.56 +        super(Credentials, self).__init__(parent, flags)
    2.57 +        self.setWindowTitle('OpenSecuirty Credentials Request')
    2.58 +        self.setup_ui()
    2.59 +        
    2.60 +        # positionate ourself central
    2.61 +        screen = QtGui.QDesktopWidget().screenGeometry()
    2.62 +        self.resize(self.geometry().width() * 1.25, self.geometry().height())
    2.63 +        size = self.geometry()
    2.64 +        self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2)
    2.65 +        
    2.66 +        # fix up text
    2.67 +        self.lbText.setText(text)
    2.68 +        
    2.69 +
    2.70 +    def clicked_about(self):
    2.71 +        """clicked the about button"""
    2.72 +        dlgAbout = About()
    2.73 +        dlgAbout.exec_()
    2.74 +    
    2.75 +
    2.76 +    def clicked_cancel(self):
    2.77 +        """clicked the cancel button"""
    2.78 +        self.reject()
    2.79 +    
    2.80 +
    2.81 +    def clicked_ok(self):
    2.82 +        """clicked the ok button"""
    2.83 +        sys.stdout.write('{ ')
    2.84 +        sys.stdout.write('\'user\': \'')
    2.85 +        sys.stdout.write(self.edUser.text())
    2.86 +        sys.stdout.write('\', ')
    2.87 +        sys.stdout.write('\'password\': \'')
    2.88 +        sys.stdout.write(self.edPassword.text())
    2.89 +        sys.stdout.write('\' ')
    2.90 +        sys.stdout.write('}\n')
    2.91 +        self.accept()
    2.92 +    
    2.93 +
    2.94 +    def setup_ui(self):
    2.95 +        
    2.96 +        """Create the widgets."""
    2.97 +        
    2.98 +        lyMain = QtGui.QVBoxLayout(self)
    2.99 +        lyMain.setContentsMargins(8, 8, 8, 8)
   2.100 +        
   2.101 +        # content area: left pixmap, right text
   2.102 +        lyContent = QtGui.QHBoxLayout()
   2.103 +        lyMain.addLayout(lyContent)
   2.104 +        
   2.105 +        # pixmap
   2.106 +        lbPix = QtGui.QLabel()
   2.107 +        lbPix.setPixmap(QtGui.QPixmapCache.find('opensecurity_icon_64'))
   2.108 +        lyContent.addWidget(lbPix, 0, QtCore.Qt.Alignment(QtCore.Qt.AlignTop + QtCore.Qt.AlignHCenter))
   2.109 +        lyContent.addSpacing(16)
   2.110 +        
   2.111 +        # text ...
   2.112 +        lyText = QtGui.QGridLayout()
   2.113 +        lyContent.addLayout(lyText)
   2.114 +        self.lbText = QtGui.QLabel()
   2.115 +        lyText.addWidget(self.lbText, 0, 0, 1, 2)
   2.116 +        
   2.117 +        lbUser = QtGui.QLabel('&User:')
   2.118 +        lyText.addWidget(lbUser, 1, 0)
   2.119 +        self.edUser = QtGui.QLineEdit()
   2.120 +        lyText.addWidget(self.edUser, 1, 1)
   2.121 +        lbUser.setBuddy(self.edUser)
   2.122 +        
   2.123 +        lbPassword = QtGui.QLabel('&Password:')
   2.124 +        lyText.addWidget(lbPassword, 2, 0)
   2.125 +        self.edPassword = QtGui.QLineEdit()
   2.126 +        self.edPassword.setEchoMode(QtGui.QLineEdit.Password)
   2.127 +        lyText.addWidget(self.edPassword, 2, 1)
   2.128 +        lbPassword.setBuddy(self.edPassword)
   2.129 +        
   2.130 +        lyText.addWidget(QtGui.QWidget(), 3, 0, 1, 2)
   2.131 +        lyText.setColumnStretch(1, 1)
   2.132 +        lyText.setRowStretch(3, 1)
   2.133 +        
   2.134 +        lyMain.addStretch(1)
   2.135 +        
   2.136 +        # buttons
   2.137 +        lyButton = QtGui.QHBoxLayout()
   2.138 +        lyMain.addLayout(lyButton)
   2.139 +        
   2.140 +        lyButton.addStretch(1)
   2.141 +        btnOk = QtGui.QPushButton('&Ok', self)
   2.142 +        btnOk.setDefault(True)
   2.143 +        btnOk.setMinimumWidth(100)
   2.144 +        lyButton.addWidget(btnOk)
   2.145 +        btnCancel = QtGui.QPushButton('&Cancel', self)
   2.146 +        btnCancel.setMinimumWidth(100)
   2.147 +        lyButton.addWidget(btnCancel)
   2.148 +        btnAbout = QtGui.QPushButton('&About', self)
   2.149 +        btnAbout.setMinimumWidth(100)
   2.150 +        lyButton.addWidget(btnAbout)
   2.151 +        
   2.152 +        button_width = max(btnOk.width(), btnCancel.width(), btnAbout.width())
   2.153 +        btnOk.setMinimumWidth(button_width)
   2.154 +        btnCancel.setMinimumWidth(button_width)
   2.155 +        btnAbout.setMinimumWidth(button_width)
   2.156 +        
   2.157 +        # reduce to the max
   2.158 +        self.resize(lyMain.minimumSize())
   2.159 +        
   2.160 +        # connectors
   2.161 +        btnOk.clicked.connect(self.clicked_ok)
   2.162 +        btnCancel.clicked.connect(self.clicked_cancel)
   2.163 +        btnAbout.clicked.connect(self.clicked_about)
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/OpenSecurity/bin/cygwin.py	Fri Dec 06 12:10:30 2013 +0100
     3.3 @@ -0,0 +1,105 @@
     3.4 +#!/bin/env python
     3.5 +# -*- coding: utf-8 -*-
     3.6 +
     3.7 +# ------------------------------------------------------------
     3.8 +# cygwin command
     3.9 +# 
    3.10 +# executes a cygwin command inside the opensecurity project
    3.11 +#
    3.12 +# Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
    3.13 +#
    3.14 +# Copyright (C) 2013 AIT Austrian Institute of Technology
    3.15 +# AIT Austrian Institute of Technology GmbH
    3.16 +# Donau-City-Strasse 1 | 1220 Vienna | Austria
    3.17 +# http://www.ait.ac.at
    3.18 +#
    3.19 +# This program is free software; you can redistribute it and/or
    3.20 +# modify it under the terms of the GNU General Public License
    3.21 +# as published by the Free Software Foundation version 2.
    3.22 +# 
    3.23 +# This program is distributed in the hope that it will be useful,
    3.24 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.25 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    3.26 +# GNU General Public License for more details.
    3.27 +# 
    3.28 +# You should have received a copy of the GNU General Public License
    3.29 +# along with this program; if not, write to the Free Software
    3.30 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, 
    3.31 +# Boston, MA  02110-1301, USA.
    3.32 +# ------------------------------------------------------------
    3.33 +
    3.34 +
    3.35 +# ------------------------------------------------------------
    3.36 +# imports
    3.37 +
    3.38 +import os
    3.39 +import subprocess
    3.40 +import sys
    3.41 +
    3.42 +# local
    3.43 +from environment import Environment
    3.44 +
    3.45 +
    3.46 +# ------------------------------------------------------------
    3.47 +# code
    3.48 +
    3.49 +
    3.50 +class Cygwin(object):
    3.51 +
    3.52 +    """Some nifty methods working with Cygwin"""
    3.53 +    
    3.54 +    def __call__(self, command, stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE):
    3.55 +        """make an instance of this object act as a function"""
    3.56 +        return self.execute(command, stdin, stdout, stderr)
    3.57 +
    3.58 +        
    3.59 +    @staticmethod
    3.60 +    def root():
    3.61 +        """get the path to our local cygwin installment"""
    3.62 +        return os.path.join(Environment('OpenSecurity').prefix_path, '..', 'cygwin')
    3.63 +
    3.64 +
    3.65 +    def execute(self, command, stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE):
    3.66 +        """execute a cygwin shell command
    3.67 +        
    3.68 +        command is list of arguments like ['/bin/ls', '-al', '-h']
    3.69 +        
    3.70 +        a Popen object is returned"""
    3.71 +        command_path = Cygwin.root() + os.sep.join(command[0].split('/'))
    3.72 +        command = [command_path] + command[1:]
    3.73 +        
    3.74 +        return subprocess.Popen(command, shell = False, stdin = stdin, stdout = stdout, stderr = stderr)
    3.75 +        
    3.76 +        
    3.77 +    @staticmethod
    3.78 +    def is_X11_running():
    3.79 +        """check if we can connect to a X11 running instance"""
    3.80 +        p = Cygwin()(['/bin/bash', '-c', 'DISPLAY=:0 /usr/bin/xset -q'])
    3.81 +        stdout, stderr = p.communicate()
    3.82 +        return p.returncode == 0
    3.83 +        
    3.84 +        
    3.85 +    @staticmethod
    3.86 +    def start_X11():
    3.87 +        """start X11 in the background (if not already running) on DISPLAY=:0"""
    3.88 +        
    3.89 +        # do not start if already running
    3.90 +        if Cygwin.is_X11_running():
    3.91 +            return
    3.92 +            
    3.93 +        # launch X11 (forget output and return immediately)
    3.94 +        p = Cygwin()(['/bin/bash', '--login', '-i', '-c', ' X :0 -multiwindow'], stdin = None, stdout = None, stderr = None)
    3.95 +        
    3.96 +    
    3.97 +# start
    3.98 +if __name__ == "__main__":
    3.99 +
   3.100 +    # execute what is given on the command line
   3.101 +    c = Cygwin()
   3.102 +    p = c(sys.argv[1:])
   3.103 +    
   3.104 +    # wait until the process finished and grab the output
   3.105 +    stdout, stderr = p.communicate()
   3.106 +    print('=== call result on stdout: ===\n' + stdout)
   3.107 +    print('=== call result on stderr: ===\n' + stderr)
   3.108 +    
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/OpenSecurity/bin/environment.py	Fri Dec 06 12:10:30 2013 +0100
     4.3 @@ -0,0 +1,103 @@
     4.4 +#!/bin/env python
     4.5 +# -*- coding: utf-8 -*-
     4.6 +
     4.7 +# ------------------------------------------------------------
     4.8 +# environment.py
     4.9 +# 
    4.10 +# pick some current environment infos
    4.11 +#
    4.12 +# Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
    4.13 +#
    4.14 +# Copyright (C) 2013 AIT Austrian Institute of Technology
    4.15 +# AIT Austrian Institute of Technology GmbH
    4.16 +# Donau-City-Strasse 1 | 1220 Vienna | Austria
    4.17 +# http://www.ait.ac.at
    4.18 +#
    4.19 +# This program is free software; you can redistribute it and/or
    4.20 +# modify it under the terms of the GNU General Public License
    4.21 +# as published by the Free Software Foundation version 2.
    4.22 +# 
    4.23 +# This program is distributed in the hope that it will be useful,
    4.24 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.25 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    4.26 +# GNU General Public License for more details.
    4.27 +# 
    4.28 +# You should have received a copy of the GNU General Public License
    4.29 +# along with this program; if not, write to the Free Software
    4.30 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, 
    4.31 +# Boston, MA  02110-1301, USA.
    4.32 +# ------------------------------------------------------------
    4.33 +
    4.34 +
    4.35 +# ------------------------------------------------------------
    4.36 +# imports
    4.37 +
    4.38 +import os
    4.39 +import os.path
    4.40 +import sys
    4.41 +
    4.42 +
    4.43 +# ------------------------------------------------------------
    4.44 +# code
    4.45 +
    4.46 +
    4.47 +class Environment(object):
    4.48 +    
    4.49 +    """Hold some nifty environment stuff in a dedicated class."""
    4.50 +    
    4.51 +    def __init__(self, application = None):
    4.52 +        
    4.53 +        # if we ain't got a path to start from, all is valid/lost
    4.54 +        if len(sys.path[0]) == 0:
    4.55 +            self._prefix_path = ''
    4.56 +            self._data_path = ''
    4.57 +            return
    4.58 +        
    4.59 +        # the prefix path
    4.60 +        #
    4.61 +        # - on Linux: this is ../../ to the current executable
    4.62 +        #   e.g. "/usr/bin/myprogram" --> "/usr"
    4.63 +        #
    4.64 +        # - on Windows (inkl. Cygwin): this is the installation folder
    4.65 +        #   e.g. "C:/Program Files/MyProgram/myprogam" --> "C:/Program Files/MyProgram"
    4.66 +        #
    4.67 +        if sys.platform == 'linux2':
    4.68 +            self._prefix_path = os.path.split(sys.path[0])[0]
    4.69 +        elif sys.platform == 'win32' or sys.platform == 'cygwin':
    4.70 +            self._prefix_path = sys.path[0]
    4.71 +            
    4.72 +        # the data path where all data files are stored
    4.73 +        if sys.platform == 'linux2':
    4.74 +            if not application is None:
    4.75 +                self._data_path = os.path.join(self._prefix_path, os.path.join('share', application))
    4.76 +            else:
    4.77 +                self._data_path = os.path.join(self._prefix_path, 'share')
    4.78 +        elif sys.platform == 'win32' or sys.platform == 'cygwin':
    4.79 +            self._data_path = self._prefix_path
    4.80 +
    4.81 +            
    4.82 +    def data_path_get(self):
    4.83 +        """dat_path get"""
    4.84 +        return self._data_path
    4.85 +        
    4.86 +    data_path = property(data_path_get)
    4.87 +            
    4.88 +            
    4.89 +    def prefix_path_get(self):
    4.90 +        """prefix_path get"""
    4.91 +        return self._prefix_path
    4.92 +        
    4.93 +    prefix_path = property(prefix_path_get)
    4.94 +            
    4.95 +# test method			
    4.96 +def test():
    4.97 +
    4.98 +	"""Test: class Environment"""
    4.99 +	e = Environment('My Application')
   4.100 +	print('prefix_path: "{0}"'.format(e.prefix_path))
   4.101 +	print('  data_path: "{0}"'.format(e.data_path))
   4.102 +			
   4.103 +			
   4.104 +# test the module			
   4.105 +if __name__ == '__main__':
   4.106 +	test()
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/OpenSecurity/bin/launch.py	Fri Dec 06 12:10:30 2013 +0100
     5.3 @@ -0,0 +1,287 @@
     5.4 +#!/bin/env python
     5.5 +# -*- coding: utf-8 -*-
     5.6 +
     5.7 +# ------------------------------------------------------------
     5.8 +# opensecurity-launcher
     5.9 +# 
    5.10 +# launches an application inside a VM
    5.11 +#
    5.12 +# Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
    5.13 +#
    5.14 +# Copyright (C) 2013 AIT Austrian Institute of Technology
    5.15 +# AIT Austrian Institute of Technology GmbH
    5.16 +# Donau-City-Strasse 1 | 1220 Vienna | Austria
    5.17 +# http://www.ait.ac.at
    5.18 +#
    5.19 +# This program is free software; you can redistribute it and/or
    5.20 +# modify it under the terms of the GNU General Public License
    5.21 +# as published by the Free Software Foundation version 2.
    5.22 +# 
    5.23 +# This program is distributed in the hope that it will be useful,
    5.24 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.25 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    5.26 +# GNU General Public License for more details.
    5.27 +# 
    5.28 +# You should have received a copy of the GNU General Public License
    5.29 +# along with this program; if not, write to the Free Software
    5.30 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, 
    5.31 +# Boston, MA  02110-1301, USA.
    5.32 +# ------------------------------------------------------------
    5.33 +
    5.34 +
    5.35 +# ------------------------------------------------------------
    5.36 +# imports
    5.37 +
    5.38 +import argparse
    5.39 +import os
    5.40 +import subprocess
    5.41 +import sys
    5.42 +
    5.43 +from PyQt4 import QtCore
    5.44 +from PyQt4 import QtGui
    5.45 +
    5.46 +# local
    5.47 +from about import About
    5.48 +from cygwin import Cygwin
    5.49 +from environment import Environment
    5.50 +import opensecurity_server
    5.51 +
    5.52 +
    5.53 +# ------------------------------------------------------------
    5.54 +# code
    5.55 +
    5.56 +
    5.57 +class Chooser(QtGui.QDialog, object):
    5.58 +    
    5.59 +    """Ask the user what to launch."""
    5.60 +    
    5.61 +    def __init__(self, parent = None, flags = QtCore.Qt.WindowFlags(0)):
    5.62 +    
    5.63 +        super(Chooser, self).__init__(parent, flags)
    5.64 +        self.setWindowTitle('OpenSecuirty Launch Application')
    5.65 +        self.setup_ui()
    5.66 +        
    5.67 +        # known vms and applications
    5.68 +        self._apps, self_vms = [], []
    5.69 +        
    5.70 +        # positionate ourself central
    5.71 +        screen = QtGui.QDesktopWidget().screenGeometry()
    5.72 +        self.resize(self.geometry().width() * 1.25, self.geometry().height())
    5.73 +        size = self.geometry()
    5.74 +        self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2)
    5.75 +        
    5.76 +        # refresh vm and command input
    5.77 +        self.refresh()
    5.78 +        
    5.79 +        
    5.80 +    def app_get(self):
    5.81 +        """The application of the user."""
    5.82 +        a = str(self._cbApplication.currentText())
    5.83 +        for app in self._apps:
    5.84 +            if a == app['name']:
    5.85 +                return app['command']
    5.86 +        return a
    5.87 +        
    5.88 +    app = property(app_get)
    5.89 +        
    5.90 +
    5.91 +    def clicked_about(self):
    5.92 +        """clicked the about button"""
    5.93 +        dlgAbout = About()
    5.94 +        dlgAbout.exec_()
    5.95 +
    5.96 +
    5.97 +    def clicked_cancel(self):
    5.98 +        """clicked the cancel button"""
    5.99 +        self.reject()
   5.100 +    
   5.101 +
   5.102 +    def clicked_ok(self):
   5.103 +        """clicked the ok button"""
   5.104 +        self.accept()
   5.105 +    
   5.106 +    
   5.107 +    def refresh(self):
   5.108 +        """load the known vms and commands and adjust input fields"""
   5.109 +        
   5.110 +        self._apps = opensecurity_server.query_apps()
   5.111 +        self._vms = opensecurity_server.query_vms()
   5.112 +        
   5.113 +        # add the VMs we know
   5.114 +        self._cbApplication.clear()
   5.115 +        for app in self._apps:
   5.116 +            self._cbApplication.addItem(app['name'])
   5.117 +        
   5.118 +        # add the commands we know
   5.119 +        self._cbVM.clear()
   5.120 +        for vm in self._vms:
   5.121 +            self._cbVM.addItem(vm['name'])
   5.122 +        
   5.123 +        
   5.124 +    def setup_ui(self):
   5.125 +        """Create the widgets."""
   5.126 +        
   5.127 +        lyMain = QtGui.QVBoxLayout(self)
   5.128 +        lyMain.setContentsMargins(8, 8, 8, 8)
   5.129 +        
   5.130 +        # content area: left pixmap, right text
   5.131 +        lyContent = QtGui.QHBoxLayout()
   5.132 +        lyMain.addLayout(lyContent)
   5.133 +        
   5.134 +        # pixmap
   5.135 +        lbPix = QtGui.QLabel()
   5.136 +        lbPix.setPixmap(QtGui.QPixmapCache.find('opensecurity_icon_64'))
   5.137 +        lyContent.addWidget(lbPix, 0, QtCore.Qt.Alignment(QtCore.Qt.AlignTop + QtCore.Qt.AlignHCenter))
   5.138 +        lyContent.addSpacing(16)
   5.139 +        
   5.140 +        # launch ...
   5.141 +        lyLaunch = QtGui.QGridLayout()
   5.142 +        lyContent.addLayout(lyLaunch)
   5.143 +        lbTitle = QtGui.QLabel('Specify details for application to launch.')
   5.144 +        lyLaunch.addWidget(lbTitle, 0, 0, 1, 2)
   5.145 +        
   5.146 +        lbVM = QtGui.QLabel('&VM-ID:')
   5.147 +        lyLaunch.addWidget(lbVM, 1, 0)
   5.148 +        self._cbVM = QtGui.QComboBox()
   5.149 +        self._cbVM.setEditable(True)
   5.150 +        self._cbVM.setInsertPolicy(QtGui.QComboBox.InsertAlphabetically)
   5.151 +        lyLaunch.addWidget(self._cbVM, 1, 1)
   5.152 +        lbVM.setBuddy(self._cbVM)
   5.153 +        
   5.154 +        lbApplication = QtGui.QLabel('&Application:')
   5.155 +        lyLaunch.addWidget(lbApplication, 2, 0)
   5.156 +        self._cbApplication = QtGui.QComboBox()
   5.157 +        self._cbApplication.setEditable(True)
   5.158 +        self._cbApplication.setInsertPolicy(QtGui.QComboBox.InsertAlphabetically)
   5.159 +        lyLaunch.addWidget(self._cbApplication, 2, 1)
   5.160 +        lbApplication.setBuddy(self._cbApplication)
   5.161 +        
   5.162 +        lyLaunch.addWidget(QtGui.QWidget(), 3, 0, 1, 2)
   5.163 +        lyLaunch.setColumnStretch(1, 1)
   5.164 +        lyLaunch.setRowStretch(3, 1)
   5.165 +        
   5.166 +        lyMain.addStretch(1)
   5.167 +        
   5.168 +        # buttons
   5.169 +        lyButton = QtGui.QHBoxLayout()
   5.170 +        lyMain.addLayout(lyButton)
   5.171 +        
   5.172 +        lyButton.addStretch(1)
   5.173 +        btnOk = QtGui.QPushButton('&Ok', self)
   5.174 +        btnOk.setDefault(True)
   5.175 +        btnOk.setMinimumWidth(100)
   5.176 +        lyButton.addWidget(btnOk)
   5.177 +        btnCancel = QtGui.QPushButton('&Cancel', self)
   5.178 +        btnCancel.setMinimumWidth(100)
   5.179 +        lyButton.addWidget(btnCancel)
   5.180 +        btnAbout = QtGui.QPushButton('&About', self)
   5.181 +        btnAbout.setMinimumWidth(100)
   5.182 +        lyButton.addWidget(btnAbout)
   5.183 +        
   5.184 +        button_width = max(btnOk.width(), btnCancel.width(), btnAbout.width())
   5.185 +        btnOk.setMinimumWidth(button_width)
   5.186 +        btnCancel.setMinimumWidth(button_width)
   5.187 +        btnAbout.setMinimumWidth(button_width)
   5.188 +        
   5.189 +        # reduce to the max
   5.190 +        self.resize(lyMain.minimumSize())
   5.191 +        
   5.192 +        # connectors
   5.193 +        btnOk.clicked.connect(self.clicked_ok)
   5.194 +        btnCancel.clicked.connect(self.clicked_cancel)
   5.195 +        btnAbout.clicked.connect(self.clicked_about)
   5.196 +
   5.197 +        
   5.198 +    def user_get(self):
   5.199 +        """The user of the vm of choice."""
   5.200 +        v = str(self._cbVM.currentText())
   5.201 +        for vm in self._vms:
   5.202 +            if v == vm['name']:
   5.203 +                return vm['user']
   5.204 +        return v
   5.205 +        
   5.206 +    user = property(user_get)
   5.207 +    
   5.208 +    
   5.209 +    def vm_get(self):
   5.210 +        """The vm of choice."""
   5.211 +        v = str(self._cbVM.currentText())
   5.212 +        for vm in self._vms:
   5.213 +            if v == vm['name']:
   5.214 +                return vm['ip']
   5.215 +        return v
   5.216 +        
   5.217 +    vm = property(vm_get)
   5.218 +        
   5.219 +        
   5.220 +def ask_user():
   5.221 +    """ask the user for VM and app to start"""
   5.222 +    
   5.223 +    # launch Qt
   5.224 +    app = QtGui.QApplication(sys.argv)
   5.225 +    
   5.226 +    # prebuild the pixmap cache: fetch all jpg, png and jpeg images and load them
   5.227 +    image_path = os.path.join(Environment("OpenSecurity").data_path, '..', 'gfx')
   5.228 +    for file in os.listdir(image_path):
   5.229 +        if file.lower().rpartition('.')[2] in ('jpg', 'png', 'jpeg'):
   5.230 +            QtGui.QPixmapCache.insert(file.lower().rpartition('.')[0], QtGui.QPixmap(os.path.join(image_path, file)))
   5.231 +            
   5.232 +    # we should have now our application icon
   5.233 +    app.setWindowIcon(QtGui.QIcon(QtGui.QPixmapCache.find('opensecurity_icon_64')))
   5.234 +    
   5.235 +    # pop up the dialog
   5.236 +    dlg = Chooser()
   5.237 +    dlg.show()
   5.238 +    app.exec_()
   5.239 +    
   5.240 +    if dlg.result() == QtGui.QDialog.Accepted:
   5.241 +        return dlg.user, dlg.vm, dlg.app
   5.242 +
   5.243 +    return '', '', ''
   5.244 +    
   5.245 +
   5.246 +def main():
   5.247 +    """entry point"""
   5.248 +    
   5.249 +    # parse command line
   5.250 +    parser = argparse.ArgumentParser(description = 'OpenSecurity Launcher: run application in VM')
   5.251 +    parser.add_argument('user', metavar='USER', help='USER on Virtual Machine', nargs='?', type=str, default='')
   5.252 +    parser.add_argument('ip', metavar='IP', help='IP of Virtual Machine', nargs='?', type=str, default='')
   5.253 +    parser.add_argument('command', metavar='COMMAND', help='Full path of command and arguments to start inside VM', nargs='?', type=str, default='')
   5.254 +    args = parser.parse_args()
   5.255 +    
   5.256 +    # we must have at least all or none set
   5.257 +    set_user = args.user != ''
   5.258 +    set_ip = args.ip != ''
   5.259 +    set_command = args.command != ''
   5.260 +    set_ALL = set_user and set_ip and set_command
   5.261 +    set_NONE = (not set_user) and (not set_ip) and (not set_command)
   5.262 +    if (not set_ALL) and (not set_NONE):
   5.263 +        sys.stderr.write("Please specify user, ip and command or none.\n")
   5.264 +        sys.stderr.write("Type '--help' for help.\n")
   5.265 +        sys.exit(1)
   5.266 +        
   5.267 +    # check if we need to ask the user
   5.268 +    if set_NONE:
   5.269 +        args.user, args.ip, args.command = ask_user()
   5.270 +        
   5.271 +    # still no IP? --> no chance, over and out!
   5.272 +    if args.ip == '':
   5.273 +        sys.exit(0)
   5.274 +        
   5.275 +    # ensure we have our X11 running
   5.276 +    Cygwin.start_X11()
   5.277 +    
   5.278 +    # the SSH command
   5.279 +    user_at_guest = args.user + '@' + args.ip
   5.280 +    ssh = 'DISPLAY=:0 /usr/bin/ssh -Y ' + user_at_guest + ' ' + args.command
   5.281 +    print(ssh)
   5.282 +    
   5.283 +    # off we go!
   5.284 +    Cygwin()(['/bin/bash', '--login', '-i', '-c', ssh], None, None, None)
   5.285 +
   5.286 +    
   5.287 +# start
   5.288 +if __name__ == "__main__":
   5.289 +    main()
   5.290 +
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/OpenSecurity/bin/opensecurity_client_restful_server.py	Fri Dec 06 12:10:30 2013 +0100
     6.3 @@ -0,0 +1,215 @@
     6.4 +#!/bin/env python
     6.5 +# -*- coding: utf-8 -*-
     6.6 +
     6.7 +# ------------------------------------------------------------
     6.8 +# opensecurity_client_restful_server
     6.9 +# 
    6.10 +# the OpenSecurity client RESTful server
    6.11 +#
    6.12 +# Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
    6.13 +#
    6.14 +# Copyright (C) 2013 AIT Austrian Institute of Technology
    6.15 +# AIT Austrian Institute of Technology GmbH
    6.16 +# Donau-City-Strasse 1 | 1220 Vienna | Austria
    6.17 +# http://www.ait.ac.at
    6.18 +#
    6.19 +# This program is free software; you can redistribute it and/or
    6.20 +# modify it under the terms of the GNU General Public License
    6.21 +# as published by the Free Software Foundation version 2.
    6.22 +# 
    6.23 +# This program is distributed in the hope that it will be useful,
    6.24 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.25 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    6.26 +# GNU General Public License for more details.
    6.27 +# 
    6.28 +# You should have received a copy of the GNU General Public License
    6.29 +# along with this program; if not, write to the Free Software
    6.30 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, 
    6.31 +# Boston, MA  02110-1301, USA.
    6.32 +# ------------------------------------------------------------
    6.33 +
    6.34 +
    6.35 +# ------------------------------------------------------------
    6.36 +# imports
    6.37 +
    6.38 +import os
    6.39 +import os.path
    6.40 +import subprocess
    6.41 +import sys
    6.42 +import web
    6.43 +
    6.44 +# local
    6.45 +from environment import Environment
    6.46 +import opensecurity_server
    6.47 +
    6.48 +
    6.49 +# ------------------------------------------------------------
    6.50 +# const
    6.51 +
    6.52 +
    6.53 +__version__ = "0.1"
    6.54 +
    6.55 +
    6.56 +"""All the URLs we know mapping to class handler"""
    6.57 +opensecurity_urls = (
    6.58 +    '/application',             'os_application',
    6.59 +    '/credentials',             'os_credentials',
    6.60 +    '/password',                'os_password',
    6.61 +    '/',                        'os_root'
    6.62 +)
    6.63 +
    6.64 +
    6.65 +# ------------------------------------------------------------
    6.66 +# code
    6.67 +
    6.68 +
    6.69 +class os_application:
    6.70 +    """OpenSecurity '/application' handler.
    6.71 +    
    6.72 +    This is called on GET /application?vm=VM-ID&app=APP-ID
    6.73 +    This tries to access the vm identified with the label VM-ID
    6.74 +    and launched the application identified APP-ID
    6.75 +    """
    6.76 +    
    6.77 +    def GET(self):
    6.78 +        
    6.79 +        # pick the arguments
    6.80 +        args = web.input()
    6.81 +        
    6.82 +        # we _need_ a vm
    6.83 +        if not "vm" in args:
    6.84 +            raise web.badrequest()
    6.85 +        
    6.86 +        # we _need_ a app
    6.87 +        if not "app" in args:
    6.88 +            raise web.badrequest()
    6.89 +        
    6.90 +        apps = opensecurity_server.query_apps()
    6.91 +        vms = opensecurity_server.query_vms()
    6.92 +        
    6.93 +        # check if we do have valid vm
    6.94 +        v = [v for v in vms if v['name'] == args.vm]
    6.95 +        if len(v) == 0:
    6.96 +            raise web.notfound('vm not found')
    6.97 +        v = v[0]
    6.98 +        
    6.99 +        # check if we do have a valid app
   6.100 +        a = [a for a in apps if a['name'] == args.app]
   6.101 +        if len(a) == 0:
   6.102 +            raise web.notfound('app not found')
   6.103 +        a = a[0]
   6.104 +        
   6.105 +        # invoke launch with 
   6.106 +        res = "starting: launch " + v['user'] + " " + v['ip'] + " " + a['command']
   6.107 +
   6.108 +        launch_image = os.path.join(sys.path[0], 'launch.py')
   6.109 +        process_command = [sys.executable, launch_image, v['user'], v['ip'], a['command']]
   6.110 +        process = subprocess.Popen(process_command, shell = False, stdout = subprocess.PIPE)
   6.111 +        result = process.communicate()[0]
   6.112 +        if process.returncode != 0:
   6.113 +            return 'Launch of application aborted.'
   6.114 +        
   6.115 +        return result
   6.116 +        
   6.117 +
   6.118 +class os_credentials:
   6.119 +    """OpenSecurity '/credentials' handler.
   6.120 +    
   6.121 +    This is called on GET /credentials?text=TEXT.
   6.122 +    Ideally this should pop up a user dialog to insert his
   6.123 +    credentials based the given TEXT.
   6.124 +    """
   6.125 +    
   6.126 +    def GET(self):
   6.127 +        
   6.128 +        # pick the arguments
   6.129 +        args = web.input()
   6.130 +        
   6.131 +        # we _need_ a device id
   6.132 +        if not "text" in args:
   6.133 +            raise web.badrequest()
   6.134 +        
   6.135 +        # invoke the user dialog as a subprocess
   6.136 +        dlg_credentials_image = os.path.join(sys.path[0], 'opensecurity_dialog.py')
   6.137 +        process_command = [sys.executable, dlg_credentials_image, 'credentials', args.text]
   6.138 +        process = subprocess.Popen(process_command, shell = False, stdout = subprocess.PIPE)
   6.139 +        result = process.communicate()[0]
   6.140 +        if process.returncode != 0:
   6.141 +            return 'Credentials request has been aborted.'
   6.142 +        
   6.143 +        return result
   6.144 +
   6.145 +
   6.146 +class os_password:
   6.147 +    """OpenSecurity '/password' handler.
   6.148 +    
   6.149 +    This is called on GET /password?text=TEXT.
   6.150 +    Ideally this should pop up a user dialog to insert his
   6.151 +    password based device name.
   6.152 +    """
   6.153 +    
   6.154 +    def GET(self):
   6.155 +        
   6.156 +        # pick the arguments
   6.157 +        args = web.input()
   6.158 +        
   6.159 +        # we _need_ a device id
   6.160 +        if not "text" in args:
   6.161 +            raise web.badrequest()
   6.162 +            
   6.163 +        # invoke the user dialog as a subprocess
   6.164 +        dlg_credentials_image = os.path.join(sys.path[0], 'opensecurity_dialog.py')
   6.165 +        process_command = [sys.executable, dlg_credentials_image, 'password', args.text]
   6.166 +        process = subprocess.Popen(process_command, shell = False, stdout = subprocess.PIPE)
   6.167 +        result = process.communicate()[0]
   6.168 +        if process.returncode != 0:
   6.169 +            return 'password request has been aborted.'
   6.170 +        
   6.171 +        return result
   6.172 +
   6.173 +
   6.174 +class os_root:
   6.175 +    """OpenSecurity '/' handler"""
   6.176 +    
   6.177 +    def GET(self):
   6.178 +    
   6.179 +        res = "OpenSecurity-Client RESTFul Server { \"version\": \"%s\" }" % __version__
   6.180 +        
   6.181 +        # add some sample links
   6.182 +        res = res + """
   6.183 +        
   6.184 +USAGE EXAMPLES:
   6.185 +        
   6.186 +Request a password: 
   6.187 +    (copy paste this into your browser's address field after the host:port)
   6.188 +    
   6.189 +    /password?text=Give+me+a+password+for+device+%22My+USB+Drive%22+(ID%3A+32090-AAA-X0)
   6.190 +    
   6.191 +    (eg.: http://127.0.0.1:8090/password?text=Give+me+a+password+for+device+%22My+USB+Drive%22+(ID%3A+32090-AAA-X0))
   6.192 +    NOTE: check yout taskbar, the dialog window may not pop up in front of your browser window.
   6.193 +    
   6.194 +    
   6.195 +Request a combination of user and password:
   6.196 +    (copy paste this into your browser's address field after the host:port)
   6.197 +    
   6.198 +    /credentials?text=Tell+the+NSA+which+credentials+to+use+in+order+to+avoid+hacking+noise+on+wire.
   6.199 +    
   6.200 +    (eg.: http://127.0.0.1:8090/credentials?text=Tell+the+NSA+which+credentials+to+use+in+order+to+avoid+hacking+noise+on+wire.)
   6.201 +    NOTE: check yout taskbar, the dialog window may not pop up in front of your browser window.
   6.202 +    
   6.203 +
   6.204 +Start a Browser:
   6.205 +    (copy paste this into your browser's address field after the host:port)
   6.206 +
   6.207 +    /application?vm=Debian+7&app=Browser
   6.208 +
   6.209 +    (e.g. http://127.0.0.1:8090/application?vm=Debian+7&app=Browser)
   6.210 +        """
   6.211 +    
   6.212 +        return res
   6.213 +
   6.214 +
   6.215 +# start
   6.216 +if __name__ == "__main__":
   6.217 +    server = web.application(opensecurity_urls, globals())
   6.218 +    server.run()
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/OpenSecurity/bin/opensecurity_dialog.py	Fri Dec 06 12:10:30 2013 +0100
     7.3 @@ -0,0 +1,93 @@
     7.4 +#!/bin/env python
     7.5 +# -*- coding: utf-8 -*-
     7.6 +
     7.7 +# ------------------------------------------------------------
     7.8 +# opensecurity-dialog
     7.9 +# 
    7.10 +# an opensecurity dialog
    7.11 +#
    7.12 +# Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
    7.13 +#
    7.14 +# Copyright (C) 2013 AIT Austrian Institute of Technology
    7.15 +# AIT Austrian Institute of Technology GmbH
    7.16 +# Donau-City-Strasse 1 | 1220 Vienna | Austria
    7.17 +# http://www.ait.ac.at
    7.18 +#
    7.19 +# This program is free software; you can redistribute it and/or
    7.20 +# modify it under the terms of the GNU General Public License
    7.21 +# as published by the Free Software Foundation version 2.
    7.22 +# 
    7.23 +# This program is distributed in the hope that it will be useful,
    7.24 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
    7.25 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    7.26 +# GNU General Public License for more details.
    7.27 +# 
    7.28 +# You should have received a copy of the GNU General Public License
    7.29 +# along with this program; if not, write to the Free Software
    7.30 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, 
    7.31 +# Boston, MA  02110-1301, USA.
    7.32 +# ------------------------------------------------------------
    7.33 +
    7.34 +
    7.35 +# ------------------------------------------------------------
    7.36 +# imports
    7.37 +
    7.38 +import argparse
    7.39 +import os
    7.40 +import sys
    7.41 +
    7.42 +from PyQt4 import QtCore
    7.43 +from PyQt4 import QtGui
    7.44 +
    7.45 +# local
    7.46 +from credentials import Credentials
    7.47 +from environment import Environment
    7.48 +from password import Password
    7.49 +
    7.50 +
    7.51 +# ------------------------------------------------------------
    7.52 +# code
    7.53 +
    7.54 +
    7.55 +def main():
    7.56 +    
    7.57 +    # parse command line
    7.58 +    parser = argparse.ArgumentParser(description = 'OpenSecurity Dialog.')
    7.59 +    parser.add_argument('mode', metavar='MODE', help='dialog mode: \'password\' or \'credentials\'')
    7.60 +    parser.add_argument('text', metavar='TEXT', help='text to show')
    7.61 +    args = parser.parse_args()
    7.62 +    
    7.63 +    app = QtGui.QApplication(sys.argv)
    7.64 +    
    7.65 +    # prebuild the pixmap cache: fetch all jpg, png and jpeg images and load them
    7.66 +    data_path = Environment("OpenSecurity").data_path
    7.67 +    image_path = os.path.join(data_path, '..', 'gfx')
    7.68 +    for file in os.listdir(image_path):
    7.69 +        if file.lower().rpartition('.')[2] in ('jpg', 'png', 'jpeg'):
    7.70 +            QtGui.QPixmapCache.insert(file.lower().rpartition('.')[0], QtGui.QPixmap(os.path.join(image_path, file)))
    7.71 +            
    7.72 +    # we should have now our application icon
    7.73 +    app.setWindowIcon(QtGui.QIcon(QtGui.QPixmapCache.find('opensecurity_icon_64')))
    7.74 +    
    7.75 +    if args.mode == 'password':
    7.76 +        dlg = Password(args.text)
    7.77 +    
    7.78 +    if args.mode == 'credentials':
    7.79 +        dlg = Credentials(args.text)
    7.80 +    
    7.81 +    # pop up the dialog
    7.82 +    dlg.show()
    7.83 +    app.exec_()
    7.84 +    
    7.85 +    # give proper result code
    7.86 +    if dlg.result() == QtGui.QDialog.Accepted:
    7.87 +        res = 0
    7.88 +    else:
    7.89 +        res = 1
    7.90 +    sys.exit(res)
    7.91 +    
    7.92 +
    7.93 +# start
    7.94 +if __name__ == "__main__":
    7.95 +    main()
    7.96 +
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/OpenSecurity/bin/opensecurity_server.py	Fri Dec 06 12:10:30 2013 +0100
     8.3 @@ -0,0 +1,71 @@
     8.4 +#!/bin/env python
     8.5 +# -*- coding: utf-8 -*-
     8.6 +
     8.7 +# ------------------------------------------------------------
     8.8 +# opensecurity-server
     8.9 +# 
    8.10 +# talk to the opensecurity server
    8.11 +#
    8.12 +# Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
    8.13 +#
    8.14 +# Copyright (C) 2013 AIT Austrian Institute of Technology
    8.15 +# AIT Austrian Institute of Technology GmbH
    8.16 +# Donau-City-Strasse 1 | 1220 Vienna | Austria
    8.17 +# http://www.ait.ac.at
    8.18 +#
    8.19 +# This program is free software; you can redistribute it and/or
    8.20 +# modify it under the terms of the GNU General Public License
    8.21 +# as published by the Free Software Foundation version 2.
    8.22 +# 
    8.23 +# This program is distributed in the hope that it will be useful,
    8.24 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
    8.25 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    8.26 +# GNU General Public License for more details.
    8.27 +# 
    8.28 +# You should have received a copy of the GNU General Public License
    8.29 +# along with this program; if not, write to the Free Software
    8.30 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, 
    8.31 +# Boston, MA  02110-1301, USA.
    8.32 +# ------------------------------------------------------------
    8.33 +
    8.34 +# ------------------------------------------------------------
    8.35 +# import
    8.36 +
    8.37 +from pprint import PrettyPrinter
    8.38 +
    8.39 +
    8.40 +# ------------------------------------------------------------
    8.41 +# code
    8.42 +
    8.43 +def query_apps():
    8.44 +    """get the list of known apps"""
    8.45 +    
    8.46 +    # TODO: REPLACE THIS HARDCODED STUFF WITH REAL CODE TO THE OS SERVER
    8.47 +    apps = [ 
    8.48 +        { 'vm': 'Debian 7', 'name': 'Browser', 'command': '/usr/bin/iceweasel'}, 
    8.49 +        { 'vm': 'Debian 7', 'name': 'VLC', 'command': '/usr/bin/vlc'}
    8.50 +    ]
    8.51 +    
    8.52 +    return apps
    8.53 +    
    8.54 +
    8.55 +def query_vms():
    8.56 +    """get the list of registered vms, their ip and the prefered user"""
    8.57 +    
    8.58 +    # TODO: REPLACE THIS HARDCODED STUFF WITH REAL CODE TO THE OS SERVER
    8.59 +    vms = [ 
    8.60 +        { 'user': 'user', 'name': 'Debian 7', 'ip': '192.168.56.101'}, 
    8.61 +        { 'user': 'user', 'name': 'Anit-Virus VM', 'ip': '192.168.56.101'}
    8.62 +    ]
    8.63 +    
    8.64 +    return vms
    8.65 +
    8.66 +    
    8.67 +# start
    8.68 +if __name__ == "__main__":
    8.69 +    print("known apps: ")
    8.70 +    PrettyPrinter().pprint(query_apps())
    8.71 +    print("known vms: ")
    8.72 +    PrettyPrinter().pprint(query_vms())
    8.73 +    
    8.74 +
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/OpenSecurity/bin/opensecurity_tray.py	Fri Dec 06 12:10:30 2013 +0100
     9.3 @@ -0,0 +1,131 @@
     9.4 +#!/bin/env python
     9.5 +# -*- coding: utf-8 -*-
     9.6 +
     9.7 +# ------------------------------------------------------------
     9.8 +# opensecurity-dialog
     9.9 +# 
    9.10 +# an opensecurity dialog
    9.11 +#
    9.12 +# Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
    9.13 +#
    9.14 +# Copyright (C) 2013 AIT Austrian Institute of Technology
    9.15 +# AIT Austrian Institute of Technology GmbH
    9.16 +# Donau-City-Strasse 1 | 1220 Vienna | Austria
    9.17 +# http://www.ait.ac.at
    9.18 +#
    9.19 +# This program is free software; you can redistribute it and/or
    9.20 +# modify it under the terms of the GNU General Public License
    9.21 +# as published by the Free Software Foundation version 2.
    9.22 +# 
    9.23 +# This program is distributed in the hope that it will be useful,
    9.24 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
    9.25 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    9.26 +# GNU General Public License for more details.
    9.27 +# 
    9.28 +# You should have received a copy of the GNU General Public License
    9.29 +# along with this program; if not, write to the Free Software
    9.30 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, 
    9.31 +# Boston, MA  02110-1301, USA.
    9.32 +# ------------------------------------------------------------
    9.33 +
    9.34 +
    9.35 +# ------------------------------------------------------------
    9.36 +# imports
    9.37 +
    9.38 +import argparse
    9.39 +import os
    9.40 +import subprocess
    9.41 +import sys
    9.42 +
    9.43 +from PyQt4 import QtCore
    9.44 +from PyQt4 import QtGui
    9.45 +
    9.46 +# local
    9.47 +from about import About
    9.48 +from environment import Environment
    9.49 +
    9.50 +
    9.51 +# ------------------------------------------------------------
    9.52 +# code
    9.53 +
    9.54 +
    9.55 +class OpenSecurityTrayIcon(QtGui.QSystemTrayIcon):
    9.56 +    
    9.57 +    """This is the OpenSecuirty Tray Icon"""
    9.58 +
    9.59 +    def __init__(self, icon, parent=None):
    9.60 +        
    9.61 +        super(OpenSecurityTrayIcon, self).__init__(icon, parent)
    9.62 +        self.setup_ui()
    9.63 +        
    9.64 +        
    9.65 +    def clicked_about(self):
    9.66 +        """clicked about"""
    9.67 +        dlgAbout = About()
    9.68 +        dlgAbout.exec_()
    9.69 +    
    9.70 +
    9.71 +    def clicked_exit(self):
    9.72 +        """clicked exit"""
    9.73 +        sys.exit(0)
    9.74 +    
    9.75 +
    9.76 +    def clicked_launch_application(self):
    9.77 +        """clicked the launch an application"""
    9.78 +        dlg_launch_image = os.path.join(sys.path[0], 'launch.pyw')
    9.79 +        process_command = [sys.executable, dlg_launch_image]
    9.80 +        print(process_command)
    9.81 +        process = subprocess.Popen(process_command, shell = False)
    9.82 +        process.communicate()
    9.83 +            
    9.84 +            
    9.85 +    def clicked_refresh(self):
    9.86 +        """clicked refresh"""
    9.87 +        self.setup_ui()
    9.88 +
    9.89 +    
    9.90 +    def setup_ui(self):
    9.91 +        """create the user interface
    9.92 +        As for the system tray this is 'just' the context menu.
    9.93 +        """
    9.94 +    
    9.95 +        # define the tray icon menu
    9.96 +        menu = QtGui.QMenu(self.parent())
    9.97 +        self.setContextMenu(menu)
    9.98 +        
    9.99 +        # add known apps
   9.100 +        
   9.101 +        # add standard menu items
   9.102 +        cAcLaunch = menu.addAction(QtGui.QIcon(QtGui.QPixmapCache.find('opensecurity_icon_64')), 'Lauch Application')
   9.103 +        menu.addSeparator()
   9.104 +        cAcRefresh = menu.addAction('Refresh')
   9.105 +        cAcAbout = menu.addAction("About")
   9.106 +        cAcExit = menu.addAction("Exit")
   9.107 +        
   9.108 +        cAcLaunch.triggered.connect(self.clicked_launch_application)
   9.109 +        cAcRefresh.triggered.connect(self.clicked_refresh)
   9.110 +        cAcAbout.triggered.connect(self.clicked_about)
   9.111 +        cAcExit.triggered.connect(self.clicked_exit)
   9.112 +        
   9.113 +        
   9.114 +def main():
   9.115 +    
   9.116 +    app = QtGui.QApplication(sys.argv)
   9.117 +
   9.118 +    # prebuild the pixmap cache: fetch all jpg, png and jpeg images and load them
   9.119 +    image_path = os.path.join(Environment("OpenSecurity").data_path, '..', 'gfx')
   9.120 +    for file in os.listdir(image_path):
   9.121 +        if file.lower().rpartition('.')[2] in ('jpg', 'png', 'jpeg'):
   9.122 +            QtGui.QPixmapCache.insert(file.lower().rpartition('.')[0], QtGui.QPixmap(os.path.join(image_path, file)))
   9.123 +
   9.124 +    w = QtGui.QWidget()
   9.125 +    trayIcon = OpenSecurityTrayIcon(QtGui.QIcon(QtGui.QPixmapCache.find('opensecurity_icon_64')), w)
   9.126 +
   9.127 +    trayIcon.show()
   9.128 +    sys.exit(app.exec_())
   9.129 +   
   9.130 +
   9.131 +# start
   9.132 +if __name__ == "__main__":
   9.133 +    main()
   9.134 +
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/OpenSecurity/bin/password.py	Fri Dec 06 12:10:30 2013 +0100
    10.3 @@ -0,0 +1,150 @@
    10.4 +#!/bin/env python
    10.5 +# -*- coding: utf-8 -*-
    10.6 +
    10.7 +# ------------------------------------------------------------
    10.8 +# password-dialog
    10.9 +# 
   10.10 +# ask the user a password
   10.11 +#
   10.12 +# Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
   10.13 +#
   10.14 +# Copyright (C) 2013 AIT Austrian Institute of Technology
   10.15 +# AIT Austrian Institute of Technology GmbH
   10.16 +# Donau-City-Strasse 1 | 1220 Vienna | Austria
   10.17 +# http://www.ait.ac.at
   10.18 +#
   10.19 +# This program is free software; you can redistribute it and/or
   10.20 +# modify it under the terms of the GNU General Public License
   10.21 +# as published by the Free Software Foundation version 2.
   10.22 +# 
   10.23 +# This program is distributed in the hope that it will be useful,
   10.24 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
   10.25 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   10.26 +# GNU General Public License for more details.
   10.27 +# 
   10.28 +# You should have received a copy of the GNU General Public License
   10.29 +# along with this program; if not, write to the Free Software
   10.30 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, 
   10.31 +# Boston, MA  02110-1301, USA.
   10.32 +# ------------------------------------------------------------
   10.33 +
   10.34 +
   10.35 +# ------------------------------------------------------------
   10.36 +# imports
   10.37 +
   10.38 +import sys
   10.39 +
   10.40 +from PyQt4 import QtCore
   10.41 +from PyQt4 import QtGui
   10.42 +
   10.43 +# local
   10.44 +from about import About
   10.45 +
   10.46 +# ------------------------------------------------------------
   10.47 +# code
   10.48 +
   10.49 +
   10.50 +class Password(QtGui.QDialog):
   10.51 +    
   10.52 +    """Ask the user for a password."""
   10.53 +    
   10.54 +    def __init__(self, text, parent = None, flags = QtCore.Qt.WindowFlags(0)):
   10.55 +        
   10.56 +        # super call and widget init
   10.57 +        super(Password, self).__init__(parent, flags)
   10.58 +        self.setWindowTitle('OpenSecuirty Password Request')
   10.59 +        self.setup_ui()
   10.60 +        
   10.61 +        # positionate ourself central
   10.62 +        screen = QtGui.QDesktopWidget().screenGeometry()
   10.63 +        self.resize(self.geometry().width() * 1.25, self.geometry().height())
   10.64 +        size = self.geometry()
   10.65 +        self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2)
   10.66 +        
   10.67 +        # fix up text
   10.68 +        self.lbText.setText(text)
   10.69 +        
   10.70 +
   10.71 +    def clicked_about(self):
   10.72 +        """clicked the about button"""
   10.73 +        dlgAbout = About()
   10.74 +        dlgAbout.exec_()
   10.75 +    
   10.76 +
   10.77 +    def clicked_cancel(self):
   10.78 +        """clicked the cancel button"""
   10.79 +        self.reject()
   10.80 +    
   10.81 +
   10.82 +    def clicked_ok(self):
   10.83 +        """clicked the ok button"""
   10.84 +        sys.stdout.write('{ ')
   10.85 +        sys.stdout.write('\'password\': \'')
   10.86 +        sys.stdout.write(self.edPassword.text())
   10.87 +        sys.stdout.write('\' ')
   10.88 +        sys.stdout.write('}\n')
   10.89 +        self.accept()
   10.90 +    
   10.91 +
   10.92 +    def setup_ui(self):
   10.93 +        
   10.94 +        """Create the widgets."""
   10.95 +        
   10.96 +        lyMain = QtGui.QVBoxLayout(self)
   10.97 +        lyMain.setContentsMargins(8, 8, 8, 8)
   10.98 +        
   10.99 +        # content area: left pixmap, right text
  10.100 +        lyContent = QtGui.QHBoxLayout()
  10.101 +        lyMain.addLayout(lyContent)
  10.102 +        
  10.103 +        # pixmap
  10.104 +        lbPix = QtGui.QLabel()
  10.105 +        lbPix.setPixmap(QtGui.QPixmapCache.find('opensecurity_icon_64'))
  10.106 +        lyContent.addWidget(lbPix, 0, QtCore.Qt.Alignment(QtCore.Qt.AlignTop + QtCore.Qt.AlignHCenter))
  10.107 +        lyContent.addSpacing(16)
  10.108 +        
  10.109 +        # text ...
  10.110 +        lyText = QtGui.QVBoxLayout()
  10.111 +        lyContent.addLayout(lyText)
  10.112 +        self.lbText = QtGui.QLabel()
  10.113 +        lyText.addWidget(self.lbText)
  10.114 +        lyPassword = QtGui.QHBoxLayout()
  10.115 +        lyText.addLayout(lyPassword)
  10.116 +        lbPassword = QtGui.QLabel('&Password:')
  10.117 +        lyPassword.addWidget(lbPassword)
  10.118 +        self.edPassword = QtGui.QLineEdit()
  10.119 +        self.edPassword.setEchoMode(QtGui.QLineEdit.Password)
  10.120 +        lyPassword.addWidget(self.edPassword)
  10.121 +        lbPassword.setBuddy(self.edPassword)
  10.122 +        lyText.addStretch(1)
  10.123 +        
  10.124 +        lyMain.addStretch(1)
  10.125 +        
  10.126 +        # buttons
  10.127 +        lyButton = QtGui.QHBoxLayout()
  10.128 +        lyMain.addLayout(lyButton)
  10.129 +        
  10.130 +        lyButton.addStretch(1)
  10.131 +        btnOk = QtGui.QPushButton('&Ok', self)
  10.132 +        btnOk.setDefault(True)
  10.133 +        btnOk.setMinimumWidth(100)
  10.134 +        lyButton.addWidget(btnOk)
  10.135 +        btnCancel = QtGui.QPushButton('&Cancel', self)
  10.136 +        btnCancel.setMinimumWidth(100)
  10.137 +        lyButton.addWidget(btnCancel)
  10.138 +        btnAbout = QtGui.QPushButton('&About', self)
  10.139 +        btnAbout.setMinimumWidth(100)
  10.140 +        lyButton.addWidget(btnAbout)
  10.141 +        
  10.142 +        button_width = max(btnOk.width(), btnCancel.width(), btnAbout.width())
  10.143 +        btnOk.setMinimumWidth(button_width)
  10.144 +        btnCancel.setMinimumWidth(button_width)
  10.145 +        btnAbout.setMinimumWidth(button_width)
  10.146 +        
  10.147 +        # reduce to the max
  10.148 +        self.resize(lyMain.minimumSize())
  10.149 +        
  10.150 +        # connectors
  10.151 +        btnOk.clicked.connect(self.clicked_ok)
  10.152 +        btnCancel.clicked.connect(self.clicked_cancel)
  10.153 +        btnAbout.clicked.connect(self.clicked_about)
    11.1 --- a/OpenSecurity/client/about.py	Fri Dec 06 10:47:26 2013 +0100
    11.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.3 @@ -1,126 +0,0 @@
    11.4 -#!/bin/env python
    11.5 -# -*- coding: utf-8 -*-
    11.6 -
    11.7 -# ------------------------------------------------------------
    11.8 -# about-dialog
    11.9 -# 
   11.10 -# tell the user about the project
   11.11 -#
   11.12 -# Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
   11.13 -#
   11.14 -# Copyright (C) 2013 AIT Austrian Institute of Technology
   11.15 -# AIT Austrian Institute of Technology GmbH
   11.16 -# Donau-City-Strasse 1 | 1220 Vienna | Austria
   11.17 -# http://www.ait.ac.at
   11.18 -#
   11.19 -# This program is free software; you can redistribute it and/or
   11.20 -# modify it under the terms of the GNU General Public License
   11.21 -# as published by the Free Software Foundation version 2.
   11.22 -# 
   11.23 -# This program is distributed in the hope that it will be useful,
   11.24 -# but WITHOUT ANY WARRANTY; without even the implied warranty of
   11.25 -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   11.26 -# GNU General Public License for more details.
   11.27 -# 
   11.28 -# You should have received a copy of the GNU General Public License
   11.29 -# along with this program; if not, write to the Free Software
   11.30 -# Foundation, Inc., 51 Franklin Street, Fifth Floor, 
   11.31 -# Boston, MA  02110-1301, USA.
   11.32 -# ------------------------------------------------------------
   11.33 -
   11.34 -
   11.35 -# ------------------------------------------------------------
   11.36 -# imports
   11.37 -
   11.38 -import os
   11.39 -
   11.40 -from PyQt4 import QtCore
   11.41 -from PyQt4 import QtGui
   11.42 -
   11.43 -# local
   11.44 -from environment import Environment
   11.45 -
   11.46 -# ------------------------------------------------------------
   11.47 -# vars
   11.48 -
   11.49 -
   11.50 -ABOUT_TEXT = """
   11.51 -<html>
   11.52 -<body bgcolor="#FFFFFF">
   11.53 -
   11.54 -<div align="center">
   11.55 -<p/>
   11.56 -<img src="image:ait_logo_no_claim.png"/>
   11.57 -<p/>
   11.58 -<h1>OpenSecurity</h1>
   11.59 -<p/>
   11.60 -</div>
   11.61 -<p/>
   11.62 -Blah ...<br/>
   11.63 -
   11.64 -<p>
   11.65 -Copyright (C) 2013, AIT Austrian Institute of Technology<br/>
   11.66 -AIT Austrian Institute of Technology GmbH<br/>
   11.67 -Donau-City-Strasse 1 | 1220 Vienna | Austria<br/>
   11.68 -<a href="http://www.ait.ac.at">http://www.ait.ac.at</a>
   11.69 -</p>
   11.70 -</div>
   11.71 -
   11.72 -</body>
   11.73 -</html>
   11.74 -""";
   11.75 -
   11.76 -
   11.77 -# ------------------------------------------------------------
   11.78 -# code
   11.79 -
   11.80 -
   11.81 -class About(QtGui.QDialog):
   11.82 -    
   11.83 -    """Show some about stuff."""
   11.84 -    
   11.85 -    def __init__(self, parent = None, flags = QtCore.Qt.WindowFlags(0)):
   11.86 -        
   11.87 -        # super call and widget init
   11.88 -        super(About, self).__init__(parent, flags)
   11.89 -        
   11.90 -        # setup image search path
   11.91 -        QtCore.QDir.setSearchPaths("image", QtCore.QStringList(os.path.join(Environment('opensecurity').data_path, '..', 'gfx')));
   11.92 -        
   11.93 -        self.setWindowTitle('About OpenSecuirty ...')
   11.94 -        self.setup_ui()
   11.95 -        
   11.96 -
   11.97 -    def setup_ui(self):
   11.98 -        
   11.99 -        """Create the widgets."""
  11.100 -        
  11.101 -        lyMain = QtGui.QVBoxLayout(self)
  11.102 -        lyMain.setContentsMargins(8, 8, 8, 8)
  11.103 -        
  11.104 -        lbAbout = QtGui.QLabel()
  11.105 -        lbAbout.setStyleSheet("QWidget { background: white; color: black; };")
  11.106 -        lbAbout.setText(ABOUT_TEXT)
  11.107 -        lbAbout.setContentsMargins(12, 12, 12, 12)
  11.108 -        
  11.109 -        scAbout = QtGui.QScrollArea()
  11.110 -        scAbout.setWidget(lbAbout)
  11.111 -        scAbout.viewport().setStyleSheet("QWidget { background: white; color: black; };")
  11.112 -        lyMain.addWidget(scAbout)
  11.113 -        
  11.114 -        # buttons
  11.115 -        lyButton = QtGui.QHBoxLayout()
  11.116 -        lyMain.addLayout(lyButton)
  11.117 -        
  11.118 -        lyButton.addStretch(1)
  11.119 -        btnOk = QtGui.QPushButton('&Ok', self)
  11.120 -        btnOk.setMinimumWidth(100)
  11.121 -        lyButton.addWidget(btnOk)
  11.122 -        
  11.123 -        # connectors
  11.124 -        btnOk.clicked.connect(self.accept)
  11.125 -        
  11.126 -        # reduce to the max
  11.127 -        self.setMinimumSize(400, 200)
  11.128 -        self.resize(lyMain.minimumSize())
  11.129 -
    12.1 --- a/OpenSecurity/client/credentials.py	Fri Dec 06 10:47:26 2013 +0100
    12.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.3 @@ -1,160 +0,0 @@
    12.4 -#!/bin/env python
    12.5 -# -*- coding: utf-8 -*-
    12.6 -
    12.7 -# ------------------------------------------------------------
    12.8 -# credentials-dialog
    12.9 -# 
   12.10 -# ask the user credentials
   12.11 -#
   12.12 -# Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
   12.13 -#
   12.14 -# Copyright (C) 2013 AIT Austrian Institute of Technology
   12.15 -# AIT Austrian Institute of Technology GmbH
   12.16 -# Donau-City-Strasse 1 | 1220 Vienna | Austria
   12.17 -# http://www.ait.ac.at
   12.18 -#
   12.19 -# This program is free software; you can redistribute it and/or
   12.20 -# modify it under the terms of the GNU General Public License
   12.21 -# as published by the Free Software Foundation version 2.
   12.22 -# 
   12.23 -# This program is distributed in the hope that it will be useful,
   12.24 -# but WITHOUT ANY WARRANTY; without even the implied warranty of
   12.25 -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12.26 -# GNU General Public License for more details.
   12.27 -# 
   12.28 -# You should have received a copy of the GNU General Public License
   12.29 -# along with this program; if not, write to the Free Software
   12.30 -# Foundation, Inc., 51 Franklin Street, Fifth Floor, 
   12.31 -# Boston, MA  02110-1301, USA.
   12.32 -# ------------------------------------------------------------
   12.33 -
   12.34 -
   12.35 -# ------------------------------------------------------------
   12.36 -# imports
   12.37 -
   12.38 -import sys
   12.39 -
   12.40 -from PyQt4 import QtCore
   12.41 -from PyQt4 import QtGui
   12.42 -
   12.43 -# local
   12.44 -from about import About
   12.45 -
   12.46 -# ------------------------------------------------------------
   12.47 -# code
   12.48 -
   12.49 -
   12.50 -class Credentials(QtGui.QDialog):
   12.51 -    
   12.52 -    """Ask the user for credentials."""
   12.53 -    
   12.54 -    def __init__(self, text, parent = None, flags = QtCore.Qt.WindowFlags(0)):
   12.55 -        
   12.56 -        super(Credentials, self).__init__(parent, flags)
   12.57 -        self.setWindowTitle('OpenSecuirty Credentials Request')
   12.58 -        self.setup_ui()
   12.59 -        
   12.60 -        # positionate ourself central
   12.61 -        screen = QtGui.QDesktopWidget().screenGeometry()
   12.62 -        self.resize(self.geometry().width() * 1.25, self.geometry().height())
   12.63 -        size = self.geometry()
   12.64 -        self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2)
   12.65 -        
   12.66 -        # fix up text
   12.67 -        self.lbText.setText(text)
   12.68 -        
   12.69 -
   12.70 -    def clicked_about(self):
   12.71 -        """clicked the about button"""
   12.72 -        dlgAbout = About()
   12.73 -        dlgAbout.exec_()
   12.74 -    
   12.75 -
   12.76 -    def clicked_cancel(self):
   12.77 -        """clicked the cancel button"""
   12.78 -        self.reject()
   12.79 -    
   12.80 -
   12.81 -    def clicked_ok(self):
   12.82 -        """clicked the ok button"""
   12.83 -        sys.stdout.write('{ ')
   12.84 -        sys.stdout.write('\'user\': \'')
   12.85 -        sys.stdout.write(self.edUser.text())
   12.86 -        sys.stdout.write('\', ')
   12.87 -        sys.stdout.write('\'password\': \'')
   12.88 -        sys.stdout.write(self.edPassword.text())
   12.89 -        sys.stdout.write('\' ')
   12.90 -        sys.stdout.write('}\n')
   12.91 -        self.accept()
   12.92 -    
   12.93 -
   12.94 -    def setup_ui(self):
   12.95 -        
   12.96 -        """Create the widgets."""
   12.97 -        
   12.98 -        lyMain = QtGui.QVBoxLayout(self)
   12.99 -        lyMain.setContentsMargins(8, 8, 8, 8)
  12.100 -        
  12.101 -        # content area: left pixmap, right text
  12.102 -        lyContent = QtGui.QHBoxLayout()
  12.103 -        lyMain.addLayout(lyContent)
  12.104 -        
  12.105 -        # pixmap
  12.106 -        lbPix = QtGui.QLabel()
  12.107 -        lbPix.setPixmap(QtGui.QPixmapCache.find('opensecurity_icon_64'))
  12.108 -        lyContent.addWidget(lbPix, 0, QtCore.Qt.Alignment(QtCore.Qt.AlignTop + QtCore.Qt.AlignHCenter))
  12.109 -        lyContent.addSpacing(16)
  12.110 -        
  12.111 -        # text ...
  12.112 -        lyText = QtGui.QGridLayout()
  12.113 -        lyContent.addLayout(lyText)
  12.114 -        self.lbText = QtGui.QLabel()
  12.115 -        lyText.addWidget(self.lbText, 0, 0, 1, 2)
  12.116 -        
  12.117 -        lbUser = QtGui.QLabel('&User:')
  12.118 -        lyText.addWidget(lbUser, 1, 0)
  12.119 -        self.edUser = QtGui.QLineEdit()
  12.120 -        lyText.addWidget(self.edUser, 1, 1)
  12.121 -        lbUser.setBuddy(self.edUser)
  12.122 -        
  12.123 -        lbPassword = QtGui.QLabel('&Password:')
  12.124 -        lyText.addWidget(lbPassword, 2, 0)
  12.125 -        self.edPassword = QtGui.QLineEdit()
  12.126 -        self.edPassword.setEchoMode(QtGui.QLineEdit.Password)
  12.127 -        lyText.addWidget(self.edPassword, 2, 1)
  12.128 -        lbPassword.setBuddy(self.edPassword)
  12.129 -        
  12.130 -        lyText.addWidget(QtGui.QWidget(), 3, 0, 1, 2)
  12.131 -        lyText.setColumnStretch(1, 1)
  12.132 -        lyText.setRowStretch(3, 1)
  12.133 -        
  12.134 -        lyMain.addStretch(1)
  12.135 -        
  12.136 -        # buttons
  12.137 -        lyButton = QtGui.QHBoxLayout()
  12.138 -        lyMain.addLayout(lyButton)
  12.139 -        
  12.140 -        lyButton.addStretch(1)
  12.141 -        btnOk = QtGui.QPushButton('&Ok', self)
  12.142 -        btnOk.setDefault(True)
  12.143 -        btnOk.setMinimumWidth(100)
  12.144 -        lyButton.addWidget(btnOk)
  12.145 -        btnCancel = QtGui.QPushButton('&Cancel', self)
  12.146 -        btnCancel.setMinimumWidth(100)
  12.147 -        lyButton.addWidget(btnCancel)
  12.148 -        btnAbout = QtGui.QPushButton('&About', self)
  12.149 -        btnAbout.setMinimumWidth(100)
  12.150 -        lyButton.addWidget(btnAbout)
  12.151 -        
  12.152 -        button_width = max(btnOk.width(), btnCancel.width(), btnAbout.width())
  12.153 -        btnOk.setMinimumWidth(button_width)
  12.154 -        btnCancel.setMinimumWidth(button_width)
  12.155 -        btnAbout.setMinimumWidth(button_width)
  12.156 -        
  12.157 -        # reduce to the max
  12.158 -        self.resize(lyMain.minimumSize())
  12.159 -        
  12.160 -        # connectors
  12.161 -        btnOk.clicked.connect(self.clicked_ok)
  12.162 -        btnCancel.clicked.connect(self.clicked_cancel)
  12.163 -        btnAbout.clicked.connect(self.clicked_about)
    13.1 --- a/OpenSecurity/client/cygwin.py	Fri Dec 06 10:47:26 2013 +0100
    13.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.3 @@ -1,105 +0,0 @@
    13.4 -#!/bin/env python
    13.5 -# -*- coding: utf-8 -*-
    13.6 -
    13.7 -# ------------------------------------------------------------
    13.8 -# cygwin command
    13.9 -# 
   13.10 -# executes a cygwin command inside the opensecurity project
   13.11 -#
   13.12 -# Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
   13.13 -#
   13.14 -# Copyright (C) 2013 AIT Austrian Institute of Technology
   13.15 -# AIT Austrian Institute of Technology GmbH
   13.16 -# Donau-City-Strasse 1 | 1220 Vienna | Austria
   13.17 -# http://www.ait.ac.at
   13.18 -#
   13.19 -# This program is free software; you can redistribute it and/or
   13.20 -# modify it under the terms of the GNU General Public License
   13.21 -# as published by the Free Software Foundation version 2.
   13.22 -# 
   13.23 -# This program is distributed in the hope that it will be useful,
   13.24 -# but WITHOUT ANY WARRANTY; without even the implied warranty of
   13.25 -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13.26 -# GNU General Public License for more details.
   13.27 -# 
   13.28 -# You should have received a copy of the GNU General Public License
   13.29 -# along with this program; if not, write to the Free Software
   13.30 -# Foundation, Inc., 51 Franklin Street, Fifth Floor, 
   13.31 -# Boston, MA  02110-1301, USA.
   13.32 -# ------------------------------------------------------------
   13.33 -
   13.34 -
   13.35 -# ------------------------------------------------------------
   13.36 -# imports
   13.37 -
   13.38 -import os
   13.39 -import subprocess
   13.40 -import sys
   13.41 -
   13.42 -# local
   13.43 -from environment import Environment
   13.44 -
   13.45 -
   13.46 -# ------------------------------------------------------------
   13.47 -# code
   13.48 -
   13.49 -
   13.50 -class Cygwin(object):
   13.51 -
   13.52 -    """Some nifty methods working with Cygwin"""
   13.53 -    
   13.54 -    def __call__(self, command, stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE):
   13.55 -        """make an instance of this object act as a function"""
   13.56 -        return self.execute(command, stdin, stdout, stderr)
   13.57 -
   13.58 -        
   13.59 -    @staticmethod
   13.60 -    def root():
   13.61 -        """get the path to our local cygwin installment"""
   13.62 -        return os.path.join(Environment('OpenSecurity').prefix_path, '..', 'cygwin')
   13.63 -
   13.64 -
   13.65 -    def execute(self, command, stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE):
   13.66 -        """execute a cygwin shell command
   13.67 -        
   13.68 -        command is list of arguments like ['/bin/ls', '-al', '-h']
   13.69 -        
   13.70 -        a Popen object is returned"""
   13.71 -        command_path = Cygwin.root() + os.sep.join(command[0].split('/'))
   13.72 -        command = [command_path] + command[1:]
   13.73 -        
   13.74 -        return subprocess.Popen(command, shell = False, stdin = stdin, stdout = stdout, stderr = stderr)
   13.75 -        
   13.76 -        
   13.77 -    @staticmethod
   13.78 -    def is_X11_running():
   13.79 -        """check if we can connect to a X11 running instance"""
   13.80 -        p = Cygwin()(['/bin/bash', '-c', 'DISPLAY=:0 /usr/bin/xset -q'])
   13.81 -        stdout, stderr = p.communicate()
   13.82 -        return p.returncode == 0
   13.83 -        
   13.84 -        
   13.85 -    @staticmethod
   13.86 -    def start_X11():
   13.87 -        """start X11 in the background (if not already running) on DISPLAY=:0"""
   13.88 -        
   13.89 -        # do not start if already running
   13.90 -        if Cygwin.is_X11_running():
   13.91 -            return
   13.92 -            
   13.93 -        # launch X11 (forget output and return immediately)
   13.94 -        p = Cygwin()(['/bin/bash', '--login', '-i', '-c', ' X :0 -multiwindow'], stdin = None, stdout = None, stderr = None)
   13.95 -        
   13.96 -    
   13.97 -# start
   13.98 -if __name__ == "__main__":
   13.99 -
  13.100 -    # execute what is given on the command line
  13.101 -    c = Cygwin()
  13.102 -    p = c(sys.argv[1:])
  13.103 -    
  13.104 -    # wait until the process finished and grab the output
  13.105 -    stdout, stderr = p.communicate()
  13.106 -    print('=== call result on stdout: ===\n' + stdout)
  13.107 -    print('=== call result on stderr: ===\n' + stderr)
  13.108 -    
    14.1 --- a/OpenSecurity/client/environment.py	Fri Dec 06 10:47:26 2013 +0100
    14.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.3 @@ -1,103 +0,0 @@
    14.4 -#!/bin/env python
    14.5 -# -*- coding: utf-8 -*-
    14.6 -
    14.7 -# ------------------------------------------------------------
    14.8 -# environment.py
    14.9 -# 
   14.10 -# pick some current environment infos
   14.11 -#
   14.12 -# Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
   14.13 -#
   14.14 -# Copyright (C) 2013 AIT Austrian Institute of Technology
   14.15 -# AIT Austrian Institute of Technology GmbH
   14.16 -# Donau-City-Strasse 1 | 1220 Vienna | Austria
   14.17 -# http://www.ait.ac.at
   14.18 -#
   14.19 -# This program is free software; you can redistribute it and/or
   14.20 -# modify it under the terms of the GNU General Public License
   14.21 -# as published by the Free Software Foundation version 2.
   14.22 -# 
   14.23 -# This program is distributed in the hope that it will be useful,
   14.24 -# but WITHOUT ANY WARRANTY; without even the implied warranty of
   14.25 -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14.26 -# GNU General Public License for more details.
   14.27 -# 
   14.28 -# You should have received a copy of the GNU General Public License
   14.29 -# along with this program; if not, write to the Free Software
   14.30 -# Foundation, Inc., 51 Franklin Street, Fifth Floor, 
   14.31 -# Boston, MA  02110-1301, USA.
   14.32 -# ------------------------------------------------------------
   14.33 -
   14.34 -
   14.35 -# ------------------------------------------------------------
   14.36 -# imports
   14.37 -
   14.38 -import os
   14.39 -import os.path
   14.40 -import sys
   14.41 -
   14.42 -
   14.43 -# ------------------------------------------------------------
   14.44 -# code
   14.45 -
   14.46 -
   14.47 -class Environment(object):
   14.48 -    
   14.49 -    """Hold some nifty environment stuff in a dedicated class."""
   14.50 -    
   14.51 -    def __init__(self, application = None):
   14.52 -        
   14.53 -        # if we ain't got a path to start from, all is valid/lost
   14.54 -        if len(sys.path[0]) == 0:
   14.55 -            self._prefix_path = ''
   14.56 -            self._data_path = ''
   14.57 -            return
   14.58 -        
   14.59 -        # the prefix path
   14.60 -        #
   14.61 -        # - on Linux: this is ../../ to the current executable
   14.62 -        #   e.g. "/usr/bin/myprogram" --> "/usr"
   14.63 -        #
   14.64 -        # - on Windows (inkl. Cygwin): this is the installation folder
   14.65 -        #   e.g. "C:/Program Files/MyProgram/myprogam" --> "C:/Program Files/MyProgram"
   14.66 -        #
   14.67 -        if sys.platform == 'linux2':
   14.68 -            self._prefix_path = os.path.split(sys.path[0])[0]
   14.69 -        elif sys.platform == 'win32' or sys.platform == 'cygwin':
   14.70 -            self._prefix_path = sys.path[0]
   14.71 -            
   14.72 -        # the data path where all data files are stored
   14.73 -        if sys.platform == 'linux2':
   14.74 -            if not application is None:
   14.75 -                self._data_path = os.path.join(self._prefix_path, os.path.join('share', application))
   14.76 -            else:
   14.77 -                self._data_path = os.path.join(self._prefix_path, 'share')
   14.78 -        elif sys.platform == 'win32' or sys.platform == 'cygwin':
   14.79 -            self._data_path = self._prefix_path
   14.80 -
   14.81 -            
   14.82 -    def data_path_get(self):
   14.83 -        """dat_path get"""
   14.84 -        return self._data_path
   14.85 -        
   14.86 -    data_path = property(data_path_get)
   14.87 -            
   14.88 -            
   14.89 -    def prefix_path_get(self):
   14.90 -        """prefix_path get"""
   14.91 -        return self._prefix_path
   14.92 -        
   14.93 -    prefix_path = property(prefix_path_get)
   14.94 -            
   14.95 -# test method			
   14.96 -def test():
   14.97 -
   14.98 -	"""Test: class Environment"""
   14.99 -	e = Environment('My Application')
  14.100 -	print('prefix_path: "{0}"'.format(e.prefix_path))
  14.101 -	print('  data_path: "{0}"'.format(e.data_path))
  14.102 -			
  14.103 -			
  14.104 -# test the module			
  14.105 -if __name__ == '__main__':
  14.106 -	test()
    15.1 --- a/OpenSecurity/client/launch.py	Fri Dec 06 10:47:26 2013 +0100
    15.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.3 @@ -1,287 +0,0 @@
    15.4 -#!/bin/env python
    15.5 -# -*- coding: utf-8 -*-
    15.6 -
    15.7 -# ------------------------------------------------------------
    15.8 -# opensecurity-launcher
    15.9 -# 
   15.10 -# launches an application inside a VM
   15.11 -#
   15.12 -# Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
   15.13 -#
   15.14 -# Copyright (C) 2013 AIT Austrian Institute of Technology
   15.15 -# AIT Austrian Institute of Technology GmbH
   15.16 -# Donau-City-Strasse 1 | 1220 Vienna | Austria
   15.17 -# http://www.ait.ac.at
   15.18 -#
   15.19 -# This program is free software; you can redistribute it and/or
   15.20 -# modify it under the terms of the GNU General Public License
   15.21 -# as published by the Free Software Foundation version 2.
   15.22 -# 
   15.23 -# This program is distributed in the hope that it will be useful,
   15.24 -# but WITHOUT ANY WARRANTY; without even the implied warranty of
   15.25 -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   15.26 -# GNU General Public License for more details.
   15.27 -# 
   15.28 -# You should have received a copy of the GNU General Public License
   15.29 -# along with this program; if not, write to the Free Software
   15.30 -# Foundation, Inc., 51 Franklin Street, Fifth Floor, 
   15.31 -# Boston, MA  02110-1301, USA.
   15.32 -# ------------------------------------------------------------
   15.33 -
   15.34 -
   15.35 -# ------------------------------------------------------------
   15.36 -# imports
   15.37 -
   15.38 -import argparse
   15.39 -import os
   15.40 -import subprocess
   15.41 -import sys
   15.42 -
   15.43 -from PyQt4 import QtCore
   15.44 -from PyQt4 import QtGui
   15.45 -
   15.46 -# local
   15.47 -from about import About
   15.48 -from cygwin import Cygwin
   15.49 -from environment import Environment
   15.50 -import opensecurity_server
   15.51 -
   15.52 -
   15.53 -# ------------------------------------------------------------
   15.54 -# code
   15.55 -
   15.56 -
   15.57 -class Chooser(QtGui.QDialog, object):
   15.58 -    
   15.59 -    """Ask the user what to launch."""
   15.60 -    
   15.61 -    def __init__(self, parent = None, flags = QtCore.Qt.WindowFlags(0)):
   15.62 -    
   15.63 -        super(Chooser, self).__init__(parent, flags)
   15.64 -        self.setWindowTitle('OpenSecuirty Launch Application')
   15.65 -        self.setup_ui()
   15.66 -        
   15.67 -        # known vms and applications
   15.68 -        self._apps, self_vms = [], []
   15.69 -        
   15.70 -        # positionate ourself central
   15.71 -        screen = QtGui.QDesktopWidget().screenGeometry()
   15.72 -        self.resize(self.geometry().width() * 1.25, self.geometry().height())
   15.73 -        size = self.geometry()
   15.74 -        self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2)
   15.75 -        
   15.76 -        # refresh vm and command input
   15.77 -        self.refresh()
   15.78 -        
   15.79 -        
   15.80 -    def app_get(self):
   15.81 -        """The application of the user."""
   15.82 -        a = str(self._cbApplication.currentText())
   15.83 -        for app in self._apps:
   15.84 -            if a == app['name']:
   15.85 -                return app['command']
   15.86 -        return a
   15.87 -        
   15.88 -    app = property(app_get)
   15.89 -        
   15.90 -
   15.91 -    def clicked_about(self):
   15.92 -        """clicked the about button"""
   15.93 -        dlgAbout = About()
   15.94 -        dlgAbout.exec_()
   15.95 -
   15.96 -
   15.97 -    def clicked_cancel(self):
   15.98 -        """clicked the cancel button"""
   15.99 -        self.reject()
  15.100 -    
  15.101 -
  15.102 -    def clicked_ok(self):
  15.103 -        """clicked the ok button"""
  15.104 -        self.accept()
  15.105 -    
  15.106 -    
  15.107 -    def refresh(self):
  15.108 -        """load the known vms and commands and adjust input fields"""
  15.109 -        
  15.110 -        self._apps = opensecurity_server.query_apps()
  15.111 -        self._vms = opensecurity_server.query_vms()
  15.112 -        
  15.113 -        # add the VMs we know
  15.114 -        self._cbApplication.clear()
  15.115 -        for app in self._apps:
  15.116 -            self._cbApplication.addItem(app['name'])
  15.117 -        
  15.118 -        # add the commands we know
  15.119 -        self._cbVM.clear()
  15.120 -        for vm in self._vms:
  15.121 -            self._cbVM.addItem(vm['name'])
  15.122 -        
  15.123 -        
  15.124 -    def setup_ui(self):
  15.125 -        """Create the widgets."""
  15.126 -        
  15.127 -        lyMain = QtGui.QVBoxLayout(self)
  15.128 -        lyMain.setContentsMargins(8, 8, 8, 8)
  15.129 -        
  15.130 -        # content area: left pixmap, right text
  15.131 -        lyContent = QtGui.QHBoxLayout()
  15.132 -        lyMain.addLayout(lyContent)
  15.133 -        
  15.134 -        # pixmap
  15.135 -        lbPix = QtGui.QLabel()
  15.136 -        lbPix.setPixmap(QtGui.QPixmapCache.find('opensecurity_icon_64'))
  15.137 -        lyContent.addWidget(lbPix, 0, QtCore.Qt.Alignment(QtCore.Qt.AlignTop + QtCore.Qt.AlignHCenter))
  15.138 -        lyContent.addSpacing(16)
  15.139 -        
  15.140 -        # launch ...
  15.141 -        lyLaunch = QtGui.QGridLayout()
  15.142 -        lyContent.addLayout(lyLaunch)
  15.143 -        lbTitle = QtGui.QLabel('Specify details for application to launch.')
  15.144 -        lyLaunch.addWidget(lbTitle, 0, 0, 1, 2)
  15.145 -        
  15.146 -        lbVM = QtGui.QLabel('&VM-ID:')
  15.147 -        lyLaunch.addWidget(lbVM, 1, 0)
  15.148 -        self._cbVM = QtGui.QComboBox()
  15.149 -        self._cbVM.setEditable(True)
  15.150 -        self._cbVM.setInsertPolicy(QtGui.QComboBox.InsertAlphabetically)
  15.151 -        lyLaunch.addWidget(self._cbVM, 1, 1)
  15.152 -        lbVM.setBuddy(self._cbVM)
  15.153 -        
  15.154 -        lbApplication = QtGui.QLabel('&Application:')
  15.155 -        lyLaunch.addWidget(lbApplication, 2, 0)
  15.156 -        self._cbApplication = QtGui.QComboBox()
  15.157 -        self._cbApplication.setEditable(True)
  15.158 -        self._cbApplication.setInsertPolicy(QtGui.QComboBox.InsertAlphabetically)
  15.159 -        lyLaunch.addWidget(self._cbApplication, 2, 1)
  15.160 -        lbApplication.setBuddy(self._cbApplication)
  15.161 -        
  15.162 -        lyLaunch.addWidget(QtGui.QWidget(), 3, 0, 1, 2)
  15.163 -        lyLaunch.setColumnStretch(1, 1)
  15.164 -        lyLaunch.setRowStretch(3, 1)
  15.165 -        
  15.166 -        lyMain.addStretch(1)
  15.167 -        
  15.168 -        # buttons
  15.169 -        lyButton = QtGui.QHBoxLayout()
  15.170 -        lyMain.addLayout(lyButton)
  15.171 -        
  15.172 -        lyButton.addStretch(1)
  15.173 -        btnOk = QtGui.QPushButton('&Ok', self)
  15.174 -        btnOk.setDefault(True)
  15.175 -        btnOk.setMinimumWidth(100)
  15.176 -        lyButton.addWidget(btnOk)
  15.177 -        btnCancel = QtGui.QPushButton('&Cancel', self)
  15.178 -        btnCancel.setMinimumWidth(100)
  15.179 -        lyButton.addWidget(btnCancel)
  15.180 -        btnAbout = QtGui.QPushButton('&About', self)
  15.181 -        btnAbout.setMinimumWidth(100)
  15.182 -        lyButton.addWidget(btnAbout)
  15.183 -        
  15.184 -        button_width = max(btnOk.width(), btnCancel.width(), btnAbout.width())
  15.185 -        btnOk.setMinimumWidth(button_width)
  15.186 -        btnCancel.setMinimumWidth(button_width)
  15.187 -        btnAbout.setMinimumWidth(button_width)
  15.188 -        
  15.189 -        # reduce to the max
  15.190 -        self.resize(lyMain.minimumSize())
  15.191 -        
  15.192 -        # connectors
  15.193 -        btnOk.clicked.connect(self.clicked_ok)
  15.194 -        btnCancel.clicked.connect(self.clicked_cancel)
  15.195 -        btnAbout.clicked.connect(self.clicked_about)
  15.196 -
  15.197 -        
  15.198 -    def user_get(self):
  15.199 -        """The user of the vm of choice."""
  15.200 -        v = str(self._cbVM.currentText())
  15.201 -        for vm in self._vms:
  15.202 -            if v == vm['name']:
  15.203 -                return vm['user']
  15.204 -        return v
  15.205 -        
  15.206 -    user = property(user_get)
  15.207 -    
  15.208 -    
  15.209 -    def vm_get(self):
  15.210 -        """The vm of choice."""
  15.211 -        v = str(self._cbVM.currentText())
  15.212 -        for vm in self._vms:
  15.213 -            if v == vm['name']:
  15.214 -                return vm['ip']
  15.215 -        return v
  15.216 -        
  15.217 -    vm = property(vm_get)
  15.218 -        
  15.219 -        
  15.220 -def ask_user():
  15.221 -    """ask the user for VM and app to start"""
  15.222 -    
  15.223 -    # launch Qt
  15.224 -    app = QtGui.QApplication(sys.argv)
  15.225 -    
  15.226 -    # prebuild the pixmap cache: fetch all jpg, png and jpeg images and load them
  15.227 -    image_path = os.path.join(Environment("OpenSecurity").data_path, '..', 'gfx')
  15.228 -    for file in os.listdir(image_path):
  15.229 -        if file.lower().rpartition('.')[2] in ('jpg', 'png', 'jpeg'):
  15.230 -            QtGui.QPixmapCache.insert(file.lower().rpartition('.')[0], QtGui.QPixmap(os.path.join(image_path, file)))
  15.231 -            
  15.232 -    # we should have now our application icon
  15.233 -    app.setWindowIcon(QtGui.QIcon(QtGui.QPixmapCache.find('opensecurity_icon_64')))
  15.234 -    
  15.235 -    # pop up the dialog
  15.236 -    dlg = Chooser()
  15.237 -    dlg.show()
  15.238 -    app.exec_()
  15.239 -    
  15.240 -    if dlg.result() == QtGui.QDialog.Accepted:
  15.241 -        return dlg.user, dlg.vm, dlg.app
  15.242 -
  15.243 -    return '', '', ''
  15.244 -    
  15.245 -
  15.246 -def main():
  15.247 -    """entry point"""
  15.248 -    
  15.249 -    # parse command line
  15.250 -    parser = argparse.ArgumentParser(description = 'OpenSecurity Launcher: run application in VM')
  15.251 -    parser.add_argument('user', metavar='USER', help='USER on Virtual Machine', nargs='?', type=str, default='')
  15.252 -    parser.add_argument('ip', metavar='IP', help='IP of Virtual Machine', nargs='?', type=str, default='')
  15.253 -    parser.add_argument('command', metavar='COMMAND', help='Full path of command and arguments to start inside VM', nargs='?', type=str, default='')
  15.254 -    args = parser.parse_args()
  15.255 -    
  15.256 -    # we must have at least all or none set
  15.257 -    set_user = args.user != ''
  15.258 -    set_ip = args.ip != ''
  15.259 -    set_command = args.command != ''
  15.260 -    set_ALL = set_user and set_ip and set_command
  15.261 -    set_NONE = (not set_user) and (not set_ip) and (not set_command)
  15.262 -    if (not set_ALL) and (not set_NONE):
  15.263 -        sys.stderr.write("Please specify user, ip and command or none.\n")
  15.264 -        sys.stderr.write("Type '--help' for help.\n")
  15.265 -        sys.exit(1)
  15.266 -        
  15.267 -    # check if we need to ask the user
  15.268 -    if set_NONE:
  15.269 -        args.user, args.ip, args.command = ask_user()
  15.270 -        
  15.271 -    # still no IP? --> no chance, over and out!
  15.272 -    if args.ip == '':
  15.273 -        sys.exit(0)
  15.274 -        
  15.275 -    # ensure we have our X11 running
  15.276 -    Cygwin.start_X11()
  15.277 -    
  15.278 -    # the SSH command
  15.279 -    user_at_guest = args.user + '@' + args.ip
  15.280 -    ssh = 'DISPLAY=:0 /usr/bin/ssh -Y ' + user_at_guest + ' ' + args.command
  15.281 -    print(ssh)
  15.282 -    
  15.283 -    # off we go!
  15.284 -    Cygwin()(['/bin/bash', '--login', '-i', '-c', ssh], None, None, None)
  15.285 -
  15.286 -    
  15.287 -# start
  15.288 -if __name__ == "__main__":
  15.289 -    main()
  15.290 -
    16.1 --- a/OpenSecurity/client/opensecurity_client_restful_server.py	Fri Dec 06 10:47:26 2013 +0100
    16.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.3 @@ -1,215 +0,0 @@
    16.4 -#!/bin/env python
    16.5 -# -*- coding: utf-8 -*-
    16.6 -
    16.7 -# ------------------------------------------------------------
    16.8 -# opensecurity_client_restful_server
    16.9 -# 
   16.10 -# the OpenSecurity client RESTful server
   16.11 -#
   16.12 -# Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
   16.13 -#
   16.14 -# Copyright (C) 2013 AIT Austrian Institute of Technology
   16.15 -# AIT Austrian Institute of Technology GmbH
   16.16 -# Donau-City-Strasse 1 | 1220 Vienna | Austria
   16.17 -# http://www.ait.ac.at
   16.18 -#
   16.19 -# This program is free software; you can redistribute it and/or
   16.20 -# modify it under the terms of the GNU General Public License
   16.21 -# as published by the Free Software Foundation version 2.
   16.22 -# 
   16.23 -# This program is distributed in the hope that it will be useful,
   16.24 -# but WITHOUT ANY WARRANTY; without even the implied warranty of
   16.25 -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   16.26 -# GNU General Public License for more details.
   16.27 -# 
   16.28 -# You should have received a copy of the GNU General Public License
   16.29 -# along with this program; if not, write to the Free Software
   16.30 -# Foundation, Inc., 51 Franklin Street, Fifth Floor, 
   16.31 -# Boston, MA  02110-1301, USA.
   16.32 -# ------------------------------------------------------------
   16.33 -
   16.34 -
   16.35 -# ------------------------------------------------------------
   16.36 -# imports
   16.37 -
   16.38 -import os
   16.39 -import os.path
   16.40 -import subprocess
   16.41 -import sys
   16.42 -import web
   16.43 -
   16.44 -# local
   16.45 -from environment import Environment
   16.46 -import opensecurity_server
   16.47 -
   16.48 -
   16.49 -# ------------------------------------------------------------
   16.50 -# const
   16.51 -
   16.52 -
   16.53 -__version__ = "0.1"
   16.54 -
   16.55 -
   16.56 -"""All the URLs we know mapping to class handler"""
   16.57 -opensecurity_urls = (
   16.58 -    '/application',             'os_application',
   16.59 -    '/credentials',             'os_credentials',
   16.60 -    '/password',                'os_password',
   16.61 -    '/',                        'os_root'
   16.62 -)
   16.63 -
   16.64 -
   16.65 -# ------------------------------------------------------------
   16.66 -# code
   16.67 -
   16.68 -
   16.69 -class os_application:
   16.70 -    """OpenSecurity '/application' handler.
   16.71 -    
   16.72 -    This is called on GET /application?vm=VM-ID&app=APP-ID
   16.73 -    This tries to access the vm identified with the label VM-ID
   16.74 -    and launched the application identified APP-ID
   16.75 -    """
   16.76 -    
   16.77 -    def GET(self):
   16.78 -        
   16.79 -        # pick the arguments
   16.80 -        args = web.input()
   16.81 -        
   16.82 -        # we _need_ a vm
   16.83 -        if not "vm" in args:
   16.84 -            raise web.badrequest()
   16.85 -        
   16.86 -        # we _need_ a app
   16.87 -        if not "app" in args:
   16.88 -            raise web.badrequest()
   16.89 -        
   16.90 -        apps = opensecurity_server.query_apps()
   16.91 -        vms = opensecurity_server.query_vms()
   16.92 -        
   16.93 -        # check if we do have valid vm
   16.94 -        v = [v for v in vms if v['name'] == args.vm]
   16.95 -        if len(v) == 0:
   16.96 -            raise web.notfound('vm not found')
   16.97 -        v = v[0]
   16.98 -        
   16.99 -        # check if we do have a valid app
  16.100 -        a = [a for a in apps if a['name'] == args.app]
  16.101 -        if len(a) == 0:
  16.102 -            raise web.notfound('app not found')
  16.103 -        a = a[0]
  16.104 -        
  16.105 -        # invoke launch with 
  16.106 -        res = "starting: launch " + v['user'] + " " + v['ip'] + " " + a['command']
  16.107 -
  16.108 -        launch_image = os.path.join(sys.path[0], 'launch.py')
  16.109 -        process_command = [sys.executable, launch_image, v['user'], v['ip'], a['command']]
  16.110 -        process = subprocess.Popen(process_command, shell = False, stdout = subprocess.PIPE)
  16.111 -        result = process.communicate()[0]
  16.112 -        if process.returncode != 0:
  16.113 -            return 'Launch of application aborted.'
  16.114 -        
  16.115 -        return result
  16.116 -        
  16.117 -
  16.118 -class os_credentials:
  16.119 -    """OpenSecurity '/credentials' handler.
  16.120 -    
  16.121 -    This is called on GET /credentials?text=TEXT.
  16.122 -    Ideally this should pop up a user dialog to insert his
  16.123 -    credentials based the given TEXT.
  16.124 -    """
  16.125 -    
  16.126 -    def GET(self):
  16.127 -        
  16.128 -        # pick the arguments
  16.129 -        args = web.input()
  16.130 -        
  16.131 -        # we _need_ a device id
  16.132 -        if not "text" in args:
  16.133 -            raise web.badrequest()
  16.134 -        
  16.135 -        # invoke the user dialog as a subprocess
  16.136 -        dlg_credentials_image = os.path.join(sys.path[0], 'opensecurity_dialog.py')
  16.137 -        process_command = [sys.executable, dlg_credentials_image, 'credentials', args.text]
  16.138 -        process = subprocess.Popen(process_command, shell = False, stdout = subprocess.PIPE)
  16.139 -        result = process.communicate()[0]
  16.140 -        if process.returncode != 0:
  16.141 -            return 'Credentials request has been aborted.'
  16.142 -        
  16.143 -        return result
  16.144 -
  16.145 -
  16.146 -class os_password:
  16.147 -    """OpenSecurity '/password' handler.
  16.148 -    
  16.149 -    This is called on GET /password?text=TEXT.
  16.150 -    Ideally this should pop up a user dialog to insert his
  16.151 -    password based device name.
  16.152 -    """
  16.153 -    
  16.154 -    def GET(self):
  16.155 -        
  16.156 -        # pick the arguments
  16.157 -        args = web.input()
  16.158 -        
  16.159 -        # we _need_ a device id
  16.160 -        if not "text" in args:
  16.161 -            raise web.badrequest()
  16.162 -            
  16.163 -        # invoke the user dialog as a subprocess
  16.164 -        dlg_credentials_image = os.path.join(sys.path[0], 'opensecurity_dialog.py')
  16.165 -        process_command = [sys.executable, dlg_credentials_image, 'password', args.text]
  16.166 -        process = subprocess.Popen(process_command, shell = False, stdout = subprocess.PIPE)
  16.167 -        result = process.communicate()[0]
  16.168 -        if process.returncode != 0:
  16.169 -            return 'password request has been aborted.'
  16.170 -        
  16.171 -        return result
  16.172 -
  16.173 -
  16.174 -class os_root:
  16.175 -    """OpenSecurity '/' handler"""
  16.176 -    
  16.177 -    def GET(self):
  16.178 -    
  16.179 -        res = "OpenSecurity-Client RESTFul Server { \"version\": \"%s\" }" % __version__
  16.180 -        
  16.181 -        # add some sample links
  16.182 -        res = res + """
  16.183 -        
  16.184 -USAGE EXAMPLES:
  16.185 -        
  16.186 -Request a password: 
  16.187 -    (copy paste this into your browser's address field after the host:port)
  16.188 -    
  16.189 -    /password?text=Give+me+a+password+for+device+%22My+USB+Drive%22+(ID%3A+32090-AAA-X0)
  16.190 -    
  16.191 -    (eg.: http://127.0.0.1:8090/password?text=Give+me+a+password+for+device+%22My+USB+Drive%22+(ID%3A+32090-AAA-X0))
  16.192 -    NOTE: check yout taskbar, the dialog window may not pop up in front of your browser window.
  16.193 -    
  16.194 -    
  16.195 -Request a combination of user and password:
  16.196 -    (copy paste this into your browser's address field after the host:port)
  16.197 -    
  16.198 -    /credentials?text=Tell+the+NSA+which+credentials+to+use+in+order+to+avoid+hacking+noise+on+wire.
  16.199 -    
  16.200 -    (eg.: http://127.0.0.1:8090/credentials?text=Tell+the+NSA+which+credentials+to+use+in+order+to+avoid+hacking+noise+on+wire.)
  16.201 -    NOTE: check yout taskbar, the dialog window may not pop up in front of your browser window.
  16.202 -    
  16.203 -
  16.204 -Start a Browser:
  16.205 -    (copy paste this into your browser's address field after the host:port)
  16.206 -
  16.207 -    /application?vm=Debian+7&app=Browser
  16.208 -
  16.209 -    (e.g. http://127.0.0.1:8090/application?vm=Debian+7&app=Browser)
  16.210 -        """
  16.211 -    
  16.212 -        return res
  16.213 -
  16.214 -
  16.215 -# start
  16.216 -if __name__ == "__main__":
  16.217 -    server = web.application(opensecurity_urls, globals())
  16.218 -    server.run()
    17.1 --- a/OpenSecurity/client/opensecurity_dialog.py	Fri Dec 06 10:47:26 2013 +0100
    17.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.3 @@ -1,93 +0,0 @@
    17.4 -#!/bin/env python
    17.5 -# -*- coding: utf-8 -*-
    17.6 -
    17.7 -# ------------------------------------------------------------
    17.8 -# opensecurity-dialog
    17.9 -# 
   17.10 -# an opensecurity dialog
   17.11 -#
   17.12 -# Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
   17.13 -#
   17.14 -# Copyright (C) 2013 AIT Austrian Institute of Technology
   17.15 -# AIT Austrian Institute of Technology GmbH
   17.16 -# Donau-City-Strasse 1 | 1220 Vienna | Austria
   17.17 -# http://www.ait.ac.at
   17.18 -#
   17.19 -# This program is free software; you can redistribute it and/or
   17.20 -# modify it under the terms of the GNU General Public License
   17.21 -# as published by the Free Software Foundation version 2.
   17.22 -# 
   17.23 -# This program is distributed in the hope that it will be useful,
   17.24 -# but WITHOUT ANY WARRANTY; without even the implied warranty of
   17.25 -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   17.26 -# GNU General Public License for more details.
   17.27 -# 
   17.28 -# You should have received a copy of the GNU General Public License
   17.29 -# along with this program; if not, write to the Free Software
   17.30 -# Foundation, Inc., 51 Franklin Street, Fifth Floor, 
   17.31 -# Boston, MA  02110-1301, USA.
   17.32 -# ------------------------------------------------------------
   17.33 -
   17.34 -
   17.35 -# ------------------------------------------------------------
   17.36 -# imports
   17.37 -
   17.38 -import argparse
   17.39 -import os
   17.40 -import sys
   17.41 -
   17.42 -from PyQt4 import QtCore
   17.43 -from PyQt4 import QtGui
   17.44 -
   17.45 -# local
   17.46 -from credentials import Credentials
   17.47 -from environment import Environment
   17.48 -from password import Password
   17.49 -
   17.50 -
   17.51 -# ------------------------------------------------------------
   17.52 -# code
   17.53 -
   17.54 -
   17.55 -def main():
   17.56 -    
   17.57 -    # parse command line
   17.58 -    parser = argparse.ArgumentParser(description = 'OpenSecurity Dialog.')
   17.59 -    parser.add_argument('mode', metavar='MODE', help='dialog mode: \'password\' or \'credentials\'')
   17.60 -    parser.add_argument('text', metavar='TEXT', help='text to show')
   17.61 -    args = parser.parse_args()
   17.62 -    
   17.63 -    app = QtGui.QApplication(sys.argv)
   17.64 -    
   17.65 -    # prebuild the pixmap cache: fetch all jpg, png and jpeg images and load them
   17.66 -    data_path = Environment("OpenSecurity").data_path
   17.67 -    image_path = os.path.join(data_path, '..', 'gfx')
   17.68 -    for file in os.listdir(image_path):
   17.69 -        if file.lower().rpartition('.')[2] in ('jpg', 'png', 'jpeg'):
   17.70 -            QtGui.QPixmapCache.insert(file.lower().rpartition('.')[0], QtGui.QPixmap(os.path.join(image_path, file)))
   17.71 -            
   17.72 -    # we should have now our application icon
   17.73 -    app.setWindowIcon(QtGui.QIcon(QtGui.QPixmapCache.find('opensecurity_icon_64')))
   17.74 -    
   17.75 -    if args.mode == 'password':
   17.76 -        dlg = Password(args.text)
   17.77 -    
   17.78 -    if args.mode == 'credentials':
   17.79 -        dlg = Credentials(args.text)
   17.80 -    
   17.81 -    # pop up the dialog
   17.82 -    dlg.show()
   17.83 -    app.exec_()
   17.84 -    
   17.85 -    # give proper result code
   17.86 -    if dlg.result() == QtGui.QDialog.Accepted:
   17.87 -        res = 0
   17.88 -    else:
   17.89 -        res = 1
   17.90 -    sys.exit(res)
   17.91 -    
   17.92 -
   17.93 -# start
   17.94 -if __name__ == "__main__":
   17.95 -    main()
   17.96 -
    18.1 --- a/OpenSecurity/client/opensecurity_server.py	Fri Dec 06 10:47:26 2013 +0100
    18.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.3 @@ -1,71 +0,0 @@
    18.4 -#!/bin/env python
    18.5 -# -*- coding: utf-8 -*-
    18.6 -
    18.7 -# ------------------------------------------------------------
    18.8 -# opensecurity-server
    18.9 -# 
   18.10 -# talk to the opensecurity server
   18.11 -#
   18.12 -# Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
   18.13 -#
   18.14 -# Copyright (C) 2013 AIT Austrian Institute of Technology
   18.15 -# AIT Austrian Institute of Technology GmbH
   18.16 -# Donau-City-Strasse 1 | 1220 Vienna | Austria
   18.17 -# http://www.ait.ac.at
   18.18 -#
   18.19 -# This program is free software; you can redistribute it and/or
   18.20 -# modify it under the terms of the GNU General Public License
   18.21 -# as published by the Free Software Foundation version 2.
   18.22 -# 
   18.23 -# This program is distributed in the hope that it will be useful,
   18.24 -# but WITHOUT ANY WARRANTY; without even the implied warranty of
   18.25 -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18.26 -# GNU General Public License for more details.
   18.27 -# 
   18.28 -# You should have received a copy of the GNU General Public License
   18.29 -# along with this program; if not, write to the Free Software
   18.30 -# Foundation, Inc., 51 Franklin Street, Fifth Floor, 
   18.31 -# Boston, MA  02110-1301, USA.
   18.32 -# ------------------------------------------------------------
   18.33 -
   18.34 -# ------------------------------------------------------------
   18.35 -# import
   18.36 -
   18.37 -from pprint import PrettyPrinter
   18.38 -
   18.39 -
   18.40 -# ------------------------------------------------------------
   18.41 -# code
   18.42 -
   18.43 -def query_apps():
   18.44 -    """get the list of known apps"""
   18.45 -    
   18.46 -    # TODO: REPLACE THIS HARDCODED STUFF WITH REAL CODE TO THE OS SERVER
   18.47 -    apps = [ 
   18.48 -        { 'vm': 'Debian 7', 'name': 'Browser', 'command': '/usr/bin/iceweasel'}, 
   18.49 -        { 'vm': 'Debian 7', 'name': 'VLC', 'command': '/usr/bin/vlc'}
   18.50 -    ]
   18.51 -    
   18.52 -    return apps
   18.53 -    
   18.54 -
   18.55 -def query_vms():
   18.56 -    """get the list of registered vms, their ip and the prefered user"""
   18.57 -    
   18.58 -    # TODO: REPLACE THIS HARDCODED STUFF WITH REAL CODE TO THE OS SERVER
   18.59 -    vms = [ 
   18.60 -        { 'user': 'user', 'name': 'Debian 7', 'ip': '192.168.56.101'}, 
   18.61 -        { 'user': 'user', 'name': 'Anit-Virus VM', 'ip': '192.168.56.101'}
   18.62 -    ]
   18.63 -    
   18.64 -    return vms
   18.65 -
   18.66 -    
   18.67 -# start
   18.68 -if __name__ == "__main__":
   18.69 -    print("known apps: ")
   18.70 -    PrettyPrinter().pprint(query_apps())
   18.71 -    print("known vms: ")
   18.72 -    PrettyPrinter().pprint(query_vms())
   18.73 -    
   18.74 -
    19.1 --- a/OpenSecurity/client/opensecurity_tray.py	Fri Dec 06 10:47:26 2013 +0100
    19.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.3 @@ -1,131 +0,0 @@
    19.4 -#!/bin/env python
    19.5 -# -*- coding: utf-8 -*-
    19.6 -
    19.7 -# ------------------------------------------------------------
    19.8 -# opensecurity-dialog
    19.9 -# 
   19.10 -# an opensecurity dialog
   19.11 -#
   19.12 -# Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
   19.13 -#
   19.14 -# Copyright (C) 2013 AIT Austrian Institute of Technology
   19.15 -# AIT Austrian Institute of Technology GmbH
   19.16 -# Donau-City-Strasse 1 | 1220 Vienna | Austria
   19.17 -# http://www.ait.ac.at
   19.18 -#
   19.19 -# This program is free software; you can redistribute it and/or
   19.20 -# modify it under the terms of the GNU General Public License
   19.21 -# as published by the Free Software Foundation version 2.
   19.22 -# 
   19.23 -# This program is distributed in the hope that it will be useful,
   19.24 -# but WITHOUT ANY WARRANTY; without even the implied warranty of
   19.25 -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   19.26 -# GNU General Public License for more details.
   19.27 -# 
   19.28 -# You should have received a copy of the GNU General Public License
   19.29 -# along with this program; if not, write to the Free Software
   19.30 -# Foundation, Inc., 51 Franklin Street, Fifth Floor, 
   19.31 -# Boston, MA  02110-1301, USA.
   19.32 -# ------------------------------------------------------------
   19.33 -
   19.34 -
   19.35 -# ------------------------------------------------------------
   19.36 -# imports
   19.37 -
   19.38 -import argparse
   19.39 -import os
   19.40 -import subprocess
   19.41 -import sys
   19.42 -
   19.43 -from PyQt4 import QtCore
   19.44 -from PyQt4 import QtGui
   19.45 -
   19.46 -# local
   19.47 -from about import About
   19.48 -from environment import Environment
   19.49 -
   19.50 -
   19.51 -# ------------------------------------------------------------
   19.52 -# code
   19.53 -
   19.54 -
   19.55 -class OpenSecurityTrayIcon(QtGui.QSystemTrayIcon):
   19.56 -    
   19.57 -    """This is the OpenSecuirty Tray Icon"""
   19.58 -
   19.59 -    def __init__(self, icon, parent=None):
   19.60 -        
   19.61 -        super(OpenSecurityTrayIcon, self).__init__(icon, parent)
   19.62 -        self.setup_ui()
   19.63 -        
   19.64 -        
   19.65 -    def clicked_about(self):
   19.66 -        """clicked about"""
   19.67 -        dlgAbout = About()
   19.68 -        dlgAbout.exec_()
   19.69 -    
   19.70 -
   19.71 -    def clicked_exit(self):
   19.72 -        """clicked exit"""
   19.73 -        sys.exit(0)
   19.74 -    
   19.75 -
   19.76 -    def clicked_launch_application(self):
   19.77 -        """clicked the launch an application"""
   19.78 -        dlg_launch_image = os.path.join(sys.path[0], 'launch.pyw')
   19.79 -        process_command = [sys.executable, dlg_launch_image]
   19.80 -        print(process_command)
   19.81 -        process = subprocess.Popen(process_command, shell = False)
   19.82 -        process.communicate()
   19.83 -            
   19.84 -            
   19.85 -    def clicked_refresh(self):
   19.86 -        """clicked refresh"""
   19.87 -        self.setup_ui()
   19.88 -
   19.89 -    
   19.90 -    def setup_ui(self):
   19.91 -        """create the user interface
   19.92 -        As for the system tray this is 'just' the context menu.
   19.93 -        """
   19.94 -    
   19.95 -        # define the tray icon menu
   19.96 -        menu = QtGui.QMenu(self.parent())
   19.97 -        self.setContextMenu(menu)
   19.98 -        
   19.99 -        # add known apps
  19.100 -        
  19.101 -        # add standard menu items
  19.102 -        cAcLaunch = menu.addAction(QtGui.QIcon(QtGui.QPixmapCache.find('opensecurity_icon_64')), 'Lauch Application')
  19.103 -        menu.addSeparator()
  19.104 -        cAcRefresh = menu.addAction('Refresh')
  19.105 -        cAcAbout = menu.addAction("About")
  19.106 -        cAcExit = menu.addAction("Exit")
  19.107 -        
  19.108 -        cAcLaunch.triggered.connect(self.clicked_launch_application)
  19.109 -        cAcRefresh.triggered.connect(self.clicked_refresh)
  19.110 -        cAcAbout.triggered.connect(self.clicked_about)
  19.111 -        cAcExit.triggered.connect(self.clicked_exit)
  19.112 -        
  19.113 -        
  19.114 -def main():
  19.115 -    
  19.116 -    app = QtGui.QApplication(sys.argv)
  19.117 -
  19.118 -    # prebuild the pixmap cache: fetch all jpg, png and jpeg images and load them
  19.119 -    image_path = os.path.join(Environment("OpenSecurity").data_path, '..', 'gfx')
  19.120 -    for file in os.listdir(image_path):
  19.121 -        if file.lower().rpartition('.')[2] in ('jpg', 'png', 'jpeg'):
  19.122 -            QtGui.QPixmapCache.insert(file.lower().rpartition('.')[0], QtGui.QPixmap(os.path.join(image_path, file)))
  19.123 -
  19.124 -    w = QtGui.QWidget()
  19.125 -    trayIcon = OpenSecurityTrayIcon(QtGui.QIcon(QtGui.QPixmapCache.find('opensecurity_icon_64')), w)
  19.126 -
  19.127 -    trayIcon.show()
  19.128 -    sys.exit(app.exec_())
  19.129 -   
  19.130 -
  19.131 -# start
  19.132 -if __name__ == "__main__":
  19.133 -    main()
  19.134 -
    20.1 --- a/OpenSecurity/client/password.py	Fri Dec 06 10:47:26 2013 +0100
    20.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.3 @@ -1,150 +0,0 @@
    20.4 -#!/bin/env python
    20.5 -# -*- coding: utf-8 -*-
    20.6 -
    20.7 -# ------------------------------------------------------------
    20.8 -# password-dialog
    20.9 -# 
   20.10 -# ask the user a password
   20.11 -#
   20.12 -# Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
   20.13 -#
   20.14 -# Copyright (C) 2013 AIT Austrian Institute of Technology
   20.15 -# AIT Austrian Institute of Technology GmbH
   20.16 -# Donau-City-Strasse 1 | 1220 Vienna | Austria
   20.17 -# http://www.ait.ac.at
   20.18 -#
   20.19 -# This program is free software; you can redistribute it and/or
   20.20 -# modify it under the terms of the GNU General Public License
   20.21 -# as published by the Free Software Foundation version 2.
   20.22 -# 
   20.23 -# This program is distributed in the hope that it will be useful,
   20.24 -# but WITHOUT ANY WARRANTY; without even the implied warranty of
   20.25 -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   20.26 -# GNU General Public License for more details.
   20.27 -# 
   20.28 -# You should have received a copy of the GNU General Public License
   20.29 -# along with this program; if not, write to the Free Software
   20.30 -# Foundation, Inc., 51 Franklin Street, Fifth Floor, 
   20.31 -# Boston, MA  02110-1301, USA.
   20.32 -# ------------------------------------------------------------
   20.33 -
   20.34 -
   20.35 -# ------------------------------------------------------------
   20.36 -# imports
   20.37 -
   20.38 -import sys
   20.39 -
   20.40 -from PyQt4 import QtCore
   20.41 -from PyQt4 import QtGui
   20.42 -
   20.43 -# local
   20.44 -from about import About
   20.45 -
   20.46 -# ------------------------------------------------------------
   20.47 -# code
   20.48 -
   20.49 -
   20.50 -class Password(QtGui.QDialog):
   20.51 -    
   20.52 -    """Ask the user for a password."""
   20.53 -    
   20.54 -    def __init__(self, text, parent = None, flags = QtCore.Qt.WindowFlags(0)):
   20.55 -        
   20.56 -        # super call and widget init
   20.57 -        super(Password, self).__init__(parent, flags)
   20.58 -        self.setWindowTitle('OpenSecuirty Password Request')
   20.59 -        self.setup_ui()
   20.60 -        
   20.61 -        # positionate ourself central
   20.62 -        screen = QtGui.QDesktopWidget().screenGeometry()
   20.63 -        self.resize(self.geometry().width() * 1.25, self.geometry().height())
   20.64 -        size = self.geometry()
   20.65 -        self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2)
   20.66 -        
   20.67 -        # fix up text
   20.68 -        self.lbText.setText(text)
   20.69 -        
   20.70 -
   20.71 -    def clicked_about(self):
   20.72 -        """clicked the about button"""
   20.73 -        dlgAbout = About()
   20.74 -        dlgAbout.exec_()
   20.75 -    
   20.76 -
   20.77 -    def clicked_cancel(self):
   20.78 -        """clicked the cancel button"""
   20.79 -        self.reject()
   20.80 -    
   20.81 -
   20.82 -    def clicked_ok(self):
   20.83 -        """clicked the ok button"""
   20.84 -        sys.stdout.write('{ ')
   20.85 -        sys.stdout.write('\'password\': \'')
   20.86 -        sys.stdout.write(self.edPassword.text())
   20.87 -        sys.stdout.write('\' ')
   20.88 -        sys.stdout.write('}\n')
   20.89 -        self.accept()
   20.90 -    
   20.91 -
   20.92 -    def setup_ui(self):
   20.93 -        
   20.94 -        """Create the widgets."""
   20.95 -        
   20.96 -        lyMain = QtGui.QVBoxLayout(self)
   20.97 -        lyMain.setContentsMargins(8, 8, 8, 8)
   20.98 -        
   20.99 -        # content area: left pixmap, right text
  20.100 -        lyContent = QtGui.QHBoxLayout()
  20.101 -        lyMain.addLayout(lyContent)
  20.102 -        
  20.103 -        # pixmap
  20.104 -        lbPix = QtGui.QLabel()
  20.105 -        lbPix.setPixmap(QtGui.QPixmapCache.find('opensecurity_icon_64'))
  20.106 -        lyContent.addWidget(lbPix, 0, QtCore.Qt.Alignment(QtCore.Qt.AlignTop + QtCore.Qt.AlignHCenter))
  20.107 -        lyContent.addSpacing(16)
  20.108 -        
  20.109 -        # text ...
  20.110 -        lyText = QtGui.QVBoxLayout()
  20.111 -        lyContent.addLayout(lyText)
  20.112 -        self.lbText = QtGui.QLabel()
  20.113 -        lyText.addWidget(self.lbText)
  20.114 -        lyPassword = QtGui.QHBoxLayout()
  20.115 -        lyText.addLayout(lyPassword)
  20.116 -        lbPassword = QtGui.QLabel('&Password:')
  20.117 -        lyPassword.addWidget(lbPassword)
  20.118 -        self.edPassword = QtGui.QLineEdit()
  20.119 -        self.edPassword.setEchoMode(QtGui.QLineEdit.Password)
  20.120 -        lyPassword.addWidget(self.edPassword)
  20.121 -        lbPassword.setBuddy(self.edPassword)
  20.122 -        lyText.addStretch(1)
  20.123 -        
  20.124 -        lyMain.addStretch(1)
  20.125 -        
  20.126 -        # buttons
  20.127 -        lyButton = QtGui.QHBoxLayout()
  20.128 -        lyMain.addLayout(lyButton)
  20.129 -        
  20.130 -        lyButton.addStretch(1)
  20.131 -        btnOk = QtGui.QPushButton('&Ok', self)
  20.132 -        btnOk.setDefault(True)
  20.133 -        btnOk.setMinimumWidth(100)
  20.134 -        lyButton.addWidget(btnOk)
  20.135 -        btnCancel = QtGui.QPushButton('&Cancel', self)
  20.136 -        btnCancel.setMinimumWidth(100)
  20.137 -        lyButton.addWidget(btnCancel)
  20.138 -        btnAbout = QtGui.QPushButton('&About', self)
  20.139 -        btnAbout.setMinimumWidth(100)
  20.140 -        lyButton.addWidget(btnAbout)
  20.141 -        
  20.142 -        button_width = max(btnOk.width(), btnCancel.width(), btnAbout.width())
  20.143 -        btnOk.setMinimumWidth(button_width)
  20.144 -        btnCancel.setMinimumWidth(button_width)
  20.145 -        btnAbout.setMinimumWidth(button_width)
  20.146 -        
  20.147 -        # reduce to the max
  20.148 -        self.resize(lyMain.minimumSize())
  20.149 -        
  20.150 -        # connectors
  20.151 -        btnOk.clicked.connect(self.clicked_ok)
  20.152 -        btnCancel.clicked.connect(self.clicked_cancel)
  20.153 -        btnAbout.clicked.connect(self.clicked_about)
    21.1 --- a/OpenSecurity/cygwin64/Cygwin.vbs	Fri Dec 06 10:47:26 2013 +0100
    21.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.3 @@ -1,50 +0,0 @@
    21.4 -Option Explicit
    21.5 -
    21.6 -' ------------------------------------------------------------
    21.7 -' start a cygwin shell
    21.8 -'
    21.9 -' Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
   21.10 -'
   21.11 -' Copyright (C) 2013 AIT Austrian Institute of Technology
   21.12 -' AIT Austrian Institute of Technology GmbH
   21.13 -' Donau-City-Strasse 1 | 1220 Vienna | Austria
   21.14 -' http://www.ait.ac.at
   21.15 -' ------------------------------------------------------------
   21.16 -
   21.17 -' ------------------------------------------------------------
   21.18 -' This starts a cygwin shell within a relocatable cygwin
   21.19 -' folder but without a DOS shell window prior. The idea is
   21.20 -' to do it like in this BAT snippet below:
   21.21 -'
   21.22 -'		@echo off
   21.23 -' 		SET INSTALL_DRIVE=%~d0
   21.24 -' 		SET INSTALL_FOLDER=%~p0
   21.25 -' 		SET CYGWIN_BIN="%INSTALL_DRIVE%%INSTALL_FOLDER%bin"
   21.26 -' 		SET CYGWIN_BASH="%INSTALL_DRIVE%%INSTALL_FOLDER%bin\bash"
   21.27 -' 		%INSTALL_DRIVE%
   21.28 -' 		chdir "%CYGWIN_BIN%"
   21.29 -' 		start mintty.exe %CYGWIN_BASH% --login -i
   21.30 -'
   21.31 -' ------------------------------------------------------------
   21.32 -
   21.33 -' setup the basic objects
   21.34 -Dim cFSO
   21.35 -Dim cShell
   21.36 -Set cShell = CreateObject("WScript.Shell")
   21.37 -Set cFSO = CreateObject("Scripting.FileSystemObject")
   21.38 -
   21.39 -' parse script location and cd into folder
   21.40 -Dim sPath
   21.41 -sPath = Wscript.ScriptFullName
   21.42 -sPath = cFSO.GetAbsolutePathName(sPath)
   21.43 -sPath = cFSO.GetParentFolderName(sPath)
   21.44 -cShell.CurrentDirectory = sPath
   21.45 -
   21.46 -' locations of mintty and bash
   21.47 -Dim sMinTTYPath
   21.48 -Dim sBashPath
   21.49 -sMinTTYPath = """" & sPath & "\bin\mintty" & """"
   21.50 -sBashPath = """" & sPath & "\bin\bash" & """"
   21.51 -
   21.52 -' start a cygwin shell
   21.53 -cShell.Run sMinTTYPath & " " & sBashPath & " --login -i", 1, false
    22.1 --- a/OpenSecurity/cygwin64/content.txt	Fri Dec 06 10:47:26 2013 +0100
    22.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.3 @@ -1,10 +0,0 @@
    22.4 -Content of Opensecurity/cygwin
    22.5 -==============================
    22.6 -
    22.7 -This folder contains a complete Cygwin - 64 Bit with at least these packages installed:
    22.8 -
    22.9 -    - bash
   22.10 -    - coreutils
   22.11 -    - openssh
   22.12 -    - xinit
   22.13 -    - genisofs
    23.1 Binary file OpenSecurity/cygwin64/setup-x86_64.exe has changed