Пример #1
0
 def __init__(self, logger, config_filename=CONFIG_FILENAME):
     self._node_dict = {}
     self._crash_dict = {}
     self._logger = logger
     self._config = ConfigParser(config_filename)
     beacon_port, beacon_timeout, config_req_interval = self._config.beacon_config
     report_port = self._config.report_server_config
     web_port = self._config.web_server_config
     self._beacon_queue = Queue()
     self._node_queue = Queue()
     self._report_queue = Queue()
     self._web_queue = Queue()
     self._db_queue = Queue()
     self._db_worker = DatabaseWorker(self._db_queue, self._node_dict,
                                      self._crash_dict)
     self._db_worker.load()
     self._beacon_server = BeaconServer(beacon_port, self._beacon_queue)
     self._beacon_worker = BeaconWorker(self._beacon_queue,
                                        self._node_queue, self._db_queue,
                                        beacon_timeout, config_req_interval,
                                        self._node_dict)
     self._report_server = ReportServer(report_port, self._report_queue)
     self._report_worker = ReportWorker(self._report_queue, self._db_queue,
                                        self._node_dict, self._crash_dict)
     self._node_client_worker = NodeClientWorker(self._node_queue)
     self._web_server = WebServer(web_port, self._web_queue, self.web_main)
Пример #2
0
 def __init__(self, logger, config_filename=CONFIG_FILENAME):
     self._logger = logger
     self._node_config = ConfigParser(config_filename)
     self._reporter_queue = Queue()
     if self._node_config.node_net_mode == "net":
         beacon_server, beacon_port, beacon_interval = self._node_config.beacon_config
         report_server, report_port = self._node_config.report_config
         tcp_listener_port = self._node_config.listener_config
         self._listener_queue = Queue()
         self._beacon_client = BeaconClient(beacon_server, beacon_port, self._node_config.node_name,
                                            beacon_interval, tcp_listener_port)
         self._tcp_listener = Listener(tcp_listener_port, self._listener_queue)
         self._listener_worker = ListenerWorker(self._listener_queue, self._reporter_queue)
         self._report_worker = ReportWorker(True, self._reporter_queue, self._node_config.file_type,
                                            self._node_config.programs, report_server, report_port)
     else:  # else single mode
         self._report_worker = ReportWorker(False, self._reporter_queue, self._node_config.file_type,
                                            self._node_config.programs)
     if self._node_config.node_op_mode == 'fuzzing':
         self._fuzzer = self.__choose_fuzzer()
         if os.path.isfile("fuzz_state.pickle"):
             try:
                 with open("fuzz_state.pickle", 'r') as fd:
                     self._fuzzer.set_state(pickle.load(fd))
                 os.remove("fuzz_state.pickle")
             except KeyError as er:
                 self._logger.error("Error while restoring the PRNG state -> " + er.message)
                 self._fuzzer.set_seed()
         self._operation_worker = FuzzingWorker(self._node_config.programs, self._fuzzer, self._reporter_queue,)
     elif self._node_config.node_op_mode == 'reducing':
         self._reducer = self.__choose_reducer()
         self._operation_worker = ReducingWorker(self._reducer, self._node_config.programs, self._reporter_queue)
     else:
         raise ValueError('Unsupported operation mode!')
