def main(): try: addr = config.load()['mix_addr'] port = int(config.load()['mix_port']) bindsocket = socket.socket() bindsocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) bindsocket.bind((addr, port)) bindsocket.listen(300) except Exception as e: conf = config.load() conf['mix_stat'] = "false" config.update(conf) our.error(e) exit() while config.load()['mix_stat'].lower() == "true": try: connstream, fromaddr = bindsocket.accept() t = threading.Thread(target=client_conn, args=(connstream, )) t.start() except Exception as e: out.error("error") print(e) if 'connstream' in dir(): connstream.close() bindsocket.close()
def main(): define("port", default=int(config.load()["port"]), type=int) define("address", default=config.load()["ip"]) tornado.options.parse_command_line() path = lambda root, *a: os.path.join(root, *a) ROOT = os.path.dirname(os.path.abspath(__file__)) settings = {} settings['static_path'] = path(ROOT, "web", "static") settings['template_loader'] = tornado.template.Loader( path(ROOT, "web", "templates")) settings['login_url'] = "/login" settings['debug'] = True site.addsitedir(path(ROOT, 'handlers')) conf = config.load() conf['scapy_stat'] = 'false' conf['tornado_stat'] = 'false' conf['scan_stat'] = 'false' conf['mix_stat'] = 'false' conf['tornado_run_stat'] = 'false' config.update(conf) app = make_app(settings) app.listen(port=options.port, address=options.address) out.good("Web app start at: http://%s:%s" % (options.address, options.port)) tornado.ioloop.IOLoop.current().start()
def post(self): conf_all = config.load() for i in self.request.body.split("&"): para = secure.clear(urllib.unquote(i.split("=", 1)[0])) value = secure.clear(urllib.unquote(i.split("=", 1)[1])) if para in conf_all.keys(): conf_all[para] = value config.update(conf_all) return self.render("config.html", config=config.load())
def get(self): stat = secure.clear(self.get_argument("stat")) config_all = config.load() config_all['scan_stat'] = stat config.update(config_all) if stat.lower() == "true": thread = threading.Thread(target=scan.scan_start, args=()) thread.setDaemon(True) thread.start() return self.write(out.jump("/scan_config"))
def main(): NIC = config.load()["scapy_network_card"] # network adapter name try: if NIC == 'all': sniff(filter="tcp", prn=lambda x: capture(x)) else: sniff(iface=NIC, filter="tcp", prn=lambda x: capture(x)) except Exception as e: error("scapy out!") conf = config.load() conf['scapy_stat'] = "false" config.update(conf)
def update_section(section_name): is_user_section = config.is_user_section(section_name) apply_name = request.forms.get('apply') try: if apply_name == 'submit': form = get_form_dict(request.forms, is_user_section) config.update({ section_name: form }, save=True) return '保存成功 :)' if apply_name == 'delete': config.delete(section_name) return '删除成功 :)' except Exception as e: return exception_format % e
def post(self): proxy_type = self.get_argument("type") if proxy_type == "mix_proxy": conf = config.load() conf["mix_addr"] = secure.clear(self.get_argument("mix_addr")) conf["mix_port"] = secure.clear(self.get_argument("mix_port")) config.update(conf) elif proxy_type == "scapy": conf = config.load() conf['scapy_out'] = secure.clear(self.get_argument('scapy_out')) conf['scapy_network_card'] = self.get_argument( 'scapy_network_card') config.update(conf) elif proxy_type == "tornado": conf = config.load() conf['tornado_address'] = secure.clear( self.get_argument('tornado_address')) conf['tornado_port'] = secure.clear( self.get_argument('tornado_port')) config.update(conf) return self.write(out.jump("/proxy?type=" + proxy_type))
def get(self): proxy_type = self.get_argument("type") conf = {} if proxy_type == "mix_proxy": conf['mix_addr'] = config.load()['mix_addr'] conf['mix_port'] = config.load()['mix_port'] stat = config.load()['mix_stat'] try: start_stat = self.get_argument("stat") start_conf = config.load() start_conf['mix_stat'] = start_stat config.update(start_conf) if start_stat.lower() == "true": thread = threading.Thread(target=mix_proxy.main) thread.setDaemon(True) thread.start() else: secure.kill(config.load()['mix_addr'], int(config.load()['mix_port']), "GE") return self.write(out.jump("/proxy?type=" + proxy_type)) except: pass elif proxy_type == "scapy": conf['scapy_out'] = config.load()['scapy_out'] conf['scapy_network_card'] = config.load()['scapy_network_card'] stat = config.load()['scapy_stat'] try: start_stat = secure.clear(self.get_argument("stat")) start_conf = config.load() start_conf['scapy_stat'] = start_stat config.update(start_conf) if start_stat.lower() == "true": thread = threading.Thread(target=pyscapy.main) thread.setDaemon(True) thread.start() return self.write(out.jump("/proxy?type=" + proxy_type)) except: pass elif proxy_type == "tornado": conf['tornado_address'] = config.load()['tornado_address'] conf['tornado_port'] = config.load()['tornado_port'] stat = config.load()['tornado_stat'] try: start_stat = secure.clear(self.get_argument("stat")) start_conf = config.load() start_conf['tornado_stat'] = start_stat config.update(start_conf) if start_stat.lower() == "true" and config.load( )['tornado_run_stat'] == 'false': thread = threading.Thread(target=proxy_io.main) thread.setDaemon(True) thread.start() start_conf = config.load() start_conf['tornado_run_stat'] = 'true' config.update(start_conf) return self.write(out.jump("/proxy?type=" + proxy_type)) except: pass else: return self.write(out.jump("/")) return self.render("proxy.html", proxy_type=proxy_type, conf=conf, stat=stat)
# ============================================================================= SHUTDOWN = 0 REBOOT = 0 # ============================================================================== # CREATE OR UPDATE wfpiconsole.ini FILE # ============================================================================== # Import required modules from lib import config as configFile from pathlib import Path # Create or update config file if required if not Path('wfpiconsole.ini').is_file(): configFile.create() else: configFile.update() # ============================================================================== # INITIALISE KIVY GRAPHICS BACKEND BASED ON CURRENT HARDWARE TYPE # ============================================================================== # Import required modules import configparser import os # Load config file config = configparser.ConfigParser() config.read('wfpiconsole.ini') # Initialise Kivy backend based on current hardware if config['System']['Hardware'] == 'Pi4': os.environ['SDL_VIDEO_ALLOW_SCREENSAVER'] = '1'