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 # ------------------------------------------------------------
40 from vmmanager.vmmanager import VMManager
43 from environment import Environment
46 # ------------------------------------------------------------
52 """All the URLs we know mapping to class handler"""
54 '/device_change', 'os_device_change',
55 '/application', 'os_application',
56 '/device', 'os_device',
57 '/device/credentials', 'os_device_credentials',
58 '/device/password', 'os_device_password',
63 # ------------------------------------------------------------
71 """OpenSecurity '/application' handler.
73 This is called on GET /application?vm=VM-ID&app=APP-ID
74 This tries to access the vm identified with the label VM-ID
75 and launched the application identified APP-ID
85 raise web.badrequest()
89 raise web.badrequest()
91 ## TODO: HARD CODED STUFF HERE! THIS SHOULD BE FLEXIBLE!
92 ssh_private_key = os.path.join(Environment("opensecurity").data_path, 'share', '192.168.56.15.ppk')
93 putty_session = '192.168.56.15'
94 process_command = ['plink.exe', '-i', ssh_private_key, putty_session, args.app]
95 si = subprocess.STARTUPINFO()
96 si.dwFlags = subprocess.STARTF_USESHOWWINDOW
97 si.wShowWindow = subprocess.SW_HIDE
98 print('tyring to launch: ' + ' '.join(process_command))
99 process = subprocess.Popen(process_command, shell = True)
100 return 'launched: ' + ' '.join(process_command)
104 """OpenSecurity '/device' handler"""
109 class os_device_change:
111 """OpenSecurity '/device_change' handler"""
114 print 'received device_change'
115 gvm_mgr.cygwin_path = 'c:\\cygwin64\\bin\\'
116 gvm_mgr.handleDeviceChange()
118 #gvm_mgr.configureHostNetworking()
119 return "os_device_change"
122 class os_device_credentials:
124 """OpenSecurity '/device/credentials' handler.
126 This is called on GET /device/credentials?id=DEVICE-ID.
127 Ideally this should pop up a user dialog to insert his
128 credentials based the DEVICE-ID
136 # we _need_ a device id
138 raise web.badrequest()
140 # invoke the user dialog as a subprocess
141 dlg_credentials_image = os.path.join(sys.path[0], 'opensecurity-dialog.py')
142 process_command = [sys.executable, dlg_credentials_image, 'credentials', 'Please provide credentials for accessing \ndevice: "{0}".'.format(args.id)]
143 process = subprocess.Popen(process_command, shell = False, stdout = subprocess.PIPE)
144 result = process.communicate()[0]
145 if process.returncode != 0:
146 return 'Credentials request has been aborted.'
151 class os_device_password:
153 """OpenSecurity '/device/password' handler.
155 This is called on GET /device/password?id=DEVICE-ID.
156 Ideally this should pop up a user dialog to insert his
157 password based the DEVICE-ID
165 # we _need_ a device id
167 raise web.badrequest()
169 # invoke the user dialog as a subprocess
170 dlg_credentials_image = os.path.join(sys.path[0], 'opensecurity-dialog.py')
171 process_command = [sys.executable, dlg_credentials_image, 'password', 'Please provide a password for accessing \ndevice: "{0}".'.format(args.id)]
172 process = subprocess.Popen(process_command, shell = False, stdout = subprocess.PIPE)
173 result = process.communicate()[0]
174 if process.returncode != 0:
175 return 'Credentials request has been aborted.'
182 """OpenSecurity '/' handler"""
185 return "OpenSecurity-Server { \"version\": \"%s\" }" % __version__
189 if __name__ == "__main__":
190 server = web.application(opensecurity_urls, globals())