コード例 #1
0
ファイル: toughctl.py プロジェクト: talkincode/ToughNMS
def run():
    log.startLogging(sys.stdout)
    parser = argparse.ArgumentParser()
    parser.add_argument('-manage', '--manage', action='store_true', default=False, dest='manage', help='run manage')
    parser.add_argument('-initdb', '--initdb', action='store_true', default=False, dest='initdb', help='run initdb')
    parser.add_argument('-port', '--port', type=int, default=0, dest='port', help='admin port')
    parser.add_argument('-debug', '--debug', action='store_true', default=False, dest='debug', help='debug option')
    parser.add_argument('-x', '--xdebug', action='store_true', default=False, dest='xdebug', help='xdebug option')
    parser.add_argument('-c', '--conf', type=str, default="/etc/toughnms.json", dest='conf', help='config file')
    args = parser.parse_args(sys.argv[1:])

    config = iconfig.find_config(args.conf)
    syslog = logger.Logger(config)
    dbengine = get_engine(config)
    dispatch.register(syslog)

    with open("/var/toughnms/token","wb") as tf:
        tf.write(md5(config.system.secret.encode('utf-8')).hexdigest())

    update_timezone(config)
    check_env(config)

    if args.debug or args.xdebug:
        config.defaults.debug = True

    if args.port > 0:
        config.server.port = int(args.port)

    if args.manage:
        from toughnms.console import admin_app
        admin_app.run(config,dbengine)
        reactor.run()

    if args.initdb:
        init_db.update(get_engine(config))
コード例 #2
0
 def __init__(self, config, dbengine, radcache=None):
     self.config = config
     self.dict = dictionary.Dictionary(
         os.path.join(os.path.dirname(toughradius.__file__),
                      'dictionarys/dictionary'))
     self.db_engine = dbengine or get_engine(config)
     self.mcache = radcache
     self.pusher = ZmqPushConnection(
         ZmqFactory(),
         ZmqEndpoint('connect', 'ipc:///tmp/radiusd-acct-result'))
     self.stat_pusher = ZmqPushConnection(
         ZmqFactory(), ZmqEndpoint('connect',
                                   'ipc:///tmp/radiusd-stat-task'))
     self.puller = ZmqPullConnection(
         ZmqFactory(),
         ZmqEndpoint('connect', 'ipc:///tmp/radiusd-acct-message'))
     self.puller.onPull = self.process
     logger.info("init acct worker pusher : %s " % (self.pusher))
     logger.info("init acct worker puller : %s " % (self.puller))
     logger.info("init auth stat pusher : %s " % (self.stat_pusher))
     self.acct_class = {
         STATUS_TYPE_START: RadiusAcctStart,
         STATUS_TYPE_STOP: RadiusAcctStop,
         STATUS_TYPE_UPDATE: RadiusAcctUpdate,
         STATUS_TYPE_ACCT_ON: RadiusAcctOnoff,
         STATUS_TYPE_ACCT_OFF: RadiusAcctOnoff
     }
コード例 #3
0
ファイル: taskd.py プロジェクト: zhangzhezh/ToughRADIUS
 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)
コード例 #4
0
ファイル: taskd.py プロジェクト: leigf/ToughRADIUS
    def __init__(self, config=None, dbengine=None, **kwargs):

        self.config = config
        self.db_engine = dbengine or get_engine(config)
        self.db = scoped_session(sessionmaker(bind=self.db_engine, autocommit=False, autoflush=False))
        self.expire_notify_task = expire_notify.ExpireNotifyTask(config,self.db)
        self.ddns_update_task = ddns_update.DdnsUpdateTask(config,self.db)
コード例 #5
0
ファイル: radiusd.py プロジェクト: leigf/ToughRADIUS
 def __init__(self, config, dbengine):
     self.config = config
     self.dict = dictionary.Dictionary(
         os.path.join(os.path.dirname(toughradius.__file__), 'dictionarys/dictionary'))
     self.db_engine = dbengine or get_engine(config)
     self.aes = utils.AESCipher(key=self.config.system.secret)
     self.mcache = mcache.Mcache()
