Adds switching between raw config files and only active config lines

main
Yasen Pramatarov 2024-08-31 19:50:58 +03:00
parent 54d6ce2ec4
commit f88fc0f819
5 changed files with 57 additions and 21 deletions

View File

@ -8,7 +8,7 @@ class Config {
} }
// loading the config.js // loading the config.js
public function getPlatformConfigjs($platformDetails) { public function getPlatformConfigjs($platformDetails, $raw = false) {
// constructing the URL // constructing the URL
$configjsFile = $platformDetails['jitsi_url'] . '/config.js'; $configjsFile = $platformDetails['jitsi_url'] . '/config.js';
@ -28,12 +28,20 @@ class Config {
$fileContent = @file_get_contents($configjsFile, false, $context); $fileContent = @file_get_contents($configjsFile, false, $context);
if ($fileContent !== false) { if ($fileContent !== false) {
// remove block comments
$platformConfigjs = preg_replace('!/\*.*?\*/!s', '', $fileContent); // when we need only uncommented values
// remove single-line comments if ($raw === false) {
$platformConfigjs = preg_replace('/\/\/[^\n]*/', '', $platformConfigjs); // remove block comments
// remove empty lines $platformConfigjs = preg_replace('!/\*.*?\*/!s', '', $fileContent);
$platformConfigjs = preg_replace('/^\s*[\r\n]/m', '', $platformConfigjs); // 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; return $platformConfigjs;
@ -42,7 +50,7 @@ class Config {
// loading the interface_config.js // loading the interface_config.js
public function getPlatformInterfaceConfigjs($platformDetails) { public function getPlatformInterfaceConfigjs($platformDetails, $raw = false) {
// constructing the URL // constructing the URL
$interfaceConfigjsFile = $platformDetails['jitsi_url'] . '/interface_config.js'; $interfaceConfigjsFile = $platformDetails['jitsi_url'] . '/interface_config.js';
@ -62,12 +70,20 @@ class Config {
$fileContent = @file_get_contents($interfaceConfigjsFile, false, $context); $fileContent = @file_get_contents($interfaceConfigjsFile, false, $context);
if ($fileContent !== false) { if ($fileContent !== false) {
// remove block comments
$platformInterfaceConfigjs = preg_replace('!/\*.*?\*/!s', '', $fileContent); // when we need only uncommented values
// remove single-line comments if ($raw === false) {
$platformInterfaceConfigjs = preg_replace('/\/\/[^\n]*/', '', $platformInterfaceConfigjs); // remove block comments
// remove empty lines $platformInterfaceConfigjs = preg_replace('!/\*.*?\*/!s', '', $fileContent);
$platformInterfaceConfigjs = preg_replace('/^\s*[\r\n]/m', '', $platformInterfaceConfigjs); // remove single-line comments
$platformInterfaceConfigjs = preg_replace('/\/\/[^\n]*/', '', $platformInterfaceConfigjs);
// remove empty lines
$platformInterfaceConfigjs = preg_replace('/^\s*[\r\n]/m', '', $platformInterfaceConfigjs);
// when we need the full file as it is
} else {
$platformInterfaceConfigjs = $fileContent;
}
} }
return $platformInterfaceConfigjs; return $platformInterfaceConfigjs;

View File

@ -101,18 +101,25 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// no form submitted, show the templates // no form submitted, show the templates
} else { } else {
// $item - config.js and interface_config.js are special case; remote loaded files
switch ($item) { switch ($item) {
case 'configjs': case 'configjs':
$mode = $_REQUEST['mode'] ?? '';
$raw = ($mode === 'raw');
$platformDetails = $configure->getPlatformDetails($config, $platform_id); $platformDetails = $configure->getPlatformDetails($config, $platform_id);
$platformConfigjs = $configure->getPlatformConfigjs($platformDetails); $platformConfigjs = $configure->getPlatformConfigjs($platformDetails, $raw);
include('../app/templates/config-list-configjs.php'); include('../app/templates/config-list-configjs.php');
break; break;
case 'interfaceconfigjs': case 'interfaceconfigjs':
$mode = $_REQUEST['mode'] ?? '';
$raw = ($mode === 'raw');
$platformDetails = $configure->getPlatformDetails($config, $platform_id); $platformDetails = $configure->getPlatformDetails($config, $platform_id);
$platformInterfaceConfigjs = $configure->getPlatformInterfaceConfigjs($platformDetails); $platformInterfaceConfigjs = $configure->getPlatformInterfaceConfigjs($platformDetails, $raw);
include('../app/templates/config-list-interfaceconfigjs.php'); include('../app/templates/config-list-interfaceconfigjs.php');
break; break;
// if there is no $item, we work on the local config file
default: default:
switch ($action) { switch ($action) {
case 'add': case 'add':

View File

@ -3,8 +3,15 @@
<div class="card text-center w-75 mx-lef"> <div class="card text-center w-75 mx-lef">
<p class="h4 card-header">Configuration of the Jitsi platform <strong><?= htmlspecialchars($platformDetails['name']) ?></strong></p> <p class="h4 card-header">Configuration of the Jitsi platform <strong><?= htmlspecialchars($platformDetails['name']) ?></strong></p>
<div class="card-body"> <div class="card-body">
<p class="card-text">URL: <?= htmlspecialchars($platformDetails['jitsi_url']) ?></p> <p class="card-text">
<p class="card-text">config.js</p> <span class="m-3">URL: <?= htmlspecialchars($platformDetails['jitsi_url']) ?></span>
<span class="m-3">FILE: config.js</span>
<?php if ($mode === 'raw') { ?>
<span class="m-3"><a class="btn btn-light" href="<?= $app_root ?>?platform=<?= htmlspecialchars($platform_id) ?>&page=config&item=configjs">view only active lines</a></span>
<?php } else { ?>
<span class="m-3"><a class="btn btn-light" href="<?= $app_root ?>?platform=<?= htmlspecialchars($platform_id) ?>&page=config&item=configjs&mode=raw">view raw file contents</a></span>
<?php } ?>
</p>
<pre style="text-align: left;"> <pre style="text-align: left;">
<?php <?php
echo htmlspecialchars($platformConfigjs); echo htmlspecialchars($platformConfigjs);

View File

@ -3,8 +3,15 @@
<div class="card text-center w-75 mx-lef"> <div class="card text-center w-75 mx-lef">
<p class="h4 card-header">Configuration of the Jitsi platform <strong><?= htmlspecialchars($platformDetails['name']) ?></strong></p> <p class="h4 card-header">Configuration of the Jitsi platform <strong><?= htmlspecialchars($platformDetails['name']) ?></strong></p>
<div class="card-body"> <div class="card-body">
<p class="card-text">URL: <?= htmlspecialchars($platformDetails['jitsi_url']) ?></p> <p class="card-text">
<p class="card-text">interface_config.js</p> <span class="m-3">URL: <?= htmlspecialchars($platformDetails['jitsi_url']) ?></span>
<span class="m-3">FILE: interface_config.js</span>
<?php if ($mode === 'raw') { ?>
<span class="m-3"><a class="btn btn-light" href="<?= $app_root ?>?platform=<?= htmlspecialchars($platform_id) ?>&page=config&item=interfaceconfigjs">view only active lines</a></span>
<?php } else { ?>
<span class="m-3"><a class="btn btn-light" href="<?= $app_root ?>?platform=<?= htmlspecialchars($platform_id) ?>&page=config&item=interfaceconfigjs&mode=raw">view raw file contents</a></span>
<?php } ?>
</p>
<pre style="text-align: left;"> <pre style="text-align: left;">
<?php <?php
echo htmlspecialchars($platformInterfaceConfigjs); echo htmlspecialchars($platformInterfaceConfigjs);

View File

@ -73,7 +73,6 @@ if (isset($_REQUEST['item'])) {
$item = ''; $item = '';
} }
// check if logged in // check if logged in
unset($user); unset($user);
if (isset($_COOKIE['username'])) { if (isset($_COOKIE['username'])) {