Пример #3
0
class PyFuzz2Server:
    def __init__(self, logger, config_filename=CONFIG_FILENAME):
        self._node_dict = {}
        self._crash_dict = {}
        self._logger = logger
        self._config = ConfigParser(config_filename)
        beacon_port, beacon_timeout, config_req_interval = self._config.beacon_config
        report_port = self._config.report_server_config
        web_port = self._config.web_server_config
        self._beacon_queue = Queue()
        self._node_queue = Queue()
        self._report_queue = Queue()
        self._web_queue = Queue()
        self._db_queue = Queue()
        self._db_worker = DatabaseWorker(self._db_queue, self._node_dict,
                                         self._crash_dict)
        self._db_worker.load()
        self._beacon_server = BeaconServer(beacon_port, self._beacon_queue)
        self._beacon_worker = BeaconWorker(self._beacon_queue,
                                           self._node_queue, self._db_queue,
                                           beacon_timeout, config_req_interval,
                                           self._node_dict)
        self._report_server = ReportServer(report_port, self._report_queue)
        self._report_worker = ReportWorker(self._report_queue, self._db_queue,
                                           self._node_dict, self._crash_dict)
        self._node_client_worker = NodeClientWorker(self._node_queue)
        self._web_intf = WebInterface(self._web_queue, self._node_dict,
                                      self._crash_dict)
        self._web_server = WebServer(web_port, self._web_intf.app)
        self._web_worker = WebWorker(self._node_dict, self._web_queue,
                                     self._node_queue, self._db_queue)

    def main(self):
        self._logger.info("PyFuzz2 Server started...")
        self._beacon_server.start_server()
        self._beacon_worker.start_worker()
        self._report_server.start_server()
        self._report_worker.start_worker()
        self._web_server.start_server()
        self._node_client_worker.start_worker()
        self._db_worker.start_worker()
        self._web_worker.start_worker()
        while True:
            try:
                gevent.wait()
            except KeyboardInterrupt:
                self.__shut_down()
                exit(0)

    def __shut_down(self):
        self._beacon_server.stop_server()
        self._beacon_worker.stop_worker()
        self._report_server.stop_server()
        self._report_worker.stop_worker()
        self._web_server.stop_server()
        self._node_client_worker.stop_worker()
        self._db_worker.stop_worker()
        self._web_worker.stop_worker()
        gevent.sleep(0)
Пример #4
0
class PyFuzz2Server:
    def __init__(self, logger, config_filename=CONFIG_FILENAME):
        self._node_dict = {}
        self._crash_dict = {}
        self._logger = logger
        self._config = ConfigParser(config_filename)
        beacon_port, beacon_timeout, config_req_interval = self._config.beacon_config
        report_port = self._config.report_server_config
        web_port = self._config.web_server_config
        self._beacon_queue = Queue()
        self._node_queue = Queue()
        self._report_queue = Queue()
        self._web_queue = Queue()
        self._db_queue = Queue()
        self._db_worker = DatabaseWorker(self._db_queue, self._node_dict, self._crash_dict)
        self._db_worker.load()
        self._beacon_server = BeaconServer(beacon_port, self._beacon_queue)
        self._beacon_worker = BeaconWorker(self._beacon_queue, self._node_queue, self._db_queue,
                                           beacon_timeout, config_req_interval, self._node_dict)
        self._report_server = ReportServer(report_port, self._report_queue)
        self._report_worker = ReportWorker(self._report_queue, self._db_queue, self._node_dict, self._crash_dict)
        self._node_client_worker = NodeClientWorker(self._node_queue)
        self._web_intf = WebInterface(self._web_queue, self._node_dict, self._crash_dict)
        self._web_server = WebServer(web_port, self._web_intf.app)
        self._web_worker = WebWorker(self._node_dict, self._web_queue, self._node_queue, self._db_queue)

    def main(self):
        self._logger.info("PyFuzz2 Server started...")
        self._beacon_server.start_server()
        self._beacon_worker.start_worker()
        self._report_server.start_server()
        self._report_worker.start_worker()
        self._web_server.start_server()
        self._node_client_worker.start_worker()
        self._db_worker.start_worker()
        self._web_worker.start_worker()
        while True:
            try:
                gevent.wait()
            except KeyboardInterrupt:
                self.__shut_down()
                exit(0)

    def __shut_down(self):
        self._beacon_server.stop_server()
        self._beacon_worker.stop_worker()
        self._report_server.stop_server()
        self._report_worker.stop_worker()
        self._web_server.stop_server()
        self._node_client_worker.stop_worker()
        self._db_worker.stop_worker()
        self._web_worker.stop_worker()
        gevent.sleep(0)
