From d7538b950efdc2a202b5ce043d2f65da2d49f2df Mon Sep 17 00:00:00 2001 From: Herwin Date: Mon, 15 May 2023 18:50:30 +0200 Subject: [PATCH] Added ENV variables for all config, Fixed error in cleaner script Update cleaner.py, docker-compose.yml, and 2 more files... --- cleaner.py | 12 ++++-- docker-compose.yml | 5 +++ htdocs/index.php | 28 ++++++++----- readme.md | 101 +++++++++++++++++++++++++++++++++------------ 4 files changed, 106 insertions(+), 40 deletions(-) diff --git a/cleaner.py b/cleaner.py index b8379c2..4a4a392 100644 --- a/cleaner.py +++ b/cleaner.py @@ -3,8 +3,14 @@ import signal import sys import time -# Keep files for 73 hours (3 days + 1 hours) -MAX_FILE_AGE_SECONDS = (72 + 1) * 60 * 60 +# Keep files for 72 hours (3 days) +try: + MAX_FILE_AGE_SECONDS = int(os.environ.get('NP_MAX_FILE_AGE_HOURS', "72")) * 60 * 60 +except err: + print("Error: ") + print(err) + print("Using 72 hours instead !") + MAX_FILE_AGE_SECONDS = 72 * 60 * 60 # Once done cleaning, sleep for 5 minutes SLEEP_TIME_SECONDS = 5 * 60 @@ -37,7 +43,7 @@ start_time = time.time() file_deleted_count = 0 for item in os.listdir("/data/"): - item_path = os.path.join(folder_path, item) + item_path = os.path.join("/data/", item) if os.path.isdir(item_path): file_deleted_count = file_deleted_count + delete_old_files(item_path, start_time) diff --git a/docker-compose.yml b/docker-compose.yml index e285bb8..cc84c98 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -32,6 +32,7 @@ services: dockerfile: Dockerfile_cleaner environment: - TZ=Europe/Brussels + - "NP_MAX_FILE_AGE_HOURS=72" volumes: - ./recordings:/data - ./cleaner.py:/app/app.py:ro @@ -43,6 +44,10 @@ services: ports: - 26880:80 environment: + - "NP_CAM_cam1=Camera #1" + - "NP_CAM_cam2=Camera #2" + - "NP_TITLE=NibblePoker's Mini CCTV NVR" + - "NP_FOOTER=Made by BOZET Herwin" - TZ=Europe/Brussels volumes: - ./htdocs:/var/www/html # Cannot be "ro" since the recordings are mounted into it. diff --git a/htdocs/index.php b/htdocs/index.php index f09b4fc..63cc70c 100644 --- a/htdocs/index.php +++ b/htdocs/index.php @@ -1,10 +1,17 @@ $envValue) { + if (strpos($envKey, 'NP_CAM_') === 0) { + array_push($camsInfo, [substr($envKey, strlen('NP_CAM_')), $envValue]); + } +} + +// Grabbing the other env variables. +$pageTitle = $_ENV['NP_TITLE'] ?? 'NibblePoker\'s Mini CCTV NVR'; +$pageFooter = $_ENV['NP_FOOTER'] ?? 'Made by BOZET Herwin on Github'; // Root location of all recordings. (Not used yet) $rootLocation = "./data/"; @@ -102,7 +109,7 @@ function sizeFormat($bytes) { - NibblePoker's Mini CCTV NVR + <?php echo($pageTitle); ?>