diff options
author | makefu <github@syntax-fehler.de> | 2014-04-02 11:15:54 +0200 |
---|---|---|
committer | makefu <github@syntax-fehler.de> | 2014-04-02 11:15:54 +0200 |
commit | 732876299f4dccb4caa3a915879d2b5945bbdd42 (patch) | |
tree | 779db4d8f7cfb6223b6d47bd2f157143a48760f8 /elchos/root-image/krebs/lib/network | |
parent | eb83b606a5baadcf35353b5461d2a0e520ecba6c (diff) |
filehooker is now elchOS
Diffstat (limited to 'elchos/root-image/krebs/lib/network')
-rw-r--r-- | elchos/root-image/krebs/lib/network | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/elchos/root-image/krebs/lib/network b/elchos/root-image/krebs/lib/network new file mode 100644 index 00000000..9863a803 --- /dev/null +++ b/elchos/root-image/krebs/lib/network @@ -0,0 +1,100 @@ +#@include core +. /krebs/lib/core + +# TODO refactor this +which_get_loader(){ + if ! exists curl ; then + if ! exists wget ; then + warn "Please install curl or wget" + return 1 + else + echo "wget -q -O-" + fi + else + echo "curl -L -s" + fi + return 0 +} + +which_head_loader(){ + if ! exists curl ; then + if ! exists wget ; then + warn "Please install curl or wget" + return 1 + else + echo "wget -O- --spider -S -q" + fi + else + echo "curl -L -I -s" + fi + return 0 +} + +http_get(){ + eval "$(which_get_loader)" "${1?please provide url}" +} +http_head(){ + eval "$(which_head_loader)" "${1?please provide url}" 2>&1 +} + +internet(){ + secret=$(http_get http://krebsco.de/secret 2>/dev/null) + if [ "$secret" = "1337" ]; then + return 0 + else + echo "cannot load secret or secret incorrect" >&2 + return 1 + fi +} + +which_telnet(){ + # find Telnet or similar and executes it at the end + # requires exist + # if env TELNET is set, will be trying to run this + # Tries the following things: + # telnet + # nc + # netcat + # busybox telnet + if [ -e "${TELNET:-does_not_exist}" ]; then + info "Will be using $TELNET as Telnet Client" + echo $TELNET + elif exists telnet ;then + command -v telnet + elif exists nc ;then + command -v nc + elif exists netcat;then + command -v netcat + elif exists busybox;then + echo `command -v busybox` telnet + else + die 'Cannot find telnet binary, please install either telnet-client or busybox or netcat or provided TELNET environment.' + fi +} + +run_telnet(){ + host="$1" + port="$2" + $(which_telnet) "$host" "$port" +} + +send_irc(){ + ## reads from stdin, writes to IRC + ## + ## requires func: exists() anytelnet() + if [ -z "${HOSTN:-}" ]; then + HOSTN="$(get_hostname)" + info "no HOSTN given, using $HOSTN instead" + fi + IRCCHANNEL=${IRCCHANNEL:-"#krebs_incoming"} + IRCSERVER=${IRCSERVER:-"irc.freenode.net"} + IRCPORT=${IRCPORT:-6667} + NICK="${NICK:-${HOSTN}_$(head /dev/urandom | tr -dc "0123456789" | head -c3)}" + info "starting irc connect as $NICK" + ( echo "NICK $NICK"; + echo "USER $NICK $IRCSERVER bla : $NICK"; + echo "JOIN $IRCCHANNEL"; + sleep 23; + while read line; do echo "PRIVMSG $IRCCHANNEL :$line";sleep 1;done + sleep 5; ) | run_telnet $IRCSERVER $IRCPORT 2>/dev/null +} |