Rebuilds livejs pages

main
Yasen Pramatarov 2025-01-29 10:46:06 +02:00
parent 25da7331f0
commit b971a76662
3 changed files with 93 additions and 186 deletions

View File

@ -8,68 +8,25 @@
class Settings { class Settings {
/** /**
* Loads the config.js file from the Jitsi server. * Loads javascript file 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.
* *
* @param string $jitsiUrl The base URL of 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). * @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. * @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 // constructing the URL
$interfaceConfigjsFile = $jitsiUrl . '/interface_config.js'; $jsFile = $jitsiUrl . '/' . $livejsFile;
// default content, if we can't get the file contents // 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 // ssl options
$contextOptions = [ $contextOptions = [
@ -80,27 +37,60 @@ class Settings {
]; ];
$context = stream_context_create($contextOptions); $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 // get the file
$fileContent = @file_get_contents($interfaceConfigjsFile, false, $context); $fileContent = @file_get_contents($jsFile, false, $context);
if ($fileContent !== false) { if ($fileContent !== false) {
// Quick validation of content
$firstLine = strtolower(trim(substr($fileContent, 0, 100)));
if (strpos($firstLine, '<!doctype html>') !== false ||
strpos($firstLine, '<html') !== false ||
strpos($firstLine, '<?xml') !== false) {
return "The file $livejsFile appears to be HTML/XML content instead of JavaScript.";
}
// when we need only uncommented values // when we need only uncommented values
if ($raw === false) { if ($raw === false) {
// remove block comments // remove block comments
$platformInterfaceConfigjs = preg_replace('!/\*.*?\*/!s', '', $fileContent); $jsFileContent = preg_replace('!/\*.*?\*/!s', '', $fileContent);
// remove single-line comments // remove single-line comments
$platformInterfaceConfigjs = preg_replace('/\/\/[^\n]*/', '', $platformInterfaceConfigjs); $jsFileContent = preg_replace('/\/\/[^\n]*/', '', $jsFileContent);
// remove empty lines // remove empty lines
$platformInterfaceConfigjs = preg_replace('/^\s*[\r\n]/m', '', $platformInterfaceConfigjs); $jsFileContent = preg_replace('/^\s*[\r\n]/m', '', $jsFileContent);
// when we need the full file as it is // when we need the full file as it is
} else { } else {
$platformInterfaceConfigjs = $fileContent; $jsFileContent = $fileContent;
} }
} }
return $platformInterfaceConfigjs; return $jsFileContent;
} }

View File

@ -1,141 +1,19 @@
<?php <?php
$action = $_REQUEST['action'] ?? ''; $mode = $_REQUEST['mode'] ?? '';
$agent = $_REQUEST['agent'] ?? ''; $raw = ($mode === 'raw');
$livejsFile = $_REQUEST['item'] ?? '';
require '../app/classes/settings.php'; require '../app/classes/settings.php';
require '../app/classes/agent.php';
require '../app/classes/conference.php';
require '../app/classes/host.php';
$settingsObject = new Settings(); $settingsObject = new Settings();
$agentObject = new Agent($dbWeb);
$hostObject = new Host($dbWeb);
// connect to Jilo database $livejsData = $settingsObject->getPlatformJsFile($platformDetails[0]['jitsi_url'], $item, $raw);
//$response = connectDB($config, 'jilo', $platformDetails[0]['jilo_database'], $platform_id);
//
//// if DB connection has error, display it and stop here
//if ($response['db'] === null) {
// Messages::flash('ERROR', 'DEFAULT', $response['error']);
// otherwise if DB connection is OK, go on
//} else {
// $db = $response['db'];
//
// $conferenceObject = new Conference($db);
switch ($item) {
case 'graphs':
// Connect to Jilo database for log data
$jilo_response = connectDB($config, 'jilo', $platformDetails[0]['jilo_database'], $platform_id);
if ($jilo_response['db'] === null) {
Messages::flash('ERROR', 'DEFAULT', $jilo_response['error']);
break;
}
$jilo_db = $jilo_response['db'];
// Get date range for the last 7 days
$from_time = date('Y-m-d', strtotime('-7 days'));
$until_time = date('Y-m-d');
// Define graphs to show
$graphs = [
[
'graph_name' => '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';
// Get any new messages // Get any new messages
include '../app/includes/messages.php'; include '../app/includes/messages.php';
include '../app/includes/messages-show.php'; include '../app/includes/messages-show.php';
// Load the template // Load the template
include '../app/templates/graphs-combined.php'; include '../app/templates/livejs.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:
}
//}
?> ?>

View File

@ -0,0 +1,39 @@
<!-- remote config "<?= htmlspecialchars($livejsFile) ?>" -->
<div class="container-fluid mt-2">
<div class="row mb-4">
<div class="col-12 mb-4">
<h2 class="mb-0">Remote Jitsi config</h2>
<small>contents of the file "<strong><?= htmlspecialchars($livejsFile) ?></strong>"</small>
</div>
</div>
<div class="row">
<div class="mb-4">
<div class="card mb-4">
<div class="card-header">
<h5 class="mb-0">
<i class="fas fa-file me-2 text-secondary"></i>
<small><span class="text-muted"><?= htmlspecialchars($platformDetails[0]['jitsi_url']) ?>:</span> <?= htmlspecialchars($livejsFile) ?></small>
<span class="card-text">
<?php if ($mode === 'raw') { ?>
<span class="m-3"><a class="btn border btn-primary" href="<?= htmlspecialchars($app_root) ?>?platform=<?= htmlspecialchars($platform_id) ?>&page=livejs&item=<?= htmlspecialchars($livejsFile) ?>">view only active lines</a></span>
<?php } else { ?>
<span class="m-3"><a class="btn border btn-secondary" href="<?= htmlspecialchars($app_root) ?>?platform=<?= htmlspecialchars($platform_id) ?>&page=livejs&item=<?= htmlspecialchars($livejsFile) ?>&mode=raw">view raw file contents</a></span>
<?php } ?>
</span>
</h5>
</div>
<div class="card-body">
<pre class="results">
<?php
echo htmlspecialchars($livejsData);
?>
</pre>
</div>
</div>
</div>
</div>
</div>
<!-- /remote config "<?= htmlspecialchars($livejsFile) ?>" -->