-
Notifications
You must be signed in to change notification settings - Fork 26
/
query_mailer_ovh
executable file
·61 lines (40 loc) · 1.83 KB
/
query_mailer_ovh
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/sh
###########################################################################
# Query Mailer - Generates a Postscreen whitelist for a mailhost that #
# doesn't publish their outbound mailer IPs via SPF records #
# https://github.com/stevejenkins/postwhite #
###########################################################################
# By Jesse Norell (https://github.com/jnorell)
# and Steve Jenkins (https://www.stevejenkins.com/)
version="1.1"
lastupdated="16 April 2018"
temp_file="/tmp/ovh_hosts.txt"
whitelist_file="/etc/postfix/postscreen_ovh_whitelist.cidr"
###########################################################################
# This script uses "mail-out.ovh.net" as a working example of a mailhost
# that does not publish their outbound mailer IP address via SPF records. To
# use this script as a template for additional hosts:
# 1. Copy this script to a new unique filename
# 2. Edit the script's mailhost and numerical range values as required
# 3. Set a unique output file (/etc/postfix/postscreen_*_whitelist.cidr)
# 4. Configure cron to run the new script as often as you like
# 5. Include the output file in Postfix's postscreen_access_list parameter
###########################################################################
# Uncomment to see output
set -x
printf "Querying outbound IP addresses. This could take a while...\n"
# Query user-defined mailer range
for a in {1..99};
do for b in {1..300};
do host ${a}.mo${b}.mail-out.ovh.net;
done;
done > $temp_file
# Format queried hosts
printf "Formatting custom whitelist...\n"
grep 'has address' /tmp/ovh_hosts.txt | awk '{print $4 " permit"}' | sort -uV > $whitelist_file
# Restart Postfix
printf "Restarting Postfix...\n"
postfix reload
# All done!
printf "Done!\n"
exit