def application(environ, start_response): """MiG app called automatically by wsgi""" # TODO: verify security of this environment exposure # pass environment on to sub handlers os.environ = environ # TODO: we should avoid print calls completely in backends # make sure print calls do not interfere with wsgi sys.stdout = sys.stderr configuration = get_configuration_object() # get and log ID of user currently logged in # We can't import helper before environ is ready because it indirectly # tries to use pre-mangled environ for conf loading from shared.httpsclient import extract_client_id client_id = extract_client_id(configuration, environ) fieldstorage = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ) user_arguments_dict = fieldstorage_to_dict(fieldstorage) # default to html output_format = 'html' if user_arguments_dict.has_key('output_format'): output_format = user_arguments_dict['output_format'][0] try: if not configuration.site_enable_wsgi: raise Exception("WSGI interface not enabled for this grid") # Environment contains python script _somewhere_ , try in turn # and fall back to dashboard if all fails script_path = requested_page(environ, 'dashboard.py') backend = os.path.basename(script_path).replace('.py' , '') module_path = 'shared.functionality.%s' % backend (output_objs, ret_val) = stub(module_path, configuration, client_id, user_arguments_dict, environ) status = '200 OK' except Exception, exc: status = '500 ERROR' (output_objs, ret_val) = ([{'object_type': 'title', 'text' : 'Unsupported Interface'}, {'object_type': 'error_text', 'text' : str(exc)}, # Enable next two lines only for debugging # {'object_type': 'text', 'text': # str(environ)} {'object_type': 'link', 'text': 'Go to default interface', 'destination': '/index.html'}, ], returnvalues.SYSTEM_ERROR)
def init_cgi_script(environ, delayed_input=None): """Shared init""" configuration = get_configuration_object() logger = configuration.logger # get and log ID of user currently logged in client_id = extract_client_id(configuration, environ) logger.info('script: %s cert: %s' % (requested_page(), client_id)) if not delayed_input: fieldstorage = cgi.FieldStorage() user_arguments_dict = fieldstorage_to_dict(fieldstorage) else: user_arguments_dict = {'__DELAYED_INPUT__': delayed_input} return (configuration, logger, client_id, user_arguments_dict)
def application(environ, start_response): """MiG app called automatically by wsgi""" # TODO: verify security of this environment exposure # pass environment on to sub handlers os.environ = environ # TODO: we should avoid print calls completely in backends # make sure print calls do not interfere with wsgi sys.stdout = sys.stderr configuration = get_configuration_object() _logger = configuration.logger # get and log ID of user currently logged in # We can't import helper before environ is ready because it indirectly # tries to use pre-mangled environ for conf loading from shared.httpsclient import extract_client_id client_id = extract_client_id(configuration, environ) fieldstorage = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ) user_arguments_dict = fieldstorage_to_dict(fieldstorage) # default to html output_format = 'html' if user_arguments_dict.has_key('output_format'): output_format = user_arguments_dict['output_format'][0] backend = "UNKNOWN" output_objs = [] try: if not configuration.site_enable_wsgi: _logger.error("WSGI interface is disabled in configuration") raise Exception("WSGI interface not enabled for this site") # Environment contains python script _somewhere_ , try in turn # and fall back to dashboard if all fails script_path = requested_page(environ, configuration.site_landing_page) script_name = os.path.basename(script_path) backend = os.path.splitext(script_name)[0] module_path = 'shared.functionality.%s' % backend (allow, msg) = allow_script(configuration, script_name, client_id) if allow: (output_objs, ret_val) = stub(configuration, client_id, module_path, backend, user_arguments_dict, environ) else: (output_objs, ret_val) = reject_main(client_id, user_arguments_dict) status = '200 OK' except Exception, exc: _logger.error("handling of WSGI request for %s from %s failed: %s" % (backend, client_id, exc)) status = '500 ERROR' crash_helper(configuration, backend, output_objs) output_objs.append({ 'object_type': 'link', 'text': 'Go to default interface', 'destination': configuration.site_landing_page }) ret_val = returnvalues.SYSTEM_ERROR