From 54ca7f3b130bb792d97ef73b1734f13b448de1ba Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 9 Nov 2020 13:49:43 -0500 Subject: [PATCH 1/3] Handle SSDP data error --- fHDHR/device/ssdp.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fHDHR/device/ssdp.py b/fHDHR/device/ssdp.py index 812dc42..a38ce47 100644 --- a/fHDHR/device/ssdp.py +++ b/fHDHR/device/ssdp.py @@ -108,7 +108,11 @@ class SSDPServer(): (host, port) = address - header, payload = data.decode().split('\r\n\r\n')[:2] + try: + header, payload = data.decode().split('\r\n\r\n')[:2] + except ValueError: + self.logger.error("Error with Received packet from {}: {}".format(address, data)) + return lines = header.split('\r\n') cmd = lines[0].split(' ') From 50f724489ebc4773bdb78f8a27772e548a53fcdd Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 9 Nov 2020 14:10:35 -0500 Subject: [PATCH 2/3] Add Version Information and Warnings --- fHDHR/config/__init__.py | 21 ++++++++++++++++++++- fHDHR/http/pages/version_html.py | 22 ++++++++++------------ fHDHR/tools/__init__.py | 13 +++++++++++++ 3 files changed, 43 insertions(+), 13 deletions(-) diff --git a/fHDHR/config/__init__.py b/fHDHR/config/__init__.py index 3b3ec39..e4a7257 100644 --- a/fHDHR/config/__init__.py +++ b/fHDHR/config/__init__.py @@ -4,9 +4,10 @@ import configparser import pathlib import logging import subprocess +import platform import fHDHR.exceptions -from fHDHR.tools import isint, isfloat, is_arithmetic +from fHDHR.tools import isint, isfloat, is_arithmetic, is_docker class Config(): @@ -158,6 +159,22 @@ class Config(): if self.dict["fhdhr"]["stream_type"] not in ["direct", "ffmpeg"]: raise fHDHR.exceptions.ConfigurationError("Invalid stream type. Exiting...") + opersystem = platform.system() + self.dict["main"]["opersystem"] = opersystem + if opersystem in ["Linux", "Darwin"]: + # Linux/Mac + if os.getuid() == 0 or os.geteuid() == 0: + print('Warning: Do not run fHDHR with root privileges.') + elif opersystem in ["Windows"]: + # Windows + if os.environ.get("USERNAME") == "Administrator": + print('Warning: Do not run fHDHR as Administrator.') + else: + print("Uncommon Operating System, use at your own risk.") + + isdocker = is_docker() + self.dict["main"]["isdocker"] = isdocker + if self.dict["fhdhr"]["stream_type"] == "ffmpeg": try: ffmpeg_command = [self.dict["ffmpeg"]["ffmpeg_path"], @@ -173,6 +190,8 @@ class Config(): except FileNotFoundError: ffmpeg_version = None self.dict["ffmpeg"]["version"] = ffmpeg_version + else: + self.dict["ffmpeg"]["version"] = "N/A" if not self.dict["fhdhr"]["discovery_address"] and self.dict["fhdhr"]["address"] != "0.0.0.0": self.dict["fhdhr"]["discovery_address"] = self.dict["fhdhr"]["address"] diff --git a/fHDHR/http/pages/version_html.py b/fHDHR/http/pages/version_html.py index 7483851..fcb54b5 100644 --- a/fHDHR/http/pages/version_html.py +++ b/fHDHR/http/pages/version_html.py @@ -31,20 +31,18 @@ class Version_HTML(): fakefile.write(" \n") fakefile.write(" \n") - fakefile.write(" \n") - fakefile.write(" %s\n" % ("fHDHR")) - fakefile.write(" %s\n" % (str(self.fhdhr.version))) - fakefile.write(" \n") + table_guts = [ + ["fHDHR", self.fhdhr.version], + ["Python", sys.version], + ["Operating System", self.fhdhr.config.dict["main"]["opersystem"]], + ["Using Docker", self.fhdhr.config.dict["main"]["isdocker"]], + ["ffmpeg", self.fhdhr.config.dict["ffmpeg"]["version"]] + ] - fakefile.write(" \n") - fakefile.write(" %s\n" % ("Python")) - fakefile.write(" %s\n" % (str(sys.version))) - fakefile.write(" \n") - - if self.fhdhr.config.dict["fhdhr"]["stream_type"] == "ffmpeg": + for item in table_guts: fakefile.write(" \n") - fakefile.write(" %s\n" % ("ffmpeg")) - fakefile.write(" %s\n" % (str(self.fhdhr.config.dict["ffmpeg"]["version"]))) + fakefile.write(" %s\n" % (str(item[0]))) + fakefile.write(" %s\n" % (str(item[1]))) fakefile.write(" \n") for line in page_elements["end"]: diff --git a/fHDHR/tools/__init__.py b/fHDHR/tools/__init__.py index 8bafb55..33daf32 100644 --- a/fHDHR/tools/__init__.py +++ b/fHDHR/tools/__init__.py @@ -1,3 +1,5 @@ +import os +import re import ast import requests import xml.etree.ElementTree @@ -6,6 +8,17 @@ UNARY_OPS = (ast.UAdd, ast.USub) BINARY_OPS = (ast.Add, ast.Sub, ast.Mult, ast.Div, ast.Mod) +def is_docker(): + path = "/proc/self/cgroup" + if not os.path.isfile(path): + return False + with open(path) as f: + for line in f: + if re.match("\d+:[\w=]+:/docker(-[ce]e)?/\w+", line): + return True + return False + + def sub_el(parent, name, text=None, **kwargs): el = xml.etree.ElementTree.SubElement(parent, name, **kwargs) if text: From b0e5de9d439b1886547e62796f6c325a11a2c700 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Mon, 9 Nov 2020 14:31:05 -0500 Subject: [PATCH 3/3] Ensure spawn on Windows --- fHDHR/cli/run.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fHDHR/cli/run.py b/fHDHR/cli/run.py index 0790ec6..773cbf0 100644 --- a/fHDHR/cli/run.py +++ b/fHDHR/cli/run.py @@ -37,6 +37,10 @@ def run(settings, logger, db): fhdhr = fHDHR_OBJ(settings, logger, db) fhdhrweb = fHDHR_HTTP_Server(fhdhr) + # Ensure spawn on Windows instead of fork + if settings.dict["main"]["opersystem"] in ["Windows"]: + multiprocessing.set_start_method('spawn') + try: print("HTTP Server Starting")