Commit 6173bc8e authored by Daniel STAN's avatar Daniel STAN

dump_creds reset les mdp

parent 8a5822d4
......@@ -5,6 +5,10 @@ from __future__ import print_function
from gestion import secrets_new as secrets
import pika
import json
import random
import datetime
import string
from lc_ldap import crans_utils
CREDS = pika.credentials.PlainCredentials('oie', secrets.get('rabbitmq_oie'), True)
PARAMS = pika.ConnectionParameters(host='rabbitmq.crans.org',
......@@ -14,6 +18,13 @@ rabbit_c = pika.BlockingConnection(PARAMS)
ch = rabbit_c.channel()
ch.queue_declare('CransTicket')
def gen_password():
"""Génère un mot de passe aléatoire"""
random.seed(datetime.datetime.now().microsecond)
chars = string.letters + string.digits + '/=+*'
length = 10
return ''.join([random.choice(chars) for _ in xrange(length)])
class Ticket(object):
data = []
......@@ -35,7 +46,21 @@ class Ticket(object):
todo['type'] = 'wifi'
self.add_entry(todo)
def reset_password(self, adh):
login = adh['uid'][0].value
try:
value = gen_password()
adh['userPassword'] = [crans_utils.hash_password(value).decode('ascii')]
except EnvironmentError:
print("Impossible de changer le mot de passe de %s" % login)
exit(2)
self.add_account(login, value)
def print(self):
ch.basic_publish(exchange='', routing_key='CransTicket', body=json.dumps(self.data))
if not self.data:
print("Nothing to print !")
return
ch.basic_publish(exchange='', routing_key='CransTicket',
body=json.dumps(self.data))
print("Un nouveau ticket est en cours d'impression ...")
......@@ -6,17 +6,35 @@ import pika
import json
import sys
from lc_ldap.shortcuts import lc_ldap_readonly
from lc_ldap.shortcuts import lc_ldap_admin
from affich_tools import prompt
import lc_ldap.filter2 as filter
from client import Ticket
ldap = lc_ldap_readonly()
ldap = lc_ldap_admin()
f = filter.human_to_ldap(sys.argv[1].decode('utf-8'))
res = ldap.search(f)
if len(res) > 1:
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.startswith('--'):
print("Unknown arg")
exit(12)
else:
conf_filter = arg
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:
print("More than one result")
exit(1)
elif not res:
......@@ -33,10 +51,14 @@ else:
break
ticket = Ticket()
if 'uid' in item and conf_reset_password:
ticket.reset_password(item)
if hasattr(item, 'machines'):
for m in item.machines():
ticket.add_machine(m)
if not conf_wifi_only or 'machineWifi' in m['objectClass']:
ticket.add_machine(m)
else:
ticket.add_machine(item)
ticket.print()
......@@ -2,9 +2,6 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
import string
import datetime
import random
import sys
from lc_ldap import crans_utils
from lc_ldap.shortcuts import lc_ldap_admin
......@@ -12,13 +9,6 @@ from client import Ticket
conn = lc_ldap_admin()
def gen_password():
"""Génère un mot de passe aléatoire"""
random.seed(datetime.datetime.now().microsecond)
chars = string.letters + string.digits + '/=+*'
length = 10
return ''.join([random.choice(chars) for _ in xrange(length)])
if len(sys.argv) != 2:
print("Veuillez taper UN login")
exit(1)
......@@ -29,13 +19,6 @@ if not adh:
exit(1)
adh = adh[0]
try:
value = gen_password()
adh['userPassword'] = [crans_utils.hash_password(value).decode('ascii')]
except EnvironmentError:
print("Impossible de changer le mot de passe de %s" % login)
exit(2)
ticket = Ticket()
ticket.add_account(login, value)
ticket.reset_password(adh)
ticket.print()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment