Skip to content

Commit

Permalink
Merge pull request #118 from lbr38/devel
Browse files Browse the repository at this point in the history
3.7.3
  • Loading branch information
lbr38 authored Oct 23, 2023
2 parents 798deac + 1fdbae1 commit 22d5ae6
Show file tree
Hide file tree
Showing 28 changed files with 3,669 additions and 755 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/operations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ jobs:

- name: Setup PHP
run: |
curl -fsSL https://packages.sury.org/php/apt.gpg| gpg --dearmor -o /etc/apt/trusted.gpg.d/sury-keyring.gpg
echo "deb https://packages.sury.org/php/ bullseye main" | tee /etc/apt/sources.list.d/sury-php.list
curl -sS https://packages.bespin.ovh/repo/gpgkeys/packages.bespin.ovh.pub | gpg --dearmor > /etc/apt/trusted.gpg.d/packages.bespin.ovh.gpg
echo "deb https://packages.bespin.ovh/repo/repomanager-php/bullseye/main_prod bullseye main" > /etc/apt/sources.list.d/php.list
- name: Install PHP modules
run: apt-get update && apt-get install -y php8.1-fpm php8.1-cli php8.1-sqlite3 php8.1-xml php8.1-curl sqlite3
Expand Down
5 changes: 3 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ RUN apt-get install postfix -y

# Add nginx and PHP 8.1 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/bullseye/nginx_prod bullseye nginx" > /etc/apt/sources.list.d/repomanager-repomanager-nginx_bullseye_nginx.list
RUN echo "deb https://packages.bespin.ovh/repo/repomanager-docker/bullseye/main_prod bullseye main" > /etc/apt/sources.list.d/repomanager-repomanager-docker_bullseye_main.list
RUN echo "deb https://packages.bespin.ovh/repo/repomanager-nginx/bullseye/nginx_prod bullseye nginx" > /etc/apt/sources.list.d/nginx.list
RUN echo "deb https://packages.bespin.ovh/repo/repomanager-php/bullseye/main_prod bullseye main" > /etc/apt/sources.list.d/php.list
RUN apt-get update -y

# Install nginx and PHP 8.1
Expand All @@ -52,6 +52,7 @@ RUN rm -rf /etc/nginx/sites-enabled/default /var/www/html
# Configure PHP
RUN cp /tmp/repomanager/docker/config/php/www.conf /etc/php/8.1/fpm/pool.d/www.conf
RUN sed -i "s/^upload_max_filesize.*$/upload_max_filesize = $max_upload_size/g" /etc/php/8.1/fpm/php.ini
RUN sed -i "s/^post_max_size.*$/post_max_size = $max_upload_size/g" /etc/php/8.1/fpm/php.ini

# Configure SQLite
RUN echo ".headers on" > /root/.sqliterc
Expand Down
1 change: 1 addition & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ if [ ! -z "$MAX_UPLOAD_SIZE" ];then
sed -i "s/client_max_body_size.*$/client_max_body_size ${MAX_UPLOAD_SIZE};/g" /etc/nginx/sites-enabled/repomanager.conf
# PHP configuration
sed -i "s/^upload_max_filesize.*$/upload_max_filesize = ${MAX_UPLOAD_SIZE}/g" /etc/php/8.1/fpm/php.ini
sed -i "s/^post_max_size.*$/post_max_size = ${MAX_UPLOAD_SIZE}/g" /etc/php/8.1/fpm/php.ini
fi

