| 1 | # -*- coding: utf-8 -*- |
|---|
| 2 | import ldap |
|---|
| 3 | from config import ldapSERVER, ldapBASE |
|---|
| 4 | from common import log |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | def checkORGQuota(): |
|---|
| 8 | return None |
|---|
| 9 | |
|---|
| 10 | def testUpLDAP(): |
|---|
| 11 | return anonymousLDAPbind() != None |
|---|
| 12 | |
|---|
| 13 | def 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 | |
|---|
| 29 | def 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 | |
|---|
| 46 | def 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 | |
|---|
| 70 | def 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 | |
|---|
| 79 | def 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 | |
|---|
| 86 | def checkORGApprovalMode(): |
|---|
| 87 | return None |
|---|
| 88 | |
|---|
| 89 | def checkORGCordinatorActivity(): |
|---|
| 90 | return None |
|---|
| 91 | |
|---|
| 92 | def grantORGCordinatorPasswordReset(): |
|---|
| 93 | return None |
|---|