示例#1
0
 def __init__(self, config=None, dbengine=None, **kwargs):
     self.config = config
     self.db_engine = dbengine or get_engine(config, pool_size=20)
     self.aes = kwargs.pop("aes", None)
     self.cache = kwargs.pop(
         "cache",
         CacheManager(redis_conf(config),
                      cache_name='RadiusTaskCache-%s' % os.getpid()))
     self.cache.print_hit_stat(300)
     self.db = scoped_session(
         sessionmaker(bind=self.db_engine,
                      autocommit=False,
                      autoflush=False))
     self.taskclss = []
     self.load_tasks()
     if not kwargs.get('standalone'):
         logger.info("start register taskd events")
         dispatch.register(log_trace.LogTrace(redis_conf(config)),
                           check_exists=True)
         event_params = dict(dbengine=self.db_engine,
                             mcache=self.cache,
                             aes=self.aes)
         event_path = os.path.abspath(
             os.path.dirname(toughradius.manage.events.__file__))
         dispatch.load_events(event_path,
                              "toughradius.manage.events",
                              event_params=event_params)
示例#2
0
    def __init__(self, config=None, dbengine=None, **kwargs):

        self.config = config

        settings = dict(
            cookie_secret="12oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo=",
            login_url="/admin/login",
            template_path=os.path.join(os.path.dirname(toughradius.__file__), "views"),
            static_path=os.path.join(os.path.dirname(toughradius.__file__), "static"),
            xsrf_cookies=True,
            config=self.config,
            debug=self.config.system.debug,
            xheaders=True,
        )

        self.tp_lookup = TemplateLookup(
            directories=[settings['template_path']],
            default_filters=['decode.utf8'],
            input_encoding='utf-8',
            output_encoding='utf-8',
            encoding_errors='ignore',
            module_directory="/tmp/toughradius_admin"
        )

        self.db_engine = dbengine or get_engine(config)
        self.db = scoped_session(sessionmaker(bind=self.db_engine, autocommit=False, autoflush=False))
        self.session_manager = session.SessionManager(settings["cookie_secret"], self.db_engine, 600)

        redisconf = redis_conf(config)
        self.session_manager = redis_session.SessionManager(redisconf,settings["cookie_secret"], 600)
        self.mcache = redis_cache.CacheManager(redisconf,cache_name='RadiusManageCache-%s'%os.getpid())
        self.mcache.print_hit_stat(60)
        
        self.db_backup = DBBackup(models.get_metadata(self.db_engine), excludes=[
            'tr_online','system_session','system_cache','tr_ticket','tr_billing','tr_online_stat',
            'tr_flow_stat'
        ])

        self.aes = utils.AESCipher(key=self.config.system.secret)

        # cache event init
        dispatch.register(self.mcache)

        # app init_route
        load_handlers(handler_path=os.path.join(os.path.abspath(os.path.dirname(__file__))),
            pkg_prefix="toughradius.manage", excludes=['views','webserver','radius'])

        # app event init
        event_params= dict(dbengine=self.db_engine, mcache=self.mcache, aes=self.aes)
        dispatch.load_events(os.path.join(os.path.abspath(os.path.dirname(toughradius.manage.events.__file__))),
            "toughradius.manage.events",event_params=event_params)

        permit.add_route(cyclone.web.StaticFileHandler, 
                            r"/admin/backup/download/(.*)",
                            u"下载数据",MenuSys, 
                            handle_params={"path": self.config.database.backup_path},
                            order=5.0005)
        cyclone.web.Application.__init__(self, permit.all_handlers, **settings)
示例#3
0
    def __init__(self, config=None, dbengine=None, **kwargs):

        self.config = config

        settings = dict(
            cookie_secret="12oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo=",
            login_url="/admin/login",
            template_path=os.path.join(os.path.dirname(toughradius.__file__), "views"),
            static_path=os.path.join(os.path.dirname(toughradius.__file__), "static"),
            xsrf_cookies=True,
            config=self.config,
            debug=self.config.system.debug,
            xheaders=True,
        )

        self.tp_lookup = TemplateLookup(
            directories=[settings['template_path']],
            default_filters=['decode.utf8'],
            input_encoding='utf-8',
            output_encoding='utf-8',
            encoding_errors='ignore',
            module_directory="/tmp/toughradius_admin"
        )

        self.db_engine = dbengine or get_engine(config)
        self.db = scoped_session(sessionmaker(bind=self.db_engine, autocommit=False, autoflush=False))
        self.session_manager = session.SessionManager(settings["cookie_secret"], self.db_engine, 600)

        redisconf = redis_conf(config)
        self.session_manager = redis_session.SessionManager(redisconf,settings["cookie_secret"], 600)
        self.mcache = redis_cache.CacheManager(redisconf,cache_name='RadiusManageCache-%s'%os.getpid())
        self.mcache.print_hit_stat(60)
        
        self.db_backup = DBBackup(models.get_metadata(self.db_engine), excludes=[
            'tr_online','system_session','system_cache','tr_ticket'])

        self.aes = utils.AESCipher(key=self.config.system.secret)

        # cache event init
        dispatch.register(self.mcache)

        # app init_route
        load_handlers(handler_path=os.path.join(os.path.abspath(os.path.dirname(__file__))),
            pkg_prefix="toughradius.manage", excludes=['views','webserver','radius'])

        # app event init
        event_params= dict(dbengine=self.db_engine, mcache=self.mcache, aes=self.aes)
        dispatch.load_events(os.path.join(os.path.abspath(os.path.dirname(toughradius.manage.events.__file__))),
            "toughradius.manage.events",event_params=event_params)

        permit.add_route(cyclone.web.StaticFileHandler, 
                            r"/admin/backup/download/(.*)",
                            u"下载数据",MenuSys, 
                            handle_params={"path": self.config.database.backup_path},
                            order=5.0005)
        cyclone.web.Application.__init__(self, permit.all_handlers, **settings)
