Skip to content

Commit

Permalink
Feat: add Whitelist of IPs/hosts to disable login notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
erfjab committed Sep 1, 2024
1 parent b551447 commit b6d2658
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ UVICORN_PORT = 8000
# NOTIFY_IF_DAYS_LEF_REACHED = True
# NOTIFY_LOGIN = True

## Whitelist of IPs/hosts to disable login notifications
# LOGIN_WHITE_LIST = '1.1.1.1,sub.domain.com,127.0.0.1'

### for developers
# DOCS=True
# DEBUG=True
Expand Down
6 changes: 4 additions & 2 deletions app/routers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from fastapi.security import OAuth2PasswordRequestForm
from app.utils import report
from app.dependencies import validate_admin, get_admin_by_username

from config import LOGIN_WHITE_LIST

router = APIRouter(tags=['Admin'], prefix='/api')

Expand Down Expand Up @@ -41,7 +41,9 @@ def admin_token(
headers={"WWW-Authenticate": "Bearer"},
)

report.login(form_data.username, '🔒', client_ip, True)
if client_ip not in LOGIN_WHITE_LIST:
report.login(form_data.username, '🔒', client_ip, True)

return Token(
access_token=create_admin_token(
form_data.username,
Expand Down
1 change: 1 addition & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
GRPC_USER_AGENT_TEMPLATE = config("GRPC_USER_AGENT_TEMPLATE", default="user_agent/grpc.json")

EXTERNAL_CONFIG = config("EXTERNAL_CONFIG", default="", cast=str)
LOGIN_WHITE_LIST = [ip.strip() for ip in config("LOGIN_WHITE_LIST", default="", cast=str).split(",") if ip.strip()]

USE_CUSTOM_JSON_DEFAULT = config("USE_CUSTOM_JSON_DEFAULT", default=False, cast=bool)
USE_CUSTOM_JSON_FOR_V2RAYN = config("USE_CUSTOM_JSON_FOR_V2RAYN", default=False, cast=bool)
Expand Down

0 comments on commit b6d2658

Please sign in to comment.