示例#1
0
 def run(self):
     signal.signal(signal.SIGINT, self.sigHandler)
     if self.config["GENERAL"]["PARENT_PROXY"] and self.config["GENERAL"]["AVAILABLE_PROXY_LIST"]:
         self.watchUpstream = 1
         self.monitor = monitor_upstream.monitorThread(self.config, signal.SIGINT)
         thread.start_new_thread(self.monitor.run, ())
     try:
         s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         s.bind((self.MyHost, self.ListenPort))
     except socket.error:
         print "ERROR: Could not create socket. Possibly port %s is still being used by another process." % self.config[
             "GENERAL"
         ][
             "LISTEN_PORT"
         ]
         sys.exit(1)
     print "Now listening at %s on port %s" % (self.config["GENERAL"]["HOST"], self.config["GENERAL"]["LISTEN_PORT"])
     while 1:
         s.listen(self.config["GENERAL"]["MAX_CONNECTION_BACKLOG"])
         try:
             conn, addr = s.accept()
             if self.config["GENERAL"]["ALLOW_EXTERNAL_CLIENTS"]:
                 self.client_run(conn, addr)
             else:
                 if addr[0] in self.config["GENERAL"]["FRIENDLY_IPS"]:
                     self.client_run(conn, addr)
                 else:
                     conn.close()
         except socket.error:
             pass
     s.close()
示例#2
0
文件: server.py 项目: cyril-wx/mutils
 def run(self):
     signal.signal(signal.SIGINT, self.sigHandler)
     if self.config['GENERAL']['PARENT_PROXY'] and self.config['GENERAL'][
             'AVAILABLE_PROXY_LIST']:
         self.watchUpstream = 1
         self.monitor = monitor_upstream.monitorThread(
             self.config, signal.SIGINT)
         thread.start_new_thread(self.monitor.run, ())
     try:
         s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
         s.bind((self.MyHost, self.ListenPort))
     except socket.error:
         print "ERROR: Could not create socket. Possibly port %s is still being used by another process." % self.config[
             'GENERAL']['LISTEN_PORT']
         sys.exit(1)
     print 'Now listening at %s on port %s' % (
         self.config['GENERAL']['HOST'],
         self.config['GENERAL']['LISTEN_PORT'])
     while (1):
         s.listen(self.config['GENERAL']['MAX_CONNECTION_BACKLOG'])
         try:
             conn, addr = s.accept()
             if self.config['GENERAL']['ALLOW_EXTERNAL_CLIENTS']:
                 self.client_run(conn, addr)
             else:
                 if addr[0] in self.config['GENERAL']['FRIENDLY_IPS']:
                     self.client_run(conn, addr)
                 else:
                     conn.close()
         except socket.error:
             pass
     s.close()
示例#3
0
文件: server.py 项目: cyril-wx/mutils
 def sigHandler(self, signum=None, frame=None):
     if signum == signal.SIGINT:
         if self.watchUpstream:
             if self.sigLock.acquire(0):
                 old_monitor = self.monitor
                 self.config['GENERAL']['AVAILABLE_PROXY_LIST'].insert(
                     0, self.config['GENERAL']['PARENT_PROXY'])
                 self.monLock.acquire(
                 )  # Keep locked section as small as possible
                 self.config['GENERAL']['PARENT_PROXY'] = self.config[
                     'GENERAL']['AVAILABLE_PROXY_LIST'].pop()
                 self.monitor = monitor_upstream.monitorThread(
                     self.config, signal.SIGINT)
                 self.monLock.release()
                 print "Moving to proxy server: " + self.config['GENERAL'][
                     'PARENT_PROXY']
                 old_monitor.alive = 0
                 thread.start_new_thread(self.monitor.run, ())
                 map(lambda x: x.exit(), old_monitor.threadsToKill)
                 old_monitor.die()  # Protected from recursion by lock
                 self.sigLock.release()
         else:
             # SIGINT is only special if we are in upstream mode:
             print 'Got SIGINT, exiting now...'
             sys.exit(1)
     else:
         print 'Got SIGNAL ' + str(signum) + ', exiting now...'
         sys.exit(1)
     return