コード例 #6
0
ファイル: toughctl.py プロジェクト: talkincode/toughtester
def run():
    log.startLogging(sys.stdout)
    parser = argparse.ArgumentParser()
    parser.add_argument('-admin', '--admin', action='store_true', default=False, dest='admin', help='run admin')
    parser.add_argument('-initdb', '--initdb', action='store_true', default=False, dest='initdb', help='run initdb')
    parser.add_argument('-debug', '--debug', action='store_true', default=False, dest='debug', help='debug option')
    parser.add_argument('-c', '--conf', type=str, default="/etc/toughtester.json", dest='conf', help='config file')
    args = parser.parse_args(sys.argv[1:])

    config = iconfig.find_config(args.conf)
    update_timezone(config)
    check_env(config)

    if args.debug:
        config.system.debug = True

    syslog = logger.Logger(config)
    dbengine = get_engine(config)
    dispatch.register(syslog)

    if args.admin:
        start_admin(config,dbengine=dbengine)
        start_authorized(config, dbengine)
        reactor.run()    


    elif args.initdb:
        start_initdb(config)

    else:
        parser.print_help()
コード例 #7
0
 def __init__(self, config, dbengine):
     self.config = config
     self.dict = dictionary.Dictionary(
         os.path.join(os.path.dirname(toughradius.__file__),
                      'dictionarys/dictionary'))
     self.db_engine = dbengine or get_engine(config)
     self.aes = utils.AESCipher(key=self.config.system.secret)
     self.mcache = mcache.Mcache()
コード例 #8
0
ファイル: httpd.py プロジェクト: WyattShao/ToughRADIUS
    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)
コード例 #9
0
ファイル: toughctl.py プロジェクト: Evan-hu/ToughRADIUS
def run():
    log.startLogging(sys.stdout)
    parser = argparse.ArgumentParser()
    parser.add_argument('-manage', '--manage', action='store_true', default=False, dest='manage', help='run manage')
    parser.add_argument('-task', '--task', action='store_true', default=False, dest='task', help='run task')
    parser.add_argument('-auth', '--auth', action='store_true', default=False, dest='auth', help='run auth')
    parser.add_argument('-acct', '--acct', action='store_true', default=False, dest='acct', help='run acct')
    parser.add_argument('-worker', '--worker', action='store_true', default=False, dest='worker', help='run worker')
    parser.add_argument('-standalone', '--standalone', action='store_true', default=False, dest='standalone', help='run standalone')
    parser.add_argument('-initdb', '--initdb', action='store_true', default=False, dest='initdb', help='run initdb')
    parser.add_argument('-debug', '--debug', action='store_true', default=False, dest='debug', help='debug option')
    parser.add_argument('-c', '--conf', type=str, default="/etc/toughradius.json", dest='conf', help='config file')
    args = parser.parse_args(sys.argv[1:])

    config = iconfig.find_config(args.conf)
    syslog = logger.Logger(config)
    dbengine = get_engine(config)
    dispatch.register(syslog)

    update_timezone(config)
    check_env(config)

    if args.debug:
        config.defaults.debug = True

    if args.manage:
        httpd.run(config,dbengine)
        reactor.run()    

    elif args.auth:
        radiusd.run_auth(config)
        reactor.run()
    
    elif args.acct:
        radiusd.run_acct(config)
        reactor.run()

    elif args.worker:
        radiusd.run_worker(config,dbengine)
        reactor.run()   

    elif args.task:
        taskd.run(config,dbengine)
        reactor.run()

    elif args.standalone:
        httpd.run(config,dbengine)
        radiusd.run_auth(config)
        radiusd.run_acct(config)
        radiusd.run_worker(config,dbengine)
        taskd.run(config,dbengine)
        reactor.run()
        
    elif args.initdb:
        run_initdb(config)
    else:
        parser.print_help()
コード例 #10
0
ファイル: inittest.py プロジェクト: WyattShao/ToughRADIUS
def update(config,force=False):
    try:
        db_engine = get_engine(config)
        print 'init test datat'
        db = scoped_session(sessionmaker(bind=db_engine, autocommit=False, autoflush=True))()
        inittest(db)
    except:
        import traceback
        traceback.print_exc()
