commit 068d73cf8dcd7b6cb680d02bea641fbc4d5ca7bb
parent e64ea00b531055f5f1bc22eb1bbfd208a35e238e
Author: JayVii <jayvii[AT]posteo[DOT]de>
Date: Sat, 20 Apr 2024 14:41:52 +0200
Implement authentification
Diffstat:
2 files changed, 37 insertions(+), 4 deletions(-)
diff --git a/env.php b/env.php
@@ -0,0 +1,14 @@
+<?php
+/*
+* SPDX-FileCopyrightText: 2024 JayVii <jayvii[AT]posteo[DOT]de>
+* SPDX-License-Identifier: AGPL-3.0-or-later
+*/
+
+/* Authentification Key.
+* If set, videos and feeds can only be loaded if auth key matches.
+* Set to null if it should not be used.
+*/
+//$auth_key="f7331f90cb24e34c8cfd59e3ad46bbe1";
+$auth_key=null;
+
+?>
diff --git a/index.php b/index.php
@@ -4,6 +4,10 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
+if (file_exists("./env.php")) {
+ include "./env.php";
+}
+
function analyze_video($video_file) {
include_once("3rdparty/getid3/getid3/getid3.php");
$getID3 = new getID3;
@@ -11,7 +15,14 @@ function analyze_video($video_file) {
return $video_info;
}
-if (!is_null($_GET["channel"])) {
+// Authentification
+if ($_GET["auth"] != $auth_key && !is_null($auth_key)) {
+ $auth = false;
+} else {
+ $auth = true;
+}
+
+if (!is_null($_GET["channel"]) && $auth) {
// Fetch Youtube XML Feed
$channel_xml = file(
@@ -135,7 +146,7 @@ if (!is_null($_GET["channel"])) {
header("Content-type: application/xml");
print_r($rss_xml);
-} else if (!is_null($_GET["video"])) {
+} else if (!is_null($_GET["video"]) && $auth) {
$download_retry = 0;
while (
!file_exists(basename($_GET["video"]) . ".opus") &&
@@ -175,10 +186,18 @@ if (!is_null($_GET["channel"])) {
echo "<html><head><title>yt2rss</title></head><body>";
echo "<h1>yt2rss</h1>";
echo "<p><a href=\"https://codeberg.org/jayvii/yt2rss\">Learn more</a></p>";
- echo "<p>Usage:</p><ul>";
+ echo "<p>Usage:</p>";
+ echo "<ul>";
echo "<li>https://" . $_SERVER["SERVER_NAME"] .
"/?channel=UCt_Y3j8CpXx366et1RaHACA</li>";
echo "<li>https://" . $_SERVER["SERVER_NAME"] . "/?video=TV8tEq56vHI</li>";
- echo "</ul></body></html>";
+ echo "</ul>";
+ if (!is_null($auth_key)) {
+ echo "<p>This Service requires an authnetification key." .
+ "If you have one, add it to the request URLs with " .
+ "\"&auth=MY_KEY\". " .
+ "If you do not have one (yet), please contact the server admin.";
+ }
+ echo "</body></html>";
}
?>