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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)))
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)))
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
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
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
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
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
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")
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')
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)
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)
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)
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)