コード例 #11
0
ファイル: admin_app.py プロジェクト: talkincode/ToughNMS
    def __init__(self, config=None, dbengine=None, **kwargs):

        self.config = config

        settings = dict(
            cookie_secret="12oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo=",
            login_url="/login",
            template_path=os.path.join(os.path.dirname(toughnms.__file__), "views"),
            static_path=os.path.join(os.path.dirname(toughnms.__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/toughnms"
        )

        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)
        self.mcache = cache.CacheManager(self.db_engine)
        self.nagapi = NagiosApi(self.config)
        self.mongodb = MongoDB(self.config.database.mongodb_url,self.config.database.mongodb_port)

        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="toughnms.console", excludes=['base','webserver','radius'])

        self.init_route_permit()

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


        # for g in self.nagapi.list_hostgroup():
        #     for host in g.get_effective_hosts():
        #         permit.add_route(host_perf.HostPerfDataHandler, 
        #             r"/gperfdata?group_name=%s&host_name=%s"%(g.hostgroup_name,host.host_name),
        #             utils.safeunicode(host.alias),
        #             MenuRes,
        #             is_menu=True,
        #             order=7.0005)
        cyclone.web.Application.__init__(self, permit.all_handlers, **settings)
コード例 #12
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)
コード例 #13
0
ファイル: inittest.py プロジェクト: toughmen/ToughRADIUS
def update(config, force=False):
    try:
        db_engine = get_engine(config)
        print 'init test datat'
        db = scoped_session(
            sessionmaker(bind=db_engine, autocommit=False, autoflush=True))()
        inittest(db)
    except:
        import traceback
        traceback.print_exc()
コード例 #14
0
    def __init__(self, config=None, log=None, **kwargs):

        self.config = config
        self.syslog = log or logger.Logger(config)

        settings = dict(
            cookie_secret="12oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo=",
            login_url="/admin/login",
            template_path=os.path.join(os.path.dirname(__file__), "views"),
            static_path=os.path.join(os.path.dirname(toughradius.__file__),
                                     "static"),
            xsrf_cookies=True,
            config=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='replace',
            module_directory="/tmp/admin")

        self.db_engine = 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)
        self.mcache = cache.CacheManager(self.db_engine)
        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)

        permit.add_route(
            cyclone.web.StaticFileHandler,
            r"/backup/download/(.*)",
            u"下载数据",
            MenuSys,
            handle_params={"path": self.config.database.backup_path},
            order=1.0405)

        self.init_route()

        self.zauth_agent = authorize.ZAuthAgent(self)
        self.zacct_agent = acctounting.ZAcctAgent(self)

        cyclone.web.Application.__init__(self, permit.all_handlers, **settings)
コード例 #15
0
    def __init__(self, config=None, dbengine=None, **kwargs):

        self.config = config
        self.db_engine = dbengine or get_engine(config)
        self.db = scoped_session(
            sessionmaker(bind=self.db_engine,
                         autocommit=False,
                         autoflush=False))
        self.expire_notify_task = expire_notify.ExpireNotifyTask(
            config, self.db)
        self.ddns_update_task = ddns_update.DdnsUpdateTask(config, self.db)
コード例 #16
0
ファイル: taskd.py プロジェクト: kozora/ToughRADIUS
    def __init__(self, config=None, dbengine=None, **kwargs):

        self.config = config
        self.db_engine = dbengine or get_engine(config)
        self.cache = cache.CacheManager(self.db_engine)
        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)

        dispatch.register(radius_events.__call__(self.db_engine,self.cache))
コード例 #17
0
ファイル: radiusd.py プロジェクト: niebaopeng/ToughRADIUS
 def __init__(self, config, dbengine):
     self.config = config
     self.dict = dictionary.Dictionary(
         os.path.join(os.path.dirname(toughradius.__file__), 'dictionarys/dictionary'))
     self.db_engine = dbengine or get_engine(config)
     self.aes = utils.AESCipher(key=self.config.system.secret)
     self.mcache = mcache.Mcache()
     self.pusher = ZmqPushConnection(ZmqFactory(), ZmqEndpoint('connect', 'ipc:///tmp/radiusd-auth-result'))
     self.puller = ZmqPullConnection(ZmqFactory(), ZmqEndpoint('connect', 'ipc:///tmp/radiusd-auth-message'))
     self.puller.onPull = self.process
     logger.info("init auth worker pusher : %s " % (self.pusher))
     logger.info("init auth worker puller : %s " % (self.puller))
コード例 #18
0
ファイル: taskd.py プロジェクト: myapple/ToughRADIUS
 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)
