dump_creds reset les mdp
This commit is contained in:
parent
8a5822d4df
commit
6173bc8e89
3 changed files with 55 additions and 25 deletions
27
client.py
Executable file → Normal file
27
client.py
Executable file → Normal file
|
@ -5,6 +5,10 @@ from __future__ import print_function
|
||||||
from gestion import secrets_new as secrets
|
from gestion import secrets_new as secrets
|
||||||
import pika
|
import pika
|
||||||
import json
|
import json
|
||||||
|
import random
|
||||||
|
import datetime
|
||||||
|
import string
|
||||||
|
from lc_ldap import crans_utils
|
||||||
|
|
||||||
CREDS = pika.credentials.PlainCredentials('oie', secrets.get('rabbitmq_oie'), True)
|
CREDS = pika.credentials.PlainCredentials('oie', secrets.get('rabbitmq_oie'), True)
|
||||||
PARAMS = pika.ConnectionParameters(host='rabbitmq.crans.org',
|
PARAMS = pika.ConnectionParameters(host='rabbitmq.crans.org',
|
||||||
|
@ -14,6 +18,13 @@ rabbit_c = pika.BlockingConnection(PARAMS)
|
||||||
ch = rabbit_c.channel()
|
ch = rabbit_c.channel()
|
||||||
ch.queue_declare('CransTicket')
|
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):
|
class Ticket(object):
|
||||||
|
|
||||||
data = []
|
data = []
|
||||||
|
@ -35,7 +46,21 @@ class Ticket(object):
|
||||||
todo['type'] = 'wifi'
|
todo['type'] = 'wifi'
|
||||||
self.add_entry(todo)
|
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):
|
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 ...")
|
print("Un nouveau ticket est en cours d'impression ...")
|
||||||
|
|
||||||
|
|
|
@ -6,17 +6,35 @@ import pika
|
||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from lc_ldap.shortcuts import lc_ldap_readonly
|
from lc_ldap.shortcuts import lc_ldap_admin
|
||||||
from affich_tools import prompt
|
from affich_tools import prompt
|
||||||
import lc_ldap.filter2 as filter
|
import lc_ldap.filter2 as filter
|
||||||
|
|
||||||
from client import Ticket
|
from client import Ticket
|
||||||
|
|
||||||
ldap = lc_ldap_readonly()
|
ldap = lc_ldap_admin()
|
||||||
|
|
||||||
f = filter.human_to_ldap(sys.argv[1].decode('utf-8'))
|
conf_wifi_only = True
|
||||||
res = ldap.search(f)
|
conf_reset_password = False
|
||||||
if len(res) > 1:
|
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")
|
print("More than one result")
|
||||||
exit(1)
|
exit(1)
|
||||||
elif not res:
|
elif not res:
|
||||||
|
@ -33,10 +51,14 @@ else:
|
||||||
break
|
break
|
||||||
|
|
||||||
ticket = Ticket()
|
ticket = Ticket()
|
||||||
|
if 'uid' in item and conf_reset_password:
|
||||||
|
ticket.reset_password(item)
|
||||||
if hasattr(item, 'machines'):
|
if hasattr(item, 'machines'):
|
||||||
for m in 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:
|
else:
|
||||||
ticket.add_machine(item)
|
ticket.add_machine(item)
|
||||||
|
|
||||||
ticket.print()
|
ticket.print()
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import string
|
|
||||||
import datetime
|
|
||||||
import random
|
|
||||||
import sys
|
import sys
|
||||||
from lc_ldap import crans_utils
|
from lc_ldap import crans_utils
|
||||||
from lc_ldap.shortcuts import lc_ldap_admin
|
from lc_ldap.shortcuts import lc_ldap_admin
|
||||||
|
@ -12,13 +9,6 @@ from client import Ticket
|
||||||
|
|
||||||
conn = lc_ldap_admin()
|
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:
|
if len(sys.argv) != 2:
|
||||||
print("Veuillez taper UN login")
|
print("Veuillez taper UN login")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
@ -29,13 +19,6 @@ if not adh:
|
||||||
exit(1)
|
exit(1)
|
||||||
adh = adh[0]
|
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 = Ticket()
|
||||||
ticket.add_account(login, value)
|
ticket.reset_password(adh)
|
||||||
ticket.print()
|
ticket.print()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue