summaryrefslogtreecommitdiffstats
path: root/filehooker/root-image/krebs/lib/network
diff options
context:
space:
mode:
authormakefu <github@syntax-fehler.de>2014-03-17 07:51:03 +0100
committermakefu <github@syntax-fehler.de>2014-03-17 07:51:03 +0100
commit1fa15dd59e7dc58f4331305b9f401d3aabfa53cd (patch)
tree6e4ee2f1096652276b86f4b9334fa06aafdb38bf /filehooker/root-image/krebs/lib/network
parent536bfe6d1e3cce27b6a84d4c19f7feafac690b53 (diff)
filehooker: initial commit
using archiso magic scripts
Diffstat (limited to 'filehooker/root-image/krebs/lib/network')
-rw-r--r--filehooker/root-image/krebs/lib/network100
1 files changed, 100 insertions, 0 deletions
diff --git a/filehooker/root-image/krebs/lib/network b/filehooker/root-image/krebs/lib/network
new file mode 100644
index 00000000..df2ae153
--- /dev/null
+++ b/filehooker/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="${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
+}