Beispiel #1
0
def run(conf):
    try:
        os.environ['CONFDIR'] = os.path.dirname(conf)
        from toughradius.common import config as iconfig
        from toughradius.radiusd.master import RudiusAuthServer
        config = iconfig.find_config(conf)
        logging.config.dictConfig(config.logger)
        address = (config.radiusd.host, int(config.radiusd.auth_port))
        auth_server = RudiusAuthServer(address, config)

        os.environ['CONFDIR'] = os.path.dirname(conf)
        from toughradius.common import config as iconfig
        config = iconfig.find_config(conf)
        logging.config.dictConfig(config.logger)
        from toughradius.radiusd.master import RudiusAcctServer
        address = (config.radiusd.host, int(config.radiusd.acct_port))
        acct_server = RudiusAcctServer(address, config)

        # gevent.signal(signal.SIGTERM, auth_server.close)
        # gevent.signal(signal.SIGINT, auth_server.close)
        # gevent.signal(signal.SIGTERM, acct_server.close)
        # gevent.signal(signal.SIGINT, acct_server.close)
        auth_server.start()
        acct_server.start()
        logging.info(auth_server)
        logging.info(acct_server)

        from toughradius.radiusd import apiserver
        apiserver.start(host=config.api['host'],
                        port=int(config.api['port']),
                        forever=False)
    except:
        import traceback
        traceback.print_exc()
Beispiel #2
0
def chkcfg(conf):
    try:
        os.environ['CONFDIR'] = os.path.dirname(conf)
        from toughradius.common import config as iconfig
        from pprint import pprint as pp
        config = iconfig.find_config(conf)
        print '%s %s %s' % ('-' * 50, conf, '-' * 50)
        print json.dumps(config, ensure_ascii=True, indent=4, sort_keys=False)
        print '%s logger %s' % ('-' * 50, '-' * 50)
        print json.dumps(config.logger, ensure_ascii=True, indent=4, sort_keys=False)
        print '%s clients %s' % ('-' * 50, '-' * 50)
        print json.dumps(config.clients, ensure_ascii=True, indent=4, sort_keys=False)
        print '-' * 110
    except:
        import traceback
        traceback.print_exc()
Beispiel #3
0
def apiserv(conf, debug, port):
    try:
        os.environ['CONFDIR'] = os.path.dirname(conf)
        from toughradius.common import config as iconfig
        config = iconfig.find_config(conf)
        logging.config.dictConfig(config.logger)
        from toughradius.radiusd import apiserver

        if debug:
            config.api['debug'] = True
        if port > 0:
            config.api['port'] = port

        apiserver.start(host=config.api['host'], port=int(config.api['port']))
    except:
        import traceback
        traceback.print_exc()
Beispiel #4
0
def radiusd(conf, debug, auth_port,acct_port,api_port, pool_size):
    try:
        os.environ['CONFDIR'] = os.path.dirname(conf)
        from toughradius.common import config as iconfig
        from toughradius.radiusd.master import RudiusAuthServer
        from toughradius.radiusd.master import RudiusAcctServer
        from toughradius.radiusd import apiserver
        config = iconfig.find_config(conf)

        logging.config.dictConfig(config.logger)

        if debug:
            config.radiusd['debug'] = True

        if auth_port > 0:
            config.radiusd['auth_port'] = auth_port

        if acct_port > 0:
            config.radiusd['acct_port'] = acct_port

        if api_port > 0:
            config.api['port'] = api_port

        if pool_size > 0:
            config.radiusd['pool_size'] = pool_size

        auth_address = (config.radiusd.host, int(config.radiusd.auth_port))
        acct_address = (config.radiusd.host, int(config.radiusd.acct_port))
        auth_server = RudiusAuthServer(auth_address, config)
        acct_server = RudiusAcctServer(acct_address, config)
        # gevent.signal(signal.SIGTERM, auth_server.close)
        # gevent.signal(signal.SIGINT, auth_server.close)
        # gevent.signal(signal.SIGTERM, acct_server.close)
        # gevent.signal(signal.SIGINT, acct_server.close)
        auth_server.start()
        gevent.sleep(0.1)
        acct_server.start()
        gevent.sleep(0.1)
        logging.info(auth_server)
        logging.info(acct_server)
        apiserver.start(host=config.api['host'], port=int(config.api['port']), forever=False)
        gevent.wait()
    except:
        import traceback
        traceback.print_exc()
Beispiel #5
0
def acct(conf, debug, acct_port, pool_size):
    try:
        os.environ['CONFDIR'] = os.path.dirname(conf)
        from toughradius.common import config as iconfig
        config = iconfig.find_config(conf)
        logging.config.dictConfig(config.logger)
        from toughradius.radiusd.master import RudiusAcctServer

        if debug:
            config.radiusd['debug'] = True
        if acct_port > 0:
            config.radiusd['acct_port'] = acct_port
        if pool_size > 0:
            config.radiusd['pool_size'] = pool_size

        address = (config.radiusd.host, int(config.radiusd.acct_port))
        server = RudiusAcctServer(address, config)
        logging.info(server)
        server.serve_forever()
    except:
        import traceback
        traceback.print_exc()
Beispiel #6
0
def run():
    parser = argparse.ArgumentParser()
    parser.add_argument('-admin', '--admin', action='store_true', default=False, dest='admin', help='run admin')
    parser.add_argument('-customer', '--customer', action='store_true', default=False, dest='customer', help='run customer')
    parser.add_argument('-port', '--port', type=int, default=0, dest='port', help='server port')
    parser.add_argument('-initdb', '--initdb', action='store_true', default=False, dest='initdb', help='run initdb')
    parser.add_argument('-dumpdb', '--dumpdb', type=str, default=None, dest='dumpdb', help='run dumpdb')
    parser.add_argument('-restoredb', '--restoredb', type=str, default=None, dest='restoredb', help='run restoredb')
    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.conf", dest='conf', help='config file')
    args = parser.parse_args(sys.argv[1:])

    config = iconfig.find_config(args.conf)
    
    if args.debug:
        config.defaults.debug = True

    if args.dumpdb:
        return run_dumpdb(config, args.dumpdb)

    if args.restoredb:
        return run_restoredb(config, args.restoredb)

    if args.admin:
        if args.port > 0:
            config.admin.port = args.port
        run_admin(config)    

    if args.customer:
        if args.port > 0:
            config.customer.port = args.port        
        run_customer(config)
        
    elif args.initdb:
        run_initdb(config)
    else:
        print 'do nothing'