diff --git a/app/pages/config.php b/app/pages/config.php index 777bdff..ca3303b 100644 --- a/app/pages/config.php +++ b/app/pages/config.php @@ -25,7 +25,7 @@ $agentObject = new Agent($dbWeb); if ($_SERVER['REQUEST_METHOD'] == 'POST') { /** - * Handles form submissions from editing page + * Handles form submissions from editing */ // editing the config file @@ -42,200 +42,126 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { } } - // new host adding - } elseif (isset($_POST['new']) && isset($_POST['item']) && $_POST['new'] === 'true' && $_POST['item'] === 'host') { - $newHost = [ - 'address' => $address, - 'port' => $port, - 'platform_id' => $platform_id, - 'name' => $name, - ]; - $result = $hostObject->addHost($newHost); - if ($result === true) { - $_SESSION['notice'] = "New Jilo host added."; - } else { - $_SESSION['error'] = "Adding the host failed. Error: $result"; - } - - // new agent adding - } elseif (isset($_POST['new']) && isset($_POST['item']) && $_POST['new'] === 'true' && $_POST['item'] === 'agent') { - $newAgent = [ - 'type_id' => $type, - 'url' => $url, - 'secret_key' => $secret_key, - 'check_period' => $check_period, - ]; - $result = $agentObject->addAgent($platform_id, $newAgent); - if ($result === true) { - $_SESSION['notice'] = "New Jilo Agent added."; - } else { - $_SESSION['error'] = "Adding the agent failed. Error: $result"; - } - - // new platform adding - } elseif (isset($_POST['new']) && $_POST['new'] === 'true') { - $newPlatform = [ - 'name' => $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"; - } - - // deleting a host - } elseif (isset($_POST['delete']) && isset($_POST['host']) && $_POST['delete'] === 'true') { - $result = $hostObject->deleteHost($host); - if ($result === true) { - $_SESSION['notice'] = "Host id \"{$_REQUEST['host']}\" deleted."; - } else { - $_SESSION['error'] = "Deleting the host failed. Error: $result"; - } - - // deleting an agent - } elseif (isset($_POST['delete']) && isset($_POST['agent']) && $_POST['delete'] === 'true') { - $result = $agentObject->deleteAgent($agent); - if ($result === true) { - $_SESSION['notice'] = "Agent id \"{$_REQUEST['agent']}\" deleted."; - } else { - $_SESSION['error'] = "Deleting the agent failed. Error: $result"; - } - - // deleting a platform - } elseif (isset($_POST['delete']) && $_POST['delete'] === 'true') { - $platform = $_POST['platform']; - $result = $platformObject->deletePlatform($platform); - if ($result === true) { - $_SESSION['notice'] = "Platform \"{$platformObject['name']}\" added."; - } else { - $_SESSION['error'] = "Adding the platform failed. Error: $result"; - } - - // an update to an existing host + // host operations } elseif (isset($_POST['item']) && $_POST['item'] === 'host') { - $host_id = $_POST['host']; - $platform_id = $_POST['platform']; - $updatedHost = [ - 'id' => $host_id, - 'address' => $_POST['address'], - 'name' => $_POST['name'] - ]; - $result = $hostObject->editHost($platform_id, $updatedHost); - - // Check if it's an AJAX request - if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && - strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { - - // Clear any output buffers to ensure clean JSON - while (ob_get_level()) ob_end_clean(); - - header('Content-Type: application/json'); + if (isset($_POST['delete']) && $_POST['delete'] === 'true') { // This is a host delete + $host_id = $_POST['host']; + $result = $hostObject->deleteHost($host_id); if ($result === true) { - echo json_encode(['success' => true]); + $_SESSION['notice'] = "Host deleted successfully."; } else { - echo json_encode([ - 'success' => false, - 'message' => "Editing the host failed. Error: $result" - ]); + $_SESSION['error'] = "Deleting the host failed. Error: $result"; } - exit(); - } else { - // Regular form submission + } else if (!isset($_POST['host'])) { // This is a new host + $newHost = [ + 'address' => $_POST['address'], + 'platform_id' => $_POST['platform'], + 'name' => $_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' => $_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: $app_root?page=config&item=$item"); - exit(); } - // an update to an existing agent + // agent operations } elseif (isset($_POST['item']) && $_POST['item'] === 'agent') { - $agent_id = $_POST['agent']; - $platform_id = $_POST['platform']; - $updatedAgent = [ - 'id' => $agent_id, - 'agent_type_id' => $_POST['agent_type_id'], - 'url' => $_POST['url'], - 'secret_key' => $_POST['secret_key'], - 'check_period' => $_POST['check_period'] - ]; - $result = $agentObject->editAgent($platform_id, $updatedAgent); - - // Check if it's an AJAX request - if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && - strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { - - // Clear any output buffers to ensure clean JSON - while (ob_get_level()) ob_end_clean(); - - header('Content-Type: application/json'); + if (isset($_POST['delete']) && $_POST['delete'] === 'true') { // This is an agent delete + $agent_id = $_POST['agent']; + $result = $agentObject->deleteAgent($agent_id); if ($result === true) { - echo json_encode(['success' => true]); + $_SESSION['notice'] = "Agent deleted successfully."; } else { - echo json_encode([ - 'success' => false, - 'message' => "Editing the agent failed. Error: $result" - ]); + $_SESSION['error'] = "Deleting the agent failed. Error: $result"; } - exit(); - } else { - // Regular form submission + } else if (isset($_POST['new']) && $_POST['new'] === 'true') { // This is a new agent + $newAgent = [ + 'type_id' => $_POST['type'], + 'url' => $_POST['url'], + 'secret_key' => $_POST['secret_key'], + 'check_period' => $_POST['check_period'], + ]; + $result = $agentObject->addAgent($_POST['platform'], $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']; + $platform_id = $_POST['platform']; + $updatedAgent = [ + 'id' => $agent_id, + 'agent_type_id' => $_POST['agent_type_id'], + 'url' => $_POST['url'], + 'secret_key' => $_POST['secret_key'], + 'check_period' => $_POST['check_period'] + ]; + $result = $agentObject->editAgent($platform_id, $updatedAgent); if ($result === true) { $_SESSION['notice'] = "Agent edited."; } else { $_SESSION['error'] = "Editing the agent failed. Error: $result"; } - header("Location: $app_root?page=config&item=$item"); - exit(); } - // an update to an existing platform - } else { - $platform = $_POST['platform_id']; - $updatedPlatform = [ - 'name' => $_POST['name'], - 'jitsi_url' => $_POST['jitsi_url'], - 'jilo_database' => $_POST['jilo_database'] - ]; - $result = $platformObject->editPlatform($platform, $updatedPlatform); - - // Check if it's an AJAX request - if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && - strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { - - // Clear any output buffers to ensure clean JSON - while (ob_get_level()) ob_end_clean(); - - header('Content-Type: application/json'); + // 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) { - echo json_encode(['success' => true]); + $_SESSION['notice'] = "Platform deleted successfully."; } else { - echo json_encode([ - 'success' => false, - 'message' => "Editing the platform failed. Error: $result" - ]); + $_SESSION['error'] = "Deleting the platform failed. Error: $result"; } - exit(); - } else { - // Regular form submission + } 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: $app_root?page=config&item=$item"); - exit(); } } -// FIXME the new file is not loaded on first page load - unset($config); - header("Location: $app_root?page=config&item=$item"); + // After any POST operation, redirect back to the main config page + header("Location: $app_root?page=config"); exit(); } else { @@ -245,76 +171,6 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { switch ($item) { - case 'platform': - if (isset($action) && $action === 'add') { - include '../app/templates/config-platform-add.php'; - } elseif (isset($action) && $action === 'edit') { - include '../app/templates/config-platform-edit.php'; - } elseif (isset($action) && $action === 'delete') { - include '../app/templates/config-platform-delete.php'; - } else { - if ($userObject->hasRight($user_id, 'view config file')) { - include '../app/templates/config-platform.php'; - } else { - include '../app/templates/error-unauthorized.php'; - } - } - break; - - case 'host': - if (isset($action) && $action === 'add') { - include '../app/templates/config-host-add.php'; - } elseif (isset($action) && $action === 'edit') { - $hostDetails = $hostObject->getHostDetails($platform_id, $agent); - include '../app/templates/config-host-edit.php'; - } elseif (isset($action) && $action === 'delete') { - $hostDetails = $hostObject->getHostDetails($platform_id, $agent); - include '../app/templates/config-host-delete.php'; - } else { - if ($userObject->hasRight($user_id, 'view config file')) { - $hostDetails = $hostObject->getHostDetails(); - include '../app/templates/config-host.php'; - } else { - include '../app/templates/error-unauthorized.php'; - } - } - break; - - case 'agent': - if (isset($action) && $action === 'add') { - $jilo_agent_types = $agentObject->getAgentTypes(); - $platform_id = $_REQUEST['platform'] ?? ''; - if (!empty($platform_id)) { - $jilo_agents_in_platform = $agentObject->getPlatformAgentTypes($platform_id); - $jilo_agent_types_in_platform = array_column($jilo_agents_in_platform, 'agent_type_id'); - include '../app/templates/config-agent-add.php'; - } else { - $_SESSION['error'] = "Platform ID is required to add an agent."; - header("Location: $app_root?page=config&item=agent"); - exit(); - } - } elseif (isset($action) && $action === 'edit') { - if (isset($_REQUEST['agent'])) { - $platform_id = $_REQUEST['platform'] ?? ''; - $agentDetails = $agentObject->getAgentDetails($platform_id, $agent)['0']; - $jilo_agent_types = $agentObject->getAgentTypes(); - include '../app/templates/config-agent-edit.php'; - } - } elseif (isset($action) && $action === 'delete') { - if (isset($_REQUEST['agent'])) { - $platform_id = $_REQUEST['platform'] ?? ''; - $agentDetails = $agentObject->getAgentDetails($platform_id, $agent)['0']; - include '../app/templates/config-agent-delete.php'; - } - } else { - if ($userObject->hasRight($user_id, 'view config file')) { - include '../app/templates/config-agent.php'; - } else { - include '../app/templates/error-unauthorized.php'; - } - } - break; - case 'config_file': if (isset($action) && $action === 'edit') { include '../app/templates/config-configfile-edit.php'; @@ -328,9 +184,11 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { break; default: - // the default config page is the platforms page - header("Location: $app_root?page=config&item=platform"); - exit(); + if ($userObject->hasRight($user_id, 'view config file')) { + include '../app/templates/config-jilo.php'; + } else { + include '../app/templates/error-unauthorized.php'; + } } } diff --git a/app/templates/config-add-agent.php b/app/templates/config-add-agent.php deleted file mode 100644 index 43578b7..0000000 --- a/app/templates/config-add-agent.php +++ /dev/null @@ -1,72 +0,0 @@ - - -
-

Add new Jilo Agent to Jitsi platform ""

-
- -
- -
-
- - * -
-
- -

type of agent (meet, jvb, jibri, etc.)
if a type has already been aded, it's disabled here

-
-
- -
-
- - * -
-
- -

URL of the Jilo Agent API (https://example.com:8081)

-
-
- -
-
- - * -
-
- -

secret key for generating the access JWT token

-
-
- -
-
- - * -
-
- -

period in minutes for the automatic agent check (0 disables it)

-
-
- - - - -
- Cancel - -
-
-
- diff --git a/app/templates/config-agent-add.php b/app/templates/config-agent-add.php deleted file mode 100644 index aea8f6d..0000000 --- a/app/templates/config-agent-add.php +++ /dev/null @@ -1,59 +0,0 @@ - - -
-

Add new Jilo agent

-
-
- - - - -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
-
- -
-
- - Cancel -
-
-
-
-
diff --git a/app/templates/config-agent-delete.php b/app/templates/config-agent-delete.php deleted file mode 100644 index 34c4f91..0000000 --- a/app/templates/config-agent-delete.php +++ /dev/null @@ -1,31 +0,0 @@ - -
-

Delete Jilo agent

-
-

Are you sure you want to delete this agent?

- -
- Agent ID:
- Type:
- URL:
- Check Period: -
- -
- - - - - -
- - Cancel -
-
-
-
- -
- Agent not found. -
- diff --git a/app/templates/config-agent-edit.php b/app/templates/config-agent-edit.php deleted file mode 100644 index 5d53c95..0000000 --- a/app/templates/config-agent-edit.php +++ /dev/null @@ -1,57 +0,0 @@ - -
-

Edit Jilo agent

-
-
- - - - -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
-
- -
-
- - Cancel -
-
-
-
-
- -
- Agent not found. -
- diff --git a/app/templates/config-delete-agent.php b/app/templates/config-delete-agent.php deleted file mode 100644 index fd2381d..0000000 --- a/app/templates/config-delete-agent.php +++ /dev/null @@ -1,32 +0,0 @@ - - -
-

Jilo Agent configuration for Jitsi platform ""

-
-

delete an agent:

-
- $value) { -// if ($key === 'id') continue; -?> -
-
- -
-
-
- -
-
- -
- - -

Are you sure you want to delete this agent?

-
- Cancel - -
-
-
- diff --git a/app/templates/config-edit-agent.php b/app/templates/config-edit-agent.php deleted file mode 100644 index dc5756c..0000000 --- a/app/templates/config-edit-agent.php +++ /dev/null @@ -1,68 +0,0 @@ - - -
-

Jilo Agent configuration for Jitsi platform ""

-
-

edit the agent details:

-
- -
-
- - * -
-
- -

type of agent (meet, jvb, jibri, all)

-
-
- -
-
- - * -
-
- -

URL of the Jilo Agent API (https://example.com:8081)

-
-
- -
-
- - * -
-
- -

secret key for generating the access JWT token

-
-
- -
-
- - * -
-
- -

period in minutes for the automatic agent check (0 disables it)

-
-
- - -
- - Cancel - -
-
-
- diff --git a/app/templates/config-host-add.php b/app/templates/config-host-add.php deleted file mode 100644 index 70b46c4..0000000 --- a/app/templates/config-host-add.php +++ /dev/null @@ -1,50 +0,0 @@ - - -
-

Add new host in Jitsi platform

-
-
- -
-
- - * -
-
- -

DNS name or IP address of the machine

-
-
- -
-
- - * -
-
- -

port on which the Jilo Agent is listening

-
-
- -
-
- -
-
- -

description or name of the host (optional)

-
-
- - - - -
- Cancel -    - -
-
-
- diff --git a/app/templates/config-host-delete.php b/app/templates/config-host-delete.php deleted file mode 100644 index 809e53a..0000000 --- a/app/templates/config-host-delete.php +++ /dev/null @@ -1,32 +0,0 @@ - - -
-

Jilo configuration for Jitsi platform ""

-
-

delete a host:

-
- $value) { -?> -
-
- -
-
-
- -
-
- -
- - -

Are you sure you want to delete this host?

-
- Cancel -    - -
-
-
- diff --git a/app/templates/config-platform.php b/app/templates/config-jilo.php similarity index 62% rename from app/templates/config-platform.php rename to app/templates/config-jilo.php index 9ce57a8..5fdbda6 100644 --- a/app/templates/config-platform.php +++ b/app/templates/config-jilo.php @@ -6,9 +6,9 @@

Jitsi Meet platforms configuration

- +
@@ -47,23 +47,17 @@
- - - - - - - @@ -108,7 +102,7 @@
- +
@@ -118,9 +112,9 @@ for platform ""
- +
@@ -130,7 +124,7 @@ return isset($agent['host_id']) && $agent['host_id'] === $host['id']; }); ?> -
+
@@ -179,15 +173,14 @@ - +
- + getAgentDetails($platform['id']); ?>
@@ -197,9 +190,9 @@ for this host
- +
@@ -207,7 +200,7 @@ - + @@ -215,7 +208,7 @@ - + @@ -317,56 +309,278 @@ + + + + + + + + + + + + + + + + + + + diff --git a/app/templates/config-list.php b/app/templates/config-list.php deleted file mode 100644 index a0ea0cc..0000000 --- a/app/templates/config-list.php +++ /dev/null @@ -1,134 +0,0 @@ - - -
-

Jilo configuration

-

- platforms - hosts - endpoints -    - config file -

-
-

main variables

- - -
-

platforms configuration  add new

- -getAgentDetails($platform_array['id']); -?> - - -
-
- -
- - platform () -
-
-
- -
-
- -
-
- edit platform - - delete platform - - delete platform - -
-
- -
-
- $value) { - if ($key === 'id') continue; -?> -
-
- : -
-
- -
-
- - -
-
-

jilo agents on platform () -
- total   - - add new - -

- - - - -
-
-
-
- agent id : -
- -
-
-
- agent type: -
-
- -
-
-
-
- endpoint: -
-
- -
-
- -
-
- check period: -
-
- -
-
- -
-
-
-
- - - - -
-
-
-
- - - -
-
- diff --git a/app/templates/config-platform-add.php b/app/templates/config-platform-add.php deleted file mode 100644 index 1f72115..0000000 --- a/app/templates/config-platform-add.php +++ /dev/null @@ -1,51 +0,0 @@ - - -
-

Add new Jitsi platform

-
- -
- -
-
- - * -
-
- -

descriptive name for the platform

-
-
- -
-
- - * -
-
- -

URL of the Jitsi Meet (used for checks and for loading config.js)

-
-
- -
-
- - * -
-
- -

path to the database file (relative to the app root)

-
-
- - - -
- Cancel -    - - -
-
- diff --git a/app/templates/config-platform-delete.php b/app/templates/config-platform-delete.php deleted file mode 100644 index 9dcafe4..0000000 --- a/app/templates/config-platform-delete.php +++ /dev/null @@ -1,32 +0,0 @@ - - -
-

Jilo configuration for Jitsi platform "" :: delete

-
-
- $value) { - if ($key === 'id') continue; -?> -
-
- -
-
-
- -
-
- -
- - -

Are you sure you want to delete this platform?

-
- Cancel -    - - -
-
-
Agent TypeAgent type Endpoint URL Check period (minutes) Actions
@@ -244,7 +237,7 @@ - + @@ -277,10 +270,9 @@ - +