From b971a766627c4b09b46c3377e0f41c142a52cdad Mon Sep 17 00:00:00 2001 From: Yasen Pramatarov Date: Wed, 29 Jan 2025 10:46:06 +0200 Subject: [PATCH] Rebuilds livejs pages --- app/classes/settings.php | 108 +++++++++++++++----------------- app/pages/livejs.php | 132 ++------------------------------------- app/templates/livejs.php | 39 ++++++++++++ 3 files changed, 93 insertions(+), 186 deletions(-) create mode 100644 app/templates/livejs.php diff --git a/app/classes/settings.php b/app/classes/settings.php index 254df4d..a8ad20e 100644 --- a/app/classes/settings.php +++ b/app/classes/settings.php @@ -8,68 +8,25 @@ class Settings { /** - * Loads the config.js file from the Jitsi server. - * - * @param string $jitsiUrl The base URL of the Jitsi server. - * @param bool $raw Whether to return the full file (true) or only uncommented values (false). - * - * @return string The content of the config.js file or an error message. - */ - public function getPlatformConfigjs($jitsiUrl, $raw = false) { - // constructing the URL - $configjsFile = $jitsiUrl . '/config.js'; - - // default content, if we can't get the file contents - $platformConfigjs = "The file $configjsFile can't be loaded."; - - // ssl options - $contextOptions = [ - 'ssl' => [ - 'verify_peer' => true, - 'verify_peer_name' => true, - ], - ]; - $context = stream_context_create($contextOptions); - - // get the file - $fileContent = @file_get_contents($configjsFile, false, $context); - - if ($fileContent !== false) { - - // when we need only uncommented values - if ($raw === false) { - // remove block comments - $platformConfigjs = preg_replace('!/\*.*?\*/!s', '', $fileContent); - // remove single-line comments - $platformConfigjs = preg_replace('/\/\/[^\n]*/', '', $platformConfigjs); - // remove empty lines - $platformConfigjs = preg_replace('/^\s*[\r\n]/m', '', $platformConfigjs); - - // when we need the full file as it is - } else { - $platformConfigjs = $fileContent; - } - } - - return $platformConfigjs; - - } - - - /** - * Loads the interface_config.js file from the Jitsi server. + * Loads javascript file the Jitsi server. * * @param string $jitsiUrl The base URL of the Jitsi server. + * @param string $livejsFile The name of the remote js file to load. * @param bool $raw Whether to return the full file (true) or only uncommented values (false). * * @return string The content of the interface_config.js file or an error message. */ - public function getPlatformInterfaceConfigjs($jitsiUrl, $raw = false) { + public function getPlatformJsFile($jitsiUrl, $livejsFile, $raw = false) { // constructing the URL - $interfaceConfigjsFile = $jitsiUrl . '/interface_config.js'; + $jsFile = $jitsiUrl . '/' . $livejsFile; // default content, if we can't get the file contents - $platformInterfaceConfigjs = "The file $interfaceConfigjsFile can't be loaded."; + $jsFileContent = "The file $livejsFile can't be loaded."; + + // Check if URL is valid + if (!filter_var($jsFile, FILTER_VALIDATE_URL)) { + return "Invalid URL: $jsFile"; + } // ssl options $contextOptions = [ @@ -80,27 +37,60 @@ class Settings { ]; $context = stream_context_create($contextOptions); + // Try to get headers first to check if file exists and wasn't redirected + $headers = @get_headers($jsFile, 1); // 1 to get headers as array + if ($headers === false) { + return "The file $livejsFile can't be loaded (connection error)."; + } + + // Check for redirects + $statusLine = $headers[0]; + if (strpos($statusLine, '301') !== false || strpos($statusLine, '302') !== false) { + return "The file $livejsFile was redirected - this might indicate the file doesn't exist."; + } + + // Check if we got 200 OK + if (strpos($statusLine, '200') === false) { + return "The file $livejsFile can't be loaded (HTTP error: $statusLine)."; + } + + // Check content type + $contentType = isset($headers['Content-Type']) ? $headers['Content-Type'] : ''; + if (is_array($contentType)) { + $contentType = end($contentType); // get last content-type in case of redirects + } + if (stripos($contentType, 'javascript') === false && stripos($contentType, 'text/plain') === false) { + return "The file $livejsFile doesn't appear to be a JavaScript file (got $contentType)."; + } + // get the file - $fileContent = @file_get_contents($interfaceConfigjsFile, false, $context); + $fileContent = @file_get_contents($jsFile, false, $context); if ($fileContent !== false) { + // Quick validation of content + $firstLine = strtolower(trim(substr($fileContent, 0, 100))); + if (strpos($firstLine, '') !== false || + strpos($firstLine, ' 'conferences', - 'graph_title' => 'Conferences in "' . htmlspecialchars($platformDetails[0]['name']) . '" over time', - 'datasets' => [] - ], - [ - 'graph_name' => 'participants', - 'graph_title' => 'Participants in "' . htmlspecialchars($platformDetails[0]['name']) . '" over time', - 'datasets' => [] - ] - ]; - - // Get Jitsi API data - $conferences_api = $agentObject->getHistoricalData( - $platform_id, - 'jicofo', - 'conferences', - $from_time, - $until_time - ); - $graphs[0]['datasets'][] = [ - 'data' => $conferences_api, - 'label' => 'Conferences from Jitsi API', - 'color' => 'rgba(75, 192, 192, 1)' - ]; - - // Get conference data from logs - $conferences_logs = $conferenceObject->conferenceNumber( - $from_time, - $until_time - ); - $graphs[0]['datasets'][] = [ - 'data' => $conferences_logs, - 'label' => 'Conferences from Logs', - 'color' => 'rgba(255, 99, 132, 1)' - ]; - - // Get participants data - $participants_api = $agentObject->getHistoricalData( - $platform_id, - 'jicofo', - 'participants', - $from_time, - $until_time - ); - $graphs[1]['datasets'][] = [ - 'data' => $participants_api, - 'label' => 'Participants from Jitsi API', - 'color' => 'rgba(75, 192, 192, 1)' - ]; - - // Prepare data for template - $graph = $graphs; - - // prepare the widget - $widget['full'] = false; - $widget['name'] = 'Graphs'; - $widget['title'] = 'Jitsi graphs'; +$livejsData = $settingsObject->getPlatformJsFile($platformDetails[0]['jitsi_url'], $item, $raw); // Get any new messages include '../app/includes/messages.php'; include '../app/includes/messages-show.php'; // Load the template - include '../app/templates/graphs-combined.php'; - break; - - case 'configjs': - $mode = $_REQUEST['mode'] ?? ''; - $raw = ($mode === 'raw'); - $platformConfigjs = $settingsObject->getPlatformConfigjs($platformDetails[0]['jitsi_url'], $raw); -// Get any new messages -include '../app/includes/messages.php'; -include '../app/includes/messages-show.php'; - -// Load the template - include '../app/templates/data-configjs.php'; - break; - - case 'interfaceconfigjs': - $mode = $_REQUEST['mode'] ?? ''; - $raw = ($mode === 'raw'); - $platformInterfaceConfigjs = $settingsObject->getPlatformInterfaceConfigjs($platformDetails[0]['jitsi_url'], $raw); -// Get any new messages -include '../app/includes/messages.php'; -include '../app/includes/messages-show.php'; - -// Load the template - include '../app/templates/data-interfaceconfigjs.php'; - break; - - default: - } - -//} +include '../app/templates/livejs.php'; ?> diff --git a/app/templates/livejs.php b/app/templates/livejs.php new file mode 100644 index 0000000..1463e4e --- /dev/null +++ b/app/templates/livejs.php @@ -0,0 +1,39 @@ + + +
+
+
+

Remote Jitsi config

+ contents of the file "" +
+
+ +
+
+
+
+
+ + : + + + view only active lines + + view raw file contents + + +
+ +
+
+
+
+                                    
+
+
+
+
+
+