Exemplo n.º 1
0
def start_server(config,app):
    '''
    启动守护进程
    '''
    apps = app == 'all' and ['radiusd','admin','customer'] or [app]
    for _app in apps:
        shell.info('start %s'%_app)
        _run_daemon(config,_app)
Exemplo n.º 2
0
def stop_server(app):
    '''
    停止守护进程
    '''
    apps = (app == 'all' and ['radiusd','admin','customer'] or [app])
    for _app in apps:
        shell.info('stop %s'%_app)
        _kill_daemon(_app)
Exemplo n.º 3
0
def start_server(config, app):
    """
    启动守护进程
    """
    apps = app == "all" and ["radiusd", "admin", "customer", "control"] or [app]
    for _app in apps:
        shell.info("start %s" % _app)
        _run_daemon(config, _app)
Exemplo n.º 4
0
def stop_server(app):
    """
    停止守护进程
    """
    apps = app == "all" and ["radiusd", "admin", "customer", "control"] or [app]
    for _app in apps:
        shell.info("stop %s" % _app)
        _kill_daemon(_app)
Exemplo n.º 5
0
def stop_server(app):
    '''
    停止守护进程
    '''
    apps = (app == 'all' and ['radiusd', 'admin', 'customer', 'control']
            or [app])
    for _app in apps:
        shell.info('stop %s' % _app)
        _kill_daemon(_app)
Exemplo n.º 6
0
def restart_server(config,app):
    apps = (app == 'all' and ['radiusd','admin','customer'] or [app])
    for _app in apps:
        shell.info('stop %s'%_app)
        _kill_daemon(_app)
        time.sleep(0.1)
        shell.info('start %s'%_app)
        _run_daemon(config,_app)
        time.sleep(0.1)
Exemplo n.º 7
0
def restart_server(config, app):
    apps = (app == 'all' and ['radiusd', 'admin', 'customer'] or [app])
    for _app in apps:
        shell.info('stop %s' % _app)
        _kill_daemon(_app)
        time.sleep(0.1)
        shell.info('start %s' % _app)
        _run_daemon(config, _app)
        time.sleep(0.1)
Exemplo n.º 8
0
def start_server(config, app):
    '''
    启动守护进程
    '''
    apps = app == 'all' and ['radiusd', 'admin', 'customer', 'control'] or [
        app
    ]
    for _app in apps:
        shell.info('start %s' % _app)
        _run_daemon(config, _app)
Exemplo n.º 9
0
def execute_sqls(config, sqlstr):
    sh.info("exec sql >> %s" % sqlstr)
    results = []
    with get_engine(config).begin() as conn:
        try:
            results = conn.execute(_sql(sqlstr))
        except Exception as err:
            return sh.err("exec sql error: %s" % str(err))
    sh.info("exec sql done")
    print_result(results)
Exemplo n.º 10
0
def execute_sqls(config,sqlstr):
    sh.info('exec sql >> %s'%sqlstr)
    results = []
    with get_engine(config).begin() as conn:
        try:
            results = conn.execute(_sql(sqlstr))
        except Exception as err:
            return sh.err('exec sql error: %s'%str(err))
    sh.info('exec sql done')
    print_result(results)
Exemplo n.º 11
0
def restart_server(config, app):
    '''
    重启守护进程
    '''
    apps = (app == 'all' and ['radiusd', 'admin', 'customer', 'control']
            or [app])
    for _app in apps:
        shell.info('stop %s' % _app)
        _kill_daemon(_app)
        shell.info('start %s' % _app)
        _run_daemon(config, _app)
Exemplo n.º 12
0
def print_result(rs):
    n = 0
    rstr = []
    for r in rs:
        if n == 100:
            return
        try:
            _r = ', '.join([ '%s=%s'%(k,_decode(r[k])) for k in r.keys()])
            rstr.append(_r)
        except Exception as err:
            sh.warn('print result error: %s'%str(err))
    sh.info('Result:\n\n%s\n'%('\n'.join(rstr)))        
Exemplo n.º 13
0
def print_result(rs):
    n = 0
    rstr = []
    for r in rs:
        if n == 100:
            return
        try:
            _r = ", ".join(["%s=%s" % (k, _decode(r[k])) for k in r.keys()])
            rstr.append(_r)
        except Exception as err:
            sh.warn("print result error: %s" % str(err))
    sh.info("Result:\n\n%s\n" % ("\n".join(rstr)))
