113 lines
3.5 KiB
Bash
Executable File
113 lines
3.5 KiB
Bash
Executable File
#!/bin/bash
|
|
source config
|
|
|
|
statuspage() {
|
|
echo "Content-type: text/html"
|
|
echo ""
|
|
echo "<html>"
|
|
echo "<head>"
|
|
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">'
|
|
echo "<style> body { color:black ; background-image: url('background.jpg'); background-repeat: no-repeat; background-size: cover; } .info { display: inline-block; background: white ; margin: 1px; padding: 1px ;} </style>"
|
|
echo "</head>"
|
|
echo "<body>"
|
|
echo "<center>"
|
|
echo '<img id="banner" src="banner.png"><br>'
|
|
if [ "$captcha" != "true" ]
|
|
then
|
|
echo "<span class='box info'>"
|
|
echo "Registration failed, chud."
|
|
echo "<br><br>"
|
|
echo "You need to know the animu girls better."
|
|
echo "<br><br>"
|
|
echo "<a href=$registrationurl/registerform.sh>You have to go back</a>"
|
|
echo $(date +"%Y-%m-%d %H:%M:%S") "$realip" "$login" failed registration with wrong captcha >> /var/log/register/log
|
|
echo "</span>"
|
|
elif [ "$password" != "$retype" ]
|
|
then
|
|
echo "<span class='box info'>"
|
|
echo "Registration failed, chud."
|
|
echo "<br><br>"
|
|
echo "Passwords do not match."
|
|
echo "<br><br>"
|
|
echo "<a href=$registrationurl/registerform.sh>You have to go back</a>"
|
|
|
|
echo "</span>"
|
|
echo $(date +"%Y-%m-%d %H:%M:%S") "$realip" "$login" failed registration with wrong password >> /var/log/register/log
|
|
else
|
|
echo "<pre class='info'>"
|
|
registerscript
|
|
echo "</pre>"
|
|
echo "<br>"
|
|
echo "<span class='box info'>"
|
|
if [[ $regstatus == 0 ]]
|
|
then
|
|
echo "<a href=$elementurl/#/login>Go to Login</a>"
|
|
registercounter
|
|
echo $(date +"%Y-%m-%d %H:%M:%S") "$realip" "$login" has registered >> /var/log/register/log
|
|
else
|
|
echo "<a href=$registrationurl/registerform.sh>You have to go back</a>"
|
|
echo $(date +"%Y-%m-%d %H:%M:%S") "$realip" shit is fucked yo >> /var/log/register/log
|
|
|
|
echo "</span>"
|
|
fi
|
|
fi
|
|
echo "</center>"
|
|
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" "$captchouliurl/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" "$synapse_admin_api"
|
|
regstatus=$?
|
|
unset secret
|
|
}
|
|
|
|
registercounter(){
|
|
date -d '+1 minute' +%s > /tmp/counter
|
|
}
|
|
|
|
ratelimit(){
|
|
currentstamp=$(date +%s)
|
|
if [[ "$currentstamp" < $(cat /tmp/counter) ]]
|
|
then
|
|
# ratelimit
|
|
echo $(cat /tmp/counter)+120 | bc > /tmp/counternew
|
|
mv /tmp/counternew /tmp/counter
|
|
captcha=false
|
|
echo $(date +"%Y-%m-%d %H:%M:%S") $realip ratelimiting until $(date +"%Y-%m-%d %H:%M:%S" -d @$(cat /tmp/counter)) >> /var/log/register/log
|
|
else
|
|
echo $(date +"%Y-%m-%d %H:%M:%S") $realip noratelimit >> /var/log/register/log
|
|
fi
|
|
}
|
|
|
|
# receive post data
|
|
data=$(cat)
|
|
id=$(rawurldecode "$(echo "$data" | cut -d '=' -f 5)" | sed -e 's/"//g')
|
|
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")
|
|
realip=$(env | grep HTTP_X_FORWARDED_FOR | cut -d '=' -f 2 | cut -d ',' -f 1)
|
|
|
|
ratelimit
|
|
statuspage
|
|
|
|
exit 0
|