示例#4
0
 def run(self):
     self.stop_thread = False
     #signal.signal(signal.SIGINT, self.sigHandler)
     if self.config['GENERAL']['PARENT_PROXY'] and self.config['GENERAL']['AVAILABLE_PROXY_LIST']:
         self.watchUpstream = 1
         self.monitor = monitor_upstream.monitorThread(self.config, signal.SIGINT)
         thread.start_new_thread(self.monitor.run, ())
     try:
         s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         s.bind((self.MyHost, self.ListenPort))
     except socket.error:
         print "ERROR: Could not create socket. Possibly port %s is still being used by another process." % self.config['GENERAL']['LISTEN_PORT']
         sys.exit(1)
     print 'Now listening at %s on port %s' % (self.config['GENERAL']['HOST'], self.config['GENERAL']['LISTEN_PORT'])
     while(not self.stop_thread):
         s.listen(self.config['GENERAL']['MAX_CONNECTION_BACKLOG'])
         try:
             conn, addr = s.accept()
             if self.config['GENERAL']['ALLOW_EXTERNAL_CLIENTS']:
                 self.client_run(conn, addr)
             else:
                 if addr[0] in self.config['GENERAL']['FRIENDLY_IPS']:
                     self.client_run(conn, addr)
                 else:
                     conn.close()
         except socket.error:
             pass
     s.close()
     print "Proxy Stopped"
示例#5
0
文件: server.py 项目: qluo1/ntlmaps
    def run(self):
        signal.signal(signal.SIGINT, self.sigHandler)
        if (
            self.config["GENERAL"]["PARENT_PROXY"]
            and self.config["GENERAL"]["AVAILABLE_PROXY_LIST"]
        ):
            self.watchUpstream = 1
            self.monitor = monitor_upstream.monitorThread(self.config, signal.SIGINT)
            thread.start_new_thread(self.monitor.run, ())
        try:
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s.bind((self.MyHost, self.ListenPort))
        except socket.error:
            print(
                "ERROR: Could not create socket. Possibly port %s is still being used by another process."
                % self.config["GENERAL"]["LISTEN_PORT"]
            )
            sys.exit(1)
        print(
            "Now listening at %s on port %s"
            % (self.config["GENERAL"]["HOST"], self.config["GENERAL"]["LISTEN_PORT"])
        )
        while 1:
            s.listen(self.config["GENERAL"]["MAX_CONNECTION_BACKLOG"])
            try:
                conn, addr = s.accept()
                LOG.info("accept conn from: %s", addr)
                if self.config["GENERAL"]["ALLOW_EXTERNAL_CLIENTS"]:
                    self.client_run(conn, addr)
                else:
                    if addr[0] in self.config["GENERAL"]["FRIENDLY_IPS"]:
                        self.client_run(conn, addr)
                    else:
                        conn.close()
            except socket.error as e:
                LOG.exception(e)

        s.close()
示例#6
0
 def sigHandler(self, signum=None, frame=None):
     if signum == signal.SIGINT:
         if self.watchUpstream:
             if self.sigLock.acquire(0):
                 old_monitor = self.monitor
                 self.config["GENERAL"]["AVAILABLE_PROXY_LIST"].insert(0, self.config["GENERAL"]["PARENT_PROXY"])
                 self.monLock.acquire()  # Keep locked section as small as possible
                 self.config["GENERAL"]["PARENT_PROXY"] = self.config["GENERAL"]["AVAILABLE_PROXY_LIST"].pop()
                 self.monitor = monitor_upstream.monitorThread(self.config, signal.SIGINT)
                 self.monLock.release()
                 print "Moving to proxy server: " + self.config["GENERAL"]["PARENT_PROXY"]
                 old_monitor.alive = 0
                 thread.start_new_thread(self.monitor.run, ())
                 map(lambda x: x.exit(), old_monitor.threadsToKill)
                 old_monitor.die()  # Protected from recursion by lock
                 self.sigLock.release()
         else:
             # SIGINT is only special if we are in upstream mode:
             print "Got SIGINT, exiting now..."
             sys.exit(1)
     else:
         print "Got SIGNAL " + str(signum) + ", exiting now..."
         sys.exit(1)
     return