def reset_password(self, username): userInfo = self.findUser(username) userDN = userInfo[0] if not userDN: return False new_password = GeneratePassword(10) c.new_account = False c.username = userInfo[1]['uid'][0] c.password = new_password if self.update_attribute( userDN, 'userPassword', new_password): send_email(render('email/ldap_account.mako'), 'Password reset request', email_to=userInfo[1]['mail']) return new_password else: return None
def reset_password(self, username): userInfo = self.findUser(username) userDN = userInfo[0] if not userDN: return False new_password = GeneratePassword(10) c.new_account = False c.username = userInfo[1]['uid'][0] c.password = new_password if self.update_attribute(userDN, 'userPassword', new_password): send_email(render('email/ldap_account.mako'), 'Password reset request', email_to=userInfo[1]['mail']) return new_password else: return None
def EmailDiffs(self, prod_config, staging_config, email_from='admin@yourdomain', email_to=['email_user@yourdomain']): prod_config = prod_config.splitlines(1) staging_config = staging_config.splitlines(1) diff = ''.join(unified_diff(prod_config, staging_config, 'production', 'staging')) diff = diff.replace('\n', '<br />') diff = diff.replace(' ', '  ') return send_email( 'Cotendo Updates:<br />%s' % diff, 'Cotendo DNS Update', email_from, email_to)
def EmailDiffs(self, prod_config, staging_config, email_from='admin@yourdomain', email_to=['email_user@yourdomain']): prod_config = prod_config.splitlines(1) staging_config = staging_config.splitlines(1) diff = ''.join( unified_diff(prod_config, staging_config, 'production', 'staging')) diff = diff.replace('\n', '<br />') diff = diff.replace(' ', '  ') return send_email('Cotendo Updates:<br />%s' % diff, 'Cotendo DNS Update', email_from, email_to)
def create(self, username, full_name, email, shell='/bin/bash', title='', manager='', departmentNumber='', roomNumber='', deploycode = 'false', orgchartmanager = 'false', utilityaccount = 'false'): username = str(username) full_name = str(full_name) email = str(email) shell = str(shell) title = str(title) manager = str(manager) departmentNumber = str(departmentNumber) roomNumber = str(roomNumber) deploycode = str(deploycode) orgchartmanager = str(orgchartmanager) utilityaccount = str(utilityaccount) attrs = {} attrs['objectClass'] = [ 'top', 'posixAccount', 'person', 'organizationalPerson', 'inetOrgPerson', 'yourdomain', 'extensibleobject'] attrs['uid'] = username attrs['cn'] = full_name namesplit = full_name.split() if len(namesplit) == 2: attrs['givenName'] = namesplit[0] attrs['sn'] = namesplit[1] elif len(namesplit) == 1: attrs['givenName'] = namesplit[0] attrs['sn'] = '' else: attrs['givenName'] = '' attrs['sn'] = '' attrs['mail'] = email attrs['homeDirectory'] = '/home/%s' % username attrs['loginShell'] = shell attrs['gidNumber'] = '1008' attrs['uidNumber'] = str(int(self.last_uid) + 1) attrs['nsAccountLock'] = 'false' # YourDomain object attrs['title'] = title attrs['manager'] = manager attrs['departmentNumber'] = departmentNumber attrs['roomNumber'] = roomNumber attrs['deploycode'] = deploycode attrs['orgchartmanager'] = orgchartmanager attrs['utilityaccount'] = utilityaccount ldif = modlist.addModlist(attrs) self.connection.add_s('uid=%s' % username+','+_baseDN, ldif) c.new_account = True c.full_name = full_name c.username = username c.password = GeneratePassword(10) # Create the vpn-client for that user if utilityaccount == 'false': run_ssh_command('vpn_machine', './vpn-client.sh %s' % username) # Send Welcome Email self.update_attribute( 'uid=%s' % username+','+_baseDN, 'userPassword', c.password) if attrs['mail']: try: send_email(render('email/ldap_account.mako'), 'Welcome to Yourdomain!', email_to=attrs['mail']) except Exception as e: print e
def create(self, username, full_name, email, shell='/bin/bash', title='', manager='', departmentNumber='', roomNumber='', deploycode='false', orgchartmanager='false', utilityaccount='false'): username = str(username) full_name = str(full_name) email = str(email) shell = str(shell) title = str(title) manager = str(manager) departmentNumber = str(departmentNumber) roomNumber = str(roomNumber) deploycode = str(deploycode) orgchartmanager = str(orgchartmanager) utilityaccount = str(utilityaccount) attrs = {} attrs['objectClass'] = [ 'top', 'posixAccount', 'person', 'organizationalPerson', 'inetOrgPerson', 'yourdomain', 'extensibleobject' ] attrs['uid'] = username attrs['cn'] = full_name namesplit = full_name.split() if len(namesplit) == 2: attrs['givenName'] = namesplit[0] attrs['sn'] = namesplit[1] elif len(namesplit) == 1: attrs['givenName'] = namesplit[0] attrs['sn'] = '' else: attrs['givenName'] = '' attrs['sn'] = '' attrs['mail'] = email attrs['homeDirectory'] = '/home/%s' % username attrs['loginShell'] = shell attrs['gidNumber'] = '1008' attrs['uidNumber'] = str(int(self.last_uid) + 1) attrs['nsAccountLock'] = 'false' # YourDomain object attrs['title'] = title attrs['manager'] = manager attrs['departmentNumber'] = departmentNumber attrs['roomNumber'] = roomNumber attrs['deploycode'] = deploycode attrs['orgchartmanager'] = orgchartmanager attrs['utilityaccount'] = utilityaccount ldif = modlist.addModlist(attrs) self.connection.add_s('uid=%s' % username + ',' + _baseDN, ldif) c.new_account = True c.full_name = full_name c.username = username c.password = GeneratePassword(10) # Create the vpn-client for that user if utilityaccount == 'false': run_ssh_command('vpn_machine', './vpn-client.sh %s' % username) # Send Welcome Email self.update_attribute('uid=%s' % username + ',' + _baseDN, 'userPassword', c.password) if attrs['mail']: try: send_email(render('email/ldap_account.mako'), 'Welcome to Yourdomain!', email_to=attrs['mail']) except Exception as e: print e