#!/usr/local/cpanel/3rdparty/bin/perl # gniza WHM Plugin — Main Config Editor 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::Validator; use GnizaWHM::UI; my $CONFIG_FILE = '/etc/gniza/gniza.conf'; my $form = Cpanel::Form::parseform(); my $method = $ENV{'REQUEST_METHOD'} // 'GET'; # ── Handle POST ────────────────────────────────────────────── my @errors; my $saved = 0; if ($method eq 'POST') { unless (GnizaWHM::UI::verify_csrf_token($form->{'gniza_csrf'})) { push @errors, 'Invalid or expired form token. Please try again.'; } if (!@errors) { my %data; for my $key (@GnizaWHM::Config::MAIN_KEYS) { $data{$key} = $form->{$key} // ''; } my $validation_errors = GnizaWHM::Validator::validate_main_config(\%data); if (@$validation_errors) { @errors = @$validation_errors; } else { my ($ok, $err) = GnizaWHM::Config::write($CONFIG_FILE, \%data, \@GnizaWHM::Config::MAIN_KEYS); if ($ok) { GnizaWHM::UI::set_flash('success', 'Configuration saved successfully.'); print "Status: 302 Found\r\n"; print "Location: settings.cgi\r\n\r\n"; exit; } else { push @errors, "Failed to save config: $err"; } } } } # ── Render Page ────────────────────────────────────────────── print "Content-Type: text/html\r\n\r\n"; Whostmgr::HTMLInterface::defheader('gniza Backup Manager — Settings', '', '/cgi/gniza-whm/settings.cgi'); print GnizaWHM::UI::page_header('Settings'); print GnizaWHM::UI::render_nav('settings.cgi'); print GnizaWHM::UI::render_flash(); if (@errors) { print GnizaWHM::UI::render_errors(\@errors); } # Load current config (or use POST data if validation failed) my $conf; if (@errors && $method eq 'POST') { $conf = {}; for my $key (@GnizaWHM::Config::MAIN_KEYS) { $conf->{$key} = $form->{$key} // ''; } } else { $conf = GnizaWHM::Config::parse($CONFIG_FILE, 'main'); } # Helper to output a text field row sub field_text { my ($key, $label, $hint, $extra) = @_; $extra //= ''; my $val = GnizaWHM::UI::esc($conf->{$key} // ''); my $hint_html = $hint ? qq{ $hint} : ''; print qq{