Esempio n. 1
0
 def update_dnsRecord(self): 
     """
     update the clienthost's IPv6 and IPv4 records in the DNS-ldap-backend ;)
    
     got modify example from:
     http://www.packtpub.com/article/python-ldap-applications-more-ldap-operations-and-the-ldap-url-library
     thanks.
     """
     logging.debug("writing AAAA, lastSeen and A record for%s back to DNS.", self.userID)
     ip = func.get_local_ip()
     ipv6 = func.get_local_ipv6()
     time = nowstr()
     if not ip:
         logging.error('Host has no ip')
         return False
     if not ipv6:
         #logging.warning('Host has no ipv6.')
         #return False
         logging.info('Host has no ipv6')
     if not time:
         logging.error('Host has no clock')
         return False
    	#removed till ipv6 is deployed.
     #mod_attr = [( ldap.MOD_REPLACE, 'aAAARecord', ipv6 ),
     mod_attr = [( ldap.MOD_REPLACE, 'aRecord', ip),
                 ( ldap.MOD_REPLACE, 'lastSeen', time )]
     try:
         return self.conn.modify_s(self.userID, mod_attr)
     except ldap.INSUFFICIENT_ACCESS:
         logging.critical("%s HAS INSUFFICIENT_ACCESS (write) to ldap directory server, please contact the URZ about this issue !", self.userID )
         return False
     logging.info('updated DNS record for %s', self.userID)
     return True
Esempio n. 2
0
    def add_host(self, hostname=None, target=None, classes=None, **args):
        """
        @see UniDomain.Classes.db#add_host
        """
        # some prechecks
        if not classes: classes = []
        if not target: target = self.home[0]
        if not hostname: hostname = func.getlocalhostname()
        shortname = hostname.split('.')[0]
        if len(self.home) == 0:
            logging.warning(
                '%s does not have enough rights to add hosts to the database',
                self.userID)
            return False

        # setup host object
        host_dn = 'cn=%s,%s' % (shortname, target
                                )  # we use first home dn as target container
        #FIXME: I dont like this krb5-dependancy...
        host_usid = 'host/%s@%s' % (hostname, self.config.krb5realm)
        logging.debug('using %s as usid', host_usid)
        if len(self.list_hosts(hostname)) > 0:
            logging.warning('Host %s already exists. Not changing.', hostname)
            return True
        logging.debug('Looks good. Adding %s to %s', hostname, target)
        host_data = [
            ('cn', shortname),
            ('udSerial', '%i' % self.next_udSerial()),
            ('lastSeen', nowstr()),
            ('objectClass', ['top', 'dNSZone', 'udHost']),
            ('relativeDomainName', shortname),
            ('zoneName', self.config.dnszone),
            ('dNSTTL', '3600'),
            ('dNSClass', 'IN'),
            ('ARecord', func.get_local_ip()),
            ('FQDN', hostname),
            ('USID', host_usid),
            ('description', 'new registered host object'),
        ]
        ipv6 = func.get_local_ipv6()
        if ipv6:
            host_data.append(('aAAARecord', ipv6))
        if len(classes) > 0:
            host_data.append(('udGroup', classes))
        try:
            self.conn.result(self.conn.add(host_dn, host_data))
            # add policies
            queries = [
                self.conn.add(
                    'cn=%s,%s' % (policy, host_dn),
                    [('objectClass', ['top', 'udPolicy']), args[policy]])
                for policy in args
            ]
            [self.conn.result(query) for query in queries]
        except Exception, err:
            logging.warning('add_host(): Trouble adding to ldap.\n%s',
                            str(err))
            return False
Esempio n. 3
0
    def add_host(self, hostname = None, target = None, classes = None, **args):
        """
        @see UniDomain.Classes.db#add_host
        """
        # some prechecks
        if not classes: classes = []
        if not target: target = self.home[0]
        if not hostname: hostname = func.getlocalhostname()
        shortname = hostname.split('.')[0]
        if len(self.home) == 0:
            logging.warning('%s does not have enough rights to add hosts to the database', self.userID)
            return False

        # setup host object
        host_dn = 'cn=%s,%s' % (shortname, target) # we use first home dn as target container
        #FIXME: I dont like this krb5-dependancy...
        host_usid = 'host/%s@%s' % (hostname, self.config.krb5realm)
        logging.debug('using %s as usid', host_usid)
        if len(self.list_hosts(hostname)) > 0:
            logging.warning('Host %s already exists. Not changing.', hostname)
            return True
        logging.debug('Looks good. Adding %s to %s', hostname, target)
        host_data = [
            ('cn', shortname),
            ('udSerial', '%i' % self.next_udSerial()),
            ('lastSeen', nowstr()),
            ('objectClass', ['top', 'dNSZone', 'udHost']),
            ('relativeDomainName', shortname),
            ('zoneName', self.config.dnszone),
            ('dNSTTL', '3600'),
            ('dNSClass', 'IN'),
            ('ARecord', func.get_local_ip()),
            ('FQDN', hostname),
            ('USID', host_usid),
            ('description', 'new registered host object'),
        ]
        ipv6 = func.get_local_ipv6()
        if ipv6:
            host_data.append(('aAAARecord', ipv6))
        if len(classes) > 0:
            host_data.append(('udGroup', classes))
        try:
            self.conn.result(self.conn.add(host_dn, host_data))
            # add policies
            queries = [
                self.conn.add(
                    'cn=%s,%s' % (policy, host_dn), 
                    [('objectClass', ['top','udPolicy']),args[policy]]
                )  
                for policy in args
            ]
            [
                self.conn.result(query)   
                for query in queries
            ]
        except Exception, err:
            logging.warning('add_host(): Trouble adding to ldap.\n%s', str(err))
            return False
Esempio n. 4
0
    def update_dnsRecord(self):
        """
        update the clienthost's IPv6 and IPv4 records in the DNS-ldap-backend ;)
       
        got modify example from:
        http://www.packtpub.com/article/python-ldap-applications-more-ldap-operations-and-the-ldap-url-library
        thanks.
        """
        logging.debug("writing AAAA, lastSeen and A record for%s back to DNS.",
                      self.userID)
        ip = func.get_local_ip()
        ipv6 = func.get_local_ipv6()
        time = nowstr()
        if not ip:
            logging.error('Host has no ip')
            return False
        if not ipv6:
            #logging.warning('Host has no ipv6.')
            #return False
            logging.info('Host has no ipv6')
        if not time:
            logging.error('Host has no clock')
            return False

    #removed till ipv6 is deployed.
    #mod_attr = [( ldap.MOD_REPLACE, 'aAAARecord', ipv6 ),
        mod_attr = [(ldap.MOD_REPLACE, 'aRecord', ip),
                    (ldap.MOD_REPLACE, 'lastSeen', time)]
        try:
            return self.conn.modify_s(self.userID, mod_attr)
        except ldap.INSUFFICIENT_ACCESS:
            logging.critical(
                "%s HAS INSUFFICIENT_ACCESS (write) to ldap directory server, please contact the URZ about this issue !",
                self.userID)
            return False
        logging.info('updated DNS record for %s', self.userID)
        return True