v-wordpress-plugin-updater/update-api/classes/LogsHelper.php

69 lines
2.5 KiB
PHP
Raw Normal View History

modified: .gitignore modified: README.md modified: mu-plugin/v-sys-plugin-updater-mu.php modified: mu-plugin/v-sys-plugin-updater.php modified: mu-plugin/v-sys-theme-updater.php deleted: update-api/app/forms/home-forms.php deleted: update-api/app/forms/plupdate-forms.php deleted: update-api/app/forms/thupdate-forms.php deleted: update-api/app/helpers/home-helper.php deleted: update-api/app/helpers/logs-helper.php deleted: update-api/app/helpers/plupdate-helper.php deleted: update-api/app/helpers/thupdate-helper.php new file: update-api/classes/forms/HomeFormHandler.php new file: update-api/classes/forms/PlFormHandler.php new file: update-api/classes/forms/ThFormHandler.php new file: update-api/classes/helpers/HomeHelper.php new file: update-api/classes/helpers/LogsHelper.php new file: update-api/classes/helpers/PlHelper.php new file: update-api/classes/helpers/ThHelper.php new file: update-api/classes/util/security.php modified: update-api/lib/auth-lib.php new file: update-api/lib/class-lib.php modified: update-api/lib/load-lib.php deleted: update-api/lib/waf-lib.php modified: update-api/public/.htaccess new file: update-api/public/api.php modified: update-api/public/assets/css/login.css modified: update-api/public/assets/css/mobile.css deleted: update-api/public/assets/css/pages.css modified: update-api/public/assets/css/styles.css modified: update-api/public/index.php modified: update-api/public/login.php deleted: update-api/public/plugins/api.php deleted: update-api/public/plugins/download.php deleted: update-api/public/themes/api.php deleted: update-api/public/themes/download.php renamed: update-api/app/pages/home.php -> update-api/views/home.php renamed: update-api/app/pages/logs.php -> update-api/views/logs.php renamed: update-api/app/pages/plupdate.php -> update-api/views/plupdate.php renamed: update-api/app/pages/thupdate.php -> update-api/views/thupdate.php
2025-06-29 14:59:47 -04:00
<?php
2025-07-04 20:30:15 -04:00
// @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
modified: .gitignore modified: README.md modified: mu-plugin/v-sys-plugin-updater-mu.php modified: mu-plugin/v-sys-plugin-updater.php modified: mu-plugin/v-sys-theme-updater.php deleted: update-api/app/forms/home-forms.php deleted: update-api/app/forms/plupdate-forms.php deleted: update-api/app/forms/thupdate-forms.php deleted: update-api/app/helpers/home-helper.php deleted: update-api/app/helpers/logs-helper.php deleted: update-api/app/helpers/plupdate-helper.php deleted: update-api/app/helpers/thupdate-helper.php new file: update-api/classes/forms/HomeFormHandler.php new file: update-api/classes/forms/PlFormHandler.php new file: update-api/classes/forms/ThFormHandler.php new file: update-api/classes/helpers/HomeHelper.php new file: update-api/classes/helpers/LogsHelper.php new file: update-api/classes/helpers/PlHelper.php new file: update-api/classes/helpers/ThHelper.php new file: update-api/classes/util/security.php modified: update-api/lib/auth-lib.php new file: update-api/lib/class-lib.php modified: update-api/lib/load-lib.php deleted: update-api/lib/waf-lib.php modified: update-api/public/.htaccess new file: update-api/public/api.php modified: update-api/public/assets/css/login.css modified: update-api/public/assets/css/mobile.css deleted: update-api/public/assets/css/pages.css modified: update-api/public/assets/css/styles.css modified: update-api/public/index.php modified: update-api/public/login.php deleted: update-api/public/plugins/api.php deleted: update-api/public/plugins/download.php deleted: update-api/public/themes/api.php deleted: update-api/public/themes/download.php renamed: update-api/app/pages/home.php -> update-api/views/home.php renamed: update-api/app/pages/logs.php -> update-api/views/logs.php renamed: update-api/app/pages/plupdate.php -> update-api/views/plupdate.php renamed: update-api/app/pages/thupdate.php -> update-api/views/thupdate.php
2025-06-29 14:59:47 -04:00
/*
* Project: Update API
* Author: Vontainment
* URL: https://vontainment.com
* File: LogsHelper.php
* Description: WordPress Update API Helper for logs display and processing
*/
class LogsHelper
{
2025-07-04 20:16:50 -04:00
public static function processLogFile(string $logFile): string
modified: .gitignore modified: README.md modified: mu-plugin/v-sys-plugin-updater-mu.php modified: mu-plugin/v-sys-plugin-updater.php modified: mu-plugin/v-sys-theme-updater.php deleted: update-api/app/forms/home-forms.php deleted: update-api/app/forms/plupdate-forms.php deleted: update-api/app/forms/thupdate-forms.php deleted: update-api/app/helpers/home-helper.php deleted: update-api/app/helpers/logs-helper.php deleted: update-api/app/helpers/plupdate-helper.php deleted: update-api/app/helpers/thupdate-helper.php new file: update-api/classes/forms/HomeFormHandler.php new file: update-api/classes/forms/PlFormHandler.php new file: update-api/classes/forms/ThFormHandler.php new file: update-api/classes/helpers/HomeHelper.php new file: update-api/classes/helpers/LogsHelper.php new file: update-api/classes/helpers/PlHelper.php new file: update-api/classes/helpers/ThHelper.php new file: update-api/classes/util/security.php modified: update-api/lib/auth-lib.php new file: update-api/lib/class-lib.php modified: update-api/lib/load-lib.php deleted: update-api/lib/waf-lib.php modified: update-api/public/.htaccess new file: update-api/public/api.php modified: update-api/public/assets/css/login.css modified: update-api/public/assets/css/mobile.css deleted: update-api/public/assets/css/pages.css modified: update-api/public/assets/css/styles.css modified: update-api/public/index.php modified: update-api/public/login.php deleted: update-api/public/plugins/api.php deleted: update-api/public/plugins/download.php deleted: update-api/public/themes/api.php deleted: update-api/public/themes/download.php renamed: update-api/app/pages/home.php -> update-api/views/home.php renamed: update-api/app/pages/logs.php -> update-api/views/logs.php renamed: update-api/app/pages/plupdate.php -> update-api/views/plupdate.php renamed: update-api/app/pages/thupdate.php -> update-api/views/thupdate.php
2025-06-29 14:59:47 -04:00
{
$log_file_path = LOG_DIR . "/$logFile";
$output = '';
if (file_exists($log_file_path)) {
$log_array = file($log_file_path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$log_by_domain = [];
foreach ($log_array as $entry) {
list($domain, $date, $status) = explode(' ', $entry);
$log_by_domain[$domain] = [
modified: .gitignore modified: README.md modified: mu-plugin/v-sys-plugin-updater-mu.php modified: mu-plugin/v-sys-plugin-updater.php modified: mu-plugin/v-sys-theme-updater.php deleted: update-api/app/forms/home-forms.php deleted: update-api/app/forms/plupdate-forms.php deleted: update-api/app/forms/thupdate-forms.php deleted: update-api/app/helpers/home-helper.php deleted: update-api/app/helpers/logs-helper.php deleted: update-api/app/helpers/plupdate-helper.php deleted: update-api/app/helpers/thupdate-helper.php new file: update-api/classes/forms/HomeFormHandler.php new file: update-api/classes/forms/PlFormHandler.php new file: update-api/classes/forms/ThFormHandler.php new file: update-api/classes/helpers/HomeHelper.php new file: update-api/classes/helpers/LogsHelper.php new file: update-api/classes/helpers/PlHelper.php new file: update-api/classes/helpers/ThHelper.php new file: update-api/classes/util/security.php modified: update-api/lib/auth-lib.php new file: update-api/lib/class-lib.php modified: update-api/lib/load-lib.php deleted: update-api/lib/waf-lib.php modified: update-api/public/.htaccess new file: update-api/public/api.php modified: update-api/public/assets/css/login.css modified: update-api/public/assets/css/mobile.css deleted: update-api/public/assets/css/pages.css modified: update-api/public/assets/css/styles.css modified: update-api/public/index.php modified: update-api/public/login.php deleted: update-api/public/plugins/api.php deleted: update-api/public/plugins/download.php deleted: update-api/public/themes/api.php deleted: update-api/public/themes/download.php renamed: update-api/app/pages/home.php -> update-api/views/home.php renamed: update-api/app/pages/logs.php -> update-api/views/logs.php renamed: update-api/app/pages/plupdate.php -> update-api/views/plupdate.php renamed: update-api/app/pages/thupdate.php -> update-api/views/thupdate.php
2025-06-29 14:59:47 -04:00
'date' => $date,
'status' => $status,
];
}
ob_start();
echo '<div class="log-row">';
foreach ($log_by_domain as $domain => $entry) {
$date_diff = (strtotime(date('Y-m-d')) - strtotime($entry['date'])) / (60 * 60 * 24);
$classes = '';
if ($entry['status'] == 'Failed') {
$classes .= ' error';
} elseif ($entry['status'] == 'Success') {
$classes .= ' success';
}
if ($date_diff > 30) {
$classes .= ' lost';
}
$classes = trim($classes);
echo '<div class="log-sub-box' . ($classes ? " $classes" : '') . '">';
echo '<h3>' . htmlspecialchars($domain, ENT_QUOTES, 'UTF-8') . '</h3>';
if ($entry['status'] == 'Failed') {
echo '<p class="log-entry" style="color:red;">' .
htmlspecialchars($entry['date'], ENT_QUOTES, 'UTF-8') . ' ' .
htmlspecialchars($entry['status'], ENT_QUOTES, 'UTF-8') .
'</p>';
} else {
echo '<p class="log-entry" style="color:green;">' .
htmlspecialchars($entry['date'], ENT_QUOTES, 'UTF-8') . ' ' .
htmlspecialchars($entry['status'], ENT_QUOTES, 'UTF-8') .
'</p>';
modified: .gitignore modified: README.md modified: mu-plugin/v-sys-plugin-updater-mu.php modified: mu-plugin/v-sys-plugin-updater.php modified: mu-plugin/v-sys-theme-updater.php deleted: update-api/app/forms/home-forms.php deleted: update-api/app/forms/plupdate-forms.php deleted: update-api/app/forms/thupdate-forms.php deleted: update-api/app/helpers/home-helper.php deleted: update-api/app/helpers/logs-helper.php deleted: update-api/app/helpers/plupdate-helper.php deleted: update-api/app/helpers/thupdate-helper.php new file: update-api/classes/forms/HomeFormHandler.php new file: update-api/classes/forms/PlFormHandler.php new file: update-api/classes/forms/ThFormHandler.php new file: update-api/classes/helpers/HomeHelper.php new file: update-api/classes/helpers/LogsHelper.php new file: update-api/classes/helpers/PlHelper.php new file: update-api/classes/helpers/ThHelper.php new file: update-api/classes/util/security.php modified: update-api/lib/auth-lib.php new file: update-api/lib/class-lib.php modified: update-api/lib/load-lib.php deleted: update-api/lib/waf-lib.php modified: update-api/public/.htaccess new file: update-api/public/api.php modified: update-api/public/assets/css/login.css modified: update-api/public/assets/css/mobile.css deleted: update-api/public/assets/css/pages.css modified: update-api/public/assets/css/styles.css modified: update-api/public/index.php modified: update-api/public/login.php deleted: update-api/public/plugins/api.php deleted: update-api/public/plugins/download.php deleted: update-api/public/themes/api.php deleted: update-api/public/themes/download.php renamed: update-api/app/pages/home.php -> update-api/views/home.php renamed: update-api/app/pages/logs.php -> update-api/views/logs.php renamed: update-api/app/pages/plupdate.php -> update-api/views/plupdate.php renamed: update-api/app/pages/thupdate.php -> update-api/views/thupdate.php
2025-06-29 14:59:47 -04:00
}
echo '</div>';
}
echo '</div>';
$output = ob_get_contents();
ob_end_clean();
return $output;
} else {
return 'Log file not found.';
}
}
}