keys = {} # Server section... servers_with_weights = {} servers = [] servers_weighted = [] server_count = 0 servers_weighted_count = 0 server_defaults = {} server_default_port = ":80" server_ports = {} servers_interface_ip = [] servers_server_config = {} servers_purge = {} # Start the threading queues... server_queue = Queue.Queue() # End global variable section for config # Set the above variables via the read function from config_functions.py read()
keys = {} #Server section... servers_with_weights = {} servers = [] servers_weighted = [] server_count = 0 servers_weighted_count = 0 server_defaults = {} server_default_port = ":80" server_ports = {} servers_interface_ip = [] servers_server_config = {} servers_purge = {} # Start the threading queues... server_queue = Queue.Queue() # End global variable section for config # Set the above variables via the read function from config_functions.py read()
def post(self, *args, **kwargs): """ Add XSRF back in after testing... Check the header for the 'application/json' Content-Type """ self.set_header("Server", "API Server v" + version) dict_data = "{}" header = str(self.request.headers["Content-Type"]).lower( ) # If Content-Type is not there or malformed then the server catches before this point. if args is None or args[0] == "" or header != "application/json": #if config.logging: # log("%s\t%s://%s%s\tForbidden\tHeader not set correctly" % (config.http_response_codes["forbidden"], self.request.protocol, self.request.host, self.request.uri), "WARNING") raise tornado.web.HTTPError( config.http_response_codes["forbidden"]) # Force the api ip_restrict to check. passed = ip_restrict(self.request.remote_ip, api=True) if not passed: #if config.logging: # log("%s\t%s%s%s://%s%s\tForbidden\tIP Restricted: %s" % (config.http_response_codes["forbidden"], config.ip["log_prefix"], config.log_message_formats["requested_prefix"], self.request.protocol, self.request.host, self.request.uri, self.request.remote_ip), "WARNING") raise tornado.web.HTTPError( config.http_response_codes["forbidden"] ) # The exception will catch this so force it again self.set_header("Content-Type", "application/json") command = str(args[0]).lower() # Break down the json into a dictionary. Some will be a simple name/value pair and others an array and others a list. try: dict_data = convert(json.loads(self.request.body)) if command == "log_rotation": if len(dict_data[command]) > 0: config.log_rotation = dict_data[command] elif command == "log_backups": if len(dict_data[command]) > 0: config.log_backups = dict_data[command] elif command == "log_when": if len(dict_data[command]) > 0: config.log_when = dict_data[command] elif command == "alert_email": config.alert_email.clear() config.alert_email = dict_data[command] elif command == "keys": if len(dict_data[command]) > 0: config.keys.clear() config.keys = dict_data[command] elif command == "read": read() elif command == "write": # Writes out the yaml file yaml_write("config", "config.yaml") if config.logging: log("POST %s\t%s://%s%s\t%s\t%s\t%s" % (config.http_response_codes["found"], self.request.protocol, self.request.host, self.request.uri, self.request.remote_ip, self.request.headers["User-Agent"], dict_data)) self.write("{\"%s\": %s}" % ("success", True)) except BaseException, e: log( "POST %s\t%s://%s%s\t%s\t%s\t%s\t%s" % (config.http_response_codes["general_error"], self.request.protocol, self.request.host, self.request.uri, self.request.remote_ip, self.request.headers["User-Agent"], e, dict_data), "CRITICAL") self.write("{\"%s\": %s}" % ("success", False))
def post(self, *args, **kwargs): """ Add XSRF back in after testing... Check the header for the 'application/json' Content-Type """ self.set_header("Server", "API Server v" + version) dict_data = "{}" header = str(self.request.headers["Content-Type"]).lower() # If Content-Type is not there or malformed then the server catches before this point. if args is None or args[0] == "" or header != "application/json": #if config.logging: # log("%s\t%s://%s%s\tForbidden\tHeader not set correctly" % (config.http_response_codes["forbidden"], self.request.protocol, self.request.host, self.request.uri), "WARNING") raise tornado.web.HTTPError(config.http_response_codes["forbidden"]) # Force the api ip_restrict to check. passed = ip_restrict(self.request.remote_ip, api=True) if not passed: #if config.logging: # log("%s\t%s%s%s://%s%s\tForbidden\tIP Restricted: %s" % (config.http_response_codes["forbidden"], config.ip["log_prefix"], config.log_message_formats["requested_prefix"], self.request.protocol, self.request.host, self.request.uri, self.request.remote_ip), "WARNING") raise tornado.web.HTTPError(config.http_response_codes["forbidden"]) # The exception will catch this so force it again self.set_header("Content-Type", "application/json") command = str(args[0]).lower() # Break down the json into a dictionary. Some will be a simple name/value pair and others an array and others a list. try: dict_data = convert(json.loads(self.request.body)) if command == "log_rotation": if len(dict_data[command]) > 0: config.log_rotation = dict_data[command] elif command == "log_backups": if len(dict_data[command]) > 0: config.log_backups = dict_data[command] elif command == "log_when": if len(dict_data[command]) > 0: config.log_when = dict_data[command] elif command == "alert_email": config.alert_email.clear() config.alert_email = dict_data[command] elif command == "keys": if len(dict_data[command]) > 0: config.keys.clear() config.keys = dict_data[command] elif command == "read": read() elif command == "write": # Writes out the yaml file yaml_write("config", "config.yaml") if config.logging: log("POST %s\t%s://%s%s\t%s\t%s\t%s" % ( config.http_response_codes["found"], self.request.protocol, self.request.host, self.request.uri, self.request.remote_ip, self.request.headers["User-Agent"], dict_data)) self.write("{\"%s\": %s}" % ("success", True)) except BaseException, e: log("POST %s\t%s://%s%s\t%s\t%s\t%s\t%s" % ( config.http_response_codes["general_error"], self.request.protocol, self.request.host, self.request.uri, self.request.remote_ip, self.request.headers["User-Agent"], e, dict_data), "CRITICAL") self.write("{\"%s\": %s}" % ("success", False))