diff --git a/CHANGELOG.md b/CHANGELOG.md index 00a761d..b8124b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ All notable changes to this project will be documented in this file. ## Unreleased +### Changed +- Jitsi platforms config moved from file to SQLite database + #### Links - upstream: https://code.lindeas.com/lindeas/jilo-web/compare/v0.2...HEAD - codeberg: https://codeberg.org/lindeas/jilo-web/compare/v0.2...HEAD diff --git a/app/classes/config.php b/app/classes/config.php index 0d00fb3..14c8e87 100644 --- a/app/classes/config.php +++ b/app/classes/config.php @@ -2,15 +2,10 @@ class Config { - public function getPlatformDetails($config, $platform_id) { - $platformDetails = $config['platforms'][$platform_id]; - return $platformDetails; - } - // loading the config.js - public function getPlatformConfigjs($platformDetails, $raw = false) { + public function getPlatformConfigjs($jitsiUrl, $raw = false) { // constructing the URL - $configjsFile = $platformDetails['jitsi_url'] . '/config.js'; + $configjsFile = $jitsiUrl . '/config.js'; // default content, if we can't get the file contents $platformConfigjs = "The file $configjsFile can't be loaded."; @@ -50,9 +45,9 @@ class Config { // loading the interface_config.js - public function getPlatformInterfaceConfigjs($platformDetails, $raw = false) { + public function getPlatformInterfaceConfigjs($jitsiUrl, $raw = false) { // constructing the URL - $interfaceConfigjsFile = $platformDetails['jitsi_url'] . '/interface_config.js'; + $interfaceConfigjsFile = $jitsiUrl . '/interface_config.js'; // default content, if we can't get the file contents $platformInterfaceConfigjs = "The file $interfaceConfigjsFile can't be loaded."; diff --git a/app/classes/database.php b/app/classes/database.php index 01f14a9..ca90434 100644 --- a/app/classes/database.php +++ b/app/classes/database.php @@ -1,7 +1,5 @@ db = $database->getConnection(); + } + + // get details of a specified platform ID (or all) + public function getPlatformDetails($platform_id = '') { + $sql = 'SELECT * FROM platforms'; + if ($platform_id !== '') { + $sql .= ' WHERE id = :platform_id'; + $query = $this->db->prepare($sql); + $query->bindParam(':platform_id', $platform_id); + } else { + $query = $this->db->prepare($sql); + } + + $query->execute(); + + return $query->fetchAll(PDO::FETCH_ASSOC); + } + + // add new platform + public function addPlatform($newPlatform) { + try { + $sql = 'INSERT INTO platforms + (name, jitsi_url, jilo_database) + VALUES + (:name, :jitsi_url, :jilo_database)'; + + $query = $this->db->prepare($sql); + $query->execute([ + ':name' => $newPlatform['name'], + ':jitsi_url' => $newPlatform['jitsi_url'], + ':jilo_database' => $newPlatform['jilo_database'], + ]); + + $query->execute(); + return true; + + } catch (Exception $e) { + return $e->getMessage(); + } + } + + // edit an existing platform + public function editPlatform($platform_id, $updatedPlatform) { + try { + $sql = 'UPDATE platforms SET + name = :name, + jitsi_url = :jitsi_url, + jilo_database = :jilo_database + WHERE + id = :platform_id'; + + $query = $this->db->prepare($sql); + $query->execute([ + ':name' => $updatedPlatform['name'], + ':jitsi_url' => $updatedPlatform['jitsi_url'], + ':jilo_database' => $updatedPlatform['jilo_database'], + ':platform_id' => $platform_id, + ]); + + $query->execute(); + return true; + + } catch (Exception $e) { + return $e->getMessage(); + } + } + + + // delete a platform + public function deletePlatform($platform_id) { + try { + $sql = 'DELETE FROM platforms + WHERE + id = :platform_id'; + + $query = $this->db->prepare($sql); + $query->bindParam(':platform_id', $platform_id); + + $query->execute(); + return true; + + } catch (Exception $e) { + return $e->getMessage(); + } + } + + +} + +?> diff --git a/app/config/jilo-web.conf.php b/app/config/jilo-web.conf.php index 00848b8..a40286c 100644 --- a/app/config/jilo-web.conf.php +++ b/app/config/jilo-web.conf.php @@ -31,27 +31,6 @@ return [ // development has verbose error messages, production has not 'environment' => 'development', - // ************************************* - // Maintained by the app, edit with care - // ************************************* - - 'platforms' => [ - '0' => [ - 'name' => 'lindeas', - 'jitsi_url' => 'https://meet.lindeas.com', - 'jilo_database' => '../../jilo/jilo-meet.lindeas.db', - ], - '1' => [ - 'name' => 'meet.example.com', - 'jitsi_url' => 'https://meet.example.com', - 'jilo_database' => '../../jilo/jilo.db', - ], - '2' => [ - 'name' => 'test3', - 'jitsi_url' => 'https://test3.example.com', - 'jilo_database' => '../../jilo/jilo2.db', - ], - ], ]; ?> diff --git a/app/helpers/config.php b/app/helpers/config.php deleted file mode 100644 index a1fab9c..0000000 --- a/app/helpers/config.php +++ /dev/null @@ -1,25 +0,0 @@ - $value) { - $output .= $indent . "'" . $key . "'" . ' => '; - - if (is_array($value)) { - $output .= formatArray($value, $indentLevel + 1); - } else { - $output .= var_export($value, true); - } - - $output .= ",\n"; - } - - $output .= str_repeat(' ', $indentLevel - 1) . ']'; - - return $output; -} - -?> diff --git a/app/helpers/database.php b/app/helpers/database.php index c32b0ad..db56adc 100644 --- a/app/helpers/database.php +++ b/app/helpers/database.php @@ -1,14 +1,13 @@ 'sqlite', diff --git a/app/helpers/render.php b/app/helpers/render.php index c25a8ba..b55a8da 100644 --- a/app/helpers/render.php +++ b/app/helpers/render.php @@ -4,40 +4,14 @@ function renderConfig($configPart, $indent, $platform=false, $parent='') { global $app_root; global $config; - if ($parent === 'platforms') { -?> -
Jilo web configuration for Jitsi platform "= htmlspecialchars($platform_id) ?>"
+Jilo web configuration for Jitsi platform "= htmlspecialchars($platformDetails[0]['name']) ?>"
delete a platform: