Пример #1
0
 def realtimeloadcfg(self):
     #return 
     import ProxyConfig
     cfgfile = 'config.json'
     cfgcls = ProxyConfig.config(cfgfile)
     (rdtrules,mdfrules,repostrules) = cfgcls.read()
     self.mdfrules = mdfrules['Rules']
     self.redirectrules = rdtrules['Rules']
     self.repostrules =  repostrules['Rules']
Пример #2
0
 def realtimeloadcfg(self):
     return 
     import ProxyConfig
     from gt.gtcore.env import Gtenv
     myenv = Gtenv("")
     path = myenv.getpath()
     print path
     cfgfile = path + '/config.json'
     cfgcls = ProxyConfig.config(cfgfile)
     (rdtrules,mdfrules,repostrules) = cfgcls.read()
     self.mdfrules = mdfrules['Rules']
     self.redirectrules = rdtrules['Rules']
     self.repostrules =  repostrules['Rules']
Пример #3
0
   if daemon:
       pass
       #daemonize (logger)
   signal.signal (signal.SIGINT, handler)
 
   if args:
       allowed = []
       for name in args:
           client = socket.gethostbyname(name)
           allowed.append(client)
           logger.log (logging.INFO, "Accept: %s (%s)" % (client, name))
       ProxyHandler.allowed_clients = allowed
   else:
       logger.log (logging.INFO, "Any clients will be served...")
       
   cfgcls = ProxyConfig.config(cfgfile)
   cfg = {}
   (cfg['Redirect'],cfg['Modify']) = cfgcls.read()
   ProxyHandler.config = cfg
   
   rulematch = RuleMatch.RuleMatch(cfg['Redirect'],cfg['Modify'])
   ProxyHandler.rulehandler = rulematch
 
   #server_address = (socket.gethostbyname (local_hostname), port)
   server_address = ('127.0.0.1', port)
   ProxyHandler.protocol = "HTTP/1.0"
   httpd = ThreadingHTTPServer (server_address, ProxyHandler, logger)
   sa = httpd.socket.getsockname ()
   print "Servering HTTP on", sa[0], "port", sa[1]
   req_count = 0
   while not run_event.isSet ():
Пример #4
0
def init():
    cfgcls = ProxyConfig.config('test.json')
    cfg = cfgcls.read()
    return cfg
Пример #5
0
def main ():
    path = sys.path[0]
    if os.path.isfile(path):
        path = os.path.dirname(path)
    #path = "F:\\release"
    gtdir = path
    myenv = Gtenv(path) 
    path = myenv.getpath() 
    cfgfile = path + '/config.json'
    logfile = ""
    try:
        cf = ConfigParser.ConfigParser()
        cf.read(path + "/service.ini")
        logfile = path + "/" + cf.get("log","proxy")
    except Exception as e:
        pass    
    if logfile == '':
        logfile = path + '/proxy.log'
    daemon  = False
    max_log_size = 2
    port = 8000
    allowed = []
    run_event = threading.Event ()
    local_hostname = socket.gethostname ()
    
    '''
  
    try: opts, args = getopt.getopt (sys.argv[1:], "l:dhp:", [])
    except getopt.GetoptError, e:
        usage (str (e))
        return 1
  
    for opt, value in opts:
        if opt == "-c": cfgfile = value
        if opt == "-p": port = int (value)
        if opt == "-l": logfile = value
        if opt == "-d": daemon = not daemon
        if opt == "-h":
            usage ()
            return 0
            
    '''
  
    # setup the log file
    logger = logSetup (logfile, max_log_size, daemon)
    
    #logger.info("a..........")
    
    licdays,licdate = trial.haskey()
    if licdays == 0 or (licdate - date.today()).days < 0:
        licdays,licdate = auth.haslic()
        if licdays == 0 or (licdate - date.today()).days < 0:
            logger.warning('试用授权到期或没有正式授权文件,系统启动失败!')
            return 0
        else:
            myenv.istrial = False
            myenv.licdate = licdate
    else:
        myenv.istrial = True
        myenv.licdate = licdate
    if daemon:
        pass
        #daemonize (logger)
    #signal.signal (signal.SIGINT, handler) #必须屏蔽
    #logger.info("b..........")
  
    '''
    if args:
        allowed = []
        for name in args:
            client = socket.gethostbyname(name)
            allowed.append(client)
            logger.log (logging.INFO, "Accept: %s (%s)" % (client, name))
        ProxyHandler.allowed_clients = allowed
    else:
        logger.log (logging.WARNING, "Any clients will be served...")
    '''
        
    cfgcls = ProxyConfig.config(cfgfile)
    cfg = {}
    (cfg['Redirect'],cfg['Modify'],cfg['Repost']) = cfgcls.read()
    ProxyHandler.config = cfg
    
    rulematch = RuleMatch.RuleMatch(cfg['Redirect'],cfg['Modify'],cfg['Repost'])
    ProxyHandler.rulehandler = rulematch
  
    #server_address = (socket.gethostbyname (local_hostname), port)
    server_address = ('127.0.0.1', port)
    ProxyHandler.protocol = "HTTP/1.0"
    httpd = ThreadingHTTPServer (server_address, ProxyHandler, logger)
    sa = httpd.socket.getsockname ()
    logger.warning("Servering HTTP Proxy on %s port %s", sa[0], sa[1])
    req_count = 0
    myenv.running = True
    myenv.checked = False
    while myenv.running and not run_event.isSet ():
        try:
            httpd.handle_request ()
            req_count += 1
            if req_count == 1000:
                logger.log (logging.INFO, "Number of active threads: %s",
                            threading.activeCount ())
                req_count = 0
            if not myenv.running:
                httpd.__is_shut_down = True
        except select.error, e:
            if e[0] == 4: pass
            else:
                logger.log (logging.CRITICAL, "Errno: %d - %s", e[0], e[1])