Skip to content

Commit

Permalink
4.14.1
Browse files Browse the repository at this point in the history
  • Loading branch information
lbr38 committed Dec 4, 2024
1 parent 0df6a4e commit 2fc1882
Show file tree
Hide file tree
Showing 41 changed files with 1,050 additions and 795 deletions.
5 changes: 0 additions & 5 deletions Todolist
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@
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
6 changes: 3 additions & 3 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ RUN apt-get install findutils iputils-ping git gnupg2 rpm librpmsign9 createrepo
RUN apt-get install postfix -y

# Add nginx and PHP 8.3 repositories
RUN curl -sS https://packages.bespin.ovh/repo/gpgkeys/packages.bespin.ovh.pub | gpg --dearmor > /etc/apt/trusted.gpg.d/packages.bespin.ovh.gpg
RUN echo "deb https://packages.bespin.ovh/repo/repomanager-nginx/bookworm/nginx_prod bookworm nginx" > /etc/apt/sources.list.d/nginx.list
RUN echo "deb https://packages.bespin.ovh/repo/repomanager-php/bookworm/main_prod bookworm main" > /etc/apt/sources.list.d/php.list
RUN curl -sS https://packages.repomanager.net/repo/gpgkeys/packages.repomanager.net.pub | gpg --dearmor > /etc/apt/trusted.gpg.d/packages.repomanager.net.gpg
RUN echo "deb https://packages.repomanager.net/repo/repomanager-nginx/bookworm/nginx_prod bookworm nginx" > /etc/apt/sources.list.d/nginx.list
RUN echo "deb https://packages.repomanager.net/repo/repomanager-php/bookworm/main_prod bookworm main" > /etc/apt/sources.list.d/php.list
RUN apt-get update -y

# Install nginx and PHP 8.3
Expand Down
3 changes: 3 additions & 0 deletions docker/init
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ fi
/bin/su -s /bin/bash -c "/usr/bin/php $WWW_DIR/tools/database/initialize.php" www-data
/bin/su -s /bin/bash -c "/usr/bin/php $WWW_DIR/tools/database/update.php" www-data

# Start shell service in background
/bin/bash "$WWW_DIR/bin/service" &

# Start repomanager service
/bin/su -s /bin/bash -c "/usr/bin/php $WWW_DIR/tools/service.php" www-data

Expand Down
10 changes: 10 additions & 0 deletions www/bin/service
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

# Commands to run every day
while true; do
/usr/bin/apt-get clean all > /dev/null
/usr/bin/apt-get update -y -qq > /dev/null

