source: arma2/frontend/org.py @ 945ee719561fdc5edb101c445e7866a7b92a4c48

Revision 945ee719561fdc5edb101c445e7866a7b92a4c48, 2.4 KB checked in by Dererk <dererk@…>, 2 years ago (diff)

Chequea la existencia de un usuario (domainless):

  • Hoy goSA nos limita a no poder tener mas de un usuario con el mismo nick, aunque sean diferentes dominios :-@

Chequea slugs en FQDN y no-FQDN (cortos).

  • Property mode set to 100644
Line 
1# -*- coding: utf-8 -*-
2import ldap
3from config import ldapSERVER, ldapBASE
4from common import log
5
6
7def checkORGQuota():
8    return None
9
10def testUpLDAP():
11   return anonymousLDAPbind() != None
12
13def anonymousLDAPbind():
14    # Compatibility mode, JIC ®
15    # l.protocol_version = ldap.VERSION2
16
17    # This might through an exception
18    try:
19        return ldap.open(ldapSERVER).simple_bind("", "")
20   
21    except ldap.SERVER_DOWN:
22        log("CRITICAL", "SERVER FAILED: DOWN")
23        return None
24    except:
25        log("CRITICAL", "SERVER FAILED: Unknown (Server wasn't detected down)")
26        return None
27
28
29def checkIfUserExist(Nick):
30    """ Funcion interna para pre-validar la disponibilidad de un usuario tras el POST  """
31    l=ldap.open(ldapSERVER)
32    # Compatibility mode, JIC ®
33    # l.protocol_version = ldap.VERSION2
34
35    # This might through an exception
36    try:
37        l.simple_bind("","")
38        return user.lower() in [entry[1]['uid'][0].lower() for entry in l.search_s(ldapBASE,2,'uid=*')] 
39    except ldap.SERVER_DOWN:
40        # I'll do something interesting with this in the future...
41        return None
42    except:
43        return None
44
45
46def checkORG(ORG):
47    """
48        Mas simple que hacer Lassagna:
49        - SLUG FQDN (Full Qualified Domain Name) / Dominio completo
50        <playmobil> >>> org.checkORG('cafelug.org.ar')
51        <playmobil> True
52        - SLUG Corto:
53        <playmobil> >>> org.checkORG('cafelug')
54        <playmobil> True
55        <playmobil> >>> org.checkORG('sluc')
56        <playmobil> True
57        <playmobil> >>> org.checkORG('sluc.org.ar')
58        <playmobil> True
59        <playmobil> >>> org.checkORG('slucpuaj.org.ar')
60        <playmobil> False
61    """
62    l=anonymousLDAPbind()
63
64    if '.' in ORG:
65        return ORG in [entry[1]['ou'][0] for entry in l.search_s(ldapBASE,1,'ou='+'*')]
66    else:
67        return ORG in [entry[1]['o'][0] for entry in l.search_s(ldapBASE,1,'o='+'*')]
68
69
70def listORGs(FQDN=False):
71    l=anonymousLDAPbind()
72
73    if FQDN:
74        return [entry[1]['ou'][0] for entry in l.search_s(ldapBASE,1,'ou='+'*')]
75    else:
76        return [entry[1]['o'][0] for entry in l.search_s(ldapBASE,1,'o='+'*')]
77
78
79def getLDAPuidNumber():
80    l=anonymousLDAPbind()
81    uidNumberList=[entry[1]['uidNumber'] for entry in l.search_s(ldapBASE,2,'uidNumber='+'*')]
82    uidNumberList.sort(reverse=True)
83    return uidNumberList[0]+1
84
85
86def checkORGApprovalMode():
87    return None
88
89def checkORGCordinatorActivity():
90    return None
91
92def grantORGCordinatorPasswordReset():
93    return None
Note: See TracBrowser for help on using the repository browser.