Compare commits

...
2 Commits
Author SHA1 Message Date
fram3d 8caf2bddbc fix import and checking ratelimit in routes 2026-10-24 04:14:33 +02:00
fram3d bcd0b10a2d add ratelimiting to README 2026-10-24 04:06:30 +02:00
2 changed files with 5 additions and 1 deletions

No files matched your search

+3
View File
@@ -9,6 +9,7 @@ A lightweight user management system for LDAP, implemented using Flask. This app
- **User Unregistration**: Users can remove themselves from the LDAP system. - **User Unregistration**: Users can remove themselves from the LDAP system.
- **Captcha Protection**: Uses a custom captcha mechanism to mitigate bot registrations. - **Captcha Protection**: Uses a custom captcha mechanism to mitigate bot registrations.
- **LDAP Integration**: Directly interacts with LDAP for all credential and user management tasks. - **LDAP Integration**: Directly interacts with LDAP for all credential and user management tasks.
- **Rate limiting** (new): Setting rate limiting for user registration.
## Prerequisites ## Prerequisites
@@ -37,6 +38,8 @@ A lightweight user management system for LDAP, implemented using Flask. This app
- `LDAPPASS`: Admin password for LDAP operations. - `LDAPPASS`: Admin password for LDAP operations.
- `USERBASE`: The base DN for users. - `USERBASE`: The base DN for users.
- `CAPTCHA_PATH`: Path where captcha images are stored. - `CAPTCHA_PATH`: Path where captcha images are stored.
- `PERIOD`: Time period after which the rate limiting counter resets
- `LIMIT`: Number of allowed user registrations in the given time PERIOD
4. **Setup Captcha script**: 4. **Setup Captcha script**:
Ensure the `captcha.sh` script is available in `/usr/local/bin/` and is executable. Ensure the `captcha.sh` script is available in `/usr/local/bin/` and is executable.
+2 -1
View File
@@ -1,6 +1,7 @@
from flask import render_template, request, redirect from flask import render_template, request, redirect
from luser import app from luser import app
from luser.models import LUSER from luser.models import LUSER
from luser.models import ratelimit
from passlib.hash import ldap_salted_sha1,sha512_crypt from passlib.hash import ldap_salted_sha1,sha512_crypt
import subprocess import subprocess
import random import random
@@ -88,7 +89,7 @@ def unregister():
@app.route('/account/register/', methods=['POST', 'GET']) @app.route('/account/register/', methods=['POST', 'GET'])
def register(): def register():
rl = ratelimit(PERIOD, LIMIT, "/var/luser/luser/.ratelimit") rl = ratelimit(PERIOD, LIMIT, "/var/luser/luser/.ratelimit")
if rl.check(1): if rl.check(1) == False:
return 'Error: rate limit exceeded, please come again in ' + PERIOD return 'Error: rate limit exceeded, please come again in ' + PERIOD
if request.method == 'GET': if request.method == 'GET':
captcha_solution = str(random.randint(0,999999)) captcha_solution = str(random.randint(0,999999))