diff --git a/app/classes/host.php b/app/classes/host.php new file mode 100644 index 0000000..8b394fa --- /dev/null +++ b/app/classes/host.php @@ -0,0 +1,118 @@ +db = $database->getConnection(); + } + + // get details of a specified host ID (or all) in a specified platform ID + public function getHostDetails($platform_id = '', $host_id = '') { + $sql = 'SELECT + id, + address, + port, + platform_id, + name + FROM + hosts'; + + if ($platform_id !== '' && $host_id !== '') { + $sql .= ' WHERE platform_id = :platform_id AND id = :host_id'; + } elseif ($platform_id !== '') { + $sql .= ' WHERE platform_id = :platform_id'; + } elseif ($host_id !== '') { + $sql .= ' WHERE id = :host_id'; + } + + $query = $this->db->prepare($sql); + + if ($platform_id !== '') { + $query->bindParam(':platform_id', $platform_id); + } + if ($host_id !== '') { + $query->bindParam(':host_id', $host_id); + } + + $query->execute(); + + return $query->fetchAll(PDO::FETCH_ASSOC); + } + + + // add new host + public function addHost($newHost) { + try { + $sql = 'INSERT INTO hosts + (address, port, platform_id, name) + VALUES + (:address, :port, :platform_id, :name)'; + + $query = $this->db->prepare($sql); + $query->execute([ + ':address' => $newHost['address'], + ':port' => $newHost['port'], + ':platform_id' => $newHost['platform_id'], + ':name' => $newHost['name'], + ]); + + return true; + + } catch (Exception $e) { + return $e->getMessage(); + } + } + + // edit an existing host + public function editAgent($platform_id, $updatedAgent) { + try { + $sql = 'UPDATE jilo_agents SET + agent_type_id = :agent_type_id, + url = :url, + secret_key = :secret_key, + check_period = :check_period + WHERE + id = :agent_id + AND + platform_id = :platform_id'; + + $query = $this->db->prepare($sql); + $query->execute([ + ':agent_type_id' => $updatedAgent['agent_type_id'], + ':url' => $updatedAgent['url'], + ':secret_key' => $updatedAgent['secret_key'], + ':check_period' => $updatedAgent['check_period'], + ':agent_id' => $updatedAgent['id'], + ':platform_id' => $platform_id, + ]); + + return true; + + } catch (Exception $e) { + return $e->getMessage(); + } + } + + + // delete a host + public function deleteAgent($agent_id) { + try { + $sql = 'DELETE FROM jilo_agents + WHERE + id = :agent_id'; + + $query = $this->db->prepare($sql); + $query->bindParam(':agent_id', $agent_id); + + $query->execute(); + return true; + + } catch (Exception $e) { + return $e->getMessage(); + } + } + +} + +?> diff --git a/app/helpers/sanitize.php b/app/helpers/sanitize.php index 7d213b1..8b6e8a7 100644 --- a/app/helpers/sanitize.php +++ b/app/helpers/sanitize.php @@ -28,6 +28,17 @@ if (isset($_SESSION['error'])) { $error = htmlspecialchars($_SESSION['error']); // 'error' for errors } +// hosts +if (isset($_POST['address'])) { + $address = htmlspecialchars($_POST['address']); +} +if (isset($_POST['port'])) { + $port = htmlspecialchars($_POST['port']); +} +if (isset($_POST['name'])) { + $name = htmlspecialchars($_POST['name']); +} + // agents if (isset($_POST['type'])) { $type = htmlspecialchars($_POST['type']); diff --git a/app/pages/config.php b/app/pages/config.php index ec9ef47..ece6447 100644 --- a/app/pages/config.php +++ b/app/pages/config.php @@ -4,9 +4,11 @@ $action = $_REQUEST['action'] ?? ''; $agent = $_REQUEST['agent'] ?? ''; require '../app/classes/config.php'; +require '../app/classes/host.php'; require '../app/classes/agent.php'; $configObject = new Config(); +$hostObject = new Host($dbWeb); $agentObject = new Agent($dbWeb); // if a form is submitted, it's from the edit page @@ -17,8 +19,23 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { // $content = file_get_contents($config_file); // $updatedContent = $content; + // new host adding + if (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 - if (isset($_POST['new']) && isset($_POST['item']) && $_POST['new'] === 'true' && $_POST['item'] === 'agent') { + } elseif (isset($_POST['new']) && isset($_POST['item']) && $_POST['new'] === 'true' && $_POST['item'] === 'agent') { $newAgent = [ 'type_id' => $type, 'url' => $url, @@ -136,6 +153,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { 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'; diff --git a/app/templates/config-host-add.php b/app/templates/config-host-add.php new file mode 100644 index 0000000..1c5d8b6 --- /dev/null +++ b/app/templates/config-host-add.php @@ -0,0 +1,49 @@ + + +
Add new host in Jitsi platform = htmlspecialchars($platformDetails[0]['name']) ?>
+Jilo configuration :: Jitsi Meet hosts
+Jitsi hosts configuration +
+getHostDetails($platform_array['id']); +?> + ++ platform = htmlspecialchars($platform_array['name']) ?> +
+ + + ++ = htmlspecialchars($host_array['address']) ?>:= htmlspecialchars($host_array['port']) ?> + + edit host + delete host +
+ ++ total = htmlspecialchars(count($hosts)) ?> = htmlspecialchars(count($hosts)) === 1 ? 'jilo host' : 'jilo hosts' ?> + + add new +
+ +