From 3e48f73dab5f19257f567ffcb1f80946c82891a7 Mon Sep 17 00:00:00 2001 From: Ludovic <54670129+lbr38@users.noreply.github.com> Date: Wed, 11 Sep 2024 12:07:22 +0200 Subject: [PATCH] 4.9.0 --- Todolist | 4 +- www/controllers/Common.php | 40 ---- www/controllers/Host.php | 13 +- www/controllers/Log/Log.php | 48 +++-- www/controllers/Repo/Mirror/Deb.php | 44 ++++ www/controllers/Repo/Mirror/Mirror.php | 12 ++ www/controllers/Repo/Mirror/Rpm.php | 44 ++++ www/controllers/Repo/Repo.php | 65 +++++- www/controllers/Task/Form/Create.php | 10 + .../Task/Form/Param/PackageExclude.php | 21 ++ .../Task/Form/Param/PackageInclude.php | 21 ++ www/controllers/Task/Form/Update.php | 10 + www/controllers/Task/Log.php | 28 ++- www/controllers/Task/Param.php | 9 +- www/controllers/Task/Repo/Create.php | 4 +- www/controllers/Task/Repo/Duplicate.php | 2 +- www/controllers/Task/Repo/Env.php | 1 + www/controllers/Task/Repo/Finalize.php | 14 +- www/controllers/Task/Repo/Package/Sign.php | 2 +- www/controllers/Task/Repo/Package/Sync.php | 4 + www/controllers/Task/Repo/Update.php | 4 +- www/controllers/ajax/host.php | 15 ++ www/models/Connection.php | 25 ++- www/models/Cve/Cve.php | 36 ++-- www/models/Cve/Tools/Import.php | 14 +- www/models/Environment.php | 6 +- www/models/Group.php | 22 +- www/models/History.php | 6 +- www/models/Host.php | 202 +++++++++++------- www/models/Layout/ContainerState.php | 8 +- www/models/Log/Log.php | 28 +-- www/models/Login.php | 24 +-- www/models/Notification.php | 10 +- www/models/Profile.php | 46 ++-- www/models/Repo/Listing.php | 10 +- www/models/Repo/Repo.php | 154 ++++++++----- www/models/Settings.php | 4 +- www/models/Source.php | 16 +- www/models/Stat.php | 22 +- www/models/Task/Schedule/Schedule.php | 2 +- www/models/Task/Task.php | 46 ++-- www/public/assets/favicon.ico | Bin 1742 -> 3821 bytes www/public/resources/js/functions.js | 33 +++ www/public/resources/js/general.js | 23 +- www/public/resources/js/host.js | 182 +++++++--------- www/public/resources/js/task.js | 2 + www/public/resources/styles/common.css | 54 ++++- www/public/resources/styles/run.css | 10 - www/public/resources/styles/stats-hosts.css | 35 --- www/update/database/4.9.0.php | 25 +++ www/update/database/{ => archives}/3.7.11.php | 0 www/update/database/{ => archives}/3.7.15.php | 0 www/update/database/{ => archives}/3.7.17.php | 0 www/update/database/{ => archives}/3.7.6.php | 0 www/update/database/{ => archives}/4.0.0.php | 0 www/version | 2 +- .../header/general-log-messages.inc.php | 42 +++- .../includes/containers/hosts/list.inc.php | 7 + www/views/includes/forms/tasks/update.inc.php | 105 ++++++--- www/views/includes/panels/repos/new.inc.php | 22 ++ www/views/includes/repos-list.inc.php | 2 +- .../includes/tables/host/requests.inc.php | 116 ++++++++-- .../tasks/new-update-rebuild.inc.php | 32 ++- 63 files changed, 1195 insertions(+), 593 deletions(-) create mode 100644 www/controllers/Task/Form/Param/PackageExclude.php create mode 100644 www/controllers/Task/Form/Param/PackageInclude.php create mode 100644 www/update/database/4.9.0.php rename www/update/database/{ => archives}/3.7.11.php (100%) rename www/update/database/{ => archives}/3.7.15.php (100%) rename www/update/database/{ => archives}/3.7.17.php (100%) rename www/update/database/{ => archives}/3.7.6.php (100%) rename www/update/database/{ => archives}/4.0.0.php (100%) diff --git a/Todolist b/Todolist index a09deb05..1d800f6b 100644 --- a/Todolist +++ b/Todolist @@ -1,7 +1,5 @@ [ IN PROGRESS ] - - (Feature) Add checkboxes to select all the latest snapshots in repos list - - (Feature) Add packages deduplication between snapshots [ BUGS ] @@ -18,7 +16,7 @@ - Think about a way to publish debian repos in a more elegant way. Currently: https:///repo/debian/dists/buster/main_prod buster main_prod - (RPM) See how to accelerate the rpm signing process by using multi-threading - (Feature) Support Arch Linux packages https://blog.desdelinux.net/en/create-your-local-arch-linux-repository/ - - (Feature) Add a way to filter wanted/unwanted packages from a repository sync, with a regex + [ HOSTS / LINUPDATE ] diff --git a/www/controllers/Common.php b/www/controllers/Common.php index 3c269d48..0ef7bfe9 100644 --- a/www/controllers/Common.php +++ b/www/controllers/Common.php @@ -145,46 +145,6 @@ public static function printAlert(string $message, string $alertType = null) echo ''; } - /** - * Affiche une erreur générique ou personnalisée lorsqu'il y a eu une erreur d'exécution d'une requête dans la base de données - * Ajoute une copie de l'erreur dans le fichier de logs 'exceptions' - */ - public static function dbError(string $exception = null) - { - /** - * Date et heure de l'évènement - */ - $content = PHP_EOL . date("Y-m-d H:i:s") . PHP_EOL; - - /** - * Récupération du nom du fichier ayant fait appel à cette fonction - */ - $content .= 'File : ' . debug_backtrace()[0]['file'] . PHP_EOL; - - /** - * Si une exception a été catchée, on va l'ajouter au contenu - */ - if (!empty($exception)) { - $content .= 'Error catched ¬' . PHP_EOL . $exception . PHP_EOL; - } - - /** - * Ajout du contenu au fichier de log - */ - $content .= '___________________________' . PHP_EOL; - file_put_contents(EXCEPTIONS_LOG, $content, FILE_APPEND); - - /** - * Lancement d'une exception qui sera catchée par printAlert - * Si le mode debug est activé alors on affiche l'exception dans le message d'erreur - */ - if (!empty($exception) and DEBUG_MODE === true) { - throw new Exception('An error occured while executing request in database
' . $exception . '
'); - } else { - throw new Exception('An error occured while executing request in database'); - } - } - /** * Colore l'environnement d'une étiquette rouge ou blanche */ diff --git a/www/controllers/Host.php b/www/controllers/Host.php index b89a8fdd..ec46228b 100644 --- a/www/controllers/Host.php +++ b/www/controllers/Host.php @@ -331,8 +331,7 @@ public function getPackageTimeline(string $id, string $packageName) /** * Build the timeline to display and send it back to the ajax controller because it is jquery that will take care of displaying it afterwards */ - $content = '

' . strtoupper($packageName) . ' PACKAGE HISTORY

