Skip to content

Commit

Permalink
Merge pull request #144 from lbr38/devel
Browse files Browse the repository at this point in the history
3.7.10
  • Loading branch information
lbr38 authored Dec 27, 2023
2 parents 06cb3cd + 5ddab01 commit 3e5c252
Show file tree
Hide file tree
Showing 41 changed files with 1,165 additions and 979 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/operations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
run: /bin/su -s /bin/bash -c "php /var/www/repomanager/operations/execute.php --id='ci-deb-duplicate-repo'" www-data

- name: Print duplicated deb repo content
run: ls -l /home/repo/debian-copy/buster/contrib_pprd/pool/contrib/
run: ls -l /home/repo/debian-copy/buster/contrib_pprd/pool/contrib/*.deb

- name: Run job - Create deb repo env
run: /bin/su -s /bin/bash -c "php /var/www/repomanager/operations/execute.php --id='ci-deb-create-env'" www-data
Expand All @@ -110,7 +110,7 @@ jobs:
run: /bin/su -s /bin/bash -c "php /var/www/repomanager/operations/execute.php --id='ci-rpm-mirror-repo'" www-data

- name: Print mirrored rpm repo content
run: ls -l /home/repo/nginx_pprd/
run: ls -l /home/repo/nginx_pprd/packages/*/*.rpm

- name: Run job - Update rpm repo
run: /bin/su -s /bin/bash -c "php /var/www/repomanager/operations/execute.php --id='ci-rpm-update-repo'" www-data
Expand Down
21 changes: 13 additions & 8 deletions Todolist
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
[ IN PROGRESS ]

- Update documentation
- (JS/PHP) Add pagination in tables
- Convert 'Last access requets' table to a paginated table
- Remove the old authentication method (via -d parameters), once linupdate 2.2.11 is released
- (DEB) Error with reprepro hanging while mirroring ubuntu > jammy > main
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1056380
https://salsa.debian.org/debian/reprepro.git
- Try using apt-ftparchive + gpg instead of reprepro for debian repos


[ BUGS ]
Expand All @@ -18,9 +23,6 @@
/usr/bin/rpm -qp --qf "%|DSAHEADER?{%{DSAHEADER:pgpsig}}:{%|RSAHEADER?{%{RSAHEADER:pgpsig}}:{(none}|}| %{NVRA}\n" mysql-community-release-el7-5.noarch.rpm
- (KO) Mirror a debian repo with translations => translations are not included by reprepro
- (KO) Mirror a debian repo with multiple archs and translations => translations are not included by reprepro
- (DEB) Error with reprepro hanging while mirroring ubuntu > jammy > main
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1056380
https://salsa.debian.org/debian/reprepro.git


[ OPERATIONS ]
Expand Down Expand Up @@ -49,11 +51,15 @@
- 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
- (RPM) See how to accelerate the rpm signing process by using multi-threading
- (DEB) Add a feature to be able to add distributions to the list of pre-defined distributions (and do the same for sections)
- (DEB) Repository install: if the repository has 'src' packages, also add the 'deb-src' line to the installation command lines


[ SETTINGS ]

- Deprecate 'Allow planifications to update repositories' setting and enable it by default

[ STATS ]

- Convert 'Last access requets' table to a paginated table
[ STATS ]


[ HOSTS / LINUPDATE ]
Expand All @@ -74,9 +80,8 @@

[ API ]

- Remove the old authentication method (via -d parameters), once linupdate 2.2.11 is released


[ MAIL ]

- Add an alternative way of sending mails via SMTP server: https://github.com/lbr38/repomanager/issues/139
https://stackoverflow.com/questions/73868867/how-to-implement-oauth-2-0-in-phpmailer-for-exchange-online
54 changes: 19 additions & 35 deletions www/controllers/Api/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,6 @@ public function __construct()
}
}

/**
* Retrieve authentication header if any
*/
if (!empty($_SERVER['HTTP_AUTHORIZATION'])) {
$this->authHeader = $_SERVER['HTTP_AUTHORIZATION'];
}

