Skip to content

Commit

Permalink
patch
Browse files Browse the repository at this point in the history
  • Loading branch information
lbr38 committed Jan 12, 2025
1 parent c0663c1 commit 06452be
Show file tree
Hide file tree
Showing 21 changed files with 416 additions and 435 deletions.
2 changes: 1 addition & 1 deletion Todolist
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[ IN PROGRESS ]
- (Feature) Add a way to edit repository properties like its source repository


[ IMPROVEMENTS / FEATURES ]

[ 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
- (Feature) Add a way to edit repository properties like its source repository
- (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
Expand Down
2 changes: 1 addition & 1 deletion www/controllers/Cve/Tools/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ public function importAffectedHosts()
/**
* Open host database
*/
$hostPackageController = new \Controllers\Host\Package($host['Id']);
$hostPackageController = new \Controllers\Host\Package\Package($host['Id']);

/**
* Get list of all installed packages on this host
Expand Down
202 changes: 0 additions & 202 deletions www/controllers/Host.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,6 @@ public function getLastPendingRequest(int $id)
return $this->model->getLastPendingRequest($id);
}

/**
* Retrieve information about all actions performed on host packages (install, update, remove...)
* It is possible to add an offset to the request
*/
public function getEventsHistory(bool $withOffset = false, int $offset = 0)
{
return $this->model->getEventsHistory($withOffset, $offset);
}

/**
* Récupère la liste des paquets issus d'un évènemnt et dont l'état des paquets est défini par $packageState (installed, upgraded, removed)
* Les informations sont récupérées à la fois dans la table packages et dans packages_history
Expand All @@ -223,199 +214,6 @@ public function getEventPackagesList(string $eventId, string $packageState)
return $this->model->getEventPackagesList($eventId, $packageState);
}

/**
* Récupère le détails d'un évènement sur un type de paquets en particulier (installés, mis à jour, etc...)
* Cette fonction est notamment déclenchée au passage de la souris sur une ligne de l'historique des évènements
*/
public function getEventDetails(string $id, string $eventId, string $packageState)
{
/**
* Si il manque l'id de l'hôte, on quitte car on en a besoin pour ouvrir sa BDD dédiée
*/
if (empty($id)) {
throw new Exception('Host Id must be specified');
}

$packageState = \Controllers\Common::validateData($packageState);

/**
* Ouverture de la BDD dédiée de l'hôte
*/
$this->model->openHostDb($id);

$packages = $this->model->getEventDetails($eventId, $packageState);

if ($packageState == 'installed') {
$title = 'INSTALLED';
$icon = 'check.svg';
}
if ($packageState == 'reinstalled') {
$title = 'REINSTALLED';
$icon = 'check.svg';
}
if ($packageState == 'dep-installed') {
$title = 'DEPENDENCIES INSTALLED';
$icon = 'check.svg';
}
if ($packageState == 'upgraded') {
$title = 'UPDATED';
$icon = 'update-yellow.svg';
}
if ($packageState == 'removed') {
$title = 'UNINSTALLED';
$icon = 'error.svg';
}
if ($packageState == 'purged') {
$title = 'PURGED';
$icon = 'error.svg';
}
if ($packageState == 'downgraded') {
$title = 'DOWNGRADED';
$icon = 'rollback.svg';
}

$content = '<div class="flex item-align-center column-gap-5"><img src="/assets/icons/' . $icon . '" class="icon-np" /><h6 class="margin-top-0">' . $title . '</h6></div>';
$content .= '<p class="note margin-bottom-15">' . count($packages) . ' package(s)</p>';
$content .= '<div class="grid grid-2 column-gap-10 row-gap-6 justify-space-between">';

foreach ($packages as $package) {
$content .= '<div class="flex align-item-center column-gap-5 min-width-200">';
$content .= \Controllers\Common::printProductIcon($package['Name']);
$content .= '<span class="copy">' . $package['Name'] . '</span>';
$content .= '</div>';
$content .= '<span class="copy">' . $package['Version'] . '</span>';
}

$content .= '</div>';

return $content;
}

/**
* Retrieve the complete history of a package (its installation, its updates, etc...)
*/
public function getPackageTimeline(string $id, string $packageName)
{
/**
* If the host id is missing, we quit because we need it to open its dedicated DB
*/
if (empty($id)) {
throw new Exception('Host Id must be specified');
}

/**
* Open the dedicated DB of the host
*/
$this->model->openHostDb($id);

$events = $this->model->getPackageTimeline($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 = '<div class="timeline">';

/**
* The first block will be displayed on the left in the timeline
*/
$contentPosition = 'left';

foreach ($events as $event) {
/**
* Add the date, time and state of the package
*/
if ($event['State'] == "inventored") {
$contentIcon = 'package';
$contentText = 'INVENTORED';
}
if ($event['State'] == "installed") {
$contentIcon = 'check';
$contentText = 'INSTALLED';
}
if ($event['State'] == "dep-installed") {
$contentIcon = 'check';
$contentText = 'INSTALLED (as depencency)';
}
if ($event['State'] == "reinstalled") {
$contentIcon = 'check';
$contentText = 'REINSTALLED';
}
if ($event['State'] == "upgraded") {
$contentIcon = 'update-yellow';
$contentText = 'UPDATED';
}
if ($event['State'] == "removed") {
$contentIcon = 'error';
$contentText = 'UNINSTALLED';
}
if ($event['State'] == "purged") {
$contentIcon = 'error';
$contentText = 'UNINSTALLED (purged)';
}
if ($event['State'] == "downgraded") {
$contentIcon = 'rollback';
$contentText = 'DOWNGRADED';
}

/**
* Position of the container block in the timeline according to the last displayed
*/
$content .= '<div class="timeline-container timeline-container-' . $contentPosition . '">';

/**
* Display the date, time and state of the package
*/
$content .= '<div class="div-generic-blue flex align-item-center column-gap-30">';
$content .= '<div class="flex flex-direction-column row-gap-2">';
$content .= '<p>' . DateTime::createFromFormat('Y-m-d', $event['Date'])->format('d-m-Y') . '</p>';
$content .= '<p class="lowopacity-cst">' . $event['Time'] . '</p>';
$content .= '</div>';
$content .= '<div class="flex flex-direction-column row-gap-2">';
$content .= '<div class="flex align-item-center column-gap-5">';
$content .= '<img src="/assets/icons/' . $contentIcon . '.svg" class="icon" />';
$content .= '<h6 class="margin-top-0">' . $contentText . '</h6>';
$content .= '</div>';
$content .= '<p class="lowopacity-cst copy">' . $event['Version'] . '</p>';
$content .= '</div>';
$content .= '</div>';

/**
* If the previous block was on the left, we display the next one on the right and vice versa
*/
if ($contentPosition == "left") {
$contentPosition = 'right';
} elseif ($contentPosition == "right") {
$contentPosition = 'left';
}

$content .= '</div>';
}

/**
* Close the timeline
*/
$content .= '</div>';

return $content;
}

/**
* Compte le nombre de paquets installés, mis à jour, désinstallés... au cours des X derniers jours.
* Retourne un array contenant les dates => nombre de paquet
* Fonction utilisées notamment pour la création du graphique ChrtJS de type 'line' sur la page d'un hôte
*/
public function getLastPackagesStatusCount(string $status, string $days)
{
if ($status != 'installed' and $status != 'upgraded' and $status != 'removed') {
throw new Exception("Invalid status");
}

$dateEnd = date('Y-m-d');
$dateStart = date_create($dateEnd)->modify("-${days} days")->format('Y-m-d');

return $this->model->getLastPackagesStatusCount($status, $dateStart, $dateEnd);
}

/**
* Edit the display settings on the hosts page
*/
Expand Down
40 changes: 0 additions & 40 deletions www/controllers/Host/Package.php

This file was deleted.

75 changes: 75 additions & 0 deletions www/controllers/Host/Package/Event.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

namespace Controllers\Host\Package;

use Exception;

class Event
{
private $hostId;
private $model;

public function __construct(int $hostId)
{
$this->hostId = $hostId;
$this->model = new \Models\Host\Package\Event($hostId);
}

/**
* Retrieves the details of an event for a specific type of packages (installed, updated, etc...)
* This function is triggered when hovering over a line in the event history
*/
public function getDetails(string $eventId, string $packageState) : string
{
$packageState = \Controllers\Common::validateData($packageState);

/**
* Retrieve the details of the event
*/
$packages = $this->model->getDetails($eventId, $packageState);

if ($packageState == 'installed') {
$title = 'INSTALLED';
$icon = 'check.svg';
}
if ($packageState == 'reinstalled') {
$title = 'REINSTALLED';
$icon = 'check.svg';
}
if ($packageState == 'dep-installed') {
$title = 'DEPENDENCIES INSTALLED';
$icon = 'check.svg';
}
if ($packageState == 'upgraded') {
$title = 'UPDATED';
$icon = 'update-yellow.svg';
}
if ($packageState == 'removed') {
$title = 'UNINSTALLED';
$icon = 'error.svg';
}
if ($packageState == 'purged') {
$title = 'PURGED';
$icon = 'error.svg';
}
if ($packageState == 'downgraded') {
$title = 'DOWNGRADED';
$icon = 'rollback.svg';
}

ob_start();

include_once(ROOT . '/views/includes/host/package/event-details.inc.php');

return ob_get_clean();
}

/**
* Retrieve informations about all actions performed on host packages (install, update, remove...)
* It is possible to add an offset to the request
*/
public function getHistory(bool $withOffset = false, int $offset = 0) : array
{
return $this->model->getHistory($withOffset, $offset);
}
}
Loading

0 comments on commit 06452be

Please sign in to comment.