synapse-registration-bash/do-register.sh

102 lines
2.4 KiB
Bash
Executable File

#!/bin/bash
registered() {
echo "Content-type: text/html"
echo ""
echo "<html>"
echo "<head>"
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">'
echo "</head>"
echo "<body>"
echo "<pre>"
registerscript
echo "</pre>"
echo "<br>"
if [[ $regstatus == 0 ]]
then
echo "<a href=https://matrix.midov.pl/#/login>Go to Login</a>"
else
echo "<a href=https://midov.pl/registerform.sh>Go back</a>"
fi
echo "</body>"
echo "</html>"
}
registerfailed() {
echo "Content-type: text/html"
echo ""
echo "<html>"
echo "<head>"
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">'
echo "</head>"
echo "<body>"
echo "Registration failed, chud."
echo "<br>"
echo "You need to know the animu girls better."
echo "<br>"
echo "<a href=https://midov.pl/registerform.sh>Go back</a>"
echo "<br>"
echo "</body>"
echo "</html>"
}
passwordsdonotmatch() {
echo "Content-type: text/html"
echo ""
echo "<html>"
echo "<head>"
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">'
echo "</head>"
echo "<body>"
echo "Registration failed, chud."
echo "<br>"
echo "Passwords do not match."
echo "<br>"
echo "<a href=https://midov.pl/registerform.sh>Go back</a>"
echo "<br>"
echo "</body>"
echo "</html>"
}
rawurldecode() {
# All escape characters must be encoded, we can replace %NN with \xNN and pass the lot to printf -b,
# which will decode hex
printf -v REPLY '%b' "${1//%/\\x}"
echo "${REPLY}"
}
checkcaptchouli() {
curl --silent -XPOST --data "captchouli-id=$1" http://mugi.midov.pl/status
}
registerscript() {
# contains the secret variable with the shared secret thing for synapse
source ~/.secret
# script from synapse.. should have curled the api but i did not want to deal with the nonces
~/register_new_matrix_user.py -u "$login" -p "$password" --no-admin -k $secret http://yoshika.midov.pl:8008
regstatus=$?
unset secret
}
data=$(cat)
id=$(rawurldecode $(echo "$data" | cut -d '=' -f 5))
login=$(rawurldecode $(echo "$data" | cut -d '=' -f 2 | cut -d '&' -f 1))
password=$(rawurldecode $(echo "$data" | cut -d '=' -f 3 | cut -d '&' -f 1))
retype=$(rawurldecode $(echo "$data" | cut -d '=' -f 4 | cut -d '&' -f 1))
# returns true or false depending if user passed or not
captcha=$(checkcaptchouli "$id")
if [ "$captcha" != "true" ]
then
registerfailed
elif [ "$password" != "$retype" ]
then
passwordsdonotmatch
else
registered
fi
registrationpage
exit 0