Add simple web interface to paste a page URL
authorChristian Weiske <cweiske@cweiske.de>
Wed, 6 Mar 2019 20:21:21 +0000 (21:21 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Wed, 6 Mar 2019 20:21:21 +0000 (21:21 +0100)
www/form.php [new file with mode: 0644]
www/functions.php
www/play.php

diff --git a/www/form.php b/www/form.php
new file mode 100644 (file)
index 0000000..460864e
--- /dev/null
@@ -0,0 +1,49 @@
+<?php
+$dreamboxUrlNoAuth = preg_replace('#//[^@]+@#', '//', $dreamboxUrl);
+?>
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+  <title>playVideoOnDreamboxProxy</title>
+  <meta name="author" content="Christian Weiske"/>
+  <meta name="generator" content="playVideoOnDreamboxProxy"/>
+ </head>
+ <body>
+  <h1>playVideoOnDreamboxProxy</h1>
+  <p>
+   This proxy application allows you to play videos on your Dreambox;
+   either direct video URLs or videos linked in HTML pages.
+  </p>
+  <p>
+   You may use the
+   <a href="https://cweiske.de/playVideoOnDreambox.htm#android">Android app</a>
+   or the
+   <a href="https://cweiske.de/playVideoOnDreambox.htm#firefox">Firefox browser extension</a>
+   to control it directly.
+  </p>
+
+
+  <h2>Video URL input</h2>
+  <p>
+   Enter the URL of a video or a web site that contains a video:
+  </p>
+  <form method="post" action="">
+   <input type="url" name="url" required="" autofocus=""
+          placeholder="URL"
+          size="40"/>
+   <button type="submit">Play on Dreambox</button>
+  </form>
+  <p>
+   Video will be played on
+   <a href="<?= $dreamboxUrlNoAuth ?>"><?= $dreamboxUrlNoAuth ?></a>.
+  </p>
+
+
+  <hr/>
+  <p>
+   Licensed under the
+   <a href="http://www.gnu.org/licenses/agpl.html">AGPL v3+</a>.
+   <a href="https://cweiske.de/playVideoOnDreambox.htm">Homepage</a>.
+  </p>
+ </body>
+</html>
index b094e36e042c6b417551a0692aa80088957a59f5..6ad1044e27273a404c0ed571536eb184be80a219 100644 (file)
@@ -7,14 +7,21 @@ function getPageUrl()
             errorInput('No URL given as command line parameter');
         }
         $pageUrl = $argv[1];
             errorInput('No URL given as command line parameter');
         }
         $pageUrl = $argv[1];
-    } else {
-        if (!isset($_SERVER['CONTENT_TYPE'])) {
-            errorInput('Content type header missing');
-        } else if ($_SERVER['CONTENT_TYPE'] != 'text/plain') {
-            errorInput('Content type is not text/plain but ' . $_SERVER['CONTENT_TYPE']);
-        }
+    } else if (!isset($_SERVER['CONTENT_TYPE'])) {
+        errorInput('Content type header missing');
+    } else if ($_SERVER['CONTENT_TYPE'] == 'text/plain') {
+        //Android app
         $pageUrl = file_get_contents('php://input');
         $pageUrl = file_get_contents('php://input');
+    } else if ($_SERVER['CONTENT_TYPE'] == 'application/x-www-form-urlencoded') {
+        //Web form
+        if (!isset($_POST['url'])) {
+            errorInput('"url" POST parameter missing');
+        }
+        $pageUrl = $_POST['url'];
+    } else {
+        errorInput('Content type is not text/plain but ' . $_SERVER['CONTENT_TYPE']);
     }
     }
+
     $parts = parse_url($pageUrl);
     if ($parts === false) {
         errorInput('Invalid URL in POST data');
     $parts = parse_url($pageUrl);
     if ($parts === false) {
         errorInput('Invalid URL in POST data');
index 810995123a9881030249c296421364ec3b657b45..502e3f24ce50c1b703fea9ce6cb73609b6def223 100644 (file)
@@ -8,6 +8,11 @@ if (file_exists($cfgFile)) {
     include $cfgFile;
 }
 
     include $cfgFile;
 }
 
+if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'GET') {
+    require __DIR__ . '/form.php';
+    exit();
+}
+
 set_error_handler('errorHandlerStore');
 
 $pageUrl  = getPageUrl();
 set_error_handler('errorHandlerStore');
 
 $pageUrl  = getPageUrl();