Exemplo n.º 14
0
def find_config(conf_file=None):
    cfgs = [conf_file, '/etc/radiusd.conf']
    config = ConfigParser.ConfigParser()
    flag = False
    for c in cfgs:
        if c and os.path.exists(c):
            config.read(c)
            config.set('DEFAULT', 'cfgfile', c)
            sh.info("use config:%s" % c)
            flag = True
            break

    if not flag:
        return None
    else:
        return config
Exemplo n.º 15
0
def find_config(conf_file=None):
    windows_dir = os.getenv("WINDIR") and os.path.join(os.getenv("WINDIR"), "radiusd.conf") or None
    cfgs = [conf_file, "/etc/radiusd.conf", "./radiusd.conf", "~/radiusd.conf", windows_dir]
    config = ConfigParser.ConfigParser()
    flag = False
    for c in cfgs:
        if c and os.path.exists(c):
            config.read(c)
            config.set("DEFAULT", "cfgfile", c)
            sh.info("use config:%s" % c)
            flag = True
            break

    if not flag:
        return None
    else:
        return config
Exemplo n.º 16
0
def find_config(conf_file=None):
    cfgs = [
        conf_file,
        '/etc/radiusd.conf'
    ]
    config = ConfigParser.ConfigParser()
    flag = False
    for c in cfgs:
        if c and os.path.exists(c):
            config.read(c)
            config.set('DEFAULT', 'cfgfile', c)
            sh.info("use config:%s"%c)  
            flag = True
            break
   
    if not flag:
        return None
    else:    
        return config
Exemplo n.º 17
0
def find_config(conf_file=None):
    windows_dir = os.getenv("WINDIR") and os.path.join(os.getenv("WINDIR"),
                                                       'radiusd.conf') or None
    cfgs = [
        conf_file, '/etc/radiusd.conf', './radiusd.conf', '~/radiusd.conf',
        windows_dir
    ]
    config = ConfigParser.ConfigParser()
    flag = False
    for c in cfgs:
        if c and os.path.exists(c):
            config.read(c)
            config.set('DEFAULT', 'cfgfile', c)
            sh.info("use config:%s" % c)
            flag = True
            break

    if not flag:
        return None
    else:
        return config
Exemplo n.º 18
0
def find_config(conf_file=None):
    windows_dir = os.getenv("WINDIR") and os.path.join(os.getenv("WINDIR"),'radiusd.conf') or None
    cfgs = [
        conf_file,
        '/etc/radiusd.conf',
        './radiusd.conf',
        '~/radiusd.conf',
        windows_dir
    ]
    config = ConfigParser.ConfigParser()
    flag = False
    for c in cfgs:
        if c and os.path.exists(c):
            config.read(c)
            sh.info("use config:%s"%c)  
            flag = True
            break
   
    if not flag:
        return None
    else:    
        return config
Exemplo n.º 19
0
def execute_sqlf(config, sqlfile):
    sh.info("exec sql file >> %s" % sqlfile)
    if not os.path.exists(sqlfile):
        return sh.warn("sqlfile not exists")
    conn = get_engine(config).raw_connection()
    try:
        for line in open(sqlfile):
            sh.info(line)
            conn.execute(line)
    except Exception as err:
        return sh.err("exec sql file error: %s" % str(err))
    finally:
        conn.close()
    sh.info("exec sql file done")
Exemplo n.º 20
0
def execute_sqlf(config, sqlfile):
    sh.info('exec sql file >> %s' % sqlfile)
    if not os.path.exists(sqlfile):
        return sh.warn('sqlfile not exists')
    conn = get_engine(config).raw_connection()
    try:
        for line in open(sqlfile):
            sh.info(line)
            conn.execute(line)
    except Exception as err:
        return sh.err('exec sql file error: %s' % str(err))
    finally:
        conn.close()
    sh.info('exec sql file done')
