summaryrefslogtreecommitdiffstats
path: root/retiolum/scripts
diff options
context:
space:
mode:
authormakefu <github@syntax-fehler.de>2013-03-07 11:40:38 +0100
committermakefu <github@syntax-fehler.de>2013-03-07 11:40:38 +0100
commit7fa8fb85b072f612adb322f8a02617e1bd737020 (patch)
tree683df8268baae71451633518aa7ff7ea258a4aa8 /retiolum/scripts
parentdbe2d838ba6834788265029162b2dd7d82473335 (diff)
parentef4eb3189363f5cd9a33b43693322a68d3142979 (diff)
Merge branch 'master' of github.com:krebscode/painload
Diffstat (limited to 'retiolum/scripts')
-rwxr-xr-xretiolum/scripts/adv_graphgen/anonytize.sh6
-rw-r--r--retiolum/scripts/adv_graphgen/find_super14
-rw-r--r--retiolum/scripts/adv_graphgen/find_super.py43
-rwxr-xr-xretiolum/scripts/adv_graphgen/parse_tinc_stats.py8
-rwxr-xr-xretiolum/scripts/adv_graphgen/sanitize.sh6
-rwxr-xr-xretiolum/scripts/tinc_setup/install.sh2
-rwxr-xr-xretiolum/scripts/tinc_setup/new_install.sh159
7 files changed, 85 insertions, 153 deletions
diff --git a/retiolum/scripts/adv_graphgen/anonytize.sh b/retiolum/scripts/adv_graphgen/anonytize.sh
index b31f4dbb..2e2045e4 100755
--- a/retiolum/scripts/adv_graphgen/anonytize.sh
+++ b/retiolum/scripts/adv_graphgen/anonytize.sh
@@ -9,8 +9,8 @@ LOG_FILE=${LOG_FILE:-/var/log/syslog}
TYPE=svg
TYPE2=png
OPENER=/bin/true
-DOTFILE=`mktemp`
-trap 'rm $DOTFILE' INT TERM
+DOTFILE=`mktemp --suffix=anon`
+trap 'rm $DOTFILE' INT TERM KILL
sudo -E python tinc_stats2json |\
python parse_tinc_anon.py> $DOTFILE
@@ -24,7 +24,7 @@ do
mv $tmpgraph $1/retiolum_$i.$TYPE
i=`expr $i + 1`
done
-#convert -resize 20% $1/retiolum_1.$TYPE $1/retiolum_1.$TYPE2
+convert $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
diff --git a/retiolum/scripts/adv_graphgen/find_super b/retiolum/scripts/adv_graphgen/find_super
deleted file mode 100644
index c89a94fb..00000000
--- a/retiolum/scripts/adv_graphgen/find_super
+++ /dev/null
@@ -1,14 +0,0 @@
-#!/bin/sh
-cd /etc/tinc/retiolum/hosts
-ls -1 . | while read fname;
-do
- for i in `sed -n 's/Address\s*=\s*\(.*\)/\1/p' $fname`;do
- if nc -zw 5 $i 655 2>/dev/null; then
- echo "$fname - $i reachable"
- #else
- #echo -n
- #echo "$fname - $i unreachable"
-
- fi
- done
-done
diff --git a/retiolum/scripts/adv_graphgen/find_super.py b/retiolum/scripts/adv_graphgen/find_super.py
index df01734e..ae0fae8f 100644
--- a/retiolum/scripts/adv_graphgen/find_super.py
+++ b/retiolum/scripts/adv_graphgen/find_super.py
@@ -1,6 +1,6 @@
#!/usr/bin/python
-def find_super(path="/etc/tinc/retiolum/hosts"):
+def find_potential_super(path="/etc/tinc/retiolum/hosts"):
import os
import re
@@ -23,28 +23,37 @@ def find_super(path="/etc/tinc/retiolum/hosts"):
if addrs : yield (f ,[(addr ,int(port)) for addr in addrs])
-def check_super(path="/etc/tinc/retiolum/hosts"):
- from socket import socket,AF_INET,SOCK_STREAM
- for host,addrs in find_super(path):
+def try_connect(addr):
+ try:
+ from socket import socket,AF_INET,SOCK_STREAM
+ s = socket(AF_INET,SOCK_STREAM)
+ s.settimeout(2)
+ s.connect(addr)
+ s.settimeout(None)
+ s.close()
+ return addr
+ except Exception as e:
+ pass
+ #return ()
+
+def check_one_super(ha):
+ host,addrs = ha
valid_addrs = []
for addr in addrs:
- try:
- s = socket(AF_INET,SOCK_STREAM)
- s.settimeout(3)
- s.connect(addr)
- #print("success connecting %s:%d"%(addr))
- s.settimeout(None)
- s.close()
- valid_addrs.append(addr)
- except Exception as e:
- pass
- #print("cannot connect to %s:%d"%(addr))
- if valid_addrs: yield (host,valid_addrs)
+ ret = try_connect(addr)
+ if ret: valid_addrs.append(ret)
+ if valid_addrs: return (host,valid_addrs)
+
+def check_all_the_super(path="/etc/tinc/retiolum/hosts"):
+ from multiprocessing import Pool
+ p = Pool(20)
+ return filter(None,p.map(check_one_super,find_potential_super(path)))
+
if __name__ == "__main__":
"""
usage
"""
- for host,addrs in check_super():
+ for host,addrs in check_all_the_super():
print host,addrs
diff --git a/retiolum/scripts/adv_graphgen/parse_tinc_stats.py b/retiolum/scripts/adv_graphgen/parse_tinc_stats.py
index 76a3ffcd..e5bd96a8 100755
--- a/retiolum/scripts/adv_graphgen/parse_tinc_stats.py
+++ b/retiolum/scripts/adv_graphgen/parse_tinc_stats.py
@@ -2,7 +2,7 @@
# -*- coding: utf8 -*-
from BackwardsReader import BackwardsReader
import sys,json
-from find_super import check_super
+from find_super import check_all_the_super
try:
from time import time
import socket
@@ -18,7 +18,7 @@ except Exception as e:
sys.stderr.write("Cannot connect to graphite: %s\n" % str(e))
supernodes= [ ]
-for supernode,addr in check_super():
+for supernode,addr in check_all_the_super():
supernodes.append(supernode)
""" TODO: Refactoring needed to pull the edges out of the node structures again,
it should be easier to handle both structures"""
@@ -39,6 +39,7 @@ def write_digraph(nodes):
for k,v in nodes.iteritems():
write_node(k,v)
print ('}')
+
def dump_graph(nodes):
from time import time
graph = {}
@@ -48,6 +49,7 @@ def dump_graph(nodes):
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
@@ -95,6 +97,7 @@ def generate_stats(nodes):
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:
@@ -143,6 +146,7 @@ def delete_unused_nodes(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
diff --git a/retiolum/scripts/adv_graphgen/sanitize.sh b/retiolum/scripts/adv_graphgen/sanitize.sh
index 45d29a22..846cc549 100755
--- a/retiolum/scripts/adv_graphgen/sanitize.sh
+++ b/retiolum/scripts/adv_graphgen/sanitize.sh
@@ -9,8 +9,8 @@ LOG_FILE=${LOG_FILE:-/var/log/syslog}
TYPE=svg
TYPE2=png
OPENER=/bin/true
-DOTFILE=`mktemp`
-trap 'rm $DOTFILE' INT TERM
+DOTFILE=`mktemp --suffix=san`
+trap 'rm $DOTFILE' INT TERM KILL
sudo -E python tinc_stats2json |\
python parse_tinc_stats.py > $DOTFILE
@@ -25,7 +25,7 @@ do
i=`expr $i + 1`
done
-#convert -resize 20% $1/retiolum_1.$TYPE $1/retiolum_1.$TYPE2
+convert $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
diff --git a/retiolum/scripts/tinc_setup/install.sh b/retiolum/scripts/tinc_setup/install.sh
index a72d2b8b..9efe863c 100755
--- a/retiolum/scripts/tinc_setup/install.sh
+++ b/retiolum/scripts/tinc_setup/install.sh
@@ -65,7 +65,7 @@ Name = $myname
ConnectTo = euer
ConnectTo = albi10
ConnectTo = pigstarter
-ConnectTo = supernode
+ConnectTo = slowpoke
Device = /dev/net/tun
EOF
diff --git a/retiolum/scripts/tinc_setup/new_install.sh b/retiolum/scripts/tinc_setup/new_install.sh
index 85a61be8..1ff42e54 100755
--- a/retiolum/scripts/tinc_setup/new_install.sh
+++ b/retiolum/scripts/tinc_setup/new_install.sh
@@ -12,9 +12,10 @@ SUBNET4=${SUBNET4:-10.243}
SUBNET6=${SUBNET6:-42}
TEMPDIR=${TEMPDIR:-auto}
TINCDIR=${TINCDIR:-auto}
+exists() { type "$1" >/dev/null 2>/dev/null; }
-if type hostname >/dev/null ;then SYSHOSTN=${HOSTNAME:-$(hostname)}
-elif type uci >/dev/null ;then SYSHOSTN=$(uci get system.@system[0].hostname)
+if exists hostname ;then SYSHOSTN=${HOSTNAME:-$(hostname)}
+elif exists uci ;then SYSHOSTN=$(uci get system.@system[0].hostname)
elif [ -e /etc/hostname ] ;then SYSHOSTN=$(cat /etc/hostname)
else SYSHOSTN="unknown"
fi
@@ -28,7 +29,7 @@ RMASK=${RMASK:-255.255.0.0}
URL=${URL:-http://euer.krebsco.de/retiolum/hosts.tar.gz}
SURL=${SURL:-http://euer.krebsco.de/retiolum/supernodes.tar.gz}
-IRCCHANNEL=${IRCCHANNEL:-"#krebsco"}
+IRCCHANNEL=${IRCCHANNEL:-"#krebs"}
IRCSERVER=${IRCSERVER:-"irc.freenode.net"}
IRCPORT=${IRCPORT:-6667}
@@ -40,30 +41,6 @@ IP6=${IP6:-0}
RAND4=1
RAND6=1
-usage()
-{
-cat << EOF
-usage $0 options
-This script gets you into the KREBS Darknet
-all parameters are optional
-
-Options:
- -h Show this message(haha)
- -4 \$ipv4 specify an ip(version 4), this also disables random ip mode, default is random
- -6 \$ipv6 specify an ip(version 6), this also disables random ip mode, default is random
- -s \$SUBNET Choose another Subnet(version4), default is 10.243
- -x \$SUBNET Choose another Subnet(version6), default is 42
- -m \$MASK Choose another Subnet Mask(version4), default is 16
- -j \$MASK Choose another Subnet Mask(version6), default is 16
- -t \$DIR Choose another Temporary directory, default is /tmp/tinc-install-fu
- -o \$HOST Choose another Hostname, default is your system hostname
- -n \$NET Choose another tincd netname,this also specifies the path to your tinc config, default is retiolum
- -u \$URL specify another hostsfiles.tar.gz url, default is http://euer.krebsco.de/retiolum/hosts.tar.gz
- -l \$OS specify an OS, numeric parameter.0=Automatic 1=Linux 2=Android, disables automatic OS-finding, default is 0
- -r \$ADDR give the node an reachable remote address, ipv4 or dns
-EOF
-}
-
#convert hostmask to subnetmask only version 4
host2subnet()
{
@@ -129,14 +106,16 @@ get_hostname()
find_os()
{
if grep -qe 'Linux' /etc/*release 2>/dev/null || grep -qe 'Linux' /etc/issue 2>/dev/null; then
- OS=1
- elif type getprop >/dev/null; then
- OS=2
+ OS='linux'
+ elif exists getprop ; then
+ OS='android'
elif test -e /etc/openwrt_release; then
- OS=3
+ OS='openwrt'
+ elif uname -s | grep -qi 'darwin'; then
+ OS='osx'
else
echo "Cannot determine your operating system, falling back to Linux"
- OS=1
+ OS='linux'
fi
}
@@ -159,13 +138,13 @@ if [ $OS -eq 0 ]; then
fi
#check if everything is installed
-if ! type awk >/dev/null; then
+if ! exists awk ; then
echo "Please install awk"
exit 1
fi
-if ! type curl >/dev/null; then
- if ! type wget >/dev/null; then
+if ! exists curl ; then
+ if ! exists wget ; then
echo "Please install curl or wget"
exit 1
else
@@ -180,90 +159,38 @@ if ! $(ping -c 1 -W 5 euer.krebsco.de 1>/dev/null) ;then
exit 1
fi
-
-#parse options
-while getopts "h4:6:s:x:m:j:t:o:n:u:l:" OPTION
-do
- case $OPTION in
- h)
- usage
- exit 1
- ;;
- 4)
- IP4=$OPTARG
- RAND4=0
- if ! check_ip_valid4 $IP4; then echo "ipv4 is invalid" && exit 1; fi
- ;;
- 6)
- IP6=$OPTARG
- RAND6=0
- if ! check_ip_valid6 $IP6; then echo "ipv6 is invalid" && exit 1; fi
- ;;
- s)
- SUBNET4=$OPTARG
- ;;
- x)
- SUBNET6=$OPTARG
- ;;
- m)
- MASK4=$OPTARG
- ;;
- j)
- MASK6=$OPTARG
- ;;
- t)
- TEMPDIR=$OPTARG
- ;;
- o)
- HOSTN=$OPTARG
- ;;
- n)
- NETNAME=$OPTARG
- ;;
- u)
- URL=$OPTARG
- if $(! curl -s --head $URL | head -n 1 | grep "HTTP/1.[01] [23].." > /dev/null); then
- echo "url not reachable"
- exit 1
- fi
- ;;
- l)
- OS=$OPTARG
- if ! [ "$(echo $OS | awk -F"." ' $0 ~ /^[0-2]$/' )" == $OS ]; then
- echo "invalid input for OS"
- exit 1
- fi
- ;;
- r)
- ADDR=$OPTARG
- ;;
-
- esac
-done
-
-#check for OS
-if [ $OS -eq 0 ]; then
- find_os
-fi
-
#check if everything is installed
-if [ $OS -eq 2 ]; then
+if [ $OS = 'android' ]; then
if ! test -e /data/data/org.poirsouille.tinc_gui/files/tincd; then
echo "Please install tinc-gui"
exit 1
else
TINCBIN=/data/data/org.poirsouille.tinc_gui/files/tincd
- if [ $TINCDIR = 'auto' ]; then TINCDIR=/usr/local/etc/tinc ;fi
- if [ $TEMPDIR = 'auto' ]; then TEMPDIR=/data/secure/data ;fi
+ DEV="/dev/tun"
+ if [ $TINCDIR = 'auto' ]; then TINCDIR="/usr/local/etc/tinc" ;fi
+ if [ $TEMPDIR = 'auto' ]; then TEMPDIR="/storage/sdcard0/tinc-fu" ;fi
+ mount -o remount,rw /
+ mount -o remount,rw /system
+ fi
+elif [ $OS = 'osx' ]; then
+ if ! exists tincd >/dev/null; then
+ echo "Please install tinc"
+ exit 1
+ else
+ TINCBIN=tincd
+ DEV="/dev/net/tun"
+ if [ $TINCDIR = 'auto' ]; then TINCDIR="/usr/local/etc/tinc" ;fi
+ if [ $TEMPDIR = 'auto' ]; then TEMPDIR="/tmp/tinc-install-fu" ;fi
fi
else
- if ! type tincd >/dev/null; then
+ if ! exists tincd >/dev/null; then
echo "Please install tinc"
exit 1
else
TINCBIN=tincd
- if [ $TINCDIR = 'auto' ]; then TINCDIR=/etc/tinc ;fi
- if [ $TEMPDIR = 'auto' ]; then TEMPDIR=/tmp/tinc-install-fu ;fi
+ DEV="/dev/net/tun"
+ if [ $TINCDIR = 'auto' ]; then TINCDIR="/etc/tinc" ;fi
+ if [ $TEMPDIR = 'auto' ]; then TEMPDIR="/tmp/tinc-install-fu" ;fi
fi
fi
@@ -319,7 +246,7 @@ get_hostname $HOSTN
mkdir -p $TINCDIR/$NETNAME
cd $TINCDIR/$NETNAME
-if [ $OS -eq 3 ]; then
+if [ $OS = 'openwrt' ]; then
mkdir hosts
$LOADER $SURL | tar xz -C hosts/
else
@@ -333,14 +260,14 @@ echo "Subnet = $IP6" >> hosts/$HOSTN
cat>tinc.conf<<EOF
Name = $HOSTN
-Device = /dev/net/tun
+Device = $DEV
#newer tinc features
LocalDiscovery = yes
AutoConnect = 3
#ConnectTos
-ConnectTo = supernode
+ConnectTo = slowpoke
ConnectTo = pigstarter
ConnectTo = pico
EOF
@@ -348,7 +275,7 @@ EOF
host2subnet $MASK4
#check if ip is installed
-if type ip >/dev/null; then
+if exists ip >/dev/null; then
echo 'dirname="`dirname "$0"`"' > tinc-up
echo '' >> tinc-up
echo 'conf=$dirname/tinc.conf' >> tinc-up
@@ -382,16 +309,22 @@ fi
#fix permissions
chmod +x tinc-up
-chown -R root:root .
+chown -R 0:0 .
#generate keys with tinc
-if type tincctl >/dev/null; then
+if exists tincctl ; then
yes | tincctl -n $NETNAME generate-keys
cat rsa_key.pub >> hosts/$HOSTN
else
yes | $TINCBIN -n $NETNAME -K
fi
+if [ $OS = 'android' ]; then
+ mkdir /etc/tinc
+ cd /
+ mv $TINCDIR/$NETNAME /etc/tinc/
+ cd /etc/tinc/$NETNAME
+fi
#write to irc-channel
NICK="${HOSTN}_$(head /dev/urandom | tr -dc "0123456789" | head -c3)"