48 lines
1.1 KiB
Python
Executable file
48 lines
1.1 KiB
Python
Executable file
#!/bin/bash /usr/scripts/python.sh
|
|
|
|
import pika
|
|
import json
|
|
import sys
|
|
|
|
from lc_ldap.shortcuts import lc_ldap_readonly
|
|
from affich_tools import prompt
|
|
import lc_ldap.filter2 as filter
|
|
import config
|
|
|
|
rabbit_c = pika.BlockingConnection(config.PARAMS)
|
|
ch = rabbit_c.channel()
|
|
ch.queue_declare('CransTicket')
|
|
|
|
ldap = lc_ldap_readonly()
|
|
|
|
|
|
f = filter.human_to_ldap(sys.argv[1].decode('utf-8'))
|
|
adh = ldap.search(f)
|
|
if len(adh) > 1:
|
|
print "More than one result"
|
|
exit()
|
|
elif not adh:
|
|
print "Nobody"
|
|
else:
|
|
adh = adh[0]
|
|
adh.display()
|
|
while True:
|
|
c = prompt("[O/N]").lower()
|
|
if c == 'n':
|
|
exit()
|
|
elif c == 'o':
|
|
break
|
|
|
|
m = adh.machines()
|
|
|
|
to_print = []
|
|
for machine in m:
|
|
if u'<automatique>' in machine['macAddress']:
|
|
continue
|
|
login = machine['host'][0].split('.', 1)[0]
|
|
todo = {'login': login, 'macAddress': machine['macAddress'][0].value}
|
|
if machine.has_key('ipsec'):
|
|
todo['secret'] = machine['ipsec'][0].value
|
|
to_print.append(todo)
|
|
|
|
ch.basic_publish(exchange='', routing_key='CransTicket', body=json.dumps(to_print))
|