Skip to content

Commit

Permalink
Merge pull request #109 from lbr38/devel
Browse files Browse the repository at this point in the history
3.6.1
  • Loading branch information
lbr38 authored Sep 17, 2023
2 parents f871ba5 + 36de6c1 commit 5b8c205
Show file tree
Hide file tree
Showing 45 changed files with 942 additions and 803 deletions.
1 change: 0 additions & 1 deletion .github/workflows/operations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ jobs:
# deb
- name: Run job - Mirror deb repo
#run: sudo -u www-data php /var/www/repomanager/operations/execute.php --id='ci-mirror-repo' || sleep 10; cat /var/lib/repomanager/logs/main/lastlog.log; exit 1
run: /bin/su -s /bin/bash -c "php /var/www/repomanager/operations/execute.php --id='ci-deb-mirror-repo'" www-data

- name: Print mirrored deb repo content
Expand Down
1 change: 1 addition & 0 deletions www/config/properties.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
'project_logo' => 'https://github.com/lbr38/repomanager/raw/stable/www/public/assets/images/repomanager.png',
'project_git_repo' => 'https://github.com/lbr38/repomanager',
'project_git_repo_raw' => 'https://raw.githubusercontent.com/lbr38/repomanager/stable',
'project_update_doc_url' => 'https://github.com/lbr38/repomanager/wiki/01.-Installation-and-update#update-repomanager'
);
2 changes: 1 addition & 1 deletion www/controllers/App/Config/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static function get()
* If an update is available, generate a new notification
*/
if (UPDATE_AVAILABLE == 'true') {
$message = '<span class="yellowtext">A new release is available: <b>' . GIT_VERSION . '</b>.</span><br><br>Please update your docker image.</span>';
$message = '<span class="yellowtext">A new release is available: <b>' . GIT_VERSION . '</b>.</span><br><br>Please update your docker image by following the steps documented here: <b><a href="' . PROJECT_UPDATE_DOC_URL . '"></a></b></span>';
$NOTIFICATION_MESSAGES[] = array('Title' => 'Update available', 'Message' => $message);
$NOTIFICATION++;
}
Expand Down
28 changes: 0 additions & 28 deletions www/controllers/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,34 +145,6 @@ public static function printAlert(string $message, string $alertType = null)
echo '</script>';
}

/**
* Fonction affichant un message de confirmation avant de supprimer
* $message = le message à afficher
* $url = lien GET vers la page de suppression
* $divID = un id unique du div caché contenant le message et les bouton supprimer ou annuler
* $aID = une class avec un ID unique du bouton cliquable permettant d'afficher/fermer la div caché. Attention le bouton d'affichage doit être avant l'appel de cette fonction.
*/
public static function deleteConfirm(string $message, string $url, $divID, $aID)
{
echo "<div id=\"$divID\" class=\"hide confirmAlert\">";
echo "<span class=\"confirmAlert-message\">$message</span>";
echo '<div class="confirmAlert-buttons-container">';
echo "<a href=\"$url\"><span class=\"btn-doConfirm\">Delete</span></a>";
echo "<span class=\"$aID btn-doCancel pointer\">Cancel</span>";
echo '</div>';

echo "<script>";
echo "$(document).ready(function(){";
echo "$(\".$aID\").click(function(){";
echo "$(\"div#$divID\").slideToggle(150);";
echo '$(this).toggleClass("open");';
echo "});";
echo "});";
echo "</script>";
echo '</div>';
unset($message, $url, $divID, $aID);
}

/**
* Affiche une erreur générique ou personnalisée lorsqu'il y a eu une erreur d'exécution d'une requête dans la base de données
* Ajoute une copie de l'erreur dans le fichier de logs 'exceptions'
Expand Down
2 changes: 1 addition & 1 deletion www/controllers/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Environment
{
private $model;

public function __construct(array $variables = [])
public function __construct()
{
$this->model = new \Models\Environment();
}
Expand Down
9 changes: 6 additions & 3 deletions www/controllers/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ public function new(string $name)
*/
$this->model->add($name);

\Models\History::set($_SESSION['username'], 'Create a new group <span class="label-white">' . $name . '</span> (type: ' . $this->type . ')', 'success');
$myhistory = new \Controllers\History();
$myhistory->set($_SESSION['username'], 'Create a new group <span class="label-white">' . $name . '</span> (type: ' . $this->type . ')', 'success');

