diff --git a/client.py b/client.py index a61c8ce..681f7a4 100644 --- a/client.py +++ b/client.py @@ -9,27 +9,9 @@ import random import datetime import string from lc_ldap import crans_utils - import config - -CREDS = pika.credentials.PlainCredentials('oie', secrets.get('rabbitmq_oie'), True) import sys -if '--debug' in sys.argv[1:]: - CREDS = pika.credentials.PlainCredentials('rasputin', secrets.get('rabbitmq_rasputin'), True) -PARAMS = pika.ConnectionParameters(host='rabbitmq.crans.org', - port=5671, credentials=CREDS, ssl=True) -rabbit_c = pika.BlockingConnection(PARAMS) - -ch = rabbit_c.channel() -if '--debug' in sys.argv[1:]: - QUEUE_NAME = 'CransTicketDebug' - print("Debug") -elif '--aux' in sys.argv[1:]: - QUEUE_NAME = config.AUXQUEUE -else: - QUEUE_NAME = config.MAINQUEUE -ch.queue_declare(QUEUE_NAME) def gen_password(): """Génère un mot de passe aléatoire""" @@ -39,8 +21,10 @@ def gen_password(): return ''.join([random.choice(chars) for _ in xrange(length)]) class Ticket(object): - - data = [] + def __init__(self, debug=False, aux=False): + self.data = [] + self.debug = debug + self.aux = aux def add_entry(self, x): self.data.append(x) @@ -115,7 +99,21 @@ class Ticket(object): if not self.data: print("Nothing to print !") return - ch.basic_publish(exchange='', routing_key=QUEUE_NAME, + creds = pika.credentials.PlainCredentials('oie', secrets.get('rabbitmq_oie'), True) + if self.debug: + queue_name = 'CransTicketDebug' + creds = pika.credentials.PlainCredentials('rasputin', secrets.get('rabbitmq_rasputin'), True) + print("Debug") + elif self.aux: + queue_name = config.AUXQUEUE + else: + queue_name = config.MAINQUEUE + params = pika.ConnectionParameters(host='rabbitmq.crans.org', + port=5671, credentials=creds, ssl=True) + rabbit_c = pika.BlockingConnection(params) + ch = rabbit_c.channel() + ch.queue_declare(queue_name) + ch.basic_publish(exchange='', routing_key=queue_name, body=json.dumps(self.data)) print("Un nouveau ticket est en cours d'impression ...") diff --git a/dump_creds.py b/dump_creds.py index 8a5529a..766143c 100755 --- a/dump_creds.py +++ b/dump_creds.py @@ -6,7 +6,7 @@ from __future__ import print_function import pika import json import sys - +import argparse from lc_ldap.shortcuts import lc_ldap_admin from affich_tools import prompt import lc_ldap.filter2 as filter @@ -19,27 +19,30 @@ conf_wifi_only = True conf_reset_password = False conf_filter = None -for arg in sys.argv[1:]: - if arg == '--all': - conf_wifi_only = False - elif arg == '--pass': - conf_reset_password = True - elif arg == '--debug': - pass - elif arg == '--aux': - pass - elif arg.startswith('--'): - print("Unknown arg") - exit(12) - else: - conf_filter = arg + +parser = argparse.ArgumentParser() +parser.add_argument("--all", help="Affiche toutes les machines, fixe et mobiles", action="store_true") +parser.add_argument("--pwd", help="Réinitialise le mot de passe de l'adhérent", action="store_true") +parser.add_argument("--debug", help="Réinitialise le mot de passe de l'adhérent", action="store_true") +parser.add_argument("--aux", help="Choisir l'imprimante auxilliaire", action="store_true") +parser.add_argument("conf_filter", help="Filtre pour la recherche d'un adhérent dans la bas") +args = parser.parse_args() + + +if args.all: + conf_wifi_only = False +elif args.pwd: + conf_reset_password = True +elif args.debug: + pass +elif args.aux: + pass + +conf_filter = args.conf_filter f = filter.human_to_ldap(conf_filter.decode('utf-8')) res = ldap.search(f, mode='rw') -if not conf_filter: - print("Give a filter !") - exit(3) -elif len(res) > 1: +if len(res) > 1: print("More than one result") exit(1) elif not res: @@ -61,7 +64,7 @@ else: elif c == 'o': break -ticket = Ticket() +ticket = Ticket(args.debug,args.aux) if 'uid' in item and conf_reset_password: ticket.reset_password(item)