def cookieUpdateToDB(nickname, pwd, cookie): setval = "password='******',lastdate='%d',cookie='%s',update_fail=0" % ( pwd, int(time.time()), cookie) condition = "nickname='%s'" % (nickname) logger.debug('setval:%s, condition:%s', setval, condition) rv = libdb.LibDB().update_db(setval, condition, CONF['database']['table']) return rv
def admin(): global g_records, g_stat, g_cnt tarry = [] darry = [] #获取表项数量 count = libdb.LibDB().query_count(CONF['database']['table']) if count != False: Digit = count[0] else: Digit = '0' g_stat['total'] = Digit st = datetime.datetime.now() + datetime.timedelta(minutes=-120) for i in range(0, 121): sn = st + datetime.timedelta(minutes=i) ts = sn.strftime("%H:%M") tarry.append(ts) if g_cnt.has_key(ts): darry.append(g_cnt[ts]) else: darry.append(0) return render_template("console.html", g_records=g_records, g_stat=g_stat, tarry=tarry, darry=darry)
def cookieWriteToDB(nickname, pwd, cookie): key = "nickname, password, regdate, lastdate, colddate, cookie" value = "'%s', '%s', '%d', '%d', '%d', '%s'" % (nickname, pwd, \ int(time.time()), int(time.time()), \ int(time.time()), cookie) logger.debug('key:%s, value:%s', key, value) rv = libdb.LibDB().insert_db(key, value, CONF['database']['table']) return rv
def updateFailWriteToDB(nickname, update_fail): if update_fail == 'update_fail': setval = "update_fail=update_fail+1" else: return False condition = "nickname='%s'" % (nickname) logger.debug('setval:%s, condition:%s', setval, condition) rv = libdb.LibDB().update_db(setval, condition, CONF['database']['table']) return rv
def TakeOutCksFromDB(cks_num): #先取出DB中表项数目 condition = 'lastdate>%d' % (int(time.time() - 3600 * 24 * 6)) count = libdb.LibDB().query_count_by_condition(condition, CONF['database']['table']) if count != False: total = count[0] else: total = 0 logger.debug(type(cks_num)) cks_num = int(cks_num) if total >= cks_num: take_num = cks_num else: take_num = total logger.debug('准备从数据库取出cookies数量:%d', take_num) records = libdb.LibDB().query_num_by_condition(take_num, condition, CONF['database']['table']) return records
def http_do_action(action): """ :param action: :return: ou :字典,包含信息 ou['data']['xxx'] : ou['msg'] :信息 ou['error'] : 0 ok : 1 写数据库失败 : 2 命令字暂不支持 : 3 参数错误 : 4 读数据库失败 """ ou = dict(error=0, data=dict(), msg='ok') if action == 'queryOneByDate': #测试命令:curl -d "action=queryOneByDate&day=2019-1-7" -X POST http://localhost:8889/strapi/http.do day = request.form.get('day') if day == None: ou['error'] = 3 ou['msg'] = '参数错误' return ou timestampBegin = str_to_timestamp(day + ' 0:0:0') timestampEnd = str_to_timestamp(day + ' 23:59:59') conditon = 'lastdate >= %d and lastdate <= %d and update_fail <= 5' % ( timestampBegin, timestampEnd) sql = libdb.LibDB().query_one_by_condition(conditon, CONF['database']['table']) if sql == False: ou['error'] = 4 ou['msg'] = '读账号信息从数据库失败' return ou count = libdb.LibDB().query_count_by_condition( conditon, CONF['database']['table']) if count == False: ou['error'] = 4 ou['msg'] = '读账号数量从数据库失败' return ou total = count[0] if total == 0: data_str = '%d|none' % (total) else: data_str = '%d|%s|%s|%s' % (total, sql[2], sql[3], sql[9]) logger.debug('账号信息:%s', data_str) data_encryed = base64.b64encode(data_str) ou['msg'] = '获取成功' ou['data']['acc'] = data_encryed elif action == 'queryOneOutDate': #测试命令:curl -d "action=queryOneOutDate" -X POST http://localhost:8889/strapi/http.do timestamp = int(time.time() - 3600 * 24 * 6) conditon = 'lastdate <= %d and update_fail <= 5' % (timestamp) sql = libdb.LibDB().query_one_by_condition(conditon, CONF['database']['table']) if sql == False: ou['error'] = 4 ou['msg'] = '读账号信息从数据库失败' return ou count = libdb.LibDB().query_count_by_condition( conditon, CONF['database']['table']) if count == False: ou['error'] = 4 ou['msg'] = '读账号数量从数据库失败' return ou total = count[0] if total == 0: data_str = '%d|none' % (total) else: data_str = '%d|%s|%s|%s' % (total, sql[2], sql[3], sql[9]) logger.debug('账号信息:%s', data_str) data_encryed = base64.b64encode(data_str) ou['msg'] = '获取成功' ou['data']['acc'] = data_encryed elif action == 'queryOne': #测试命令:curl -d "action=queryOneOutDate" -X POST http://localhost:8889/strapi/http.do timestamp = int(time.time() - 3600 * 24 * 6) conditon = 'lastdate >= %d and update_fail <= 5' % (timestamp) sql = libdb.LibDB().query_one_by_condition(conditon, CONF['database']['table']) if sql == False: ou['error'] = 4 ou['msg'] = '读账号信息从数据库失败' return ou count = libdb.LibDB().query_count_by_condition( conditon, CONF['database']['table']) if count == False: ou['error'] = 4 ou['msg'] = '读账号数量从数据库失败' return ou total = count[0] if total == 0: data_str = '%d|none' % (total) else: data_str = '%d|%s|%s|%s' % (total, sql[2], sql[3], sql[9]) logger.debug('账号信息:%s', data_str) data_encryed = base64.b64encode(data_str) ou['msg'] = '获取成功' ou['data']['acc'] = data_encryed elif action == 'insertOne': #测试命令:curl -d "action=insertOne&entry=xxxx" -X POST http://localhost:8889/strapi/http.do entry = request.form.get('entry') if entry == None: ou['error'] = 3 ou['msg'] = '参数错误' return ou logger.debug('获取加密前:' + entry) str = base64.b64decode(entry) logger.debug('解密后:' + str) str = str.split('|') logger.debug(str) rv = cookieWriteToDB(str[0], str[1], str[2]) if rv != True: ou['error'] = 1 ou['msg'] = '写数据库失败' return ou ou['data']['num'] = 1 ou['msg'] = 'insert success' elif action == 'queryOneByNickname': # 测试命令:curl -d "action=queryOneByNickname&nick=xxxx" -X POST http://localhost:8889/strapi/http.do nick = request.form.get('nick') if nick == None: ou['error'] = 3 ou['msg'] = '参数错误' return ou sql = libdb.LibDB().query_one('nickname', nick, CONF['database']['table']) if sql == False: ou['error'] = 4 ou['msg'] = '读数据库失败' return ou if sql == None: ou['msg'] = '没有该用户信息' t = dict() t['id'] = None t['uid'] = None t['nickname'] = None t['password'] = None t['regdate'] = None t['lastdate'] = None t['colddate'] = None t['lastip'] = None t['usednum'] = None t['cookie'] = None else: ou['msg'] = 'read success' t = dict() t['id'] = sql[0] t['uid'] = sql[1] t['nickname'] = sql[2] t['password'] = sql[3] t['regdate'] = datetime.datetime.fromtimestamp(sql[4]) t['lastdate'] = datetime.datetime.fromtimestamp(sql[5]) t['colddate'] = datetime.datetime.fromtimestamp(sql[6]) t['lastip'] = sql[7] t['usednum'] = sql[8] t['cookie'] = sql[9] ou['data'] = t elif action == 'updateOne': # 测试命令:curl -d "action=updateOne&entry=xxxx" -X POST http://localhost:8889/strapi/http.do entry = request.form.get('entry') if entry == None: ou['error'] = 3 ou['msg'] = '参数错误' return ou logger.debug('获取加密前:' + entry) str = base64.b64decode(entry) logger.debug('解密后:' + str) str = str.split('|') logger.debug(str) if len(str) == 3: rv = cookieUpdateToDB(str[0], str[1], str[2]) elif len(str) == 2: rv = updateFailWriteToDB(str[0], str[1]) if rv != True: ou['error'] = 1 ou['msg'] = 'updaet DB failed' return ou ou['data']['num'] = 1 ou['msg'] = 'update success' else: ou['error'] = 2 ou['msg'] = '命令字暂不支持' return ou return ou