Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Approach
- Read existing files before writing. Don't re-read unless changed.
- Thorough in reasoning, concise in output.
- Skip files over 100KB unless required.
- No sycophantic openers or closing fluff.
- No emojis or em-dashes.
- Do not guess APIs, versions, flags, commit SHAs, or package names. Verify by reading code or docs before asserting.
44 changes: 0 additions & 44 deletions www/controllers/Layout/Chart/vars/repo-storage-chart.vars.inc.php

This file was deleted.

62 changes: 48 additions & 14 deletions www/controllers/Layout/Container/vars/hosts/overview.vars.inc.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,61 @@
<?php
use \Controllers\Host\Package\Package;

$hostController = new \Controllers\Host\Host();
$hostListingController = new \Controllers\Host\Listing();
$totalOutdated = 0;
$totalUptodate = 0;
$compliancePercent = 0;

// Getting hosts list
$hosts = $hostListingController->get();

/**
* Getting total hosts
*/
$totalHosts = count($hostListingController->get());
// Getting total hosts
$totalHosts = count($hosts);

/**
* Getting a list of all hosts kernel
*/
// Getting a list of all host kernels and sort them by count desc
$kernels = $hostListingController->getKernel();
array_multisort(array_column($kernels, 'Count'), SORT_DESC, $kernels);

/**
* Getting a list of all hosts profiles
*/
// Getting a list of all host profiles and sort them by count desc
$profiles = $hostListingController->getProfile();
array_multisort(array_column($profiles, 'Count'), SORT_DESC, $profiles);

/**
* Getting a list of all hosts requiring a reboot
*/
// Getting a list of all hosts requiring a reboot
$rebootRequiredList = $hostListingController->getRebootRequired();
$rebootRequiredCount = count($rebootRequiredList);

unset($hostListingController);
// Getting general hosts threshold settings
$hostsSettings = $hostController->getSettings();

// Threshold of the maximum number of available update above which the host is considered as 'not up to date' (but not critical)
$packagesCountConsideredOutdated = $hostsSettings['pkgs_count_considered_outdated'];

// Loop through the list of hosts to determine the number of hosts up to date and not up to date
foreach ($hosts as $host) {
// Open the dedicated database of the host from its ID to be able to retrieve additional information
$hostPackageController = new Package($host['Id']);

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

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

/**
* If the total number of available packages retrieved previously is > $packagesCountConsideredOutdated (threshold defined by the user) then we increment $totalOutdated (counts the number of hosts that are not up to date in the chartjs)
* Else it's $totalUptodate that we increment.
*/
if ($packagesAvailableTotal >= $packagesCountConsideredOutdated) {
$totalOutdated++;
} else {
$totalUptodate++;
}
}

// Calculation of the compliance percent (number of hosts up to date / total number of hosts * 100)
if ($totalHosts > 0) {
$compliancePercent = round(($totalUptodate / $totalHosts) * 100);
}

unset($hostController, $hostListingController, $hostPackageController, $hosts, $hostsSettings, $packagesCountConsideredOutdated, $packagesAvailableTotal, $packagesInstalledTotal);
61 changes: 59 additions & 2 deletions www/controllers/Layout/Container/vars/repos/list.vars.inc.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
use \Controllers\Utils\Convert;

$repoSnapshotController = new \Controllers\Repo\Snapshot\Snapshot();
$groupController = new \Controllers\Group\Repo();
$repoController = new \Controllers\Repo\Repo();
Expand All @@ -15,8 +17,8 @@
$diskTotalSpace = disk_total_space(REPOS_DIR);
$diskFreeSpace = disk_free_space(REPOS_DIR);
$diskUsedSpace = $diskTotalSpace - $diskFreeSpace;
$diskFreeSpaceHuman = \Controllers\Utils\Convert::sizeToHuman($diskFreeSpace);
$diskUsedSpaceHuman = \Controllers\Utils\Convert::sizeToHuman($diskUsedSpace);
$diskFreeSpaceHuman = Convert::sizeToHuman($diskFreeSpace);
$diskUsedSpaceHuman = Convert::sizeToHuman($diskUsedSpace);
$diskUsedSpacePercent = round(($diskUsedSpace / $diskTotalSpace) * 100);
$diskFreeSpacePercent = round(($diskFreeSpace / $diskTotalSpace) * 100);

Expand All @@ -40,4 +42,59 @@
$nextScheduledTasks = array_unique($nextScheduledTasks, SORT_REGULAR);
}