Пример #5
0
 def __init__(self, logger, config_filename=CONFIG_FILENAME):
     self._logger = logger
     self._node_config = ConfigParser(config_filename)
     self._reporter_queue = Queue()
     if self._node_config.node_net_mode == "net":
         beacon_server, beacon_port, beacon_interval = self._node_config.beacon_config
         report_server, report_port = self._node_config.report_config
         tcp_listener_port = self._node_config.listener_config
         self._listener_queue = Queue()
         self._beacon_client = BeaconClient(beacon_server, beacon_port,
                                            self._node_config.node_name,
                                            beacon_interval,
                                            tcp_listener_port)
         self._tcp_listener = Listener(tcp_listener_port,
                                       self._listener_queue)
         self._listener_worker = ListenerWorker(self._listener_queue,
                                                self._reporter_queue)
         self._report_worker = ReportWorker(True, self._reporter_queue,
                                            self._node_config.file_type,
                                            self._node_config.programs,
                                            report_server, report_port)
     else:  # else single mode
         self._report_worker = ReportWorker(False, self._reporter_queue,
                                            self._node_config.file_type,
                                            self._node_config.programs)
     if self._node_config.node_op_mode == 'fuzzing':
         self._fuzzer = self.__choose_fuzzer()
         if os.path.isfile("fuzz_state.pickle"):
             try:
                 with open("fuzz_state.pickle", 'r') as fd:
                     self._fuzzer.set_state(pickle.load(fd))
                 os.remove("fuzz_state.pickle")
             except KeyError as er:
                 self._logger.error(
                     "Error while restoring the PRNG state -> " +
                     er.message)
                 self._fuzzer.set_seed()
         self._operation_worker = FuzzingWorker(
             self._node_config.programs,
             self._fuzzer,
             self._reporter_queue,
         )
     elif self._node_config.node_op_mode == 'reducing':
         self._reducer = self.__choose_reducer()
         self._operation_worker = ReducingWorker(self._reducer,
                                                 self._node_config.programs,
                                                 self._reporter_queue)
     else:
         raise ValueError('Unsupported operation mode!')
Пример #6
0
 def __init__(self, logger, config_filename=CONFIG_FILENAME):
     self._logger = logger
     self._config = ConfigParser(config_filename)
     self._beacon_port, self._beacon_timeout = self._config.beacon_config
     self._report_port = self._config.report_server_config
     self._web_port = self._config.web_server_config
     self._beacon_queue = Queue()
     self._node_queue = Queue()
     self._report_queue = Queue()
     self._web_queue = Queue()
     self._beacon_server = BeaconServer(self._beacon_port, self._beacon_queue)
     self._beacon_worker = BeaconWorker(self._beacon_queue, self._node_queue, self._beacon_timeout)
     self._report_server = ReportServer(self._report_port, self._report_queue)
     self._report_worker = ReportWorker(self._report_queue, self._beacon_worker.nodes)
     self._node_client_worker = NodeClientWorker(self._node_queue)
     self._web_server = WebServer(self._web_port, self._web_queue, self.web_main)
Пример #7
0
 def __init__(self, logger, config_filename=CONFIG_FILENAME):
     self._node_dict = {}
     self._crash_dict = {}
     self._logger = logger
     self._config = ConfigParser(config_filename)
     beacon_port, beacon_timeout, config_req_interval = self._config.beacon_config
     report_port = self._config.report_server_config
     web_port = self._config.web_server_config
     self._beacon_queue = Queue()
     self._node_queue = Queue()
     self._report_queue = Queue()
     self._web_queue = Queue()
     self._db_queue = Queue()
     self._db_worker = DatabaseWorker(self._db_queue, self._node_dict, self._crash_dict)
     self._db_worker.load()
     self._beacon_server = BeaconServer(beacon_port, self._beacon_queue)
     self._beacon_worker = BeaconWorker(self._beacon_queue, self._node_queue, self._db_queue,
                                        beacon_timeout, config_req_interval, self._node_dict)
     self._report_server = ReportServer(report_port, self._report_queue)
     self._report_worker = ReportWorker(self._report_queue, self._db_queue, self._node_dict, self._crash_dict)
     self._node_client_worker = NodeClientWorker(self._node_queue)
     self._web_server = WebServer(web_port, self._web_queue, self.web_main)
