diff options
| -rw-r--r-- | cholerab/ENTERPRISE_PATTERN (renamed from cholerab/pattern/README) | 16 | ||||
| -rwxr-xr-x | retiolum/bin/announce_pubkey | 35 | ||||
| -rw-r--r-- | retiolum/doc/cronjob | 4 | ||||
| -rwxr-xr-x | retiolum/scripts/tinc_setup/install.sh | 2 | ||||
| -rwxr-xr-x | retiolum/scripts/tinc_setup/new_install.sh | 158 | ||||
| -rw-r--r-- | retiolum/scripts/tinc_setup/write_channel.py | 27 | 
6 files changed, 214 insertions, 28 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/doc/cronjob b/retiolum/doc/cronjob index 356b5c96..3f640311 100644 --- a/retiolum/doc/cronjob +++ b/retiolum/doc/cronjob @@ -1,3 +1,7 @@  cron-eintrag fuer automatisches hosts-update +ueberschreibt keine bearbeitete host-dateien  if ping -c 1 euer.krebsco.de -W 5 &>/dev/null; then (curl http://euer.krebsco.de/retiolum/hosts.tar.gz | tar xzk -C /etc/tinc/retiolum/hosts/);fi + +ueberschreibt bearbeitete hostdateien +if ping -c 1 euer.krebsco.de -W 5 &>/dev/null; then (curl http://euer.krebsco.de/retiolum/hosts.tar.gz | tar xz -C /etc/tinc/retiolum/hosts/);fi 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/new_install.sh b/retiolum/scripts/tinc_setup/new_install.sh new file mode 100755 index 00000000..ab42aedc --- /dev/null +++ b/retiolum/scripts/tinc_setup/new_install.sh @@ -0,0 +1,158 @@ +#!/bin/sh + +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 + -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 + -s \$SUBNET Choose another Subnet(version4), default is 10.243. + -m \$MASK   Choose another Subnet Mask(version4), default is /16 + -u \$URL    specify another hostsfiles.tar.gz url, default is euer.krebsco.de/retiolum/hosts.tar.gz +EOF +} + +#check if ip is valid ipv4 function +check_ip_valid4() +{ +    if [ "$(echo $1 | awk -F"\." ' $0 ~ /^([0-9]{1,3}\.){3}[0-9]{1,3}$/ && $1 <=255 && $2 <= 255 && $3 <= 255 && $4 <= 255 ' 2>/dev/null)" == "$1" ] && [ ${1:0:${#SUBNET4}} == $SUBNET4 ] +    then +        return 0 +    else +        return 1 +    fi +} + +#check if ip is taken function +check_ip_taken() +{ +    if grep -q -E "$1(#|/)" $TEMPDIR/hosts/* ;then +        echo $1 is taken +        return 1 +    else +        echo $1 seems free +        return 0 +    fi +} + +#if hostname is taken, count upwards until it isn't taken function +check_hostname() +{ +    TSTFILE=$TEMPDIR/hosts/$1 +    LCOUNTER=0 +    if test -e $TSTFILE; then +        while test -e $TSTFILE; do +            let LCOUNTER=LCOUNTER+1 +            TSTFILE=$TEMPDIR/hosts/$1$LCOUNTER +        done +        HOSTN=$1$LCOUNTER +    else +        HOSTN=$1 +    fi +} + +TEMPDIR=/tmp/tinc-install-fu +HOSTN=$(hostname) +NETNAME=retiolum +SUBNET4=10.243. +MASK4=/16 +RAND=1 +URL=euer.krebsco.de/retiolum/hosts.tar.gz + +#check if everything is installed +if $(! test -e "/usr/sbin/tincd"); then +    echo "Please install tinc" +    exit 1 +fi + +if $(! test -e /usr/bin/awk); then +    echo "Please install awk" +    exit 1 +fi + +if $(! test -e /usr/bin/curl); then +    echo "Please install curl" +    exit 1 +fi + +if $(! /bin/ping -c 1 euer.krebsco.de -W 5 &>/dev/null) ;then +    echo "Cant reach euer, check if your internet is working" +    exit 1 +fi + + +#parse options +while getopts "h4:t:o:n:s:m:u:" OPTION +do +    case $OPTION in +        h) +            usage +            exit 1 +            ;; +        4) +            IP4=$OPTARG +            RAND=0 +            if ! check_ip_valid4 $IP4; then echo "ip is invalid" && exit 1; fi +            ;; +        t) +            TEMPDIR=$OPTARG +            ;; +        o) +            HOSTN=$OPTARG +            ;; +        n) +            NETNAME=$OPTARG +            ;; +        s) +            SUBNET4=$OPTARG +            ;; +        m) +            MASK4=$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 +            ;; + +    esac +done + +#test if tinc directory already exists +if test -e /etc/tinc/$NETNAME; then +    echo "tinc config directory /etc/tinc/$NETNAME does already exist. (backup and) delete config directory and restart" +    exit 1 +fi + +#get tinc-hostfiles +mkdir -p $TEMPDIR/hosts +curl euer.krebsco.de/retiolum/hosts.tar.gz | tar zx -C $TEMPDIR/hosts/ + +#check for free ip +until check_ip_taken $IP4; do +    if [ $RAND -eq 1 ]; then +        IP4="10.243.$((RANDOM%255)).$((RANDOM%255))" +    else +        printf 'choose new ip: ' +        read IP4 +        while !  check_ip_valid4 $IP4; do +            printf 'the ip is invalid, retard, choose a valid ip: ' +            read IP4 +        done +    fi +done + +#check for free hostname +check_hostname $HOSTN + +echo "your ip is $IP4" +echo "your hostname is $HOSTN" 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()  | 
