ratelimiting

This commit is contained in:
Midov 2023-04-03 09:50:45 +02:00
parent e3ace52726
commit 5f6b5d86cc

View File

@ -19,7 +19,8 @@ statuspage() {
echo "<br><br>"
echo "You need to know the animu girls better."
echo "<br><br>"
echo "<a href=$registrationurl/registerform.sh>Go back</a>"
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
@ -28,9 +29,10 @@ statuspage() {
echo "<br><br>"
echo "Passwords do not match."
echo "<br><br>"
echo "<a href=$registrationurl/registerform.sh>Go back</a>"
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
@ -40,8 +42,11 @@ statuspage() {
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>Go back</a>"
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
@ -72,17 +77,36 @@ registerscript() {
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)")
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