Skip to content

Commit c020bd8

Browse files
authored
Merge pull request #225 from lbr38/devel
4.16.0
2 parents b4f3440 + e8a3c4e commit c020bd8

File tree

46 files changed

+1306
-770
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1306
-770
lines changed

Todolist

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
[ REPOS ]
77

88
- 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
9-
- (Feature) Add a way to edit repository properties like its source repository
109
- (Feature) Support Arch Linux packages
1110
https://blog.desdelinux.net/en/create-your-local-arch-linux-repository/
1211
https://wiki.archlinux.org/title/Pacman#Repositories_and_mirrors

docker/config/nginx/repomanager.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ server {
102102

103103
location ~ \.(?:css|js|woff2?|svg|gif|map)$ {
104104
try_files $uri $uri/ =404;
105-
add_header Cache-Control "public, max-age=15778463";
105+
add_header Cache-Control "public, max-age=3600";
106106
add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;" always;
107107
add_header Referrer-Policy "no-referrer" always;
108108
add_header X-Content-Type-Options "nosniff" always;

www/controllers/Api/Host/Host.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function execute()
9999
* https://repomanager.mydomain.net/api/v2/host/registering
100100
*/
101101
if ($this->component == 'registering' and $this->method == 'DELETE') {
102-
$myhost->unregister();
102+
$myhost->delete($myhost->getId());
103103
return array('message' => array('Host has been deleted.'));
104104
}
105105

www/controllers/Cve/Tools/Import.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -447,12 +447,12 @@ public function importAffectedHosts()
447447
/**
448448
* Open host database
449449
*/
450-
$myhost->openHostDb($host['Id']);
450+
$hostPackageController = new \Controllers\Host\Package\Package($host['Id']);
451451

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

458458
foreach ($installedPackages as $package) {
@@ -470,11 +470,6 @@ public function importAffectedHosts()
470470
'Os_family' => $hostOsFamily,
471471
'Installed_packages' => $installedPackagesArray
472472
);
473-
474-
/**
475-
* Close host database
476-
*/
477-
$myhost->closeHostDb();
478473
}
479474

480475
/**

www/controllers/Host.php

Lines changed: 26 additions & 237 deletions
Original file line numberDiff line numberDiff line change
@@ -188,31 +188,6 @@ public function getHostWithProfile(string $profile)
188188
return $this->model->getHostWithProfile($profile);
189189
}
190190

191-
/**
192-
* Récupère la liste des paquets présents sur l'hôte
193-
*/
194-
public function getPackagesInventory()
195-
{
196-
return $this->model->getPackagesInventory();
197-
}
198-
199-
/**
200-
* Retourne les paquets installés sur l'hôte
201-
*/
202-
public function getPackagesInstalled()
203-
{
204-
return $this->model->getPackagesInstalled();
205-
}
206-
207-
/**
208-
* Retrieve the list of packages available for update on the host
209-
* It is possible to add an offset to the request
210-
*/
211-
public function getPackagesAvailable(bool $withOffset = false, int $offset = 0)
212-
{
213-
return $this->model->getPackagesAvailable($withOffset, $offset);
214-
}
215-
216191
/**
217192
* Retrieve the list of requests sent to the host
218193
* It is possible to add an offset to the request
@@ -230,15 +205,6 @@ public function getLastPendingRequest(int $id)
230205
return $this->model->getLastPendingRequest($id);
231206
}
232207

233-
/**
234-
* Retrieve information about all actions performed on host packages (install, update, remove...)
235-
* It is possible to add an offset to the request
236-
*/
237-
public function getEventsHistory(bool $withOffset = false, int $offset = 0)
238-
{
239-
return $this->model->getEventsHistory($withOffset, $offset);
240-
}
241-
242208
/**
243209
* 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)
244210
* Les informations sont récupérées à la fois dans la table packages et dans packages_history
@@ -248,189 +214,6 @@ public function getEventPackagesList(string $eventId, string $packageState)
248214
return $this->model->getEventPackagesList($eventId, $packageState);
249215
}
250216

251-
/**
252-
* Récupère le détails d'un évènement sur un type de paquets en particulier (installés, mis à jour, etc...)
253-
* Cette fonction est notamment déclenchée au passage de la souris sur une ligne de l'historique des évènements
254-
*/
255-
public function getEventDetails(string $id, string $eventId, string $packageState)
256-
{
257-
/**
258-
* Si il manque l'id de l'hôte, on quitte car on en a besoin pour ouvrir sa BDD dédiée
259-
*/
260-
if (empty($id)) {
261-
throw new Exception('Host Id must be specified');
262-
}
263-
264-
$packageState = \Controllers\Common::validateData($packageState);
265-
266-
/**
267-
* Ouverture de la BDD dédiée de l'hôte
268-
*/
269-
$this->model->openHostDb($id);
270-
271-
$packages = $this->model->getEventDetails($eventId, $packageState);
272-
273-
if ($packageState == 'installed') {
274-
$content = '<p><b>Installed:</b></p>';
275-
}
276-
if ($packageState == 'dep-installed') {
277-
$content = '<p><b>Installed dependencies:</b></p>';
278-
}
279-
if ($packageState == 'upgraded') {
280-
$content = '<p><b>Updated:</b></p>';
281-
}
282-
if ($packageState == 'removed') {
283-
$content = '<p><b>Uninstalled:</b></p>';
284-
}
285-
if ($packageState == 'downgraded') {
286-
$content = '<p><b>Downgraded:</b></p>';
287-
}
288-
289-
$content .= '<div class="grid grid-2 column-gap-10 row-gap-6 justify-space-between">';
290-
291-
foreach ($packages as $package) {
292-
$content .= '<div class="flex align-item-center column-gap-5 min-width-200">';
293-
$content .= \Controllers\Common::printProductIcon($package['Name']);
294-
$content .= '<span class="copy">' . $package['Name'] . '</span>';
295-
$content .= '</div>';
296-
$content .= '<span class="copy">' . $package['Version'] . '</span>';
297-
}
298-
299-
$content .= '</div>';
300-
301-
return $content;
302-
}
303-
304-
/**
305-
* Retrieve the complete history of a package (its installation, its updates, etc...)
306-
*/
307-
public function getPackageTimeline(string $id, string $packageName)
308-
{
309-
/**
310-
* If the host id is missing, we quit because we need it to open its dedicated DB
311-
*/
312-
if (empty($id)) {
313-
throw new Exception('Host Id must be specified');
314-
}
315-
316-
/**
317-
* Open the dedicated DB of the host
318-
*/
319-
$this->model->openHostDb($id);
320-
321-
$events = $this->model->getPackageTimeline($packageName);
322-
323-
/**
324-
* 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
325-
*/
326-
$content = '<div class="timeline">';
327-
328-
/**
329-
* The first block will be displayed on the left in the timeline
330-
*/
331-
$contentPosition = 'left';
332-
333-
foreach ($events as $event) {
334-
/**
335-
* Add the date, time and state of the package
336-
*/
337-
if ($event['State'] == "inventored") {
338-
$contentIcon = 'package';
339-
$contentText = 'Inventored';
340-
}
341-
if ($event['State'] == "installed") {
342-
$contentIcon = 'down';
343-
$contentText = 'Installed';
344-
}
345-
if ($event['State'] == "dep-installed") {
346-
$contentIcon = 'down';
347-
$contentText = 'Installed (as depencency)';
348-
}
349-
if ($event['State'] == "upgraded") {
350-
$contentIcon = 'update';
351-
$contentText = 'Updated';
352-
}
353-
if ($event['State'] == "removed") {
354-
$contentIcon = 'delete';
355-
$contentText = 'Uninstalled';
356-
}
357-
if ($event['State'] == "downgraded") {
358-
$contentIcon = 'arrow-back';
359-
$contentText = 'Downgraded';
360-
}
361-
if ($event['State'] == "reinstalled") {
362-
$contentIcon = 'down';
363-
$contentText = 'Reinstalled';
364-
}
365-
if ($event['State'] == "purged") {
366-
$contentIcon = 'delete';
367-
$contentText = 'Uninstalled (purged)';
368-
}
369-
370-
/**
371-
* Position of the container block in the timeline according to the last displayed
372-
*/
373-
$content .= '<div class="timeline-container timeline-container-' . $contentPosition . '">';
374-
375-
/**
376-
* Display the date, time and state of the package
377-
*/
378-
$content .= '<div class="table-container">';
379-
$content .= '<img src="/assets/icons/' . $contentIcon . '.svg" class="icon" />';
380-
$content .= '<div class="flex flex-direction-column">';
381-
$content .= '<p>' . DateTime::createFromFormat('Y-m-d', $event['Date'])->format('d-m-Y') . '</p>';
382-
$content .= '<p class="lowopacity-cst">' . $event['Time'] . '</p>';
383-
$content .= '</div>';
384-
$content .= '<div class="flex flex-direction-column">';
385-
$content .= '<p>' . $contentText . '</p>';
386-
$content .= '<p class="lowopacity-cst copy">Version: ' . $event['Version'] . '</p>';
387-
$content .= '</div>';
388-
$content .= '</div>';
389-
390-
/**
391-
* If this event is the result of an update, install or uninstall event, then we indicate the Id of the event
392-
*/
393-
// if (!empty($event['Id_event'])) {
394-
// $content .= '<a href="#' . $event['Id_event'] . '" >';
395-
// }
396-
397-
/**
398-
* If the previous block was on the left, we display the next one on the right and vice versa
399-
*/
400-
if ($contentPosition == "left") {
401-
$contentPosition = 'right';
402-
} elseif ($contentPosition == "right") {
403-
$contentPosition = 'left';
404-
}
405-
406-
$content .= '</div>';
407-
}
408-
409-
/**
410-
* Close the timeline
411-
*/
412-
$content .= '</div>';
413-
414-
return $content;
415-
}
416-
417-
/**
418-
* Compte le nombre de paquets installés, mis à jour, désinstallés... au cours des X derniers jours.
419-
* Retourne un array contenant les dates => nombre de paquet
420-
* Fonction utilisées notamment pour la création du graphique ChrtJS de type 'line' sur la page d'un hôte
421-
*/
422-
public function getLastPackagesStatusCount(string $status, string $days)
423-
{
424-
if ($status != 'installed' and $status != 'upgraded' and $status != 'removed') {
425-
throw new Exception("Invalid status");
426-
}
427-
428-
$dateEnd = date('Y-m-d');
429-
$dateStart = date_create($dateEnd)->modify("-${days} days")->format('Y-m-d');
430-
431-
return $this->model->getLastPackagesStatusCount($status, $dateStart, $dateEnd);
432-
}
433-
434217
/**
435218
* Edit the display settings on the hosts page
436219
*/
@@ -998,9 +781,9 @@ public function register()
998781
/**
999782
* Lorsque appelé par l'api, HOSTS_DIR n'est pas setté, donc on le fait
1000783
*/
1001-
if (!defined('HOSTS_DIR')) {
1002-
define('HOSTS_DIR', ROOT . '/hosts');
1003-
}
784+
// if (!defined('HOSTS_DIR')) {
785+
// define('HOSTS_DIR', DATA_DIR . '/hosts');
786+
// }
1004787

1005788
/**
1006789
* Si on n'a pas renseigné l'IP ou le hostname alors on quitte
@@ -1083,9 +866,9 @@ public function register()
1083866
*/
1084867
} else {
1085868
/**
1086-
* Ajout de l'hôte en base de données
869+
* Add the host in database
1087870
*/
1088-
$this->model->addHost($this->ip, $this->hostname, $this->authId, $this->token, $this->onlineStatus, date('Y-m-d'), date('H:i:s'));
871+
$this->model->add($this->ip, $this->hostname, $this->authId, $this->token, $this->onlineStatus, date('Y-m-d'), date('H:i:s'));
1089872

1090873
/**
1091874
* Récupération de l'Id de l'hôte ajouté en BDD
@@ -1118,14 +901,30 @@ public function register()
1118901
}
1119902

1120903
/**
1121-
* Suppression d'un hôte depuis l'api
904+
* Delete a host from the database
1122905
*/
1123-
public function unregister()
906+
public function delete(int $id)
1124907
{
908+
$hostRequestController = new \Controllers\Host\Request();
909+
1125910
/**
1126-
* Changement du status de l'hôte en base de données ('deleted')
911+
* Delete host from database
1127912
*/
1128-
$this->model->setHostInactive($this->id);
913+
$this->model->delete($id);
914+
915+
/**
916+
* Add a new ws request to disconnect the host
917+
*/
918+
$hostRequestController->new($id, 'disconnect');
919+
920+
/**
921+
* Delete host's dedicated database
922+
*/
923+
if (is_dir(HOSTS_DIR . '/' . $id)) {
924+
\Controllers\Filesystem\Directory::deleteRecursive(HOSTS_DIR . '/' . $id);
925+
}
926+
927+
unset($hostRequestController);
1129928
}
1130929

1131930
/**
@@ -1211,20 +1010,10 @@ public function hostExec(array $hostsId, string $action)
12111010
* Case where the requested action is a delete
12121011
*/
12131012
if ($action == 'delete') {
1214-
/**
1215-
* First, reset host data in database
1216-
*/
1217-
$this->model->resetHost($hostId);
1218-
12191013
/**
12201014
* Set host status to 'deleted' in database
12211015
*/
1222-
$this->model->setHostInactive($hostId);
1223-
1224-
/**
1225-
* Add a new ws request to disconnect the host
1226-
*/
1227-
$hostRequestController->new($hostId, 'disconnect');
1016+
$this->delete($hostId);
12281017
}
12291018

12301019
/**

0 commit comments

Comments
 (0)