34 lines
990 B
Python
Executable file
34 lines
990 B
Python
Executable file
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
import os
|
|
import sys
|
|
import random
|
|
from sh import grep,ErrorReturnCode_1
|
|
sys.path.append('/usr/scripts/')
|
|
|
|
import lc_ldap.shortcuts
|
|
from lc_ldap.attributs import imprimeur, nounou
|
|
|
|
conn=lc_ldap.shortcuts.lc_ldap_admin()
|
|
code_path='/usr/scripts/var/digicode/'
|
|
|
|
try:
|
|
aid=int(sys.argv[1][1:])
|
|
except ValueError:
|
|
sys.stdout.write('NONE')
|
|
exit(0)
|
|
adh = conn.search(u"aid=%s" % aid)[0]
|
|
login = str(adh.get('uid',['NONE'])[0])
|
|
try:
|
|
sys.stdout.write(grep('-rl',login, code_path).split('/')[-1])
|
|
except ErrorReturnCode_1:
|
|
droits = [str(d) for d in adh.get('droits', [])]
|
|
if imprimeur in droits or nounou in droits:
|
|
code = str(random.randint(100000, 999999))
|
|
while os.path.isfile(code_path + code):
|
|
code = str(random.randint(100000, 999999))
|
|
with open(code_path + code, 'w') as f:
|
|
f.write(login + '\n')
|
|
sys.stdout.write(str(code))
|
|
else:
|
|
sys.stdout.write('NONE')
|