$groups = [];
$repos = [];
$snapshots = [];

foreach ($groupsList as $group) {
$show = true;
$previousId = null;

/**
* Permissions
* If the user is not an admin, check if the group is in the user permissions
*/
if (!IS_ADMIN) {
// If 'all' is not in the user permissions, then it means the user has specific permissions and cannot view all groups
if (!in_array('all', USER_PERMISSIONS['repositories']['view'])) {
// Check if the current group Id is in the user permissions, if not then skip to the next group
if (!in_array($group['Id'], USER_PERMISSIONS['repositories']['view']['groups'])) {
$show = false;
}
}
}

if (!isset($groups[$group['Id']])) {
$groups[$group['Id']] = [
'name' => $group['Name'],
'repos' => [],
'count' => 0,
'show' => $show
];
}

foreach ($myrepoListing->listByGroup($group['Name']) as $repo) {
// Add the whole repo to the repos array
$repos[] = $repo;

// Add the repoId to the group if not already in the group repos (to avoid duplicate repos in the same group)
if (!in_array($repo['repoId'], $groups[$group['Id']]['repos'])) {
$groups[$group['Id']]['repos'][] = $repo['repoId'];
}

// Add 1 to the group count only if the repoId is different from the previous one
if ($previousId != $repo['repoId']) {
$groups[$group['Id']]['count']++;
}

// TODO: If the repository is in the user permissions, then the group become showable for the user

$previousId = $repo['repoId'];
}



}

unset($groupController, $repoController, $taskController, $diskTotalSpace, $diskFreeSpace, $diskUsedSpace, $data);
13 changes: 13 additions & 0 deletions www/controllers/Layout/Container/vars/tasks/tasks.vars.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
$taskListingController = new \Controllers\Task\Listing();

// Get all tasks and count them
$totalCount = count($taskListingController->get());

// Get running tasks
$runningCount = count($taskListingController->getRunning());

// Get scheduled tasks
$scheduledCount = count($taskListingController->getScheduled());

unset($taskListingController);
2 changes: 1 addition & 1 deletion www/controllers/Layout/Panel/vars/repos/edit.vars.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* Check that action and repos params have been sent
*/
if (empty($item['repos'])) {
throw new Exception('Task repositories required');
throw new Exception('Repositories required');
}

$slidePanelTitle = 'EDIT REPOSITORY & SNAPSHOT PROPERTIES';
Expand Down
48 changes: 20 additions & 28 deletions www/controllers/Layout/Panel/vars/repos/install.vars.inc.php
Original file line number Diff line number Diff line change
@@ -1,58 +1,47 @@
<?php
$environmentController = new \Controllers\Environment();
use Controllers\Repo\Repo;
use Controllers\Environment;

/**
* Check that action and repos params have been sent
*/
$environmentController = new Environment();

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

/**
* Retrieve the repositories
*/
// Retrieve the repositories
try {
$repos = json_decode($item['repos'], true, 512, JSON_THROW_ON_ERROR);
} catch (Exception $e) {
throw new Exception('Could not decode the repositories');
}

/**
* Prepare the commands output
*/
// Prepare the commands output
ob_start();

foreach ($repos as $repo) {
$repoController = new \Controllers\Repo\Repo();
$repoController = new Repo();

/**
* Check that the Ids are numeric
*/
// Check that the Ids are numeric
if (!is_numeric($repo['repo-id'])) {
throw new Exception('Repository Id #' . $repo['repo-id'] . ' is invalid');
}
if (!is_numeric($repo['snap-id'])) {
throw new Exception('Snapshot Id #' . $repo['snap-id'] . ' is invalid');
}

/**
* Check that the Ids exist in the database
*/
// Check that the Ids exist in the database
if (!$repoController->existsId($repo['repo-id'])) {
throw new Exception('Repository Id #' . $repo['repo-id'] . ' does not exist');
}
if (!$repoController->existsSnapId($repo['snap-id'])) {
throw new Exception('Snapshot Id #' . $repo['snap-id'] . ' does not exist');
}

/**
* Retrieve all repo data from the Ids
*/
// Retrieve all repo data from the Ids
$repoController->getAllById($repo['repo-id'], $repo['snap-id']);

/**
* Retrieve the package type of the repo
*/
// Retrieve the package type of the repo
$packageType = $repoController->getPackageType();
$packagesTypes[] = $packageType; ?>

Expand All @@ -67,20 +56,23 @@
echo '<p class="label-white">' . $repoController->getName() . ' ❯ ' . $repoController->getReleasever() . '</p>⸺';
} ?>