コード例 #19
0
ファイル: initdb.py プロジェクト: lxyjyy/ToughRADIUS
def update(config):
    try:
        db_engine = get_engine(config)
        if int(os.environ.get("DB_INIT", 1)) == 1:
            print 'starting update database...'
            metadata = models.get_metadata(db_engine)
            metadata.drop_all(db_engine)
            metadata.create_all(db_engine)
            print 'update database done'
            db = scoped_session(sessionmaker(bind=db_engine, autocommit=False, autoflush=True))()
            init_db(db)
    except:
        import traceback
        traceback.print_exc()
コード例 #20
0
def update(config):
    try:
        db_engine = get_engine(config)
        if int(os.environ.get("DB_INIT", 1)) == 1:
            print 'starting update database...'
            metadata = models.get_metadata(db_engine)
            metadata.drop_all(db_engine)
            metadata.create_all(db_engine)
            print 'update database done'
            db = scoped_session(sessionmaker(bind=db_engine, autocommit=False, autoflush=True))()
            init_db(db)
    except:
        import traceback
        traceback.print_exc()
コード例 #21
0
ファイル: taskd.py プロジェクト: popoimm/ToughRADIUS
    def __init__(self, config=None, dbengine=None, **kwargs):

        self.config = config
        self.db_engine = dbengine or get_engine(config,pool_size=20)
        self.cache = cache.CacheManager(self.db_engine,cache_name='RadiusTaskCache-%s'%os.getpid())
        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)

        dispatch.register(radius_events.__call__(self.db_engine,self.cache))
コード例 #22
0
ファイル: initdb.py プロジェクト: leigf/ToughRADIUS
def update(config):
    try:
        db_engine = get_engine(config)
        print 'starting update database...'
        metadata = models.get_metadata(db_engine)
        metadata.drop_all(db_engine)
        metadata.create_all(db_engine)
        print 'update database done'
        db = scoped_session(sessionmaker(bind=db_engine, autocommit=False, autoflush=True))()
        init_db(db)
    except:
        print 'initdb error, retry wait 5 second'
        time.sleep(5.0)
        update(config)
コード例 #23
0
ファイル: radiusd.py プロジェクト: zhangzhezh/ToughRADIUS
 def __init__(self, config, dbengine, radcache=None):
     self.config = config
     self.dict = dictionary.Dictionary(
         os.path.join(os.path.dirname(toughradius.__file__), 'dictionarys/dictionary'))
     self.db_engine = dbengine or get_engine(config)
     self.aes = utils.AESCipher(key=self.config.system.secret)
     self.mcache = radcache
     self.pusher = ZmqPushConnection(ZmqFactory(), ZmqEndpoint('connect', 'ipc:///tmp/radiusd-auth-result'))
     self.stat_pusher = ZmqPushConnection(ZmqFactory(), ZmqEndpoint('connect', 'ipc:///tmp/radiusd-stat-task'))
     self.puller = ZmqPullConnection(ZmqFactory(), ZmqEndpoint('connect', 'ipc:///tmp/radiusd-auth-message'))
     self.puller.onPull = self.process
     reactor.listenUDP(0, self)
     logger.info("init auth worker pusher : %s " % (self.pusher))
     logger.info("init auth worker puller : %s " % (self.puller))
     logger.info("init auth stat pusher : %s " % (self.stat_pusher))
コード例 #24
0
def update(config):
    try:
        db_engine = get_engine(config)
        print 'starting update database...'
        metadata = models.get_metadata(db_engine)
        metadata.drop_all(db_engine)
        metadata.create_all(db_engine)
        print 'update database done'
        db = scoped_session(
            sessionmaker(bind=db_engine, autocommit=False, autoflush=True))()
        init_db(db)
    except:
        print 'initdb error, retry wait 5 second'
        time.sleep(5.0)
        update(config)