\Controllers\App\Cache::clear();
}
Expand Down Expand Up @@ -161,7 +162,8 @@ public function rename(string $actualName, string $newName)
*/
$this->model->rename($actualName, $newName);

\Models\History::set($_SESSION['username'], 'Rename group: <span class="label-white">' . $actualName . '</span> to <span class="label-white">' . $newName . '</span> (type: ' . $this->type . ')', 'success');
$myhistory = new \Controllers\History();
$myhistory->set($_SESSION['username'], 'Rename group: <span class="label-white">' . $actualName . '</span> to <span class="label-white">' . $newName . '</span> (type: ' . $this->type . ')', 'success');

\Controllers\App\Cache::clear();
}
Expand All @@ -184,7 +186,8 @@ public function delete(string $name)
*/
$this->model->delete($name);

\Models\History::set($_SESSION['username'], 'Delete group <span class="label-white">' . $name . '</span> (type: '. $this->type . ')', 'success');
$myhistory = new \Controllers\History();
$myhistory->set($_SESSION['username'], 'Delete group <span class="label-white">' . $name . '</span> (type: '. $this->type . ')', 'success');

\Controllers\App\Cache::clear();
}
Expand Down
64 changes: 64 additions & 0 deletions www/controllers/History.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace Controllers;

use Exception;

class History
{
private $model;

public function __construct()
{
$this->model = new \Models\History();
}

/**
* Retrieve all history
*/
public function getAll()
{
return $this->model->getAll();
}

/**
* Retrieve all history from a user
*/
public function getByUser(int $userId)
{
$userId = \Controllers\Common::validateData($userId);

if (!is_numeric($userId)) {
printAlert('User Id is invalid', 'error');
return;
}

return $this->model->getByUser($userId);
}

/**
* Add new history line in database
*/
public function set(string $username, string $action, string $state)
{
$mylogin = new \Controllers\Login();

$username = \Controllers\Common::validateData($username);
$action = \Controllers\Common::validateData($action);
$state = \Controllers\Common::validateData($state);

/**
* Check if user exists
*/
if (!$mylogin->userExists($username)) {
throw new Exception('User ' . $username . ' does not exist');
}

/**
* Retrieve user Id from username
*/
$userId = $mylogin->getIdByUsername($username);

$this->model->set($userId, $action, $state);
}
}
3 changes: 2 additions & 1 deletion www/controllers/Host.php
Original file line number Diff line number Diff line change
Expand Up @@ -1727,6 +1727,7 @@ public function addHostsIdToGroup(array $hostsId = null, string $groupName)
}
}

\Models\History::set($_SESSION['username'], 'Modification of hosts members of the group <span class="label-white">' . $groupName . '</span>', 'success');
$myhistory = new \Controllers\History();
$myhistory->set($_SESSION['username'], 'Modification of hosts members of the group <span class="label-white">' . $groupName . '</span>', 'success');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,24 @@
setcookie('view-logfile', $logfile, time() + 3600 * 24 * 30, '/');
}
}

if ($logfileGet == 'latest') {
if (file_exists(MAIN_LOGS_DIR . '/latest')) {
$logfile = '/latest';

/**
* Rewrite cookie
*/
setcookie('view-logfile', $logfile, time() + 3600 * 24 * 30, '/');
}
}
}