Пример #8
0
class PyFuzz2Node:
    def __init__(self, logger, config_filename=CONFIG_FILENAME):
        self._logger = logger
        self._node_config = ConfigParser(config_filename)
        self._reporter_queue = Queue()
        if self._node_config.node_net_mode == "net":
            beacon_server, beacon_port, beacon_interval = self._node_config.beacon_config
            report_server, report_port = self._node_config.report_config
            tcp_listener_port = self._node_config.listener_config
            self._listener_queue = Queue()
            self._beacon_client = BeaconClient(beacon_server, beacon_port,
                                               self._node_config.node_name,
                                               beacon_interval,
                                               tcp_listener_port)
            self._tcp_listener = Listener(tcp_listener_port,
                                          self._listener_queue)
            self._listener_worker = ListenerWorker(self._listener_queue,
                                                   self._reporter_queue)
            self._report_worker = ReportWorker(True, self._reporter_queue,
                                               self._node_config.file_type,
                                               self._node_config.programs,
                                               report_server, report_port)
        else:  # else single mode
            self._report_worker = ReportWorker(False, self._reporter_queue,
                                               self._node_config.file_type,
                                               self._node_config.programs)
        if self._node_config.node_op_mode == 'fuzzing':
            self._fuzzer = self.__choose_fuzzer()
            if os.path.isfile("fuzz_state.pickle"):
                try:
                    with open("fuzz_state.pickle", 'r') as fd:
                        self._fuzzer.set_state(pickle.load(fd))
                    os.remove("fuzz_state.pickle")
                except KeyError as er:
                    self._logger.error(
                        "Error while restoring the PRNG state -> " +
                        er.message)
                    self._fuzzer.set_seed()
            self._operation_worker = FuzzingWorker(
                self._node_config.programs,
                self._fuzzer,
                self._reporter_queue,
            )
        elif self._node_config.node_op_mode == 'reducing':
            self._reducer = self.__choose_reducer()
            self._operation_worker = ReducingWorker(self._reducer,
                                                    self._node_config.programs,
                                                    self._reporter_queue)
        else:
            raise ValueError('Unsupported operation mode!')

    def __choose_fuzzer(self):
        return FUZZERS[self._node_config.fuzzer_type][1].from_list(
            self._node_config.fuzzer_config)

    def __choose_reducer(self):
        return REDUCERS[self._node_config.reducer_type][1].from_list(
            self._node_config.reducer_config)

    def __stop_all_workers(self):
        self._operation_worker.stop_worker()
        if self._node_config.node_net_mode == "net":
            self._listener_worker.stop_worker()
            self._beacon_client.stop_beacon()
            self._tcp_listener.stop()

    def __save_fuzz_state(self):
        fuzz_state = self._fuzzer.prng_state
        with open("fuzz_state.pickle", 'w+') as fd:
            pickle.dump(fuzz_state, fd)  # Save the state of the prng

    def main(self):
        start = time.time()
        self._logger.info("PyFuzz 2 Node started ...")
        if self._node_config.node_net_mode == "net":
            self._beacon_client.start_beacon()
            self._tcp_listener.serve()
            self._listener_worker.start_worker()
        self._report_worker.start_worker()
        self._operation_worker.start_worker()
        while True:
            try:
                if self._node_config.node_net_mode == "net":
                    if self._listener_worker.new_config:
                        self._logger.info("Received new config")
                        self.__stop_all_workers()
                        # self.__save_fuzz_state() if there is a new config it shouldn't restore the state??
                        restart(self._node_config.sleep_time + 5)
                    elif self._listener_worker.reset:
                        self._logger.info(
                            "Node is going to reboot on received command")
                        self.__stop_all_workers()
                        gevent.sleep(5)
                        if self._node_config.node_op_mode == "fuzzing":
                            self.__save_fuzz_state()
                        gevent.sleep(self._node_config.sleep_time + 5)
                        reboot()
                if time.time() - start > (8 * 60 *
                                          60):  # Reboot after eight hours
                    self._logger.info("Node is going to reboot")
                    self.__stop_all_workers()
                    gevent.sleep(5)
                    if self._node_config.node_op_mode == "fuzzing":
                        self.__save_fuzz_state()
                    gevent.sleep(self._node_config.sleep_time + 5)
                    reboot()
                gevent.sleep(
                    5
                )  # It's enough to check the above stuff every 5 seconds instead of burning cpu time
            except KeyboardInterrupt:
                self.__stop_all_workers()
                quit()
