diff --git a/.gitignore b/.gitignore index 1e98ca9c532b62dcdb27ae1c21202050984f1bc3..4cee2dc132860a815a76083f293e1f1f101f71d9 100755 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ composer.lock installed.lck apps/maarch_entreprise/xml/config.xml +apps/maarch_entreprise/xml/config.json apps/maarch_entreprise/xml/mailevaConfig.xml apps/maarch_entreprise/xml/log4php.xml *.log diff --git a/apps/maarch_entreprise/xml/config.json.default b/apps/maarch_entreprise/xml/config.json.default new file mode 100644 index 0000000000000000000000000000000000000000..9f0ed144965421580bbbc0c842de0812e7c31392 --- /dev/null +++ b/apps/maarch_entreprise/xml/config.json.default @@ -0,0 +1,21 @@ +{ + "config": { + "lang": "fr", + "applicationName": "MAARCH DEV", + "cookieTime": 200, + "timezone": "Europe/Paris", + "maarchDirectory" : "/var/www/html/MaarchCourrier/", + "customID" : "", + "maarchUrl" : "http://preview.maarchcourrier.com/" + }, + "database": [ + { + "server": "127.0.0.1", + "port": "5432", + "type": "POSTGRESQL", + "name": "MaarchCourrier", + "user": "maarch", + "password": "maarch" + } + ] +} diff --git a/migration/20.10/migrate.sh b/migration/20.10/migrate.sh index b06e1ee17a770a6eaeee65307738ec1ed6b4b82a..76c7c412b6bb6af9f428bd901175351a13e6e3ee 100755 --- a/migration/20.10/migrate.sh +++ b/migration/20.10/migrate.sh @@ -1,5 +1,5 @@ #!/bin/sh -php ./migrateModulesConfig.php +php ./migrateConfigXml.php # mettre en premier php ./migrateNotificationsProperties.php php ./migrateNotificationsConfig.php php ./migrateRemoteSignatureBookConfig.php diff --git a/migration/20.10/migrateConfigXml.php b/migration/20.10/migrateConfigXml.php new file mode 100644 index 0000000000000000000000000000000000000000..ee8806933e6cc252b6f1865899af03d72b6270ea --- /dev/null +++ b/migration/20.10/migrateConfigXml.php @@ -0,0 +1,89 @@ +<?php + +require '../../vendor/autoload.php'; + +chdir('../..'); + +$path = "apps/maarch_entreprise/xml/config.xml"; +if (file_exists($path)) { + if (!is_readable($path)) { + printf("[ERROR] Fichier apps/maarch_entreprise/xml/config.xml non lisible.\n"); + } else { + $loadedXml = simplexml_load_file($path); + + if ($loadedXml) { + $jsonFile = [ + 'config' => [ + 'lang' => (string)$loadedXml->CONFIG->lang, + 'applicationName' => (string)$loadedXml->CONFIG->applicationname, + 'cookieTime' => 10080, + 'timezone' => (string)$loadedXml->CONFIG->timezone, +// 'maarchDirectory' => (string)$loadedXml->CONFIG->maarchDirectory, +// 'customID' => (string)$loadedXml->CONFIG->customID, +// 'maarchUrl' => (string)$loadedXml->CONFIG->maarchUrl, + ], + 'database' => [ + [ + "server" => (string)$loadedXml->CONFIG->databaseserver, + "port" => (string)$loadedXml->CONFIG->databaseserverport, + "type" => (string)$loadedXml->CONFIG->databasetype, + "name" => (string)$loadedXml->CONFIG->databasename, + "user" => (string)$loadedXml->CONFIG->databaseuser, + "password" => (string)$loadedXml->CONFIG->databasepassword + ] + ] + ]; + + $fp = fopen("apps/maarch_entreprise/xml/config.json", 'w'); + fwrite($fp, json_encode($jsonFile, JSON_PRETTY_PRINT)); + fclose($fp); + + // unlink($path); + printf("[SUCCESS] Fichier apps/maarch_entreprise/xml/config.xml migré.\n"); + } + } +} + +$customs = scandir('custom'); +foreach ($customs as $custom) { + if (in_array($custom, ['custom.json', 'custom.xml', '.', '..'])) { + continue; + } + + $path = "custom/{$custom}/apps/maarch_entreprise/xml/config.xml"; + if (file_exists($path)) { + if (!is_readable($path)) { + printf("[ERROR] Fichier custom/{$custom}/apps/maarch_entreprise/xml/config.xml non lisible.\n"); + continue; + } + $loadedXml = simplexml_load_file($path); + + if ($loadedXml) { + $jsonFile = [ + 'config' => [ + 'lang' => (string)$loadedXml->CONFIG->lang, + 'applicationName' => (string)$loadedXml->CONFIG->applicationname, + 'cookieTime' => 10080, + 'timezone' => (string)$loadedXml->CONFIG->timezone, + ], + 'database' => [ + [ + "server" => (string)$loadedXml->CONFIG->databaseserver, + "port" => (string)$loadedXml->CONFIG->databaseserverport, + "type" => (string)$loadedXml->CONFIG->databasetype, + "name" => (string)$loadedXml->CONFIG->databasename, + "user" => (string)$loadedXml->CONFIG->databaseuser, + "password" => (string)$loadedXml->CONFIG->databasepassword + ] + ] + ]; + + $fp = fopen("custom/{$custom}/apps/maarch_entreprise/xml/config.json", 'w'); + fwrite($fp, json_encode($jsonFile, JSON_PRETTY_PRINT)); + fclose($fp); + +// unlink($path); + printf("[SUCCESS] Fichier custom/{$custom}/apps/maarch_entreprise/xml/config.xml migré.\n"); + } + } +} diff --git a/migration/20.10/migrateModulesConfig.php b/migration/20.10/migrateModulesConfig.php deleted file mode 100755 index 5bf76fca2292f0956d7e7e9f7db322f9a255a854..0000000000000000000000000000000000000000 --- a/migration/20.10/migrateModulesConfig.php +++ /dev/null @@ -1,63 +0,0 @@ -<?php - -require '../../vendor/autoload.php'; - -chdir('../..'); - -$nonReadableFiles = []; -$migrated = 0; -$customs = scandir('custom'); - -foreach ($customs as $custom) { - if (in_array($custom, ['custom.json', 'custom.xml', '.', '..'])) { - continue; - } - - \SrcCore\models\DatabasePDO::reset(); - new \SrcCore\models\DatabasePDO(['customId' => $custom]); - - $path = "custom/{$custom}/apps/maarch_entreprise/xml/config.xml"; - if (file_exists($path)) { - if (!is_readable($path) || !is_writable($path)) { - $nonReadableFiles[] = $path; - continue; - } - $loadedXml = simplexml_load_file($path); - - if ($loadedXml) { - unset($loadedXml->CONFIG->CookieTime); - $loadedXml->CONFIG->cookieTime = 10080; - $i = 0; - foreach ($loadedXml->MODULES as $value) { - if (in_array($loadedXml->MODULES[$i]->moduleid, ['convert', 'reports', 'full_text', 'cases'])) { - unset($loadedXml->MODULES[$i]); - } - $i++; - } - - $res = formatXml($loadedXml); - $fp = fopen($path, "w+"); - if ($fp) { - fwrite($fp, $res); - } - - $migrated++; - } - } -} - -foreach ($nonReadableFiles as $file) { - printf("The file %s it is not readable or not writable.\n", $file); -} - -printf($migrated . " custom(s) avec config.xml (modules) trouvé(s) et migré(s).\n"); - -function formatXml($simpleXMLElement) -{ - $xmlDocument = new DOMDocument('1.0'); - $xmlDocument->preserveWhiteSpace = false; - $xmlDocument->formatOutput = true; - $xmlDocument->loadXML($simpleXMLElement->asXML()); - - return $xmlDocument->saveXML(); -} diff --git a/src/core/controllers/AuthenticationController.php b/src/core/controllers/AuthenticationController.php index 95c7d9d63af6f7494f1376c975cc836424be092e..8a0d7dff7c89e4789780aa06ef7eca1096a2fb86 100755 --- a/src/core/controllers/AuthenticationController.php +++ b/src/core/controllers/AuthenticationController.php @@ -298,11 +298,11 @@ class AuthenticationController { $sessionTime = AuthenticationController::MAX_DURATION_TOKEN; - $loadedXml = CoreConfigModel::getXmlLoaded(['path' => 'apps/maarch_entreprise/xml/config.xml']); - if ($loadedXml) { - if (!empty($loadedXml->CONFIG->cookieTime)) { - if ($sessionTime > (int)$loadedXml->CONFIG->cookieTime) { - $sessionTime = (int)$loadedXml->CONFIG->cookieTime; + $file = CoreConfigModel::getJsonLoaded(['path' => 'apps/maarch_entreprise/xml/config.json']); + if ($file) { + if (!empty($file['config']['cookieTime'])) { + if ($sessionTime > (int)$file['config']['cookieTime']) { + $sessionTime = (int)$file['config']['cookieTime']; } } } @@ -323,9 +323,9 @@ class AuthenticationController { $sessionTime = AuthenticationController::MAX_DURATION_TOKEN; - $loadedXml = CoreConfigModel::getXmlLoaded(['path' => 'apps/maarch_entreprise/xml/config.xml']); - if ($loadedXml) { - $sessionTime = (int)$loadedXml->CONFIG->cookieTime; + $file = CoreConfigModel::getJsonLoaded(['path' => 'apps/maarch_entreprise/xml/config.json']); + if ($file) { + $sessionTime = (int)$file['config']['cookieTime']; } $token = [ diff --git a/src/core/models/CoreConfigModel.php b/src/core/models/CoreConfigModel.php index 03dba875c11239b8d0b99b4188dd7ede24cdb656..71462ef59266c2f436f0fa3c9cb0b1778df304c9 100755 --- a/src/core/models/CoreConfigModel.php +++ b/src/core/models/CoreConfigModel.php @@ -59,10 +59,10 @@ class CoreConfigModel public static function getConfigPath() { $customId = CoreConfigModel::getCustomId(); - if (!empty($customId) && is_file("custom/{$customId}/apps/maarch_entreprise/xml/config.xml")) { - $path = "custom/{$customId}/apps/maarch_entreprise/xml/config.xml"; + if (!empty($customId) && is_file("custom/{$customId}/apps/maarch_entreprise/xml/config.json")) { + $path = "custom/{$customId}/apps/maarch_entreprise/xml/config.json"; } else { - $path = 'apps/maarch_entreprise/xml/config.xml'; + $path = 'apps/maarch_entreprise/xml/config.json'; } return $path; @@ -76,10 +76,10 @@ class CoreConfigModel return $applicationName; } - $loadedXml = CoreConfigModel::getXmlLoaded(['path' => 'apps/maarch_entreprise/xml/config.xml']); + $file = CoreConfigModel::getJsonLoaded(['path' => 'apps/maarch_entreprise/xml/config.json']); - if ($loadedXml) { - $applicationName = (string)$loadedXml->CONFIG->applicationname; + if (!empty($file['config']['applicationName'])) { + $applicationName = $file['config']['applicationName']; return $applicationName; } @@ -99,10 +99,10 @@ class CoreConfigModel { $availableLanguages = ['en', 'fr', 'nl']; - $loadedXml = CoreConfigModel::getXmlLoaded(['path' => 'apps/maarch_entreprise/xml/config.xml']); + $file = CoreConfigModel::getJsonLoaded(['path' => 'apps/maarch_entreprise/xml/config.json']); - if ($loadedXml) { - $lang = (string)$loadedXml->CONFIG->lang; + if ($file) { + $lang = $file['config']['lang']; if (in_array($lang, $availableLanguages)) { return $lang; } @@ -140,11 +140,11 @@ class CoreConfigModel { $timezone = 'Europe/Paris'; - $loadedXml = CoreConfigModel::getXmlLoaded(['path' => 'apps/maarch_entreprise/xml/config.xml']); + $file = CoreConfigModel::getJsonLoaded(['path' => 'apps/maarch_entreprise/xml/config.json']); - if ($loadedXml) { - if (!empty((string)$loadedXml->CONFIG->timezone)) { - $timezone = (string)$loadedXml->CONFIG->timezone; + if ($file) { + if (!empty($file['config']['timezone'])) { + $timezone = $file['config']['timezone']; } } @@ -246,48 +246,26 @@ class CoreConfigModel return $xmlfile; } - /** - * @codeCoverageIgnore - */ - public static function initAngularStructure() + public static function getJsonLoaded(array $args) { - $lang = CoreConfigModel::getLanguage(); - $appName = CoreConfigModel::getApplicationName(); - - $structure = '<!doctype html>'; - $structure .= "<html lang='{$lang}'>"; - $structure .= '<head>'; - $structure .= "<meta charset='utf-8'>"; - $structure .= "<title>{$appName}</title>"; - $structure .= "<link rel='icon' type=\"image/svg+xml\" href='static.php?filename=logo_only.svg' />"; - - /* CSS PARTS */ - $structure .= '<link rel="stylesheet" href="../../node_modules/@fortawesome/fontawesome-free/css/all.css" media="screen" />'; - $structure .= '<link rel="stylesheet" href="css/font-awesome-maarch/css/font-maarch.css" media="screen" />'; - $structure .= '<link rel="stylesheet" href="../../node_modules/jstree-bootstrap-theme/dist/themes/proton/style.min.css" media="screen" />'; - - $structure .= '</head>'; - - /* SCRIPS PARTS */ - $structure .= "<script src='../../node_modules/jquery/dist/jquery.min.js'></script>"; - $structure .= "<script src='../../node_modules/zone.js/dist/zone.min.js'></script>"; - $structure .= "<script src='../../node_modules/bootstrap/dist/js/bootstrap.min.js'></script>"; - $structure .= "<script src='../../node_modules/tinymce/tinymce.min.js'></script>"; - $structure .= "<script src='../../node_modules/jquery.nicescroll/dist/jquery.nicescroll.min.js'></script>"; - $structure .= "<script src='../../node_modules/tooltipster/dist/js/tooltipster.bundle.min.js'></script>"; - $structure .= "<script src='../../node_modules/jquery-typeahead/dist/jquery.typeahead.min.js'></script> "; - $structure .= "<script src='../../node_modules/chosen-js/chosen.jquery.min.js'></script>"; - $structure .= "<script src='../../node_modules/jstree-bootstrap-theme/dist/jstree.js'></script>"; - $structure .= "<script src='js/angularFunctions.js'></script>"; - - /* AUTO DISCONNECT */ - $structure .= "<script>checkCookieAuth();</script>"; - - $structure .= '<body>'; - $structure .= '</body>'; - $structure .= '</html>'; - - return $structure; + ValidatorModel::notEmpty($args, ['path']); + ValidatorModel::stringType($args, ['path']); + + $customId = CoreConfigModel::getCustomId(); + + if (is_file("custom/{$customId}/{$args['path']}")) { + $path = "custom/{$customId}/{$args['path']}"; + } else { + $path = $args['path']; + } + + $file = null; + if (file_exists($path)) { + $file = file_get_contents($path); + $file = json_decode($file, true); + } + + return $file; } /** diff --git a/src/core/models/DatabasePDO.php b/src/core/models/DatabasePDO.php index 2595d1acd216a80b00099f65f1cfdab6199562ff..b805dfd3a2cdb2d00750953a9ccc0399ab883357 100755 --- a/src/core/models/DatabasePDO.php +++ b/src/core/models/DatabasePDO.php @@ -26,98 +26,70 @@ class DatabasePDO return; } - $server = ''; - $port = ''; - $name = ''; - $user = ''; - $password = ''; - $formattedDriver = ''; - - if (!empty($args['server'])) { - $server = $args['server']; - $port = $args['port']; - $name = $args['name']; - $user = $args['user']; - $password = $args['password']; - self::$type = $args['type']; + if (!empty($args['customId'])) { + $customId = $args['customId']; } else { - if (!empty($args['customId'])) { - $customId = $args['customId']; - } else { - $customId = CoreConfigModel::getCustomId(); - } - - if (!empty($customId) && file_exists("custom/{$customId}/apps/maarch_entreprise/xml/config.xml")) { - $path = "custom/{$customId}/apps/maarch_entreprise/xml/config.xml"; - } else { - $path = 'apps/maarch_entreprise/xml/config.xml'; - } - - if (!file_exists($path)) { - if (file_exists("{$GLOBALS['MaarchDirectory']}custom/{$customId}/apps/maarch_entreprise/xml/config.xml")) { - $path = "{$GLOBALS['MaarchDirectory']}custom/{$customId}/apps/maarch_entreprise/xml/config.xml"; - } else { - $path = "{$GLOBALS['MaarchDirectory']}apps/maarch_entreprise/xml/config.xml"; - } - } + $customId = CoreConfigModel::getCustomId(); + } - if (file_exists($path)) { - $loadedXml = simplexml_load_file($path); - if ($loadedXml) { - $server = (string)$loadedXml->CONFIG->databaseserver; - $port = (string)$loadedXml->CONFIG->databaseserverport; - $name = (string)$loadedXml->CONFIG->databasename; - $user = (string)$loadedXml->CONFIG->databaseuser; - $password = (string)$loadedXml->CONFIG->databasepassword; - self::$type = (string)$loadedXml->CONFIG->databasetype; - } - } + if (!empty($customId) && file_exists("custom/{$customId}/apps/maarch_entreprise/xml/config.json")) { + $path = "custom/{$customId}/apps/maarch_entreprise/xml/config.json"; + } else { + $path = 'apps/maarch_entreprise/xml/config.json'; } - if (self::$type == 'POSTGRESQL') { - $formattedDriver = 'pgsql'; - } elseif (self::$type == 'MYSQL') { - $formattedDriver = 'mysql'; - } elseif (self::$type == 'ORACLE') { - $formattedDriver = 'oci'; + if (!file_exists($path)) { + throw new \Exception('No configuration file found'); + } + $jsonFile = file_get_contents($path); + $jsonFile = json_decode($jsonFile, true); + if (empty($jsonFile['database'])) { + throw new \Exception('No database part found in configuration file'); } - ValidatorModel::notEmpty( - ['driver' => $formattedDriver, 'server' => $server, 'port' => $port, 'name' => $name, 'user' => $user], - ['driver', 'server', 'port', 'name', 'user'] - ); - ValidatorModel::stringType( - ['driver' => $formattedDriver, 'server' => $server, 'name' => $name, 'user' => $user], - ['driver', 'server', 'name', 'user'] - ); - ValidatorModel::intVal(['port' => $port], ['port']); + foreach ($jsonFile['database'] as $key => $database) { + $server = $database['server']; + $port = $database['port']; + $name = $database['name']; + $user = $database['user']; + $password = $database['password']; + self::$type = $database['type']; - if (self::$type == 'ORACLE') { - $dsn = "oci:dbname=(DESCRIPTION = (ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = {$server})(PORT = {$port})))(CONNECT_DATA =(SERVICE_NAME = {$name})))"; - } else { - $dsn = "{$formattedDriver}:host={$server};port={$port};dbname={$name}"; - } + ValidatorModel::notEmpty(['server' => $server, 'port' => $port, 'name' => $name, 'user' => $user], ['server', 'port', 'name', 'user']); + ValidatorModel::stringType(['server' => $server, 'name' => $name, 'user' => $user], ['server', 'name', 'user']); + ValidatorModel::intVal(['port' => $port], ['port']); + + $formattedDriver = 'pgsql'; + if (self::$type == 'POSTGRESQL') { + $formattedDriver = 'pgsql'; + } elseif (self::$type == 'MYSQL') { + $formattedDriver = 'mysql'; + } elseif (self::$type == 'ORACLE') { + $formattedDriver = 'oci'; + } - $options = [ - \PDO::ATTR_PERSISTENT => true, - \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, - \PDO::ATTR_CASE => \PDO::CASE_NATURAL - ]; + $options = [ + \PDO::ATTR_PERSISTENT => true, + \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, + \PDO::ATTR_CASE => \PDO::CASE_NATURAL + ]; - try { - self::$pdo = new \PDO($dsn, $user, $password, $options); - } catch (\PDOException $PDOException) { + $dsn = "{$formattedDriver}:host={$server};port={$port};dbname={$name}"; try { - $options[\PDO::ATTR_PERSISTENT] = false; self::$pdo = new \PDO($dsn, $user, $password, $options); } catch (\PDOException $PDOException) { - throw new \Exception($PDOException->getMessage()); + try { + $options[\PDO::ATTR_PERSISTENT] = false; + self::$pdo = new \PDO($dsn, $user, $password, $options); + } catch (\PDOException $PDOException) { + if (!empty($jsonFile['database'][$key + 1])) { + continue; + } else { + throw new \Exception($PDOException->getMessage()); + } + } } } - - if (self::$type == 'ORACLE') { - $this->query("alter session set nls_date_format='dd-mm-yyyy HH24:MI:SS'"); - } } public function query($queryString, array $data = []) @@ -199,11 +171,6 @@ class DatabasePDO self::$preparedQueries = []; } - public function getType() - { - return self::$type; - } - public function beginTransaction() { return self::$pdo->beginTransaction();