Exemplo n.º 21
0
def setup_config():
    sh.info("set config...")
    config_path = sh.read('set your config file path,[ /etc/radiusd.conf ]'
                          ) or '/etc/radiusd.conf'
    config = ConfigParser.RawConfigParser()
    sh.info("set default option")
    config.set('DEFAULT', 'debug', (sh.read("set debug [0/1] [0]:") or '0'))
    config.set('DEFAULT', 'tz', (sh.read("time zone [ CST-8 ]:") or 'CST-8'))
    config.set('DEFAULT', 'secret', gen_secret(32))

    sh.info("set database option")
    config.add_section('database')
    config.set('database', 'dbtype',
               (sh.read("database type [sqlite]:") or 'sqlite'))
    config.set('database', 'dburl',
               (sh.read("database url [sqlite:////tmp/toughradius.sqlite3]:")
                or 'sqlite:////tmp/toughradius.sqlite3'))
    config.set('database', 'echo',
               (sh.read("database echo sql [false]:") or 'false'))
    config.set('database', 'pool_size',
               (sh.read("database pool_size [30]:") or '30'))
    config.set('database', 'pool_recycle',
               (sh.read("database pool_recycle(second) [300]:") or '300'))

    sh.info("set radiusd option")
    config.add_section('radiusd')
    config.set('radiusd', 'authport',
               (sh.read("radiusd authport [1812]:") or '1812'))
    config.set('radiusd', 'acctport',
               (sh.read("radiusd acctport [1813]:") or '1813'))
    config.set('radiusd', 'adminport',
               (sh.read("radiusd adminport [1815]:") or '1815'))
    config.set('radiusd', 'cache_timeout',
               (sh.read("radiusd cache_timeout (second) [600]:") or '600'))
    config.set('radiusd', 'logfile',
               (sh.read("log file [ /var/log/radiusd.log ]:")
                or '/var/log/radiusd.log'))

    sh.info("set admin option")
    config.add_section('admin')
    config.set('admin', 'port', (sh.read("admin http port [1816]:") or '1816'))
    config.set(
        'admin', 'logfile',
        (sh.read("log file [ /var/log/admin.log ]:") or '/var/log/admin.log'))

    sh.info("set customer option")
    config.add_section('customer')
    config.set('customer', 'port',
               (sh.read("customer http port [1817]:") or '1817'))
    config.set('customer', 'logfile',
               (sh.read("log file [ /var/log/customer.log ]:")
                or '/var/log/customer.log'))

    with open(config_path, 'wb') as configfile:
        config.write(configfile)
        sh.succ("config save to %s" % config_path)
Exemplo n.º 22
0
def stop_server(app):
    apps = (app == 'all' and ['radiusd','admin','customer'] or [app])
    for _app in apps:
        shell.info('stop %s'%_app)
        _kill_daemon(_app)
        time.sleep(0.1)
Exemplo n.º 23
0
def setup_config():
    sh.info("set config...")
    config_path = sh.read('set your config file path,[ /etc/radiusd.conf ]') or '/etc/radiusd.conf'
    config = ConfigParser.RawConfigParser()
    sh.info("set default option")
    config.set('DEFAULT', 'debug', (sh.read("set debug [0/1] [0]:") or '0') )
    config.set('DEFAULT', 'tz', (sh.read("time zone [ CST-8 ]:") or 'CST-8') )
    config.set('DEFAULT','secret',gen_secret(32))
    
    sh.info("set database option")
    config.add_section('database')
    config.set('database','dbtype', (sh.read("database type [sqlite]:") or 'sqlite' ))
    config.set('database','dburl',( sh.read("database url [sqlite:////tmp/toughradius.sqlite3]:") or 'sqlite:////tmp/toughradius.sqlite3' ))
    config.set('database','echo',(sh.read("database echo sql [false]:") or 'false' ))
    config.set('database','pool_size',(sh.read("database pool_size [30]:") or '30' ))
    config.set('database','pool_recycle',(sh.read("database pool_recycle(second) [300]:") or '300' ))
    
    sh.info("set radiusd option")
    config.add_section('radiusd')
    config.set('radiusd','authport',(sh.read("radiusd authport [1812]:") or '1812'))
    config.set('radiusd','acctport',(sh.read("radiusd acctport [1813]:") or '1813'))
    config.set('radiusd','adminport',(sh.read("radiusd adminport [1815]:") or '1815'))
    config.set('radiusd','cache_timeout',(sh.read("radiusd cache_timeout (second) [600]:") or '600'))
    config.set('radiusd', 'logfile', (sh.read("log file [ /var/log/radiusd.log ]:") or '/var/log/radiusd.log') )
    
    sh.info("set admin option")
    config.add_section('admin')
    config.set('admin','port',(sh.read("admin http port [1816]:") or '1816'))
    config.set('admin', 'logfile', (sh.read("log file [ /var/log/admin.log ]:") or '/var/log/admin.log') )
    
    sh.info("set customer option")
    config.add_section('customer')
    config.set('customer','port',(sh.read("customer http port [1817]:") or '1817'))
    config.set('customer', 'logfile', (sh.read("log file [ /var/log/customer.log ]:") or '/var/log/customer.log') )
    
    with open(config_path,'wb') as configfile:
        config.write(configfile)
        sh.succ("config save to %s"%config_path)
Exemplo n.º 24
0
def stop_server(app):
    apps = (app == 'all' and ['radiusd', 'admin', 'customer'] or [app])
    for _app in apps:
        shell.info('stop %s' % _app)
        _kill_daemon(_app)
        time.sleep(0.1)