# Sleep for a day
/usr/bin/sleep 86400
done
4 changes: 4 additions & 0 deletions www/controllers/App/Config/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public static function get()
if (!defined('HOSTS_DB')) {
define('HOSTS_DB', DB_DIR . "/repomanager-hosts.db");
}
// Websocket server database
if (!defined('WS_DB')) {
define('WS_DB', DB_DIR . "/repomanager-ws.db");
}
// GnuPG home
if (!defined('GPGHOME')) {
define('GPGHOME', DATA_DIR . "/.gnupg");
Expand Down
6 changes: 3 additions & 3 deletions www/controllers/FatalErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ class FatalErrorHandler
{
private $taskId;
private $logController;
private $layoutContainerStateController;
private $layoutContainerReloadController;
private $reservedMemory;

public function __construct()
{
$this->logController = new \Controllers\Log\Log();
$this->layoutContainerStateController = new \Controllers\Layout\ContainerState();
$this->layoutContainerReloadController = new \Controllers\Layout\ContainerReload();

/**
* Keep some memory reserved for fatalHandler() to run even in a memory error state
Expand Down Expand Up @@ -62,7 +62,7 @@ public function fatalHandler()
$this->logController->log('error', 'Fatal error occured', $error['message']);
}

$this->layoutContainerStateController->update('header/general-log-messages');
$this->layoutContainerReloadController->reload('header/general-log-messages');

/**
* Exit
Expand Down
222 changes: 27 additions & 195 deletions www/controllers/Host.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Host
{
protected $host_db; // BDD dédiée de l'hôte
private $model;
private $layoutContainerStateController;
private $layoutContainerReloadController;
private $id;
private $idArray = array();
private $ip;
Expand All @@ -35,11 +35,8 @@ class Host

public function __construct()
{
/**
* Ouverture de la base de données 'hosts' (repomanager-hosts.db)
*/
$this->model = new \Models\Host();
$this->layoutContainerStateController = new \Controllers\Layout\ContainerState();
$this->layoutContainerReloadController = new \Controllers\Layout\ContainerReload();
}

public function setId(string $id)
Expand Down Expand Up @@ -1136,6 +1133,8 @@ public function unregister()
*/
public function hostExec(array $hostsId, string $action)
{
$hostRequestController = new \Controllers\Host\Request();

/**
* Only admins should be able to perform actions
*/
Expand All @@ -1152,16 +1151,16 @@ public function hostExec(array $hostsId, string $action)
throw new Exception('Action to execute is invalid');
}

$hostUpdateError = array();
$hostUpdateOK = array();
$hostResetError = array();
$hostResetOK = array();
$hostDeleteError = array();
$hostDeleteOK = array();
$hostGeneralUpdateError = array();
$hostGeneralUpdateOK = array();
$hostPackagesStatusUpdateError = array();
$hostPackagesStatusUpdateOK = array();
$hostUpdateError = array();
$hostUpdateOK = array();
$hostResetError = array();
$hostResetOK = array();
$hostDeleteError = array();
$hostDeleteOK = array();
$hostGeneralUpdateError = array();
$hostGeneralUpdateOK = array();
$hostPackagesStatusUpdateError = array();
$hostPackagesStatusUpdateOK = array();

/**
* First check that hosts Id are valid
Expand Down Expand Up @@ -1225,7 +1224,7 @@ public function hostExec(array $hostsId, string $action)
/**
* Add a new ws request to disconnect the host
*/
$this->newWsRequest($hostId, 'disconnect');
$hostRequestController->new($hostId, 'disconnect');
}

/**
Expand All @@ -1235,7 +1234,7 @@ public function hostExec(array $hostsId, string $action)
/**
* Add a new websocket request in the database
*/
$this->newWsRequest($hostId, 'request-general-infos');
$hostRequestController->new($hostId, 'request-general-infos');
}

/**
Expand All @@ -1245,7 +1244,7 @@ public function hostExec(array $hostsId, string $action)
/**
* Add a new websocket request in the database
*/
$this->newWsRequest($hostId, 'request-packages-infos');
$hostRequestController->new($hostId, 'request-packages-infos');
}

/**
Expand All @@ -1268,32 +1267,32 @@ public function hostExec(array $hostsId, string $action)
*/
if ($action == 'reset') {
$message = 'Following hosts have been reseted:';
$this->layoutContainerStateController->update('hosts/overview');
$this->layoutContainerStateController->update('hosts/list');
$this->layoutContainerStateController->update('host/summary');
$this->layoutContainerStateController->update('host/packages');
$this->layoutContainerStateController->update('host/history');
$this->layoutContainerReloadController->reload('hosts/overview');
$this->layoutContainerReloadController->reload('hosts/list');
$this->layoutContainerReloadController->reload('host/summary');
$this->layoutContainerReloadController->reload('host/packages');
$this->layoutContainerReloadController->reload('host/history');
}

if ($action == 'delete') {
$message = 'Following hosts have been deleted:';
$this->layoutContainerStateController->update('hosts/overview');
$this->layoutContainerStateController->update('hosts/list');
$this->layoutContainerReloadController->reload('hosts/overview');
$this->layoutContainerReloadController->reload('hosts/list');
}

if ($action == 'request-all-packages-update') {
$message = 'Requesting packages update to the following hosts:';
$this->layoutContainerStateController->update('host/requests');
$this->layoutContainerReloadController->reload('host/requests');
}