Пример #9
0
class PyFuzz2Server:
    def __init__(self, logger, config_filename=CONFIG_FILENAME):
        self._node_dict = {}
        self._crash_dict = {}
        self._logger = logger
        self._config = ConfigParser(config_filename)
        self._beacon_port, self._beacon_timeout = self._config.beacon_config
        self._report_port = self._config.report_server_config
        self._web_port = self._config.web_server_config
        self._beacon_queue = Queue()
        self._node_queue = Queue()
        self._report_queue = Queue()
        self._web_queue = Queue()
        self._db_queue = Queue()
        self._db_worker = DatabaseWorker(self._db_queue, self._node_dict, self._crash_dict)
        self._db_worker.load()
        self._beacon_server = BeaconServer(self._beacon_port, self._beacon_queue)
        self._beacon_worker = BeaconWorker(self._beacon_queue, self._node_queue, self._db_queue,
                                           self._beacon_timeout, self._node_dict)
        self._report_server = ReportServer(self._report_port, self._report_queue)
        self._report_worker = ReportWorker(self._report_queue, self._db_queue, self._node_dict, self._crash_dict)
        self._node_client_worker = NodeClientWorker(self._node_queue)
        self._web_server = WebServer(self._web_port, self._web_queue, self.web_main)

    def main(self):
        self._logger.info("PyFuzz2 Server started...")
        self._beacon_server.serve()
        self._beacon_worker.start_worker()
        self._report_server.serve()
        self._report_worker.start_worker()
        self._web_server.serve()
        self._node_client_worker.start_worker()
        self._db_worker.start_worker()
        while True:
            try:
                gevent.wait()
            except KeyboardInterrupt:
                exit(0)

    def web_main(self, environ, start_response):
        site = WebSite()
        func = "home"
        if environ['PATH_INFO'] == "/index.py" or environ['PATH_INFO'] == "/":
            parameters = parse_qs(environ['QUERY_STRING'])
            if "func" in parameters:
                func = parameters['func'][0] if parameters['func'][0] in site.funcs else "home"
            if func == "home":
                if 'reboot' in parameters:
                    key = parameters['reboot'][0]
                    self._beacon_worker.nodes[key].status = False
                    self._node_queue.put([(key, self._beacon_worker.nodes[key].listener_port), MESSAGE_TYPES['RESET'],
                                          ""])
                if "submit" in parameters and "node" in parameters:
                    key = parameters['node'][0]
                    self._logger.debug("Preparing new config")
                    node_conf = node.model.config.ConfigParser.create_config(environ['wsgi.input'].read())
                    self._beacon_worker.nodes[key].status = False
                    self._node_queue.put([(key, self._beacon_worker.nodes[key].listener_port),
                                         MESSAGE_TYPES['SET_CONFIG'], node_conf])
                if "del" in parameters:
                    key = parameters['del'][0]
                    del(self._beacon_worker.nodes[key])
                status, headers, html = site.home(self._beacon_worker.nodes)
            elif func == "node_detail":
                if "node" in parameters and parameters['node'][0] in self._beacon_worker.nodes.keys():
                    key = parameters['node'][0]
                    status, headers, html = site.node_detail(self._beacon_worker.nodes[key])
                else:
                    status, headers, html = site.file_not_found()
            elif func == "stats":
                status, headers, html = site.stats(self._node_dict, self._crash_dict)
        elif environ['PATH_INFO'] == "/style.css":
            status, headers, html = site.get_style()
        elif environ['PATH_INFO'] == "/scripts.js":
            status, headers, html = site.get_scripts()
        else:
            status, headers, html = site.file_not_found()
        if self._logger.level == logging.DEBUG:
            html += "<br><br>" + str(environ) + "<br><br>" + func + "<br><br>" + environ['wsgi.input'].read()
        start_response(status, headers)
        return [str(html)]