/**
* If no logfile is specified, we take the last one
*/
if ($logfile == 'none') {
$logfiles = array_diff(scandir(MAIN_LOGS_DIR, SCANDIR_SORT_DESCENDING), array('..', '.', 'lastlog.log'));
$logfiles = array_diff(scandir(MAIN_LOGS_DIR, SCANDIR_SORT_DESCENDING), array('..', '.', 'latest'));

if (!empty($logfiles[1])) {
$logfile = $logfiles[1];
Expand Down
5 changes: 3 additions & 2 deletions www/controllers/Layout/Tab/History.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public static function render()
}

$myusers = new \Controllers\Login();
$myhistory = new \Controllers\History();

/**
* Cas où on souhaite filtrer par Id utilisateur
Expand All @@ -33,9 +34,9 @@ public static function render()
* Case it must be filtered by user
*/
if (!empty($filterByUser) and $filterByUser == "yes") {
$historyLines = \Models\History::getByUser($filterByUserId);
$historyLines = $myhistory->getByUser($filterByUserId);
} else {
$historyLines = \Models\History::getAll();
$historyLines = $myhistory->getAll();
}

/**
Expand Down
8 changes: 4 additions & 4 deletions www/controllers/Log/OperationLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ public function __construct(string $type, int $pid)
}

/**
* Update symbolic link lastlog.log to point to the newly created log file
* Update symbolic link 'latest' to point to the newly created log file
*/
if (file_exists(MAIN_LOGS_DIR . '/lastlog.log')) {
unlink(MAIN_LOGS_DIR . '/lastlog.log');
if (file_exists(MAIN_LOGS_DIR . '/latest')) {
unlink(MAIN_LOGS_DIR . '/latest');
}

exec("ln -sfn $this->location " . MAIN_LOGS_DIR . '/lastlog.log');
exec("ln -sfn $this->location " . MAIN_LOGS_DIR . '/latest');
}

public function getPid()
Expand Down
30 changes: 22 additions & 8 deletions www/controllers/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,18 @@ private function getHashedPasswordFromDb(string $username)
return $this->model->getHashedPasswordFromDb($username);
}

/**
* Get Id by username
*/
public function getIdByUsername(string $username)
{
return $this->model->getIdByUsername($username);
}

/**
* Get username by user Id
*/
private function getUsernameById(string $id)
public function getUsernameById(string $id)
{
return $this->model->getUsernameById($id);
}
Expand Down Expand Up @@ -182,7 +190,8 @@ public function addUser(string $username, string $role)
*/
$this->model->addUser($username, $hashedPassword, $role);

\Models\History::set($_SESSION['username'], "Created user: <b>$username</b>", 'success');
$myhistory = new \Controllers\History();
$myhistory->set($_SESSION['username'], "Created user: <b>$username</b>", 'success');

/**
* Return temporary generated password
Expand Down Expand Up @@ -220,7 +229,8 @@ public function checkUsernamePwd(string $username, string $password)
* If specified password does not match database password, then it is invalid
*/
if (!password_verify($password, $hashedPassword)) {
\Models\History::set($username, 'Authentication failed: Invalid password', 'error');
$myhistory = new \Controllers\History();
$myhistory->set($username, 'Authentication failed: Invalid password', 'error');
throw new Exception('Invalid login and/or password');
}
}
Expand Down Expand Up @@ -268,7 +278,8 @@ public function edit(string $username, string $firstName = null, string $lastNam
$_SESSION['last_name'] = $lastName;
$_SESSION['email'] = $email;

\Models\History::set($username, "Personal informations modification", 'success');
$myhistory = new \Controllers\History();
$myhistory->set($username, "Personal informations modification", 'success');
}

/**
Expand Down Expand Up @@ -330,7 +341,8 @@ public function changePassword(string $username, string $actualPassword, string
*/
$this->model->updatePassword($username, $newPasswordHashed);

\Models\History::set($_SESSION['username'], "Password modification", 'success');
$myhistory = new \Controllers\History();
$myhistory->set($_SESSION['username'], "Password modification", 'success');
}

/**
Expand Down Expand Up @@ -369,7 +381,8 @@ public function resetPassword(string $id)
*/
$this->model->updatePassword($username, $hashedPassword);

\Models\History::set($_SESSION['username'], "Reset password of user <b>$username</b>", 'success');
$myhistory = new \Controllers\History();
$myhistory->set($_SESSION['username'], "Reset password of user <b>$username</b>", 'success');

/**
* Return new password
Expand Down Expand Up @@ -483,13 +496,14 @@ public function deleteUser(string $id)
*/
$this->model->deleteUser($id);

\Models\History::set($_SESSION['username'], "Delete user <b>$username</b>", 'success');
$myhistory = new \Controllers\History();
$myhistory->set($_SESSION['username'], "Delete user <b>$username</b>", 'success');
}

/**
* Check if user exists in database
*/
private function userExists(string $username)
public function userExists(string $username)
{
return $this->model->userExists($username);
}
Expand Down
Loading

0 comments on commit 5b8c205

Please sign in to comment.