Handle dreambox web interface authentication errors
authorChristian Weiske <cweiske@cweiske.de>
Tue, 13 Nov 2018 19:50:48 +0000 (20:50 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Tue, 13 Nov 2018 19:50:48 +0000 (20:50 +0100)
www/functions.php
www/play.php

index 43c3a7771a6148cc38800303d93f0e651c12230c..36aacec10baca5f000e7d9c218bfb4f75467ead5 100644 (file)
@@ -95,7 +95,21 @@ function playVideoOnDreambox($videoUrl, $dreamboxHost)
     ini_set('track_errors', 1);
     $xml = @file_get_contents('http://' . $dreamboxHost . '/web/session');
     if ($xml === false) {
     ini_set('track_errors', 1);
     $xml = @file_get_contents('http://' . $dreamboxHost . '/web/session');
     if ($xml === false) {
-        errorOut('Failed to fetch dreambox session token: ' . $php_errormsg);
+        list($http, $code, $message) = explode(
+            ' ', $http_response_header[0], 3
+        );
+        if ($code == 401) {
+            //dreambox web interface authentication has been enabled
+            errorOut(
+                'Error: Web interface authentication is required',
+                '401 Dreambox web authentication required'
+            );
+        } else {
+            errorOut(
+                'Failed to fetch dreambox session token: ' . $php_errormsg,
+                $code . ' ' . $message
+            );
+        }
     }
     $sx = simplexml_load_string($xml);
     $token = (string) $sx;
     }
     $sx = simplexml_load_string($xml);
     $token = (string) $sx;
index 5d631a00f1cef370e9e3b95f7d610f886d7ae009..36f3e6c56e7009e02144f488b9d675f943d28eb3 100644 (file)
@@ -21,18 +21,22 @@ playVideoOnDreambox($videoUrl, $dreamboxHost);
 
 function errorInput($msg)
 {
 
 function errorInput($msg)
 {
-    header('HTTP/1.0 400 Bad Request');
-    header('Content-type: text/plain');
+    if (!headers_sent()) {
+        header('HTTP/1.0 400 Bad Request');
+        header('Content-type: text/plain');
+    }
     echo $msg . "\n";
     exit(1);
 }
 
 function errorOut($msg, $httpStatus = '500 Internal Server Error')
 {
     echo $msg . "\n";
     exit(1);
 }
 
 function errorOut($msg, $httpStatus = '500 Internal Server Error')
 {
-    header('HTTP/1.0 ' . $httpStatus);
-    header('Content-type: text/plain');
+    if (!headers_sent()) {
+        header('HTTP/1.0 ' . $httpStatus);
+        header('Content-type: text/plain');
+    }
     echo $msg . "\n";
     syslog(LOG_ERR, 'playVideoOnDreamboxProxy: ' . $httpStatus . ': ' . $msg);
     exit(2);
 }
     echo $msg . "\n";
     syslog(LOG_ERR, 'playVideoOnDreamboxProxy: ' . $httpStatus . ': ' . $msg);
     exit(2);
 }
-?>
\ No newline at end of file
+?>