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

View File

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

View File

@ -3,8 +3,15 @@
<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>
<div class="card-body">
<p class="card-text">URL: <?= htmlspecialchars($platformDetails['jitsi_url']) ?></p>
<p class="card-text">config.js</p>
<p class="card-text">
<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;">
<?php
echo htmlspecialchars($platformConfigjs);

View File

@ -3,8 +3,15 @@
<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>
<div class="card-body">
<p class="card-text">URL: <?= htmlspecialchars($platformDetails['jitsi_url']) ?></p>
<p class="card-text">interface_config.js</p>
<p class="card-text">
<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;">
<?php
echo htmlspecialchars($platformInterfaceConfigjs);

View File

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