diff options
-rw-r--r-- | cholerab/ENTERPRISE_PATTERN (renamed from cholerab/pattern/README) | 16 | ||||
-rwxr-xr-x | retiolum/bin/announce_pubkey | 35 | ||||
-rwxr-xr-x | retiolum/bin/tinc_stats2json (renamed from retiolum/scripts/adv_graphgen/tinc_stats.py) | 58 | ||||
-rw-r--r-- | retiolum/hosts/euer | 2 | ||||
-rw-r--r-- | retiolum/hosts/incept | 2 | ||||
-rw-r--r-- | retiolum/hosts/muhbaasu | 2 | ||||
-rwxr-xr-x | retiolum/scripts/adv_graphgen/anonytize.sh | 2 | ||||
-rwxr-xr-x | retiolum/scripts/adv_graphgen/sanitize.sh | 2 | ||||
-rwxr-xr-x | retiolum/scripts/tinc_setup/install.sh | 2 | ||||
-rw-r--r-- | retiolum/scripts/tinc_setup/write_channel.py | 27 |
10 files changed, 106 insertions, 42 deletions
diff --git a/cholerab/pattern/README b/cholerab/ENTERPRISE_PATTERN index 0980ac6e..4e417709 100644 --- a/cholerab/pattern/README +++ b/cholerab/ENTERPRISE_PATTERN @@ -65,4 +65,20 @@ Literate Programming -------------------- Omit all the comments. +Litterate Programming +--------------------- +Write throw-away code and it will become production code + +Enterprise Expect +----------------- +Because you always know what you want, `expect(3)` script code can be replaced +by a `subshell and pipe` pattern : + +<code> + ( echo "$username"; sleep 1; echo "$password"; sleep 1; echo "cp old new" ) | telnet +</code> + +painload example: `//retiolum/bin/announce_pubkey` + + diff --git a/retiolum/bin/announce_pubkey b/retiolum/bin/announce_pubkey new file mode 100755 index 00000000..ce5aed19 --- /dev/null +++ b/retiolum/bin/announce_pubkey @@ -0,0 +1,35 @@ +#!/bin/sh +set -euf +HOST="${1:-}" + +usage (){ +cat <<EOF +usage: $0 HOSTNAME + +also, you are made of stupid +EOF +exit 23 +} + +[ "x$HOST" = "x" ] && usage + +CHANNEL="#krebsco" +IRCHOST="irc.freenode.net" +PORT=6667 +RETIOLUM="/etc/tinc/retiolum" +PUBFILE="$RETIOLUM/hosts/$HOST" + +if [ ! -e $PUBFILE ] ;then + echo "cannot find $PUBFILE - host $HOST wrong?" ; + echo + usage +fi + +NICK="${HOST}_$((RANDOM%666))" + +( echo "NICK $NICK"; + echo "USER $NICK $IRCHOST bla : $NICK"; + echo "JOIN $CHANNEL"; + sleep 23; + sed "s/^\(.*\)/PRIVMSG $CHANNEL : \1/" $PUBFILE; + sleep 5; ) | telnet $IRCHOST $PORT diff --git a/retiolum/scripts/adv_graphgen/tinc_stats.py b/retiolum/bin/tinc_stats2json index d0d47aff..acadb306 100755 --- a/retiolum/scripts/adv_graphgen/tinc_stats.py +++ b/retiolum/bin/tinc_stats2json @@ -1,13 +1,17 @@ #!/usr/bin/python -from BackwardsReader import BackwardsReader +import subprocess import os import re import sys import json -TINC_NETWORK = os.environ.get("TINC_NETWORK","retiolum") -os.environ["LOG_FILE"] + +TINC_NETWORK =os.environ.get("TINC_NETWORK","retiolum") + +# is_legacy is the parameter which defines if the tinc config files are handled old fashioned (parse from syslog), +# or if the new and hip tincctl should be used +is_legacy= os.environ.get("TINC_LEGACY",False) SYSLOG_FILE = os.environ.get("LOG_FILE","/var/log/everything.log") @@ -21,11 +25,14 @@ BEGIN_EDGES = "Edges:" END_EDGES = "End of edges." def get_tinc_block(log_file): - """ returns an iterateable block from the given log file (syslog) """ + """ returns an iterateable block from the given log file (syslog) + This function became obsolete with the introduction of tincctl + """ + from BackwardsReader import BackwardsReader tinc_block = [] in_block = False bf = BackwardsReader(log_file) - BOL = re.compile(".*tinc.retiolum\[[0-9]+\]: ") + BOL = re.compile(".*tinc.%s\[[0-9]+\]: " % TINC_NETWORK) while True: line = bf.readline() if not line: @@ -44,6 +51,36 @@ def get_tinc_block(log_file): break return reversed(tinc_block) +def parse_new_input(): + nodes = {} + pnodes = subprocess.check_output(["tincctl","-n",TINC_NETWORK,"dump","reachable","nodes"]) + for line in pnodes.split('\n'): + if not line: continue + l = line.split() + nodes[l[0]]= { 'external-ip': l[2], 'external-port' : l[4] } + psubnets = subprocess.check_output(["tincctl","-n",TINC_NETWORK,"dump","subnets"]) + for line in psubnets.split('\n'): + if not line: continue + l = line.split() + try: + if not nodes[l[2]].get('internal-ip',False): + nodes[l[2]]['internal-ip'] = [] + nodes[l[2]]['internal-ip'].append(l[0].split('#')[0]) + except KeyError: + pass # node does not exist (presumably) + pedges = subprocess.check_output(["tincctl","-n",TINC_NETWORK,"dump","edges"]) + for line in pedges.split('\n'): + if not line: continue + l = line.split() + try: + if not nodes[l[0]].has_key('to') : + nodes[l[0]]['to'] = [] + nodes[l[0]]['to'].append( + {'name':l[2],'addr':l[4],'port':l[6],'weight' : l[10] }) + except KeyError: + pass #node does not exist + return nodes + def parse_input(log_data): nodes={} for line in log_data: @@ -68,7 +105,6 @@ def parse_input(log_data): if END_EDGES in line : break l = line.replace('\n','').split() - if not nodes[l[0]].has_key('to') : nodes[l[0]]['to'] = [] nodes[l[0]]['to'].append( @@ -78,6 +114,10 @@ def parse_input(log_data): if __name__ == '__main__': import subprocess,time - subprocess.call(["pkill","-SIGUSR2", "tincd"]) - time.sleep(1) - print json.dumps(parse_input((get_tinc_block(SYSLOG_FILE)))) + if is_legacy: + subprocess.call(["pkill","-SIGUSR2", "tincd"]) + time.sleep(1) + print json.dumps(parse_input((get_tinc_block(SYSLOG_FILE)))) + else: + print json.dumps(parse_new_input()) + diff --git a/retiolum/hosts/euer b/retiolum/hosts/euer index 391705c5..d2240575 100644 --- a/retiolum/hosts/euer +++ b/retiolum/hosts/euer @@ -1,4 +1,4 @@ -Address = euer.krebsco.de +#Address = euer.krebsco.de Address = 84.23.67.119 Subnet = 42:974a:3ecf:3c49:06c0:4cd1:3c6f:59d9/128 Subnet = 10.243.0.95/32 diff --git a/retiolum/hosts/incept b/retiolum/hosts/incept index 1ff5365b..348e44b1 100644 --- a/retiolum/hosts/incept +++ b/retiolum/hosts/incept @@ -1,5 +1,5 @@ Address = 77.95.224.63 -Address = incept.krebsco.de +#Address = incept.krebsco.de Address = 2a00:7b80:3008:3::fafc:241 Subnet = 10.243.0.174 Subnet = 42:a2fc:1c89:65c7:6e60:1f62:eaf9:e9b6/128 diff --git a/retiolum/hosts/muhbaasu b/retiolum/hosts/muhbaasu index d758fef2..83fb3933 100644 --- a/retiolum/hosts/muhbaasu +++ b/retiolum/hosts/muhbaasu @@ -1,5 +1,5 @@ Address = 217.160.206.154 -Address = muhbaasu.de +#Address = muhbaasu.de Subnet = 10.243.0.200 Subnet = 42:3f88:faa3:ae13:6ff7:13ee:17d7:421a/128 diff --git a/retiolum/scripts/adv_graphgen/anonytize.sh b/retiolum/scripts/adv_graphgen/anonytize.sh index d49793cb..dec6e456 100755 --- a/retiolum/scripts/adv_graphgen/anonytize.sh +++ b/retiolum/scripts/adv_graphgen/anonytize.sh @@ -11,7 +11,7 @@ TYPE2=png OPENER=/bin/true DOTFILE=`mktemp` trap 'rm $DOTFILE' INT TERM -sudo LOG_FILE=$LOG_FILE python tinc_stats.py |\ +sudo LOG_FILE=$LOG_FILE python ../../tinc_stats2json |\ python parse_tinc_anon.py> $DOTFILE diff --git a/retiolum/scripts/adv_graphgen/sanitize.sh b/retiolum/scripts/adv_graphgen/sanitize.sh index c46662f3..78d74ce6 100755 --- a/retiolum/scripts/adv_graphgen/sanitize.sh +++ b/retiolum/scripts/adv_graphgen/sanitize.sh @@ -11,7 +11,7 @@ TYPE2=png OPENER=/bin/true DOTFILE=`mktemp` trap 'rm $DOTFILE' INT TERM -sudo LOG_FILE=$LOG_FILE python tinc_stats.py |\ +sudo LOG_FILE=$LOG_FILE python ../../tinc_stats2json |\ python parse_tinc_stats.py > $DOTFILE diff --git a/retiolum/scripts/tinc_setup/install.sh b/retiolum/scripts/tinc_setup/install.sh index a6b50b8a..2e36b83a 100755 --- a/retiolum/scripts/tinc_setup/install.sh +++ b/retiolum/scripts/tinc_setup/install.sh @@ -73,7 +73,7 @@ if [ ! -e rsa_key.priv ] then echo "creating new keys" tincd -n $netname -K - python ${CURR}/write_channel.py $myname || \ + $MYBIN/announce_pubkey $myname || \ echo "cannot write public key to IRC, you are on your own. Good Luck" else echo "key files already exist, skipping" diff --git a/retiolum/scripts/tinc_setup/write_channel.py b/retiolum/scripts/tinc_setup/write_channel.py deleted file mode 100644 index 8299fa8d..00000000 --- a/retiolum/scripts/tinc_setup/write_channel.py +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/python -import random, sys, time, socket -try: - myname=sys.argv[1] -except: - print("you are made of stupid") - exit (23) - -CHANNEL = '#krebsco' -HOST='irc.freenode.net' -FILE="/etc/tinc/retiolum/hosts/"+myname -PORT=6667 -NICK= myname+"_"+str(random.randint(23,666)) - -print("Connecting...") -sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM) -sock.connect((HOST,PORT)) -print(NICK) -sock.send("NICK %s\r\n" % NICK) -sock.send("USER %s %s bla : %s\r\n" %(NICK,HOST,NICK)) -sock.send("JOIN %s\r\n" % CHANNEL) -time.sleep(23) -f = open(FILE,'r') -a = [ sock.send("PRIVMSG %s : %s" % ( CHANNEL,line)) for line in f] -time.sleep(5) #because irc is so lazy -print("closing socket") -sock.close() |