summaryrefslogtreecommitdiffstats
path: root/ship/lib/network
blob: 9d7ea1970763b4010e17a8c48e3db6e34eabd567 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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
}