Skip to content

Commit

Permalink
Merge pull request #209 from lbr38/devel
Browse files Browse the repository at this point in the history
4.13.0
  • Loading branch information
lbr38 authored Nov 24, 2024
2 parents bc44641 + 129c9ff commit f2e0b1b
Show file tree
Hide file tree
Showing 107 changed files with 4,700 additions and 3,042 deletions.
10 changes: 0 additions & 10 deletions .github/workflows/tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ jobs:
- name: Print PHP version
run: php --version

# TODO : temporaire
# A retirer une fois que 4.12.0 est publiée
- name: Install PHP yaml extension
run: apt-get update -y && apt-get install -y php8.3-yaml

# Copy latest source code to the root directory
- name: Setup latest source code
run: |
Expand Down Expand Up @@ -93,11 +88,6 @@ jobs:
- name: Print PHP version
run: php --version

# TODO : temporaire
# A retirer une fois que 4.12.0 est publiée
- name: Install PHP yaml extension
run: apt-get update -y && apt-get install -y php8.3-yaml

# Copy latest source code to the root directory
- name: Setup latest source code
run: |
Expand Down
13 changes: 6 additions & 7 deletions Todolist
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@

[ IMPROVEMENTS / FEATURES ]

[ GENERAL ]

- (JS) Refactor and mutualize the ajax functions


[ REPOS ]

- 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/
https://wiki.archlinux.org/title/Pacman#Repositories_and_mirrors
https://wiki.archlinux.org/title/DeveloperWiki:NewMirrors


[ TASKS ]

- Use standard websocket client to update tasks log output https://github.com/websockets/ws


[ CVE ]

- Check for affected hosts when sending packages with linupdate
Expand Down
3 changes: 1 addition & 2 deletions www/controllers/App/Config/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static function get()
/**
* Following parameters can be empty (or equal to 0), we don't increment the error counter in their case
*/
$ignoreEmptyParam = array('PROXY', 'RPM_DEFAULT_ARCH', 'DEB_DEFAULT_ARCH', 'DEB_DEFAULT_TRANSLATION', 'REPO_CONF_FILES_PREFIX', 'RETENTION');
$ignoreEmptyParam = array('EMAIL_RECIPIENT', 'PROXY', 'RPM_DEFAULT_ARCH', 'DEB_DEFAULT_ARCH', 'DEB_DEFAULT_TRANSLATION', 'REPO_CONF_FILES_PREFIX', 'RETENTION');

if (in_array($key, $ignoreEmptyParam)) {
continue;
Expand Down Expand Up @@ -68,7 +68,6 @@ public static function get()
define('EMAIL_RECIPIENT', explode(',', $settings['EMAIL_RECIPIENT']));
} else {
define('EMAIL_RECIPIENT', array());
$__LOAD_SETTINGS_MESSAGES[] = '<code>DEFAULT CONTACT</code> setting is not defined. At least one email address should be defined.';
}
}

Expand Down
9 changes: 5 additions & 4 deletions www/controllers/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function __construct(string $level = 'all')
\Controllers\App\Config\Properties::get();
\Controllers\App\Config\Main::get();
\Controllers\App\Config\Settings::get();
\Controllers\App\Config\Env::get();
\Controllers\App\Structure\Directory::create();
\Controllers\App\Structure\File::create();
}
Expand Down Expand Up @@ -77,7 +78,7 @@ public function __construct(string $level = 'all')
* Errors related to the loading of the main configuration
*/
if (defined('__LOAD_SETTINGS_ERROR') && __LOAD_SETTINGS_ERROR > 0) {
$__LOAD_ERROR_MESSAGES[] = "<b>Some settings are not properly configured</b>:<br>";
$__LOAD_ERROR_MESSAGES[] = "<b>Some settings are not properly configured</b>:";
$__LOAD_ERROR_MESSAGES = array_merge($__LOAD_ERROR_MESSAGES, __LOAD_SETTINGS_MESSAGES);
++$__LOAD_GENERAL_ERROR;
}
Expand All @@ -86,7 +87,7 @@ public function __construct(string $level = 'all')
* Create dirs errors
*/
if (defined('__CREATE_DIRS_ERROR') && __CREATE_DIRS_ERROR > 0) {
$__LOAD_ERROR_MESSAGES[] = "<br><b>Some directories could not be generated</b>:<br>";
$__LOAD_ERROR_MESSAGES[] = "<b>Some directories could not be generated</b>:";
$__LOAD_ERROR_MESSAGES = array_merge($__LOAD_ERROR_MESSAGES, __CREATE_DIRS_MESSAGES);
++$__LOAD_GENERAL_ERROR;
}
Expand All @@ -95,7 +96,7 @@ public function __construct(string $level = 'all')
* Create files errors
*/
if (defined('__CREATE_FILES_ERROR') && __CREATE_FILES_ERROR > 0) {
$__LOAD_ERROR_MESSAGES[] = "<br><b>Some files could not be generated</b>:<br>";
$__LOAD_ERROR_MESSAGES[] = "<b>Some files could not be generated</b>:";
$__LOAD_ERROR_MESSAGES = array_merge($__LOAD_ERROR_MESSAGES, __CREATE_FILES_MESSAGES);
++$__LOAD_GENERAL_ERROR;
}
Expand All @@ -104,7 +105,7 @@ public function __construct(string $level = 'all')
* Errors related to the loading of the environments
*/
if (defined('__LOAD_ERROR_EMPTY_ENVS') && __LOAD_ERROR_EMPTY_ENVS > 0) {
$__LOAD_ERROR_MESSAGES[] = '<br><b>You must at least configure 1 environment.</b>';
$__LOAD_ERROR_MESSAGES[] = '<b>You must at least configure 1 environment.</b>';
++$__LOAD_GENERAL_ERROR;
}

