Skip to content

Commit

Permalink
bashcov fullpath
Browse files Browse the repository at this point in the history
  • Loading branch information
jcbf committed Jan 27, 2017
1 parent 0dd3cde commit e983f0d
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 39 deletions.
4 changes: 0 additions & 4 deletions Gemfile

This file was deleted.

43 changes: 31 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
[![Travis-CI badge][travis-img]][travis]
[![SemaphoreCI badge][semaphore-img]][semaphore]
[![Magnum CI badge][magnum-img]][magnum]
[![Drone badge][drone-img]][drone]
[![Shippable badge][shippable-img]][shippable]

[![Join the chat at https://gitter.im/jsarenik/spf-tools][gitter-img]][gitter]
Expand All @@ -33,13 +32,13 @@ and `exists` ones.

Your original TXT record which causes more than 10 DNS look-ups
should be saved as an otherwise unused subdomain TXT record
(e.g. `orig.energystan.com`).
(e.g. `spf-orig.jasan.tk`).

Create a configuration file:

cat > ~/.spf-toolsrc <<EOF
DOMAIN=energystan.com
ORIG_SPF=orig.energystan.com
DOMAIN=jasan.tk
ORIG_SPF=spf-orig.jasan.tk
DESPF_SKIP_DOMAINS=_spf.domain1.com:spf.domain2.org
DNS_TIMEOUT=5
EOF
Expand Down Expand Up @@ -164,8 +163,8 @@ To use this script, file `.spf-toolsrc` in `$HOME` directory should
contain `TOKEN` and `EMAIL` variable definitions which are then used
to connect to CloudFlare API. The file should also contain `DOMAIN`
and `ORIG_SPF` variables which stand for the target SPF domain
(e.g. `energystan.com`) and original SPF record with includes
(e.g. `orig.energystan.com`) in order to use `runspftools.sh`
(e.g. `jasan.tk`) and original SPF record with includes
(e.g. `spf-orig.jasan.tk`) in order to use `runspftools.sh`
without modifying the script.

Usage:
Expand All @@ -176,16 +175,38 @@ Usage:
|| cat /tmp/out | ./mkzoneent.sh | ./cloudflare.sh


## Example
### iprange.sh

./despf.sh | ./normalize.sh | ./simplify.sh \
Extra dependencies: [iprange](https://github.com/firehol/iprange)

This script optimizes the IPv4 address block output (similar to, but
more than `simplify.sh` because it can join multiple networks into
one bigger).

Usage:

./despf.sh | ./iprange.sh

Example:

$ ./despf.sh cont.jasan.tk
ip4:13.111.0.0/24
ip4:13.111.1.0/24
ip4:13.111.2.0/24
ip4:13.111.3.0/24
$ ./despf.sh cont.jasan.tk | ./iprange.sh
ip4:13.111.0.0/22

## Putting it all together

./despf.sh | ./normalize.sh | ./simplify.sh | ./iprange.sh \
| ./mkblocks.sh | ./xsel.sh


## Links

* https://dmarcian.com/spf-survey/spf.energystan.com
* https://dmarcian.com/spf-survey/orig.energystan.com
* https://dmarcian.com/spf-survey/spf.jasan.tk
* https://dmarcian.com/spf-survey/spf-orig.jasan.tk
* http://www.kitterman.com/spf/validate.html
* http://serverfault.com/questions/584708
* http://www.openspf.org/SPF_Record_Syntax
Expand Down Expand Up @@ -221,8 +242,6 @@ Usage:
[semaphore]: https://semaphoreci.com/jsarenik/spf-tools
[magnum-img]: https://magnum-ci.com/status/10aadca49949b855fa11ca7a44022c8a.png
[magnum]: https://magnum-ci.com/public/1acdb8198c9cbd13c5db/builds
[drone-img]: https://drone.io/github.com/jsarenik/spf-tools/status.png
[drone]: https://drone.io/github.com/jsarenik/spf-tools/latest
[gitter-img]: https://badges.gitter.im/Join%20Chat.svg
[gitter]: https://gitter.im/jsarenik/spf-tools
[shippable-img]: https://api.shippable.com/projects/5770eda33be4f4faa56ae58a/badge?branch=master
Expand Down
11 changes: 11 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
dependencies:
cache_directories:
- ../.m2/repository

pre:
- sh -ex misc/ci-setup.sh

## Customize test commands
test:
override:
- sh -ex misc/ci-runtest.sh
4 changes: 2 additions & 2 deletions cloudflare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#
# Usage: ./despf.sh | ./simplify.sh | mkblocks.sh | \
# mkzoneent.sh | ./cloudflare.sh <domain>
# E.g.: ... | ./cloudflare.sh energystan.com
# E.g.: ... | ./cloudflare.sh jasan.tk

for cmd in jq awk sed grep
do
Expand All @@ -37,7 +37,7 @@ a="/$0"; a=${a%/*}; a=${a#/}; a=${a:-.}; BINDIR=$(cd $a; pwd)
test -n "$TOKEN" || { echo "TOKEN not set! Exiting." >&2; exit 1; }
test -n "$EMAIL" || { echo "EMAIL not set! Exiting.">&2; exit 1; }

DOMAIN=${1:-'energystan.com'}
DOMAIN=${1:-'jasan.tk'}
TTL=1 # 1 = auto
APIURL="https://www.cloudflare.com/api_json.html"
idsfile=$(mktemp /tmp/cloudflare-ids-XXXXXX)
Expand Down
4 changes: 2 additions & 2 deletions compare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
#
# Usage: ./compare.sh DOMAIN1 DOMAIN2

domain1=${1:-'spf.energystan.com'}
domain2=${2:-'orig.energystan.com'}
domain1=${1:-'jasan.tk'}
domain2=${2:-'spf-orig.jasan.tk'}

a="/$0"; a=${a%/*}; a=${a#/}; a=${a:-.}; BINDIR=$(cd $a; pwd)
PATH=$BINDIR:$PATH
Expand Down
2 changes: 1 addition & 1 deletion despf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ usage() {
exit 1
}

domain=${DOMAIN:-'orig.energystan.com'}
domain=${DOMAIN:-'spf-orig.jasan.tk'}
test -n "$domain" -o "$#" -gt 0 || usage
while getopts "t:s:h-" opt; do
case $opt in
Expand Down
4 changes: 2 additions & 2 deletions genspfzone.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
#
##############################################################################

ORIGDOMAIN=${1:-'orig.energystan.com'}
DOMAIN=${1:-'energystan.com'}
ORIGDOMAIN=${1:-'spf-orig.jasan.tk'}
DOMAIN=${1:-'jasan.tk'}

a="/$0"; a=${a%/*}; a=${a#/}; a=${a:-.}; BINDIR=$(cd $a; pwd)
PATH=$BINDIR:$PATH
Expand Down
19 changes: 10 additions & 9 deletions include/despf.inc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ myhost() {
}

get_txt() {
myhost -t TXT "$@" | cut -d\" -f2
myhost -t TXT "$@" | cut -d\" -f2- | sed -e 's/\" \"//g;s/\"$//'
}

get_mx() {
Expand Down Expand Up @@ -79,7 +79,7 @@ printip() {
}

# dea <hostname> <cidr>
# dea both.energystan.com
# dea both.jasan.tk
# 1.2.3.4
# fec0::1
dea() {
Expand All @@ -102,12 +102,12 @@ parsepf() {
then
myns=$(findns $host 2>/dev/null)
else
myns=$(sed -n 's/nameserver \([\.:0-9a-f]*\)/\1/p' /etc/resolv.conf)
myns=$(sed -n 's/^nameserver \([\.:0-9a-f]*\)/\1/p' /etc/resolv.conf)
fi
for ns in $myns
do
get_txt $host $ns 2>/dev/null \
| grep -Eo 'v=spf1 [^"]+' && break
| grep -Eio 'v=spf1 [^"]+' && break
done
}

Expand Down Expand Up @@ -137,7 +137,7 @@ getem() {
}

# getamx host mech [mech [...]]
# e.g. host="energystan.com"
# e.g. host="jasan.tk"
# e.g. mech="a a:gnu.org a:google.com/24 mx:gnu.org mx:jasan.tk/24"
getamx() {
local cidr ahost
Expand All @@ -158,6 +158,7 @@ getamx() {
lookuphost=$(echo $ahost | cut -d\/ -f1)
fi
fi
mech=$(echo $mech | tr '[A-Z]' '[a-z]')
if [ "$mech" = "a" ]; then
dea $lookuphost $cidr
elif [ "$mech" = "mx" ]; then
Expand All @@ -181,12 +182,12 @@ despf() {
myspf=$(parsepf $host | sed 's/redirect=/include:/')

set +e
dogetem=$(echo $myspf | grep -Eo 'include:[^[:blank:]]+') \
dogetem=$(echo $myspf | grep -Eio 'include:[^[:blank:]]+') \
&& getem $myloop $dogetem
dogetamx=$(echo $myspf | grep -Eo -w '(mx|a)((\/|:)[^[:blank:]]+)?') \
dogetamx=$(echo $myspf | grep -Eio -w '(mx|a)((\/|:)[^[:blank:]]+)?') \
&& getamx $host $dogetamx
echo $myspf | grep -Eo 'ip[46]:[^[:blank:]]+' | cut -d: -f2- | printip
echo $myspf | grep -Eo '(exists|ptr):[^[:blank:]]+'
echo $myspf | grep -Eio 'ip[46]:[^[:blank:]]+' | cut -d: -f2- | printip
echo $myspf | grep -Eio '(exists|ptr):[^[:blank:]]+'
set -e
}

Expand Down
28 changes: 28 additions & 0 deletions iprange.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/sh
#
# This script uses iprange from https://github.com/firehol/iprange
# in order to optimize resulting list. E.g. if the original SPF records
# would result (after calling despf.sh) in
# ip4:13.111.0.0/24
# ip4:13.111.1.0/24
# ip4:13.111.2.0/24
# ip4:13.111.3.0/24
#
# then if such result is piped into this script it will print just
# ip4:13.111.0.0/22
#
# Thanks to @bakerjalexander for suggestion!
#
# Usage: despf.sh <domain> | iprange.sh

TMP=/tmp/iprange

type iprange > /dev/null
if [ $? -ne 0 ] ; then
cat
exit
fi
cat > $TMP
grep -v ^ip4: $TMP > $TMP-rest
grep ^ip4: $TMP | cut -d: -f2- | iprange | while read l; do echo "ip4:$l"; done
cat $TMP-rest
11 changes: 5 additions & 6 deletions misc/ci-runtest.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

ODIR="$PWD/mybin"
export PATH="$ODIR:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/usr/local/musl/bin:$HOME/bin"
ODIR=$PWD/mybin
export PATH=$ODIR:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/usr/local/musl/bin:$HOME/bin

pwd

Expand All @@ -11,13 +11,12 @@ do
type $cmd >/dev/null
done

which host || true
host jasan.tk || true

which host
host jasan.tk

echo "COVERAGE is $COVERAGE"
if [ "x1" = "x$COVERAGE" ] ; then
bashcov -- tests/test-shell.sh
/home/travis/.rvm/gems/ruby-2.2.5/wrappers/bashcov -- tests/test-shell.sh
else
tests/test-shell.sh || DEBUG=1 tests/test-shell.sh
fi
6 changes: 6 additions & 0 deletions shippable.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
language: none

build:
ci:
- misc/ci-setup.sh
- misc/ci-runtest.sh
2 changes: 1 addition & 1 deletion simplify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ grep "^ip6:" $tmpfile.orig
grep -v "^ip[46]:" $tmpfile.orig

if [ $? -eq 1 ]; then
return 0
exit 0
fi

0 comments on commit e983f0d

Please sign in to comment.