summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/network49
1 files changed, 49 insertions, 0 deletions
diff --git a/lib/network b/lib/network
new file mode 100644
index 00000000..9d7ea197
--- /dev/null
+++ b/lib/network
@@ -0,0 +1,49 @@
+#!/bin/sh
+#include core
+
+anytelnet(){
+ # 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"
+ elif exists telnet ;then
+ TELNET="$(command -v telnet)"
+ elif exists nc ;then
+ TELNET="$(command -v nc)"
+ elif exists netcat;then
+ TELNET="$(command -v netcat)"
+ elif exists busybox;then
+ TELNET="$(command -v busybox) telnet"
+ else
+ error "Cannot find telnet binary, please install either telnet-client or busybox or netcat or provided TELNET environment.\nbailing out!"
+ return 1
+ fi
+ $TELNET $@
+}
+
+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; ) | anytelnet $IRCSERVER $IRCPORT 2>/dev/null | line_to_dot
+}