Created
May 6, 2017 07:37
-
-
Save quinncomendant/4e62a0e4ab82d7b6fe0dc3947510c4c7 to your computer and use it in GitHub Desktop.
Create a custom sender config file for spamdyke using a template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# Quinn Comendant <quinn@strangecode.com> | |
# 06 May 2017 14:45:53 | |
# | |
# Functions | |
# | |
function usage() { | |
echo "Usage: $(basename $0) ADDR | |
Create a custom sender config file for spamdyke using a template. | |
- if ADDR is a hostname add config to /var/qmail/spamdyke/_sender_/com/example/subdom | |
- if ADDR is an IP address add config to /var/qmail/spamdyke/_ip_/111/222/333/444 | |
Then the config files will be opened in $EDITOR (e.g., subdom or 444 is the config file). | |
"; | |
exit 1; | |
} | |
# | |
# Main | |
# | |
if [[ $(id -u) != 0 ]]; then | |
echo "You must be root to execute this script"; | |
exit; | |
fi | |
# Display help if run without arguments. | |
[[ $# == 0 ]] && usage && exit 0; | |
[[ $# != 1 ]] && echo "Invalid arguments. Run with -h for help." && exit 1; | |
EDITOR=${EDITOR:-vim}; | |
SPAMDYKEBASEDIR='/var/qmail/spamdyke'; | |
SPAMDYKECONFTEMPLATE="reject-missing-sender-mx=0 | |
reject-empty-rdns=0 | |
reject-unresolvable-rdns=0 | |
graylist-level=none | |
"; | |
ADDR=$1; | |
if [[ $ADDR =~ [0-9]+\.[0-9]+\.[0-9]+\.[0-9]+ ]]; then | |
# ADDR is a IP address | |
IFS='.' read -r -a ADDRPARTS <<< "$ADDR"; | |
CONFDIR=$(printf '%s/_ip_/%d/%d/%d' "$SPAMDYKEBASEDIR" "${ADDRPARTS[0]}" "${ADDRPARTS[1]}" "${ADDRPARTS[2]}"); | |
mkdir -p "$CONFDIR"; | |
CONFFILE=$(printf '%s/%d' "$CONFDIR" "${ADDRPARTS[3]}"); | |
cat - > "$CONFFILE" <<<"$SPAMDYKECONFTEMPLATE"; | |
test -f "$CONFFILE" && vim "$CONFFILE"; | |
else | |
# Otherwise assume is a hostname. | |
ADDRPARTS=$(echo "$ADDR" | tr '.' $"\n" | tac | tr $"\n" '/'); | |
CONFDIR=$(printf '%s/_sender_/%s' "$SPAMDYKEBASEDIR" "$(dirname "$ADDRPARTS")"); | |
mkdir -p "$CONFDIR"; | |
CONFFILE=$(printf '%s/%s' "$CONFDIR" "$(basename "$ADDRPARTS")"); | |
cat - > "$CONFFILE" <<<"$SPAMDYKECONFTEMPLATE"; | |
test -f "$CONFFILE" && vim "$CONFFILE"; | |
fi | |
chown -R vpopmail:vchkpw $SPAMDYKEBASEDIR/{_ip_,_sender_}; | |
exit 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment