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 gvm_mgr.cygwin_path = 'c:\\cygwin64\\bin\\'
115 #gvm_mgr.configureHostNetworking()
116 print 'received device_change'
117 return "os_device_change"
120 class os_device_credentials:
122 """OpenSecurity '/device/credentials' handler.
124 This is called on GET /device/credentials?id=DEVICE-ID.
125 Ideally this should pop up a user dialog to insert his
126 credentials based the DEVICE-ID
134 # we _need_ a device id
136 raise web.badrequest()
138 # invoke the user dialog as a subprocess
139 dlg_credentials_image = os.path.join(sys.path[0], 'opensecurity-dialog.py')
140 process_command = [sys.executable, dlg_credentials_image, 'credentials', 'Please provide credentials for accessing \ndevice: "{0}".'.format(args.id)]
141 process = subprocess.Popen(process_command, shell = False, stdout = subprocess.PIPE)
142 result = process.communicate()[0]
143 if process.returncode != 0:
144 return 'Credentials request has been aborted.'
149 class os_device_password:
151 """OpenSecurity '/device/password' handler.
153 This is called on GET /device/password?id=DEVICE-ID.
154 Ideally this should pop up a user dialog to insert his
155 password based the DEVICE-ID
163 # we _need_ a device id
165 raise web.badrequest()
167 # invoke the user dialog as a subprocess
168 dlg_credentials_image = os.path.join(sys.path[0], 'opensecurity-dialog.py')
169 process_command = [sys.executable, dlg_credentials_image, 'password', 'Please provide a password for accessing \ndevice: "{0}".'.format(args.id)]
170 process = subprocess.Popen(process_command, shell = False, stdout = subprocess.PIPE)
171 result = process.communicate()[0]
172 if process.returncode != 0:
173 return 'Credentials request has been aborted.'
180 """OpenSecurity '/' handler"""
183 return "OpenSecurity-Server { \"version\": \"%s\" }" % __version__
187 if __name__ == "__main__":
188 server = web.application(opensecurity_urls, globals())