From 500021adcf08495453dea3c654905217e04a7875 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Mon, 2 Mar 2015 21:39:36 +0100 Subject: [PATCH] init --- DEBIAN/conffiles | 1 + DEBIAN/control | 7 ++ DEBIAN/postins | 2 + DEBIAN/postrm | 1 + usr/bin/spfgenerator | 156 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 167 insertions(+) create mode 100644 DEBIAN/conffiles create mode 100644 DEBIAN/control create mode 100755 DEBIAN/postins create mode 100755 DEBIAN/postrm create mode 100755 usr/bin/spfgenerator diff --git a/DEBIAN/conffiles b/DEBIAN/conffiles new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/DEBIAN/conffiles @@ -0,0 +1 @@ + diff --git a/DEBIAN/control b/DEBIAN/control new file mode 100644 index 0000000..7695129 --- /dev/null +++ b/DEBIAN/control @@ -0,0 +1,7 @@ +Package: spfgenerator +Version: 1.1.1 +Section: base +Priority: optional +Architecture: all +Maintainer: Simon Vieille +Description: SPF Generator diff --git a/DEBIAN/postins b/DEBIAN/postins new file mode 100755 index 0000000..13f4793 --- /dev/null +++ b/DEBIAN/postins @@ -0,0 +1,2 @@ +#!/bin/sh + diff --git a/DEBIAN/postrm b/DEBIAN/postrm new file mode 100755 index 0000000..1a24852 --- /dev/null +++ b/DEBIAN/postrm @@ -0,0 +1 @@ +#!/bin/sh diff --git a/usr/bin/spfgenerator b/usr/bin/spfgenerator new file mode 100755 index 0000000..774843f --- /dev/null +++ b/usr/bin/spfgenerator @@ -0,0 +1,156 @@ +#!/bin/sh + +showHelp() { + cat < + Allow IP to send email for the domain. + Can be used several times. + + -i, --include + Any domains that may deliver or relay mail for the domain. + Can be used several times. + + -a + Add any other server hostname that may deliver or relay mail for the domain. + If domain is empty, it allow current IP address of the domain to send email for the domain. + Can be used several times. + + -p, --policy + Default value: @ + + -s, --short + Only show the value +EOF +} + +MX=0 +IPv4s= +IPv6s= +INCLUDEs= +POLICY='?all' +DOMAIN=@ +SHORT=0 +As= + +testData() { + if [ -z "$1" ]; then + ( + echo "Invalid parameter ($2)\n" + showHelp + ) >&2 + exit 1 + fi +} + +addIp() { + if [ -n "$1" ]; then + if [ $(echo "$1" | egrep "^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+") ]; then + IPv4s="$IPv4s ip4:$1" + else + IPv6s="$IPv6s ip6:$1" + fi + fi +} + +addA() { + if [ -z "$1" ]; then + As="$As a" + else + As="$As a:$1" + fi +} + +addInclude() { + if [ -n "$1" ]; then + INCLUDEs="$INCLUDEs include:$1" + fi +} + +for i in $@; do + case $1 in + -h|--help) + showHelp + exit 0 + ;; + -mx) + MX=1 + shift + ;; + -s|--short) + SHORT=1 + shift + ;; + -a) + shift + addA $1 + shift + ;; + -ip) + shift + addIp $1 + shift + ;; + -i|--include) + shift + addInclude $1 + shift + ;; + -p|--policy) + shift + case $1 in + neutral) POLICY='?all';; + soft) POLICY='~all';; + fail) POLICY='-all';; + esac + shift + ;; + -d|--domain) + shift + DOMAIN=$1 + shift + ;; + esac +done + +testData "$DOMAIN" domain +testData "$IPv4s$IPv6s" ip + +( + if [ $MX -eq 1 ]; then + MX=mx + fi + + if [ $SHORT -eq 0 ]; then + echo "$DOMAIN IN TXT \"v=spf1 $MX $As $IPv4s $IPv6s $INCLUDEs $POLICY\"" + else + echo "v=spf1 $MX $As $IPv4s $IPv6s $INCLUDEs $POLICY" + fi +) | sed 's/ */ /g'