def purge_removed_computers(): from mmc.plugins.base.computers import ComputerManager from mmc.plugins.base import LdapUserGroupControl # Get all imaging targets targets = ImagingDatabase().getAllRegisteredComputers() # Creating root context to query ComputerManager ctx = SecurityContext() ctx.userid = 'root' ctx.userdn = LdapUserGroupControl().searchUserDN(ctx.userid) # Init to_delete computer list to_delete = [] for uuid in targets: if ComputerManager().getComputerCount(ctx, {'uuid': uuid}) == 0: # If the target computer is not in ComputerManager database anymore # we unregister it from imaging to_delete.append(uuid) # Unregistering orphan targets without backup if to_delete: logging.getLogger().info('Orphan imaging computer(s) found') logging.getLogger().info('Going to purge %s' % ' '.join(to_delete)) computersUnregister(to_delete, False) return True
def getInformations(self, dynamic = False): from mmc.plugins.base import ComputerManager, LdapUserGroupControl if not self.config.is_subscribe_done: return { 'is_subsscribed': False } ret = { 'is_subsscribed':True, 'product_name':self.config.subs_product_name, 'vendor_name':self.config.subs_vendor_name, 'vendor_mail':self.config.subs_vendor_mail, 'customer_name':self.config.subs_customer_name, 'customer_mail':self.config.subs_customer_mail, 'comment':self.config.subs_comment, 'users':self.config.subs_users, 'upgrade_url':self.config.subs_upgrade_url, 'computers':self.config.subs_computers, 'support_mail':self.config.subs_support_mail, 'support_phone':self.config.subs_support_phone, 'support_comment':self.config.subs_support_comment } if dynamic: # Don't count SAMBA admin and nobody users userCount = 0 users = LdapUserGroupControl().search(searchFilter="(&(uid=*)(objectClass=inetOrgPerson))", attrs=["uid", "gidNumber"]) for user in users: try: user = user[0][1] if (('uid' in user and not user['uid'] == ['nobody']) and ('gidNumber' in user and not user['gidNumber'] == ['512'])): userCount += 1 except: pass # we add the number of user and computers we have right now ret['installed_users'] = userCount ret['too_much_users'] = (ret['users'] > 0 and ret['installed_users'] > ret['users']) if ComputerManager().isActivated(): ret['installed_computers'] = ComputerManager().getTotalComputerCount() else: ret['installed_computers'] = 0 ret['too_much_computers'] = (ret['computers'] and ret['installed_computers'] > ret['computers']) return ret
def getContext(self): s = SecurityContext() s.userid = self.userid s.userdn = LdapUserGroupControl().searchUserDN(self.userid) return s
def getContext(self, user='******'): s = SecurityContext() s.userid = user s.userdn = LdapUserGroupControl().searchUserDN(s.userid) return s
def mmc_change_password(login, password): if existUser(login): LdapUserGroupControl().changeUserPasswd(login, password)