コード例 #25
0
ファイル: backup.py プロジェクト: lanyeit/toughwlan
def restoredb(config,restorefs):
    if not os.path.exists(restorefs):
        print 'backup file not exists'
    else:
        engine = get_engine(config)
        db = engine.connect()
        metadata = models.get_metadata(engine)
        with gzip.open(restorefs,'rb') as rfs:
            cache_datas = {}
            for line in rfs:
                try:
                    tabname, rdata = json.loads(line)

                    if tabname == 'table_names' and rdata:
                        for table_name in rdata:
                            print "clean table %s" % table_name
                            db.execute("delete from %s;" % table_name)
                        continue

                    if tabname not in cache_datas:
                        cache_datas[tabname] = [rdata]
                    else:
                        cache_datas[tabname].append(rdata)

                    if tabname in cache_datas and len(cache_datas[tabname]) >= 500:
                        print 'insert datas<%s> into %s' % (len(cache_datas[tabname]), tabname)
                        db.execute(metadata.tables[tabname].insert().values(cache_datas[tabname]))
                        del cache_datas[tabname]

                except:
                    print 'error data %s ...'% line
                    import traceback
                    traceback.print_exc()

            print "insert last data"
            for tname, tdata in cache_datas.iteritems():
                try:
                    print 'insert datas<%s> into %s' % (len(tdata), tname)
                    db.execute(metadata.tables[tname].insert().values(tdata))
                except:
                    print 'error data %s ...' % tdata
                    import traceback
                    traceback.print_exc()

            cache_datas.clear()

        db.close()
コード例 #26
0
ファイル: webserver.py プロジェクト: davisldq/ToughRADIUS
    def __init__(self, config=None, dbengine=None, log=None, **kwargs):

        self.config = config
        self.syslog = log or logger.Logger(config)

        settings = dict(
            cookie_secret="12oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo=",
            login_url="/admin/login",
            template_path=os.path.join(os.path.dirname(__file__), "views"),
            static_path=os.path.join(os.path.dirname(toughradius.__file__), "static"),
            xsrf_cookies=True,
            config=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="replace",
            module_directory="/tmp/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)
        self.mcache = cache.CacheManager(self.db_engine)
        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)

        permit.add_route(
            cyclone.web.StaticFileHandler,
            r"/backup/download/(.*)",
            u"下载数据",
            MenuSys,
            handle_params={"path": self.config.database.backup_path},
            order=1.0405,
        )

        self.init_route()

        cyclone.web.Application.__init__(self, permit.all_handlers, **settings)
コード例 #27
0
    def __init__(self, config=None, dbengine=None, **kwargs):

        self.config = config
        self.db_engine = dbengine or get_engine(config)
        self.cache = cache.CacheManager(self.db_engine)
        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)

        dispatch.register(radius_events.__call__(self.db_engine, self.cache))
コード例 #28
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)
コード例 #29
0
ファイル: toughctl.py プロジェクト: lanyeit/toughwlan
def run():
    log.startLogging(sys.stdout)
    parser = argparse.ArgumentParser()
    parser.add_argument('-admin', '--admin', action='store_true', default=False, dest='admin', help='run admin')
    parser.add_argument('-portal', '--portal', action='store_true', default=False, dest='portal', help='run portal')
    parser.add_argument('-acagent', '--acagent', action='store_true', default=False, dest='acagent', help='run acagent')
    parser.add_argument('-standalone', '--standalone', action='store_true', default=False, dest='standalone', help='run standalone')
    parser.add_argument('-initdb', '--initdb', action='store_true', default=False, dest='initdb', help='run initdb')
    parser.add_argument('-debug', '--debug', action='store_true', default=False, dest='debug', help='debug option')
    parser.add_argument('-c', '--conf', type=str, default="/etc/toughwlan.json", dest='conf', help='config file')
    args = parser.parse_args(sys.argv[1:])

    config = iconfig.find_config(args.conf)
    update_timezone(config)
    check_env(config)

    if args.debug:
        config.system.debug = True

    syslog = logger.Logger(config)
    dbengine = get_engine(config)

    if args.admin:
        start_admin(config,dbengine=dbengine,log=syslog)
        reactor.run()    

    elif args.portal:
        start_portal(config,dbengine=dbengine,log=syslog)
        reactor.run()

    elif args.acagent:
        start_acagent(config,dbengine=dbengine,log=syslog)
        reactor.run()

    elif args.standalone:
        start_admin(config,dbengine=dbengine,log=syslog)
        start_portal(config,dbengine=dbengine,log=syslog)
        start_acagent(config,dbengine=dbengine,log=syslog)
        reactor.run()

    elif args.initdb:
        start_initdb(config)

    else:
        parser.print_help()
