def connect(self, name = None, user = None, passwd = None, flows_path = None, graphs_path = None, crontime = None): try: dbinfo = Config() try: conn = MySQLdb.connect(user=dbinfo.getUser(), passwd=dbinfo.getPassword(), db=dbinfo.getDBName(), host="localhost") self.cursor = conn.cursor() return True except MySQLdb.Error, e: pass sys.exit(0) print "Error %d: %s" % (e.args[0],e.args[1]) return False except: dbinfo = Config(None, name, user, passwd, flows_path, graphs_path, crontime) try: conn = MySQLdb.connect(user=dbinfo.getUser(), passwd=dbinfo.getPassword(), db=dbinfo.getDBName(), host="localhost") self.cursor = conn.cursor() return True except MySQLdb.Error, e: pass print "Error %d: %s" % (e.args[0],e.args[1]) return False
def checkifexists(unixtime): config=Config() DB_NAME=config.getDBName() DB_HOST='localhost' DB_USER=config.getUser() DB_PASS=config.getPassword() db = MySQLdb.connect(user=DB_USER, passwd=DB_PASS, db=DB_NAME, host=DB_HOST) c = db.cursor() c.execute('Select * from rrd_n where time_unix=%s'%(unixtime)) result=c.fetchone() if result: return 1; return 0;
def __init__(self, name = None, user = None, passwd = None, flows_path = None, graphs_path = None, crontime = None): if name == None: try: dbinfo = Config() except: pass try: conn = MySQLdb.connect(user=dbinfo.getUser(), passwd=dbinfo.getPassword(), db=dbinfo.getDBName(), host="localhost") self.cursor = conn.cursor() except MySQLdb.Error, e: pass
#!/usr/bin/python import time import MySQLdb from Config import Config import os config=Config() DB_NAME=config.getDBName(); DB_HOST='localhost' DB_USER=config.getUser(); DB_PASS=config.getPassword(); INCREMENT=config.getCronTime() LOGSPATH=config.getLogsPath() db = MySQLdb.connect(user=DB_USER, passwd=DB_PASS, db=DB_NAME, host=DB_HOST) c = db.cursor() #check if logs path exists, if not create it if not os.path.exists(LOGSPATH): os.makedirs(LOGSPATH) logs=open(LOGSPATH+'/cleanup_log','a+') #maxtime=31536000 year=31536000 #year in seconds maxtime=int(config.getOldesttime())*year
data = sock.recv(2048) print('Received "%s"' % data.decode("utf-8")) if data.decode("utf-8").startswith("accepted"): print("Request accepted") if data.decode("utf-8").startswith("rejected"): print("Request rejected") break finally: sock.close() if __name__ == "__main__": # setting vars if args.set_server_address: a = args.set_server_address.split(":") printResult("server host", Config.setHost(a[0])) if len(a) > 1: printResult("server port", Config.setPort(a[1])) elif args.set_user_name: printResult("user-name", Config.setHost(args.set_user_name)) elif args.set_user_pass: # encryption to be added printResult("user-pass", Config.setPass(args.set_user_pass)) # message types elif args.set_ping_ttl: sendMessage("setTTL %s" % args.set_ping_ttl) elif args.add_to_deathclock: sendMessage("extend %s" % args.add_to_deathclock) else: sendMessage("ping %s %s" % (Config.getUser(), Config.getPass()))
except MySQLdb.Error, e: pass print "Error %d: %s" % (e.args[0],e.args[1]) return False else: try: dbinfo = Config() try: conn = MySQLdb.connect(user=dbinfo.getUser(), passwd=dbinfo.getPassword(), db=dbinfo.getDBName(), host="localhost") self.cursor = conn.cursor() return True except MySQLdb.Error, e: sys.exit(0) print "Error %d: %s" % (e.args[0],e.args[1]) return False except: