-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzimbra-own-domain-spoof-prevent.py
37 lines (33 loc) · 1.39 KB
/
zimbra-own-domain-spoof-prevent.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python
# Checks for /opt/zimbra/postfix/conf/sender_access_new and domains Zimbra has configured,
# and if there is a mismatch, updates the file and restarts ZCS MTA
# - run as zimbra user
# - Insert this line: "check_sender_access lmdb:/opt/zimbra/postfix/conf/sender_access_new"
# in /opt/zimbra/conf/zmconfigd/smtpd_sender_restrictions.cf, above the line that has
# "regexp:/opt/zimbra/common/conf/tag_as_foreign.re%%"
# - Add to crontab for periodic checks
import sys
from subprocess import Popen, PIPE, call
def run(command):
p = Popen(command , shell=True, stdout=PIPE, stderr=PIPE)
out, err = p.communicate()
out = out.decode("utf-8")
err = err.decode("utf-8")
#print(command)
#print(out)
return out
def main():
zcs_domains = run("zmprov gad")
zcs_domains = zcs_domains.split()
postfix_domains = run("cat /opt/zimbra/postfix/conf/sender_access_new|awk '{ print $1 }'")
postfix_domains = postfix_domains.split()
if set(zcs_domains) != set(postfix_domains):
print("Updating postfix sender_access_new")
with open('/opt/zimbra/postfix/conf/sender_access_new', 'w') as f:
for i in zcs_domains:
f.write("%s 550 YOU ARE NOT ME.\n" % str(i))
run("postmap /opt/zimbra/postfix/conf/sender_access_new")
run("zmmtactl stop")
run("zmmtactl start")
if __name__ == '__main__':
main()