init checkPahekoLdap.py
This commit is contained in:
48
bin/checkPahekoLdap.py
Executable file
48
bin/checkPahekoLdap.py
Executable file
@@ -0,0 +1,48 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from lib.paheko import Paheko
|
||||||
|
from lib.ldap import Ldap
|
||||||
|
|
||||||
|
paheko = Paheko()
|
||||||
|
categorie_membres = paheko.get_categorie_id("Membres")
|
||||||
|
membres = paheko.get_users_in_categorie(categorie_membres)
|
||||||
|
|
||||||
|
def test_quota(paheko_entry, ldap_entry):
|
||||||
|
ok = True
|
||||||
|
quota_disque = paheko_entry["quota_disque"].strip("'")
|
||||||
|
if f"{quota_disque}G".encode() != ldap_entry[1]['mailQuota'][0]:
|
||||||
|
ok = False
|
||||||
|
|
||||||
|
return ok
|
||||||
|
|
||||||
|
def test_mail_secours(paheko_entry, ldap_entry):
|
||||||
|
try:
|
||||||
|
if paheko_entry["email_secours"]:
|
||||||
|
return paheko_entry["email_secours"].strip("'").encode() == ldap_entry[1]['mailDeSecours'][0]
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
except e:
|
||||||
|
print(paheko_entry)
|
||||||
|
print(ldap_entry)
|
||||||
|
raise e
|
||||||
|
|
||||||
|
with Ldap() as ldap:
|
||||||
|
try:
|
||||||
|
for membre in membres:
|
||||||
|
ldap_entry = ldap.get_email(membre["email"])[0]
|
||||||
|
|
||||||
|
ok = True
|
||||||
|
|
||||||
|
#ok &= test_quota(membre, ldap_entry)
|
||||||
|
ok &= test_mail_secours(membre, ldap_entry)
|
||||||
|
|
||||||
|
if not ok:
|
||||||
|
print(membre)
|
||||||
|
print(ldap_entry)
|
||||||
|
print()
|
||||||
|
except Exception as e:
|
||||||
|
print(membre)
|
||||||
|
print(ldap.get_email(membre["email"]))
|
||||||
|
raise e
|
@@ -6,10 +6,12 @@ def getDockersConfig(key):
|
|||||||
for line in config:
|
for line in config:
|
||||||
if line.startswith(f"{key}="):
|
if line.startswith(f"{key}="):
|
||||||
return line.split("=", 1)[1].split("#")[0].strip()
|
return line.split("=", 1)[1].split("#")[0].strip()
|
||||||
|
raise Exception(f"getDockersConfig(): No config for {key}")
|
||||||
|
|
||||||
def getSecretConfig(serv, key):
|
def getSecretConfig(serv, key):
|
||||||
with open(SECRETS.format(serv=serv)) as config:
|
with open(SECRETS.format(serv=serv)) as config:
|
||||||
for line in config:
|
for line in config:
|
||||||
if line.startswith(f"{key}="):
|
if line.startswith(f"{key}="):
|
||||||
return line.split("=", 2)[1].split("#")[0].strip()
|
return line.split("=", 2)[1].split("#")[0].strip()
|
||||||
|
raise Exception(f"getSecretConfig(): No config for {serv}/{key}")
|
||||||
|
|
||||||
|
@@ -3,8 +3,8 @@ import requests
|
|||||||
|
|
||||||
from .config import getDockersConfig, getSecretConfig
|
from .config import getDockersConfig, getSecretConfig
|
||||||
|
|
||||||
paheko_ident = getDockersConfig("paheko_API_USER")
|
paheko_ident = getSecretConfig("paheko", "API_USER")
|
||||||
paheko_pass = getDockersConfig("paheko_API_PASSWORD")
|
paheko_pass = getSecretConfig("paheko", "API_PASSWORD")
|
||||||
paheko_auth = (paheko_ident, paheko_pass)
|
paheko_auth = (paheko_ident, paheko_pass)
|
||||||
paheko_url = f"https://kaz-paheko.{getDockersConfig('domain')}"
|
paheko_url = f"https://kaz-paheko.{getDockersConfig('domain')}"
|
||||||
|
|
||||||
@@ -24,14 +24,22 @@ class Paheko:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def get_categorie_id(self, categorie_name):
|
||||||
|
categories = self.get_categories()
|
||||||
|
for categorie in categories.values():
|
||||||
|
if categorie["name"] == categorie_name:
|
||||||
|
return categorie["id"]
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_users_in_categorie(self,categorie):
|
def get_users_in_categorie(self,categorie):
|
||||||
"""
|
"""
|
||||||
Afficher les membres d'une catégorie Paheko
|
Afficher les membres d'une catégorie Paheko
|
||||||
"""
|
"""
|
||||||
if not categorie.isdigit():
|
if not (isinstance(categorie, int) or categorie.isdigit()):
|
||||||
return 'Id de category non valide', 400
|
return 'Id de category non valide', 400
|
||||||
|
|
||||||
api_url = paheko_url + '/api/user/category/'+categorie+'.json'
|
api_url = f"{paheko_url}/api/user/category/{categorie}.json"
|
||||||
|
|
||||||
response = requests.get(api_url, auth=paheko_auth)
|
response = requests.get(api_url, auth=paheko_auth)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user