#!/usr/local/cpanel/3rdparty/bin/perl # gniza WHM Plugin — Setup Wizard # 3-step wizard: SSH Key → Remote Destination → Schedule use strict; use warnings; use lib '/usr/local/cpanel/whostmgr/docroot/cgi/gniza-whm/lib'; use Whostmgr::HTMLInterface (); use Cpanel::Form (); use File::Copy (); use GnizaWHM::Config; use GnizaWHM::Validator; use GnizaWHM::Cron; use GnizaWHM::UI; my $form = Cpanel::Form::parseform(); my $method = $ENV{'REQUEST_METHOD'} // 'GET'; my $step = $form->{'step'} // '1'; if ($step eq 'test') { handle_test_connection() } elsif ($step eq '2') { handle_step2() } elsif ($step eq '3') { handle_step3() } else { handle_step1() } exit; # ── Test Connection (JSON) ──────────────────────────────────── sub handle_test_connection { print "Content-Type: application/json\r\n\r\n"; my $host = $form->{'host'} // ''; my $port = $form->{'port'} || '22'; my $user = $form->{'user'} || 'root'; my $key = $form->{'key'} // ''; if ($host eq '' || $key eq '') { print qq({"success":false,"message":"Host and SSH key path are required."}); exit; } my ($ok, $err) = GnizaWHM::UI::test_ssh_connection($host, $port, $user, $key); if ($ok) { print qq({"success":true,"message":"SSH connection successful."}); } else { $err //= 'Unknown error'; $err =~ s/\\/\\\\/g; $err =~ s/"/\\"/g; $err =~ s/\n/\\n/g; $err =~ s/\r/\\r/g; $err =~ s/\t/\\t/g; $err =~ s/[\x00-\x1f]//g; print qq({"success":false,"message":"SSH connection failed: $err"}); } exit; } # ── Step 1: SSH Key ────────────────────────────────────────── sub handle_step1 { print "Content-Type: text/html\r\n\r\n"; Whostmgr::HTMLInterface::defheader('gniza Setup Wizard', '', '/cgi/gniza-whm/setup.cgi'); print GnizaWHM::UI::page_header('gniza Setup Wizard'); render_steps_indicator(1); my $keys = GnizaWHM::UI::detect_ssh_keys(); print qq{
gniza uses SSH keys to connect to remote backup destinations. An SSH key must be set up before adding a remote.
\n}; if (@$keys) { print qq{Existing keys found:
\n}; print qq{| Type | Path | Public Key | |
|---|---|---|---|
| }; print qq{ | $esc_type | }; print qq{$esc_path | };
print qq{$pub | }; print qq{
/root/.ssh/. You need to create one first.Generate a new SSH key (if needed):
\n}; print qq{ssh-keygen -t ed25519 -f /root/.ssh/id_ed25519 -N ""\n}; print qq{
Copy the public key to the remote server:
\n}; print qq{ssh-copy-id -i /root/.ssh/id_ed25519.pub user\@host\n}; print qq{
Run these commands in WHM → Server Configuration → Terminal, or via SSH.
\n}; print qq{