コード例 #30
0
ファイル: radiusd.py プロジェクト: niebaopeng/ToughRADIUS
 def __init__(self, config, dbengine):
     self.config = config
     self.dict = dictionary.Dictionary(
         os.path.join(os.path.dirname(toughradius.__file__), 'dictionarys/dictionary'))
     self.db_engine = dbengine or get_engine(config)
     self.mcache = mcache.Mcache()
     self.pusher = ZmqPushConnection(ZmqFactory(), ZmqEndpoint('connect', 'ipc:///tmp/radiusd-acct-result'))
     self.puller = ZmqPullConnection(ZmqFactory(), ZmqEndpoint('connect', 'ipc:///tmp/radiusd-acct-message'))
     self.puller.onPull = self.process
     logger.info("init acct worker pusher : %s " % (self.pusher))
     logger.info("init acct worker puller : %s " % (self.puller))
     self.acct_class = {
         STATUS_TYPE_START: RadiusAcctStart,
         STATUS_TYPE_STOP: RadiusAcctStop,
         STATUS_TYPE_UPDATE: RadiusAcctUpdate,
         STATUS_TYPE_ACCT_ON: RadiusAcctOnoff,
         STATUS_TYPE_ACCT_OFF: RadiusAcctOnoff
     }
コード例 #31
0
ファイル: taskd.py プロジェクト: toughmen/ToughRADIUS
 def __init__(self, config=None, dbengine=None, **kwargs):
     self.config = config
     self.db_engine = dbengine or get_engine(config, pool_size=20)
     redisconf = settings.redis_conf(config)
     self.cache = redis_cache.CacheManager(redisconf,
                                           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)
     dispatch.register(radius_events.__call__(self.db_engine, self.cache))
コード例 #32
0
ファイル: backup.py プロジェクト: lanyeit/toughwlan
def dumpdb(config,dumpfs):
    _dir = os.path.split(dumpfs)[0]
    if not os.path.exists(_dir):
        os.makedirs(_dir)

    engine = get_engine(config)
    db = engine.connect()
    metadata = models.get_metadata(engine)
    with gzip.open(dumpfs, 'wb') as dumpfs:

        table_names = [_name for _name, _ in metadata.tables.items()]
        table_headers = ('table_names', table_names)
        dumpfs.write(json.dumps(table_headers, ensure_ascii=False).encode('utf-8'))
        dumpfs.write('\n')

        for _name,_table in metadata.tables.items():
            if _name in excludes:
                continue
            rows = db.execute(select([_table]))
            for rows in rows:
                obj = (_name, dict(rows.items()))
                dumpfs.write(json.dumps(obj,ensure_ascii=False).encode('utf-8'))
                dumpfs.write('\n')
    db.close()
コード例 #33
0
ファイル: toughctl.py プロジェクト: davislidaqing/ToughRADIUS
def run_initdb(config):
    init_db.update(get_engine(config))