示例#4
0
def run_worker(config,dbengine,**kwargs):
    _cache = kwargs.pop("cache",CacheManager(redis_conf(config),cache_name='RadiusWorkerCache-%s'%os.getpid()))
    _cache.print_hit_stat(60)
    # app event init
    if not kwargs.get('standalone'):
        event_params= dict(dbengine=dbengine, mcache=_cache, aes=kwargs.pop('aes',None))
        event_path = os.path.abspath(os.path.dirname(toughradius.manage.events.__file__))
        dispatch.load_events(event_path,"toughradius.manage.events",event_params=event_params)
    logger.info('start radius worker: %s' % RADIUSAuthWorker(config,dbengine,radcache=_cache))
    logger.info('start radius worker: %s' % RADIUSAcctWorker(config,dbengine,radcache=_cache))
示例#5
0
def run_worker(config,dbengine,**kwargs):
    _cache = kwargs.pop("cache",CacheManager(redis_conf(config),cache_name='RadiusWorkerCache-%s'%os.getpid()))
    _cache.print_hit_stat(60)
    # app event init
    if not kwargs.get('standalone'):
        event_params= dict(dbengine=dbengine, mcache=_cache, aes=kwargs.pop('aes',None))
        event_path = os.path.abspath(os.path.dirname(toughradius.manage.events.__file__))
        dispatch.load_events(event_path,"toughradius.manage.events",event_params=event_params)
    logger.info('start radius worker: %s' % RADIUSAuthWorker(config,dbengine,radcache=_cache))
    logger.info('start radius worker: %s' % RADIUSAcctWorker(config,dbengine,radcache=_cache))
示例#6
0
 def __init__(self, config=None, dbengine=None, **kwargs):
     self.config = config
     self.db_engine = dbengine or get_engine(config,pool_size=20)
     self.aes = kwargs.pop("aes",None)
     self.cache = kwargs.pop("cache",CacheManager(redis_conf(config),cache_name='RadiusTaskCache-%s'%os.getpid()))
     self.cache.print_hit_stat(60)
     self.db = scoped_session(sessionmaker(bind=self.db_engine, autocommit=False, autoflush=False))
     self.taskclss = []
     self.load_tasks()
     if not kwargs.get('standalone'):
         event_params= dict(dbengine=self.db_engine, mcache=self.cache,aes=self.aes)
         event_path = os.path.abspath(os.path.dirname(toughradius.manage.events.__file__))
         dispatch.load_events(event_path,"toughradius.manage.events",event_params=event_params)
示例#7
0
 def __init__(self, config=None, dbengine=None, **kwargs):
     self.config = config
     self.db_engine = dbengine or get_engine(config,pool_size=20)
     self.aes = kwargs.pop("aes",None)
     self.cache = kwargs.pop("cache",CacheManager(redis_conf(config),cache_name='RadiusTaskCache-%s'%os.getpid()))
     self.cache.print_hit_stat(60)
     self.db = scoped_session(sessionmaker(bind=self.db_engine, autocommit=False, autoflush=False))
     # init task
     self.expire_notify_task = expire_notify.ExpireNotifyTask(self)
     self.ddns_update_task = ddns_update.DdnsUpdateTask(self)
     self.radius_stat_task = radius_stat.RadiusStatTask(self)
     self.online_stat_task = online_stat.OnlineStatTask(self)
     self.flow_stat_task = flow_stat.FlowStatTask(self)
     if not kwargs.get('standalone'):
         event_params= dict(dbengine=self.db_engine, mcache=self.cache,aes=self.aes)
         event_path = os.path.abspath(os.path.dirname(toughradius.manage.events.__file__))
         dispatch.load_events(event_path,"toughradius.manage.events",event_params=event_params)