def insert_log_table_name(table_name, ip, apiname, username, isSuccess, request,message,other): time_m = datetime.now().strftime('%Y_%m') table_name = str(table_name)+"_"+str(time_m) conn = dbinfo() try: createtime = datetime.now().strftime('%Y-%m-%d %H:%M:%S') conncur = conn.cursor() connsql = "INSERT INTO "+table_name +"(ip, apiname,username,isSuccess,request,message,other,times) VALUES (%s,%s,%s,%s,%s,%s,%s,%s) " conncur.execute(connsql, (ip, apiname, username, isSuccess, request,message,other,createtime)) conn.commit() conn.close() return True except Exception as e: try: conn = dbinfo() conncur = conn.cursor() connsql = "CREATE TABLE `%s` (`id` int(11) NOT NULL AUTO_INCREMENT,`ip` varchar(255) DEFAULT NULL,`apiname` varchar(255) DEFAULT NULL,`username` varchar(255) NOT NULL,`isSuccess` varchar(255) DEFAULT NULL,`request` mediumtext,`message` mediumtext,`other` varchar(2550) DEFAULT NULL,`times` datetime DEFAULT NULL,PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;" % ( table_name) conncur.execute(connsql) conn.commit() createtime = datetime.now().strftime('%Y-%m-%d %H:%M:%S') conncur = conn.cursor() connsql = "INSERT INTO " + table_name + "(ip, apiname,username,isSuccess,request,message,other,times) VALUES (%s,%s,%s,%s,%s,%s,%s,%s) " conncur.execute(connsql, (ip, apiname, username, isSuccess, request, message, other, createtime)) conn.commit() conn.close() return True except Exception as es: return False
def crear_record_ldap(): conn = dbinfo() try: conncur = conn.cursor() connsql = '''CREATE TABLE `record_ldap` ( `id` int(11) NOT NULL AUTO_INCREMENT, `account` varchar(255) NOT NULL, `apps` varchar(255) NOT NULL, `applicant` varchar(255) NOT NULL, `application_division` varchar(255) NOT NULL, `manager` varchar(255) NOT NULL, `permission` varchar(255) NOT NULL, `Application_Date` varchar(255) NOT NULL, `end` varchar(255) NOT NULL, `link_server` varchar(255) NOT NULL, `Status` varchar(255) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=68 DEFAULT CHARSET=utf8''' conncur.execute(connsql) histroycounts = conncur.fetchall() conn.commit() conn.close() return histroycounts except Exception as e: print(e) return False
def create_exmailboxsize(): conn = dbinfo() try: conncur = conn.cursor() connsql = '''DROP TABLE IF EXISTS `exmailboxsize`; CREATE TABLE `exmailboxsize` ( `id` int(11) NOT NULL AUTO_INCREMENT, `databaseIdentity` varchar(255) DEFAULT NULL COMMENT '数据库名称', `databaseGuid` varchar(255) DEFAULT NULL COMMENT '数据库guid(唯一标识)', `databaseSizeStr` varchar(255) DEFAULT NULL COMMENT '数据库大小(显示)', `databaseSizeInt` bigint(255) DEFAULT NULL COMMENT '数据库实际大小(单位:b)', `databaseSpaceStr` varchar(255) DEFAULT NULL COMMENT '数据库空白空间大小(显示)', `databaseSpaceInt` bigint(255) DEFAULT NULL COMMENT '数据库空白空间大小(单位:b)', `databaseMailboxNumber` int(11) DEFAULT NULL COMMENT 'DB内数据库数量', `databaseSpaceProportion` int(11) DEFAULT NULL COMMENT '空白空间占比', `messageDatetime` datetime DEFAULT NULL COMMENT '数据时间', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;''' conncur.execute(connsql) histroycounts = conncur.fetchall() conn.commit() conn.close() return histroycounts except Exception as e: return False
def insert_indexmessagedb( allusercountvalue, alldisableusercountvalue, allexpiredpasswordusercountvalue, alllockusercountvalue, nologoinusercountvalue, allgroupcountvalue, allgrouptalkgroupcountvalue, allgroupsavegroupcpuntvalue, allgroupnomembercountvalue, allgrouphasmailcountvalue, allcomputercountvalue, allcomputernologoincountvalue, allcomputernodisablecpuntvalue, allcomputerdisablecountvalue, allexchangeusercountvalue, allnoexchangeusercountvalue, allexchangehasarchivecpuntvalue, allexchangenodizhicountvalue, allexchangenoarchivecountvalue): #写入数据 conn = dbinfo() try: createtime = datetime.now().strftime('%Y-%m-%d %H:%M:%S') conncur = conn.cursor() connsql = "INSERT INTO indexmessage (allusercountvalue, alldisableusercountvalue, allexpiredpasswordusercountvalue, alllockusercountvalue, nologoinusercountvalue, allgroupcountvalue, allgrouptalkgroupcountvalue, allgroupsavegroupcpuntvalue,allgroupnomembercountvalue,allgrouphasmailcountvalue,allcomputercountvalue,allcomputernologoincountvalue,allcomputernodisablecpuntvalue,allcomputerdisablecountvalue,allexchangeusercountvalue,allnoexchangeusercountvalue,allexchangehasarchivecpuntvalue,allexchangenodizhicountvalue,allexchangenoarchivecountvalue,datetime) VALUE (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)" aa = conncur.execute( connsql, (allusercountvalue, alldisableusercountvalue, allexpiredpasswordusercountvalue, alllockusercountvalue, nologoinusercountvalue, allgroupcountvalue, allgrouptalkgroupcountvalue, allgroupsavegroupcpuntvalue, allgroupnomembercountvalue, allgrouphasmailcountvalue, allcomputercountvalue, allcomputernologoincountvalue, allcomputernodisablecpuntvalue, allcomputerdisablecountvalue, allexchangeusercountvalue, allnoexchangeusercountvalue, allexchangehasarchivecpuntvalue, allexchangenodizhicountvalue, allexchangenoarchivecountvalue, createtime)) conn.commit() conn.close() return aa except Exception as e: print(e)
def insert_ldapdb(account, apps, applicant, application_division, manager, permission, Application_Date,end,link_server,Status): #写入数据 conn = dbinfo() try: conncur = conn.cursor() connsql = "INSERT INTO record_ldap (account, apps, applicant, application_division, manager, permission, Application_Date, end,link_server,Status) VALUE (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)" aa=conncur.execute(connsql, (account, apps, applicant, application_division, manager, permission, Application_Date,end,link_server,Status)) conn.commit() conn.close() return aa except Exception as e: print(e)
def insert_dnsdb(domain_name, apps, applicant, application_division, ops, type, Applicant_time,Status): #写入数据 conn = dbinfo() try: conncur = conn.cursor() connsql = "INSERT INTO record_dns (domain_name, apps, applicant, application_division, ops, type, Applicant_time,Status) VALUE (%s, %s, %s, %s, %s, %s, %s, %s)" aa=conncur.execute(connsql, (domain_name, apps, applicant, application_division, ops, type, Applicant_time,Status)) conn.commit() conn.close() return aa except Exception as e: print(e)
def delete_dnsdb(ID,Status): # conn = dbinfo() try: conncur = conn.cursor() connsql = "update record_dns SET status=%s where ID=%s" aa=conncur.execute(connsql, (Status, ID)) #数据库删除失败返回0,删除成功返回1 conn.commit() conn.close() return aa except Exception as e: print(e)
def upadte_dnsdb(ID,domain_name, apps, applicant, application_division, ops, type, Applicant_time): conn = dbinfo() try: conncur = conn.cursor() connsql = "update record_dns SET domain_name= %s, apps= %s, applicant= %s, application_division= %s, ops= %s, type= %s, Applicant_time= %s where ID= %s" aa = conncur.execute(connsql, (domain_name, apps, applicant, application_division, ops, type, Applicant_time,ID)) #数据库写入续约失败返回0,续约成功返回1 conn.commit() conn.close() return aa #返回1或者0 1成功 0失败 except Exception as e: print(e)
def upadte_ldapdb(ID,account, apps, applicant, application_division, manager, permission, Application_Date,end,link_server): conn = dbinfo() try: conncur = conn.cursor() connsql = "update record_ldap SET account= %s, apps= %s, applicant= %s, application_division= %s, manager= %s, permission= %s, Application_Date= %s,end= %s,link_server= %s where ID= %s" aa = conncur.execute(connsql, (account, apps, applicant, application_division, manager, permission, Application_Date,end,link_server,ID)) #数据库写入续约失败返回0,续约成功返回1 conn.commit() conn.close() return aa #返回1或者0 1成功 0失败 except Exception as e: print(e)
def selectldaprecord(): conn = dbinfo() try: conncur = conn.cursor() connsql = "show tables like 'record_ldap'" conncur.execute(connsql) histroycounts = conncur.fetchone() conn.commit() conn.close() return histroycounts except Exception as e: print(e)
def insert_tokenb(username, token): #写入数据 conn = dbinfo() try: createtime = datetime.now().strftime('%Y-%m-%d %H:%M:%S') conncur = conn.cursor() connsql = "INSERT INTO usertoken (username, token,date ) VALUE (%s,%s,%s)" aa=conncur.execute(connsql, (username, token,createtime)) conn.commit() conn.close() return aa except Exception as e: print(e)
def insert_attributeslevel(apiname,attributes): try: conn = dbinfo() conncur = conn.cursor() connsql = "INSERT INTO apiusers_attributeslevel (apiname,attributes) VALUES (%s,%s)" conncur.execute(connsql, (apiname,attributes)) histroycounts = conncur.fetchall() conn.commit() conn.close() return True except Exception as e: return False
def get_apinamepermissions_is(username_id,apiname): conn = dbinfo() try: conncur = conn.cursor() connsql = "SELECT * FROM apiusers_apinamepermissions WHERE username_id=%s AND apiname=%s" conncur.execute(connsql, (username_id,apiname)) histroycounts = conncur.fetchall() conn.commit() conn.close() return histroycounts except Exception as e: return False
def get_apiusers_profile(): conn = dbinfo() try: conncur = conn.cursor() connsql = "SELECT id,username,is_active,name,department,description FROM apiusers_profile " conncur.execute(connsql, ()) histroycounts = conncur.fetchall() conn.commit() conn.close() return histroycounts except Exception as e: return False
def getpermsessage(): try: conn = dbinfo() conncur = conn.cursor() connsql = "SELECT fieldgroup,changepwdgroup,logongroup,operagroup,monitor,zabbixurl,zabbixuser,zabbixpassword FROM UserPer LIMIT 1" conncur.execute(connsql) histroycounts = conncur.fetchone() conn.commit() conn.close() return histroycounts except Exception as e: return None
def getliisconfigtion(): try: conn = dbinfo() conncur = conn.cursor() connsql = "SELECT * FROM exiisconfig LIMIT 1" conncur.execute(connsql) histroycounts = conncur.fetchone() conn.commit() conn.close() return histroycounts except Exception as e: return None
def get_ldapdbvaule(ID): # conn = dbinfo() try: conncur = conn.cursor() connsql = "select * from record_ldap where ID=%s" conncur.execute(connsql, (ID)) histroycounts = conncur.fetchall() conn.commit() conn.close() return histroycounts except Exception as e: return False
def derroltable(id): conn = dbinfo() try: conncur = conn.cursor() connsql = "DELETE FROM messgerro where id = %s" conncur.execute(connsql, (id)) histroycounts = conncur.fetchall() conn.commit() conn.close() return histroycounts except Exception as e: print (e)
def select_apipermissions(apiname, username): conn = dbinfo() try: conncur = conn.cursor() connsql = "SELECT `apiusers_apinamepermissions`.`apiname` FROM `apiusers_apinamepermissions`,apiusers_profile WHERE (apiusers_profile.is_active = 1 AND `apiusers_apinamepermissions`.`apiname` = %s AND apiusers_profile.username = %s)" conncur.execute(connsql, (apiname, username,)) histroycounts = conncur.fetchall() conn.commit() conn.close() return histroycounts except Exception as e: return False
def upsaves(texid, title, tab,name): conn = dbinfo() try: conncur = conn.cursor() connsql = "UPDATE Mess SET title=%s,tab=%s,message=%s WHERE id=%s" conncur.execute(connsql, (title, tab, name,texid)) histroycounts = conncur.fetchall() conn.commit() conn.close() return histroycounts except Exception as e: print(e)
def update_apiusers_profile(id,name,vaule): conn = dbinfo() try: conncur = conn.cursor() connsql = "UPDATE apiusers_profile SET "+name+"=%s WHERE id=%s" conncur.execute(connsql, (vaule, id)) histroycounts = conncur.fetchall() conn.commit() conn.close() return True except Exception as e: return False
def delect_apinamepermissions_username_id(username_id): conn = dbinfo() try: conncur = conn.cursor() connsql = "DELETE FROM apiusers_apinamepermissions WHERE username_id=%s" conncur.execute(connsql, (username_id)) histroycounts = conncur.fetchall() conn.commit() conn.close() return True except Exception as e: return False
def show_tables(): try: conn = dbinfo() conncur = conn.cursor() connsql = "show tables;" conncur.execute(connsql, ()) histroycounts = conncur.fetchall() conn.commit() conn.close() return histroycounts except Exception as e: return False
def get_attributeslevel_apiname(apiname): conn = dbinfo() try: conncur = conn.cursor() connsql = "SELECT * FROM apiusers_attributeslevel WHERE apiname=%s" conncur.execute(connsql, (apiname)) histroycounts = conncur.fetchall() conn.commit() conn.close() return histroycounts except Exception as e: return False
def insert_apinamepermissions(username_id,apiname): try: conn = dbinfo() conncur = conn.cursor() connsql = "INSERT INTO apiusers_apinamepermissions (username_id,apiname) VALUES (%s,%s)" conncur.execute(connsql, (username_id,apiname)) histroycounts = conncur.fetchall() conn.commit() conn.close() return True except Exception as e: return False
def get_log_ldapattributes(): conn = dbinfo() try: conncur = conn.cursor() connsql = "select * from LDAPAttributes" conncur.execute(connsql, ()) histroycounts = conncur.fetchall() conn.commit() conn.close() return histroycounts except Exception as e: return False
def delect_attributeslevel(id): conn = dbinfo() try: conncur = conn.cursor() connsql = "DELETE FROM apiusers_attributeslevel WHERE id=%s" conncur.execute(connsql, (id)) histroycounts = conncur.fetchall() conn.commit() conn.close() return True except Exception as e: return False
def finderromintable(): try: conn = dbinfo() conncur = conn.cursor() connsql = "SELECT * FROM messgerro order by creatime desc " conncur.execute(connsql) histroycounts = conncur.fetchall() conn.commit() conn.close() return histroycounts except Exception as e: return None
def update_attributeslevel(attributes,id): conn = dbinfo() try: conncur = conn.cursor() connsql = "UPDATE apiusers_attributeslevel SET attributes=%s WHERE id=%s" conncur.execute(connsql, (attributes,id)) histroycounts = conncur.fetchall() conn.commit() conn.close() return True except Exception as e: return False
def searmesserrid(textid): conn = dbinfo() try: conncur = conn.cursor() connsql = "select * from messgerro where id = %s" conncur.execute(connsql, (textid)) histroycounts = conncur.fetchall() conn.commit() conn.close() return histroycounts except Exception as e: print(e)