- print;
-if (BindUser != ""):
- Password = getpass(BindUser + "'s password: ");
-
-# Connect to the ldap server
-l = ldap.open(LDAPServer);
-UserDn = "uid=" + BindUser + "," + BaseDn;
-if (BindUser != ""):
- l.simple_bind_s(UserDn,Password);
-else:
- l.simple_bind_s("","");
-
-HBaseDn = "ou=hosts,dc=debian,dc=org";
-HostDn = "host=" + Host + "," + HBaseDn;
+ l = connectLDAP()
+ l.simple_bind_s("","")
+
+if ListMode == 1:
+ Attrs = l.search_s(HostBaseDn,ldap.SCOPE_ONELEVEL,"host=*")
+ hosts = []
+ for hAttrs in Attrs:
+ hosts.append(hAttrs[1]['host'][0])
+ hosts.sort()
+
+ print "%-12s %-10s %-38s %-25s %s" % ("Host name","Arch","Distribution","Access","Status")
+ print "-"*115
+ for host in hosts:
+ for hAttrs in Attrs:
+ if host == hAttrs[1]['host'][0]:
+ Overview(hAttrs)
+ sys.exit(0)
+elif FingerPrints == 1:
+ if Host is not None:
+ Attrs = l.search_s(HostBaseDn,ldap.SCOPE_ONELEVEL,"host=" + Host)
+ else:
+ Attrs = l.search_s(HostBaseDn,ldap.SCOPE_ONELEVEL,"host=*")
+ hosts = []
+ for hAttrs in Attrs:
+ hosts.append(hAttrs[1]['host'][0])
+ hosts.sort()
+
+ for host in hosts:
+ for hAttrs in Attrs:
+ if host == hAttrs[1]['host'][0]:
+ if 'sshRSAHostKey' in hAttrs[1].keys():
+ for key in hAttrs[1]['sshRSAHostKey']:
+ keygen = subprocess.Popen(['/usr/bin/ssh-keygen', '-l', '-f', '-'],
+ stdin=subprocess.PIPE, stdout=subprocess.PIPE)
+ keygen.stdin.write(key + '\n')
+ keygen.stdin.close()
+ input = keygen.stdout.readline()
+ keygen.wait()
+ fingerprint = input.split(' ')
+ print "%s %s root@%s" % (fingerprint[0], fingerprint[1], host)
+ sys.exit(0)
+
+HostDn = "host=" + Host + "," + HostBaseDn