Пример #10
0
class PyFuzz2Node:
    def __init__(self, logger, config_filename=CONFIG_FILENAME):
        self._logger = logger
        self._node_config = ConfigParser(config_filename)
        self._reporter_queue = Queue()
        if self._node_config.node_net_mode == "net":
            beacon_server, beacon_port, beacon_interval = self._node_config.beacon_config
            report_server, report_port = self._node_config.report_config
            tcp_listener_port = self._node_config.listener_config
            self._listener_queue = Queue()
            self._beacon_client = BeaconClient(beacon_server, beacon_port, self._node_config.node_name,
                                               beacon_interval, tcp_listener_port)
            self._tcp_listener = Listener(tcp_listener_port, self._listener_queue)
            self._listener_worker = ListenerWorker(self._listener_queue, self._reporter_queue)
            self._report_worker = ReportWorker(True, self._reporter_queue, self._node_config.file_type,
                                               self._node_config.program_path, report_server, report_port)
        else:  # else single mode
            self._report_worker = ReportWorker(False, self._reporter_queue, self._node_config.file_type,
                                               self._node_config.program_path)
        if self._node_config.node_op_mode == 'fuzzing':
            self._fuzzer = self.__choose_fuzzer()
            if os.path.isfile("fuzz_state.pickle"):
                try:
                    with open("fuzz_state.pickle", 'r') as fd:
                        self._fuzzer.set_state(pickle.load(fd))
                    os.remove("fuzz_state.pickle")
                except KeyError as er:
                    self._logger.error("Error while restoring the PRNG state -> " + er.message)
                    self._fuzzer.set_seed()
            self._operation_worker = FuzzingWorker(self._node_config.program_path, self._fuzzer, self._reporter_queue,
                                                   self._node_config.sleep_time, self._node_config.dbg_child)
        elif self._node_config.node_op_mode == 'reducing':
            self._reducer = self.__choose_reducer()
            self._operation_worker = ReducingWorker(self._reducer, self._node_config.program_path,
                                                    self._node_config.sleep_time, self._node_config.dbg_child,
                                                    self._reporter_queue)
        else:
            raise ValueError('Unsupported operation mode!')

    def __choose_fuzzer(self):
        return FUZZERS[self._node_config.fuzzer_type][1].from_list(self._node_config.fuzzer_config)

    def __choose_reducer(self):
        if self._node_config.reducer_type == "js_reducer":
            from reducing.javascript import JsReducer
            return JsReducer(self._node_config.reducer_config[0], self._node_config.reducer_config[1])

    def __stop_all_workers(self):
        self._operation_worker.stop_worker()
        if self._node_config.node_net_mode == "net":
            self._listener_worker.stop_worker()
            self._beacon_client.stop_beacon()
            self._tcp_listener.stop()

    def __save_fuzz_state(self):
        fuzz_state = self._fuzzer.prng_state
        with open("fuzz_state.pickle", 'w+') as fd:
            pickle.dump(fuzz_state, fd)  # Save the state of the prng

    def main(self):
        start = time.time()
        self._logger.info("PyFuzz 2 Node started ...")
        if self._node_config.node_net_mode == "net":
            self._beacon_client.start_beacon()
            self._tcp_listener.serve()
            self._listener_worker.start_worker()
        self._report_worker.start_worker()
        self._operation_worker.start_worker()
        while True:
            try:
                if self._node_config.node_net_mode == "net":
                    if self._listener_worker.new_config:
                        self.__stop_all_workers()
                        # self.__save_fuzz_state() if there is a new config it shouldn't restore the state??
                        restart(self._node_config.sleep_time + 5)
                    elif self._listener_worker.reset:
                        self.__stop_all_workers()
                        gevent.sleep(5)
                        if self._node_config.node_op_mode == "fuzzing":
                            self.__save_fuzz_state()
                        gevent.sleep(self._node_config.sleep_time + 5)
                        reboot()
                if time.time() - start > (8*60*60):  # Reboot after eight hours
                    self.__stop_all_workers()
                    gevent.sleep(5)
                    if self._node_config.node_op_mode == "fuzzing":
                        self.__save_fuzz_state()
                    gevent.sleep(self._node_config.sleep_time + 5)
                    reboot()
                gevent.sleep(5)  # It's enough to check the above stuff every 5 seconds instead of burning cpu time
            except KeyboardInterrupt:
                self.__stop_all_workers()
                quit()
