From 3536b602c5e0c5d7e0e6f9a0657a972d199e2a82 Mon Sep 17 00:00:00 2001 From: hnz101 Date: Wed, 17 Jan 2024 14:13:01 +0100 Subject: [PATCH 1/2] Add service URL environment variable for docker When running inside Docker, we cannot determine the correct URL by ourselves. So we need to get it from an external variable. --- README.md | 2 ++ server/inc/API.php | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/README.md b/README.md index dd70de5..e580fea 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,8 @@ services: - type: bind source: ~/docker_files/gpodder/data target: /var/www/server/data + environment: + - gpodder_url=https://gpodder.example.org hostname: gpodder.example.org ports: - 80:80 diff --git a/server/inc/API.php b/server/inc/API.php index f2cace2..6487d12 100644 --- a/server/inc/API.php +++ b/server/inc/API.php @@ -28,6 +28,12 @@ public function __construct(DB $db) $url .= ':' . $_SERVER['SERVER_PORT']; } + // Check if environment variable with service url is set + // When running inside Docker, we cannot determine the correct URL by ourselves. + if (getenv('gpodder_url') !== false) { + $url = getenv('gpodder_url'); + } + $url .= '/'; $this->base_url = $url; } From ea58bcc3fd99e49a6469f2f7c99cd94325590559 Mon Sep 17 00:00:00 2001 From: hnz101 Date: Wed, 17 Jan 2024 14:13:20 +0100 Subject: [PATCH 2/2] fix php 8.1 htmlspecialchars() deprecation --- server/index.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/server/index.php b/server/index.php index 8952a0a..cea9ac3 100644 --- a/server/index.php +++ b/server/index.php @@ -70,12 +70,12 @@ function html_head() { - ' . htmlspecialchars($title) . ' + ' . htmlspecialchars($title ?? '') . ' -

' . htmlspecialchars($title) . '

+

' . htmlspecialchars($title ?? '') . '

'; } @@ -101,11 +101,11 @@ function html_foot() { foreach ($gpodder->listActions((int)$_GET['id']) as $row) { printf('%s%s%s%s', - htmlspecialchars($row->action), - htmlspecialchars($row->device), + htmlspecialchars($row->action ?? ''), + htmlspecialchars($row->device ?? ''), date('d/m/Y H:i', $row->changed), - htmlspecialchars($row->url), - htmlspecialchars(basename($row->url)), + htmlspecialchars($row->url ?? ''), + htmlspecialchars(basename($row->url) ?? ''), ); } } @@ -115,7 +115,7 @@ function html_foot() { foreach ($gpodder->listActiveSubscriptions() as $row) { printf('%s%s%d', $row->id, - htmlspecialchars($row->url), + htmlspecialchars($row->url ?? ''), date('d/m/Y H:i', $row->changed), $row->count ); @@ -153,7 +153,7 @@ function html_foot() { html_head(); if ($error) { - printf('

%s

', htmlspecialchars($error)); + printf('

%s

', htmlspecialchars($error ?? '')); } if (isset($_GET['token'])) { @@ -188,7 +188,7 @@ function html_foot() { echo '

Invalid captcha.

'; } elseif ($error = $gpodder->subscribe($_POST['username'] ?? '', $_POST['password'] ?? '')) { - printf('

%s

', htmlspecialchars($error)); + printf('

%s

', htmlspecialchars($error ?? '')); } else { echo '

Your account is registered.

';