mirror of
https://github.com/blakeblackshear/frigate.git
synced 2024-11-21 19:07:46 +01:00
Clean http password, clean path in debug config as well (#4519)
* Clean ffmpeg paths * Clean http passwords too * Make check optional
This commit is contained in:
parent
047c2408d2
commit
68248cc274
@ -9,4 +9,5 @@ PLUS_API_HOST = "https://api.frigate.video"
|
|||||||
# Regex Consts
|
# Regex Consts
|
||||||
|
|
||||||
REGEX_CAMERA_NAME = "^[a-zA-Z0-9_-]+$"
|
REGEX_CAMERA_NAME = "^[a-zA-Z0-9_-]+$"
|
||||||
REGEX_CAMERA_USER_PASS = ":\/\/[a-zA-Z0-9_-]+:[\S]+@"
|
REGEX_RTSP_CAMERA_USER_PASS = ":\/\/[a-zA-Z0-9_-]+:[\S]+@"
|
||||||
|
REGEX_HTTP_CAMERA_USER_PASS = "user=[a-zA-Z0-9_-]+&password=[\S]+"
|
||||||
|
@ -577,9 +577,14 @@ def events():
|
|||||||
def config():
|
def config():
|
||||||
config = current_app.frigate_config.dict()
|
config = current_app.frigate_config.dict()
|
||||||
|
|
||||||
# add in the ffmpeg_cmds
|
|
||||||
for camera_name, camera in current_app.frigate_config.cameras.items():
|
for camera_name, camera in current_app.frigate_config.cameras.items():
|
||||||
camera_dict = config["cameras"][camera_name]
|
camera_dict = config["cameras"][camera_name]
|
||||||
|
|
||||||
|
# clean paths
|
||||||
|
for input in camera_dict.get("ffmpeg", {}).get("inputs", []):
|
||||||
|
input["path"] = clean_camera_user_pass(input["path"])
|
||||||
|
|
||||||
|
# add clean ffmpeg_cmds
|
||||||
camera_dict["ffmpeg_cmds"] = copy.deepcopy(camera.ffmpeg_cmds)
|
camera_dict["ffmpeg_cmds"] = copy.deepcopy(camera.ffmpeg_cmds)
|
||||||
for cmd in camera_dict["ffmpeg_cmds"]:
|
for cmd in camera_dict["ffmpeg_cmds"]:
|
||||||
cmd["cmd"] = clean_camera_user_pass(" ".join(cmd["cmd"]))
|
cmd["cmd"] = clean_camera_user_pass(" ".join(cmd["cmd"]))
|
||||||
|
@ -20,7 +20,7 @@ import numpy as np
|
|||||||
import os
|
import os
|
||||||
import psutil
|
import psutil
|
||||||
|
|
||||||
from frigate.const import REGEX_CAMERA_USER_PASS
|
from frigate.const import REGEX_HTTP_CAMERA_USER_PASS, REGEX_RTSP_CAMERA_USER_PASS
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -718,14 +718,16 @@ def load_labels(path, encoding="utf-8"):
|
|||||||
|
|
||||||
def clean_camera_user_pass(line: str) -> str:
|
def clean_camera_user_pass(line: str) -> str:
|
||||||
"""Removes user and password from line."""
|
"""Removes user and password from line."""
|
||||||
# todo also remove http password like reolink
|
if line.startswith("rtsp://"):
|
||||||
return re.sub(REGEX_CAMERA_USER_PASS, "://*:*@", line)
|
return re.sub(REGEX_RTSP_CAMERA_USER_PASS, "://*:*@", line)
|
||||||
|
else:
|
||||||
|
return re.sub(REGEX_HTTP_CAMERA_USER_PASS, "user=*&password=*", line)
|
||||||
|
|
||||||
|
|
||||||
def escape_special_characters(path: str) -> str:
|
def escape_special_characters(path: str) -> str:
|
||||||
"""Cleans reserved characters to encodings for ffmpeg."""
|
"""Cleans reserved characters to encodings for ffmpeg."""
|
||||||
try:
|
try:
|
||||||
found = re.search(REGEX_CAMERA_USER_PASS, path).group(0)[3:-1]
|
found = re.search(REGEX_RTSP_CAMERA_USER_PASS, path).group(0)[3:-1]
|
||||||
pw = found[(found.index(":") + 1) :]
|
pw = found[(found.index(":") + 1) :]
|
||||||
return path.replace(pw, urllib.parse.quote_plus(pw))
|
return path.replace(pw, urllib.parse.quote_plus(pw))
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
|
Loading…
Reference in New Issue
Block a user