Expand Down
11 changes: 9 additions & 2 deletions www/controllers/Browse.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public static function printQueue($queue)
*/
public static function printFile($file, $path)
{
$checkbox = false;

/**
* If file has .deb or .rpm extension, then it is a package
* If it has .db extension, then it is a metadate (database)
Expand All @@ -78,6 +80,7 @@ public static function printFile($file, $path)
if ($extension == 'deb' || $extension == 'rpm') {
$title = 'Package file';
$icon = 'package';
$checkbox = true;
} else if ($extension == 'db') {
$title = 'Metadata (database) file';
$icon = 'file';
Expand All @@ -96,7 +99,11 @@ public static function printFile($file, $path)
<p><?= $file ?></p>
</div>

<input type="checkbox" class="packageName-checkbox pointer" name="packageName[]" filename="<?= $file ?>" path="<?= $path ?>" />
<?php
if ($checkbox) : ?>
<input type="checkbox" class="package-checkbox pointer" name="packageName[]" filename="<?= $file ?>" path="<?= $path ?>" />
<?php
endif ?>
</div>
</li>
<?php
Expand All @@ -109,7 +116,7 @@ public static function printSubDir($dir, $path)
{
?>
<li>
<div class="explorer-toggle header-blue pointer flex column-gap-5 align-item-center" title="Directory <?= $dir ?>">
<div class="explorer-toggle div-generic-blue pointer flex column-gap-5 align-item-center" title="Directory <?= $dir ?>">
<img src="/assets/icons/folder.svg" class="icon" />
<p><?= $dir ?></p>
</div>
Expand Down
57 changes: 49 additions & 8 deletions www/controllers/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,21 +113,50 @@ public static function isAlphanumDash(string $data, array $additionnalValidCarac
}

/**
* Colore l'environnement d'une étiquette rouge ou blanche
* Get the best contrasting text color for a given background color
*/
public static function envtag($env, $css = null)
public static function getContrastingTextColor($backgroundColor)
{
if ($env == LAST_ENV) {
$class = 'last-env';
} else {
$class = 'env';
// Convert hexadecimal color to RGB
$r = hexdec(substr($backgroundColor, 1, 2));
$g = hexdec(substr($backgroundColor, 3, 2));
$b = hexdec(substr($backgroundColor, 5, 2));

// Calculate YIQ (luma) value
$yiq = (($r * 299) + ($g * 587) + ($b * 114)) / 1000;

// Return white for dark colors and black for light colors
return ($yiq >= 128) ? '#000000' : '#ffffff';
}

/**
* Generate environment tag
*/
public static function envtag(string $name, string $css = null)
{
// Default class
$class = 'env';

// Default colors
$backgroundColor = '#ffffff';
$color = '#000000';

// Retrieve color from ENVS array
if (defined('ENVS')) {
foreach (ENVS as $env) {
if ($env['Name'] == $name and !empty($env['Color'])) {
$backgroundColor = $env['Color'];
// Get contrasting text color
$color = Common::getContrastingTextColor($backgroundColor);
}
}
}

if ($css == 'fit') {
$class .= '-fit';
$class = 'env-fit';
}

return '<span class="' . $class . '">' . $env . '</span>';
return '<span class="' . $class . '" style="background-color: ' . $backgroundColor . '; color: ' . $color . '">' . $name . '</span>';
}

/**
Expand Down Expand Up @@ -699,4 +728,16 @@ public static function isMd5(string $md5)
{
return preg_match('/^[a-f0-9]{32}$/', $md5);
}

/**
* Convert a string to a boolean
* Possible return values:
* Returns TRUE for "1", "true", "on" and "yes"
* Returns FALSE for "0", "false", "off" and "no"
* Returns NULL on failure if FILTER_NULL_ON_FAILURE is set
*/
public static function toBool(string $string)
{
return filter_var($string, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
}
}
113 changes: 87 additions & 26 deletions www/controllers/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,57 +13,110 @@ public function __construct()
$this->model = new \Models\Environment();
}

/**
* Get environment color
*/
public static function getEnvColor(string $name)
{
// Default color
$color = '#ffffff';

// Retrieve color from ENVS array
if (defined('ENVS')) {
foreach (ENVS as $env) {
if ($env['Name'] == $name and !empty($env['Color'])) {
$color = $env['Color'];
}
}
}

return $color;
}

/**
* Add a new environment
*/
public function add(string $name, string $color) : void
{
$name = \Controllers\Common::validateData($name);
$color = \Controllers\Common::validateData($color);

if (!\Controllers\Common::isAlphanumDash($name)) {
throw new Exception('Environment name contains invalid characters');
}

/**
* Check if environment already exists
*/
if ($this->exists($name)) {
throw new Exception('Environment <b>' . $name . '</b> already exists');
}

/**
* Check that color is a valid hexadecimal color
*/
if (!preg_match('/^#[a-f0-9]{6}$/i', $color)) {
throw new Exception('Invalid color');
}

/**
* Add env to database
*/
$this->model->add($name, $color);
}

/**
* Delete environment
*/
public function delete(string $name)
public function delete(int $id) : void
{
/**
* Check if environment exists
*/
if ($this->exists($name) === false) {
throw new Exception('Environment <b>' . $name . '</b> does not exist');
if ($this->existsId($id) === false) {
throw new Exception('Environment does not exist');
}

/**
* Delete env from database
*/
$this->model->delete($name);
$this->model->delete($id);
}

/**
* Add / edit the actual environments
*/
public function edit(array $envs)
public function edit(array $envs) : void
{
/**
* Delete all envs from database before inserting the new ones
*/
$this->model->deleteAll();

/**
* Check if all specified envs are valid then add them to $envsToInsert array
*/
foreach ($envs as $env) {
if (!\Controllers\Common::isAlphanumDash($env)) {
throw new Environment('Environment <b>' . $env . '</b> contains invalid characters');
$name = \Controllers\Common::validateData($env['name']);
$color = \Controllers\Common::validateData($env['color']);

if (empty($name)) {
throw new Exception('Environment name is empty');
}

$envsToInsert[] = $env;
}
if (empty($color)) {
throw new Exception('Environment color is empty');
}

/**
* Si l'array contient des environnements valides à insérer alors on traite
*/
if (!empty($envsToInsert)) {
/**
* Delete all envs from database before inserting the new ones
*/
$this->model->deleteAll();

/**
* Insert all environments
*/
foreach ($envsToInsert as $env) {
if (!empty($env)) {
$this->model->new($env);
}
if (!\Controllers\Common::isAlphanumDash($name)) {
throw new Exception('Environment <b>' . $name . '</b> contains invalid characters');
}

if ($this->exists($name)) {
throw new Exception('Environment <b>' . $name . '</b> already exists');
}

$this->model->add($name, $color);
}
}

Expand Down Expand Up @@ -99,10 +152,18 @@ public function total()
return count($this->model->listAll());
}

/**
* Return true if env Id exists
*/
public function existsId(int $id) : bool
{
return $this->model->existsId($id);
}

/**
* Return true if env exists
*/
public function exists(string $name)
public function exists(string $name) : bool
{
return $this->model->exists($name);
}
Expand Down
Loading

0 comments on commit f2e0b1b

Please sign in to comment.