def update(config): conf_file = config.get('DEFAULT', 'cfgfile') shutil.copy(conf_file, "%s.%s" % (conf_file, int(time.time()))) old_secret = config.get('DEFAULT', 'secret') config.set('DEFAULT', 'secret', gen_secret(32)) old_AESCipher = utils.AESCipher(old_secret) new_AESCipher = utils.AESCipher(config.get('DEFAULT', 'secret')) engine = get_engine(config) conn = engine.connect() # update db = scoped_session( sessionmaker(bind=engine, autocommit=False, autoflush=True))() user_query = db.query(models.SlcRadAccount) total1 = user_query.count() for user in user_query: oldpwd = old_AESCipher.decrypt(user.password) user.password = new_AESCipher.encrypt(oldpwd) vcard_query = db.query(models.SlcRechargerCard) total2 = vcard_query.count() for vcard in vcard_query: oldpwd = old_AESCipher.decrypt(vcard.card_passwd) vcard.card_passwd = new_AESCipher.encrypt(oldpwd) db.commit() with open(conf_file, 'wb') as configfile: config.write(configfile) print 'update secret success user %s,vcard %s' % (total1, total2)
def run_customer(config, daemon=False): if not daemon: from toughradius.console import customer_app customer_app.run(config, db_engine=get_engine(config)) else: _run_daemon(config, "customer")
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: for line in rfs: try: obj = json.loads(line) print "delete from %s"%obj['table'] db.execute("delete from %s"%obj['table']) print 'insert datas into %s'%obj['table'] objs = obj['data'] if len(objs) < 500: if objs:db.execute(metadata.tables[obj['table'] ].insert().values(objs)) else: while len(objs) > 0: _tmp_pbjs = objs[:500] objs = objs[500:] db.execute(metadata.tables[obj['table'] ].insert().values(_tmp_pbjs)) # db.execute("commit;") except: print 'error data %s ...'%line[:128] import traceback traceback.print_exc() db.close()
def update(config): conf_file = config.get("DEFAULT", "cfgfile") shutil.copy(conf_file, "%s.%s" % (conf_file, int(time.time()))) old_secret = config.get("DEFAULT", "secret") config.set("DEFAULT", "secret", gen_secret(32)) old_AESCipher = utils.AESCipher(old_secret) new_AESCipher = utils.AESCipher(config.get("DEFAULT", "secret")) engine = get_engine(config) conn = engine.connect() # update db = scoped_session(sessionmaker(bind=engine, autocommit=False, autoflush=True))() user_query = db.query(models.SlcRadAccount) total1 = user_query.count() for user in user_query: oldpwd = old_AESCipher.decrypt(user.password) user.password = new_AESCipher.encrypt(oldpwd) vcard_query = db.query(models.SlcRechargerCard) total2 = vcard_query.count() for vcard in vcard_query: oldpwd = old_AESCipher.decrypt(vcard.card_passwd) vcard.card_passwd = new_AESCipher.encrypt(oldpwd) db.commit() with open(conf_file, "wb") as configfile: config.write(configfile) print "update secret success user %s,vcard %s" % (total1, total2)
def run_radiusd(config, daemon=False): if not daemon: from toughradius.radiusd import server server.run(config, db_engine=get_engine(config)) else: _run_daemon(config, "radiusd")
def run_admin(config, daemon=False): if not daemon: from toughradius.console import admin_app admin_app.run(config, db_engine=get_engine(config)) else: _run_daemon(config, "admin")
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: for line in rfs: try: obj = json.loads(line) print "delete from %s" % obj['table'] db.execute("delete from %s" % obj['table']) print 'insert datas into %s' % obj['table'] objs = obj['data'] if len(objs) < 500: if objs: db.execute(metadata.tables[ obj['table']].insert().values(objs)) else: while len(objs) > 0: _tmp_pbjs = objs[:500] objs = objs[500:] db.execute(metadata.tables[ obj['table']].insert().values(_tmp_pbjs)) # db.execute("commit;") except: print 'error data %s ...' % line[:128] import traceback traceback.print_exc() db.close()
def __init__(self, config,daemon=False): self.config = config self.daemon = daemon self.init_config() self.db_engine = get_engine(config) self.actions = { portalv2.NTF_LOGOUT : self.doAckNtfLogout } reactor.callLater(5,self.init_task)
def __init__(self,config): self.config = config self.mkdb = scoped_session(sessionmaker( bind=get_engine(config), autocommit=False, autoflush=True )) self.load_users() self.radcli = RadClient(config) self.running = False self.threads = [] utils.aescipher.setup(config.get('DEFAULT','secret'))
def init_db_engine(self): if not self.db_engine: self.db_engine = get_engine(self.config) metadata = models.get_metadata(self.db_engine) self.sqla_pg = sqla_plugin.Plugin(self.db_engine, metadata, keyword='db', create=False, commit=False, use_kwargs=False)
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 __init__(self, config): self.config = config self.mkdb = scoped_session( sessionmaker(bind=get_engine(config), autocommit=False, autoflush=True)) self.load_users() self.radcli = RadClient(config) self.running = False self.threads = [] utils.aescipher.setup(config.get('DEFAULT', 'secret'))
def init_db_engine(self): if not self.db_engine: self.db_engine = get_engine(self.config) metadata = models.get_metadata(self.db_engine) self.sqla_pg = sqla_plugin.Plugin( self.db_engine, metadata, keyword='db', create=False, commit=False, use_kwargs=False )
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 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: for _name, _table in metadata.tables.items(): if _name in excludes: continue rows = db.execute(select([_table])).fetchall() obj = dict(table=_name, data=[dict(r.items()) for r in rows]) dumpfs.write(json.dumps(obj, ensure_ascii=False).encode('utf-8')) dumpfs.write('\n') db.close()
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: for _name,_table in metadata.tables.items(): if _name in excludes: continue rows = db.execute(select([_table])).fetchall() obj = dict(table=_name,data=[dict(r.items()) for r in rows]) dumpfs.write(json.dumps(obj,ensure_ascii=False).encode('utf-8')) dumpfs.write('\n') db.close()
def run_standalone(config, daemon=False): from twisted.internet import reactor from toughradius.console import admin_app from toughradius.console import customer_app from toughradius.radiusd import server logfile = config.get('radiusd', 'logfile') config.set('DEFAULT', 'standalone', 'true') config.set('admin', 'logfile', logfile) config.set('customer', 'logfile', logfile) if not daemon: db_engine = get_engine(config) server.run(config, db_engine, False) admin_app.run(config, db_engine, False) customer_app.run(config, db_engine, False) reactor.run() else: _run_daemon(config, 'standalone')
def run_standalone(config,daemon=False): from twisted.internet import reactor from toughradius.console import admin_app from toughradius.console import customer_app from toughradius.radiusd import server logfile = config.get('radiusd','logfile') config.set('DEFAULT','standalone','true') config.set('admin','logfile',logfile) config.set('customer','logfile',logfile) if not daemon: db_engine = get_engine(config) server.run(config,db_engine,False) admin_app.run(config,db_engine,False) customer_app.run(config,db_engine,False) reactor.run() else: _run_daemon(config,'standalone')
def run_standalone(config, daemon=False): """ 所有应用在一个进程的运行模式 """ from twisted.internet import reactor from toughradius.console import admin_app from toughradius.console import customer_app from toughradius.console import control_app from toughradius.radiusd import server logfile = config.get("radiusd", "logfile") config.set("DEFAULT", "standalone", "true") config.set("admin", "logfile", logfile) config.set("customer", "logfile", logfile) config.set("control", "logfile", logfile) if not daemon: db_engine = get_engine(config) server.run(config, db_engine, False) admin_app.run(config, db_engine, False) customer_app.run(config, db_engine, False) control_app.run(config, False) reactor.run() else: _run_daemon(config, "standalone")
def run_initdb(config): from toughradius.console import models models.update(get_engine(config))
def run_radiusd(config, daemon=False): if not daemon: from toughradius.radiusd import server server.run(config, db_engine=get_engine(config)) else: _run_daemon(config, 'radiusd')
def run_initdb(config): init_db.update(get_engine(config))
def run_admin(config, daemon=False): if not daemon: from toughradius.console import admin_app admin_app.run(config, db_engine=get_engine(config)) else: _run_daemon(config, 'admin')
def run_customer(config, daemon=False): if not daemon: from toughradius.console import customer_app customer_app.run(config, db_engine=get_engine(config)) else: _run_daemon(config, 'customer')
def init_db_engine(self): if not self.db_engine: self.db_engine = get_engine(self.config) self.store = Store(self.config, self.db_engine, syslog=self.syslog)
def init_db_engine(self): if not self.db_engine: self.db_engine = get_engine(self.config) self.store = Store(self.config,self.db_engine)