diff --git a/whm/gniza-whm/remotes.cgi b/whm/gniza-whm/remotes.cgi index 6722ad6..c083a79 100644 --- a/whm/gniza-whm/remotes.cgi +++ b/whm/gniza-whm/remotes.cgi @@ -258,6 +258,9 @@ sub handle_add { } if (!@errors) { + # Ensure main config exists (gniza backup requires it) + _ensure_main_config(); + # Copy example template then write values my $dest = GnizaWHM::UI::remote_conf_path($name); my $example = GnizaWHM::UI::remote_example_path(); @@ -792,3 +795,36 @@ sub _uri_escape { $str =~ s/([^A-Za-z0-9._~-])/sprintf("%%%02X", ord($1))/ge; return $str; } + +sub _ensure_main_config { + my $config_file = '/etc/gniza/gniza.conf'; + return if -f $config_file; + + # Create dirs + for my $dir ('/etc/gniza', '/etc/gniza/remotes.d', '/etc/gniza/schedules.d', '/var/log/gniza') { + mkdir $dir unless -d $dir; + } + + # Copy example or write defaults + my $example = '/usr/local/gniza/etc/gniza.conf.example'; + if (-f $example) { + File::Copy::copy($example, $config_file); + } else { + if (open my $fh, '>', $config_file) { + print $fh qq{# gniza configuration — auto-created by WHM plugin\n}; + print $fh qq{TEMP_DIR="/usr/local/gniza/workdir"\n}; + print $fh qq{INCLUDE_ACCOUNTS=""\n}; + print $fh qq{EXCLUDE_ACCOUNTS="nobody"\n}; + print $fh qq{LOG_DIR="/var/log/gniza"\n}; + print $fh qq{LOG_LEVEL="info"\n}; + print $fh qq{LOG_RETAIN=90\n}; + print $fh qq{NOTIFY_EMAIL=""\n}; + print $fh qq{NOTIFY_ON="failure"\n}; + print $fh qq{LOCK_FILE="/var/run/gniza.lock"\n}; + print $fh qq{SSH_TIMEOUT=30\n}; + print $fh qq{SSH_RETRIES=3\n}; + print $fh qq{RSYNC_EXTRA_OPTS=""\n}; + close $fh; + } + } +}