From 076d667d34a33d45498066d8c9888a2010fd2a6a Mon Sep 17 00:00:00 2001 From: Daniel STAN Date: Thu, 24 Jul 2014 11:31:13 +0200 Subject: [PATCH] pas de URLParameter sur le pika wheezy --- config.py.example | 7 +++++-- daemon.py | 3 +-- dump_creds.py | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 4 deletions(-) create mode 100755 dump_creds.py diff --git a/config.py.example b/config.py.example index e890c90..79e31fe 100644 --- a/config.py.example +++ b/config.py.example @@ -1,4 +1,7 @@ # -*- coding: utf-8 -*- +import pika -# REPLACE password here -URL='amqps://oie:****@rabbitmq.crans.org:5671/%2F' +CREDS = pika.credentials.PlainCredentials('oie', '*******', True) + +PARAMS = pika.ConnectionParameters(host='rabbitmq.crans.org', + port=5671, credentials=CREDS, ssl=True) diff --git a/daemon.py b/daemon.py index 0d5a5c4..6576cee 100755 --- a/daemon.py +++ b/daemon.py @@ -5,8 +5,7 @@ import json import dump import config -params = pika.URLParameters(config.URL) -conn = pika.BlockingConnection(params) +conn = pika.BlockingConnection(config.PARAMS) ch = conn.channel() ch.queue_declare(queue='CransTicket') def callback(ch, method, properties, body): diff --git a/dump_creds.py b/dump_creds.py new file mode 100755 index 0000000..d2e4f84 --- /dev/null +++ b/dump_creds.py @@ -0,0 +1,48 @@ +#!/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'' 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['pass'] = machine['ipsec'][0].value + to_print.append(todo) + +ch.basic_publish(exchange='', routing_key='CransTicket', body=json.dumps(to_print))