def __init__(self): self.bd = Gtk.Builder() self.bd.add_from_file("rcontool.glade") self.win = self.bd.get_object("main_window") nb = self.bd.get_object("server_info_box") # Force this box to stay small since it likes to expand nb.set_property("expand", False) self.text_tags = self.bd.get_object("text_tags") self.setup_toolbar() statusmanager.set_statusbar(self.bd.get_object("statusbar")) dic = { 'on_about_dialog_delete_event' : self.on_about_dialog_delete_event, 'on_about_dialog_response' : self.on_about_dialog_response, 'on_main_window_destroy' : self.on_main_window_destroy, 'on_server_list_button_press_event' : self.on_server_list_button_press_event, 'on_act_quit_activate' : self.on_act_quit_activate, 'on_about_menuitem_activate' : self.on_about_menuitem_activate, } self.servermanager = servermanager.ServerManager(self.bd, dic, self) self.bd.connect_signals(dic) self.win.show()
def replay(options, replay_filename): if options.admin_check and options.IsRootRequired(): platformsettings.rerun_as_administrator() configure_logging(options.log_level, options.log_file) server_manager = servermanager.ServerManager(options.record) cache_misses = None if options.cache_miss_file: if os.path.exists(options.cache_miss_file): logging.warning( 'Cache Miss Archive file %s already exists; ' 'replay will load and append entries to archive file', options.cache_miss_file) cache_misses = cachemissarchive.CacheMissArchive.Load( options.cache_miss_file) else: cache_misses = cachemissarchive.CacheMissArchive( options.cache_miss_file) if options.server: AddDnsForward(server_manager, options.server) else: real_dns_lookup = dnsproxy.RealDnsLookup( name_servers=[platformsettings.get_original_primary_nameserver()]) if options.record: httparchive.HttpArchive.AssertWritable(replay_filename) if options.append and os.path.exists(replay_filename): http_archive = httparchive.HttpArchive.Load(replay_filename) logging.info('Appending to %s (loaded %d existing responses)', replay_filename, len(http_archive)) else: http_archive = httparchive.HttpArchive() else: http_archive = httparchive.HttpArchive.Load(replay_filename) logging.info('Loaded %d responses from %s', len(http_archive), replay_filename) server_manager.AppendRecordCallback(real_dns_lookup.ClearCache) server_manager.AppendRecordCallback(http_archive.clear) ipfw_dns_host = None if options.dns_forwarding or options.shaping_dummynet: # compute the ip/host used for the DNS server and traffic shaping ipfw_dns_host = options.host if not ipfw_dns_host: ipfw_dns_host = platformsettings.get_server_ip_address( options.server_mode) if options.dns_forwarding: if not options.server_mode and ipfw_dns_host == '127.0.0.1': AddDnsForward(server_manager, ipfw_dns_host) AddDnsProxy(server_manager, options, ipfw_dns_host, options.dns_port, real_dns_lookup, http_archive) if options.ssl and options.https_root_ca_cert_path is None: options.https_root_ca_cert_path = os.path.join( os.path.dirname(__file__), 'wpr_cert.pem') http_proxy_address = options.host if not http_proxy_address: http_proxy_address = platformsettings.get_httpproxy_ip_address( options.server_mode) AddWebProxy(server_manager, options, http_proxy_address, real_dns_lookup, http_archive, cache_misses) AddTrafficShaper(server_manager, options, ipfw_dns_host) exit_status = 0 try: server_manager.Run() except KeyboardInterrupt: logging.info('Shutting down.') except (dnsproxy.DnsProxyException, trafficshaper.TrafficShaperException, platformsettings.NotAdministratorError, platformsettings.DnsUpdateError) as e: logging.critical('%s: %s', e.__class__.__name__, e) exit_status = 1 except: logging.critical(traceback.format_exc()) exit_status = 2 if options.record: http_archive.Persist(replay_filename) logging.info('Saved %d responses to %s', len(http_archive), replay_filename) if cache_misses: cache_misses.Persist() logging.info('Saved %d cache misses and %d requests to %s', cache_misses.get_total_cache_misses(), len(cache_misses.request_counts.keys()), options.cache_miss_file) return exit_status
def replay(options, replay_filename): if options.record and sys.version_info < (2, 7, 9): print ('Need Python 2.7.9 or greater for recording mode.\n' 'For instructions on how to upgrade Python on Ubuntu 14.04, see:\n' 'http://mbless.de/blog/2016/01/09/upgrade-to-python-2711-on-ubuntu-1404-lts.html\n') if options.admin_check and options.IsRootRequired(): platformsettings.rerun_as_administrator() configure_logging(options.log_level, options.log_file) server_manager = servermanager.ServerManager(options.record) if options.server: AddDnsForward(server_manager, options.server) else: if options.record: httparchive.HttpArchive.AssertWritable(replay_filename) if options.append and os.path.exists(replay_filename): http_archive = httparchive.HttpArchive.Load(replay_filename) logging.info('Appending to %s (loaded %d existing responses)', replay_filename, len(http_archive)) else: http_archive = httparchive.HttpArchive() else: http_archive = httparchive.HttpArchive.Load(replay_filename) logging.info('Loaded %d responses from %s', len(http_archive), replay_filename) server_manager.AppendRecordCallback(http_archive.clear) ipfw_dns_host = None if options.dns_forwarding or options.shaping_dummynet: # compute the ip/host used for the DNS server and traffic shaping ipfw_dns_host = options.host if not ipfw_dns_host: ipfw_dns_host = platformsettings.get_server_ip_address( options.server_mode) real_dns_lookup = dnsproxy.RealDnsLookup( name_servers=[platformsettings.get_original_primary_nameserver()], dns_forwarding=options.dns_forwarding, proxy_host=ipfw_dns_host, proxy_port=options.dns_port) server_manager.AppendRecordCallback(real_dns_lookup.ClearCache) if options.dns_forwarding: if not options.server_mode and ipfw_dns_host == '127.0.0.1': AddDnsForward(server_manager, ipfw_dns_host) AddDnsProxy(server_manager, options, ipfw_dns_host, options.dns_port, real_dns_lookup, http_archive) if options.ssl and options.https_root_ca_cert_path is None: options.https_root_ca_cert_path = os.path.join(os.path.dirname(__file__), 'wpr_cert.pem') http_proxy_address = options.host if not http_proxy_address: http_proxy_address = platformsettings.get_httpproxy_ip_address( options.server_mode) AddWebProxy(server_manager, options, http_proxy_address, real_dns_lookup, http_archive) AddTrafficShaper(server_manager, options, ipfw_dns_host) exit_status = 0 try: server_manager.Run() except KeyboardInterrupt: logging.info('Shutting down.') except (dnsproxy.DnsProxyException, trafficshaper.TrafficShaperException, platformsettings.NotAdministratorError, platformsettings.DnsUpdateError) as e: logging.critical('%s: %s', e.__class__.__name__, e) exit_status = 1 except Exception: logging.critical(traceback.format_exc()) exit_status = 2 if options.record: http_archive.Persist(replay_filename) logging.info('Saved %d responses to %s', len(http_archive), replay_filename) return exit_status
def replay(options, replay_filename): platform_settings = platformsettings.get_platform_settings() if options.IsRootRequired(): platform_settings.rerun_as_administrator() configure_logging(platform_settings, options.log_level, options.log_file) server_manager = servermanager.ServerManager(options.record) cache_misses = None if options.cache_miss_file: if os.path.exists(options.cache_miss_file): logging.warning('Cache Miss Archive file %s already exists; ' 'replay will load and append entries to archive file', options.cache_miss_file) cache_misses = cachemissarchive.CacheMissArchive.Load( options.cache_miss_file) else: cache_misses = cachemissarchive.CacheMissArchive( options.cache_miss_file) if options.server: AddDnsForward(server_manager, platform_settings, options.server) else: host = platform_settings.get_server_ip_address(options.server_mode) real_dns_lookup = dnsproxy.RealDnsLookup( name_servers=[platform_settings.get_original_primary_dns()]) if options.record: http_archive = httparchive.HttpArchive() http_archive.AssertWritable(replay_filename) else: http_archive = httparchive.HttpArchive.Load(replay_filename) logging.info('Loaded %d responses from %s', len(http_archive), replay_filename) server_manager.AppendRecordCallback(real_dns_lookup.ClearCache) server_manager.AppendRecordCallback(http_archive.clear) if options.dns_forwarding: if not options.server_mode: AddDnsForward(server_manager, platform_settings, host) AddDnsProxy(server_manager, options, host, real_dns_lookup, http_archive) if options.ssl and options.certfile is None: options.certfile = platform_settings.get_certfile_name() server_manager.AppendStartStopFunctions( [platform_settings.create_certfile, options.certfile], [os.unlink, options.certfile]) AddWebProxy(server_manager, options, host, real_dns_lookup, http_archive, cache_misses) AddTrafficShaper(server_manager, options, host) exit_status = 0 try: server_manager.Run() except KeyboardInterrupt: logging.info('Shutting down.') except (dnsproxy.DnsProxyException, trafficshaper.TrafficShaperException, platformsettings.NotAdministratorError, platformsettings.DnsUpdateError) as e: logging.critical('%s: %s', e.__class__.__name__, e) exit_status = 1 except: logging.critical(traceback.format_exc()) exit_status = 2 if options.record: http_archive.Persist(replay_filename) logging.info('Saved %d responses to %s', len(http_archive), replay_filename) if cache_misses: cache_misses.Persist() logging.info('Saved %d cache misses and %d requests to %s', cache_misses.get_total_cache_misses(), len(cache_misses.request_counts.keys()), options.cache_miss_file) return exit_status
def __init__(self,id): self.id = id self.sm = servermanager.ServerManager(self) self.logingate = logingate.Logingate(self)
import os import socket import threadpool import servermanager pool=threadpool.ThreadPool(1000) port_number=8080 address=socket.gethostbyname(socket.gethostname()) manager=servermanager.ServerManager("root") activE=True def run_server(): sock=socket.socket(socket.AF_INET,socket.SOCK_STREAM) server_address=('0.0.0.0',port_number) sock.bind(server_address) sock.listen(1) while activE: connect,user_address=sock.accept() pool.add_task( messages, connect, user_address ) #Add in locking and caching def messages(connect,user_address):