python3ify, mailman3 support
This commit is contained in:
parent
21cdc16f3f
commit
ba72fab04d
2 changed files with 52 additions and 31 deletions
|
@ -2,18 +2,27 @@
|
|||
#% welcome-email user
|
||||
#% send a welcome email to user.
|
||||
/usr/sbin/sendmail "$1@hackerspace.pl" <<EOF
|
||||
Subject: Welcome to Hackerspace Warsaw!
|
||||
Subject: Witamy! Welcome to the Warsaw Hackerspace!
|
||||
To: $1
|
||||
Content-Type: text/plain; charset="utf-8"
|
||||
|
||||
Welcome to Hackerspace Warsaw!
|
||||
Witamy w Warszawskim Hackerspacie!
|
||||
Welcome to the Warsaw Hackerspace!
|
||||
|
||||
You should now have access to (at least) our wiki and email services.
|
||||
Powinieneś/powinnaś mieć teraz dostęp do wszyskich wewnętrznych usług dla członków. Tym samym hasłem uwierzytelnisz się wszędzie.
|
||||
You should now have access to all of our internal, member-exclusive systems. You can use the same password to log in everywhwere.
|
||||
|
||||
Password changes: https://ldap.hackerspace.pl
|
||||
Przeczytaj naszą wyprawkę żeby dowiedzieć się najważniejszych związanych z Twoim członkostwem, naszym spejsem i wewnętrznymi usługami: https://wiki.hackerspace.pl/members:wyprawka
|
||||
Please read our new member handbook to learn more about your membership, our hackerspace and internal services: https://wiki.hackerspace.pl/members:wyprawka
|
||||
|
||||
All the important info is here: https://wiki.hackerspace.pl/doku.php?id=services
|
||||
Aby zmienić hasło, wejdź na: https://profile.hackerspace.pl
|
||||
To change your password, go to: https://profile.hackerspace.pl
|
||||
|
||||
In case of trouble send email to bofh@hackerspace.pl
|
||||
Aby zobaczyć stan swoich składek, wejdź na: https://kasownik.hackerspace.pl
|
||||
To see your membership fee status, go to: https://kasownik.hackerspace.pl
|
||||
|
||||
W przypadku jakichkolwiek pytań lub wątpliwości, napisz nam mejla na bofh@hackerspace.pl albo porozmawiaj z osobą która Cię zarekomendowała. Jesteśmy mili!
|
||||
In case of any questions or issues, send us an email to bofh@hackerspace.pl or talk to the person that recommened you to the space. We'll be glad to help!
|
||||
|
||||
Happy hacking!
|
||||
|
||||
|
|
|
@ -17,16 +17,19 @@ from distutils.util import strtobool
|
|||
|
||||
import ldap
|
||||
#import requests
|
||||
import urllib2
|
||||
import urllib.request, urllib.error, urllib.parse
|
||||
|
||||
SPECIAL = {
|
||||
# People who prefer non-@hackerspace.pl emails
|
||||
'seb': "s@informa.pl",
|
||||
'enki': "enki@fsck.pl",
|
||||
'pixel': "kkocel20@gmail.com",
|
||||
'ar': 'arachnist@i.am-a.cat',
|
||||
#b'seb': b"s@informa.pl", # bounce 2020/12/25 inf/q3k
|
||||
b'enki': b"enki@fsck.pl",
|
||||
b'pixel': b"kkocel20@gmail.com",
|
||||
b'ar': b'arachnist@i.am-a.cat',
|
||||
}
|
||||
|
||||
LIST_NAME = 'waw-sensitive@lists.hackerspace.pl'
|
||||
DRY_RUN = False
|
||||
|
||||
def ldap_connect():
|
||||
c = ldap.initialize('ldap://ldap.hackerspace.pl')
|
||||
c.start_tls_s()
|
||||
|
@ -42,70 +45,79 @@ def get_target_subscriptions(c):
|
|||
#okay = is_paying(uid) or is_potato(uid)
|
||||
okay = True
|
||||
if not okay:
|
||||
print "Skipping {}, because he's not a member.".format(uid)
|
||||
print("Skipping {}, because he's not a member.".format(uid))
|
||||
else:
|
||||
if uid in SPECIAL:
|
||||
emails.append(SPECIAL[uid])
|
||||
else:
|
||||
emails.append('{}@hackerspace.pl'.format(uid).lower())
|
||||
emails.append((uid + b'@hackerspace.pl').lower())
|
||||
return set(emails)
|
||||
|
||||
|
||||
def get_current_subscriptions():
|
||||
out = subprocess.check_output(['/var/lib/mailman/bin/list_members', 'waw-sensitive'])
|
||||
current = [m.strip() for m in out.split('\n') if '@' in m]
|
||||
out = subprocess.check_output(['mailman', 'members', '-e', LIST_NAME])
|
||||
current = [m.strip().lower() for m in out.split(b'\n') if b'@' in m]
|
||||
return set(current)
|
||||
|
||||
def add_users(users):
|
||||
p = subprocess.Popen(('/var/lib/mailman/bin/add_members', '-r', '-', '-w', 'y', 'waw-sensitive'),
|
||||
if DRY_RUN:
|
||||
return
|
||||
p = subprocess.Popen(('mailman', 'addmembers', '-W', '-', LIST_NAME),
|
||||
stdin=subprocess.PIPE)
|
||||
p.communicate('\n'.join(users))
|
||||
p.communicate(b'\n'.join(users))
|
||||
if p.returncode:
|
||||
raise Exception('Users addition failed')
|
||||
|
||||
def remove_users(users):
|
||||
p = subprocess.Popen(('/var/lib/mailman/bin/remove_members', '-f', '-', 'waw-sensitive'),
|
||||
if DRY_RUN:
|
||||
return
|
||||
p = subprocess.Popen(('mailman', 'delmembers', '-G', '-N', '-f', '-', '-l', LIST_NAME),
|
||||
stdin=subprocess.PIPE)
|
||||
p.communicate('\n'.join(users))
|
||||
p.communicate(b'\n'.join(users))
|
||||
if p.returncode:
|
||||
raise Exception('Users removal failed')
|
||||
|
||||
def notify(add, remove, address):
|
||||
if len(add) == 0 and len(remove) == 0:
|
||||
return
|
||||
message = u"Cześć! \n\n"
|
||||
message = "Cześć! \n\n"
|
||||
if add:
|
||||
message += u"Na listę zostały zasubskrybowane następujące adresy email:\n"
|
||||
message += '\n'.join(' - {}'.format(m) for m in add)
|
||||
message += "Na listę zostały zasubskrybowane następujące adresy email:\n"
|
||||
message += '\n'.join(' - {}'.format(m.decode('utf-8')) for m in add)
|
||||
message += '\n'
|
||||
if remove:
|
||||
message += u"Z listy zostały usunięte następujące adresy email:\n"
|
||||
message += '\n'.join(' - {}'.format(m) for m in remove)
|
||||
message += "Z listy zostały usunięte następujące adresy email:\n"
|
||||
message += '\n'.join(' - {}'.format(m.decode('utf-8')) for m in remove)
|
||||
message += '\n'
|
||||
message += u'\n\n--\nPozdro 600,\nAutomat do Subskrybowania Adresów po Listach'
|
||||
message += '\n\n--\nPozdro 600,\nAutomat do Subskrybowania Adresów po Listach'
|
||||
|
||||
if DRY_RUN:
|
||||
print('Dry run - Notifying:', message)
|
||||
return
|
||||
|
||||
msg = MIMEText(message, "plain", "utf-8")
|
||||
msg['From'] = 'HS BOFH <bofh@hackerspace.pl>'
|
||||
msg['To'] = address
|
||||
msg['Subject'] = 'Zmiany na liście WAW-Sensitive'
|
||||
p = subprocess.Popen(["/usr/sbin/sendmail", "-t"], stdin=subprocess.PIPE)
|
||||
p.communicate(msg.as_string())
|
||||
p.communicate(msg.as_bytes())
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
c = ldap_connect()
|
||||
target = get_target_subscriptions(c)
|
||||
target.add('bofh@hackerspace.pl')
|
||||
target.add(b'bofh@hackerspace.pl')
|
||||
current = get_current_subscriptions()
|
||||
to_add = target - current
|
||||
to_remove = current - target
|
||||
if to_add:
|
||||
print "Adding", to_add
|
||||
add_users(to_add)
|
||||
|
||||
if to_remove:
|
||||
print "Removing", to_remove
|
||||
print("Removing", to_remove)
|
||||
remove_users(to_remove)
|
||||
|
||||
if to_add:
|
||||
print("Adding", to_add)
|
||||
add_users(to_add)
|
||||
|
||||
if to_add or to_remove:
|
||||
notify(to_add, to_remove, 'waw-sensitive@lists.hackerspace.pl')
|
||||
|
|
Loading…
Reference in a new issue