Initial commit
This commit is contained in:
commit
8f14819c22
10
.env.example
Normal file
10
.env.example
Normal file
@ -0,0 +1,10 @@
|
||||
GITEA_CN =
|
||||
MAILCOW_CN =
|
||||
NEXTCLOUD_CN =
|
||||
MATTERMOST_CN =
|
||||
MATTERMOST_TOKEN =
|
||||
NEXTCLOUD_TOKEN =
|
||||
NEXTCLOUD_USER =
|
||||
GITEA_TOKEN =
|
||||
MAILCOW_TOKEN =
|
||||
EXCLUDED_EMAILS =
|
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
.env
|
||||
__pycache__
|
9
README.md
Normal file
9
README.md
Normal file
@ -0,0 +1,9 @@
|
||||
# GNOUS administration scripts
|
||||
|
||||
This repo aims to provide a set of various tools for GNOUS's administrative stuff.
|
||||
|
||||
## Get email addresses of GNOUS users
|
||||
|
||||
Because there is no centralized authentication system for GNOUS services, we rely on [get_emails.py](get_emails.py) to fetch all users emails from the various services.
|
||||
This is useful when GNOUS needs to communicate important information.
|
||||
It also gives more transparency about the way personal data is processed (only displayed, not stored anywhere).
|
34
api_requests.py
Normal file
34
api_requests.py
Normal file
@ -0,0 +1,34 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
import os
|
||||
import requests
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
def gitea(endpoint):
|
||||
server = 'https://' + os.environ["GITEA_CN"] + '/api/v1/'
|
||||
headers = {"Authorization": "token " + os.environ['GITEA_TOKEN']}
|
||||
|
||||
return requests.get(server+endpoint, headers=headers).json()
|
||||
|
||||
def mailcow(endpoint):
|
||||
server = 'https://' + os.environ["MAILCOW_CN"] + '/api/v1/'
|
||||
headers = {"X-API-Key": os.environ['MAILCOW_TOKEN']}
|
||||
|
||||
return requests.get(server+endpoint, headers=headers).json()
|
||||
|
||||
def mattermost(endpoint):
|
||||
server = 'https://' + os.environ["MATTERMOST_CN"] + '/api/v4/'
|
||||
headers = {"Authorization": "Bearer " + os.environ['MATTERMOST_TOKEN']}
|
||||
|
||||
return requests.get(server+endpoint, headers=headers).json()
|
||||
|
||||
def nextcloud(endpoint):
|
||||
server = 'https://' + os.environ["NEXTCLOUD_CN"] + '/ocs/v2.php/'
|
||||
format = "?format=json"
|
||||
auth_user = os.environ["NEXTCLOUD_USER"]
|
||||
auth_token = os.environ["NEXTCLOUD_TOKEN"]
|
||||
headers = { "OCS-APIRequest": "true" }
|
||||
|
||||
return requests.get(server+endpoint+format, auth=(auth_user, auth_token), headers=headers).json()
|
34
get_emails.py
Executable file
34
get_emails.py
Executable file
@ -0,0 +1,34 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
import os
|
||||
import api_requests as api
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
ENDPOINTS = {'mailcow' : 'get/mailbox/all',
|
||||
'nextcloud' : 'cloud/users',
|
||||
'gitea' : 'admin/users',
|
||||
'mattermost' : 'users'}
|
||||
|
||||
emails = []
|
||||
|
||||
for user in api.gitea(ENDPOINTS["gitea"]):
|
||||
emails.append(user["email"])
|
||||
|
||||
for user in api.mattermost(ENDPOINTS["mattermost"]):
|
||||
if "is_bot" not in user:
|
||||
emails.append(user["email"])
|
||||
|
||||
for user in api.mailcow(ENDPOINTS["mailcow"]):
|
||||
if user["username"] not in os.environ["EXCLUDED_EMAILS"]:
|
||||
emails.append(user["username"])
|
||||
|
||||
for user in api.nextcloud(ENDPOINTS["nextcloud"])["ocs"]["data"]["users"]:
|
||||
emails.append(api.nextcloud(ENDPOINTS["nextcloud"] + '/' + user)["ocs"]["data"]["email"])
|
||||
|
||||
emails = sorted(set(emails))
|
||||
print("Emails count : " + str(len(emails)))
|
||||
print("=================")
|
||||
for email in emails:
|
||||
print(email + ';')
|
Loading…
Reference in New Issue
Block a user