Files
gniza4cp/whm/gniza-whm/index.cgi
2026-03-04 05:38:48 +02:00

88 lines
3.9 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};
# Remote destinations
my @remotes = GnizaWHM::UI::list_remotes();
print qq{<div class="card bg-white shadow-sm border border-base-300 mb-6">\n<div class="card-body">\n};
print qq{<div class="flex items-center gap-3"><h2 class="card-title text-sm">Configured Remotes</h2><a href="remotes.cgi?action=add_form" class="btn btn-primary btn-xs">Add New</a></div>\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-white shadow-sm border border-base-300 mb-6">\n<div class="card-body">\n};
print qq{<div class="flex items-center gap-3"><h2 class="card-title text-sm">Active Cron Schedules</h2><a href="schedules.cgi?action=add_form" class="btn btn-primary btn-xs">Add New</a></div>\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><th>Remote Destination(s)</th></tr></thead>\n};
print qq{<tbody>\n};
for my $name (sort keys %$schedules) {
my $esc_name = GnizaWHM::UI::esc($name);
my ($timing, $remotes) = GnizaWHM::Cron::cron_to_human($schedules->{$name});
my $esc_timing = GnizaWHM::UI::esc($timing);
my $esc_remotes = GnizaWHM::UI::esc($remotes);
print qq{<tr class="hover"><td>$esc_name</td><td>$esc_timing</td><td>$esc_remotes</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};
# Overview
my $version = GnizaWHM::UI::get_gniza_version();
print qq{<div class="card bg-white 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};
print GnizaWHM::UI::page_footer();
Whostmgr::HTMLInterface::footer();