2 # -*- coding: utf-8 -*-
4 # ------------------------------------------------------------
7 # the opensecurityd as RESTful server
9 # Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
11 # Copyright (C) 2013 AIT Austrian Institute of Technology
12 # AIT Austrian Institute of Technology GmbH
13 # Donau-City-Strasse 1 | 1220 Vienna | Austria
14 # http://www.ait.ac.at
16 # This program is free software; you can redistribute it and/or
17 # modify it under the terms of the GNU General Public License
18 # as published by the Free Software Foundation version 2.
20 # This program is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 51 Franklin Street, Fifth Floor,
28 # Boston, MA 02110-1301, USA.
29 # ------------------------------------------------------------
32 # ------------------------------------------------------------
42 from environment import Environment
45 # ------------------------------------------------------------
52 """All the URLs we know mapping to class handler"""
54 '/application', 'os_application',
55 '/device', 'os_device',
56 '/device/credentials', 'os_device_credentials',
57 '/device/password', 'os_device_password',
62 # ------------------------------------------------------------
68 """OpenSecurity '/application' handler.
70 This is called on GET /application?vm=VM-ID&app=APP-ID
71 This tries to access the vm identified with the label VM-ID
72 and launched the application identified APP-ID
82 raise web.badrequest()
86 raise web.badrequest()
88 ## TODO: HARD CODED STUFF HERE! THIS SHOULD BE FLEXIBLE!
89 ssh_private_key = os.path.join(Environment("opensecurity").data_path, 'share', '192.168.56.15.ppk')
90 putty_session = '192.168.56.15'
91 process_command = ['plink.exe', '-i', ssh_private_key, putty_session, args.app]
92 si = subprocess.STARTUPINFO()
93 si.dwFlags = subprocess.STARTF_USESHOWWINDOW
94 si.wShowWindow = subprocess.SW_HIDE
95 print('tyring to launch: ' + ' '.join(process_command))
96 process = subprocess.Popen(process_command, shell = True)
97 return 'launched: ' + ' '.join(process_command)
102 """OpenSecurity '/device' handler"""
108 class os_device_credentials:
110 """OpenSecurity '/device/credentials' handler.
112 This is called on GET /device/credentials?id=DEVICE-ID.
113 Ideally this should pop up a user dialog to insert his
114 credentials based the DEVICE-ID
122 # we _need_ a device id
124 raise web.badrequest()
126 # invoke the user dialog as a subprocess
127 dlg_credentials_image = os.path.join(sys.path[0], 'opensecurity-dialog.py')
128 process_command = [sys.executable, dlg_credentials_image, 'credentials', 'Please provide credentials for accessing \ndevice: "{0}".'.format(args.id)]
129 process = subprocess.Popen(process_command, shell = False, stdout = subprocess.PIPE)
130 result = process.communicate()[0]
131 if process.returncode != 0:
132 return 'Credentials request has been aborted.'
137 class os_device_password:
139 """OpenSecurity '/device/password' handler.
141 This is called on GET /device/password?id=DEVICE-ID.
142 Ideally this should pop up a user dialog to insert his
143 password based the DEVICE-ID
151 # we _need_ a device id
153 raise web.badrequest()
155 # invoke the user dialog as a subprocess
156 dlg_credentials_image = os.path.join(sys.path[0], 'opensecurity-dialog.py')
157 process_command = [sys.executable, dlg_credentials_image, 'password', 'Please provide a password for accessing \ndevice: "{0}".'.format(args.id)]
158 process = subprocess.Popen(process_command, shell = False, stdout = subprocess.PIPE)
159 result = process.communicate()[0]
160 if process.returncode != 0:
161 return 'Credentials request has been aborted.'
168 """OpenSecurity '/' handler"""
171 return "OpenSecurity-Server { \"version\": \"%s\" }" % __version__
175 if __name__ == "__main__":
176 server = web.application(opensecurity_urls, globals())