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 9cb4b59 commit c7dec81
Show file tree
Hide file tree
Showing 22 changed files with 644 additions and 215 deletions.
9 changes: 2 additions & 7 deletions www/controllers/Cve/Tools/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -447,12 +447,12 @@ public function importAffectedHosts()
/**
* Open host database
*/
$myhost->openHostDb($host['Id']);
$hostPackageController = new \Controllers\Host\Package($host['Id']);

/**
* Get list of all installed packages on this host
*/
$installedPackages = $myhost->getPackagesInstalled($host['Id']);
$installedPackages = $hostPackageController->getInstalled();
$installedPackagesArray = array();

foreach ($installedPackages as $package) {
Expand All @@ -470,11 +470,6 @@ public function importAffectedHosts()
'Os_family' => $hostOsFamily,
'Installed_packages' => $installedPackagesArray
);

/**
* Close host database
*/
$myhost->closeHostDb();
}

/**
Expand Down
29 changes: 2 additions & 27 deletions www/controllers/Host.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,31 +188,6 @@ public function getHostWithProfile(string $profile)
return $this->model->getHostWithProfile($profile);
}

/**
* Récupère la liste des paquets présents sur l'hôte
*/
public function getPackagesInventory()
{
return $this->model->getPackagesInventory();
}

/**
* Retourne les paquets installés sur l'hôte
*/
public function getPackagesInstalled()
{
return $this->model->getPackagesInstalled();
}

/**
* Retrieve the list of packages available for update on the host
* It is possible to add an offset to the request
*/
public function getPackagesAvailable(bool $withOffset = false, int $offset = 0)
{
return $this->model->getPackagesAvailable($withOffset, $offset);
}

/**
* Retrieve the list of requests sent to the host
* It is possible to add an offset to the request
Expand Down Expand Up @@ -391,11 +366,11 @@ public function getPackageTimeline(string $id, string $packageName)
* 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">';
$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">';
$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>';
Expand Down
40 changes: 40 additions & 0 deletions www/controllers/Host/Package.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Controllers\Host;

use Exception;

class Package
{
private $model;

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

/**
* Retrieve the list of inventoried packages on the host
*/
public function getInventory() : array
{
return $this->model->getInventory();
}

/**
* Retrieve the list of installed packages on the host
*/
public function getInstalled() : array
{
return $this->model->getInstalled();
}

/**
* Retrieve the list of packages available for update on the host
* It is possible to add an offset to the request
*/
public function getAvailable(bool $withOffset = false, int $offset = 0) : array
{
return $this->model->getAvailable($withOffset, $offset);
}
}
22 changes: 6 additions & 16 deletions www/controllers/Layout/Container/vars/host/packages.vars.inc.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
<?php
$myhost = new \Controllers\Host();

$id = __ACTUAL_URI__[2];

/**
* Open host database
*/
$myhost->openHostDb($id);
$hostPackageController = new \Controllers\Host\Package($id);
$myhost = new \Controllers\Host();

/**
* Getting hosts general threshold settings
Expand All @@ -26,17 +21,12 @@
/**
* Getting installed packages and its total
*/
$packagesInventored = $myhost->getPackagesInventory();
$packagesInstalledCount = count($myhost->getPackagesInstalled());
$packagesInventored = $hostPackageController->getInventory();
$packagesInstalledCount = count($hostPackageController->getInstalled());

/**
* Getting available packages and its total
*/
$packagesAvailableTotal = count($myhost->getPackagesAvailable());

/**
* Close host database
*/
$myhost->closeHostDb();
$packagesAvailableTotal = count($hostPackageController->getAvailable());

unset($myhost);
unset($myhost, $hostPackageController);
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,17 @@
* Open the dedicated database of the host from its ID to be able to retrieve additional information
*/
$myhost->openHostDb($host['Id']);
$hostPackageController = new \Controllers\Host\Package($host['Id']);

/**
* Retrieve the total number of available packages
*/
$packagesAvailableTotal = count($myhost->getPackagesAvailable());
$packagesAvailableTotal = count($hostPackageController->getAvailable());

/**
* Retrieve the total number of installed packages
*/
$packagesInstalledTotal = count($myhost->getPackagesInstalled());
$packagesInstalledTotal = count($hostPackageController->getInstalled());

/**
* If the total number of available packages retrieved previously is > $packagesCountConsideredOutdated (threshold defined by the user) then we increment $totalNotUptodate (counts the number of hosts that are not up to date in the chartjs)
Expand Down
20 changes: 20 additions & 0 deletions www/controllers/Layout/Panel/vars/repos/edit.vars.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
if (!IS_ADMIN) {
throw new Exception('You are not allowed to access this panel');
}

$myEditForm = new \Controllers\Repo\Edit\Form();

/**
* Check that action and repos params have been sent
*/
if (empty($item['repos'])) {
throw new Exception('Task repositories required');
}

$slidePanelTitle = 'EDIT REPOSITORY & SNAPSHOT PROPERTIES';

/**
* Get form content
*/
$formContent = $myEditForm->get(json_decode($item['repos'], true));
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
<?php
$myhost = new \Controllers\Host();
$reloadableTableOffset = 0;

$id = __ACTUAL_URI__[2];

/**
* Open host database
*/
$myhost->openHostDb($id);
$hostPackageController = new \Controllers\Host\Package($id);
$reloadableTableOffset = 0;

/**
* Retrieve offset from cookie if exists
Expand All @@ -19,12 +13,12 @@
/**
* Get list of available packages updates, with offset
*/
$reloadableTableContent = $myhost->getPackagesAvailable(true, $reloadableTableOffset);
$reloadableTableContent = $hostPackageController->getAvailable(true, $reloadableTableOffset);

/**
* Get list of ALL available packages updates, without offset, for the total count
*/
$reloadableTableTotalItems = count($myhost->getPackagesAvailable());
$reloadableTableTotalItems = count($hostPackageController->getAvailable());

/**
* Count total pages for the pagination
Expand All @@ -36,9 +30,4 @@
*/
$reloadableTableCurrentPage = ceil($reloadableTableOffset / 10) + 1;

/**
* Close host database
*/
$myhost->closeHostDb();

unset($myhost);
unset($hostPackageController);
Loading

0 comments on commit c7dec81

Please sign in to comment.