# Start services
Expand Down
2 changes: 1 addition & 1 deletion notifications/notifications.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"NT01" : {
"title" : "Welcome to Repomanager",
"message" : "Hey! This is the notification section, sometimes you will see some important messages here. <br><br>For any help, please check out the <a href='https://github.com/lbr38/repomanager/wiki'>documentation</a> or feel free to add an issue on <a href='https://github.com/lbr38/repomanager/issues'>github</a>."
"message" : "Hey! This is the notification section, sometimes you will see some important messages here. <br><br>For any help, please check out the documentation <a href='https://github.com/lbr38/repomanager/wiki'>here</a> or feel free to add an issue on <a href='https://github.com/lbr38/repomanager/issues'>github</a>."
}
}
30 changes: 22 additions & 8 deletions www/controllers/App/Config/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,22 @@ public static function get()
/**
* Server url
*/
if (!empty($_SERVER['SERVER_NAME'])) {
if (!defined('__SERVER_URL__')) {
if (!defined('__SERVER_URL__')) {
if (!empty($_SERVER['HTTP_HOST'])) {
define('__SERVER_URL__', __SERVER_PROTOCOL__ . '://' . $_SERVER['HTTP_HOST']);
} else {
define('__SERVER_URL__', '');
}
}

/**
* Server IP
*/
if (!empty($_SERVER['SERVER_ADDR'])) {
if (!defined('__SERVER_IP__')) {
if (!defined('__SERVER_IP__')) {
if (!empty($_SERVER['SERVER_ADDR'])) {
define('__SERVER_IP__', $_SERVER['SERVER_ADDR']);
} else {
define('__SERVER_IP__', '');
}
}

Expand All @@ -50,7 +54,11 @@ public static function get()
if (!empty($_POST['sourceUrl'])) {
define('__ACTUAL_URL__', $_POST['sourceUrl']);
} else {
define('__ACTUAL_URL__', __SERVER_PROTOCOL__ . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
if (!empty($_SERVER['HTTP_HOST']) and !empty($_SERVER['REQUEST_URI'])) {
define('__ACTUAL_URL__', __SERVER_PROTOCOL__ . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
} else {
define('__ACTUAL_URL__', '');
}
}
}

Expand All @@ -64,16 +72,22 @@ public static function get()
if (!empty($_POST['sourceUri'])) {
define('__ACTUAL_URI__', explode('/', $_POST['sourceUri']));
} else {
define('__ACTUAL_URI__', explode('/', parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH)));
if (!empty($_SERVER["REQUEST_URI"])) {
define('__ACTUAL_URI__', explode('/', parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH)));
} else {
define('__ACTUAL_URI__', '');
}
}
}

/**
* Parameters
*/
if (!empty($_SERVER['QUERY_STRING'])) {
if (!defined('__QUERY_STRING__')) {
if (!defined('__QUERY_STRING__')) {
if (!empty($_SERVER['QUERY_STRING'])) {
define('__QUERY_STRING__', parse_url($_SERVER["QUERY_STRING"], PHP_URL_PATH));
} else {
define('__QUERY_STRING__', '');
}
}

Expand Down
190 changes: 179 additions & 11 deletions www/controllers/Layout/Container/vars/stats/list.vars.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,191 @@
*/
$myrepo->getAllById('', '', $envId);

/**
* Snapshot access stats
*/

/**
* If a filter has been selected for the main chart, the page is reloaded in the background by jquery and retrieves the chart data from the selected filter
*/
if (!empty($_GET['repo_access_chart_filter'])) {
if (\Controllers\Common::validateData($_GET['repo_access_chart_filter']) == "1week") {
$repo_access_chart_filter = "1week";
if (!empty($_GET['chartFilter'])) {
if (\Controllers\Common::validateData($_GET['chartFilter']) == "1week") {
$chartFilter = "1week";
}
if (\Controllers\Common::validateData($_GET['repo_access_chart_filter']) == "1month") {
$repo_access_chart_filter = "1month";
if (\Controllers\Common::validateData($_GET['chartFilter']) == "1month") {
$chartFilter = "1month";
}
if (\Controllers\Common::validateData($_GET['repo_access_chart_filter']) == "3months") {
$repo_access_chart_filter = "3months";
if (\Controllers\Common::validateData($_GET['chartFilter']) == "3months") {
$chartFilter = "3months";
}
if (\Controllers\Common::validateData($_GET['repo_access_chart_filter']) == "6months") {
$repo_access_chart_filter = "6months";
if (\Controllers\Common::validateData($_GET['chartFilter']) == "6months") {
$chartFilter = "6months";
}
if (\Controllers\Common::validateData($_GET['repo_access_chart_filter']) == "1year") {
$repo_access_chart_filter = "1year";
if (\Controllers\Common::validateData($_GET['chartFilter']) == "1year") {
$chartFilter = "1year";
}
}

/**
* Retrieve last access logs from database
*/
if ($myrepo->getPackageType() == 'rpm') {
$lastAccess = $mystats->getLastAccess($myrepo->getName(), '', '', $myrepo->getEnv());
}
if ($myrepo->getPackageType() == 'deb') {
$lastAccess = $mystats->getLastAccess($myrepo->getName(), $myrepo->getDist(), $myrepo->getSection(), $myrepo->getEnv());
}

/**
* Sort by date and time
*/
if (!empty($lastAccess)) {
array_multisort(array_column($lastAccess, 'Date'), SORT_DESC, array_column($lastAccess, 'Time'), SORT_DESC, $lastAccess);
}

/**
* Count repo size and packages count
*/
if ($myrepo->getPackageType() == 'rpm') {
$repoSize = \Controllers\Filesystem\Directory::getSize(REPOS_DIR . '/' . $myrepo->getDateFormatted() . '_' . $myrepo->getName());
$packagesCount = count(\Controllers\Common::findRecursive(REPOS_DIR . '/' . $myrepo->getDateFormatted() . '_' . $myrepo->getName(), 'rpm'));
}
if ($myrepo->getPackageType() == 'deb') {
$repoSize = \Controllers\Filesystem\Directory::getSize(REPOS_DIR . '/' . $myrepo->getName() . '/' . $myrepo->getDist() . '/' . $myrepo->getDateFormatted() . '_' . $myrepo->getSection());
$packagesCount = count(\Controllers\Common::findRecursive(REPOS_DIR . '/' . $myrepo->getName() . '/' . $myrepo->getDist() . '/' . $myrepo->getDateFormatted() . '_' . $myrepo->getSection(), 'deb'));
}

/**
* Convert repo size in the most suitable byte format
*/
$repoSize = \Controllers\Common::sizeFormat($repoSize);

/**
* If no filter has been selected by the user then we set it to 1 week by default
*/
if (empty($chartFilter)) {
$chartFilter = "1week";
}

/**
* Initialize the starting date of the chart, according to the selected filter
*/
if ($chartFilter == "1week") {
// the beginning of the counter starts at the current date -1 week.
$dateCounter = date('Y-m-d', strtotime('-1 week', strtotime(DATE_YMD)));
}
if ($chartFilter == "1month") {
// the beginning of the counter starts at the current date -1 month.
$dateCounter = date('Y-m-d', strtotime('-1 month', strtotime(DATE_YMD)));
}
if ($chartFilter == "3months") {
// the beginning of the counter starts at the current date -3 months.
$dateCounter = date('Y-m-d', strtotime('-3 months', strtotime(DATE_YMD)));
}
if ($chartFilter == "6months") {
// the beginning of the counter starts at the current date -6 months.
$dateCounter = date('Y-m-d', strtotime('-6 months', strtotime(DATE_YMD)));
}
if ($chartFilter == "1year") {
// the beginning of the counter starts at the current date -1 year.
$dateCounter = date('Y-m-d', strtotime('-1 year', strtotime(DATE_YMD)));
}

$repoAccessChartLabels = '';
$repoAccessChartData = '';

/**
* Process all dates until the current date (which is also processed)
*/
while ($dateCounter != date('Y-m-d', strtotime('+1 day', strtotime(DATE_YMD)))) {
if ($myrepo->getPackageType() == 'rpm') {
$dateAccessCount = $mystats->getDailyAccessCount($myrepo->getName(), '', '', $myrepo->getEnv(), $dateCounter);
}
if ($myrepo->getPackageType() == 'deb') {
$dateAccessCount = $mystats->getDailyAccessCount($myrepo->getName(), $myrepo->getDist(), $myrepo->getSection(), $myrepo->getEnv(), $dateCounter);
}

if (!empty($dateAccessCount)) {
$repoAccessChartData .= $dateAccessCount . ', ';
} else {
$repoAccessChartData .= '0, ';
}

/**
* Add the current date to the labels
*/
$repoAccessChartLabels .= "'$dateCounter', ";

/**
* Increment by 1 day to be able to process the next date
*/
$dateCounter = date('Y-m-d', strtotime('+1 day', strtotime($dateCounter)));
}

/**
* Remove the last comma
*/
$repoAccessChartLabels = rtrim($repoAccessChartLabels, ', ');
$repoAccessChartData = rtrim($repoAccessChartData, ', ');

/**
* Snapshot size stats
*/

/**
* Get stats for the last 60 days
*/
$stats = $mystats->getAll($myrepo->getEnvId());
$envSizeStats = $mystats->getEnvSize($myrepo->getEnvId(), 60);

if (!empty($envSizeStats)) {
$sizeDateLabels = '';
$sizeData = '';

foreach ($envSizeStats as $stat) {
$date = DateTime::createFromFormat('Y-m-d', $stat['Date'])->format('d-m-Y');

// Convert bytes to MB
$size = round(round($stat['Size'] / 1024) / 1024);

/**
* Build data for chart
*/
$sizeDateLabels .= '"' . $date . '", ';
$sizeData .= '"' . $size . '", ';
}

/**
* Remove last comma
*/
$sizeDateLabels = rtrim($sizeDateLabels, ', ');
$sizeData = rtrim($sizeData, ', ');
}

/**
* Snapshot package count stats
*/

$pkgCountStats = $mystats->getPkgCount($myrepo->getEnvId(), 60);

if (!empty($pkgCountStats)) {
$countDateLabels = '';
$countData = '';

foreach ($pkgCountStats as $stat) {
$date = DateTime::createFromFormat('Y-m-d', $stat['Date'])->format('d-m-Y');
$count = $stat['Packages_count'];

/**
* Build data for chart
*/
$countDateLabels .= '"' . $date . '", ';
$countData .= '"' . $count . '", ';
}

/**
* Remove last comma
*/
$countDateLabels = rtrim($countDateLabels, ', ');
$countData = rtrim($countData, ', ');
}
Loading

0 comments on commit 22d5ae6

Please sign in to comment.