if ($action == 'request-general-infos') {
$message = 'Requesting general informations to the following hosts:';
$this->layoutContainerStateController->update('host/requests');
$this->layoutContainerReloadController->reload('host/requests');
}

if ($action == 'request-packages-infos') {
$message = 'Requesting packages informations to the following hosts:';
$this->layoutContainerStateController->update('host/requests');
$this->layoutContainerReloadController->reload('host/requests');
}

$message .= '<div class="grid grid-2 column-gap-10 row-gap-10 margin-top-5">';
Expand Down Expand Up @@ -1504,171 +1503,4 @@ public function addHostsIdToGroup(array $hostsId = null, int $groupId)
}
}
}

/**
* Clean websocket connections from database
*/
public function cleanWsConnections()
{
$this->model->cleanWsConnections();
}

/**
* Return all websocket connections from database
* If a status is specified, only requests with this status will be returned, otherwise all requests will be returned
*/
public function getWsConnections(string|null $status = null)
{
return $this->model->getWsConnections($status);
}

/**
* Add new websocket connection in database
*/
public function newWsConnection(int $connectionId)
{
$this->model->newWsConnection($connectionId);
}

/**
* Delete websocket connection from database
*/
public function deleteWsConnection(int $connectionId)
{
$this->model->deleteWsConnection($connectionId);
}

/**
* Update websocket connection in database
*/
public function updateWsConnection(int $connectionId, int $hostId, string $authenticated)
{
$this->model->updateWsConnection($connectionId, $hostId, $authenticated);
}

/**
* Add new websocket request in database
*/
public function newWsRequest(int $hostId, string $request, array $requestData = [])
{
/**
* Define the request name
*/
$json['request'] = $request;

/**
* If additional json data is provided, we add it to the request
*/
if (!empty($requestData)) {
$json['data'] = $requestData;
}

$this->model->newWsRequest($hostId, json_encode($json));
}

/**
* Return all websocket requests from database
* If a status is specified, only requests with this status will be returned, otherwise all requests will be returned
*/
public function getWsRequests(string|null $status = null)
{
return $this->model->getWsRequests($status);
}

/**
* Update websocket request in database
*/
public function updateWsRequest(int $id, string $status, string $info, string $responseJson)
{
$this->model->updateWsRequest($id, $status, $info, $responseJson);
}

/**
* Update websocket request status in database
*/
public function updateWsRequestStatus(int $id, string $status)
{
$this->model->updateWsRequestStatus($id, $status);
}

/**
* Update websocket request info message in database
*/
public function updateWsRequestInfo(int $id, string $info)
{
$this->model->updateWsRequestInfo($id, $info);
}

/**
* Update websocket request retry in database
*/
public function updateWsRequestRetry(int $id, int $retry)
{
$this->model->updateWsRequestRetry($id, $retry);
}

/**
* Update websocket request next retry time in database
*/
public function updateWsRequestNextRetry(int $id, string $nextRetry)
{
$this->model->updateWsRequestNextRetry($id, $nextRetry);
}

/**
* Return websocket connection Id by host Id
*/
public function getWsConnectionIdByHostId(int $hostId)
{
return $this->model->getWsConnectionIdByHostId($hostId);
}

/**
* Cancel websocket request in database
*/
public function cancelWsRequest(int $id)
{
$this->model->cancelWsRequest($id);
}

/**
* Delete websocket request from database
*/
public function deleteWsRequest(int $id)
{
$this->model->deleteWsRequest($id);
}

/**
* Get request log details
* Request log is a file stored in the websocket-requests logs directory
*/
public function getRequestLog(int $id) : string
{
$logFile = WS_REQUESTS_LOGS_DIR . '/request-' . $id . '.log';

if (!file_exists($logFile)) {
throw new Exception('Log file does not exist');
}

if (!is_readable($logFile)) {
throw new Exception('Log file is not readable');
}

$content = file_get_contents($logFile);

if ($content === false) {
throw new Exception('Error while reading log file');
}

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);
}
}
Loading

0 comments on commit 2fc1882

Please sign in to comment.