diff options
Diffstat (limited to 'retiolum/scripts')
-rw-r--r-- | retiolum/scripts/adv_graphgen/BackwardsReader.py | 35 | ||||
-rw-r--r-- | retiolum/scripts/adv_graphgen/Makefile | 4 | ||||
-rwxr-xr-x | retiolum/scripts/adv_graphgen/all_the_graphs.sh | 5 | ||||
-rwxr-xr-x | retiolum/scripts/adv_graphgen/anonytize.sh | 31 | ||||
-rwxr-xr-x | retiolum/scripts/adv_graphgen/find_legacy_hosts.py | 59 | ||||
-rwxr-xr-x | retiolum/scripts/adv_graphgen/parse.py | 102 | ||||
-rwxr-xr-x | retiolum/scripts/adv_graphgen/parse_tinc_anon.py | 135 | ||||
-rwxr-xr-x | retiolum/scripts/adv_graphgen/parse_tinc_stats.py | 185 | ||||
-rwxr-xr-x | retiolum/scripts/adv_graphgen/sanitize.sh | 39 | ||||
-rwxr-xr-x | retiolum/scripts/adv_graphgen/tinc_stats.py | 83 | ||||
-rw-r--r-- | retiolum/scripts/autostart/Makefile | 14 | ||||
-rwxr-xr-x | retiolum/scripts/autostart/create-startup.sh | 22 | ||||
-rwxr-xr-x | retiolum/scripts/routing/defaultroute.sh | 38 | ||||
-rwxr-xr-x | retiolum/scripts/tinc_setup/install.sh | 46 | ||||
-rwxr-xr-x | retiolum/scripts/tinc_setup/tinc-up | 21 | ||||
-rw-r--r-- | retiolum/scripts/tinc_setup/write_channel.py | 9 |
16 files changed, 671 insertions, 157 deletions
diff --git a/retiolum/scripts/adv_graphgen/BackwardsReader.py b/retiolum/scripts/adv_graphgen/BackwardsReader.py new file mode 100644 index 00000000..6bdbf43c --- /dev/null +++ b/retiolum/scripts/adv_graphgen/BackwardsReader.py @@ -0,0 +1,35 @@ +import sys +import os +import string + +class BackwardsReader: + """ Stripped and stolen from : http://code.activestate.com/recipes/120686-read-a-text-file-backwards/ """ + def readline(self): + while len(self.data) == 1 and ((self.blkcount * self.blksize) < self.size): + self.blkcount = self.blkcount + 1 + line = self.data[0] + try: + self.f.seek(-self.blksize * self.blkcount, 2) + self.data = string.split(self.f.read(self.blksize) + line, '\n') + except IOError: + self.f.seek(0) + self.data = string.split(self.f.read(self.size - (self.blksize * (self.blkcount-1))) + line, '\n') + + if len(self.data) == 0: + return "" + + line = self.data[-1] + self.data = self.data[:-1] + return line + '\n' + + def __init__(self, file, blksize=4096): + """initialize the internal structures""" + self.size = os.stat(file)[6] + self.blksize = blksize + self.blkcount = 1 + self.f = open(file, 'rb') + if self.size > self.blksize: + self.f.seek(-self.blksize * self.blkcount, 2) + self.data = string.split(self.f.read(self.blksize), '\n') + if not self.data[-1]: + self.data = self.data[:-1] diff --git a/retiolum/scripts/adv_graphgen/Makefile b/retiolum/scripts/adv_graphgen/Makefile new file mode 100644 index 00000000..fafac84e --- /dev/null +++ b/retiolum/scripts/adv_graphgen/Makefile @@ -0,0 +1,4 @@ +install: + #punani install graphviz + echo "add this line to your tinc.conf if you dare:" + echo 'GraphDumpFile = |/krebs/retiolum/scripts/adv_graphgen /srv/http/tmp/graphs/' diff --git a/retiolum/scripts/adv_graphgen/all_the_graphs.sh b/retiolum/scripts/adv_graphgen/all_the_graphs.sh new file mode 100755 index 00000000..36b37f03 --- /dev/null +++ b/retiolum/scripts/adv_graphgen/all_the_graphs.sh @@ -0,0 +1,5 @@ +#!/bin/sh +echo "`date` begin all graphs" >> /tmp/build_graph +cd $(dirname $(readlink -f $0)) +(./anonytize.sh /srv/http/pub/graphs/retiolum/ && echo "`date` anonytize done" >> /tmp/build_graph)& +(./sanitize.sh /srv/http/priv/graphs/retiolum/ && echo "`date` sanitize done" >> /tmp/build_graph)& diff --git a/retiolum/scripts/adv_graphgen/anonytize.sh b/retiolum/scripts/adv_graphgen/anonytize.sh new file mode 100755 index 00000000..1ebfe972 --- /dev/null +++ b/retiolum/scripts/adv_graphgen/anonytize.sh @@ -0,0 +1,31 @@ +#!/bin/sh +set -euf +cd $(dirname `readlink -f $0`) +GRAPH_SETTER1=dot +GRAPH_SETTER2=circo +GRAPH_SETTER3='neato -Goverlap=prism ' +GRAPH_SETTER4=sfdp +LOG_FILE=/var/log/syslog +TYPE=svg +TYPE2=png +OPENER=/bin/true +DOTFILE=`mktemp` +trap 'rm $DOTFILE' INT TERM +sudo LOG_FILE=$LOG_FILE python tinc_stats.py |\ + python parse_tinc_anon.py> $DOTFILE + + +i=1 +for setter in dot circo 'neato -Goverlap=prism ' sfdp +do + tmpgraph=`mktemp --tmpdir=$1` + $setter -T$TYPE -o $tmpgraph $DOTFILE + chmod go+rx $tmpgraph + mv $tmpgraph $1/retiolum_$i.$TYPE + i=`expr $i + 1` +done +#convert -resize 20% $1/retiolum_1.$TYPE $1/retiolum_1.$TYPE2 +#convert -resize 20% $1/retiolum_2.$TYPE $1/retiolum_2.$TYPE2 +#convert -resize 20% $1/retiolum_3.$TYPE $1/retiolum_3.$TYPE2 +#convert -resize 20% $1/retiolum_4.$TYPE $1/retiolum_4.$TYPE2 +rm $DOTFILE diff --git a/retiolum/scripts/adv_graphgen/find_legacy_hosts.py b/retiolum/scripts/adv_graphgen/find_legacy_hosts.py new file mode 100755 index 00000000..52388b6d --- /dev/null +++ b/retiolum/scripts/adv_graphgen/find_legacy_hosts.py @@ -0,0 +1,59 @@ +#!/usr/bin/python +# -*- coding: utf8 -*- + +import sys,json +""" TODO: Refactoring needed to pull the edges out of the node structures again, +it should be easier to handle both structures""" +DUMP_FILE = "/krebs/db/availability" + +def get_all_nodes(): + import os + return os.listdir("/etc/tinc/retiolum/hosts") +def generate_stats(): + """ Generates some statistics of the network and nodes + """ + import json + jlines = [] + try: + f = open(DUMP_FILE,'r') + for line in f: + jlines.append(json.loads(line)) + f.close() + except Exception,e: + pass + all_nodes = {} + for k in get_all_nodes(): + all_nodes[k] = get_node_availability(k,jlines) + print ( json.dumps(all_nodes)) + +def get_node_availability(name,jlines): + """ calculates the node availability by reading the generated dump file + adding together the uptime of the node and returning the time + parms: + name - node name + jlines - list of already parsed dictionaries node archive + """ + begin = last = current = 0 + uptime = 0 + #sys.stderr.write ( "Getting Node availability of %s\n" % name) + for stat in jlines: + if not stat['nodes']: + continue + ts = stat['timestamp'] + if not begin: + begin = last = ts + current = ts + if stat['nodes'].get(name,{}).get('to',[]): + uptime += current - last + else: + pass + #sys.stderr.write("%s offline at timestamp %f\n" %(name,current)) + last = ts + all_the_time = last - begin + try: + return uptime/ all_the_time + except: + return 1 + + +generate_stats() diff --git a/retiolum/scripts/adv_graphgen/parse.py b/retiolum/scripts/adv_graphgen/parse.py deleted file mode 100755 index 9c2dd051..00000000 --- a/retiolum/scripts/adv_graphgen/parse.py +++ /dev/null @@ -1,102 +0,0 @@ -#!/usr/bin/python2 -# -*- coding: utf8 -*- - -import sys -""" TODO: Refactoring needed to pull the edges out of the node structures again, -it should be easier to handle both structures""" - -def write_digraph(nodes): - """ - writes the complete digraph in dot format - """ - print ('digraph retiolum {') - print (' node[shape=box,style=filled,fillcolor=grey]') - print (' overlap=false') - generate_stats(nodes) - nodes = delete_unused_nodes(nodes) - merge_edges(nodes) - for k,v in nodes.iteritems(): - write_node(k,v) - print ('}') -def generate_stats(nodes): - """ Generates some statistics of the network and nodes - """ - for k,v in nodes.iteritems(): - v['num_conns'] = len(v.get('to',[])) -def delete_unused_nodes(nodes): - new_nodes = {} - for k,v in nodes.iteritems(): - if v.get('to',[]): - new_nodes[k] = v - return new_nodes -def merge_edges(nodes): - """ merge back and forth edges into one - DESTRUCTS the current structure by deleting "connections" in the nodes - - """ - for k,v in nodes.iteritems(): - for con in v.get('to',[]): - for i,secon in enumerate(nodes[con['name']].get('to',[])): - if k == secon['name']: - del (nodes[con['name']]['to'][i]) - con['bidirectional'] = True - - -def write_node(k,v): - """ writes a single node and its edges - edges are weightet with the informations inside the nodes provided by - tinc - """ - node = " "+k+"[label=\"" - node += k+"\\l" - node += "external:"+v['external-ip']+":"+v['external-port']+"\\l" - if v.has_key('num_conns'): - node += "Num Connects:"+str(v['num_conns'])+"\\l" - for addr in v.get('internal-ip',['¯\\\\(°_o)/¯']): - node += "internal:"+addr+"\\l" - node +="\"" - if v['external-ip'] == "MYSELF": - node += ",fillcolor=steelblue1" - node += "]" - print node - - for con in v.get('to',[]): - edge = " "+k+ " -> " +con['name'] + "[weight="+str(float(con['weight'])) - if con.get('bidirectional',False): - edge += ",dir=both" - edge += "]" - print edge - -def parse_input(): - nodes={} - for line in sys.stdin: - line = line.replace('\n','') - if line == 'Nodes:': - nodes={} - for line in sys.stdin: - if line == 'End of nodes.\n': - break - l = line.replace('\n','').split() #TODO unhack me - nodes[l[0]]= { 'external-ip': l[2], 'external-port' : l[4] } - if line == 'Subnet list:': - for line in sys.stdin: - if line == 'End of subnet list.\n': - break - l = line.replace('\n','').split() - if not nodes[l[2]].get('internal-ip',False): - nodes[l[2]]['internal-ip'] = [] - nodes[l[2]]['internal-ip'].append(l[0].split('#')[0]) - if line == 'Edges:': - edges = {} - for line in sys.stdin: - if line == 'End of edges.\n': - break - l = line.replace('\n','').split() - - 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] }) - return nodes -nodes = parse_input() -write_digraph(nodes) diff --git a/retiolum/scripts/adv_graphgen/parse_tinc_anon.py b/retiolum/scripts/adv_graphgen/parse_tinc_anon.py new file mode 100755 index 00000000..3b0383da --- /dev/null +++ b/retiolum/scripts/adv_graphgen/parse_tinc_anon.py @@ -0,0 +1,135 @@ +#!/usr/bin/python +# -*- coding: utf8 -*- +from BackwardsReader import BackwardsReader +import sys,json +#supernodes= [ "kaah","supernode","euer","pa_sharepoint","oxberg" ] +""" TODO: Refactoring needed to pull the edges out of the node structures again, +it should be easier to handle both structures""" +DUMP_FILE = "/krebs/db/availability" +def write_digraph(nodes): + """ + writes the complete digraph in dot format + """ + print ('digraph retiolum {') + #print (' graph [center rankdir=LR packMode="clust"]') + print (' graph [center packMode="clust"]') + print (' node[shape=circle,style=filled,fillcolor=grey]') + print (' overlap=false') + generate_stats(nodes) + merge_edges(nodes) + nodes = anon_nodes(nodes) + for k,v in nodes.iteritems(): + write_node(k,v) + write_stat_node(nodes) + print ('}') + +def anon_nodes(nodes): + i = "0" + newnodes = {} + for k,v in nodes.iteritems(): + for nodek,node in nodes.iteritems(): + for to in node['to']: + if to['name'] == k: + to['name'] = i + newnodes[i] = v + i = str(int(i)+1) + return newnodes + +def write_stat_node(nodes): + ''' Write a `stats` node in the corner + This node contains infos about the current number of active nodes and connections inside the network + ''' + num_conns = 0 + num_nodes = len(nodes) + for k,v in nodes.iteritems(): + num_conns+= len(v['to']) + node_text = " stats_node [shape=box,label=\"Statistics\\l" + node_text += "Active Nodes: %s\\l" % num_nodes + node_text += "Connections : %s\\l" % num_conns + node_text += "\"" + node_text += ",fillcolor=green" + node_text += "]" + print(node_text) + +def generate_stats(nodes): + """ Generates some statistics of the network and nodes + """ + for k,v in nodes.iteritems(): + conns = v.get('to',[]) + for c in conns: #sanitize weights + if float(c['weight']) > 9000: c['weight'] = str(9001) + elif float(c['weight']) < 0: c['weight'] = str(0) + v['num_conns'] = len(conns) + v['avg_weight'] = get_node_avg_weight(conns) +def get_node_avg_weight(conns): + """ calculates the average weight for the given connections """ + if not conns: + sys.syderr.write("get_node_avg_weight: connection parameter empty") + return 9001 + else: + return sum([float(c['weight']) for c in conns])/len(conns) + +def delete_unused_nodes(nodes): + new_nodes = {} + for k,v in nodes.iteritems(): + if v['external-ip'] == "(null)": + continue + if v.get('to',[]): + new_nodes[k] = v + for k,v in new_nodes.iteritems(): + if not [ i for i in v['to'] if i['name'] in new_nodes]: + #del(new_nodes[k]) + del(k) + return new_nodes +def merge_edges(nodes): + """ merge back and forth edges into one + DESTRUCTS the current structure by deleting "connections" in the nodes + """ + for k,v in nodes.iteritems(): + for con in v.get('to',[]): + for i,secon in enumerate(nodes.get(con['name'],{}).get('to',[])): + if k == secon['name']: + del (nodes[con['name']]['to'][i]) + con['bidirectional'] = True + + +def write_node(k,v): + """ writes a single node and its edges + edges are weightet with the informations inside the nodes provided by + tinc + """ + + node = " "+k #+"[label=\"" + #node += k+"\\l" + #node += "avg weight: %.2f\\l" % v['avg_weight'] + #if v.has_key('num_conns'): + # node += "Conns:"+str(v['num_conns'])+"\\l" + #node +="\"" + #node +=",group=\""+v['external-ip'].replace(".","") + "\"" + #node += "]" + print node + + for con in v.get('to',[]): + label = con['weight'] + w = int(con['weight']) + weight = str(1000 - (((w - 150) * (1000 - 0)) / (1000 -150 )) + 0) + + length = str(float(w)/1500) + #weight = "1000" #str(300/float(con['weight'])) + #weight = str((100/float(con['weight']))) + #weight = str(-1 * (200-100000/int(con['weight']))) + if float(weight) < 0 : + weight= "1" + + #sys.stderr.write(weight + ":"+ length +" %s -> " %k + str(con) + "\n") + edge = " "+k+ " -> " +con['name'] + " [label="+label + " weight="+weight #+ " minlen="+length + if con.get('bidirectional',False): + edge += ",dir=both" + edge += "]" + print edge + +def decode_input(FILE): + return json.load(FILE) +nodes = decode_input(sys.stdin) +nodes = delete_unused_nodes(nodes) +write_digraph(nodes) diff --git a/retiolum/scripts/adv_graphgen/parse_tinc_stats.py b/retiolum/scripts/adv_graphgen/parse_tinc_stats.py new file mode 100755 index 00000000..54dcc4ab --- /dev/null +++ b/retiolum/scripts/adv_graphgen/parse_tinc_stats.py @@ -0,0 +1,185 @@ +#!/usr/bin/python +# -*- coding: utf8 -*- +from BackwardsReader import BackwardsReader +import sys,json +supernodes= [ "kaah","supernode","euer","pa_sharepoint","oxberg" ] +""" TODO: Refactoring needed to pull the edges out of the node structures again, +it should be easier to handle both structures""" +DUMP_FILE = "/krebs/db/availability" +def write_digraph(nodes): + """ + writes the complete digraph in dot format + """ + print ('digraph retiolum {') + #print (' graph [center rankdir=LR packMode="clust"]') + print (' graph [center packMode="clust"]') + print (' node[shape=box,style=filled,fillcolor=grey]') + print (' overlap=false') + generate_stats(nodes) + merge_edges(nodes) + write_stat_node(nodes) + for k,v in nodes.iteritems(): + write_node(k,v) + print ('}') +def dump_graph(nodes): + from time import time + graph = {} + graph['nodes'] = nodes + graph['timestamp'] = time() + f = open(DUMP_FILE,'a') + json.dump(graph,f) + f.write('\n') + f.close() +def write_stat_node(nodes): + ''' Write a `stats` node in the corner + This node contains infos about the current number of active nodes and connections inside the network + ''' + num_conns = 0 + num_nodes = len(nodes) + for k,v in nodes.iteritems(): + num_conns+= len(v['to']) + node_text = " stats_node [label=\"Statistics\\l" + node_text += "Active Nodes: %s\\l" % num_nodes + node_text += "Connections : %s\\l" % num_conns + node_text += "\"" + node_text += ",fillcolor=green" + node_text += "]" + print(node_text) + +def generate_stats(nodes): + """ Generates some statistics of the network and nodes + """ + jlines = [] + try: + f = BackwardsReader(DUMP_FILE) + lines_to_use = 1000 + while True: + if lines_to_use == 0: break + line = f.readline() + if not line: break + jline = json.loads(line) + if not jline['nodes']: continue + + jlines.append(jline) + lines_to_use -=1 + except Exception,e: + sys.stderr.write(str(e)) + for k,v in nodes.iteritems(): + conns = v.get('to',[]) + for c in conns: #sanitize weights + if float(c['weight']) > 9000: c['weight'] = str(9001) + elif float(c['weight']) < 0: c['weight'] = str(0) + v['num_conns'] = len(conns) + v['avg_weight'] = get_node_avg_weight(conns) + v['availability'] = get_node_availability(k,jlines) + sys.stderr.write( "%s -> %f\n" %(k ,v['availability'])) +def get_node_avg_weight(conns): + """ calculates the average weight for the given connections """ + if not conns: + sys.syderr.write("get_node_avg_weight: connection parameter empty") + return 9001 + else: + return sum([float(c['weight']) for c in conns])/len(conns) +def get_node_availability(name,jlines): + """ calculates the node availability by reading the generated dump file + adding together the uptime of the node and returning the time + parms: + name - node name + jlines - list of already parsed dictionaries node archive + """ + begin = last = current = 0 + uptime = 0 + #sys.stderr.write ( "Getting Node availability of %s\n" % name) + for stat in jlines: + if not stat['nodes']: + continue + ts = stat['timestamp'] + if not begin: + begin = last = ts + current = ts + if stat['nodes'].get(name,{}).get('to',[]): + uptime += current - last + else: + pass + #sys.stderr.write("%s offline at timestamp %f\n" %(name,current)) + last = ts + all_the_time = last - begin + try: + return uptime/ all_the_time + except: + return 1 + +def delete_unused_nodes(nodes): + new_nodes = {} + for k,v in nodes.iteritems(): + if v['external-ip'] == "(null)": + continue + if v.get('to',[]): + new_nodes[k] = v + for k,v in new_nodes.iteritems(): + if not [ i for i in v['to'] if i['name'] in new_nodes]: + #del(new_nodes[k]) + del(k) + return new_nodes +def merge_edges(nodes): + """ merge back and forth edges into one + DESTRUCTS the current structure by deleting "connections" in the nodes + """ + for k,v in nodes.iteritems(): + for con in v.get('to',[]): + for i,secon in enumerate(nodes.get(con['name'],{}).get('to',[])): + if k == secon['name']: + del (nodes[con['name']]['to'][i]) + con['bidirectional'] = True + + +def write_node(k,v): + """ writes a single node and its edges + edges are weightet with the informations inside the nodes provided by + tinc + """ + + node = " "+k+"[label=\"" + node += k+"\\l" + node += "availability: %f\\l" % v['availability'] + #node += "avg weight: %.2f\\l" % v['avg_weight'] + if v.has_key('num_conns'): + node += "Num Connects:"+str(v['num_conns'])+"\\l" + node += "external:"+v['external-ip']+":"+v['external-port']+"\\l" + for addr in v.get('internal-ip',['¯\\\\(°_o)/¯']): + node += "internal:"+addr+"\\l" + node +="\"" + if k in supernodes: + node += ",fillcolor=steelblue1" + #node +=",group=\""+v['external-ip'].replace(".","")+"\"" + node += "]" + print node + + for con in v.get('to',[]): + label = con['weight'] + w = int(con['weight']) + weight = str(1000 - (((w - 150) * (1000 - 0)) / (1000 -150 )) + 0) + + length = str(float(w)/1500) + #weight = "1000" #str(300/float(con['weight'])) + #weight = str((100/float(con['weight']))) + #weight = str(-1 * (200-100000/int(con['weight']))) + if float(weight) < 0 : + weight= "1" + + #sys.stderr.write(weight + ":"+ length +" %s -> " %k + str(con) + "\n") + edge = " "+k+ " -> " +con['name'] + "[label="+label + " weight="+weight #+ " minlen="+length + if con.get('bidirectional',False): + edge += ",dir=both" + edge += "]" + print edge + +def decode_input(FILE): + return json.load(FILE) +nodes = decode_input(sys.stdin) +nodes = delete_unused_nodes(nodes) +try: + dump_graph(nodes) +except Exception,e: + sys.stderr.write("Cannot dump graph: %s" % str(e)) +write_digraph(nodes) diff --git a/retiolum/scripts/adv_graphgen/sanitize.sh b/retiolum/scripts/adv_graphgen/sanitize.sh index 2febc54c..50f1659f 100755 --- a/retiolum/scripts/adv_graphgen/sanitize.sh +++ b/retiolum/scripts/adv_graphgen/sanitize.sh @@ -1,17 +1,32 @@ +#!/bin/sh +set -euf +cd $(dirname `readlink -f $0`) GRAPH_SETTER1=dot GRAPH_SETTER2=circo -GRAPH_SETTER3=neato -GRAPH_SETTER3=sfdp -LOG_FILE=/var/log/everything.log +GRAPH_SETTER3='neato -Goverlap=prism ' +GRAPH_SETTER4=sfdp +LOG_FILE=/var/log/syslog +TYPE=svg +TYPE2=png OPENER=/bin/true +DOTFILE=`mktemp` +trap 'rm $DOTFILE' INT TERM +sudo LOG_FILE=$LOG_FILE python tinc_stats.py |\ + python parse_tinc_stats.py > $DOTFILE -sudo pkill -USR2 tincd -sudo sed -n '/tinc.retiolum/{s/.*tinc.retiolum\[[0-9]*\]: //gp}' $LOG_FILE |\ - ./parse.py > retiolum.dot -$GRAPH_SETTER1 -Tpng -o $1retiolum_1.png retiolum.dot -$GRAPH_SETTER2 -Tpng -o $1retiolum_2.png retiolum.dot -$GRAPH_SETTER3 -Tpng -o $1retiolum_3.png retiolum.dot -$GRAPH_SETTER4 -Tpng -o $1retiolum_4.png retiolum.dot -$OPENER retiolum_1.png &>/dev/null -#rm retiolum.dot +i=1 +for setter in dot circo 'neato -Goverlap=prism ' sfdp +do + tmpgraph=`mktemp --tmpdir=$1` + $setter -T$TYPE -o $tmpgraph $DOTFILE + chmod go+rx $tmpgraph + mv $tmpgraph $1/retiolum_$i.$TYPE + i=`expr $i + 1` +done + +#convert -resize 20% $1/retiolum_1.$TYPE $1/retiolum_1.$TYPE2 +#convert -resize 20% $1/retiolum_2.$TYPE $1/retiolum_2.$TYPE2 +#convert -resize 20% $1/retiolum_3.$TYPE $1/retiolum_3.$TYPE2 +#convert -resize 20% $1/retiolum_4.$TYPE $1/retiolum_4.$TYPE2 +rm $DOTFILE diff --git a/retiolum/scripts/adv_graphgen/tinc_stats.py b/retiolum/scripts/adv_graphgen/tinc_stats.py new file mode 100755 index 00000000..d0d47aff --- /dev/null +++ b/retiolum/scripts/adv_graphgen/tinc_stats.py @@ -0,0 +1,83 @@ +#!/usr/bin/python +from BackwardsReader import BackwardsReader +import os +import re +import sys +import json + + +TINC_NETWORK = os.environ.get("TINC_NETWORK","retiolum") +os.environ["LOG_FILE"] +SYSLOG_FILE = os.environ.get("LOG_FILE","/var/log/everything.log") + + +# Tags and Delimiters +TINC_TAG="tinc.%s" % TINC_NETWORK +BEGIN_NODES = "Nodes:" +END_NODES = "End of nodes." +BEGIN_SUBNET = "Subnet list:" +END_SUBNET = "End of subnet list" +BEGIN_EDGES = "Edges:" +END_EDGES = "End of edges." + +def get_tinc_block(log_file): + """ returns an iterateable block from the given log file (syslog) """ + tinc_block = [] + in_block = False + bf = BackwardsReader(log_file) + BOL = re.compile(".*tinc.retiolum\[[0-9]+\]: ") + while True: + line = bf.readline() + if not line: + raise Exception("end of file at log file? This should not happen!") + line = BOL.sub('',line).strip() + + if END_SUBNET in line: + in_block = True + + if not in_block: + continue + + tinc_block.append(line) + + if BEGIN_NODES in line: + break + return reversed(tinc_block) + +def parse_input(log_data): + nodes={} + for line in log_data: + if BEGIN_NODES in line : + nodes={} + for line in log_data: + if END_NODES in line : + break + l = line.replace('\n','').split() #TODO unhack me + nodes[l[0]]= { 'external-ip': l[2], 'external-port' : l[4] } + if BEGIN_SUBNET in line : + for line in log_data: + if END_SUBNET in line : + break + l = line.replace('\n','').split() + if not nodes[l[2]].get('internal-ip',False): + nodes[l[2]]['internal-ip'] = [] + nodes[l[2]]['internal-ip'].append(l[0].split('#')[0]) + if BEGIN_EDGES in line : + edges = {} + for line in 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( + {'name':l[2],'addr':l[4],'port':l[6],'weight' : l[10] }) + return nodes + + +if __name__ == '__main__': + import subprocess,time + subprocess.call(["pkill","-SIGUSR2", "tincd"]) + time.sleep(1) + print json.dumps(parse_input((get_tinc_block(SYSLOG_FILE)))) diff --git a/retiolum/scripts/autostart/Makefile b/retiolum/scripts/autostart/Makefile deleted file mode 100644 index aba6bd33..00000000 --- a/retiolum/scripts/autostart/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -INIT_FOLDER=/etc/init.d -.phony: all -debian: - #TODO change the tinc file before writing - cp tinc /etc/init.d/tinc - chmod +x /etc/init.d - echo "retiolum" > /etc/tinc/nets.boot - update-rc.d tinc defaults -arch: - @cp tinc /etc/rc.d - @chmod +x /etc/rc.d/tinc - @echo "add tinc to DAEMONS in /etc/rc.conf" - - diff --git a/retiolum/scripts/autostart/create-startup.sh b/retiolum/scripts/autostart/create-startup.sh new file mode 100755 index 00000000..37edb972 --- /dev/null +++ b/retiolum/scripts/autostart/create-startup.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +if test "${nosudo-false}" != true -a `id -u` != 0; then + echo "we're going sudo..." >&2 + exec sudo "$0" "$@" + exit 23 # go to hell +fi + +readlink="`readlink -f "$0"`" +dirname="`dirname "$0"`" +cd "$dirname" + +if [ -e /etc/init.d ];then + INIT_FOLDER=/etc/init.d + update-rc.d tinc defaults #TODO debian specific +else + INIT_FOLDER=/etc/rc.d + echo "add tinc to DAEMONS in /etc/rc.conf" #TODO archlinux specific +fi + +echo "retiolum" > /etc/tinc/nets.boot +cp -a tinc $INIT_FOLDER diff --git a/retiolum/scripts/routing/defaultroute.sh b/retiolum/scripts/routing/defaultroute.sh new file mode 100755 index 00000000..d54e8bcf --- /dev/null +++ b/retiolum/scripts/routing/defaultroute.sh @@ -0,0 +1,38 @@ +#!/bin/bash +usage() +{ + echo "usage:" + echo "-h, print this help youre currently reading" + echo "-a activate routing" + echo "-d deactivate routing" +} + +defaultroute=$(ip route show | grep default | awk '{ print $3 }') +tincdir="/etc/tinc/retiolum" + +if [[ $(id -u) -gt 0 ]]; then + echo "This script should be run as root." + exit 1 +fi + +case "$1" in + -h|-help) + usage + exit 0;; + -a) + command="add" + ;; + -d) + command="del" + ;; + -*|*) + usage + exit 1;; +esac + +cat $tincdir/tinc.conf | grep ConnectTo | cut -b 13- | +while read host +do + addr=$(cat $tincdir/hosts/$host | grep Address | cut -b 11-) + route $command $addr gw $defaultroute && echo $command $addr via $defaultroute +done diff --git a/retiolum/scripts/tinc_setup/install.sh b/retiolum/scripts/tinc_setup/install.sh index 9df38df7..a6b50b8a 100755 --- a/retiolum/scripts/tinc_setup/install.sh +++ b/retiolum/scripts/tinc_setup/install.sh @@ -1,11 +1,18 @@ #! /bin/sh # USE WITH GREAT CAUTION +set -eu + +if test "${nosudo-false}" != true -a `id -u` != 0; then + echo "we're going sudo..." >&2 + exec sudo "$0" "$@" + exit 23 # go to hell +fi #make -C ../../ update set -e DIRNAME=`dirname $0` CURR=`readlink -f ${DIRNAME}` -MYBIN=../../bin +MYBIN=${CURR}/../../bin netname=retiolum # create configuration directory for $netname mkdir -p /etc/tinc/$netname/hosts @@ -15,45 +22,50 @@ echo "added known hosts:" ls -1 hosts | LC_ALL=C sort echo "delete the nodes you do not trust!" +hostname="${HOSTNAME-`cat /etc/hostname`}" myname="${1:-}" if [ ! "$myname" ] then - echo "select username: " + printf "select node name [$hostname]: " read myname + if test -z "$myname"; then + myname="$hostname" + fi fi if [ ! -e "hosts/$myname" ] then + + # TODO eloop until we found a free IPv4 + # myipv4=$(echo 42.$(for i in `seq 1 3`; do echo "ibase=16;`bin/fillxx xx|tr [a-f] [A-F]`" | bc; done)|tr \ .)/32 + myipv4="${2:-}" - mynet4=10.7.7.0 + mynet4=10.243.0.0 if [ ! "$myipv4" ] then - echo "select v4 subnet ip (1-255) :" + printf 'select v4 subnet ip (1-255): ' read v4num - myipv4=10.7.7.$v4num - if [ "$v4num" -gt 0 -a "$v4num" -lt "256" ]; - then - echo "check" - else - echo "you are made of stupid. bailing out" - exit 1 - fi + until $MYBIN/check-free-retiolum-v4 $v4num; do + echo "your're an idiot!" + printf 'select unused v4 subnet ip (1-255): ' + read v4num + done + myipv4="10.243.0.$v4num" fi echo "Subnet = $myipv4" > hosts/$myname - myipv6=`${CURR}/../../bin/fillxx 42:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx`/128 + myipv6=`$MYBIN/fillxx 42:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx`/128 echo "Subnet = $myipv6" >> hosts/$myname else echo "own host file already exists! will not write again!" fi -cp $CURR/tinc-up /etc/tinc/$netname/ - cat>tinc.conf<<EOF Name = $myname -ConnectTo = supernode -ConnectTo = kaah +ConnectTo = euer +ConnectTo = oxberg ConnectTo = pa_sharepoint +ConnectTo = supernode Device = /dev/net/tun EOF diff --git a/retiolum/scripts/tinc_setup/tinc-up b/retiolum/scripts/tinc_setup/tinc-up index ae7c68e6..a829528d 100755 --- a/retiolum/scripts/tinc_setup/tinc-up +++ b/retiolum/scripts/tinc_setup/tinc-up @@ -4,17 +4,22 @@ dirname="`dirname "$0"`" conf=$dirname/tinc.conf -name=`sed -rn 's|^ *Name *= *([^ ]*) *$|\1|p' $conf` +name=`sed -n 's|^ *Name *= *\([^ ]*\) *$|\1|p' $conf` host=$dirname/hosts/$name -route4=10.7.7.0/24 -addr4=`sed -rn 's|^ *Subnet *= *(10\.[^ ]*) *$|\1|p' $host` +ip link set $INTERFACE up -route6=42::/16 -addr6=`sed -rn 's|^ *Subnet *= *(42:[^ ]*) *$|\1|p' $host` +addr4=`sed -n 's|^ *Subnet *= *\(10[.][^ ]*\) *$|\1|p' $host` +if [ "$addr4" != '' ];then + ip -4 addr add $addr4 dev $INTERFACE + ip -4 route add 10.243.0.0/16 dev $INTERFACE +else + addr4=`sed -n 's|^ *Subnet *= *\(42[.][^ ]*\) *$|\1|p' $host` + ip -4 addr add $addr4 dev $INTERFACE + ip -4 route add 42.0.0.0/16 dev $INTERFACE +fi -ifconfig $INTERFACE up $addr4 -route add -net $route4 dev $INTERFACE +addr6=`sed -n 's|^ *Subnet *= *\(42[:][^ ]*\) *$|\1|p' $host` ip -6 addr add $addr6 dev $INTERFACE -ip -6 route add $route6 dev $INTERFACE +ip -6 route add 42::/16 dev $INTERFACE diff --git a/retiolum/scripts/tinc_setup/write_channel.py b/retiolum/scripts/tinc_setup/write_channel.py index a11d4605..8299fa8d 100644 --- a/retiolum/scripts/tinc_setup/write_channel.py +++ b/retiolum/scripts/tinc_setup/write_channel.py @@ -3,18 +3,19 @@ import random, sys, time, socket try: myname=sys.argv[1] except: - print "you are made of stupid" + print("you are made of stupid") exit (23) |