def post(self): script_name = None audit_name = get_audit_name_from_request(self) try: arguments = tornado_utils.get_form_arguments(self) execution_info = external_model.to_execution_info(arguments) script_name = execution_info.script config = self.application.config_service.load_config(script_name) if not config: message = 'Script with name "' + str(script_name) + '" not found' LOGGER.error(message) respond_error(self, 400, message) return if not can_access_script(config, self): LOGGER.warning('Access to the script "' + script_name + '" is denied for ' + audit_name) respond_error(self, 403, 'Access to the script is denied') return file_upload_feature = self.application.file_upload_feature if self.request.files: for key, value in self.request.files.items(): file_info = value[0] file_path = file_upload_feature.save_file(file_info.filename, file_info.body, audit_name) execution_info.param_values[key] = file_path model_helper.prepare_multiselect_values(execution_info.param_values, config.parameters) valid_parameters = model_helper.validate_parameters(execution_info.param_values, config) if not valid_parameters: message = 'Received invalid parameters' LOGGER.error(message) respond_error(self, 400, message) return user_id = _identify_user(self) all_audit_names = get_all_audit_names(self) LOGGER.info('Calling script ' + script_name + '. User ' + str(all_audit_names)) execution_id = self.application.execution_service.start_script( config, execution_info.param_values, user_id, all_audit_names) self.write(str(execution_id)) except Exception as e: LOGGER.exception("Error while calling the script") if hasattr(e, "strerror") and e.strerror: error_output = e.strerror else: error_output = "Unknown error occurred, contact the administrator" result = " --- ERRORS --- \n" result += error_output if script_name: script = str(script_name) else: script = "Some script" audit_name = audit_name self.application.alerts_service.send_alert( script + ' NOT STARTED', "Couldn't start the script " + script + ' by ' + audit_name + '.\n\n' + result) respond_error(self, 500, result)
def post(self): script_name = None audit_name = get_audit_name(self) try: arguments = tornado_utils.get_form_arguments(self) execution_info = external_model.to_execution_info(arguments) script_name = execution_info.script config = load_config(script_name) if not config: message = 'Script with name "' + str( script_name) + '" not found' LOGGER.error(message) respond_error(self, 400, message) return file_upload_feature = self.application.file_upload_feature if self.request.files: for key, value in self.request.files.items(): file_info = value[0] file_path = file_upload_feature.save_file( file_info.filename, file_info.body, audit_name) execution_info.param_values[key] = file_path valid_parameters = model_helper.validate_parameters( execution_info.param_values, config) if not valid_parameters: message = 'Received invalid parameters' LOGGER.error(message) respond_error(self, 400, message) return executor = ScriptExecutor(config, execution_info.param_values, audit_name) audit_command = executor.get_secure_command() LOGGER.info('Calling script: ' + audit_command) LOGGER.info('User info: ' + str(get_all_audit_names(self))) process_id = executor.start() running_scripts[process_id] = executor self.write(str(process_id)) secure_output_stream = executor.get_secure_output_stream() self.start_script_output_logger(audit_name, script_name, secure_output_stream) alerts_config = self.application.alerts_config if alerts_config: self.subscribe_fail_alerter(script_name, alerts_config, audit_name, executor, secure_output_stream) except Exception as e: LOGGER.exception("Error while calling the script") if hasattr(e, "strerror") and e.strerror: error_output = e.strerror else: error_output = "Unknown error occurred, contact the administrator" result = " --- ERRORS --- \n" result += error_output if script_name: script = str(script_name) else: script = "Some script" audit_name = audit_name send_alerts( self.application.alerts_config, script + ' NOT STARTED', "Couldn't start the script " + script + ' by ' + audit_name + '.\n\n' + result) respond_error(self, 500, result)
def post(self, user): script_name = None audit_name = get_audit_name_from_request(self) try: arguments = tornado_utils.get_form_arguments(self) execution_info = external_model.to_execution_info(arguments) script_name = execution_info.script config_model = self.application.config_service.create_config_model( script_name, user) if not config_model: message = 'Script with name "' + str( script_name) + '" not found' LOGGER.error(message) respond_error(self, 400, message) return parameter_values = execution_info.param_values if self.request.files: file_upload_feature = self.application.file_upload_feature for key, value in self.request.files.items(): file_info = value[0] file_path = file_upload_feature.save_file( file_info.filename, file_info.body, audit_name) parameter_values[key] = file_path try: config_model.set_all_param_values(parameter_values) normalized_values = dict(config_model.parameter_values) except InvalidValueException as e: message = 'Invalid parameter %s value: %s' % (e.param_name, str(e)) LOGGER.error(message) respond_error(self, 400, message) return user_id = _identify_user(self) all_audit_names = get_all_audit_names(self) LOGGER.info('Calling script ' + script_name + '. User ' + str(all_audit_names)) execution_id = self.application.execution_service.start_script( config_model, normalized_values, user_id, all_audit_names) self.write(str(execution_id)) except ConfigNotAllowedException: LOGGER.warning('Access to the script "' + script_name + '" is denied for ' + audit_name) respond_error(self, 403, 'Access to the script is denied') return except Exception as e: LOGGER.exception("Error while calling the script") if hasattr(e, "strerror") and e.strerror: error_output = e.strerror else: error_output = "Unknown error occurred, contact the administrator" result = " --- ERRORS --- \n" result += error_output if script_name: script = str(script_name) else: script = "Some script" audit_name = audit_name self.application.alerts_service.send_alert( script + ' NOT STARTED', "Couldn't start the script " + script + ' by ' + audit_name + '.\n\n' + result) respond_error(self, 500, result)