Skip to content

Commit

Permalink
Merge pull request #200 from lbr38/devel
Browse files Browse the repository at this point in the history
4.9.0
  • Loading branch information
lbr38 authored Sep 16, 2024
2 parents 3c9c2d6 + 3e48f73 commit 5e3d358
Show file tree
Hide file tree
Showing 63 changed files with 1,195 additions and 593 deletions.
4 changes: 1 addition & 3 deletions Todolist
Original file line number Diff line number Diff line change
@@ -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 ]

Expand All @@ -18,7 +16,7 @@
- Think about a way to publish debian repos in a more elegant way. Currently: https://<FQDN>/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 ]
Expand Down
40 changes: 0 additions & 40 deletions www/controllers/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,46 +145,6 @@ public static function printAlert(string $message, string $alertType = null)
echo '</script>';
}

/**
* 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 <br>' . $exception . '<br>');
} else {
throw new Exception('An error occured while executing request in database');
}
}

/**
* Colore l'environnement d'une étiquette rouge ou blanche
*/
Expand Down
13 changes: 10 additions & 3 deletions www/controllers/Host.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<h4>' . strtoupper($packageName) . ' PACKAGE HISTORY</h4>';
$content .= '<div class="timeline">';
$content = '<div class="timeline">';

/**
* The first block will be displayed on the left in the timeline
Expand Down Expand Up @@ -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';

Expand All @@ -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);
}
}
48 changes: 33 additions & 15 deletions www/controllers/Log/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

/**
Expand Down
44 changes: 44 additions & 0 deletions www/controllers/Repo/Mirror/Deb.php
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,50 @@ private function downloadDebPackages($url)
*/
$this->logOutput('<span class="opacity-80-cst">(' . $packageCounter . '/' . $totalPackages . ') ➙ ' . $debPackageLocation . ' ... </span>');

/**
* 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('<span class="opacity-80-cst">not in the list of packages to include (ignoring)</span>' . 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('<span class="opacity-80-cst">in the list of packages to exclude (ignoring)</span>' . PHP_EOL);
continue;
}
}

/**
* Check that package naming respects the Debian package naming convention
* It must ends with _<arch>.deb, if not then rename it
Expand Down
12 changes: 12 additions & 0 deletions www/controllers/Repo/Mirror/Mirror.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class Mirror
protected $sslCustomCaCertificate;
protected $curlHandle;
protected $previousSnapshotDirPath;
protected $packagesToInclude = [];
protected $packagesToExclude = [];

public function setUrl(string $url)
{
Expand Down Expand Up @@ -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;
Expand Down
44 changes: 44 additions & 0 deletions www/controllers/Repo/Mirror/Rpm.php
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,50 @@ private function downloadRpmPackages(string $url)
*/
$this->logOutput('<span class="opacity-80-cst">(' . $packageCounter . '/' . $totalPackages . ') ➙ ' . $rpmPackageLocation . ' ... </span>');

/**
* 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('<span class="opacity-80-cst">not in the list of packages to include (ignoring)</span>' . 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('<span class="opacity-80-cst">in the list of packages to exclude (ignoring)</span>' . PHP_EOL);
continue;
}
}

/**
* Check that package architecture is valid
*/
Expand Down
Loading

0 comments on commit 5e3d358

Please sign in to comment.