'; - $content .= '
'; + $content = '
'; /** * The first block will be displayed on the left in the timeline @@ -1626,7 +1625,7 @@ public function deleteWsRequest(int $id) * Get request log details * Request log is a file stored in the websocket-requests logs directory */ - public function getRequestLog(int $id) + public function getRequestLog(int $id) : string { $logFile = WS_REQUESTS_LOGS_DIR . '/request-' . $id . '.log'; @@ -1646,4 +1645,12 @@ public function getRequestLog(int $id) return $content; } + + /** + * Get request package log details + */ + public function getRequestPackageLog(int $id, string $package, string $status) : string|null + { + return $this->model->getRequestPackageLog($id, $package, $status); + } } diff --git a/www/controllers/Log/Log.php b/www/controllers/Log/Log.php index 87c4296d..2abd4e25 100644 --- a/www/controllers/Log/Log.php +++ b/www/controllers/Log/Log.php @@ -25,31 +25,49 @@ public function getUnread(string $type = null, int $limit = 0) * Log a message * Only log if a similar log message is not already logged */ - public function log(string $type, string $component, string $message) + public function log(string $type, string $component, string $message, string $details = '') { - /** - * Get all unread log - */ - $logs = $this->getUnread($type); - - if (!empty($logs)) { + try { /** - * Loop through all logs + * Get all unread log */ - foreach ($logs as $log) { + $logs = $this->getUnread($type); + + if (!empty($logs)) { /** - * If a similar log message is already logged, quit + * Loop through all logs */ - if ($log['Component'] == $component && $log['Message'] == $message) { - return; + foreach ($logs as $log) { + /** + * If a similar log message is already logged, quit + */ + if ($log['Component'] == $component && $log['Message'] == $message && $log['Details'] == $details) { + return; + } } } - } + + /** + * Log the message + */ + $this->model->log($type, $component, $message, $details); /** - * Log the message + * If the log could not be saved in database, log the error in error_log */ - $this->model->log($type, $component, $message); + } catch (\Exception $e) { + error_log('Here is a database error while trying to save log: ' . $e . PHP_EOL); + + + /** + * If the log cannot be saved then log directly in error_log + */ + if (!empty($details)) { + error_log('Here is a the original error that could not be saved in database: ' . $message . ': ' . $details . PHP_EOL); + } else { + error_log('Here is a the original error that could not be saved in database: ' . $message . PHP_EOL); + } + } } /** diff --git a/www/controllers/Repo/Mirror/Deb.php b/www/controllers/Repo/Mirror/Deb.php index f81541ca..cc1c8271 100644 --- a/www/controllers/Repo/Mirror/Deb.php +++ b/www/controllers/Repo/Mirror/Deb.php @@ -646,6 +646,50 @@ private function downloadDebPackages($url) */ $this->logOutput('(' . $packageCounter . '/' . $totalPackages . ') ➙ ' . $debPackageLocation . ' ... '); + /** + * If a list of package(s) to include has been provided, check if the package is in the list + * If not, skip the package + */ + if (!empty($this->packagesToInclude)) { + $isIn = false; + + foreach ($this->packagesToInclude as $packageToInclude) { + if (preg_match('/' . $packageToInclude . '/', $debPackageName)) { + $isIn = true; + } + } + + /** + * If package is not in the list of packages to include, skip it + */ + if (!$isIn) { + $this->logOutput('not in the list of packages to include (ignoring)' . PHP_EOL); + continue; + } + } + + /** + * If a list of package(s) to exclude has been provided, check if the package is in the list + * If so, skip the package + */ + if (!empty($this->packagesToExclude)) { + $isIn = false; + + foreach ($this->packagesToExclude as $packageToExclude) { + if (preg_match('/' . $packageToExclude . '/', $debPackageName)) { + $isIn = true; + } + } + + /** + * If package is in the list of packages to exclude, skip it + */ + if ($isIn) { + $this->logOutput('in the list of packages to exclude (ignoring)' . PHP_EOL); + continue; + } + } + /** * Check that package naming respects the Debian package naming convention * It must ends with _.deb, if not then rename it diff --git a/www/controllers/Repo/Mirror/Mirror.php b/www/controllers/Repo/Mirror/Mirror.php index e8cad1f6..51b982b8 100644 --- a/www/controllers/Repo/Mirror/Mirror.php +++ b/www/controllers/Repo/Mirror/Mirror.php @@ -31,6 +31,8 @@ class Mirror protected $sslCustomCaCertificate; protected $curlHandle; protected $previousSnapshotDirPath; + protected $packagesToInclude = []; + protected $packagesToExclude = []; public function setUrl(string $url) { @@ -97,6 +99,16 @@ public function setPreviousSnapshotDirPath(string $path) $this->previousSnapshotDirPath = $path; } + public function setPackagesToInclude(array $packages) + { + $this->packagesToInclude = $packages; + } + + public function setPackagesToExclude(array $packages) + { + $this->packagesToExclude = $packages; + } + public function getPackagesToSign() { return $this->packagesToSign; diff --git a/www/controllers/Repo/Mirror/Rpm.php b/www/controllers/Repo/Mirror/Rpm.php index 156fa3f4..5a4c7671 100644 --- a/www/controllers/Repo/Mirror/Rpm.php +++ b/www/controllers/Repo/Mirror/Rpm.php @@ -693,6 +693,50 @@ private function downloadRpmPackages(string $url) */ $this->logOutput('(' . $packageCounter . '/' . $totalPackages . ') ➙ ' . $rpmPackageLocation . ' ... '); + /** + * If a list of package(s) to include has been provided, check if the package is in the list + * If not, skip the package + */ + if (!empty($this->packagesToInclude)) { + $isIn = false; + + foreach ($this->packagesToInclude as $packageToInclude) { + if (preg_match('/' . $packageToInclude . '/', $rpmPackageName)) { + $isIn = true; + } + } + + /** + * If package is not in the list of packages to include, skip it + */ + if (!$isIn) { + $this->logOutput('not in the list of packages to include (ignoring)' . PHP_EOL); + continue; + } + } + + /** + * If a list of package(s) to exclude has been provided, check if the package is in the list + * If so, skip the package + */ + if (!empty($this->packagesToExclude)) { + $isIn = false; + + foreach ($this->packagesToExclude as $packageToExclude) { + if (preg_match('/' . $packageToExclude . '/', $rpmPackageName)) { + $isIn = true; + } + } + + /** + * If package is in the list of packages to exclude, skip it + */ + if ($isIn) { + $this->logOutput('in the list of packages to exclude (ignoring)' . PHP_EOL); + continue; + } + } + /** * Check that package architecture is valid */ diff --git a/www/controllers/Repo/Repo.php b/www/controllers/Repo/Repo.php index b7cd77bf..90edba47 100644 --- a/www/controllers/Repo/Repo.php +++ b/www/controllers/Repo/Repo.php @@ -27,6 +27,8 @@ class Repo private $env; private $description; private $group; + private $packagesToInclude = []; + private $packagesToExclude = []; private $signed; private $status; private $rebuild; @@ -164,6 +166,16 @@ public function setArch(array $arch) $this->arch = $arch; } + public function setPackagesToInclude(array $packages) + { + $this->packagesToInclude = $packages; + } + + public function setPackagesToExclude(array $packages) + { + $this->packagesToExclude = $packages; + } + public function setReleasever(string $releasever) { $this->releasever = $releasever; @@ -264,6 +276,16 @@ public function getArch() return $this->arch; } + public function getPackagesToInclude() + { + return $this->packagesToInclude; + } + + public function getPackagesToExclude() + { + return $this->packagesToExclude; + } + public function getReleasever() { return $this->releasever; @@ -305,7 +327,7 @@ public function getTaskId() } /** - * Récupère toutes les informations d'un repo, snapshot en env en base de données + * Retrieve all informations from a repo, snapshot and env in database */ public function getAllById(string|null $repoId = null, string|null $snapId = null, string|null $envId = null) { @@ -315,7 +337,7 @@ public function getAllById(string|null $repoId = null, string|null $snapId = nul } /** - * Fonction qui parse et récupère les résultats des fonctions getAllBy* + * Function that parses and retrieves the results of the getAllBy* functions */ private function getAllByParser(array $data) { @@ -377,6 +399,12 @@ private function getAllByParser(array $data) if (!empty($data['Arch'])) { $this->setArch(explode(',', $data['Arch'])); } + if (!empty($data['Pkg_included'])) { + $this->setPackagesToInclude(explode(',', $data['Pkg_included'])); + } + if (!empty($data['Pkg_excluded'])) { + $this->setPackagesToExclude(explode(',', $data['Pkg_excluded'])); + } } /** @@ -512,6 +540,8 @@ public function addReposIdToGroup(array $reposId = null, int $groupId) $this->model->removeFromGroup($actualRepoId, $groupId); } } + + \Controllers\App\Cache::clear(); } /** @@ -552,9 +582,14 @@ public function getEnvIdBySnapId(string $snapId) return $this->model->getEnvIdBySnapId($snapId); } + /** + * Set environment description + */ public function envSetDescription(string $envId, string $description) { - return $this->model->envSetDescription($envId, $description); + $this->model->envSetDescription($envId, $description); + + \Controllers\App\Cache::clear(); } /** @@ -681,6 +716,8 @@ public function cleanSnapshots() } } + \Controllers\App\Cache::clear(); + return $returnOutput; } @@ -708,6 +745,8 @@ public function cleanGroups() $this->model->removeFromGroup($id); } } + + \Controllers\App\Cache::clear(); } /** @@ -758,6 +797,22 @@ public function snapSetArch(string $snapId, array $arch) $this->model->snapSetArch($snapId, implode(',', $arch)); } + /** + * Set packages included + */ + public function snapSetPackagesIncluded(int $snapId, array $packages) + { + $this->model->snapSetPackagesIncluded($snapId, implode(',', $packages)); + } + + /** + * Set packages excluded + */ + public function snapSetPackagesExcluded(int $snapId, array $packages) + { + $this->model->snapSetPackagesExcluded($snapId, implode(',', $packages)); + } + /** * Add a repo in database */ @@ -769,9 +824,9 @@ public function add(string $source, string $packageType, string $name) /** * Add a repo snapshot in database */ - public function addSnap(string $date, string $time, string $gpgSignature, array $arch, array $includeTranslation, string $type, string $status, string $repoId) + public function addSnap(string $date, string $time, string $gpgSignature, array $arch, array $includeTranslation, array $packagesIncluded, array $packagesExcluded, string $type, string $status, string $repoId) { - $this->model->addSnap($date, $time, $gpgSignature, $arch, $includeTranslation, $type, $status, $repoId); + $this->model->addSnap($date, $time, $gpgSignature, $arch, $includeTranslation, $packagesIncluded, $packagesExcluded, $type, $status, $repoId); } /** diff --git a/www/controllers/Task/Form/Create.php b/www/controllers/Task/Form/Create.php index ecea0a5f..aa8e89a6 100644 --- a/www/controllers/Task/Form/Create.php +++ b/www/controllers/Task/Form/Create.php @@ -102,6 +102,16 @@ public function validate(array $formParams) * Check gpg sign */ Param\GpgSign::check($formParams['gpg-sign']); + + /** + * Check package(s) to include + */ + Param\PackageInclude::check($formParams['package-include']); + + /** + * Check package(s) to exclude + */ + Param\PackageExclude::check($formParams['package-exclude']); } /** diff --git a/www/controllers/Task/Form/Param/PackageExclude.php b/www/controllers/Task/Form/Param/PackageExclude.php new file mode 100644 index 00000000..86d72b94 --- /dev/null +++ b/www/controllers/Task/Form/Param/PackageExclude.php @@ -0,0 +1,21 @@ +location) { + if ($retries == 5) { + throw new Exception('Error while generating task log: cannot create symlink to the latest log file'); + } + /** - * If first unlink fails, try another time with a random sleep time - * To fix error when multiple tasks are running at the same time and tries to update the symlink + * Sleep a little bit before trying again */ - if (!unlink(MAIN_LOGS_DIR . '/latest')) { - usleep(rand(100000, 1500000)); + usleep(rand(100000, 1500000)); - if (!unlink(MAIN_LOGS_DIR . '/latest')) { - throw new Exception('Error while generating task log: cannot remove symlink to the latest log file'); - } + /** + * If the symlink already exists, delete it + */ + if (file_exists(MAIN_LOGS_DIR . '/latest')) { + unlink(MAIN_LOGS_DIR . '/latest'); } - } - if (!symlink($this->location, MAIN_LOGS_DIR . '/latest')) { - throw new Exception('Error while generating task log: cannot create symlink to the latest log file'); + symlink($this->location, MAIN_LOGS_DIR . '/latest'); + + $retries++; } } diff --git a/www/controllers/Task/Param.php b/www/controllers/Task/Param.php index 2d02d0d6..6918f17d 100644 --- a/www/controllers/Task/Param.php +++ b/www/controllers/Task/Param.php @@ -16,7 +16,7 @@ public function taskParamsCheck($taskType, $taskParams, $requiredParams) */ foreach ($requiredParams as $param) { if (empty($taskParams[$param])) { - throw new Exception($taskType . ": parameter '$param' is not defined."); + throw new Exception($taskType . ': parameter ' . $param . ' is not defined.'); } } } @@ -43,7 +43,9 @@ public function taskParamsSet($taskParams, $requiredParams = null, $optionalPara 'gpg-sign' => 'setGpgSign', 'env' => 'setEnv', 'description' => 'setDescription', - 'group' => 'setGroup' + 'group' => 'setGroup', + 'package-include' => 'setPackagesToInclude', + 'package-exclude' => 'setPackagesToExclude' ); /** @@ -61,7 +63,8 @@ public function taskParamsSet($taskParams, $requiredParams = null, $optionalPara */ if (!empty($optionalParams)) { foreach ($optionalParams as $param) { - if (!empty($taskParams[$param])) { + // if (!empty($taskParams[$param])) { + if (isset($taskParams[$param])) { $setterFunction = $setters[$param]; $this->repo->$setterFunction($taskParams[$param]); } diff --git a/www/controllers/Task/Repo/Create.php b/www/controllers/Task/Repo/Create.php index 865ee63b..b20c4e34 100644 --- a/www/controllers/Task/Repo/Create.php +++ b/www/controllers/Task/Repo/Create.php @@ -34,7 +34,7 @@ public function __construct(string $taskId) * Check and set task parameters */ $requiredParams = array('package-type', 'repo-type', 'arch'); - $optionalParams = array('env', 'group', 'description'); + $optionalParams = array('env', 'group', 'description', 'package-include', 'package-exclude'); /** * Required parameters in case the repo type is 'rpm' @@ -363,7 +363,7 @@ private function local() /** * Add snapshot to database */ - $this->repo->addSnap($this->repo->getDate(), $this->repo->getTime(), 'false', $this->repo->getArch(), array(), $this->repo->getType(), 'active', $this->repo->getRepoId()); + $this->repo->addSnap($this->repo->getDate(), $this->repo->getTime(), 'false', $this->repo->getArch(), array(), array(), array(), $this->repo->getType(), 'active', $this->repo->getRepoId()); /** * Retrieve snapshot Id from the last insert row diff --git a/www/controllers/Task/Repo/Duplicate.php b/www/controllers/Task/Repo/Duplicate.php index 3ef7651a..85ffb9ac 100644 --- a/www/controllers/Task/Repo/Duplicate.php +++ b/www/controllers/Task/Repo/Duplicate.php @@ -248,7 +248,7 @@ public function execute() /** * Add the new repo snapshot in database */ - $this->repo->addSnap($this->repo->getDate(), $this->repo->getTime(), $this->repo->getSigned(), $this->repo->getArch(), array(), $this->repo->getType(), $this->repo->getStatus(), $targetRepoId); + $this->repo->addSnap($this->repo->getDate(), $this->repo->getTime(), $this->repo->getSigned(), $this->repo->getArch(), array(), $this->repo->getPackagesToInclude(), $this->repo->getPackagesToExclude(), $this->repo->getType(), $this->repo->getStatus(), $targetRepoId); /** * Retrieve the Id of the new repo snapshot in database diff --git a/www/controllers/Task/Repo/Env.php b/www/controllers/Task/Repo/Env.php index 8b523709..4351e64d 100644 --- a/www/controllers/Task/Repo/Env.php +++ b/www/controllers/Task/Repo/Env.php @@ -40,6 +40,7 @@ public function __construct(string $taskId) */ $requiredParams = array('env'); $optionalParams = array('description'); + $this->taskParamsCheck('Repo environment', $taskParams, $requiredParams); $this->taskParamsSet($taskParams, $requiredParams, $optionalParams); diff --git a/www/controllers/Task/Repo/Finalize.php b/www/controllers/Task/Repo/Finalize.php index 97cefec1..ba0b5e7d 100644 --- a/www/controllers/Task/Repo/Finalize.php +++ b/www/controllers/Task/Repo/Finalize.php @@ -85,7 +85,7 @@ protected function finalize() * Add snapshot in database * Empty array() for package translation because it's not used for the moment */ - $this->repo->addSnap($this->repo->getDate(), $this->repo->getTime(), $this->repo->getGpgSign(), $this->repo->getArch(), array(), $this->repo->getType(), 'active', $this->repo->getRepoId()); + $this->repo->addSnap($this->repo->getDate(), $this->repo->getTime(), $this->repo->getGpgSign(), $this->repo->getArch(), array(), $this->repo->getPackagesToInclude(), $this->repo->getPackagesToExclude(), $this->repo->getType(), 'active', $this->repo->getRepoId()); /** * Retrieve the last insert row ID @@ -117,6 +117,16 @@ protected function finalize() */ $this->repo->snapSetArch($this->repo->getSnapId(), $this->repo->getArch()); + /** + * Update packages to include (it could be different from the previous one) + */ + $this->repo->snapSetPackagesIncluded($this->repo->getSnapId(), $this->repo->getPackagesToInclude()); + + /** + * Update packages to exclude (it could be different from the previous one) + */ + $this->repo->snapSetPackagesExcluded($this->repo->getSnapId(), $this->repo->getPackagesToExclude()); + /** * Mise à jour de la date */ @@ -134,7 +144,7 @@ protected function finalize() /** * Cas où un nouveau snapshot a été créé, on l'ajoute en base de données */ - $this->repo->addSnap($this->repo->getDate(), $this->repo->getTime(), $this->repo->getGpgSign(), $this->repo->getArch(), array(), 'mirror', 'active', $this->repo->getRepoId()); + $this->repo->addSnap($this->repo->getDate(), $this->repo->getTime(), $this->repo->getGpgSign(), $this->repo->getArch(), array(), $this->repo->getPackagesToInclude(), $this->repo->getPackagesToExclude(), 'mirror', 'active', $this->repo->getRepoId()); /** * On récupère l'Id du snapshot précédemment créé diff --git a/www/controllers/Task/Repo/Package/Sign.php b/www/controllers/Task/Repo/Package/Sign.php index c05bcc3d..f53b4f6c 100644 --- a/www/controllers/Task/Repo/Package/Sign.php +++ b/www/controllers/Task/Repo/Package/Sign.php @@ -148,7 +148,7 @@ private function signPackage() */ if ($myprocess->getExitCode() != 0) { echo 'KO error while signing package:' . PHP_EOL; - echo '
' . $output . '
'; + echo '
' . $output . '
'; $signError++; break; } diff --git a/www/controllers/Task/Repo/Package/Sync.php b/www/controllers/Task/Repo/Package/Sync.php index 26fdf762..3cf80963 100644 --- a/www/controllers/Task/Repo/Package/Sync.php +++ b/www/controllers/Task/Repo/Package/Sync.php @@ -172,6 +172,8 @@ private function syncPackage() $mymirror->setReleasever($this->repo->getReleasever()); $mymirror->setArch($this->repo->getArch()); $mymirror->setCheckSignature($this->repo->getGpgCheck()); + $mymirror->setPackagesToInclude($this->repo->getPackagesToInclude()); + $mymirror->setPackagesToExclude($this->repo->getPackagesToExclude()); $mymirror->setOutputFile($this->taskLog->getStepLog()); $mymirror->outputToFile(true); @@ -244,6 +246,8 @@ private function syncPackage() $mymirror->setSection($this->repo->getSection()); $mymirror->setArch($this->repo->getArch()); $mymirror->setCheckSignature($this->repo->getGpgCheck()); + $mymirror->setPackagesToInclude($this->repo->getPackagesToInclude()); + $mymirror->setPackagesToExclude($this->repo->getPackagesToExclude()); $mymirror->setOutputFile($this->taskLog->getStepLog()); $mymirror->outputToFile(true); diff --git a/www/controllers/Task/Repo/Update.php b/www/controllers/Task/Repo/Update.php index a476acbd..3150b112 100644 --- a/www/controllers/Task/Repo/Update.php +++ b/www/controllers/Task/Repo/Update.php @@ -75,10 +75,10 @@ public function __construct(string $taskId) $this->repo->getAllById(null, $taskParams['snap-id'], null); /** - * Repo override some parameters defined by the user + * Override with parameters defined by the user */ $requiredParams = array('gpg-check', 'gpg-sign', 'arch'); - $optionalParams = array('env'); + $optionalParams = array('env', 'package-include', 'package-exclude'); $this->taskParamsCheck('Update repo', $taskParams, $requiredParams); $this->taskParamsSet($taskParams, $requiredParams, $optionalParams); diff --git a/www/controllers/ajax/host.php b/www/controllers/ajax/host.php index 1989cf07..3dd91957 100644 --- a/www/controllers/ajax/host.php +++ b/www/controllers/ajax/host.php @@ -96,6 +96,21 @@ response(HTTP_OK, $content); } +/** + * Show request package log details + */ +if ($action == "getRequestPackageLog" and !empty($_POST['id']) and !empty($_POST['package']) and !empty($_POST['status'])) { + $myhost = new \Controllers\Host(); + + try { + $content = $myhost->getRequestPackageLog($_POST['id'], $_POST['package'], $_POST['status']); + } catch (\Exception $e) { + response(HTTP_BAD_REQUEST, $e->getMessage()); + } + + response(HTTP_OK, $content); +} + /** * Cancel a request sent to a host */ diff --git a/www/models/Connection.php b/www/models/Connection.php index 79631eb8..acb533cf 100644 --- a/www/models/Connection.php +++ b/www/models/Connection.php @@ -46,7 +46,7 @@ public function __construct(string $database, string|null $hostId = null, bool $ */ } elseif ($database == 'stats') { $this->open(STATS_DB); - $this->busyTimeout(10000); + $this->busyTimeout(15000); $this->enableExceptions(true); $this->enableWAL(); @@ -65,7 +65,7 @@ public function __construct(string $database, string|null $hostId = null, bool $ */ } elseif ($database == 'hosts') { $this->open(HOSTS_DB); - $this->busyTimeout(10000); + $this->busyTimeout(15000); $this->enableExceptions(true); $this->enableWAL(); @@ -84,7 +84,7 @@ public function __construct(string $database, string|null $hostId = null, bool $ */ } elseif ($database == 'host') { $this->open(HOSTS_DIR . '/' . $hostId . '/properties.db'); - $this->busyTimeout(10000); + $this->busyTimeout(15000); $this->enableExceptions(true); $this->enableWAL(); $this->generateHostTables(); @@ -293,6 +293,8 @@ private function generateMainTables() Signed CHAR(5) NOT NULL, /* true, false */ Arch VARCHAR(255), Pkg_translation VARCHAR(255), + Pkg_included VARCHAR(255), + Pkg_excluded VARCHAR(255), Type CHAR(6) NOT NULL, Reconstruct CHAR(8), /* needed, running, failed */ Status CHAR(8) NOT NULL, @@ -390,7 +392,7 @@ private function generateMainTables() $stmt->bindValue(':password_hashed', $password_hashed); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->logError($e); } } @@ -694,6 +696,7 @@ private function generateMainTables() Type CHAR(5) NOT NULL, /* info, error */ Component VARCHAR(255), Message VARCHAR(255) NOT NULL, + Details TEXT, Status CHAR(9) NOT NULL)"); /* new, acquitted */ /** @@ -1026,4 +1029,18 @@ public function columnExist(string $tableName, string $columnName) return false; } + + /** + * Log a database error in database + */ + public function logError(string $exception = null) + { + $logController = new \Controllers\Log\Log(); + + if (!empty($exception)) { + $logController->log('error', 'Database', 'An error occured while executing request in database.', $exception); + } else { + $logController->log('error', 'Database', 'An error occured while executing request in database.'); + } + } } diff --git a/www/models/Cve/Cve.php b/www/models/Cve/Cve.php index 431a107d..7d50d134 100644 --- a/www/models/Cve/Cve.php +++ b/www/models/Cve/Cve.php @@ -26,7 +26,7 @@ public function get(string $id) $stmt->bindValue(':id', $id); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -48,7 +48,7 @@ public function getIdByName(string $name) $stmt->bindValue(':name', $name); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -70,7 +70,7 @@ public function getCpe(string $id) $stmt->bindValue(':id', $id); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -92,7 +92,7 @@ public function getReferences(string $id) $stmt->bindValue(':id', $id); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -113,7 +113,7 @@ public function getAllId() $stmt = $this->db->prepare("SELECT Id FROM cve ORDER BY Id ASC"); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -158,7 +158,7 @@ public function getAll(bool $withOffset, int $offset, string|null $filter) $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { $cves[] = $row; @@ -183,7 +183,7 @@ public function getAllIdBySearch(string $search) $stmt->bindValue(':search', '%' . $search . '%'); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -206,7 +206,7 @@ public function getAffectedHosts(string $cveId, string $status) $stmt->bindValue(':status', $status); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -226,7 +226,7 @@ public function exists(string $id) $stmt->bindValue(':id', $id); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } if ($this->db->isempty($result) === true) { @@ -246,7 +246,7 @@ public function nameExists(string $nameId) $stmt->bindValue(':name', $nameId); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } if ($this->db->isempty($result) === true) { @@ -274,7 +274,7 @@ public function new(string $nameId, string $date, string $time, string $updatedD $stmt->bindValue(':cvss3Score', $cvss3Score); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } /** @@ -302,7 +302,7 @@ public function new(string $nameId, string $date, string $time, string $updatedD $stmt->bindValue(':cveId', $cveId); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } } @@ -319,7 +319,7 @@ public function new(string $nameId, string $date, string $time, string $updatedD $stmt->bindValue(':cveId', $cveId); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } } @@ -343,7 +343,7 @@ public function update(string $nameId, string $date, string $time, string $updat $stmt->bindValue(':cvss3Score', $cvss3Score); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } /** @@ -374,7 +374,7 @@ public function update(string $nameId, string $date, string $time, string $updat $stmt->bindValue(':cveId', $cveId); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } } @@ -394,7 +394,7 @@ public function cpeExist(string $part, string $vendor, string $product, string $ $stmt->bindValue(':cveId', $cveId); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } if ($this->db->isempty($result)) { @@ -418,7 +418,7 @@ public function setAffectedHost(string $cveId, string $hostId, string $productNa $stmt->bindValue(':cveId', $cveId); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -440,7 +440,7 @@ public function searchCpeProductVersion(string $product, string $version) $stmt->bindValue(':version', $version . '%'); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } // $endTime = hrtime(true); diff --git a/www/models/Cve/Tools/Import.php b/www/models/Cve/Tools/Import.php index 1685c184..f406bf63 100644 --- a/www/models/Cve/Tools/Import.php +++ b/www/models/Cve/Tools/Import.php @@ -26,7 +26,7 @@ public function setStartImport() $stmt->bindValue(':status', 'running'); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } return $this->getLastInsertRowID(); @@ -43,7 +43,7 @@ public function setEndImport(string $importId, string $duration) $stmt->bindValue(':duration', $duration); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -58,7 +58,7 @@ public function setImportStatus(string $importId, string $status) $stmt->bindValue(':status', $status); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -74,7 +74,7 @@ public function setStartHostImport() $stmt->bindValue(':status', 'running'); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } return $this->getLastInsertRowID(); @@ -91,7 +91,7 @@ public function setEndHostImport(string $importId, string $duration) $stmt->bindValue(':duration', $duration); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -106,7 +106,7 @@ public function setHostImportStatus(string $importId, string $status) $stmt->bindValue(':status', $status); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -123,7 +123,7 @@ public function clearDatabase() $this->db->query("VACUUM"); $this->db->checkMainTables(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } } diff --git a/www/models/Environment.php b/www/models/Environment.php index 3f2c828e..9baba46a 100644 --- a/www/models/Environment.php +++ b/www/models/Environment.php @@ -24,7 +24,7 @@ public function new(string $name) $stmt->bindValue(':name', $name); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -38,7 +38,7 @@ public function delete(string $name) $stmt->bindValue(':name', $name); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -108,7 +108,7 @@ public function exists(string $name) $stmt->bindValue(':env', $name); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } if ($this->db->isempty($result)) { diff --git a/www/models/Group.php b/www/models/Group.php index 6c4e3842..95f62e2a 100644 --- a/www/models/Group.php +++ b/www/models/Group.php @@ -26,7 +26,7 @@ public function add(string $name) $stmt->bindValue(':name', $name); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -45,7 +45,7 @@ public function delete(string $id) $stmt->bindValue(':id', $id); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } /** @@ -56,7 +56,7 @@ public function delete(string $id) $stmt->bindValue(':id', $id); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -78,7 +78,7 @@ public function getIdByName(string $name) $stmt->bindValue(':name', $name); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -98,7 +98,7 @@ public function getNameById(string $id) $stmt->bindValue(':id', $id); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -137,7 +137,7 @@ public function existsId(string $groupId) $stmt->bindValue(':id', $groupId); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } if ($this->db->isempty($result) === true) { @@ -157,7 +157,7 @@ public function exists(string $name) $stmt->bindValue(':name', $name); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } if ($this->db->isempty($result) === true) { @@ -178,7 +178,7 @@ public function updateName(int $id, string $name) $stmt->bindValue(':id', $id); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -208,7 +208,7 @@ public function getReposMembers(int $id) $stmt->bindValue(':id', $id); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -267,7 +267,7 @@ public function getHostsMembers(int $id) $stmt->bindValue(':id', $id); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -293,7 +293,7 @@ public function getHostsNotMembers() WHERE hosts.Id NOT IN (SELECT Id_host FROM group_members) AND hosts.Status = 'active'"); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { diff --git a/www/models/History.php b/www/models/History.php index a17c00ac..a5855e60 100644 --- a/www/models/History.php +++ b/www/models/History.php @@ -24,7 +24,7 @@ public function getAll() try { $result = $this->db->query("SELECT history.Id, history.Date, history.Time, history.Action, history.State, users.First_name, users.Last_name, users.Username FROM history JOIN users ON history.Id_user = users.Id ORDER BY Date DESC, Time DESC"); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); return; } @@ -47,7 +47,7 @@ public function getByUser(int $userId) $stmt->bindValue(':userid', $userId); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); return; } @@ -74,7 +74,7 @@ public function set(string $userId, string $action, string $state) $stmt->bindValue(':state', $state); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } } diff --git a/www/models/Host.php b/www/models/Host.php index e9ae389b..0a292c22 100644 --- a/www/models/Host.php +++ b/www/models/Host.php @@ -82,7 +82,7 @@ public function listByGroup(string $groupName) unset($stmt); } } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } $hostsIn = array(); @@ -110,7 +110,7 @@ public function setPackageHistory(string $packageName, string $packageVersion, s $stmt->bindValue(':id_event', $eventId); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->host_db->logError($e); } } @@ -129,7 +129,7 @@ public function setPackageState(string $name, string $version, string $state, st $stmt->bindValue(':id_event', $id_event); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->host_db->logError($e); } } @@ -153,7 +153,7 @@ public function addPackage(string $name, string $version, string $state, string $stmt->bindValue(':time', $time); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->host_db->logError($e); } } @@ -173,7 +173,7 @@ public function updateHostname(string $id, string $hostname) $stmt->bindValue(':id', $id); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -188,7 +188,7 @@ public function updateOS(string $id, string $os) $stmt->bindValue(':id', $id); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -203,7 +203,7 @@ public function updateOsVersion(string $id, string $osVersion) $stmt->bindValue(':id', $id); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -218,7 +218,7 @@ public function updateOsFamily(string $id, string $osFamily) $stmt->bindValue(':id', $id); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -233,7 +233,7 @@ public function updateType(string $id, string $type) $stmt->bindValue(':id', $id); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -248,7 +248,7 @@ public function updateKernel(string $id, string $kernel) $stmt->bindValue(':id', $id); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -263,7 +263,7 @@ public function updateArch(string $id, string $arch) $stmt->bindValue(':id', $id); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -278,7 +278,7 @@ public function updateProfile(string $id, string $profile) $stmt->bindValue(':id', $id); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -293,7 +293,7 @@ public function updateEnv(string $id, string $env) $stmt->bindValue(':id', $id); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -310,7 +310,7 @@ public function updateAgentStatus(string $id, string $status) $stmt->bindValue(':id', $id); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -325,7 +325,7 @@ public function updateLinupdateVersion(string $id, string $version) $stmt->bindValue(':id', $id); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -340,7 +340,7 @@ public function updateRebootRequired(string $id, string $status) $stmt->bindValue(':id', $id); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -355,7 +355,7 @@ public function deletePackageAvailable(string $packageName, string $packageVersi $stmt->bindValue(':version', $packageVersion); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->host_db->logError($e); } } @@ -384,7 +384,7 @@ public function getIdByAuth(string $authId) $stmt->bindValue(':authId', $authId); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -404,7 +404,7 @@ public function getAllById(string $id) $stmt->bindValue(':id', $id); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } $data = array(); @@ -431,7 +431,7 @@ public function getHostWithKernel(string $kernel) $stmt->bindValue(':kernel', $kernel); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -456,7 +456,7 @@ public function getHostWithProfile(string $profile) $stmt->bindValue(':profile', $profile); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -476,7 +476,7 @@ public function getPackageInfo(string $packageId) $stmt->bindValue(':packageId', $packageId); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->host_db->logError($e); } $data = array(); @@ -503,7 +503,7 @@ public function getPackageId(string $packageName, string $packageVersion = null) $stmt->bindValue(':version', $packageVersion); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->host_db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -521,7 +521,7 @@ public function getPackageId(string $packageName, string $packageVersion = null) $stmt->bindValue(':name', $packageName); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->host_db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -557,7 +557,7 @@ public function getPackageState(string $packageName, string $packageVersion = nu $stmt->bindValue(':name', $packageName); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->host_db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -578,7 +578,7 @@ public function checkIdToken(string $authId, string $token) $stmt->bindValue(':token', $token); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } if ($this->db->isempty($result)) { @@ -768,7 +768,7 @@ public function ipExists(string $ip) $stmt->bindValue(':ip', \Controllers\Common::validateData($ip)); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } if ($this->db->isempty($result) === true) { @@ -788,7 +788,7 @@ public function hostnameExists(string $hostname) $stmt->bindValue(':hostname', \Controllers\Common::validateData($hostname)); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } if ($this->db->isempty($result) === true) { @@ -808,7 +808,7 @@ public function packageExists(string $packageName) $stmt->bindValue(':name', \Controllers\Common::validateData($packageName)); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->host_db->logError($e); } if ($this->host_db->isempty($result) === true) { @@ -829,7 +829,7 @@ public function packageVersionExists(string $packageName, string $packageVersion $stmt->bindValue(':version', $packageVersion); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->host_db->logError($e); } if ($this->host_db->isempty($result) === true) { @@ -851,7 +851,7 @@ public function getHostsWithPackage(string $packageName) $stmt->bindValue(':name', "${packageName}%"); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->host_db->logError($e); } /** @@ -861,11 +861,6 @@ public function getHostsWithPackage(string $packageName) return $packages; } - /** - * Sinon on récupère les données - */ - // $packages = array(); - while ($row = $result->fetchArray(SQLITE3_ASSOC)) { $packageName = $row['Name']; $packageVersion = $row['Version']; @@ -875,7 +870,6 @@ public function getHostsWithPackage(string $packageName) /** * Le résultat sera traité par js donc on transmets un array au format JSON */ - // return json_encode($packages); return $packages; } @@ -889,7 +883,7 @@ public function packageAvailableExists(string $packageName) $stmt->bindValue(':name', $packageName); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->host_db->logError($e); } if ($this->host_db->isempty($result) === true) { @@ -910,7 +904,7 @@ public function packageVersionAvailableExists(string $packageName, string $packa $stmt->bindValue(':version', $packageVersion); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->host_db->logError($e); } if ($this->host_db->isempty($result) === true) { @@ -931,7 +925,7 @@ public function addPackageAvailable(string $name, string $version) $stmt->bindValue(':version', $version); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->host_db->logError($e); } } @@ -946,7 +940,7 @@ public function updatePackageAvailable(string $name, string $version) $stmt->bindValue(':version', $version); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->host_db->logError($e); } } @@ -961,7 +955,7 @@ public function eventExists(string $dateStart, string $timeStart) $stmt->bindValue(':time_start', $timeStart); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->host_db->logError($e); } if ($this->host_db->isempty($result) === true) { @@ -984,7 +978,7 @@ public function addEvent(string $dateStart, string $dateEnd, string $timeStart, $stmt->bindValue(':time_end', $timeEnd); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->host_db->logError($e); } } @@ -998,7 +992,7 @@ public function getSettings() try { $result = $this->db->query("SELECT * FROM settings"); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -1019,7 +1013,7 @@ public function setSettings(string $packagesConsideredOutdated, string $packages $stmt->bindValue(':packagesConsideredCritical', $packagesConsideredCritical); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -1043,7 +1037,7 @@ public function getPackagesInventory() try { $result = $this->host_db->query("SELECT * FROM packages ORDER BY Name ASC"); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->host_db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -1073,7 +1067,7 @@ public function getPackagesInstalled() try { $result = $this->host_db->query("SELECT * FROM packages WHERE State = 'inventored' or State = 'installed' or State = 'dep-installed' or State = 'upgraded' or State = 'downgraded'"); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->host_db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -1109,7 +1103,7 @@ public function getPackagesAvailable(bool $withOffset, int $offset) $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->host_db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -1146,7 +1140,7 @@ public function getRequests(int $id, bool $withOffset, int $offset) $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -1168,7 +1162,7 @@ public function getLastPendingRequest(int $id) $stmt->bindValue(':id', $id, SQLITE3_INTEGER); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -1204,7 +1198,7 @@ public function getEventsHistory(bool $withOffset, int $offset) $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->host_db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -1241,7 +1235,7 @@ public function getEventPackagesList(string $eventId, string $packageState) $stmt->bindValue(':packageState', \Controllers\Common::validateData($packageState)); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->host_db->logError($e); } $datas = array(); @@ -1269,7 +1263,7 @@ public function getEventDetails(string $eventId, string $packageState) $stmt->bindValue(':state', \Controllers\Common::validateData($packageState)); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->host_db->logError($e); } $packages = array(); @@ -1302,7 +1296,7 @@ public function getPackageTimeline(string $packageName) $stmt->bindValue(':packagename', $packageName); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->host_db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -1335,7 +1329,7 @@ public function getLastPackagesStatusCount(string $status, string $dateStart, st $stmt->bindValue(':dateEnd', $dateEnd); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->host_db->logError($e); } $array = array(); @@ -1363,7 +1357,7 @@ public function getHostnameById(int $id) $stmt->bindValue(':id', $id); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -1383,7 +1377,7 @@ public function getIpById(string $id) $stmt->bindValue(':id', $id); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -1403,7 +1397,7 @@ public function getHostStatus(string $hostname) $stmt->bindValue(':hostname', $hostname); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } $status = ''; @@ -1431,7 +1425,7 @@ public function addHost(string $ip, string $hostname, string $authId, string $to $stmt->bindValue(':time', $time); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -1451,7 +1445,7 @@ public function updateHost(string $ip, string $hostname, string $authId, string $stmt->bindValue(':time', $time); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -1466,7 +1460,7 @@ public function setHostInactive(string $hostId) $stmt->bindValue(':hostId', $hostId); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -1521,7 +1515,7 @@ public function resetHost(string $hostId) */ $this->host_db->generateHostTables(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->host_db->logError($e); } } @@ -1543,7 +1537,7 @@ public function existsId(string $id) $stmt->bindValue(':id', $id); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } if ($this->db->isempty($result) === true) { @@ -1568,7 +1562,7 @@ public function addToGroup(string $hostId, string $groupId) $stmt->bindValue(':groupId', $groupId); $result = $stmt->execute(); } catch (Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } /** @@ -1584,7 +1578,7 @@ public function addToGroup(string $hostId, string $groupId) $stmt->bindValue(':id_group', $groupId); $stmt->execute(); } catch (Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -1606,7 +1600,7 @@ public function removeFromGroup(string $hostId, string $groupId = null) $stmt->bindValue(':hostId', $hostId); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -1622,7 +1616,7 @@ public function countByProfile(string $profile) $stmt->bindValue(':profile', $profile); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -1641,7 +1635,7 @@ public function cleanWsConnections() $stmt = $this->db->prepare("DELETE FROM ws_connections"); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -1665,7 +1659,7 @@ public function getWsConnections(string|null $status) } $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -1685,7 +1679,7 @@ public function newWsConnection(int $connectionId) $stmt->bindValue(':id', $connectionId); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -1699,7 +1693,7 @@ public function deleteWsConnection(int $connectionId) $stmt->bindValue(':id', $connectionId); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -1715,7 +1709,7 @@ public function updateWsConnection(int $connectionId, int $hostId, string $authe $stmt->bindValue(':connectionId', $connectionId); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -1732,7 +1726,7 @@ public function newWsRequest(int $hostId, string $request) $stmt->bindValue(':hostId', $hostId); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -1755,7 +1749,7 @@ public function getWsRequests(string|null $status) } $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -1778,7 +1772,7 @@ public function updateWsRequest(int $id, string $status, string $info, string $i $stmt->bindValue(':id', $id); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -1793,7 +1787,7 @@ public function updateWsRequestStatus(int $id, string $status) $stmt->bindValue(':id', $id); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -1808,7 +1802,7 @@ public function updateWsRequestInfo(int $id, string $info) $stmt->bindValue(':id', $id); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -1823,7 +1817,7 @@ public function updateWsRequestRetry(int $id, int $retry) $stmt->bindValue(':id', $id); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -1838,7 +1832,7 @@ public function updateWsRequestNextRetry(int $id, string $nextRetry) $stmt->bindValue(':id', $id); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -1854,7 +1848,7 @@ public function getWsConnectionIdByHostId(int $hostId) $stmt->bindValue(':hostId', $hostId); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } $connectionId = ''; @@ -1876,7 +1870,7 @@ public function cancelWsRequest(int $id) $stmt->bindValue(':id', $id); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -1890,7 +1884,51 @@ public function deleteWsRequest(int $id) $stmt->bindValue(':id', $id); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); + } + } + + /** + * Get request package log details + */ + public function getRequestPackageLog(int $id, string $package, string $status) : string|null + { + $data = ''; + + // Example of Info_json content: + // "update":{ + // "status":"done", + // "success":{ + // "count":7, + // "packages":{ + // "brave-browser":{ + // "version":"xxxx", + // "log":"xxxx" + // }, + // "firefox":{ + // "version":"xxxx", + // "log":"xxxx" + // }, + // } + // } + // } + + try { + /** + * Extract the log of the specified package in the specified status + */ + $stmt = $this->db->prepare("SELECT json_extract(Info_json, :path) as log FROM ws_requests WHERE Id = :id"); + $stmt->bindValue(':path', '$.update.' . $status . '.packages.' . $package . '.log'); + $stmt->bindValue(':id', $id); + $result = $stmt->execute(); + } catch (\Exception $e) { + $this->db->logError($e); } + + while ($row = $result->fetchArray(SQLITE3_ASSOC)) { + $data = $row['log']; + } + + return $data; } } diff --git a/www/models/Layout/ContainerState.php b/www/models/Layout/ContainerState.php index 568552bd..dc0d65f8 100644 --- a/www/models/Layout/ContainerState.php +++ b/www/models/Layout/ContainerState.php @@ -21,7 +21,7 @@ public function get() try { $result = $this->db->query("SELECT * FROM layout_container_state"); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -42,7 +42,7 @@ public function add(string $name, string $id) $stmt->bindValue(':id', $id); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -57,7 +57,7 @@ public function update(string $name, $id) $stmt->bindValue(':name', $name); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -71,7 +71,7 @@ public function exists(string $name) $stmt->bindValue(':name', $name); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } if ($this->db->isempty($result)) { diff --git a/www/models/Log/Log.php b/www/models/Log/Log.php index 42d89c02..ba2a3b0e 100644 --- a/www/models/Log/Log.php +++ b/www/models/Log/Log.php @@ -42,7 +42,7 @@ public function getUnread(string $type = null, int $limit = 0) } $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -55,19 +55,19 @@ public function getUnread(string $type = null, int $limit = 0) /** * Log a message */ - public function log(string $type, string $component, string $message) + public function log(string $type, string $component, string $message, string $details) { - try { - $stmt = $this->db->prepare("INSERT INTO logs (Date, Time, Type, Component, Message, Status) VALUES (:date, :time, :type, :component, :message, 'new')"); - $stmt->bindValue(':date', date('Y-m-d')); - $stmt->bindValue(':time', date('H:i:s')); - $stmt->bindValue(':type', $type); - $stmt->bindValue(':component', $component); - $stmt->bindValue(':message', $message); - $stmt->execute(); - } catch (\Exception $e) { - \Controllers\Common::dbError($e); - } + /** + * No try/cacth here, if an error occurs, it will be caught in the controller + */ + $stmt = $this->db->prepare("INSERT INTO logs (Date, Time, Type, Component, Message, Details, Status) VALUES (:date, :time, :type, :component, :message, :details, 'new')"); + $stmt->bindValue(':date', date('Y-m-d')); + $stmt->bindValue(':time', date('H:i:s')); + $stmt->bindValue(':type', $type); + $stmt->bindValue(':component', $component); + $stmt->bindValue(':message', $message); + $stmt->bindValue(':details', $details); + $stmt->execute(); } /** @@ -80,7 +80,7 @@ public function acquit(int $id) $stmt->bindValue(':id', $id); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } } diff --git a/www/models/Login.php b/www/models/Login.php index 83e1e947..329eeab0 100644 --- a/www/models/Login.php +++ b/www/models/Login.php @@ -21,7 +21,7 @@ public function getEmails() try { $result = $this->db->query("SELECT Email FROM users WHERE State = 'active'"); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -43,7 +43,7 @@ public function getHashedPasswordFromDb(string $username) $stmt->bindValue(':username', $username); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -65,7 +65,7 @@ public function getIdByUsername(string $username) $stmt->bindValue(':username', $username); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -87,7 +87,7 @@ public function getUsernameById(string $id) $stmt->bindValue(':id', $id); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -109,7 +109,7 @@ public function getAll(string $username) $stmt->bindValue(':username', $username); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -129,7 +129,7 @@ public function getUsers() try { $result = $this->db->query("SELECT users.Id, users.Username, users.Api_key, users.First_name, users.Last_name, users.Email, users.Type, user_role.Name as Role_name FROM users JOIN user_role ON users.Role = user_role.Id WHERE State = 'active' ORDER BY Username ASC"); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -152,7 +152,7 @@ public function addUser(string $username, string $hashedPassword, string $role) $stmt->bindValue(':role', $role); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -169,7 +169,7 @@ public function edit(string $username, string $firstName = null, string $lastNam $stmt->bindValue(':email', $email); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -183,7 +183,7 @@ public function deleteUser(string $id) $stmt->bindValue(':id', $id); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -199,7 +199,7 @@ public function userExists(string $username) $stmt->bindValue(':username', $username); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } if ($this->db->isempty($result) === true) { @@ -220,7 +220,7 @@ public function updatePassword(string $username, string $hashedPassword) $stmt->bindValue(':password', $hashedPassword); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -235,7 +235,7 @@ public function updateApiKey(string $username, string $apiKey) $stmt->bindValue(':apikey', $apiKey); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } } diff --git a/www/models/Notification.php b/www/models/Notification.php index b98e4455..32f86ae5 100644 --- a/www/models/Notification.php +++ b/www/models/Notification.php @@ -24,7 +24,7 @@ public function get() try { $result = $this->db->query("SELECT * FROM notifications"); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -44,7 +44,7 @@ public function getUnread() try { $result = $this->db->query("SELECT Id, Title, Message FROM notifications WHERE Status = 'new'"); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -66,7 +66,7 @@ public function add(string $id, string $title, string $message) $stmt->bindValue(':message', $message); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -80,7 +80,7 @@ public function acquit(string $id) $stmt->bindValue(':id', $id); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -94,7 +94,7 @@ public function exists(string $id) $stmt->bindValue(':id', $id); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } if ($this->db->isempty($result)) { diff --git a/www/models/Profile.php b/www/models/Profile.php index bec63033..edca44ef 100644 --- a/www/models/Profile.php +++ b/www/models/Profile.php @@ -23,7 +23,7 @@ public function getIdByName(string $name) $stmt->bindValue(':name', $name); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -45,7 +45,7 @@ public function getNameById(int $id) $stmt->bindValue(':id', $id); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -65,7 +65,7 @@ public function getPackages() try { $result = $this->db->query("SELECT Name FROM profile_package ORDER BY Name ASC"); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($datas = $result->fetchArray(SQLITE3_ASSOC)) { @@ -85,7 +85,7 @@ public function getServices() try { $result = $this->db->query("SELECT Name FROM profile_service ORDER BY Name ASC"); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -112,7 +112,7 @@ public function getProfileFullConfiguration(string $profileId) $stmt->bindValue(':profileId', $profileId); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -130,7 +130,7 @@ public function getServerConfiguration() try { $result = $this->db->query("SELECT * FROM profile_settings"); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } /** @@ -157,7 +157,7 @@ public function exists(string $name) $stmt->bindValue(':name', $name); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } /** @@ -180,7 +180,7 @@ public function existsId(int $id) $stmt->bindValue(':id', $id); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } /** @@ -203,7 +203,7 @@ public function add(string $name) $stmt->bindValue(':name', $name); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -222,7 +222,7 @@ public function configure(int $id, string $name, string $packageExclude = null, $stmt->bindValue(':notes', $notes); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -236,7 +236,7 @@ public function delete(int $id) $stmt->bindValue(':id', $id); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -248,7 +248,7 @@ public function listName() try { $result = $this->db->query("SELECT Name FROM profile ORDER BY Name ASC"); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } $profiles = array(); @@ -268,7 +268,7 @@ public function list() try { $result = $this->db->query("SELECT * FROM profile ORDER BY Name ASC"); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } $profiles = array(); @@ -303,7 +303,7 @@ public function getReposMembersList($profileId) $stmt->bindValue(':profileId', $profileId); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } $repos = array(); @@ -334,7 +334,7 @@ public function reposMembersIdList($profileId) $stmt->bindValue(':profileId', $profileId); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } $repos = array(); @@ -362,7 +362,7 @@ public function addPackage(string $packageName) $stmt->bindValue(':name', $packageName); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } /** @@ -380,7 +380,7 @@ public function addPackage(string $packageName) $stmt->bindValue(':name', $packageName); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } return true; @@ -399,7 +399,7 @@ public function addService(string $serviceName) $stmt->bindValue(':name', $serviceName); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } /** @@ -417,7 +417,7 @@ public function addService(string $serviceName) $stmt->bindValue(':name', $serviceName); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } return true; @@ -433,7 +433,7 @@ public function cleanProfileRepoMembers(string $profileId) $stmt->bindValue(':profileId', $profileId); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -448,7 +448,7 @@ public function addRepoToProfile(string $profileId, string $repoId) $stmt->bindValue(':repoId', $repoId); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -466,7 +466,7 @@ public function countHosts(string $profile) $stmt->bindValue(':profile', $profile); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -488,7 +488,7 @@ public function removeRepoMemberId(int $id) $stmt->bindValue(':id', $id); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } } diff --git a/www/models/Repo/Listing.php b/www/models/Repo/Listing.php index 16ad17c0..2d99af79 100644 --- a/www/models/Repo/Listing.php +++ b/www/models/Repo/Listing.php @@ -43,7 +43,7 @@ public function list() WHERE repos_snap.Status = 'active' ORDER BY repos.Name ASC, repos.Dist ASC, repos.Section ASC, repos_env.Env ASC"); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } $repos = array(); @@ -85,7 +85,7 @@ public function listByGroup(string $groupName) repos_snap.Reconstruct, repos_snap.Status, repos_env.Description - FROM repos + FROM repos LEFT JOIN repos_snap ON repos.Id = repos_snap.Id_repo LEFT JOIN repos_env @@ -113,7 +113,7 @@ public function listByGroup(string $groupName) repos_snap.Reconstruct, repos_snap.Status, repos_env.Description - FROM repos + FROM repos LEFT JOIN repos_snap ON repos.Id = repos_snap.Id_repo LEFT JOIN repos_env @@ -130,7 +130,7 @@ public function listByGroup(string $groupName) $reposInGroup = $stmt->execute(); } } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } $reposIn = array(); @@ -172,7 +172,7 @@ public function listNameOnly(bool $bool) ORDER BY repos.Name ASC, repos.Dist ASC, repos.Section ASC"); } } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } $repos = array(); diff --git a/www/models/Repo/Repo.php b/www/models/Repo/Repo.php index da4b9e4e..6aaf5aab 100644 --- a/www/models/Repo/Repo.php +++ b/www/models/Repo/Repo.php @@ -16,7 +16,7 @@ public function __construct() } /** - * Remplace la fonction commentée ci-dessus + * Retrieve all informations from a repo, snapshot and env in database */ public function getAllById(string|null $repoId, string|null $snapId, string|null $envId) { @@ -38,6 +38,8 @@ public function getAllById(string|null $repoId, string|null $snapId, string|null repos_snap.Signed, repos_snap.Arch, repos_snap.Pkg_translation, + repos_snap.Pkg_included, + repos_snap.Pkg_excluded, repos_snap.Type, repos_snap.Reconstruct, repos_snap.Status, @@ -72,6 +74,8 @@ public function getAllById(string|null $repoId, string|null $snapId, string|null repos_snap.Signed, repos_snap.Arch, repos_snap.Pkg_translation, + repos_snap.Pkg_included, + repos_snap.Pkg_excluded, repos_snap.Type, repos_snap.Reconstruct, repos_snap.Status, @@ -103,6 +107,8 @@ public function getAllById(string|null $repoId, string|null $snapId, string|null repos_snap.Signed, repos_snap.Arch, repos_snap.Pkg_translation, + repos_snap.Pkg_included, + repos_snap.Pkg_excluded, repos_snap.Type, repos_snap.Reconstruct, repos_snap.Status, @@ -127,6 +133,8 @@ public function getAllById(string|null $repoId, string|null $snapId, string|null repos_snap.Signed, repos_snap.Arch, repos_snap.Pkg_translation, + repos_snap.Pkg_included, + repos_snap.Pkg_excluded, repos_snap.Type, repos_snap.Reconstruct, repos_snap.Status, @@ -145,7 +153,7 @@ public function getAllById(string|null $repoId, string|null $snapId, string|null } $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } /** @@ -191,7 +199,7 @@ public function getIdByName(string $name, string $dist = null, string $section = $stmt->bindValue(':name', $name); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -213,7 +221,7 @@ public function getLatestSnapId(int $repoId) $stmt->bindValue(':repoId', $repoId); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -266,7 +274,7 @@ public function getEnvIdFromRepoName(string $name, string|null $dist, string|nul $stmt->bindValue(':env', $env); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -283,7 +291,7 @@ public function getEnvIdBySnapId(string $snapId) $stmt->bindValue(':snapId', $snapId); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } $envId = array(); @@ -303,7 +311,7 @@ public function getAllRepoId() try { $result = $this->db->query("SELECT Id FROM repos"); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } $id = array(); @@ -333,7 +341,7 @@ public function getSnapByRepoId(string $repoId, string $status = null) $stmt->bindValue(':repoId', $repoId); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } $snapshots = array(); @@ -364,7 +372,7 @@ public function getLastSnapshotId(string $repoId) $stmt->bindValue(':repoId', $repoId); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } $id = ''; @@ -411,7 +419,7 @@ public function getDescriptionByName(string $name, string $dist = null, string $ $stmt->bindValue(':env', $env); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } /** @@ -438,7 +446,7 @@ public function getSnapDateById(string $snapId) $stmt->bindValue(':snapId', $snapId); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -470,7 +478,7 @@ public function getUnusedRepos() WHERE repos_snap.Status = 'active')"); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } $data = array(); @@ -505,7 +513,7 @@ public function getUnunsedSnapshot(string $repoId, string $retention) $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } $data = array(); @@ -535,11 +543,11 @@ public function envSetDescription(string $envId, string $description) $stmt->bindValue(':envId', $envId); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } unset($stmt); - \Controllers\App\Cache::clear(); + // \Controllers\App\Cache::clear(); } /** @@ -553,10 +561,10 @@ public function snapSetSigned(string $snapId, string $signed) $stmt->bindValue(':snapId', $snapId); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } - \Controllers\App\Cache::clear(); + // \Controllers\App\Cache::clear(); } /** @@ -570,10 +578,10 @@ public function snapSetDate(string $snapId, string $date) $stmt->bindValue(':snapId', $snapId); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } - \Controllers\App\Cache::clear(); + // \Controllers\App\Cache::clear(); } /** @@ -587,10 +595,10 @@ public function snapSetTime(string $snapId, string $time) $stmt->bindValue(':snapId', $snapId); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } - \Controllers\App\Cache::clear(); + // \Controllers\App\Cache::clear(); } /** @@ -604,10 +612,10 @@ public function snapSetRebuild(string $snapId, string $status = null) $stmt->bindValue(':snapId', $snapId); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } - \Controllers\App\Cache::clear(); + // \Controllers\App\Cache::clear(); } /** @@ -621,10 +629,40 @@ public function snapSetArch(string $snapId, string $arch) $stmt->bindValue(':snapId', $snapId); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } - \Controllers\App\Cache::clear(); + // \Controllers\App\Cache::clear(); + } + + /** + * Set packages included + */ + public function snapSetPackagesIncluded(int $snapId, string $packages) + { + try { + $stmt = $this->db->prepare("UPDATE repos_snap SET Pkg_included = :pkgIncluded WHERE Id = :snapId"); + $stmt->bindValue(':pkgIncluded', $packages); + $stmt->bindValue(':snapId', $snapId); + $stmt->execute(); + } catch (\Exception $e) { + $this->db->logError($e); + } + } + + /** + * Set packages excluded + */ + public function snapSetPackagesExcluded(int $snapId, string $packages) + { + try { + $stmt = $this->db->prepare("UPDATE repos_snap SET Pkg_excluded = :pkgExcluded WHERE Id = :snapId"); + $stmt->bindValue(':pkgExcluded', $packages); + $stmt->bindValue(':snapId', $snapId); + $stmt->execute(); + } catch (\Exception $e) { + $this->db->logError($e); + } } /** @@ -643,7 +681,7 @@ public function snapOpIsRunning(string $snapId) $stmt->bindValue(':snapId', $snapId); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } if ($this->db->isempty($result) === true) { @@ -664,10 +702,10 @@ public function snapSetStatus(string $snapId, string $status) $stmt->bindValue(':snapId', $snapId); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } - \Controllers\App\Cache::clear(); + // \Controllers\App\Cache::clear(); } /** @@ -680,7 +718,7 @@ public function existsId(string $id) $stmt->bindValue(':id', $id); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } if ($this->db->isempty($result) === true) { @@ -700,7 +738,7 @@ public function existsSnapId(string $id) $stmt->bindValue(':id', $id); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } if ($this->db->isempty($result) === true) { @@ -720,7 +758,7 @@ public function existsEnvId(string $id) $stmt->bindValue(':id', $id); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } if ($this->db->isempty($result) === true) { @@ -751,7 +789,7 @@ public function exists(string $name, string $dist = '', string $section = '') $stmt->bindValue(':name', $name); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } if ($this->db->isempty($result) === true) { @@ -800,7 +838,7 @@ public function existsEnv(string $name, string $dist = null, string $section = n $stmt->bindValue(':env', $env); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } if ($this->db->isempty($result) === true) { @@ -843,7 +881,7 @@ public function existsRepoSnapDate(string $date, string $name, string|null $dist $stmt->bindValue(':date', $date); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } if ($this->db->isempty($result) === true) { @@ -869,7 +907,7 @@ public function existsSnapIdEnv(string $snapId, string $env) $stmt->bindValue(':env', $env); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } if ($this->db->isempty($result) === true) { @@ -909,7 +947,7 @@ public function isActive(string $name, string $dist = null, string $section = nu $stmt->bindValue(':name', $name); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } /** @@ -938,7 +976,7 @@ public function count() ON repos.Id = repos_snap.Id_repo WHERE repos_snap.Status = 'active'"); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } return $this->db->count($result); @@ -969,33 +1007,35 @@ public function add(string $source, string $packageType, string $name, string $d $stmt->bindValue(':packageType', $packageType); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } - \Controllers\App\Cache::clear(); + // \Controllers\App\Cache::clear(); } /** * Add a repo snapshot in database */ - public function addSnap(string $date, string $time, string $gpgSignature, array $arch, array $includeTranslation, string $type, string $status, string $repoId) + public function addSnap(string $date, string $time, string $gpgSignature, array $arch, array $includeTranslation, array $packagesIncluded, array $packagesExcluded, string $type, string $status, string $repoId) { try { - $stmt = $this->db->prepare("INSERT INTO repos_snap ('Date', 'Time', 'Signed', 'Arch', 'Pkg_translation', 'Type', 'Status', 'Id_repo') VALUES (:date, :time, :signed, :arch, :includeTranslation, :type, :status, :repoId)"); + $stmt = $this->db->prepare("INSERT INTO repos_snap ('Date', 'Time', 'Signed', 'Arch', 'Pkg_translation', 'Pkg_included', 'Pkg_excluded', 'Type', 'Status', 'Id_repo') VALUES (:date, :time, :signed, :arch, :includeTranslation, :packagesIncluded, :packagesExcluded, :type, :status, :repoId)"); $stmt->bindValue(':date', $date); $stmt->bindValue(':time', $time); $stmt->bindValue(':signed', $gpgSignature); $stmt->bindValue(':arch', implode(',', $arch)); $stmt->bindValue(':includeTranslation', implode(',', $includeTranslation)); + $stmt->bindValue(':packagesIncluded', implode(',', $packagesIncluded)); + $stmt->bindValue(':packagesExcluded', implode(',', $packagesExcluded)); $stmt->bindValue(':type', $type); $stmt->bindValue(':status', $status); $stmt->bindValue(':repoId', $repoId); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } - \Controllers\App\Cache::clear(); + // \Controllers\App\Cache::clear(); } /** @@ -1010,10 +1050,10 @@ public function addEnv(string $env, string $description = null, string $snapId) $stmt->bindValue(':snapId', $snapId); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } - \Controllers\App\Cache::clear(); + // \Controllers\App\Cache::clear(); } /** @@ -1031,7 +1071,7 @@ public function addToGroup(string $repoId, string $groupId) $stmt->bindValue(':groupId', $groupId); $result = $stmt->execute(); } catch (Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } /** @@ -1047,10 +1087,10 @@ public function addToGroup(string $repoId, string $groupId) $stmt->bindValue(':id_group', $groupId); $stmt->execute(); } catch (Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } - \Controllers\App\Cache::clear(); + // \Controllers\App\Cache::clear(); } /** @@ -1071,10 +1111,10 @@ public function removeFromGroup(string $repoId, string $groupId = null) $stmt->bindValue(':repoId', $repoId); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } - \Controllers\App\Cache::clear(); + // \Controllers\App\Cache::clear(); } /** @@ -1087,7 +1127,7 @@ public function removeEnv(string $envId) $stmt->bindValue(':envId', $envId); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } unset($stmt); @@ -1106,12 +1146,12 @@ public function updateReleasever(int $repoId, string $releasever) $stmt->bindValue(':repoId', $repoId); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } unset($stmt); - \Controllers\App\Cache::clear(); + // \Controllers\App\Cache::clear(); } /** @@ -1125,12 +1165,12 @@ public function updateDist(int $repoId, string $dist) $stmt->bindValue(':repoId', $repoId); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } unset($stmt); - \Controllers\App\Cache::clear(); + // \Controllers\App\Cache::clear(); } /** @@ -1144,11 +1184,11 @@ public function updateSection(int $repoId, string $section) $stmt->bindValue(':repoId', $repoId); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } unset($stmt); - \Controllers\App\Cache::clear(); + // \Controllers\App\Cache::clear(); } } diff --git a/www/models/Settings.php b/www/models/Settings.php index b9a35446..03d10f7c 100644 --- a/www/models/Settings.php +++ b/www/models/Settings.php @@ -21,7 +21,7 @@ public function get() try { $result = $this->db->query("SELECT * FROM settings"); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -53,7 +53,7 @@ public function apply(array $settingsToApply) } $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } } diff --git a/www/models/Source.php b/www/models/Source.php index 28ec556b..648b6c2a 100644 --- a/www/models/Source.php +++ b/www/models/Source.php @@ -27,7 +27,7 @@ public function getAll(string $sourceType, string $sourceName) $stmt->bindValue(':name', $sourceName); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -50,7 +50,7 @@ public function getIdByName(string $type, string $name) $stmt->bindValue(':name', $name); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -72,7 +72,7 @@ public function getType(string $id) $stmt->bindValue(':id', $id); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -102,7 +102,7 @@ public function new(string $repoType, string $name, string $url, string $gpgKeyU $stmt->bindValue(':url', $url); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -122,7 +122,7 @@ public function edit(string $id, string $name, string $url, string|null $gpgKeyU $stmt->bindValue(':sslCaCertificatePath', $sslCaCertificatePath); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -136,7 +136,7 @@ public function delete(string $sourceId) $stmt->bindValue(':id', $sourceId); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -151,7 +151,7 @@ public function exists(string $type, string $source) $stmt->bindValue(':name', $source); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } if ($this->db->isempty($result)) { @@ -171,7 +171,7 @@ public function existsId(string $id) $stmt->bindValue(':id', $id); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } if ($this->db->isempty($result)) { diff --git a/www/models/Stat.php b/www/models/Stat.php index 2e467117..33e3c3ed 100644 --- a/www/models/Stat.php +++ b/www/models/Stat.php @@ -28,7 +28,7 @@ public function add(string $date, string $time, string $repoSize, string $packag $stmt->bindValue(':envId', $envId); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -63,7 +63,7 @@ public function addAccess(string $date, string $time, string $type, string $repo $stmt->bindValue(':result', $result); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -77,7 +77,7 @@ public function addAccessToQueue(string $request) $stmt->bindValue(':request', $request); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -92,7 +92,7 @@ public function getAccessQueue() $stmt = $this->db->prepare("SELECT * FROM access_queue LIMIT 100"); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -112,7 +112,7 @@ public function deleteFromQueue(string $id) $stmt->bindValue(':id', $id); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -126,7 +126,7 @@ public function getAll(string $envId) $stmt->bindValue('envId', $envId); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } $datas = array(); @@ -149,7 +149,7 @@ public function getEnvSize(string $envId, int $days) $stmt->bindValue(':days', $days); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } $datas = array(); @@ -172,7 +172,7 @@ public function getPkgCount(string $envId, int $days) $stmt->bindValue(':days', $days); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } $datas = array(); @@ -244,7 +244,7 @@ public function getAccess(string $type, string $name, string|null $dist, string| $stmt->bindValue(':offset', $offset, SQLITE3_INTEGER); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -285,7 +285,7 @@ public function getDailyAccessCount(string $type, string $name, string|null $dis $stmt->bindValue(':date', $date); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -320,7 +320,7 @@ public function clean(string $dateStart, string $dateEnd) $this->db->exec("VACUUM"); $this->db->exec("ANALYZE"); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } diff --git a/www/models/Task/Schedule/Schedule.php b/www/models/Task/Schedule/Schedule.php index f51e5db7..36b44f20 100644 --- a/www/models/Task/Schedule/Schedule.php +++ b/www/models/Task/Schedule/Schedule.php @@ -22,7 +22,7 @@ public function getScheduled() try { $result = $this->db->query("SELECT * FROM tasks WHERE Status = 'queued'"); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { diff --git a/www/models/Task/Task.php b/www/models/Task/Task.php index 3080bf75..5ea214b1 100644 --- a/www/models/Task/Task.php +++ b/www/models/Task/Task.php @@ -28,7 +28,7 @@ public function getById(int $id) : array $stmt->bindValue(':id', $id); $result = $stmt->execute(); } catch (Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -48,7 +48,7 @@ public function getPidById(int $id) : int $stmt->bindValue(':id', $id); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -72,7 +72,7 @@ public function getIdByPid(int $pid) : int $stmt->bindValue(':pid', $pid); $result = $stmt->execute(); } catch (Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -89,7 +89,7 @@ public function getLogfileById(int $id) : string $stmt->bindValue(':id', $id); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -110,7 +110,7 @@ public function updateDate(int $id, string $date) : void $stmt->bindValue(':id', $id); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -125,7 +125,7 @@ public function updateTime(int $id, string $time) : void $stmt->bindValue(':id', $id); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -140,7 +140,7 @@ public function updatePid(int $id, int $pid) :void $stmt->bindValue(':id', $id); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -155,7 +155,7 @@ public function updateLogfile(int $id, string $logfile) :void $stmt->bindValue(':id', $id); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -170,7 +170,7 @@ public function updateRawParams(int $id, string $rawParams) : void $stmt->bindValue(':id', $id); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -185,7 +185,7 @@ public function updateStatus(int $id, string $status) : void $stmt->bindValue(':id', $id); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -200,7 +200,7 @@ public function updateDuration(int $id, string $duration) : void $stmt->bindValue(':id', $id); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -214,7 +214,7 @@ public function somethingRunning() try { $result = $this->db->query("SELECT Id FROM tasks WHERE Status = 'running'"); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -271,7 +271,7 @@ public function listRunning(string $type, bool $withOffset, int $offset) $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -310,7 +310,7 @@ public function listScheduled(bool $withOffset, int $offset) $stmt->bindValue(':offset', $offset, SQLITE3_INTEGER); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -370,7 +370,7 @@ public function listDone(string $type, bool $withOffset, int $offset) $stmt->bindValue(':offset', $offset, SQLITE3_INTEGER); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -397,7 +397,7 @@ public function getLastScheduledTask() $stmt->bindValue(':date', date('Y-m-d', strtotime('-7 days'))); $result = $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -417,7 +417,7 @@ public function getNextScheduledTask() try { $result = $this->db->query("SELECT * FROM tasks WHERE Type = 'scheduled' AND Status = 'scheduled'"); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } while ($row = $result->fetchArray(SQLITE3_ASSOC)) { @@ -439,7 +439,7 @@ public function new(string $type, string $rawParams, string $status) : int $stmt->bindValue(':status', $status); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } /** @@ -458,7 +458,7 @@ public function duplicate(int $id) : int $stmt->bindValue(':id', $id); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } /** @@ -479,7 +479,7 @@ public function close(int $id, string $status, string $duration) $stmt->bindValue(':id', $id); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -493,7 +493,7 @@ public function enable(int $id) $stmt->bindValue(':id', $id); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -507,7 +507,7 @@ public function disable(int $id) $stmt->bindValue(':id', $id); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } @@ -521,7 +521,7 @@ public function delete(int $id) $stmt->bindValue(':id', $id); $stmt->execute(); } catch (\Exception $e) { - \Controllers\Common::dbError($e); + $this->db->logError($e); } } } diff --git a/www/public/assets/favicon.ico b/www/public/assets/favicon.ico index cebe4d88bb82df8b9a5d0a1a14e4bcecb4ece241..b10b007f2ed104716de8143988c3127231be3a41 100644 GIT binary patch literal 3821 zcmVEX>4Tx04R}tkv&MmKpe$iQ>A`X9PA(>n4vmZ5fyRNDionYs1;guFuC*#nlvOS zE{=k0!NHHks)LKOt`4q(Aou~|?BJy6A|?JWDYS_7;J6>}?mh0_0YbING^=eK&~)2O z#G+y4y_(bAaW|%hd2J!T! zZE)Tv4zawf5}y-~nshbnM}+Rhls^o6Dv*3@}@>SMI2T&o$`g0 z$13M7&RVg|>i6U?3}*C|Wvu?$|#@+8xdM{QY<8BKia}S;QA$UDdZ}E zkz)ZRXpmh$_#gc4*2+#!cuB!1(Ej2$AHzUk7pPSn=lj@kYA1mI8Mx9L{!$f~`6Rv4 z(85PR?>2C8-O!Xh;Bp7(e==lKb|pVeA)5u>&*+=dK;JFUwdVC!-^b|#kfg5SH^9Lm zFp{I}^%n2$XzuObGxh#{0EBFEu4?wq$p8QV24YJ`L;(K){{a7>y{D4^000SaNLh0L z01ejw01ejxLMWSf00007bV*G`2j~e43?U3);dYY%01W9#L_t(|+U=crl$T`{$L}*U zz@P#$h=_6^N)uU3!4z;|(_C{cx5_d#(>g{jSz4LpQYY=0E2x-;8*XSG_YDOVTyjZF zB?S~zHj!;$hMD>F$M60;zv%bQyzhN~+xz~Wdk+6_X6AXGd%y49p8MP@Qe^~m1117* z0vmyaz@LBt;wjaF?+^SL_>BD23`_$?0?uyBz_^!Z@fVoCz?kr%-5YFS_M(1%Ia6K^8ORKPg?*m*2EHMav4seVmoC8Jx ze>a$yR^Tz<0HDT8&@T9)z>Pp-L;-9BrUQEw!ckKP^CDoW0f2K=Yi;f&8jjfx_y+KZ z!M?8nt^&3%(%v>xVZLPm!ZHQXc3#T)nOhH>2)ton?nl76Ktlmu&GO&!g{fx2oG{2<^uV67n$^B^#;lD?oEATKrm zd7g%#J*vUJj|2Xpf{YqsO#%j0_!+xsa_AKU5LN=0ZJMJs(dnVdX02TE7>3b2_^fqlWx{#uy2!obhh)nDpb zij5A``}5BYiH|3NgMeBu@<9G>5u>8%6X1fPXjD~I(=VTCybGKLY~e*$ za3J)JQ5P{Ybj6YuJT^x}+6>@OZ{JG-gs#9z`m!ksJsv8vsCFj|H37Hj!wY}4S$ZJU zXwvMV2-nhs!X$K7h4|vH1p0e1R16sQ4p|a^a2NoDxzhX;_&w0qv%jo@-x0W0GlXGi zSeQS0ZN!k{Z@?~I93>OFQ$Ov2h++8)VSRvJhPt;l;AxFry(3s0!FL9Z2VOSh2Ic}^ zin3TYy@&tA5OTZ&{M3hn1rvNvy$M`skj1|=V(4OByesg1;5EbIEA&0SZ@ggR{g;h( z1g#qK74BVvh8*Mc1}f@xZ?^HmC@nS4Z$XedC3Wd0Gd2 zTlo{!zAx1`2YpMu>4q4#X+CgHwKrbSN2wEm_YFM!H}K=KzdBOy^cZ7N$SQr!vqO~$ zet=d0uQX`UXMjU0F51%gbhK8qMy+t!sB!JsG^dq;-L(R!DI$M10Jj3eW6Gx?Z-J@a zKcA#|75)c3WimN35;%;9s`1{Ws^@NmR#SyuytV=!nqFg0zB z7h;^N3Ahv3J!V997VtsDwWo;Dd(UQ@4vk?R;xt}(3plmhA&@4>4l&m5tyDj0K#cWw z(su%Du+be>0OZnt6n#C7huBQbkfrg$(sI-u>Yh&p-Zt#{1K{V@*T6ab2_81|C&&wc z7by&_(HFc!V;pS%7>yUE0wann_-(WfVu``N&(>^TC*#`PfYXhj3*zUUg#@#U51(zku*k6XJm64W-ERz*YE3roAa4Lb=Cs`@I0lXY~|1q z*n0P6%c1T!d>PGp&6>CIf@+)JV(VA*idO4%HVVFs`Fb$^N=m7uryu> zdpB`j42{(X_>Iw_T}GxIet+ZIK>)a?k^qoP3xHo)FM@zQG`-qXfW5pOZtaSRn*w%108>aC>qux9YiE$}o^+#5cnPpJ$UdQbK;J%~)VAELpJPZRG z_}|70xz69GWV&ngF*0~C(Vl4KQuZB1cPSE)dF~$wfEgr{)~RhBVPwjVs!=9b?7M>L zK)n@hHJF&k^!JNi+t&^NrY9Kyx#nROnZnf0C17TE?0tOJkm->;SV~BGdzcphbs|E- z%kG?r?5Y120h2}K2It(80yA-Y5jkB%P85--l~MCWgvM*?xy7KFo+Z;~sjMyG^-?Pz-JjN(HuWNMf{45%BC~+wh)`urrr_gb z5qV8So)VG6L?o=OUN0gyi^y)yxiQYUd!2JF<*rx@(g0~N0Ueo#(fV%@@Jr|1Z5;^z zR1x`uh(t|7Ef$fAP?d=HvIt5Nxnj<1tiOAi~x#pxX zr6%PXAfHCKBwvP26HFI|6n?Xa+#w>PopU3dbGKEv@Vy4eq5dMWt%xkzSp{ zB=afI1o+XW9aC$M7r&(*yKh{L2bAKGhxDhIa*fHwi2s##lj4GpBYXF}I@EX9RCcOsmp1ltPeICF&fj$r5 zO@Pk>cqh<<#cO~R3zcfr03HD8cLKY66HsL)K*#Is4%{jtj|cr+ortt}p{7UuYrEVd zMdS<-8P&m$udfr4xBW++d<~%8(@z$W(A~Ib>#zolQDiOI-M0Rq{9p#++sJ(@D({9_1q?7i{ zbLQRw9l@7WfZzuKSL;aHsPvwW(CuMaxR1{6{jdrEuvH}iKwH%xh;2-K8}NjV$EhvE zW;y{!>xj9w6aZka2mn}GV!>wzTv^7%$C}X`c7r2g%)zT<0Q4#+0LYAqzZ~0`_=RM~ z#BWtfq;9R#yA~!80DDIOz_KD|>&61pv5kqJX&t3k$U}6}P0UD;dDthq=%sy>(1{>~T270>iGrjYOZsT@?TTwgWE0J|_MGpl=cq6}{CaEvQfcjLEa-o&f+@ zQ2;f+2XH&E!LZkt$&87wm!wh74Bclc%sfN^z-Pv@chO;0vkhl&!Z0Sj(!sE^&gETO z0RR{qkY(E#7Xa!UpO1Y^{G}Mj#3uy^y?}Fo`DFyaxCj7P8NvU#3HzA%Q;0bxKCu@X zhD=u}0q}VU6K9ElvSZ>WP@pmKNe06(&0wu55dg;L*+Y-803iOD_$w&FnD{gRA8lSMKQ6Y{LtJpcf!frEfYVvLDDq!eS~(+Y;6 zI&yt=0RgaY1OQlQEieff;w4x(AoK*z1m+b90Nn}zfcYBXG4+yn-&;3{o^RQn4 z0GbVdt4*VTvX6SHxBw4@`2EFN zCDq4szA~eSgMdc^%tI^igLZy@NIL}?vw`D*E}qlL0K-neRrOw(gAMvOLs7@XZyP`l$ZbhoHN95&?4E1# zo3zJ$<7ijz({KD}SC~UpXm8jbeW`^x{F0#1G`9v1% G5&r>to1nq~ diff --git a/www/public/resources/js/functions.js b/www/public/resources/js/functions.js index 9c2ac530..f9a17776 100644 --- a/www/public/resources/js/functions.js +++ b/www/public/resources/js/functions.js @@ -177,6 +177,39 @@ function printLoadingVeilByParentClass(name) $('.' + name).find('.veil-on-reload').append('
Loading
'); } +/** + * Print a modal window with specified content + * @param {*} content + * @param {*} title + * @param {*} inPre + */ +function printModalWindow(content, title, inPre = true) +{ + /** + * If a modal window is already opened, remove it + */ + $('.modal-window-container').remove(); + + html = ''; + + $('footer').append(html); +} + /** * Slide div by class name or Id and save state in sessionStorage * @param {*} name diff --git a/www/public/resources/js/general.js b/www/public/resources/js/general.js index 18eff89a..25b087e2 100644 --- a/www/public/resources/js/general.js +++ b/www/public/resources/js/general.js @@ -18,9 +18,18 @@ $(document).on('click','.slide-panel-close-btn',function () { }); /** - * Event: mark log as read + * Event: show general log details */ -$(document).on('click','.acquit-log-btn',function () { +$(document).on('click','.general-log-show-info-btn',function () { + var id = $(this).attr('log-id'); + + $('pre.general-log-details[log-id="' + id + '"]').toggle(); +}); + +/** + * Event: mark general log as read + */ +$(document).on('click','.general-log-acquit-btn',function () { var id = $(this).attr('log-id'); ajaxRequest( @@ -42,11 +51,19 @@ $(document).on('click','.acquit-log-btn',function () { }); /** - * Event: hide slided window on escape button press + * Event: close request log details + */ +$(document).on('click','.modal-window-close-btn',function () { + $(".modal-window-container").remove(); +}); + +/** + * Event: hide slided window and modal window on escape button press */ $(document).keyup(function (e) { if (e.key === "Escape") { closePanel(); + $(".modal-window-container").remove(); } }); diff --git a/www/public/resources/js/host.js b/www/public/resources/js/host.js index 2b209e30..d8654e57 100644 --- a/www/public/resources/js/host.js +++ b/www/public/resources/js/host.js @@ -752,63 +752,78 @@ $(document).on('click','#installed-packages-btn',function () { /** * Event: show request log details */ -$(document).on('click','.request-show-log-btn',function () { +$(document).on('click','.request-show-log-btn',function (e) { + // Prevent parent to be triggered + e.stopPropagation(); + /** * Retrieve request id */ var id = $(this).attr('request-id'); - /** - * Get request log - */ - $.ajax({ - type: "POST", - url: "/ajax/controller.php", - data: { - controller: "host", - action: "getRequestLog", + ajaxRequest( + // Controller: + 'host', + // Action: + 'getRequestLog', + // Data: + { id: id }, - dataType: "json", - success: function (data, textStatus, jqXHR) { - /** - * Retrieve and print success message - */ - jsonValue = jQuery.parseJSON(jqXHR.responseText); + // Print success alert: + false, + // Print error alert: + true, + // Reload container: + [], + // Execute functions on success: + [ + "printModalWindow(jsonValue.message, 'LOG')" + ] + ); +}); - html = '
' - + '
' - + '
' - + '

LOG

' - + '' - + '
' - + '
' - + '
' + jsonValue.message + '
' - + '
' - + '
' - + '
'; +/** + * Event: show package log details + */ +$(document).on('click','.request-show-package-log-btn',function (e) { + /** + * Retrieve request id, package name and status + */ + var id = $(this).attr('request-id'); + var package = $(this).attr('package'); + var status = $(this).attr('status'); - /** - * Print request log - */ - $('footer').append(html); + ajaxRequest( + // Controller: + 'host', + // Action: + 'getRequestPackageLog', + // Data: + { + id: id, + package: package, + status: status }, - error: function (jqXHR, textStatus, thrownError) { - /** - * Retrieve and print error message - */ - jsonValue = jQuery.parseJSON(jqXHR.responseText); - - printAlert(jsonValue.message, 'error'); - } - }); + // Print success alert: + false, + // Print error alert: + true, + // Reload container: + [], + // Execute functions on success: + [ + "printModalWindow(jsonValue.message, 'LOG')" + ] + ); }); /** - * Event: close request log details + * Event: show request log details */ -$(document).on('click','.ws-request-close-btn',function () { - $(".ws-request-log-container").remove(); +$(document).on('click','.request-show-more-info-btn',function () { + var id = $(this).attr('request-id'); + $('div.request-details[request-id="' + id + '"]').toggle(); }); /** @@ -842,21 +857,37 @@ $(document).on('click','.cancel-request-btn',function () { }); /** - * Event : récupérer l'historique d'un paquet + * Event: print package history */ $(document).on('click','.get-package-timeline',function () { /** - * Si un historique est déjà affiché à l'écran on le détruit - */ - $(".package-details-container").remove(); - - /** - * Récupération de l'Id du package + * Retrieve id of the host and the package name */ var hostid = $(this).attr('hostid'); - var packagename = $(this).attr('packagename'); + var packageName = $(this).attr('packagename'); + var title = packageName.toUpperCase() + ' HISTORY'; - getPackageTimeline(hostid, packagename); + ajaxRequest( + // Controller: + 'host', + // Action: + 'getPackageTimeline', + // Data: + { + hostid: hostid, + packagename: packageName + }, + // Print success alert: + false, + // Print error alert: + true, + // Reload container: + [], + // Execute functions on success: + [ + "printModalWindow(jsonValue.message, '" + title + "', false)" + ] + ); }); /** @@ -922,13 +953,6 @@ $(document).on('mouseleave', '.event-packages-details', function () { $('.event-packages-details').remove(); }); -/** - * Event: close package details div - */ -$(document).on('click','.package-details-close-btn',function () { - $(".package-details-container").remove(); -}); - /** * Ajax: Create a new group * @param {string} name @@ -1082,46 +1106,6 @@ function getHostsWithPackageAjax(hostsId_array, package) }); } -/** - * Ajax : récupérer l'historique d'un paquet en base de données - * @param {string} hostid - * @param {string} packagename - */ -function getPackageTimeline(hostid, packagename) -{ - $.ajax({ - type: "POST", - url: "/ajax/controller.php", - data: { - controller: "host", - action: "getPackageTimeline", - hostid: hostid, - packagename: packagename - }, - dataType: "json", - success: function (data, textStatus, jqXHR) { - jsonValue = jQuery.parseJSON(jqXHR.responseText); - - html = '
' - + '
' - + '
' - + '' - + '
' - + '
' - + '
' + jsonValue.message + '
' - + '
' - + '
' - + '
'; - - $('footer').append(html); - }, - error: function (jqXHR, textStatus, thrownError) { - jsonValue = jQuery.parseJSON(jqXHR.responseText); - printAlert(jsonValue.message, 'error'); - }, - }); -} - /** * Ajax : récupérer les détails d'un évènement (la liste des paquets installés, mis à jour...) * @param {string} hostId diff --git a/www/public/resources/js/task.js b/www/public/resources/js/task.js index 75e06663..45c272d6 100644 --- a/www/public/resources/js/task.js +++ b/www/public/resources/js/task.js @@ -10,6 +10,8 @@ function loadNewRepoFormJS() selectToSelect2('.task-param[param-name="dist"]', 'e.g: bullseye', true); selectToSelect2('.task-param[param-name="section"]', 'e.g: main', true); selectToSelect2('.task-param[param-name="arch"]', 'Select architecture', true); + selectToSelect2('.task-param[param-name="package-include"]', 'Specify package(s)', true); + selectToSelect2('.task-param[param-name="package-exclude"]', 'Specify package(s)', true); selectToSelect2('select.task-param[param-name="schedule-day"]', 'Select day(s)...', true); selectToSelect2('select.task-param[param-name="schedule-reminder"]', 'Select reminder...', true); selectToSelect2('select.task-param[param-name="schedule-recipient"]', 'Select or add recipients...', true); diff --git a/www/public/resources/styles/common.css b/www/public/resources/styles/common.css index 44ae82b5..b5d88d5f 100644 --- a/www/public/resources/styles/common.css +++ b/www/public/resources/styles/common.css @@ -75,6 +75,15 @@ pre { font-size: 12px; } +pre.codeblock { + background-color: rgb(26 29 31); + color: white; + border-radius: 8px; + font-size: 12px; + line-height: 1.5; + padding: 20px; +} + /** * Generic class */ @@ -341,7 +350,6 @@ input::placeholder { background-color: initial; box-shadow: rgb(0 0 0) 0px 10px 13px -12px, rgb(0 0 0 / 15%) 0px 0px 10px 2px; border: 1px solid #24405c; - opacity: 0.5; } /* All blue buttons */ @@ -393,7 +401,7 @@ input::placeholder { .btn-large-tr-to-red:hover, .btn-medium-tr-to-red:hover, .btn-small-tr-to-red:hover, .btn-xsmall-tr-to-red:hover, .btn-xxsmall-tr-to-red:hover, .btn-fit-tr-to-red:hover, .round-btn-tr-to-red:hover { transition-duration: 0.2s; background-color: #dc0044; - border: 1 px solid #dc0044; + border: 1px solid #dc0044; opacity: 1; } @@ -483,11 +491,11 @@ input::placeholder { background-color: initial; box-shadow: rgb(32 25 25 / 50%) 0px 0px 15px 1px; border: 1px solid #ffffff52; - opacity: 0.5; + /* opacity: 0.5; */ } -.slide-btn-tr:hover, .slide-btn-medium-tr:hover { +/* .slide-btn-tr:hover, .slide-btn-medium-tr:hover { opacity: 1; -} +} */ /* override slide-btn */ [class^="slide-btn-medium"] { @@ -837,6 +845,42 @@ textarea { z-index: 998; } +.modal-window-container { + display: flex; + justify-content: center; + align-items: center; + position: fixed; + top: 0; + left: 0; + width: 100vw; + height: 100vh; + z-index: 10000; + margin: auto; + background-color: #182b3e82; +} + +.modal-window { + display: flex; + flex-direction: column; + width: 70%; + max-height: 80%; + padding: 15px 15px 15px 15px; + border-radius: 8px; + background-color: #112334; + overflow: auto; + box-shadow: rgb(0 0 0) 0px 10px 13px -12px, rgb(0 0 0 / 15%) 0px 0px 10px 2px; +} + +.modal-window pre { + min-height: 200px; + padding: 20px; + margin-top: 20px; + background-color: #0c141b; + border-radius: 8px; + line-height: 1.5; + text-wrap: wrap; +} + /** * Generic div */ diff --git a/www/public/resources/styles/run.css b/www/public/resources/styles/run.css index 94124511..18f2ff03 100644 --- a/www/public/resources/styles/run.css +++ b/www/public/resources/styles/run.css @@ -41,16 +41,6 @@ margin: 0; } -#log pre.codeblock { - background-color: rgb(26 29 31); - color: white; - border-radius: 4px; - font-size: 12px; - line-height: 1.5; - padding: 20px; - margin: 10px 0 0 0; -} - /* Boutons Top et Down pour atteindre le haut ou le bas de page */ #scrollButtons-container { /* flex: 0 4%; */ diff --git a/www/public/resources/styles/stats-hosts.css b/www/public/resources/styles/stats-hosts.css index 6ced16c3..32dad5b5 100644 --- a/www/public/resources/styles/stats-hosts.css +++ b/www/public/resources/styles/stats-hosts.css @@ -348,41 +348,6 @@ td:last-child, left: -16px; } -.package-details-container, .ws-request-log-container { - display: flex; - justify-content: center; - align-items: center; - position: fixed; - top: 0; - left: 0; - width: 100vw; - height: 100vh; - margin: auto; - background-color: #182b3e82; -} - -.package-details, .ws-request-log { - display: flex; - flex-direction: column; - width: 70%; - max-height: 80%; - padding: 15px 15px 15px 15px; - border-radius: 8px; - background-color: #112334; - overflow: auto; - box-shadow: rgb(0 0 0) 0px 10px 13px -12px, rgb(0 0 0 / 15%) 0px 0px 10px 2px; -} - -.ws-request-log pre { - min-height: 200px; - padding: 20px; - margin-top: 20px; - background-color: #0c141b; - border-radius: 8px; - line-height: 1.5; - text-wrap: wrap; -} - /* Desktop configuration */ @media (min-width:1500px) { .groups-container { diff --git a/www/update/database/4.9.0.php b/www/update/database/4.9.0.php new file mode 100644 index 00000000..bd1df250 --- /dev/null +++ b/www/update/database/4.9.0.php @@ -0,0 +1,25 @@ +db->columnExist('logs', 'Details') === true) { + $this->db->exec("ALTER TABLE logs ADD COLUMN Details TEXT"); +} + +/** + * Add new 'Pkg_included' column to the repos_snap table + */ +if (!$this->db->columnExist('repos_snap', 'Pkg_included') === true) { + $this->db->exec("ALTER TABLE repos_snap ADD COLUMN Pkg_included VARCHAR(255)"); +} + +/** + * Add new 'Pkg_excluded' column to the repos_snap table + */ +if (!$this->db->columnExist('repos_snap', 'Pkg_excluded') === true) { + $this->db->exec("ALTER TABLE repos_snap ADD COLUMN Pkg_excluded VARCHAR(255)"); +} diff --git a/www/update/database/3.7.11.php b/www/update/database/archives/3.7.11.php similarity index 100% rename from www/update/database/3.7.11.php rename to www/update/database/archives/3.7.11.php diff --git a/www/update/database/3.7.15.php b/www/update/database/archives/3.7.15.php similarity index 100% rename from www/update/database/3.7.15.php rename to www/update/database/archives/3.7.15.php diff --git a/www/update/database/3.7.17.php b/www/update/database/archives/3.7.17.php similarity index 100% rename from www/update/database/3.7.17.php rename to www/update/database/archives/3.7.17.php diff --git a/www/update/database/3.7.6.php b/www/update/database/archives/3.7.6.php similarity index 100% rename from www/update/database/3.7.6.php rename to www/update/database/archives/3.7.6.php diff --git a/www/update/database/4.0.0.php b/www/update/database/archives/4.0.0.php similarity index 100% rename from www/update/database/4.0.0.php rename to www/update/database/archives/4.0.0.php diff --git a/www/version b/www/version index 6ca6df11..b617d997 100644 --- a/www/version +++ b/www/version @@ -1 +1 @@ -4.8.0 \ No newline at end of file +4.9.0 \ No newline at end of file diff --git a/www/views/includes/containers/header/general-log-messages.inc.php b/www/views/includes/containers/header/general-log-messages.inc.php index ce40d8f2..a6fde227 100644 --- a/www/views/includes/containers/header/general-log-messages.inc.php +++ b/www/views/includes/containers/header/general-log-messages.inc.php @@ -5,24 +5,44 @@ */ if (LOG > 0) : ?>
-
+

Log messages ()

-
+
+
+ '; + } + if ($log['Type'] == 'info') { + echo ''; + } ?> + +

- -

+
+ '; - } - if ($log['Type'] == 'info') { - echo ''; + if (!empty($log['Details'])) { + echo '
' . $log['Details'] . '
'; } ?> - - -
-
- - Mark as read + +
+ +
+ + More info +
+ + +
+ + Mark as read +
✕'; + $shortRequestTitle = 'Update all packages failed'; + $textColor = 'redtext'; + } + $requestInfo = $successCount . ' package(s) updated, ' . $failedCount . ' failed'; } } else { diff --git a/www/views/includes/forms/tasks/update.inc.php b/www/views/includes/forms/tasks/update.inc.php index 729bba86..0c1132b3 100644 --- a/www/views/includes/forms/tasks/update.inc.php +++ b/www/views/includes/forms/tasks/update.inc.php @@ -8,39 +8,7 @@ Task will create a new mirror snapshot: -

- - - - Update parameters - - - - Architecture - - - +



@@ -93,6 +61,75 @@ + + Advanced parameters + + + + Architecture + + + + + + + + Only include package(s) + (optional) + + + + + + + + + + Exclude package(s) + (optional) + + + + + + + date<-env schema if an env is selected diff --git a/www/views/includes/panels/repos/new.inc.php b/www/views/includes/panels/repos/new.inc.php index ae90be81..4ac62c65 100644 --- a/www/views/includes/panels/repos/new.inc.php +++ b/www/views/includes/panels/repos/new.inc.php @@ -233,6 +233,28 @@ + + + + Only include package(s) + (optional) + + + + + + + + + + Exclude package(s) + (optional) + + + + + +
diff --git a/www/views/includes/repos-list.inc.php b/www/views/includes/repos-list.inc.php index 9b3f8e85..2bf0e741 100644 --- a/www/views/includes/repos-list.inc.php +++ b/www/views/includes/repos-list.inc.php @@ -41,7 +41,7 @@
- +
✔ Successful - '; + } + + // If the update failed + if ($infoJson['update']['status'] == 'failed') { + $requestInfo = ' Failed - '; + $statusColor = 'red'; + $requestStatus = 'Request completed with errors'; + } + + // Build a short info message + $requestInfo .= $successCount . ' package(s) updated, ' . $failedCount . ' failed'; + + // Retrieve the list of packages updated + $successPackages = $infoJson['update']['success']['packages']; + + // Retrieve the list of packages failed + $failedPackages = $infoJson['update']['failed']['packages']; } } else { $requestInfo = $item['Info']; } - if (file_exists(WS_REQUESTS_LOGS_DIR . '/request-' . $item['Id'] . '.log')) { - $log = true; - $title = "Show log"; - $class .= ' request-show-log-btn pointer'; + if (!empty($successPackages) or !empty($failedPackages)) { + $class .= ' request-show-more-info-btn pointer'; } } ?> -
+
@@ -115,10 +136,10 @@ } ?>
-
+
- + if (file_exists(WS_REQUESTS_LOGS_DIR . '/request-' . $item['Id'] . '.log')) : ?> +
+ +
+ +

updated

+ +
+ $details) : ?> +
+ +

+
+ +

+ +

+ + + +

+ +
+ +

failed

+ +
+ $details) : ?> +
+ +

+
+ +

+ +

+ + + +

+ +
+ +
+
diff --git a/www/views/templates/tasks/new-update-rebuild.inc.php b/www/views/templates/tasks/new-update-rebuild.inc.php index 7da46dd9..5fadcc83 100644 --- a/www/views/templates/tasks/new-update-rebuild.inc.php +++ b/www/views/templates/tasks/new-update-rebuild.inc.php @@ -51,7 +51,7 @@ ARCHITECTURE -
+
repo->getArch() as $arch) { echo '' . $arch . ''; @@ -62,6 +62,36 @@ repo->getPackagesToInclude())) : ?> + + PACKAGES TO INCLUDE + +
+ repo->getPackagesToInclude() as $package) { + echo '' . $package . ''; + } ?> +
+ + + repo->getPackagesToExclude())) : ?> + + PACKAGES TO EXCLUDE + +
+ repo->getPackagesToExclude() as $package) { + echo '' . $package . ''; + } ?> +
+ + + repo->getDescription())) { echo 'DESCRIPTION' . $this->repo->getDescription() . ''; }