try: # Import here to avoid importing QT in CLI mode from SWParser.gui import gui from PyQt4.QtGui import QApplication, QIcon from PyQt4.QtCore import QSize except ImportError: print "Failed to load GUI dependencies. Switching to CLI mode" options.no_gui = True if options.no_gui: logger.addHandler(logging.StreamHandler()) start_proxy_server(options) else: app = QApplication(sys.argv) # set the icon icons_path = os.path.join(os.getcwd(), resource_path("icons/")) app_icon = QIcon() app_icon.addFile(icons_path +'16x16.png', QSize(16,16)) app_icon.addFile(icons_path + '24x24.png', QSize(24,24)) app_icon.addFile(icons_path + '32x32.png', QSize(32,32)) app_icon.addFile(icons_path + '48x48.png', QSize(48,48)) app_icon.addFile(icons_path + '256x256.png', QSize(256,256)) app.setWindowIcon(app_icon) if options.interface: win = gui.MainWindow(options.interface, options.port) else: win = gui.MainWindow(get_external_ip(), options.port) logger.addHandler(gui.GuiLogHandler(win)) win.show() sys.exit(app.exec_())
# attempt to load gui; fallback if import error if not options.no_gui: try: # Import here to avoid importing QT in CLI mode from SWParser.gui import gui from PyQt4.QtGui import QApplication, QIcon from PyQt4.QtCore import QSize except ImportError: print "Failed to load GUI dependencies. Switching to CLI mode" options.no_gui = True if options.no_gui: logger.addHandler(logging.StreamHandler()) start_proxy_server(options) else: app = QApplication(sys.argv) # set the icon icons_path = os.path.join(os.getcwd(), resource_path("icons/")) app_icon = QIcon() app_icon.addFile(icons_path +'16x16.png', QSize(16,16)) app_icon.addFile(icons_path + '24x24.png', QSize(24,24)) app_icon.addFile(icons_path + '32x32.png', QSize(32,32)) app_icon.addFile(icons_path + '48x48.png', QSize(48,48)) app_icon.addFile(icons_path + '256x256.png', QSize(256,256)) app.setWindowIcon(app_icon) win = gui.MainWindow(get_external_ip(), options.port) logger.addHandler(gui.GuiLogHandler(win)) win.show() sys.exit(app.exec_())
def SWProxyStart(ip, port, log): # parser = argparse.ArgumentParser(description='SWParser') # parser.add_argument('-d', '--debug', action="store_true", default=False) # parser.add_argument('-g', '--no-gui', action="store_true", default=False) # parser.add_argument('-p', '--port', type=int, default=8080) # options, unknown_args = parser.parse_known_args() unknown_args = '' options = Option(ip=ip, port=port, debug=log, no_gui=True) # Set up logger level = "DEBUG" if options.debug else "INFO" logging.basicConfig( level=level, filename="proxy.log", format='%(asctime)s: %(name)s - %(levelname)s - %(message)s') logger.setLevel(logging.INFO) print get_usage_text() # Check if a PCAP file was passed in pcap_filename = None for arg in unknown_args: if arg.endswith('.pcap'): pcap_filename = arg break if pcap_filename: # Parse a PCAP file print "Parsing PCAP file..." parse_pcap(sys.argv[1]) raw_input("Press Enter to exit...") else: # Run the proxy # attempt to load gui; fallback if import error if not options.no_gui: try: # Import here to avoid importing QT in CLI mode from SWParser.gui import gui from PyQt4.QtGui import QApplication, QIcon from PyQt4.QtCore import QSize except ImportError: print "Failed to load GUI dependencies. Switching to CLI mode" options.no_gui = True if options.no_gui: logger.addHandler(logging.StreamHandler()) start_proxy_server(options) else: app = QApplication(sys.argv) # set the icon icons_path = os.path.join(os.getcwd(), resource_path("icons/")) app_icon = QIcon() app_icon.addFile(icons_path + '16x16.png', QSize(16, 16)) app_icon.addFile(icons_path + '24x24.png', QSize(24, 24)) app_icon.addFile(icons_path + '32x32.png', QSize(32, 32)) app_icon.addFile(icons_path + '48x48.png', QSize(48, 48)) app_icon.addFile(icons_path + '256x256.png', QSize(256, 256)) app.setWindowIcon(app_icon) win = gui.MainWindow(options.ip, options.port) logger.addHandler(gui.GuiLogHandler(win)) win.show() sys.exit(app.exec_())