diff options
author | tv <tv@nomic.retiolum> | 2013-11-05 12:45:53 +0100 |
---|---|---|
committer | tv <tv@nomic.retiolum> | 2013-11-05 12:45:53 +0100 |
commit | 3d7e7118aee40a2a7070e503307bdb07fe3bfc49 (patch) | |
tree | 942140a91ea23fcb4438f4f206d4bd4a598995a9 /ship/lib/network | |
parent | d5dcf81c04353fad721a0d36d7fc14b50d47583a (diff) | |
parent | 3060d3c4ce12fae2e8b754f13d0e227af2134ab5 (diff) |
Merge remote-tracking branch 'confmagic/master'
Diffstat (limited to 'ship/lib/network')
-rw-r--r-- | ship/lib/network | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/ship/lib/network b/ship/lib/network new file mode 100644 index 00000000..9d7ea197 --- /dev/null +++ b/ship/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 +} |