#!/bin/bash [ -z "$NETHELPER_SOCKET" ] && exit 1 send_helper_request () { if [ "$NETHELPER_AUTH" = "cookie" ]; then if [ -z "$NETHELPER_COOKIE" ]; then echo "Failed. There is no cookie to authenticate nethelper." exit 1 fi ( echo "AUTH COOKIE $NETHELPER_COOKIE"; cat ) | nc $NETHELPER_SOCKET else cat | nc $NETHELPER_SOCKET fi } helper_auth_type () { echo "AUTH GETTYPE" | nc $NETHELPER_SOCKET } helper_auth_getcookie () { local walltime=$1 echo "AUTH GENCOOKIE $walltime" | nc $NETHELPER_SOCKET } helper_auth_delcookie () { local cookie=$1 echo "AUTH DELCOOKIE $cookie" | nc $NETHELPER_SOCKET } get_mac () { local leasetime=$1 echo "NETCONFIG LEASEMAC $leasetime" | send_helper_request } free_mac () { local mac=$1 echo "NETCONFIG RELEASEMAC $mac" | send_helper_request } get_local_ip () { local mac=$1 echo "NETCONFIG GETIP $mac" | send_helper_request } get_rdp_forward () { local mac=$1 echo "NETCONFIG GETRDP $mac" | send_helper_request } get_ssh_forward () { local mac=$1 echo "NETCONFIG GETSSH $mac" | send_helper_request } get_port_forward () { local mac=$1 local port=$2 echo "NETCONFIG GETFWD $mac $port" | send_helper_request } helper_ping () { local ip=$1 echo "NETTEST PING $ip" | send_helper_request } helper_mping () { local mac=$1 echo "NETTEST MPING $mac" | send_helper_request } helper_nc () { local ip=$1 local port=$2 echo "NETTEST NC $ip $port" | send_helper_request } helper_mnc () { local mac=$1 local port=$2 echo "NETTEST MNC $mac $port" | send_helper_request } helper_email () { local email=$1 local jobid=$2 shift 2 local data=$* echo -e "NETSEND EMAIL $email $jobid\n$data" | send_helper_request }