<p class="label-black"><?= $repoController->getDateFormatted() ?></p>
<p class="label-white"><?= $repoController->getDateFormatted() ?></p>
<p class="repository-install-env"></p>

</div>
<span class="label-pkg-<?= $packageType ?>"><?= strtoupper($packageType) ?></span>

<span class="label-red"><?= strtoupper($packageType) ?></span>
</div>

<?php
if ($packageType == 'deb') : ?>
<pre class="repository-install-commands codeblock margin-top-10 margin-bottom-10 copy" url="<?= WWW_REPOS_DIR_URL ?>" hostname="<?= WWW_HOSTNAME ?>" prefix="<?= REPO_CONF_FILES_PREFIX ?>" package-type="<?= $packageType ?>" name="<?= $repoController->getName() ?>" dist="<?= $repoController->getDist() ?>" component="<?= $repoController->getSection() ?>"></pre>
<pre class="repository-install-commands codeblock margin-top-10 margin-bottom-10 copy" url="<?= WWW_REPOS_DIR_URL ?>" hostname="<?= WWW_HOSTNAME ?>" prefix="<?= REPO_CONF_FILES_PREFIX ?>" package-type="deb" name="<?= $repoController->getName() ?>" dist="<?= $repoController->getDist() ?>" component="<?= $repoController->getSection() ?>"></pre>
Alternative syntax (deb822):
<pre class="repository-install-commands codeblock margin-top-10 margin-bottom-10 copy" url="<?= WWW_REPOS_DIR_URL ?>" hostname="<?= WWW_HOSTNAME ?>" prefix="<?= REPO_CONF_FILES_PREFIX ?>" package-type="deb-alt" name="<?= $repoController->getName() ?>" dist="<?= $repoController->getDist() ?>" component="<?= $repoController->getSection() ?>"></pre>
<?php
endif;

if ($packageType == 'rpm') : ?>
<pre class="repository-install-commands codeblock margin-top-10 margin-bottom-10 copy" url="<?= WWW_REPOS_DIR_URL ?>" hostname="<?= WWW_HOSTNAME ?>" prefix="<?= REPO_CONF_FILES_PREFIX ?>" package-type="<?= $packageType ?>" name="<?= $repoController->getName() ?>" releasever="<?= $repoController->getReleasever() ?>"></pre>
<pre class="repository-install-commands codeblock margin-top-10 margin-bottom-10 copy" url="<?= WWW_REPOS_DIR_URL ?>" hostname="<?= WWW_HOSTNAME ?>" prefix="<?= REPO_CONF_FILES_PREFIX ?>" package-type="rpm" name="<?= $repoController->getName() ?>" releasever="<?= $repoController->getReleasever() ?>"></pre>
<?php
endif;
}
Expand Down
23 changes: 23 additions & 0 deletions www/controllers/Layout/Panel/vars/repos/rename.vars.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
use \Controllers\User\Permission\Repo as RepoPermission;

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

// If the user is not an administrator or does not have permission to edit repositories, prevent access to this panel.
if (!RepoPermission::allowedAction('edit')) {
throw new Exception('You are not allowed to access this panel');
}

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

$slidePanelTitle = 'RENAME REPOSITORY';

// Get form content
try {
$formContent = $renameFormController->get(json_decode($item['repos'], true));
} catch (JsonException $e) {
throw new Exception('Error while decoding repositories: ' . $e->getMessage());
}
23 changes: 15 additions & 8 deletions www/controllers/Layout/Tab/Run.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,27 @@

namespace Controllers\Layout\Tab;

use Controllers\User\Permission\Task as TaskPermission;
use Controllers\Layout\Container\Render;

class Run
{
public static function render()
{
// If user is not allowed to see tasks, redirect to home page
if (!TaskPermission::allowed()) {
header('Location: /');
/**
* /run now redirects to "/tasks", which is the main page for task management
* If it is followed by an ID (ex: /run/123), then redirects to /task/123
*/
$currentPath = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);

// If the path is exactly "/run", redirect to "/tasks"
if ($currentPath === '/run') {
header('Location: /tasks');
exit;
}

Render::render('tasks/log');
Render::render('tasks/list');
// If the path starts with "/run/" followed by an ID, redirect to "/task/{ID}"
if (preg_match('#^/run/(\d+)$#', $currentPath, $matches)) {
$taskId = $matches[1];
header('Location: /task/' . $taskId);
exit;
}
}
}
Loading
Loading