Пример #11
0
class PyFuzz2Server:
    def __init__(self, logger, config_filename=CONFIG_FILENAME):
        self._node_dict = {}
        self._crash_dict = {}
        self._logger = logger
        self._config = ConfigParser(config_filename)
        beacon_port, beacon_timeout, config_req_interval = self._config.beacon_config
        report_port = self._config.report_server_config
        web_port = self._config.web_server_config
        self._beacon_queue = Queue()
        self._node_queue = Queue()
        self._report_queue = Queue()
        self._web_queue = Queue()
        self._db_queue = Queue()
        self._db_worker = DatabaseWorker(self._db_queue, self._node_dict,
                                         self._crash_dict)
        self._db_worker.load()
        self._beacon_server = BeaconServer(beacon_port, self._beacon_queue)
        self._beacon_worker = BeaconWorker(self._beacon_queue,
                                           self._node_queue, self._db_queue,
                                           beacon_timeout, config_req_interval,
                                           self._node_dict)
        self._report_server = ReportServer(report_port, self._report_queue)
        self._report_worker = ReportWorker(self._report_queue, self._db_queue,
                                           self._node_dict, self._crash_dict)
        self._node_client_worker = NodeClientWorker(self._node_queue)
        self._web_server = WebServer(web_port, self._web_queue, self.web_main)

    def main(self):
        self._logger.info("PyFuzz2 Server started...")
        self._beacon_server.serve()
        self._beacon_worker.start_worker()
        self._report_server.serve()
        self._report_worker.start_worker()
        self._web_server.serve()
        self._node_client_worker.start_worker()
        self._db_worker.start_worker()
        while True:
            try:
                gevent.wait()
            except KeyboardInterrupt:
                exit(0)

    def web_main(self, environ, start_response):
        site = WebSite()
        func = "home"
        if environ['PATH_INFO'] == "/index.py" or environ['PATH_INFO'] == "/":
            parameters = parse_qs(environ['QUERY_STRING'])
            if "func" in parameters:
                func = parameters['func'][0] if parameters['func'][
                    0] in site.funcs else "home"
            if func == "home":
                if 'reboot' in parameters:
                    key = parameters['reboot'][0]
                    self._beacon_worker.nodes[key].status = False
                    self._node_queue.put([
                        (key, self._beacon_worker.nodes[key].listener_port),
                        MESSAGE_TYPES['RESET'], ""
                    ])
                if "submit" in parameters and "node" in parameters:
                    key = parameters['node'][0]
                    self._logger.debug("Preparing new config")
                    node_conf = node.model.config.ConfigParser.create_config(
                        environ['wsgi.input'].read())
                    self._beacon_worker.nodes[key].status = False
                    self._node_queue.put([
                        (key, self._beacon_worker.nodes[key].listener_port),
                        MESSAGE_TYPES['SET_CONFIG'], node_conf
                    ])
                if "del" in parameters:
                    key = parameters['del'][0]
                    del (self._beacon_worker.nodes[key])
                    self._db_queue.put(DB_TYPES['DELETE_NODE'], key)
                status, headers, html = site.home(self._beacon_worker.nodes)
            elif func == "node_detail":
                if "node" in parameters and parameters['node'][
                        0] in self._beacon_worker.nodes.keys():
                    key = parameters['node'][0]
                    status, headers, html = site.node_detail(
                        self._beacon_worker.nodes[key])
                else:
                    status, headers, html = site.file_not_found()
            elif func == "stats":
                status, headers, html = site.stats(self._node_dict,
                                                   self._crash_dict)
        elif environ['PATH_INFO'] == "/style.css":
            status, headers, html = site.get_style()
        elif environ['PATH_INFO'] == "/scripts.js":
            status, headers, html = site.get_scripts()
        else:
            status, headers, html = site.file_not_found()
        if self._logger.level == logging.DEBUG:
            html += "<br><br>" + str(
                environ
            ) + "<br><br>" + func + "<br><br>" + environ['wsgi.input'].read()
        start_response(status, headers)
        return [str(html)]