|
34 |
|
34 |
|
35 |
from __future__ import print_function |
35 |
from __future__ import print_function |
36 |
|
36 |
|
37 |
import ldap |
|
|
38 |
from ldap.filter import filter_format |
37 |
from ldap.filter import filter_format |
39 |
import sys |
38 |
import sys |
40 |
|
39 |
|
|
|
40 |
import univention.admin.uldap as uldap |
41 |
import univention.config_registry |
41 |
import univention.config_registry |
42 |
|
42 |
|
43 |
ucr = univention.config_registry.ConfigRegistry() |
43 |
ucr = univention.config_registry.ConfigRegistry() |
44 |
ucr.load() |
44 |
ucr.load() |
45 |
|
45 |
|
46 |
baseDN = ucr['ldap/base'] |
|
|
47 |
|
48 |
if ucr['interfaces/eth0/netmask'] != "255.255.0.0": |
46 |
if ucr['interfaces/eth0/netmask'] != "255.255.0.0": |
49 |
print('Only for Class B') |
47 |
print('Only for Class B') |
50 |
sys.exit(1) |
48 |
sys.exit(1) |
51 |
|
49 |
|
52 |
lo = ldap.open('localhost', 7389) |
50 |
lo, position = uldap.getAdminConnection() |
53 |
bindpw = open('/etc/ldap.secret').read() |
51 |
ldap_base = position.getBase() |
54 |
if bindpw[-1] == '\n': |
|
|
55 |
bindpw = bindpw[0:-1] |
56 |
lo.simple_bind_s("cn=admin," + baseDN, bindpw) |
57 |
|
52 |
|
58 |
computers = lo.search_s(baseDN, ldap.SCOPE_SUBTREE, 'objectClass=univentionHost', ['aRecord']) |
53 |
computers = lo.search('objectClass=univentionHost', attr=['aRecord'], base=ldap_base) |
59 |
|
54 |
|
60 |
for i in range(0, len(computers)): |
55 |
for dn, attribute in computers: |
61 |
print('DN: %s' % computers[i][0]) |
56 |
print('DN: %s' % dn) |
62 |
if 'aRecord' in computers[i][1]: |
57 |
entry = attribute['aRecord'][0].split(b'.')[2:4] |
63 |
entry = computers[i][1]['aRecord'][0].split('.')[2:4] |
58 |
reverse = lo.search( |
64 |
reverse = lo.search_s('cn=dns,%s' % baseDN, ldap.SCOPE_SUBTREE, filter_format('(&(relativeDomainName=%s)(pTRRecord=%s*))', ('.'.join(entry), ldap.explode_dn(computers[i][0], 1)[0]))) |
59 |
filter_format('(&(relativeDomainName=%s)(pTRRecord=%s*))', |
65 |
if len(reverse) != 0: |
60 |
(b'.'.join(entry).decode('utf-8'), |
66 |
print('Wrong DNS Reverse Entry for %s: %s' % (computers[i][0], reverse[0][0])) |
61 |
ucr.get('hostname'))), |
67 |
entry.reverse() |
62 |
base='cn=dns,%s' % ldap_base, |
68 |
entry = '.'.join(entry) |
63 |
) |
69 |
lo.modrdn_s(reverse[0][0], 'relativeDomainName=%s' % entry) |
64 |
if len(reverse) != 0: |
|
|
65 |
print('Wrong DNS Reverse Entry for %s: %s' % (dn, reverse[0][0])) |
66 |
entry.reverse() |
67 |
entry = '.'.join(entry).decode('utf-8') |
68 |
lo.modrdn_s(reverse[0][0], 'relativeDomainName=%s' % entry) |