From 47a6395ee891488be4becd1f3292bd28811f0069 Mon Sep 17 00:00:00 2001 From: tv Date: Mon, 14 Jan 2013 16:36:13 +0100 Subject: retiolum apply-custom-hosts-patches: initial commit Custom hosts patches are currently used for "LAN supernodes". Example patch: --- destroy 2012-05-12 04:13:57.081041849 +0100 +++ destroy 2013-01-13 18:35:30.087707751 +0100 @@ -1,3 +1,4 @@ +Address = destroy.local Subnet = 42:9277:1f1e:7599:ae4b:7cca:b4a3:fe47/128 Subnet = 10.243.0.31/32 Compression = 9 --- retiolum/bin/apply-custom-hosts-patches | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100755 retiolum/bin/apply-custom-hosts-patches (limited to 'retiolum/bin') diff --git a/retiolum/bin/apply-custom-hosts-patches b/retiolum/bin/apply-custom-hosts-patches new file mode 100755 index 00000000..2b2fda80 --- /dev/null +++ b/retiolum/bin/apply-custom-hosts-patches @@ -0,0 +1,8 @@ +#! /bin/sh +set -euf + +patch=/etc/tinc/retiolum/hosts.patch + +if test -e $patch; then + patch -N -d /etc/tinc/retiolum/hosts -r - < $patch +fi -- cgit v1.2.3 From 4e540697f4fbd26c0ec047b763d2b0177008917e Mon Sep 17 00:00:00 2001 From: root Date: Thu, 31 Jan 2013 20:35:35 +0100 Subject: //retiolum update_tinc_hosts: don't modify PATH Don't modify PATH but explicitly locate required executables (i.e. hosts), so no other executables from //retiolum/bin can sneak into update_tinc_hosts. --- retiolum/bin/update_tinc_hosts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'retiolum/bin') diff --git a/retiolum/bin/update_tinc_hosts b/retiolum/bin/update_tinc_hosts index 7be30c2a..ce1be497 100755 --- a/retiolum/bin/update_tinc_hosts +++ b/retiolum/bin/update_tinc_hosts @@ -7,8 +7,12 @@ if test "${nosudo-false}" != true -a `id -u` != 0; then exit 23 # go to hell fi -DIRNAME=`dirname $0` -export PATH="`readlink -f $DIRNAME`:$PATH" +list_hosts="$( + basename="`readlink -f "$0"`" + bindir="`dirname "$basename"`" + echo "$bindir/hosts" +)" +hosts() { "$list_hosts"; } hosts="${hosts-/etc/hosts}" -- cgit v1.2.3 From 0b2528347d6ece0d6bac5b51982d78cdb002c8e8 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 31 Jan 2013 20:45:04 +0100 Subject: //retiolum update-retiolum-hosts: don't HUP/ALRM tincd --- retiolum/bin/update-retiolum-hosts | 2 -- 1 file changed, 2 deletions(-) (limited to 'retiolum/bin') diff --git a/retiolum/bin/update-retiolum-hosts b/retiolum/bin/update-retiolum-hosts index 2a379459..e9fca25c 100755 --- a/retiolum/bin/update-retiolum-hosts +++ b/retiolum/bin/update-retiolum-hosts @@ -12,5 +12,3 @@ cd $(dirname $(readlink -f $0))/.. mkdir -p /etc/tinc/retiolum/hosts cp -v -r hosts/* /etc/tinc/retiolum/hosts -pkill -HUP tincd -pkill -ALRM tincd -- cgit v1.2.3 From 367edf6e568b9d9ac094693e2c6345f120e2a99c Mon Sep 17 00:00:00 2001 From: root Date: Thu, 31 Jan 2013 20:46:22 +0100 Subject: //retiolum update-retiolum-hosts: s/cp/rsync/ Now old hosts will be removed from /etc/tinc/retiolum/hosts. --- retiolum/bin/update-retiolum-hosts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'retiolum/bin') diff --git a/retiolum/bin/update-retiolum-hosts b/retiolum/bin/update-retiolum-hosts index e9fca25c..214ac205 100755 --- a/retiolum/bin/update-retiolum-hosts +++ b/retiolum/bin/update-retiolum-hosts @@ -1,5 +1,5 @@ #! /bin/sh -set -eu +set -euf if test "${nosudo-false}" != true -a `id -u` != 0; then echo "we're going sudo..." >&2 @@ -11,4 +11,4 @@ fi cd $(dirname $(readlink -f $0))/.. mkdir -p /etc/tinc/retiolum/hosts -cp -v -r hosts/* /etc/tinc/retiolum/hosts +rsync -va --delete hosts/ /etc/tinc/retiolum/hosts/ -- cgit v1.2.3 From 453593943e41edc1b55372951af1e3b2768e59c0 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 31 Jan 2013 21:13:44 +0100 Subject: //retiolum patch-retiolum-hosts: allow --reverse --- retiolum/bin/apply-custom-hosts-patches | 8 -------- retiolum/bin/patch-retiolum-hosts | 13 +++++++++++++ 2 files changed, 13 insertions(+), 8 deletions(-) delete mode 100755 retiolum/bin/apply-custom-hosts-patches create mode 100755 retiolum/bin/patch-retiolum-hosts (limited to 'retiolum/bin') diff --git a/retiolum/bin/apply-custom-hosts-patches b/retiolum/bin/apply-custom-hosts-patches deleted file mode 100755 index 2b2fda80..00000000 --- a/retiolum/bin/apply-custom-hosts-patches +++ /dev/null @@ -1,8 +0,0 @@ -#! /bin/sh -set -euf - -patch=/etc/tinc/retiolum/hosts.patch - -if test -e $patch; then - patch -N -d /etc/tinc/retiolum/hosts -r - < $patch -fi diff --git a/retiolum/bin/patch-retiolum-hosts b/retiolum/bin/patch-retiolum-hosts new file mode 100755 index 00000000..69d7b92c --- /dev/null +++ b/retiolum/bin/patch-retiolum-hosts @@ -0,0 +1,13 @@ +#! /bin/sh +# +# Apply custom retiolum hosts patches, if any. +# +# usage: patch-retiolum-hosts [--reverse] +# +set -euf + +patch=/etc/tinc/retiolum/hosts.patch + +if test -e $patch; then + patch -N -d /etc/tinc/retiolum/hosts -r - "$@" < $patch +fi -- cgit v1.2.3 From f2992565ab8be0544ae328c3d11243131a3b7441 Mon Sep 17 00:00:00 2001 From: tv Date: Sat, 2 Feb 2013 00:19:20 +0100 Subject: //retiolum list-known-public-addresses: initial commit --- retiolum/bin/list-known-public-addresses | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 retiolum/bin/list-known-public-addresses (limited to 'retiolum/bin') diff --git a/retiolum/bin/list-known-public-addresses b/retiolum/bin/list-known-public-addresses new file mode 100755 index 00000000..d157cea4 --- /dev/null +++ b/retiolum/bin/list-known-public-addresses @@ -0,0 +1,28 @@ +#! /bin/sh +# +# printf '%s %s\n' hostname IP-address for each known public retiolum address +# +set -eu + +cd /etc/tinc/retiolum/hosts + +grep --with-filename '^Address' * | +sed ' + # filter "%s %s %s\n" hostname var val + s/: */ / + s/ *= */ / + # filter "%s %s\n" hostname address + s/ Address \([a-zA-Z0-9.:_]*\) \?.*/ \1/ + T + # prepare hostname lookup + /:/!{/ [0-9.]*$/!{s/ / `dig +short /;s/$/` \&/}} + s/^/echo / + $s/$/\nwait/ + # perform hostname lookup +' | sh | sed ' + # drop private IPv4 addresses + / 10\./d + / 172\.\(1[6-9]\|2[0-9]\|3[01]\)\./d + / 192\.168\./d + # TODO drop private IPv6 addresses +' -- cgit v1.2.3 From c6f8c72d483fdcdf2ba4554ca7f578089df9f1c2 Mon Sep 17 00:00:00 2001 From: tv Date: Sat, 2 Feb 2013 01:22:08 +0100 Subject: //retiolum list-known-public-addresses: factorize --- retiolum/bin/list-known-public-addresses | 46 +++++++++++++++++--------------- 1 file changed, 25 insertions(+), 21 deletions(-) (limited to 'retiolum/bin') diff --git a/retiolum/bin/list-known-public-addresses b/retiolum/bin/list-known-public-addresses index d157cea4..d8073791 100755 --- a/retiolum/bin/list-known-public-addresses +++ b/retiolum/bin/list-known-public-addresses @@ -4,25 +4,29 @@ # set -eu -cd /etc/tinc/retiolum/hosts +_list_hostname_address() { + cd /etc/tinc/retiolum/hosts + grep --with-filename '^Address' * | + sed -n ' + s/: */ / + s/ *= */ / + s/ Address \([a-zA-Z0-9.:_]*\) \?.*/ \1/p' +} +_lookup_address() { + sed ' + /:/!{/ [0-9.]*$/!{s/ / `dig +short /;s/$/` \&/}} + s/^/echo / + $s/$/\nwait/ + ' | sh +} +_filter_public() { + sed ' + # drop private IPv4 addresses + / 10\./d + / 172\.\(1[6-9]\|2[0-9]\|3[01]\)\./d + / 192\.168\./d + # TODO drop private IPv6 addresses + ' +} -grep --with-filename '^Address' * | -sed ' - # filter "%s %s %s\n" hostname var val - s/: */ / - s/ *= */ / - # filter "%s %s\n" hostname address - s/ Address \([a-zA-Z0-9.:_]*\) \?.*/ \1/ - T - # prepare hostname lookup - /:/!{/ [0-9.]*$/!{s/ / `dig +short /;s/$/` \&/}} - s/^/echo / - $s/$/\nwait/ - # perform hostname lookup -' | sh | sed ' - # drop private IPv4 addresses - / 10\./d - / 172\.\(1[6-9]\|2[0-9]\|3[01]\)\./d - / 192\.168\./d - # TODO drop private IPv6 addresses -' +_list_hostname_address | _lookup_address | _filter_public -- cgit v1.2.3 From e929315a0b734aab77a68bcfa41f24faf28b8896 Mon Sep 17 00:00:00 2001 From: tv Date: Sat, 2 Feb 2013 01:31:29 +0100 Subject: //retiolum list-known-public-addresses: add online filter --- retiolum/bin/list-known-public-addresses | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'retiolum/bin') diff --git a/retiolum/bin/list-known-public-addresses b/retiolum/bin/list-known-public-addresses index d8073791..00d8d4b9 100755 --- a/retiolum/bin/list-known-public-addresses +++ b/retiolum/bin/list-known-public-addresses @@ -28,5 +28,11 @@ _filter_public() { # TODO drop private IPv6 addresses ' } +_filter_online() { + awk ' + {print"nc -zw 2 "$2" 655 2>/dev/null && echo "$1" "$2" &"} + END {print"wait"} + ' | sh +} -_list_hostname_address | _lookup_address | _filter_public +_list_hostname_address | _lookup_address | _filter_public | _filter_online -- cgit v1.2.3 From ae5b25d9c15b598460e44f2fc54168936abaca81 Mon Sep 17 00:00:00 2001 From: tv Date: Sat, 2 Feb 2013 01:50:33 +0100 Subject: //retiolum list-known-public-addresses: don't check if online --- retiolum/bin/list-known-public-addresses | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'retiolum/bin') diff --git a/retiolum/bin/list-known-public-addresses b/retiolum/bin/list-known-public-addresses index 00d8d4b9..21b1c389 100755 --- a/retiolum/bin/list-known-public-addresses +++ b/retiolum/bin/list-known-public-addresses @@ -35,4 +35,4 @@ _filter_online() { ' | sh } -_list_hostname_address | _lookup_address | _filter_public | _filter_online +_list_hostname_address | _lookup_address | _filter_public -- cgit v1.2.3 From 59ccc0fd871c4bbd12066f2f6aacf835a839885d Mon Sep 17 00:00:00 2001 From: makefu Date: Fri, 8 Feb 2013 10:10:43 +0000 Subject: add nodes-to-json: parses retiolum/hosts folder into json --- retiolum/bin/find-supernodes | 21 +++++++++++++++++++++ retiolum/bin/my-ip | 2 -- retiolum/bin/nodes-to-json.py | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 2 deletions(-) create mode 100755 retiolum/bin/find-supernodes delete mode 100755 retiolum/bin/my-ip create mode 100644 retiolum/bin/nodes-to-json.py (limited to 'retiolum/bin') diff --git a/retiolum/bin/find-supernodes b/retiolum/bin/find-supernodes new file mode 100755 index 00000000..2c316d0e --- /dev/null +++ b/retiolum/bin/find-supernodes @@ -0,0 +1,21 @@ +#! /bin/dash +set -eu +cd /etc/tinc/retiolum/hosts +for name in ` + grep '^[[:space:]]*Address[[:space:]]*=' * | + cut -d: -f1 | sort | uniq +`; do + if eval "`sed -n ' + s/[[:space:]]\+//g + s/^\(Address\|Port\)=\(.*\)/\1="\${\1+\$\1\n}\2"/p + ' $name`"; then + port=${Port-655} + for host in $Address; do + if nc -zw 2 $host $port 2>/dev/null; then + echo "$name [('$host', $port)]" + fi & + done + wait + fi & +done +wait diff --git a/retiolum/bin/my-ip b/retiolum/bin/my-ip deleted file mode 100755 index fcfbba05..00000000 --- a/retiolum/bin/my-ip +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -curl http://euer.krebsco.de/live/ip.php diff --git a/retiolum/bin/nodes-to-json.py b/retiolum/bin/nodes-to-json.py new file mode 100644 index 00000000..ca9d3c8c --- /dev/null +++ b/retiolum/bin/nodes-to-json.py @@ -0,0 +1,37 @@ +#!/usr/bin/python + +def parse_hosts_path(path="/etc/tinc/retiolum/hosts"): + import os + import re + + needle_addr = re.compile("Subnet\s*=\s*(.*)/[0-9]+") + needle_port = re.compile("Port\s*=\s*(.*)") + for f in os.listdir(path): + with open(path+"/"+f) as of: + addrs = [] + port = "655" + + for line in of.readlines(): + + addr_found = needle_addr.match(line) + if addr_found: + addrs.append(addr_found.group(1)) + + port_found = needle_port.match(line) + if port_found: + port = port_found.group(1) + + if addrs : yield (f ,[(addr ,int(port)) for addr in addrs]) + + + +if __name__ == "__main__": + """ + usage + """ + import json + import sys + db={} + for host,addrs in parse_hosts_path(sys.argv[1] if len(sys.argv) > 2 else "/etc/tinc/retiolum/hosts"): + db[host] = addrs + print(json.dumps(db)) -- cgit v1.2.3