diff --git a/app/classes/settings.php b/app/classes/settings.php new file mode 100644 index 0000000..254df4d --- /dev/null +++ b/app/classes/settings.php @@ -0,0 +1,109 @@ + [ + '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 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) { + // constructing the URL + $interfaceConfigjsFile = $jitsiUrl . '/interface_config.js'; + + // default content, if we can't get the file contents + $platformInterfaceConfigjs = "The file $interfaceConfigjsFile 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($interfaceConfigjsFile, false, $context); + + if ($fileContent !== false) { + + // 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; + + } + +} + +?> diff --git a/app/pages/settings.php b/app/pages/settings.php new file mode 100644 index 0000000..b473144 --- /dev/null +++ b/app/pages/settings.php @@ -0,0 +1,171 @@ +deleteHost($host_id); + if ($result === true) { + $_SESSION['notice'] = "Host deleted successfully."; + } else { + $_SESSION['error'] = "Deleting the host failed. Error: $result"; + } + } else if (!isset($_POST['host'])) { // This is a new host + $newHost = [ + 'address' => $_POST['address'], + 'platform_id' => $_POST['platform'], + 'name' => empty($_POST['name']) ? $_POST['address'] : $_POST['name'], + ]; + $result = $hostObject->addHost($newHost); + if ($result === true) { + $_SESSION['notice'] = "New Jilo host added."; + } else { + $_SESSION['error'] = "Adding the host failed. Error: $result"; + } + } else { // This is an edit of existing host + $host_id = $_POST['host']; + $platform_id = $_POST['platform']; + $updatedHost = [ + 'id' => $host_id, + 'address' => $_POST['address'], + 'name' => empty($_POST['name']) ? $_POST['address'] : $_POST['name'], + ]; + $result = $hostObject->editHost($platform_id, $updatedHost); + if ($result === true) { + $_SESSION['notice'] = "Host edited."; + } else { + $_SESSION['error'] = "Editing the host failed. Error: $result"; + } + } + header('Location: ' . $redirectUrl); + exit; + + // agent operations + } elseif (isset($_POST['item']) && $_POST['item'] === 'agent') { + if (isset($_POST['delete']) && $_POST['delete'] === 'true') { // This is an agent delete + $agent_id = $_POST['agent']; + $result = $agentObject->deleteAgent($agent_id); + if ($result === true) { + $_SESSION['notice'] = "Agent deleted successfully."; + } else { + $_SESSION['error'] = "Deleting the agent failed. Error: $result"; + } + } else if (isset($_POST['new']) && $_POST['new'] === 'true') { // This is a new agent + $newAgent = [ + 'type_id' => $_POST['type'], + 'url' => $_POST['url'], + 'secret_key' => empty($_POST['secret_key']) ? null : $_POST['secret_key'], + 'check_period' => empty($_POST['check_period']) ? 0 : $_POST['check_period'], + ]; + $result = $agentObject->addAgent($_POST['host'], $newAgent); + if ($result === true) { + $_SESSION['notice'] = "New Jilo agent added."; + } else { + $_SESSION['error'] = "Adding the agent failed. Error: $result"; + } + } else { // This is an edit of existing agent + $agent_id = $_POST['agent']; + $updatedAgent = [ + 'agent_type_id' => $_POST['agent_type_id'], + 'url' => $_POST['url'], + 'secret_key' => empty($_POST['secret_key']) ? null : $_POST['secret_key'], + 'check_period' => empty($_POST['check_period']) ? 0 : $_POST['check_period'], + ]; + $result = $agentObject->editAgent($agent_id, $updatedAgent); + if ($result === true) { + $_SESSION['notice'] = "Agent edited."; + } else { + $_SESSION['error'] = "Editing the agent failed. Error: $result"; + } + } + header('Location: ' . $redirectUrl); + exit; + + // platform operations + } elseif (isset($_POST['item']) && $_POST['item'] === 'platform') { + if (isset($_POST['delete']) && $_POST['delete'] === 'true') { // This is a platform delete + $platform_id = $_POST['platform']; + $result = $platformObject->deletePlatform($platform_id); + if ($result === true) { + $_SESSION['notice'] = "Platform deleted successfully."; + } else { + $_SESSION['error'] = "Deleting the platform failed. Error: $result"; + } + } else if (!isset($_POST['platform'])) { // This is a new platform + $newPlatform = [ + 'name' => $_POST['name'], + 'jitsi_url' => $_POST['jitsi_url'], + 'jilo_database' => $_POST['jilo_database'], + ]; + $result = $platformObject->addPlatform($newPlatform); + if ($result === true) { + $_SESSION['notice'] = "New Jitsi platform added."; + } else { + $_SESSION['error'] = "Adding the platform failed. Error: $result"; + } + } else { // This is an edit of existing platform + $platform_id = $_POST['platform']; + $updatedPlatform = [ + 'id' => $platform_id, + 'name' => $_POST['name'], + 'jitsi_url' => $_POST['jitsi_url'], + 'jilo_database' => $_POST['jilo_database'], + ]; + $result = $platformObject->editPlatform($updatedPlatform); + if ($result === true) { + $_SESSION['notice'] = "Platform edited."; + } else { + $_SESSION['error'] = "Editing the platform failed. Error: $result"; + } + } + header('Location: ' . $redirectUrl); + exit; + } + +} else { + /** + * Handles GET requests to display templates. + */ + + if ($userObject->hasRight($user_id, 'view settings')) { + $jilo_agent_types = $agentObject->getAgentTypes(); + include '../app/templates/settings.php'; + } else { + include '../app/templates/error-unauthorized.php'; + } +} + +?> diff --git a/app/templates/page-sidebar.php b/app/templates/page-sidebar.php index 8462cd5..92f7ce9 100644 --- a/app/templates/page-sidebar.php +++ b/app/templates/page-sidebar.php @@ -65,20 +65,20 @@ $timeNow = new DateTime('now', new DateTimeZone($userTimezone)); -
jitsi platforms config
jitsi platforms settings
system
= htmlspecialchars($key) ?> | +
+
+
+
+ = htmlspecialchars($value) ?>
+
+
+
+ = htmlspecialchars($value) ?>
+
+
+
+ |
+
---|
Agent type | +Endpoint URL | +Secret key | +Check period | +Actions | +
---|---|---|---|---|
+
+
+
+ = htmlspecialchars($agent['agent_description']) ?>
+
+
+
+ |
+ + + = htmlspecialchars($agent['url']) ?> + + + | ++ + = isset($agent['secret_key']) ? '••••••' : '' ?> + + + | ++ + = $agent['check_period'] > 0 ? + htmlspecialchars($agent['check_period']) . ' ' . + ($agent['check_period'] == 1 ? 'minute' : 'minutes') : + 'Not monitored' ?> + + + | +
+
+
+
+
+
+
+ |
+