reset mdp
This commit is contained in:
parent
d76ed2febb
commit
d627da4e47
3 changed files with 93 additions and 24 deletions
35
client.py
Executable file
35
client.py
Executable file
|
@ -0,0 +1,35 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
|
import pika
|
||||||
|
import json
|
||||||
|
import config
|
||||||
|
|
||||||
|
rabbit_c = pika.BlockingConnection(config.PARAMS)
|
||||||
|
ch = rabbit_c.channel()
|
||||||
|
ch.queue_declare('CransTicket')
|
||||||
|
|
||||||
|
class Ticket(object):
|
||||||
|
|
||||||
|
data = []
|
||||||
|
|
||||||
|
def add_entry(self, x):
|
||||||
|
self.data.append(x)
|
||||||
|
|
||||||
|
def add_account(self, login, mdp):
|
||||||
|
self.add_entry({'login': login, 'pass': mdp})
|
||||||
|
|
||||||
|
def add_machine(self, machine):
|
||||||
|
login = machine['host'][0].split('.', 1)[0]
|
||||||
|
todo = {'login': login, 'macAddress': machine['macAddress'][0].value,
|
||||||
|
'type': 'fil'}
|
||||||
|
if machine.has_key('ipsec'):
|
||||||
|
todo['secret'] = machine['ipsec'][0].value
|
||||||
|
todo['type'] = 'wifi'
|
||||||
|
self.add_entry(todo)
|
||||||
|
|
||||||
|
def print(self):
|
||||||
|
ch.basic_publish(exchange='', routing_key='CransTicket', body=json.dumps(self.data))
|
||||||
|
print("Un nouveau ticket est en cours d'impression ...")
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#!/bin/bash /usr/scripts/python.sh
|
#!/bin/bash /usr/scripts/python.sh
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import pika
|
import pika
|
||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
|
@ -7,25 +9,21 @@ import sys
|
||||||
from lc_ldap.shortcuts import lc_ldap_readonly
|
from lc_ldap.shortcuts import lc_ldap_readonly
|
||||||
from affich_tools import prompt
|
from affich_tools import prompt
|
||||||
import lc_ldap.filter2 as filter
|
import lc_ldap.filter2 as filter
|
||||||
import config
|
|
||||||
|
|
||||||
rabbit_c = pika.BlockingConnection(config.PARAMS)
|
from client import Ticket
|
||||||
ch = rabbit_c.channel()
|
|
||||||
ch.queue_declare('CransTicket')
|
|
||||||
|
|
||||||
ldap = lc_ldap_readonly()
|
ldap = lc_ldap_readonly()
|
||||||
|
|
||||||
|
|
||||||
f = filter.human_to_ldap(sys.argv[1].decode('utf-8'))
|
f = filter.human_to_ldap(sys.argv[1].decode('utf-8'))
|
||||||
adh = ldap.search(f)
|
res = ldap.search(f)
|
||||||
if len(adh) > 1:
|
if len(res) > 1:
|
||||||
print "More than one result"
|
print("More than one result")
|
||||||
exit()
|
exit()
|
||||||
elif not adh:
|
elif not res:
|
||||||
print "Nobody"
|
print("Nobody found")
|
||||||
else:
|
else:
|
||||||
adh = adh[0]
|
item = res[0]
|
||||||
adh.display()
|
item.display()
|
||||||
while True:
|
while True:
|
||||||
c = prompt("[O/N]").lower()
|
c = prompt("[O/N]").lower()
|
||||||
if c == 'n':
|
if c == 'n':
|
||||||
|
@ -33,16 +31,11 @@ else:
|
||||||
elif c == 'o':
|
elif c == 'o':
|
||||||
break
|
break
|
||||||
|
|
||||||
m = adh.machines()
|
ticket = Ticket()
|
||||||
|
if hasattr(item, 'machines'):
|
||||||
|
for m in item.machines():
|
||||||
|
ticket.add_machine(m)
|
||||||
|
else:
|
||||||
|
ticket.add_machine(item)
|
||||||
|
ticket.print()
|
||||||
|
|
||||||
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))
|
|
||||||
|
|
41
reset_pass.py
Executable file
41
reset_pass.py
Executable file
|
@ -0,0 +1,41 @@
|
||||||
|
#!/bin/bash /usr/scripts/python.sh
|
||||||
|
# -*- 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
|
||||||
|
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)
|
||||||
|
login = sys.argv[1]
|
||||||
|
adh = conn.search(u'uid=%s' % crans_utils.escape(login), mode='rw')
|
||||||
|
if not adh:
|
||||||
|
print("Adhérent introuvable")
|
||||||
|
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.print()
|
Loading…
Add table
Add a link
Reference in a new issue