/**
* Quit on error if no data was sent
*/
Expand Down Expand Up @@ -96,7 +89,7 @@ public function __construct()
/**
* Check if authentication is valid from data sent
*/
if (!$this->authenticate($this->authHeader, $this->data)) {
if (!$this->authenticate()) {
self::returnError(401, 'Bad credentials');
}

Expand All @@ -115,8 +108,20 @@ public function __construct()
* Check if authentication is valid
* It can be an API key authentication or a host authId+token authentication
*/
public function authenticate(string $authHeader = null, string|object $data = null)
public function authenticate()
{
/**
* Retrieve authentication header
*/
if (!empty($_SERVER['HTTP_AUTHORIZATION'])) {
$this->authHeader = $_SERVER['HTTP_AUTHORIZATION'];
} else {
/**
* If no authentication header is specified, return false to quit with error
*/
return false;
}

/**
* New authentication method
*/
Expand All @@ -127,24 +132,24 @@ public function authenticate(string $authHeader = null, string|object $data = nu
* "Authorization: Bearer <API_KEY>"
* "Authorization: Host <HOST_ID>:<HOST_TOKEN>"
*/
if (!empty($authHeader)) {
if (strpos($authHeader, 'Bearer ') === 0) {
if (!empty($this->authHeader)) {
if (strpos($this->authHeader, 'Bearer ') === 0) {
/**
* Extract the token
* Remove "Bearer " from the header
*/
$apiKey = substr($authHeader, 7);
$apiKey = substr($this->authHeader, 7);
}

/**
* If host Id+token are specified through the Authorization header
*/
if (strpos($authHeader, 'Host ') === 0) {
if (strpos($this->authHeader, 'Host ') === 0) {
/**
* Extract the host Id and token
* Remove "Host " from the header
*/
$hostIdToken = substr($authHeader, 5);
$hostIdToken = substr($this->authHeader, 5);

/**
* Split the host Id and token
Expand All @@ -166,27 +171,6 @@ public function authenticate(string $authHeader = null, string|object $data = nu
}
}

/**
* Old authentication method
*/

/**
* If API key is specified in data
*/
if (!empty($data->apikey)) {
$apiKey = $data->apikey;
}

/**
* If host authId and token are specified in data
*/
if (!empty($data->id)) {
$hostId = $data->id;
}
if (!empty($data->token)) {
$hostToken = $data->token;
}

/**
* If no API key or host authId and token are specified
*/
Expand Down
2 changes: 1 addition & 1 deletion www/controllers/Api/Snapshot/Snapshot.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function execute()
if ($this->method == 'PUT') {
/**
* Reconstruct a snapshot
* https://repomanager.mydomain.net/api/v2/snapshot/$this->snapId/reconstruct
* https://repomanager.mydomain.net/api/v2/snapshot/$this->snapId/rebuild
*/
if ($this->action == 'rebuild' and !empty($this->data->gpgSign)) {
/**
Expand Down
3 changes: 2 additions & 1 deletion www/controllers/App/Structure/Directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public static function create()
TEMP_DIR,
HOSTS_DIR,
WWW_CACHE,
DB_UPDATE_DONE_DIR
DB_UPDATE_DONE_DIR,
DATA_DIR . '/ssl'
);

foreach ($dirs as $dir) {
Expand Down
18 changes: 1 addition & 17 deletions www/controllers/Browse.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,7 @@ public static function printQueue($queue)
public static function printFile($file, $path)
{
echo '<li>';

/**
* Print a checkbox to delete the file only if it is a package file
*/
if (substr($file, -4) == ".rpm"
or substr($file, -4) == ".deb"
or substr($file, -4) == ".asc"
or substr($file, -4) == ".bz2"
or substr($file, -4) == ".dsc"
or substr($file, -8) == ".diff.gz"
or substr($file, -7) == ".tar.gz"
or substr($file, -7) == ".tar.xz") {
echo '<div class="explorer-file-pkg header-light-blue"><input type="checkbox" class="packageName-checkbox pointer" name="packageName[]" filename="' . $file . '" path="' . $path . '" /><img src="/assets/icons/package.svg" class="icon" /><span>' . $file . '</span></div>';
} else {
echo '<div class="explorer-file header-blue"><img src="/assets/icons/file.svg" class="icon" /><span>' . $file . '</span></div>';
}

echo '<div class="explorer-file-pkg header-light-blue"><input type="checkbox" class="packageName-checkbox pointer" name="packageName[]" filename="' . $file . '" path="' . $path . '" /><img src="/assets/icons/package.svg" class="icon" /><span>' . $file . '</span></div>';
echo '</li>';
}

Expand Down
14 changes: 10 additions & 4 deletions www/controllers/Filesystem/Directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,24 @@ class Directory
public static function copy(string $sourceDir, string $targetDir)
{
if (!is_dir($sourceDir)) {
throw new Exception('Source directory does not exist: ' . $sourceDir);
throw new Exception('Recursive copy error: source directory does not exist: ' . $sourceDir);
}

if (!is_dir($targetDir)) {
mkdir($targetDir, 0755, true);
if (!mkdir($targetDir, 0755, true)) {
throw new Exception('Recursive copy error: could not create destination directory: ' . $targetDir);
}
}

foreach ($iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($sourceDir, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $item) {
if ($item->isDir()) {
mkdir($targetDir . DIRECTORY_SEPARATOR . $iterator->getSubPathname());
if (!mkdir($targetDir . DIRECTORY_SEPARATOR . $iterator->getSubPathname())) {
throw new Exception('Recursive copy error: could not create directory: ' . $targetDir . DIRECTORY_SEPARATOR . $iterator->getSubPathname());
}
} else {
copy($item, $targetDir . DIRECTORY_SEPARATOR . $iterator->getSubPathname());
if (!copy($item, $targetDir . DIRECTORY_SEPARATOR . $iterator->getSubPathname())) {
throw new Exception('Recursive copy error: could not copy file: ' . $targetDir . DIRECTORY_SEPARATOR . $iterator->getSubPathname());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
$myrepo->getAllById('', $snapId, '');

/**
* Retrieve repo reconstruct status
* Retrieve repo rebuild status
*/
$reconstruct = $myrepo->getReconstruct();
$rebuild = $myrepo->getReconstruct();

/**
* Upload packages
Expand Down
4 changes: 2 additions & 2 deletions www/controllers/Layout/Container/vars/stats/list.vars.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@
* Retrieve last access logs from database
*/
if ($myrepo->getPackageType() == 'rpm') {
$lastAccess = $mystats->getLastAccess($myrepo->getName(), '', '', $myrepo->getEnv());
$lastAccess = $mystats->getAccess($myrepo->getName(), '', '', $myrepo->getEnv(), true, 0);
}
if ($myrepo->getPackageType() == 'deb') {
$lastAccess = $mystats->getLastAccess($myrepo->getName(), $myrepo->getDist(), $myrepo->getSection(), $myrepo->getEnv());
$lastAccess = $mystats->getAccess($myrepo->getName(), $myrepo->getDist(), $myrepo->getSection(), $myrepo->getEnv(), true, 0);
}

/**
Expand Down
73 changes: 73 additions & 0 deletions www/controllers/Layout/Table/Render.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,77 @@ public static function render(string $table, int $offset = 0)
*/
include_once(ROOT . '/views/includes/tables/' . $table . '.inc.php');
}

/**
* Generate pagination buttons
*/
public static function paginationBtn($currentPage, $totalPages)
{
$output = '';

/**
* Don't print pagination if only one page
*/
if ($totalPages == 1) {
return;
}

/**
* Previous button
*/
if ($currentPage > 1) {
$output .= '<button class="reloadable-table-page-btn pagination-btn-first pagination-btn-previous" page="' . ($currentPage - 1) . '" title="Previous"><img src="/assets/icons/previous.svg" class="icon" /></button>';
}

/**
* Button 1
*/
if ($currentPage == 1) {
$output .= '<button class="reloadable-table-page-btn pagination-btn-first pagination-btn-current" page="1">1</button>';
} else {
$output .= '<button class="reloadable-table-page-btn pagination-btn" page="1">1</button>';
}

/**
* Print 2 previous and next pages
*/
$start = max(2, $currentPage - 2);
$end = min($totalPages - 1, $currentPage + 2);

if ($start > 2) {
$output .= '<span class="pagination-btn">...</span>';
}

for ($i = $start; $i <= $end; $i++) {
if ($currentPage == $i) {
$output .= '<button class="reloadable-table-page-btn pagination-btn pagination-btn-current" page="' . $i . '">' . $i . '</button>';
} else {
$output .= '<button class="reloadable-table-page-btn pagination-btn" page="' . $i . '">' . $i . '</button>';
}
}

if ($end < $totalPages - 1) {
$output .= '<span class="pagination-btn">...</span>';
}

/**
* Button last
*/
if ($totalPages > 1) {
if ($currentPage == $totalPages) {
$output .= '<button class="reloadable-table-page-btn pagination-btn-last pagination-btn-current" page="' . $totalPages . '">' . $totalPages . '</button>';
} else {
$output .= '<button class="reloadable-table-page-btn pagination-btn" page="' . $totalPages . '">' . $totalPages . '</button>';
}
}

/**
* Next button
*/
if ($currentPage < $totalPages) {
$output .= '<button class="reloadable-table-page-btn pagination-btn-last pagination-btn-next" page="' . ($currentPage + 1) . '" title="Next"><img src="/assets/icons/next.svg" class="icon" /></button>';
}

echo $output;
}
}
49 changes: 49 additions & 0 deletions www/controllers/Layout/Table/vars/stats/access.vars.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
$mystats = new \Controllers\Stat();
$myrepo = new \Controllers\Repo\Repo();
$reloadableTableOffset = 0;
$envId = __ACTUAL_URI__[2];

/**
* Retrieve repo infos from DB
*/
$myrepo->getAllById('', '', $envId);

/**
* Retrieve offset from cookie if exists
*/
if (!empty($_COOKIE['tables/stats/access/offset']) and is_numeric($_COOKIE['tables/stats/access/offset'])) {
$reloadableTableOffset = $_COOKIE['tables/stats/access/offset'];
}

/**
* Retrieve last access logs, with offset
*/
if ($myrepo->getPackageType() == 'rpm') {
$reloadableTableContent = $mystats->getAccess($myrepo->getName(), '', '', $myrepo->getEnv(), true, $reloadableTableOffset);
}
if ($myrepo->getPackageType() == 'deb') {
$reloadableTableContent = $mystats->getAccess($myrepo->getName(), $myrepo->getDist(), $myrepo->getSection(), $myrepo->getEnv(), true, $reloadableTableOffset);
}

/**
* Retrieve last access logs, without offset, for the total count
*/
if ($myrepo->getPackageType() == 'rpm') {
$reloadableTableTotalItems = count($mystats->getAccess($myrepo->getName(), '', '', $myrepo->getEnv()));
}
if ($myrepo->getPackageType() == 'deb') {
$reloadableTableTotalItems = count($mystats->getAccess($myrepo->getName(), $myrepo->getDist(), $myrepo->getSection(), $myrepo->getEnv()));
}

/**
* Count total pages for the pagination
*/
$reloadableTableTotalPages = ceil($reloadableTableTotalItems / 10);

/**
* Calculate current page number
*/
$reloadableTableCurrentPage = ceil($reloadableTableOffset / 10) + 1;

unset($myrepo, $mystats);
Loading

0 comments on commit 3e5c252

Please sign in to comment.