コード例 #34
0
ファイル: toughctl.py プロジェクト: popoimm/ToughRADIUS
def run():
    log.startLogging(sys.stdout)
    parser = argparse.ArgumentParser()
    parser.add_argument('-manage',
                        '--manage',
                        action='store_true',
                        default=False,
                        dest='manage',
                        help='run manage')
    parser.add_argument('-task',
                        '--task',
                        action='store_true',
                        default=False,
                        dest='task',
                        help='run task')
    parser.add_argument('-auth',
                        '--auth',
                        action='store_true',
                        default=False,
                        dest='auth',
                        help='run auth')
    parser.add_argument('-acct',
                        '--acct',
                        action='store_true',
                        default=False,
                        dest='acct',
                        help='run acct')
    parser.add_argument('-worker',
                        '--worker',
                        action='store_true',
                        default=False,
                        dest='worker',
                        help='run worker')
    parser.add_argument('-standalone',
                        '--standalone',
                        action='store_true',
                        default=False,
                        dest='standalone',
                        help='run standalone')
    parser.add_argument('-initdb',
                        '--initdb',
                        action='store_true',
                        default=False,
                        dest='initdb',
                        help='run initdb')
    parser.add_argument('-debug',
                        '--debug',
                        action='store_true',
                        default=False,
                        dest='debug',
                        help='debug option')
    parser.add_argument('-exitwith',
                        '--exitwith',
                        type=float,
                        default=0,
                        dest='exitwith',
                        help='exitwith option')
    parser.add_argument('-c',
                        '--conf',
                        type=str,
                        default="/etc/toughradius.json",
                        dest='conf',
                        help='config file')
    args = parser.parse_args(sys.argv[1:])

    config = iconfig.find_config(args.conf)
    syslog = logger.Logger(config)
    dbengine = get_engine(config)
    dispatch.register(syslog)

    update_timezone(config)
    check_env(config)

    if args.debug:
        config.defaults.debug = True

    if args.manage:
        httpd.run(config, dbengine)
        reactor.run()

    elif args.auth:
        radiusd.run_auth(config)
        reactor.run()

    elif args.acct:
        radiusd.run_acct(config)
        reactor.run()

    elif args.worker:
        radiusd.run_worker(config, dbengine)
        reactor.run()

    elif args.task:
        taskd.run(config, dbengine)
        reactor.run()

    elif args.standalone:
        httpd.run(config, dbengine)
        radiusd.run_auth(config)
        radiusd.run_acct(config)
        radiusd.run_worker(config, dbengine)
        taskd.run(config, dbengine)
        if args.exitwith > 0:
            log.msg("testing application running and exit after %s seconds" %
                    args.exitwith)
            reactor.callLater(args.exitwith, reactor.stop)
        reactor.run()

    elif args.initdb:
        run_initdb(config)
    else:
        parser.print_help()
コード例 #35
0
ファイル: radiusd.py プロジェクト: davisldq/ToughRADIUS
 def __init__(self, config, dbengine, log):
     self.config = config
     self.dict = dictionary.Dictionary(os.path.join(os.path.dirname(toughradius.__file__), "dictionarys/dictionary"))
     self.syslog = log
     self.db_engine = dbengine or get_engine(config)
     self.mcache = mcache.Mcache()
コード例 #36
0
ファイル: toughctl.py プロジェクト: davislidaqing/ToughRADIUS
def run_initdb(config):
    init_db.update(get_engine(config))
コード例 #37
0
def run():
    log.startLogging(sys.stdout)
    parser = argparse.ArgumentParser()
    parser.add_argument('-manage',
                        '--manage',
                        action='store_true',
                        default=False,
                        dest='manage',
                        help='run manage')
    parser.add_argument('-task',
                        '--task',
                        action='store_true',
                        default=False,
                        dest='task',
                        help='run task')
    parser.add_argument('-auth',
                        '--auth',
                        action='store_true',
                        default=False,
                        dest='auth',
                        help='run auth')
    parser.add_argument('-acct',
                        '--acct',
                        action='store_true',
                        default=False,
                        dest='acct',
                        help='run acct')
    parser.add_argument('-standalone',
                        '--standalone',
                        action='store_true',
                        default=False,
                        dest='standalone',
                        help='run standalone')
    parser.add_argument('-initdb',
                        '--initdb',
                        action='store_true',
                        default=False,
                        dest='initdb',
                        help='run initdb')
    parser.add_argument('-debug',
                        '--debug',
                        action='store_true',
                        default=False,
                        dest='debug',
                        help='debug option')
    parser.add_argument('-c',
                        '--conf',
                        type=str,
                        default="/etc/toughradius.json",
                        dest='conf',
                        help='config file')
    args = parser.parse_args(sys.argv[1:])

    config = iconfig.find_config(args.conf)
    syslog = logger.Logger(config)
    dbengine = get_engine(config)
    dispatch.register(syslog)

    update_timezone(config)
    check_env(config)

    if args.debug:
        config.defaults.debug = True

    if args.manage:
        webserver.run(config, dbengine)
        reactor.run()

    elif args.auth:
        radiusd.run_auth(config, dbengine)
        reactor.run()

    elif args.acct:
        radiusd.run_acct(config, dbengine)
        reactor.run()

    elif args.task:
        taskd.run(config, dbengine)
        reactor.run()

    elif args.standalone:
        radiusd.run_auth(config, dbengine)
        radiusd.run_acct(config, dbengine)
        webserver.run(config, dbengine)
        taskd.run(config, dbengine)
        reactor.run()

    elif args.initdb:
        run_initdb(config)
    else:
        parser.print_help()