def genpwd(): if get_management_configuration(): pwdlengt = get_management_configuration()['lengthpwd'] else: pwdlengt = 4 password = [] password.append(randomChoice(passData)) password.append(randomChoice(passData1)) password.append(randomChoice(passData2)) password.append(randomChoice(passData3)) for i in range(int(pwdlengt) - 4): password.append(randomChoice(seed)) salt = ''.join(password) # x = 0 # p = '' # while x != len(password): # p = p + str(password[x]) # x += 1 return salt
def showmailpumangaer(request): log = logmanager() username = request.session.get('username') try: pubmes = get_management_configuration() mess = adapi().postapi( 'GetUserFromLdap', ldaps='(&(objectCategory=person)(objectClass=user)(mail=*) (' + pubmes['pubmailfence'] + '=' + username + '))', path=pubmes['pubmailou']) temptable = [] if mess['isSuccess']: for i in mess['message']: if i.get('useraccountcontrol', ['None'])[0] == 514 or i.get( 'useraccountcontrol', ['None'])[0] == 546 or i.get( 'useraccountcontrol', ['None'])[0] == 4130 or i.get( 'useraccountcontrol', ['None'])[0] == 4198: pass else: mangefenc = pubmes['pubmailfence'].lower() lastpwd = adapi().Initialapi( 'GetobjectProperty', objects=i['samaccountname'][0], objectClass='user') temptable.append({ 'samaccountname': i.get('samaccountname', ['None'])[0], 'physicaldeliveryofficename': i.get(mangefenc, ['None'])[0], 'displayname': i.get('displayname', ['None'])[0], 'mail': i.get('mail', ['None'])[0], 'PasswordExpirationDate': lastpwd['message'][0].get('PasswordExpirationDate', 'None') }) except Exception as e: log.log(returnid=1, username=username, message=username + "登录获取公共邮箱管理者账号信息", returnparameters=str(e), issuccess=1, methodname="showmailpumangaer", types="exchange") print(e) result = {'status': temptable} response = HttpResponse() response['Content-Type'] = "text/javascript" response.write(json.dumps(result)) return response
def pwdremindertips(request): post = request.POST try: tab = get_management_configuration()['pwdremindertips'] if tab == '' or tab == None or tab == "false": status = False else: status = True except Exception as e: status = False result = {'status': status} response = HttpResponse() response['Content-Type'] = "text/javascript" response.write(json.dumps(result)) return response
def __init__(self): management_configuration = get_management_configuration() self.dfs_api = management_configuration.get("dfs_api", "") self.dfs_manager = management_configuration.get("dfs_manager", "") self.dfs_group = management_configuration.get("dfs_group", "") self.Basic_authority = management_configuration.get( "Basic_authority", "") self.AD_time = management_configuration.get("AD_time", "") mysqlallvalue = dbinfo_select_global_configuration() if mysqlallvalue: mysqlallvalue = mysqlallvalue[0] self.addomain = str(mysqlallvalue['ad_domain']) self.exdomain = str(mysqlallvalue['ex_domain']) self.dict = setkey() self.signature = self.dict.get("signature", '') self.timestamp = self.dict.get("timestamp", '') self.nonce = self.dict.get("nonce", '')
def basisite(request): username = request.session.get('username') displayname = request.session.get('displayname') try: message = searchsendmail() mangerapiin = get_api('process') mangermess = genmangemessage() phonemess = genmuser() messagesend = sendmeasage() confmess = getconfiguration() titleshowmessage = shwotitle() if mangermess == None or mangermess == False: mangermess = 'fasle' elif mangermess['status'] == '0': mangermshow = genmangemessageshow() else: apiurl = genmangeurl() if phonemess == None or phonemess == False: phonemess = 'fasle' if messagesend == None or messagesend == False: messagesend = 'fasle' if message == None or message == False: message = 'fasle' if confmess == () or confmess == False: confstatus = 'fasle' elif confmess[0]['internet_group'] == None or confmess[0][ 'internet_group'] == 'None': confstatus = 'fasle' else: confmess = get_management_configuration() net = ast.literal_eval(confmess['internet_group']) wifi = ast.literal_eval(confmess['wifi_group']) vpn = ast.literal_eval(confmess['vpn_group']) except Exception as e: print(e) return render_to_response('admin/basisite.html', locals())
def senduserpassword(): try: tab = get_management_configuration()['pwdremindertips'] if tab == '' or tab == None or tab == "false": status = False else: status = True mysqlallvalue = dbinfo_select_global_configuration()[0] ad_domain = mysqlallvalue['ad_path'] if ad_domain != '' and ad_domain != None and ad_domain != "None": alluserdatetimevalue = adapi().postapi( 'GetUserpasswordexpirationdate', ldaps='(&(objectCategory=person)(objectClass=user))', path=ad_domain, Properties=["sAMAccountName", "passwordexpirationdate"]) shisidaysvalue = list() qidaysvalue = list() sandaysvalue = list() erdaysvalue = list() yidaysvalue = list() lingdaysvalue = list() if alluserdatetimevalue['isSuccess']: if alluserdatetimevalue['Count'] != 0: rows = list() li = [] for i in alluserdatetimevalue['message']: t = senduserpassword_agree_class( i['samaccountname'][0], i['passwordexpirationdate'][0]) li.append(t) t.start() for t in li: t.join() thrreturnvalue = t.senduserpassword_thr() if thrreturnvalue: if thrreturnvalue['mail'] != None: if thrreturnvalue['differencedays'] == 14: shisidaysvalue.append( thrreturnvalue['mail']) elif thrreturnvalue['differencedays'] == 7: qidaysvalue.append( thrreturnvalue['mail']) elif thrreturnvalue['differencedays'] == 3: sandaysvalue.append( thrreturnvalue['mail']) elif thrreturnvalue['differencedays'] == 2: erdaysvalue.append( thrreturnvalue['mail']) elif thrreturnvalue['differencedays'] == 1: yidaysvalue.append( thrreturnvalue['mail']) # elif thrreturnvalue['differencedays'] ==0: # lingdaysvalue.append(thrreturnvalue['mail']) subject = u'密码即将过期提醒' emaillists14 = "你的开机(邮箱)密码还有 14 天过期,请及时更改!" emaillists7 = "你的开机(邮箱)密码还有 7 天过期,请及时更改!" emaillists3 = "你的开机(邮箱)密码还有 3 天过期,请及时更改!" emaillists2 = "你的开机(邮箱)密码还有 2 天过期,请及时更改!" emaillists1 = "你的开机(邮箱)密码还有 1 天过期,请及时更改!" # emaillists0 = "你的开机(邮箱)密码还有 0 天过期,请及时更改!" email_data14 = {'emaillists': emaillists14} email_data7 = {'emaillists': emaillists7} email_data3 = {'emaillists': emaillists3} email_data2 = {'emaillists': emaillists2} email_data1 = {'emaillists': emaillists1} # email_data0 = {'emaillists': emaillists0} template = "mailmould/sendmailpassword.html" to_list14 = shisidaysvalue to_list7 = qidaysvalue to_list3 = sandaysvalue to_list2 = erdaysvalue to_list1 = yidaysvalue to_list0 = lingdaysvalue send_email_by_template(subject, template, email_data14, to_list14) send_email_by_template(subject, template, email_data7, to_list7) send_email_by_template(subject, template, email_data3, to_list3) send_email_by_template(subject, template, email_data2, to_list2) send_email_by_template(subject, template, email_data1, to_list1) except Exception as e: pass return 1
def userindexvalueshow(request): log = logmanager() username = request.session.get('username') displayname = request.session.get('displayname') ip = request.META.get('HTTP_X_FORWARDED_FOR', request.META['REMOTE_ADDR']) isSuccess = False message = {} if username: try: uservalue = adapi().Initialapi("GetobjectProperty", objects=username, objectClass="user") if uservalue['isSuccess']: userdisplayname = uservalue['message'][0]['displayName'] usermail = uservalue['message'][0]['mail'] PasswordExpirationDate = uservalue['message'][0][ 'PasswordExpirationDate'] usermemberof = uservalue['message'][0]['memberof'] usermemberoflist = list() usermemberoflastlist = list() userip = ip strtype = "" listtype = list() if type(usermemberof) == type(strtype) or type( usermemberof) == type(listtype): if type(usermemberof) == type(strtype): usermemberoflist.append(usermemberof) else: usermemberoflist = usermemberof li = list() rows = list() for i in usermemberoflist: t = MyThread(i) li.append(t) t.start() for t in li: t.join() usermemberoflastlist.append(t.get_result()) usermaillist = list() userinternetlist = list() userwifilist = list() uservpnlist = list() for i in usermemberoflastlist: if i['mail'] != None: usermaillist.append({ "displayname": i['displayName'], "mail": i['mail'] }) internet_group = ast.literal_eval( get_management_configuration()['internet_group']) for internet_group_one in internet_group: if internet_group_one['name'].lower( ) == i['sAMAccountName'].lower(): userinternetlist.append( internet_group_one['description']) wifi_group = ast.literal_eval( get_management_configuration()['wifi_group']) for wifi_group_one in wifi_group: if wifi_group_one['name'].lower( ) == i['sAMAccountName'].lower(): userwifilist.append(wifi_group_one['description']) vpn_group = ast.literal_eval( get_management_configuration()['vpn_group']) for vpn_group_one in vpn_group: if vpn_group_one['name'].lower( ) == i['sAMAccountName'].lower(): uservpnlist.append(vpn_group_one['description']) isSuccess = True message = { "userdisplayname": userdisplayname, "usermail": usermail, "usermaillist": usermaillist, "userinternetlist": userinternetlist, "userwifilist": userwifilist, "uservpnlist": uservpnlist, "ip": ip, "PasswordExpirationDate": PasswordExpirationDate } except Exception as e: isSuccess = False message = {} result = {'isSuccess': isSuccess, "message": message} return HttpResponse(json.dumps(result, cls=DatetimeEncoder), content_type="application/json") else: return HttpResponseRedirect('/', request)
def run(self): try: process = get_api("process") director_account_list = [] for i in range(len(self.account_list) - 1): username = self.account_list[i] if username: GetobjectPropertys = GetobjectProperty(username, 'user', self.domain, tokenid=None, ip=None) if GetobjectPropertys['isSuccess']: displayName = GetobjectPropertys['message'][0].get( 'displayName', '') else: displayName = "" #获取treeid 和需要添加的权限组 treelists = self.level_id_list[i].split('-') treeids = showtreeid(treelists[0], treelists[1], treelists[2]) tree_id = treeids.get('tree_id', '') group_name = showgroupname(tree_id, self.read_m_list[i]).get( "group_name", '') #根据AD账号获取主管,AD ,姓名,邮箱 manger = getmanger(username, "dfsmanger") get_management_configurations = get_management_configuration( ) if process: director_name = "系统" director_account = "系统" director_mail = "系统" else: if manger: director_account = manger mangervalue = adapi().Initialapi( "GetobjectProperty", objects=manger, objectClass="user") if mangervalue['isSuccess']: director_mail = mangervalue['message'][0].get( "mail", '') director_name = mangervalue['message'][0].get( "displayName", '') else: director_name = get_management_configurations.get( 'dfs_relation_name', '') director_account = get_management_configurations.get( 'dfs_relation', '') director_mail = get_management_configurations.get( 'dfs_relation_mail', '') else: director_name = get_management_configurations.get( 'dfs_relation_name', '') director_account = get_management_configurations.get( 'dfs_relation', '') director_mail = get_management_configurations.get( 'dfs_relation_mail', '') # 根据 level2_id 查找文件夹管理员 ,如果没有则使用默认 relations = show_level2name(treelists[1]) level2_manager_name = relations.get( 'level2_manager_name', '') level2_manager = relations.get('level2_manager', '') level2_manager_mail = relations.get( 'level2_manager_mail', '') if not level2_manager: level2_manager_name = get_management_configurations.get( 'dfs_relation_name', '') level2_manager = get_management_configurations.get( 'dfs_relation', '') level2_manager_mail = get_management_configurations.get( 'dfs_relation_mail', '') now = datetime.now().strftime('%Y-%m-%d %H:%M:%S') if tree_id and group_name and director_account and level2_manager: #确认数据无错,插数据库 flowidcounts = checkflow(username, group_name) # 检查flow表是否有相同数据 if flowidcounts['counts'] == 0: add_dfs_flows = add_dfs_flow( username, displayName, treeids['tree_id'], group_name, now, director_name, director_account, level2_manager_name, level2_manager, 0, self.adusername) #添加 if process and add_dfs_flows: value = { "status": 0, "message": { "id": add_dfs_flows['id'], "username": username, "displayname": displayName, "types": "DFS", "applytype": "申请文件夹权限", "applydetail": group_name } } process_outgoing(value) director_account_list.append( [director_account, director_mail]) if not process: for x in director_account_list: while director_account_list.count(x) > 1: del director_account_list[director_account_list.index( x)] # 去除director_account 的重复项\ # 发送邮件 for i in range(len(director_account_list)): emaillists = showmyemailflowdir( director_account_list[i][0]) #根据主管AD 账号获取工单 sendnumber = len(emaillists) if sendnumber > 0: subject = u'文件夹权限_主管审批' email_data = { 'emaillists': emaillists, 'username': self.adusername } template = "dfsweb/common/directoremail.html" if director_account_list[i][1]: to_list = [ director_account_list[i][1], ] send_email_by_template(subject, template, email_data, to_list) # 微信发送申请信息给主管 # sendjobnumber = oalistslist[i][3] # sendmsg = '您有%' % (sendnumber) + '\n' + '请您登陆平台进行审批' # sendwechat(sendjobnumber, sendmsg) except Exception as e: print(e)