Files
gniza4cp/whm/gniza-whm/index.cgi
shuki e6ac3dfe25 Show human-readable schedule timing on dashboard
Replace raw cron entries with descriptions like "Every hour, to rasp"
or "Daily at 02:00, all remotes". Add cron_to_human() to Cron.pm.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-04 05:07:05 +02:00

87 lines
3.5 KiB
Perl

#!/usr/local/cpanel/3rdparty/bin/perl
# gniza WHM Plugin — Dashboard
use strict;
use warnings;
use lib '/usr/local/cpanel/whostmgr/docroot/cgi/gniza-whm/lib';
use Whostmgr::HTMLInterface ();
use Cpanel::Form ();
use GnizaWHM::Config;
use GnizaWHM::Cron;
use GnizaWHM::UI;
# Redirect to setup wizard if gniza is not configured
unless (GnizaWHM::UI::is_configured()) {
print "Status: 302 Found\r\n";
print "Location: setup.cgi\r\n\r\n";
exit;
}
print "Content-Type: text/html\r\n\r\n";
Whostmgr::HTMLInterface::defheader('gniza Backup Manager — Dashboard', '', '/cgi/gniza-whm/index.cgi');
print GnizaWHM::UI::page_header('gniza Backup Manager');
print GnizaWHM::UI::render_nav('index.cgi');
print GnizaWHM::UI::render_flash();
# Quick links
print qq{<div class="flex gap-3 mb-5">\n};
print qq{ <a href="setup.cgi" class="btn btn-primary btn-sm">Run Setup Wizard</a>\n};
print qq{</div>\n};
# Version
my $version = GnizaWHM::UI::get_gniza_version();
print qq{<div class="card bg-base-100 shadow-sm border border-base-300 mb-6">\n<div class="card-body">\n};
print qq{<h2 class="card-title text-sm">Overview</h2>\n};
print qq{<div class="overflow-x-auto rounded-box border border-base-content/5 bg-base-100"><table class="table">\n};
print qq{<tr><td class="font-semibold w-44">gniza version</td><td>} . GnizaWHM::UI::esc($version) . qq{</td></tr>\n};
print qq{</table></div>\n};
print qq{</div>\n</div>\n};
# Remote destinations
my @remotes = GnizaWHM::UI::list_remotes();
print qq{<div class="card bg-base-100 shadow-sm border border-base-300 mb-6">\n<div class="card-body">\n};
print qq{<h2 class="card-title text-sm">Configured Remotes</h2>\n};
if (@remotes) {
print qq{<div class="overflow-x-auto rounded-box border border-base-content/5 bg-base-100"><table class="table">\n};
print qq{<thead><tr><th>Name</th><th>Host</th><th>Port</th><th>Retention</th></tr></thead>\n};
print qq{<tbody>\n};
for my $name (@remotes) {
my $conf = GnizaWHM::Config::parse(GnizaWHM::UI::remote_conf_path($name), 'remote');
my $host = GnizaWHM::UI::esc($conf->{REMOTE_HOST} // '');
my $port = GnizaWHM::UI::esc($conf->{REMOTE_PORT} // '22');
my $retention = GnizaWHM::UI::esc($conf->{RETENTION_COUNT} // '30');
my $esc_name = GnizaWHM::UI::esc($name);
print qq{<tr class="hover"><td>$esc_name</td><td>$host</td><td>$port</td><td>$retention</td></tr>\n};
}
print qq{</tbody>\n</table></div>\n};
} else {
print qq{<p>No remotes configured. <a href="setup.cgi" class="link">Run the setup wizard</a> to add one.</p>\n};
}
print qq{</div>\n</div>\n};
# Active schedules
my $schedules = GnizaWHM::Cron::get_current_schedules();
print qq{<div class="card bg-base-100 shadow-sm border border-base-300 mb-6">\n<div class="card-body">\n};
print qq{<h2 class="card-title text-sm">Active Cron Schedules</h2>\n};
if (keys %$schedules) {
print qq{<div class="overflow-x-auto rounded-box border border-base-content/5 bg-base-100"><table class="table">\n};
print qq{<thead><tr><th>Schedule</th><th>Timing</th></tr></thead>\n};
print qq{<tbody>\n};
for my $name (sort keys %$schedules) {
my $esc_name = GnizaWHM::UI::esc($name);
my $human = GnizaWHM::UI::esc(GnizaWHM::Cron::cron_to_human($schedules->{$name}));
print qq{<tr class="hover"><td>$esc_name</td><td>$human</td></tr>\n};
}
print qq{</tbody>\n</table></div>\n};
} else {
print qq{<p>No active gniza cron entries.</p>\n};
}
print qq{</div>\n</div>\n};
print GnizaWHM::UI::page_footer();
Whostmgr::HTMLInterface::footer();