Skip to content

Commit 3f0858a

Browse files
committed
fix: 修复漏洞
1 parent 59d4aaf commit 3f0858a

8 files changed

Lines changed: 21 additions & 16 deletions

File tree

core/classes.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
from aiohttp import web
55
from tqdm import tqdm
66
from typing import Union
7+
from multidict import MultiMapping
8+
from aiohttp.client_exceptions import ClientResponseError
79
import io
10+
import aiohttp
811

912

1013
@dataclass
@@ -53,4 +56,4 @@ async def express(self,
5356

5457
@abstractmethod
5558
async def recycleFiles(self, files: FileList) -> None:
56-
pass
59+
pass

core/cluster.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ async def checkStorages(self) -> bool:
542542
await asyncio.gather(*(storage.check() for storage in self.storages))
543543
)
544544

545-
def readLong(self, stream: io.BytesIO):
545+
def readLong(self, stream: io.BytesIO) -> int:
546546
result, shift = 0, 0
547547
while True:
548548
byte = ord(stream.read(1))
@@ -552,5 +552,5 @@ def readLong(self, stream: io.BytesIO):
552552
shift += 7
553553
return (result >> 1) ^ -(result & 1)
554554

555-
def readString(self, stream: io.BytesIO):
555+
def readString(self, stream: io.BytesIO) -> str:
556556
return stream.read(self.readLong(stream)).decode()

core/config.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def __init__(self, path: str) -> None:
3434
for key, value in defaults.items():
3535
self.set(key, value)
3636

37-
def load(self):
37+
def load(self) -> None:
3838
with open(self.file, "r", encoding="utf-8") as f:
3939
self.cfg = yaml.load(f.read(), Loader=yaml.FullLoader) or {}
4040

@@ -52,20 +52,20 @@ def set(self, key: str, value: Any):
5252
self._setValue(self.cfg, key.split("."), value)
5353
self.save()
5454

55-
def save(self):
55+
def save(self) -> None:
5656
self.file.parent.mkdir(parents=True, exist_ok=True)
5757
with open(self.file, "w", encoding="utf-8") as f:
5858
yaml.dump(data=self.cfg, stream=f, allow_unicode=True)
5959

60-
def _getValue(self, dict_obj, keys):
60+
def _getValue(self, dict_obj, keys) -> dict | None:
6161
for key in keys:
6262
if key in dict_obj:
6363
dict_obj = dict_obj[key]
6464
else:
6565
return None
6666
return dict_obj
6767

68-
def _setValue(self, dict_obj, keys, value):
68+
def _setValue(self, dict_obj, keys, value) -> None:
6969
for _, key in enumerate(keys[:-1]):
7070
if key not in dict_obj:
7171
dict_obj[key] = {}

core/i18n.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def __getitem__(self, key: str):
1616
def __contains__(self, key: str):
1717
return key in self.data
1818

19-
def load(self):
19+
def load(self) -> None:
2020
with open(self.path, "r", encoding="utf-8") as f:
2121
d = f.read()
2222
self.data = json.loads(d)

core/logger.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
from loguru import logger as Logger, Record
1+
from loguru import logger as Logger
22
from pathlib import Path
3-
import sys
43
from core.config import Config
54
from core.i18n import locale
5+
import sys
6+
67

78
basic_logger_format = "<green>[{time:YYYY-MM-DD HH:mm:ss}]</green><level>[{level}]<yellow>[{name}:{function}:{line}]</yellow>: {message}</level>"
89
debug_mode = Config.get("advanced.debug")
910

1011

11-
def filter(record: Record) -> bool:
12+
def filter(record) -> bool:
1213
if record["name"] and "apscheduler" in record["name"]:
1314
record["extra"] = {"depth": 2}
1415
return True

core/orm.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from datetime import timedelta, datetime
44
from calendar import monthrange
55
from typing import List, Dict
6+
from re import Match
67
import time
78
import re
89

@@ -44,8 +45,8 @@ def writeHits(hits: int, bytes: int) -> None:
4445

4546

4647
def writeAgent(agent: str, hits: int) -> None:
47-
agent = re.match(r"^(.*?)/", agent).group(1)
48-
if agent not in ["bmclapi-ctrl", "bmclapi-warden"]:
48+
regex = re.match(r"^(.*?)/", agent) or Match()
49+
if regex.group(1) not in ["bmclapi-ctrl", "bmclapi-warden"]:
4950
agent_info = session.get(AgentInfo, agent)
5051
if agent_info:
5152
agent_info.hits += hits

core/router.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def init(self) -> None:
3939
@self.route.get("/download/{hash}")
4040
async def _(
4141
request: web.Request,
42-
) -> web.Response:
42+
) -> Union[web.Response, web.FileResponse]:
4343
self.connection += 1
4444
writeAgent(request.headers["User-Agent"], 1)
4545
file_hash = request.match_info.get("hash", "").lower()

installer/installer.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fi
3535
MIRROR_PREFIX="https://ghproxy.bugungu.top/"
3636
echo "MIRROR_PREFIX=${MIRROR_PREFIX}"
3737

38-
REPO='TTB-Network/python-openbmclapi'
38+
REPO='TTB-Network/python-openbmclapi-v2'
3939
RAW_PREFIX="${MIRROR_PREFIX}https://raw.githubusercontent.com"
4040
RAW_REPO="$RAW_PREFIX/$REPO"
4141
BASE_PATH=/opt/python-openbmclapi
@@ -77,7 +77,7 @@ function fetchBlob(){
7777
target=$2
7878
filemod=$3
7979

80-
source="$RAW_REPO/master/$file"
80+
source="$RAW_REPO/main/$file"
8181
echo -e "\e[34m==> Downloading $source\e[0m"
8282
tmpf=$(mktemp -t python-openbmclapi.XXXXXXXXXXXX.downloading)
8383
curl -fsSL -o "$tmpf" "$source" || { rm "$tmpf"; return 1; }

0 commit comments

Comments
 (0)