SAR: add more data to the HyperKitty/Mailman script
This commit is contained in:
parent
f05a04b53a
commit
43cdaeda18
3 changed files with 42 additions and 3 deletions
|
@ -11,6 +11,6 @@ datacenter: phx2
|
|||
lvm_size: 750000
|
||||
|
||||
# GDPR SAR variables
|
||||
sar_script: /srv/webui/bin/hyperkitty-sar.py
|
||||
sar_script: /srv/webui/bin/mailman-sar.py
|
||||
sar_script_user: apache
|
||||
sar_output_file: mailinglists.json
|
||||
|
|
|
@ -20,6 +20,8 @@ from six.moves.urllib.parse import urljoin
|
|||
|
||||
ENV_EMAIL = "SAR_EMAIL"
|
||||
HYPERKITTY_INSTANCE = "http://localhost/archives/"
|
||||
MAILMAN_INSTANCE = "http://localhost:8001/"
|
||||
MAILMAN_AUTH = ("restadmin", "restpass")
|
||||
|
||||
log = logging.getLogger()
|
||||
|
||||
|
@ -52,6 +54,41 @@ def get_emails(address):
|
|||
return emails
|
||||
|
||||
|
||||
def get_subscriptions(address):
|
||||
url = urljoin(MAILMAN_INSTANCE,
|
||||
"3.1/members/find?subscriber={}".format(address))
|
||||
response = requests.get(url, auth=MAILMAN_AUTH)
|
||||
if response.status_code >= 300:
|
||||
log.error("Could not get URL %s: %d %s",
|
||||
url, response.status_code, response.reason)
|
||||
return []
|
||||
result = response.json()
|
||||
subscriptions = []
|
||||
for entry in result.get("entries", []):
|
||||
subscription = {
|
||||
"list_id": entry["list_id"],
|
||||
"role": entry["role"],
|
||||
"delivery_mode": entry["delivery_mode"],
|
||||
}
|
||||
# Get the subscription's preferences
|
||||
member_id = entry["member_id"]
|
||||
pref_url = urljoin(MAILMAN_INSTANCE,
|
||||
"3.1/members/{}/preferences".format(member_id))
|
||||
pref_response = requests.get(pref_url, auth=MAILMAN_AUTH)
|
||||
pref_result = pref_response.json()
|
||||
if pref_response.status_code >= 300:
|
||||
log.error("Could not get URL %s: %d %s",
|
||||
pref_url, pref_response.status_code,
|
||||
pref_response.reason)
|
||||
else:
|
||||
subscription["preferences"] = dict([
|
||||
(key, pref_result[key]) for key in pref_result
|
||||
if key not in ("http_etag", "self_link")
|
||||
])
|
||||
subscriptions.append(subscription)
|
||||
return subscriptions
|
||||
|
||||
|
||||
def parse_args():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--debug", action="store_true")
|
||||
|
@ -70,8 +107,10 @@ def main():
|
|||
stream=sys.stderr,
|
||||
)
|
||||
emails = get_emails(email)
|
||||
subscriptions = get_subscriptions(email)
|
||||
print(json.dumps(dict(
|
||||
emails=emails, count=len(emails),
|
||||
emails=emails,
|
||||
subscriptions=subscriptions,
|
||||
), indent=2))
|
||||
|
||||
|
|
@ -440,7 +440,7 @@
|
|||
- post-update.sh
|
||||
- import-mm2.py
|
||||
- periodic.py
|
||||
- hyperkitty-sar.py
|
||||
- mailman-sar.py
|
||||
|
||||
- name: install the templatized scripts
|
||||
template: src={{ item }}.j2 dest="{{ mailman_webui_basedir }}/bin/{{ item }}"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue