Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

Commit

Permalink
add temporary logging for bans (to try to fix a bug)
Browse files Browse the repository at this point in the history
  • Loading branch information
tnix100 authored Nov 7, 2024
1 parent 56a58f6 commit 299e4e1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
7 changes: 6 additions & 1 deletion cloudlink.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import websockets, asyncio, json, time, requests, os
import websockets, asyncio, json, time, requests, os, msgpack
from typing import Optional, Iterable, TypedDict, Literal, Any
from inspect import getfullargspec
from urllib.parse import urlparse, parse_qs

from utils import log, full_stack
from database import rdb

VERSION = "0.1.7.10"

Expand Down Expand Up @@ -261,6 +262,10 @@ def authenticate(self, account: dict[str, Any], token: str, listener: Optional[s

# Check ban
if (account["ban"]["state"] == "perm_ban") or (account["ban"]["state"] == "temp_ban" and account["ban"]["expires"] > time.time()):
rdb.publish("admin", msgpack.packb({
"op": "log",
"data": f"**Banned (Cloudlink)**\n@{account['_id']} ({account['uuid']})\nBan: {account['ban']}"
}))
self.send("banned", account["ban"], listener=listener)
return self.send_statuscode("Banned", listener)

Expand Down
10 changes: 8 additions & 2 deletions rest_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
from quart_cors import cors
from quart_schema import QuartSchema, RequestSchemaValidationError, validate_headers, hide
from pydantic import BaseModel
import time, os
import time, os, msgpack

from .v0 import v0


from .admin import admin_bp

from database import db, blocked_ips, registration_blocked_ips
from database import db, rdb, blocked_ips, registration_blocked_ips
import security


Expand Down Expand Up @@ -68,6 +68,7 @@ async def check_auth(headers: TokenHeader):
if hasattr(request, "internal_username") and request.internal_username: # internal auth
account = db.usersv0.find_one({"_id": request.internal_username}, projection={
"_id": 1,
"uuid": 1,
"flags": 1,
"permissions": 1,
"ban.state": 1,
Expand All @@ -76,6 +77,7 @@ async def check_auth(headers: TokenHeader):
elif headers.token: # external auth
account = db.usersv0.find_one({"tokens": headers.token}, projection={
"_id": 1,
"uuid": 1,
"flags": 1,
"permissions": 1,
"ban.state": 1,
Expand All @@ -84,6 +86,10 @@ async def check_auth(headers: TokenHeader):

if account:
if account["ban"]["state"] == "perm_ban" or (account["ban"]["state"] == "temp_ban" and account["ban"]["expires"] > time.time()):
rdb.publish("admin", msgpack.packb({
"op": "log",
"data": f"**Banned (REST API)**\n@{account['_id']} ({account['uuid']})\nInternal username: {getattr(request, "internal_username")}\nBan: {account['ban']}"
}))
return {"error": True, "type": "accountBanned"}, 403
request.user = account["_id"]
request.flags = account["flags"]
Expand Down
5 changes: 5 additions & 0 deletions supporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ def listen_for_admin_pubsub(self):
# Logout user (can't kick because of async stuff)
for c in self.cl.usernames.get(username, []):
c.logout()

case "log": # this is a temp thing
try:
self.create_post("6b69fd4b-41bb-4a2d-9591-1c6c0ea4941a", "Server", msg["data"], chat_members=["Tnix"])
except: pass
except:
continue

Expand Down

0 comments on commit 299e4e1

Please sign in to comment.