diff --git a/frigate/const.py b/frigate/const.py index 1cc14293e..d7dd8f197 100644 --- a/frigate/const.py +++ b/frigate/const.py @@ -9,4 +9,5 @@ PLUS_API_HOST = "https://api.frigate.video" # Regex Consts 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]+" diff --git a/frigate/http.py b/frigate/http.py index 5b67575e1..22d96f2d6 100644 --- a/frigate/http.py +++ b/frigate/http.py @@ -577,9 +577,14 @@ def events(): def config(): config = current_app.frigate_config.dict() - # add in the ffmpeg_cmds for camera_name, camera in current_app.frigate_config.cameras.items(): 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) for cmd in camera_dict["ffmpeg_cmds"]: cmd["cmd"] = clean_camera_user_pass(" ".join(cmd["cmd"])) diff --git a/frigate/util.py b/frigate/util.py index e6a5df4e6..9f7f419bf 100755 --- a/frigate/util.py +++ b/frigate/util.py @@ -20,7 +20,7 @@ import numpy as np import os 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__) @@ -718,14 +718,16 @@ def load_labels(path, encoding="utf-8"): def clean_camera_user_pass(line: str) -> str: """Removes user and password from line.""" - # todo also remove http password like reolink - return re.sub(REGEX_CAMERA_USER_PASS, "://*:*@", line) + if line.startswith("rtsp://"): + 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: """Cleans reserved characters to encodings for ffmpeg.""" 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) :] return path.replace(pw, urllib.parse.quote_plus(pw)) except AttributeError: