def run(self): try: time.sleep(50) UserToExcs = UserToExc(self.sAMAccountName, self.maildb) if UserToExcs['isSuccess']: result = { "isSuccess": True, "message": self.sAMAccountName + ",创建邮箱成功" } else: result = { "isSuccess": False, "message": self.sAMAccountName + ",创建邮箱失败:" + str(UserToExcs['message']) } except Exception as e: result = { "isSuccess": False, "message": self.sAMAccountName + ",创建邮箱失败:" + str(e) } insert_log_table_name('log', '', 'user_to_exc', '创建邮箱', str(result['isSuccess']), str(self.sAMAccountName), str(result), str(self.maildb)) return result
def has_permission(self, request, view): try: apiname = request.path.split(r"/")[1] except Exception as e: apiname = request._request.split(r'/')[-2] ip = request.META.get('HTTP_X_FORWARDED_FOR', request.META['REMOTE_ADDR']) apiusername = request.user select_apipermission = select_apipermissions(str(apiname), str(apiusername)) if select_apipermission: return True else: insert_log_table_name('log_api', str(ip), str(apiname), str(apiusername), 'False', str(request.data), '没有对应的api权限', str(request.auth)) return False
def has_permission(self, request, view): try: try: apiname = request.path.split(r"/")[1] except Exception as e: apiname = request._request.split(r'/')[-2] ip = request.META.get('HTTP_X_FORWARDED_FOR', request.META['REMOTE_ADDR']) apiusername = request.user attributes_level = get_attributeslevel_apiname(apiname) data = request.data if attributes_level: attributes = attributes_level[0]['attributes'] attributesList= ast.literal_eval(attributes) if "SetAccount" in apiname: attributesName = data.get('attributesName','') if attributesName.lower() in [attributesL.lower() for attributesL in attributesList]: return True else: insert_log_table_name('log_api', str(ip), str(apiname), str(apiusername), 'False', str(request.data), 'SetAccount 数据库没有对应的权限数据', str(request.auth)) return False else: data_copy = data.copy() data_copy.pop('identity') data_copy_keylist = data_copy.keys() for data_key in data_copy_keylist: if data_key.lower() not in [attributesL.lower() for attributesL in attributesList]: insert_log_table_name('log_api', str(ip), str(apiname), str(apiusername), 'False', str(request.data), str(attributes_level)+'SetAccount 数据库没有对应的权限数据', str(request.auth)) return False return True else: insert_log_table_name('log_api', str(ip), str(apiname), str(apiusername), 'False', str(request.data), 'apiusers_attributeslevel数据库没有对应的权限数据', str(request.auth)) return False except Exception as e: insert_log_table_name('log_api', str(ip), str(apiname), str(apiusername), 'False', str(request.data), "AdapiPermissionsLevel:修改AD,邮箱属性需要根据数据库确定 传入的值 的权限"+str(e), str(request.auth)) return False
def run(self): while True: # 需要通过循环来不断的运行任务 item = self.queue.get() getDatato = item[0] dn = item[1] try: distinguishedName = repeace_dn(dn) usermessage = {} result = {} status = {'status': '用户创建失败'} if '0' in getDatato: getDatato.pop('0') if 'sAMAccountName' in getDatato: sAMAccountName = getDatato['sAMAccountName'] if 'cn' in getDatato: newdistinguishedName = "CN=" + getDatato[ 'cn'] + "," + distinguishedName usermessage.update({'cn': getDatato['cn']}) getDatato.pop('cn') else: newdistinguishedName = "CN=" + sAMAccountName + "," + distinguishedName if 'userPrincipalName' in getDatato: userPrincipalName = getDatato['userPrincipalName'] getDatato.pop('userPrincipalName') else: userPrincipalName = sAMAccountName + '@' + ladp3search_domain if 'disableuser' in getDatato: userAccountControl = 546 getDatato.pop('disableuser') else: userAccountControl = 544 with ldap3RESTARTABLE as conn: newuser = conn.add(dn=newdistinguishedName, object_class=[ "top", "person", "organizationalPerson", "user" ], attributes={ 'sAMAccountName': sAMAccountName, 'userPrincipalName': userPrincipalName, 'userAccountControl': userAccountControl }) if newuser: status = {'status': '用户创建成功'} usermessage.update( {'sAMAccountName': sAMAccountName}) usermessage.update( {'userPrincipalName': userPrincipalName}) usermessage.update( {'userAccountControl': userAccountControl}) getDatato.pop('sAMAccountName') if 'password' in getDatato: passwd = getDatato['password'] getDatato.pop('password') else: passwd = getpwd(10) port = conn.server.port if int(port) == 636: modify_password = conn.extend.microsoft.modify_password( newdistinguishedName, passwd) if modify_password: result.update({'password': passwd}) modify_userAccountControl = conn.modify( dn=newdistinguishedName, changes={ 'userAccountControl': [('MODIFY_REPLACE', [512])] }) if modify_userAccountControl: usermessage.update( {'userAccountControl': 512}) else: result.update({'password': '******'}) else: result.update( {'password': '******'}) if 'maildb' in getDatato: maildb = getDatato['maildb'] if maildb: #UserCreatMail(sAMAccountName, maildb) import time import random time.sleep(int(random.randint(60, 130))) UserToExcs = UserToExc( sAMAccountName, maildb) if not UserToExcs['isSuccess']: insert_log_table_name( 'log', '', 'user_to_exc', '创建邮箱', str(UserToExcs['isSuccess']), str(sAMAccountName), str(UserToExcs['message']), str(maildb)) usermessage.update({'maildb': maildb}) getDatato.pop('maildb') for dataName, dateVaule in getDatato.items(): try: modify_user = conn.modify( dn=newdistinguishedName, changes={ dataName: [('MODIFY_REPLACE', [dateVaule])] }) if not modify_user: getDatato.update({dataName: '修改属性失败'}) except: getDatato.pop(dataName) else: status = {'status': '用户创建失败:' + str(conn.result)} else: status = {'status': '用户创建失败:sAMAccountName不能为空'} except Exception as e: status = {'status': '用户创建失败:' + str(e)} result.update(getDatato) result.update(usermessage) result.update(status) creatusermessage.append(result) self.queue.task_done()
def run(self): conn = dbinfo() if conn: try: conncur = conn.cursor() connsql = "show tables like 'django_session'" conncur.execute(connsql) django_session = conncur.fetchone() conn.commit() if not django_session: conncur = conn.cursor() connsql = '''DROP TABLE IF EXISTS `django_session`; CREATE TABLE `django_session` ( `session_key` varchar(40) NOT NULL, `session_data` longtext NOT NULL, `expire_date` datetime(6) NOT NULL, PRIMARY KEY (`session_key`), KEY `django_session_expire_date_a5c62663` (`expire_date`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; ''' conncur.execute(connsql) conn.commit() except Exception as e: insert_log_table_name('log', '127.0.0.1', 'ThrCreatMysqlTable', 'adminportal', 'False', 'django_session', '创建django_session表', str(e)) try: conncur = conn.cursor() connsql = "show tables like 'exiisconfig'" conncur.execute(connsql) django_session = conncur.fetchone() conn.commit() if not django_session: conncur = conn.cursor() connsql = '''DROP TABLE IF EXISTS `exiisconfig`; CREATE TABLE `exiisconfig` ( `id` int(11) NOT NULL AUTO_INCREMENT, `exserver` varchar(255) DEFAULT NULL, `exuser` varchar(255) DEFAULT NULL, `expassword` varchar(255) DEFAULT NULL, `exdomain` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL, `status` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;''' conncur.execute(connsql) conn.commit() except Exception as e: insert_log_table_name('log', '127.0.0.1', 'ThrCreatMysqlTable', 'adminportal', 'False', 'django_session', '创建邮箱表', str(e)) try: conncur = conn.cursor() connsql = "show tables like 'apiusers_profile'" conncur.execute(connsql) apiusers_profile = conncur.fetchone() conn.commit() if not apiusers_profile: conncur = conn.cursor() connsql = ''' DROP TABLE IF EXISTS `apiusers_profile`; CREATE TABLE `apiusers_profile` ( `id` int(11) NOT NULL AUTO_INCREMENT, `password` varchar(128) NOT NULL, `last_login` datetime(6) DEFAULT NULL, `is_superuser` tinyint(1) NOT NULL, `username` varchar(150) NOT NULL, `first_name` varchar(30) NOT NULL, `last_name` varchar(30) NOT NULL, `email` varchar(254) NOT NULL, `is_staff` tinyint(1) NOT NULL, `is_active` tinyint(1) NOT NULL, `date_joined` datetime(6) NOT NULL, `name` varchar(50) DEFAULT NULL, `department` varchar(255) DEFAULT NULL, `description` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `username` (`username`) USING BTREE ) ENGINE=InnoDB AUTO_INCREMENT=29 DEFAULT CHARSET=utf8; ''' conncur.execute(connsql) conn.commit() except Exception as e: insert_log_table_name('log', '127.0.0.1', 'ThrCreatMysqlTable', 'adminportal', 'False', 'apiusers_profile', '创建apiusers_profile表', str(e)) try: conncur = conn.cursor() connsql = "show tables like 'apiusers_apinamepermissions'" conncur.execute(connsql) apiusers_apinamepermissions = conncur.fetchone() conn.commit() if not apiusers_apinamepermissions: conncur = conn.cursor() connsql = ''' DROP TABLE IF EXISTS `apiusers_apinamepermissions`; CREATE TABLE `apiusers_apinamepermissions` ( `id` int(11) NOT NULL AUTO_INCREMENT, `apiname` varchar(50) NOT NULL, `username_id` int(11) NOT NULL, PRIMARY KEY (`id`), KEY `apiusers_permissions_username_id_10b067f1_fk_apiusers_profile_id` (`username_id`) USING BTREE, CONSTRAINT `apiusers_apinamepermissions_ibfk_2` FOREIGN KEY (`username_id`) REFERENCES `apiusers_profile` (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=137 DEFAULT CHARSET=utf8; ''' conncur.execute(connsql) conn.commit() except Exception as e: insert_log_table_name('log', '127.0.0.1', 'ThrCreatMysqlTable', 'adminportal', 'False', 'apiusers_apinamepermissions', '创建apiusers_apinamepermissions表', str(e)) try: conncur = conn.cursor() connsql = "show tables like 'apiusers_attributeslevel'" conncur.execute(connsql) apiusers_attributeslevel = conncur.fetchone() conn.commit() if not apiusers_attributeslevel: conncur = conn.cursor() connsql = ''' DROP TABLE IF EXISTS `apiusers_attributeslevel`; CREATE TABLE `apiusers_attributeslevel` ( `id` int(11) NOT NULL AUTO_INCREMENT, `apiname` varchar(255) NOT NULL, `attributes` mediumtext, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8; ''' conncur.execute(connsql) conn.commit() conncur = conn.cursor() connsql = ''' INSERT INTO `apiusers_attributeslevel` VALUES ('1', 'EXSetMailbox1', "['CN','Sn','Givename','Initials','displayName','Description', 'physicalDeliveryOfficeName','telephoneNumber','Mail', 'wWWHomePage','C','St','L','streetAddress','postOfficeBox','postalCode','homePhone','Pager','mobile','FacsimileTelephoneNumber','ipPhone','Info','Title','Department','Company','ProhibitSendQuota','ProhibitSendReceiveQuota','RecipientLimits','UseDatabaseQuotaDefaults','IssueWarningQuota','RulesQuota','ArchiveName','ArchiveQuota','ArchiveWarningQuota','Office']"); INSERT INTO `apiusers_attributeslevel` VALUES ('2', 'EXSetMailbox2', "['CN','Sn','Givename','Initials','displayName','Description', 'physicalDeliveryOfficeName','telephoneNumber','Mail', 'wWWHomePage','C','St','L','streetAddress','postOfficeBox','postalCode','homePhone','Pager','mobile','FacsimileTelephoneNumber','ipPhone','Info','Title','Department','Company','ProhibitSendQuota','ProhibitSendReceiveQuota','RecipientLimits','UseDatabaseQuotaDefaults','IssueWarningQuota','RulesQuota','ArchiveName','ArchiveQuota','ArchiveWarningQuota','Office','accountExpires','memberOf','sAMAccountName','member','memberOf','managedBy','Alias','EmailAddressPolicyenabled','PrimarySmtpAddress']"); INSERT INTO `apiusers_attributeslevel` VALUES ('3', 'Ldap3SetAccountLevel1', "['CN','Sn','Givename','Initials','displayName','Description', 'physicalDeliveryOfficeName','telephoneNumber','Mail', 'wWWHomePage','C','St','L','streetAddress','postOfficeBox','postalCode','homePhone','Pager','mobile','FacsimileTelephoneNumber','ipPhone','Info','Title','Department','Company','ProhibitSendQuota','ProhibitSendReceiveQuota','RecipientLimits','UseDatabaseQuotaDefaults','IssueWarningQuota','RulesQuota','ArchiveName','ArchiveQuota','ArchiveWarningQuota','Office']"); INSERT INTO `apiusers_attributeslevel` VALUES ('4', 'Ldap3SetAccountLevel2', "['CN','Sn','Givename','Initials','displayName','Description', 'physicalDeliveryOfficeName','telephoneNumber','Mail', 'wWWHomePage','C','St','L','streetAddress','postOfficeBox','postalCode','homePhone','Pager','mobile','FacsimileTelephoneNumber','ipPhone','Info','Title','Department','Company','ProhibitSendQuota','ProhibitSendReceiveQuota','RecipientLimits','UseDatabaseQuotaDefaults','IssueWarningQuota','RulesQuota','ArchiveName','ArchiveQuota','ArchiveWarningQuota','Office','accountExpires','memberOf','sAMAccountName','member','memberOf','managedBy','Alias','EmailAddressPolicyenabled','PrimarySmtpAddress']"); ''' conncur.execute(connsql) conn.commit() except Exception as e: insert_log_table_name('log', '127.0.0.1', 'ThrCreatMysqlTable', 'adminportal', 'False', 'apiusers_attributeslevel', '创建apiusers_attributeslevel表', str(e)) try: conncur = conn.cursor() connsql = "show tables like 'LDAPAttributes'" conncur.execute(connsql) LDAPAttributes = conncur.fetchone() conn.commit() if not LDAPAttributes: conncur = conn.cursor() connsql = ''' DROP TABLE IF EXISTS `LDAPAttributes`; CREATE TABLE `LDAPAttributes` ( `id` int(255) NOT NULL AUTO_INCREMENT, `Name` varchar(255) DEFAULT NULL, `LDAPName` varchar(255) DEFAULT NULL, `CNName` varchar(255) DEFAULT NULL, `type` varchar(255) DEFAULT NULL, `typeName` varchar(255) DEFAULT NULL, `NameUrl` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=43 DEFAULT CHARSET=utf8; ''' conncur.execute(connsql) conn.commit() conncur = conn.cursor() connsql = ''' INSERT INTO `LDAPAttributes` VALUES ('1', 'First Name', 'givenName', '名字', 'str', '字符串', null); INSERT INTO `LDAPAttributes` VALUES ('2', 'Middle Name / Initials', 'initials', '中间名首字母缩写', 'str', '字符串', null); INSERT INTO `LDAPAttributes` VALUES ('3', 'Last Name', 'sn', '姓氏', 'str', '字符串', null); INSERT INTO `LDAPAttributes` VALUES ('4', 'Logon Name', 'userPrincipalName', '登录名', 'str', '字符串', null); INSERT INTO `LDAPAttributes` VALUES ('5', 'Logon Name (Pre Windows 2000)', 'sAMAccountName', '登录名(Windows 2000以前版本)', 'str', '字符串', null); INSERT INTO `LDAPAttributes` VALUES ('6', 'Display Name', 'displayName', '显示名称', 'str', '字符串', null); INSERT INTO `LDAPAttributes` VALUES ('7', 'Full Name', 'cn', '全名', 'str', '字符串', null); INSERT INTO `LDAPAttributes` VALUES ('8', 'Description', 'description', '描述', 'str', '字符串', null); INSERT INTO `LDAPAttributes` VALUES ('9', 'Office', 'physicalDeliveryOfficeName', '办公室', 'str', '字符串', null); INSERT INTO `LDAPAttributes` VALUES ('10', 'Telephone Number', 'telephoneNumber', '电话号码', 'str', '字符串', null); INSERT INTO `LDAPAttributes` VALUES ('11', 'Email', 'mail', '电子邮件', 'str', '字符串', null); INSERT INTO `LDAPAttributes` VALUES ('12', 'Web Page', 'wWWHomePage', '网页', 'str', '字符串', null); INSERT INTO `LDAPAttributes` VALUES ('14', 'Street', 'streetAddress', '街道', 'str', '字符串', null); INSERT INTO `LDAPAttributes` VALUES ('15', 'PO Box', 'postOfficeBox', '邮政信箱', 'list', '多值字符串', null); INSERT INTO `LDAPAttributes` VALUES ('16', 'City', 'l', '市/县(地址选项卡)', 'str', '字符串', null); INSERT INTO `LDAPAttributes` VALUES ('17', 'State/Province', 'st', '省/自治区', 'str', '字符串', null); INSERT INTO `LDAPAttributes` VALUES ('18', 'Zip/Postal Code', 'postalCode', '邮政编码', 'str', '字符串', null); INSERT INTO `LDAPAttributes` VALUES ('19', 'Country ', 'co', '国家 - 例如 中国', 'str', '字符串', null); INSERT INTO `LDAPAttributes` VALUES ('20', 'Country 2', 'c', '国家2数字代码 - 例如。我们 CN', 'str', '字符串', null); INSERT INTO `LDAPAttributes` VALUES ('21', 'Country code', 'countryCode', '国家代码-eg。对于中国国家代码是156', 'int', '整数', null); INSERT INTO `LDAPAttributes` VALUES ('22', 'Add to Groups', 'memberOf', '隶属于(成员)', 'list', '多值字符串', null); INSERT INTO `LDAPAttributes` VALUES ('24', 'Account Expires (use same date format as server)', 'accountExpires', '账户过期', 'datetime', '大整数', null); INSERT INTO `LDAPAttributes` VALUES ('25', 'User Account Control ', 'userAccountControl', '用户帐户控制', 'int', '整数', null); INSERT INTO `LDAPAttributes` VALUES ('26', 'User Photo ', 'thumbnailPhoto', '用户照片', 'str', '八进制字符串', null); INSERT INTO `LDAPAttributes` VALUES ('27', 'Profile Path', 'profilePath', '配置文件路径(配置文件选项卡)', 'str', '字符串', null); INSERT INTO `LDAPAttributes` VALUES ('28', 'Login Script', 'scriptPath', '登录脚本', 'str', '字符串', null); INSERT INTO `LDAPAttributes` VALUES ('29', 'Home Folder', 'homeDirectory', '本地路径', 'str', '字符串', null); INSERT INTO `LDAPAttributes` VALUES ('30', 'Home', 'homePhone', '家庭电话', 'str', '字符串', null); INSERT INTO `LDAPAttributes` VALUES ('31', 'Pager', 'pager', '寻呼机', 'str', '字符串', null); INSERT INTO `LDAPAttributes` VALUES ('32', 'Mobile', 'mobile', '移动电话', 'str', '字符串', null); INSERT INTO `LDAPAttributes` VALUES ('33', 'Fax', 'facsimileTelephoneNumber', '传真', 'str', '字符串', null); INSERT INTO `LDAPAttributes` VALUES ('34', 'IP Phone', 'ipPhone', 'IP电话', 'str', '字符串', null); INSERT INTO `LDAPAttributes` VALUES ('35', 'Notes', 'info', '注释(电话选项卡)', 'str', '字符串', null); INSERT INTO `LDAPAttributes` VALUES ('36', 'Title', 'title', '职务', 'str', '字符串', null); INSERT INTO `LDAPAttributes` VALUES ('37', 'Department', 'department', '部门', 'str', '字符串', null); INSERT INTO `LDAPAttributes` VALUES ('38', 'Company', 'company', '公司', 'str', '字符串', null); INSERT INTO `LDAPAttributes` VALUES ('39', 'Manager', 'manager', '管理者', 'str', '字符串', null); INSERT INTO `LDAPAttributes` VALUES ('40', 'msDS-UserPasswordExpiryTimeComputed', 'msDSUserPasswordExpiryTimeComputed', '密码过期时间', 'datetime', '大整数', null); INSERT INTO `LDAPAttributes` VALUES ('41', 'whenCreated', 'whenCreated', '创建时间(R)', 'datetime', '时间属性:所有时间均为格林威治标准时间(GMT)', null); INSERT INTO `LDAPAttributes` VALUES ('42', 'whenChanged', 'whenChanged', '修改时间(M)', 'datetime', '时间属性:所有时间均为格林威治标准时间(GMT)', null); ''' conncur.execute(connsql) conn.commit() except Exception as e: insert_log_table_name('log', '127.0.0.1', 'ThrCreatMysqlTable', 'adminportal', 'False', 'LDAPAttributes', '创建LDAPAttributes表', str(e)) try: conncur = conn.cursor() connsql = "show tables like 'usertoken'" conncur.execute(connsql) usertoken = conncur.fetchone() conn.commit() if not usertoken: conncur = conn.cursor() connsql = '''DROP TABLE IF EXISTS `usertoken`; CREATE TABLE `usertoken` ( `id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(255) DEFAULT NULL, `token` varchar(255) DEFAULT NULL, `date` datetime DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8; ''' conncur.execute(connsql) conn.commit() except Exception as e: insert_log_table_name('log', '127.0.0.1', 'ThrCreatMysqlTable', 'adminportal', 'False', 'usertoken', '创建usertoken表', str(e)) try: conncur = conn.cursor() connsql = "show tables like 'Mess'" conncur.execute(connsql) Mess = conncur.fetchone() conn.commit() if not Mess: conncur = conn.cursor() connsql = '''DROP TABLE IF EXISTS `Mess`; CREATE TABLE `Mess` ( `id` int(11) NOT NULL AUTO_INCREMENT, `title` varchar(255) DEFAULT NULL, `tab` varchar(255) DEFAULT NULL, `message` longtext, `user` varchar(255) DEFAULT NULL, `date` datetime DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=42 DEFAULT CHARSET=utf8; ''' conncur.execute(connsql) conn.commit() except Exception as e: insert_log_table_name('log', '127.0.0.1', 'ThrCreatMysqlTable', 'adminportal', 'False', 'Mess', '创建Mess表', str(e)) try: conncur = conn.cursor() connsql = "show tables like 'tokenstatus'" conncur.execute(connsql) Mess = conncur.fetchone() conn.commit() if not Mess: conncur = conn.cursor() connsql = '''CREATE TABLE `tokenstatus` ( `id` int(11) NOT NULL AUTO_INCREMENT, `usergotoken` varchar(255) DEFAULT NULL, `ostatus` varchar(255) DEFAULT NULL, `tstatus` varchar(255) DEFAULT NULL, `sstatus` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4; ''' conncur.execute(connsql) conn.commit() except Exception as e: insert_log_table_name('log', '127.0.0.1', 'ThrCreatMysqlTable', 'adminportal', 'False', 'Mess', '创建tokenstatus表', str(e)) try: conncur = conn.cursor() connsql = "show tables like 'messgerro'" conncur.execute(connsql) messgerro = conncur.fetchone() conn.commit() if not messgerro: conncur = conn.cursor() connsql = '''DROP TABLE IF EXISTS `messgerro`; CREATE TABLE `messgerro` ( `id` int(11) NOT NULL AUTO_INCREMENT, `title` varchar(255) DEFAULT NULL, `userper` varchar(255) DEFAULT NULL, `accfet` varchar(255) DEFAULT NULL, `datetime` varchar(255) DEFAULT NULL, `tips` varchar(255) DEFAULT NULL, `marke` longtext, `creatuser` varchar(255) DEFAULT NULL, `creatime` datetime DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8; ''' conncur.execute(connsql) conn.commit() except Exception as e: insert_log_table_name('log', '127.0.0.1', 'ThrCreatMysqlTable', 'adminportal', 'False', 'messgerro', '创建messgerro表', str(e)) return 1
def run(self): while True: # 需要通过循环来不断的运行任务 item = self.queue.get() getDatato = item[0] username = item[1] try: usermessage = {} result = {} if '' in getDatato: getDatato.pop('') if '0' in getDatato: getDatato.pop('0') attributesldap = list(getDatato.keys()) if getDatato['sAMAccountName']: sAMAccountName_repeace = repeace_dn(getDatato['sAMAccountName']) with ldap3RESTARTABLE as conn: conn.search( search_base=ladp3search_base, search_filter='(&(sAMAccountName=' + sAMAccountName_repeace + ')(&(objectCategory=person)(objectClass=user)))', attributes=attributesldap) response = conn.response[0] dn = response.get('dn', '') if dn: attributes = response.get('attributes', '') cn = None for key, vaule in dict(attributes).items(): if key == 'cn': cn = "CN=" + getDatato.get('cn', None) else: attributesVaule = getDatato.get(key, None) if attributesVaule: attributesVaule = [attributesVaule] else: attributesVaule = [] modify_dn = conn.modify(dn=dn, changes={key: [(MODIFY_REPLACE, attributesVaule)]}) message = dn +'的属性'+key+':的值'+str(attributes[key])+'修改成'+str(getDatato[key]) insert_log_table_name('log_ldap', '172.0.0.1', 'ModifyUserThread_modify_dn', username, str(modify_dn), str(item), message, str(attributes)) if cn: modify_cn = conn.modify_dn(dn, cn) message_cn = dn + '的属性cn:的值' + str(attributes.get('cn','')) + '修改成' + str(getDatato.get('cn','')) insert_log_table_name('log_ldap', '172.0.0.1', 'ModifyUserThread_modify_cn', username, str(modify_cn), str(item), message_cn, str(attributes)) conn.search( search_base=ladp3search_base, search_filter='(&(sAMAccountName=' + sAMAccountName_repeace + ')(&(objectCategory=person)(objectClass=user)))', attributes=attributesldap) response = conn.response[0] attributesmodify = response.get('attributes', '') if attributesmodify: result.update(dict(attributesmodify)) result.update({'status': '修改成功'}) else: message_log = {'status': '没有查询到对象,或属性值传入有错'} insert_log_table_name('log_ldap', '172.0.0.1', 'ModifyUserThread_search', username, str(False), str(item), message_log, '') result.update(message_log) result.update(getDatato) else: message_log = {'status': '修改属性创建失败:sAMAccountName不能为空'} insert_log_table_name('log_ldap', '172.0.0.1', 'ModifyUserThread', username, str(False), str(item), message, '') result.update(message_log) result.update(getDatato) except Exception as e: result.update({'status': '用户创建失败:'+str(e)}) result.update(getDatato) modifyusermessage.append(result) self.queue.task_done()
def run(self): while True: # 需要通过循环来不断的运行任务 item = self.queue.get() getDatato = item[0] username = item[1] movetoou = item[2] objectClass = item[3] try: usermessage = {} result = {} if '' in getDatato: getDatato.pop('') if '0' in getDatato: getDatato.pop('0') if 'status' in getDatato: getDatato.pop('status') attributesldap = list(getDatato.keys()) if getDatato['sAMAccountName']: sAMAccountName_repeace = repeace_dn( getDatato['sAMAccountName']) if objectClass == 'user': search_filter = '(&(sAMAccountName=' + sAMAccountName_repeace + ')(&(objectCategory=person)(objectClass=user)))' elif objectClass == 'computer': search_filter = '(&(|(sAMAccountName=' + sAMAccountName_repeace + '$)(sAMAccountName=' + sAMAccountName_repeace + '))(&(objectClass=computer)))' else: search_filter = '(sAMAccountName=' + sAMAccountName_repeace + ')' with ldap3RESTARTABLE as conn: conn.search(search_base=ladp3search_base, search_filter=search_filter, attributes=attributesldap) response = conn.response[0] dn = response.get('dn', '') if dn: attributes = response.get('attributes', '') dn = repeace_dn(dn) relative_dn = dn.split(",")[0] new_superior = repeace_dn(movetoou) operation_id = conn.modify_dn( dn=dn, relative_dn=relative_dn, delete_old_dn=True, new_superior=new_superior) if operation_id: result.update(dict(attributes)) result.update({'status': '移动成功'}) else: result.update(dict(attributes)) result.update({'status': '移动失败'}) modify_dn_result = conn.result insert_log_table_name('log_ldap', '172.0.0.1', 'MoveUserThread', username, str(True), str(item), str(result), str(modify_dn_result)) else: message_log = {'status': '没有查询到对象,或属性值传入有错'} insert_log_table_name('log_ldap', '172.0.0.1', 'MoveUserThread_search', username, str(False), str(item), str(message_log), '') result.update(message_log) result.update(getDatato) else: message_log = {'status': '移动用户失败:sAMAccountName不能为空'} insert_log_table_name('log_ldap', '172.0.0.1', 'MoveUserThread', username, str(False), str(item), str(message_log), '') result.update(message_log) result.update(getDatato) except Exception as e: result.update({'status': '移动用户失败:' + str(e)}) result.update(getDatato) modifyusermessage.append(result) self.queue.task_done()
def run(self): while True: # 需要通过循环来不断的运行任务 item = self.queue.get() getDatato = item[0] username = item[1] radiovaule = item[2] pwdLastSet = item[3] add_passwd_count = item[4] add_passwd1 = item[5] try: result = {} if '' in getDatato: getDatato.pop('') if '0' in getDatato: getDatato.pop('0') attributesldap = list(getDatato.keys()) if getDatato['sAMAccountName']: sAMAccountName_repeace = repeace_dn( getDatato['sAMAccountName']) with ldap3RESTARTABLE as conn: conn.search( search_base=ladp3search_base, search_filter='(&(sAMAccountName=' + sAMAccountName_repeace + ')(&(objectCategory=person)(objectClass=user)))', attributes=['sAMAccountName', 'pwdLastSet']) response = conn.response[0] dn = response.get('dn', '') if dn: attributes = (response.get('attributes', '')) attributes['pwdLastSet'] = (utc2local( attributes['pwdLastSet'])).strftime( "%Y-%m-%d %H:%M:%S") if attributes[ 'pwdLastSet'] == '1601-01-01 08:00:00': attributes['pwdLastSet'] = 0 if radiovaule == '随机密码': passwd = getpwd(int(add_passwd_count)) elif radiovaule == '输入密码': passwd = add_passwd1 else: passwd = getDatato['password'] port = conn.server.port if int(port) == 636: modify_password = conn.extend.microsoft.modify_password( dn, passwd) if modify_password: if pwdLastSet == 'true' or (str( getDatato.get('pwdLastSet', 1)) == '0'): modify_dn = conn.modify( dn=dn, changes={ 'pwdLastSet': [(MODIFY_REPLACE, [0])] }) if modify_dn: message_log = { 'status': '密码修改成功并设置用户下次必须更改密码', 'pwdLastSet': 0 } else: message_log = { 'status': '密码修改成功,设置用户下次必须更改密码:失败', 'pwdLastSet': attributes['pwdLastSet'] } else: message_log = { 'status': '密码修改成功', 'pwdLastSet': attributes['pwdLastSet'] } else: message_log = { 'status': '密码修改:失败', 'pwdLastSet': attributes['pwdLastSet'] } result.update({ 'sAMAccountName': getDatato['sAMAccountName'], 'password': passwd }) result.update(message_log) insert_log_table_name('log_ldap', '172.0.0.1', 'ModifyUserThread', username, str(modify_password), str(item), message_log, '') else: message_log = { 'status': '修改密码LDAP必须采用加密连接,端口636,现在连接的端口:' + str(port) } result.update({ 'sAMAccountName': getDatato['sAMAccountName'] }) result.update(message_log) insert_log_table_name('log_ldap', '172.0.0.1', 'ModifyUserThread', username, str(False), str(item), message_log, '') else: message_log = { 'status': '密码修改:失败,根据sAMAccountName没有找到对象' } result.update({ 'sAMAccountName': getDatato['sAMAccountName'] }) result.update(message_log) insert_log_table_name('log_ldap', '172.0.0.1', 'ModifyUserThread', username, str(False), str(item), message_log, '') else: message_log = {'status': '密码修改失败:sAMAccountName不能为空'} insert_log_table_name('log_ldap', '172.0.0.1', 'ModifyUserThread', username, str(False), str(item), message_log, '') result.update(message_log) result.update(getDatato) except Exception as e: result.update({'status': '密码修改失败:' + str(e)}) result.update(getDatato) modifyusermessage.append(result) self.queue.task_done()
def run(self): while True: # 需要通过循环来不断的运行任务 item = self.queue.get() getDatato = item[0] username = item[1] maildb = item[2] mailarchive = item[3] mailarchivedb = item[4] try: usermessage = {} result = {} if '' in getDatato: getDatato.pop('') if '0' in getDatato: getDatato.pop('0') if 'status' in getDatato: getDatato.pop('status') attributesldap = list(getDatato.keys()) if getDatato['sAMAccountName']: sAMAccountName_repeace = repeace_dn( getDatato['sAMAccountName']) with ldap3RESTARTABLE as conn: conn.search( search_base=ladp3search_base, search_filter='(&(sAMAccountName=' + sAMAccountName_repeace + ')(&(objectCategory=person)(objectClass=user))(!(msExchHomeServerName=*))(!(mailNickname=*)))', attributes=attributesldap) response = conn.response[0] dn = response.get('dn', '') if dn: attributes = response.get('attributes', '') UserToExcs = UserToExc(sAMAccountName_repeace, maildb) if UserToExcs['isSuccess']: if mailarchive == 'true': EnableMailboxs = EnableMailbox( sAMAccountName_repeace, mailarchivedb) if EnableMailboxs['isSuccess']: message_log = { 'status': sAMAccountName_repeace + ':用户新建邮箱,并创建归档' } else: message_log = { 'status': sAMAccountName_repeace + ':用户新建邮箱成功,并创建归档失败:' + str(EnableMailboxs) } else: message_log = { 'status': sAMAccountName_repeace + ':用户新建邮箱' } else: message_log = { 'status': sAMAccountName_repeace + ':用户新建邮箱失败:' + str(UserToExcs) } result.update(dict(attributes)) result.update(message_log) insert_log_table_name('log_ldap', '172.0.0.1', 'CrearMailThread', username, str(True), str(item), str(result), '') else: message_log = {'status': '没有查询到对象,或属性值传入有错'} insert_log_table_name('log_ldap', '172.0.0.1', 'CrearMailThread_search', username, str(False), str(item), str(message_log), '') result.update(message_log) result.update(getDatato) else: message_log = {'status': '移动用户失败:sAMAccountName不能为空'} insert_log_table_name('log_ldap', '172.0.0.1', 'CrearMailThread', username, str(False), str(item), str(message_log), '') result.update(message_log) result.update(getDatato) except Exception as e: result.update({'status': '移动用户失败:' + str(e)}) result.update(getDatato) modifyusermessage.append(result) self.queue.task_done()