# Prints a confirmation prompt for install/uninstall and returns 0 if confirmed. # $1 (verb): install|uninstall # $2 (label): service label, e.g. "$mariadbLabel" # $3 (name): display name, e.g. "MariaDB" function cmdRouterConfirm() { local verb="$1" label="$2" name="$3" local title promptVerb direction if [[ "$verb" == "install" ]]; then title="Install"; promptVerb="INSTALL"; direction="to" else title="Uninstall"; promptVerb="UNINSTALL"; direction="from" fi printTitle " $label $title" printRow local confirmation read -r -p "${fontYellow}Warning!${fontReset} Are you sure you want to${fontRed} ${promptVerb}${fontBlue} ${name}${fontReset} resources ${direction} k3s? (y/n): " confirmation [[ "$confirmation" =~ ^[Yy]$ ]] } function cmdK3s() { local action="${1:-}" shift || true case "$action" in install) if cmdRouterConfirm install "$k3sLabel" "ALL"; then cmdMariadbInstall cmdRedisInstall cmdOpenlitespeedInstall cmdPostfixInstall cmdWorkerInstall cmdMetricInstall fi ;; uninstall) if cmdRouterConfirm uninstall "$k3sLabel" "ALL"; then cmdK3sResourceClean fi ;; info) printTitle " $k3sLabel Info" cmdK3sInfo ;; status) printTitle " $k3sLabel Status" cmdK3sNodesStatus ;; top) printTitle " $k3sLabel Top pod" cmdK3sTopPod ;; res) printTitle " $k3sLabel Resources $@" cmdK3sResourceList "$@" ;; *) printTitle " $k3sLabel" printRow printWarning "Unsupported or empty command: $action" cmdHelpK3S ;; esac } function cmdMariadb() { local action="${1:-}" shift || true case "$action" in install) if cmdRouterConfirm install "$mariadbLabel" "MariaDB"; then cmdMariadbInstall fi ;; uninstall) if cmdRouterConfirm uninstall "$mariadbLabel" "MariaDB"; then cmdMariadbUninstall fi ;; info) printTitle " $mariadbLabel Info" cmdMariadbInfo ;; status) printTitle " $mariadbLabel Status" cmdMariadbStatus ;; replica) printTitle " $mariadbLabel Replica rebuild" printRow local confirmation read -r -p "${fontYellow}Warning!$fontReset Do you really want to$fontRed REBUILD$fontReset the$fontBlue MariaDB replica$fontReset? (y/n): " confirmation [[ ! "$confirmation" =~ ^[Yy]$ ]] && { printRow; return 0; } cmdMariadbReplicaRebuild ;; database) printTitle " $mariadbLabel Database list" cmdMariadbDatabase ;; user) printTitle " $mariadbLabel User list" cmdMariadbUser ;; dump) printTitle " $mariadbLabel Dump Master $@" cmdMariadbMasterDump "$@" ;; dump_slave) printTitle " $mariadbLabel Dump Slave $@" cmdMariadbSlaveDump "$@" ;; *) printTitle " $mariadbLabel" printRow printWarning "Unsupported or empty command: $action" cmdHelpMariaDB ;; esac } function cmdRedis() { local action="${1:-}" shift || true case "$action" in install) if cmdRouterConfirm install "$redisLabel" "Redis"; then cmdRedisInstall fi ;; uninstall) if cmdRouterConfirm uninstall "$redisLabel" "Redis"; then cmdRedisUninstall fi ;; info) printTitle " $redisLabel Info" cmdRedisInfo ;; status) printTitle " $redisLabel Status" cmdRedisStatus ;; user) printTitle " $redisLabel User list" cmdRedisUser ;; flush) printTitle " $redisLabel Flush current DB" cmdRedisDatabaseFlush ;; pass) printTitle " $redisLabel Update default (root) pass" cmdRedisRootPassUpdate ;; *) printTitle " $redisLabel" printRow printWarning "Unsupported or empty command: $action" cmdHelpRedis ;; esac } function cmdOpenlitespeed() { local action="${1:-}" shift || true case "$action" in install) if cmdRouterConfirm install "$openlitespeedLabel" "OpenLiteSpeed"; then cmdOpenlitespeedInstall fi ;; uninstall) if cmdRouterConfirm uninstall "$openlitespeedLabel" "OpenLiteSpeed"; then cmdOpenlitespeedUninstall fi ;; info) printTitle " $openlitespeedLabel Info" cmdOpenlitespeedInfo ;; list) printTitle " $openlitespeedLabel List (all|up|down)" cmdOpenlitespeedSiteList "$@" ;; up) printTitle " $openlitespeedLabel Up $@" cmdOpenlitespeedVHostUp "$@" ;; down) printTitle " $openlitespeedLabel Down $@" cmdOpenlitespeedVHostDown "$@" ;; alias) printTitle " $openlitespeedLabel Alias $1" cmdOpenlitespeedAliasSet "$@" ;; restart) printTitle " $openlitespeedLabel Restart" cmdOpenlitespeedRestart ;; restart_php) printTitle " $openlitespeedLabel Restart PHP" cmdOpenlitespeedPhpRestart ;; white_list) printTitle " $openlitespeedLabel White list update" cmdOpenlitespeedAdminWhiteList ;; allow_list) printTitle " $openlitespeedLabel Allow list update" cmdOpenlitespeedAdminAllowList ;; alias_list) printTitle " $openlitespeedLabel Alias list $1" cmdOpenlitespeedAliasList "$@" ;; rebuild) printTitle " $openlitespeedLabel Rebuild $1" cmdOpenlitespeedVhostRebuild "$@" ;; config) printTitle " $openlitespeedLabel Config check" cmdOpenlitespeedConfigCheck ;; *) printTitle " $openlitespeedLabel" printRow printWarning "Unsupported or empty command: $action" cmdHelpOpenLiteSpeed ;; esac } function cmdPostfix() { local action="${1:-}" shift || true case "$action" in install) if cmdRouterConfirm install "$postfixLabel" "Postfix"; then cmdPostfixInstall fi ;; uninstall) if cmdRouterConfirm uninstall "$postfixLabel" "Postfix"; then cmdPostfixUninstall fi ;; info) printTitle " $postfixLabel Info" cmdPostfixInfo ;; list) if [[ -z "$1" ]]; then printInfo " $postfixLabel List all" else printInfo " $postfixLabel List $action" fi cmdPostfixList "$@" ;; domain) printInfo " $postfixLabel Domain add" postfixDomainAdd "$@" postfixPostmapRebuild ;; alias) printInfo " $postfixLabel Set alias for domain" cmdPostfixVirtualAliasSetEx "$@" ;; dkim) printInfo " $postfixLabel DKIM record for DNS (autocreate)" postfixDkimGet "$@" ;; *) printTitle " $postfixLabel" printRow printWarning "Unsupported or empty command: $action" cmdHelpPostfix ;; esac } function cmdWorker() { local action="${1:-}" shift || true case "$action" in install) if cmdRouterConfirm install "$workerLabel" "Worker"; then cmdWorkerInstall fi ;; uninstall) if cmdRouterConfirm uninstall "$workerLabel" "Worker"; then cmdWorkerUninstall fi ;; task) printInfo " $workerLabel Run $1" reportFile="$logPath/task/${appDate}_$appTime.log" printText "Start: $appDate $appTime\n" cmdWorkerTaskHandle "$@" printText "\nFinish: $(date +%Y-%m-%d) $(date +%H-%M-%S) | Time: $(( $(date +%s) - scriptStart ))s" reportFile="" ;; list) printInfo " $workerLabel Task list" cmdWorkerTaskList ;; down) printInfo " $workerLabel Put on pause..." workerAgentStop ;; up) printInfo " $workerLabel Resuming from pause..." workerAgentStart ;; reload) printInfo " $workerLabel Reload..." cmdWorkerReload ;; *) printTitle " $workerLabel" printRow printWarning "Unsupported or empty command: $action" cmdHelpWorker ;; esac } function cmdMetric() { local action="${1:-}" shift || true case "$action" in install) if cmdRouterConfirm install "$metricLabel" "Metric"; then cmdMetricInstall fi ;; uninstall) if cmdRouterConfirm uninstall "$metricLabel" "Metric"; then cmdMetricUninstall fi ;; restart) printInfo " $metricLabel Restart" metricRestart ;; *) printTitle " $metricLabel" printRow printWarning "Unsupported or empty command: $action" cmdHelpMetric ;; esac } function cmdSite() { local action="${1:-}" shift || true case "$action" in add) printTitle " $siteLabel Add $*" cmdSiteAdd "$@" ;; add_wp|wp) printTitle " $siteLabel Add Wordpress $*" cmdSiteAddWordpress "$@" ;; remove) printTitle " $siteLabel Remove $*" cmdSiteRemove "$@" ;; copy) printTitle " $siteLabel Copy $*" cmdSiteCopy "$@" ;; rename) printTitle " $siteLabel Rename $*" cmdSiteRename "$@" ;; rebuild) printTitle " $siteLabel Rebuild config $*" cmdSiteConfigRebuild "$@" ;; rebuild_wp) printTitle " $siteLabel Wordpress config rebuild $*" cmdSiteWordpressRebuild "$@" ;; reset_pass) printTitle " $siteLabel Reset ALL passwords for vhost $*" cmdSitePasswordReset "$@" ;; reset_auth) printTitle " $siteLabel Reset ALL auth settings for vhost $*" cmdSiteAuthReset "$@" ;; dump) printTitle " $siteLabel Database dump $*" cmdSiteDatabaseDump "$@" ;; info) printTitle " $siteLabel Info $*" cmdSiteInfo "$@" ;; status) printTitle " $siteLabel Status $*" cmdSiteStatus "$@" ;; *) printTitle " $siteLabel" printRow printWarning "Unsupported or empty command: $action" cmdHelpSite ;; esac } function cmdWordpress() { local action="${1:-}" shift || true case "$action" in user) printTitle " $wordpressLabel User list" cmdWordpressUserList "$@" ;; pass) printTitle " $wordpressLabel User password set" cmdWordpressPasswordSet "$@" ;; salt) printTitle " $wordpressLabel Shuffle salts $*" cmdWordpressSalt "$@" ;; check) printTitle " $wordpressLabel Check core and plugins $*" cmdWordpressCheck "$@" ;; exec) printTitle " $wordpressLabel Command exec $*" cmdWordpressExec "$@" ;; *) printTitle " $wordpressLabel" printRow printWarning "Unsupported or empty command: $action" cmdHelpWP ;; esac } function cmdSftp() { local action="${1:-}" shift || true case "$action" in user) printTitle " $systemLabel SFTP User list $*" cmdSftpUserList "$@" ;; enable) printTitle " $systemLabel SFTP Access enable $*" # Temporarily !!!! openlitespeedVhostRebuild "$@" # Temporarily !!!! cmdSftpAccessEnable "$@" ;; disable) printTitle " $systemLabel SFTP Access disable $*" cmdSftpAccessDisable "$@" ;; reset_pass) printTitle " $systemLabel SFTP Reset pass" cmdSftpPasswordSet "$@" ;; support) printTitle " $systemLabel SFTP Adding support" printRow local confirmation read -r -p "${fontYellow}Warning!$fontReset Changes will be made to the$fontRed SSH configuration$fontReset. Make sure there is a$fontBlue backup way to connect$fontReset to the server. Continue? (y/n): " confirmation [[ ! "$confirmation" =~ ^[Yy]$ ]] && { printRow; return 0; } cmdSftpAddingSupport ;; *) printTitle " $systemLabel SFTP" printRow printWarning "Unsupported or empty command: $action" cmdHelpSftp ;; esac } function cmdCron() { local action="${1:-}" shift || true case "$action" in add) printTitle " $systemLabel Cron job add" cmdCronAdd ;; remove) printTitle " $systemLabel Cron job remove" cmdCronRemove ;; list) printTitle " $systemLabel Cron job list" cmdCronList ;; *) printTitle " $systemLabel Cron" printRow printWarning "Unsupported or empty command: $action" cmdHelpCron ;; esac } function cmdBackup() { if [[ -n "$1" ]]; then cmdBackupRun "$@" else printDanger "$backupLabel Empty command" cmdHelpBackup fi } function cmdRestore() { if [[ -n "$1" ]]; then restoreRun "$@" else printDanger "$restoreLabel Empty command" cmdHelpRestore fi } function cmdStorage() { local action="${1:-}" shift || true case "$action" in list) printTitle " $storageLabel List of backups on external storage" cmdStorageBackupList ;; compare) printTitle " $systemLabel ???" cmdStorageBackupCompare ;; sync) printTitle " $systemLabel ???" cmdStorageBackupSync "$@" ;; remove) printTitle " $systemLabel Remove of backups on external storage" cmdStorageBackupRemove ;; *) printTitle " $systemLabel Storage" printRow printWarning "Unsupported or empty command: $action" cmdHelpStorage ;; esac } function cmdInstall() { printTitle " $ks3Label Full install" printRow local confirmation read -r -p "${fontYellow}Warning!$fontReset Are you sure you want to$fontRed INSTALL$fontReset $fontBlue FULL infrastrutute$fontReset? (y/n): " confirmation [[ ! "$confirmation" =~ ^[Yy]$ ]] && { printRow; return 0; } cmdInstallFull } function cmdTest() { local action="${1:-}" shift || true case "$action" in mariadb) printInfo " $testLabel MariaDB replica" testMariadbReplica ;; redis) printInfo " $testLabel Redis cluster" testRedisCluster ;; site) printInfo " $testLabel Site" testSite ;; wordpress) printInfo " $testLabel Wordpress" testSiteWordpress ;; *) printTitle " $testLabel SFTP" printRow printWarning "Unsupported or empty command: $action" cmdHelpTest ;; esac } function cmdMalware() { local action="${1:-}" shift || true case "$action" in user) printTitle " Malware user list" cmdMalwareUserList ;; muplugin) printTitle " Malware MU plugin list" cmdMalwareMuPluginList ;; file) printTitle " Malware files list" cmdMalwareFilesCheck "$@" ;; *) printTitle " $testLabel Malware" printRow printWarning "Unsupported or empty command: $action" cmdHelpMalware ;; esac } function cmdRouter() { local action="${1:-}" shift || true printHeader case "$action" in -k|--k3s) cmdK3s "$@" ;; -m|--mariadb) cmdMariadb "$@" ;; -r|--redis) cmdRedis "$@" ;; -o|--ols) cmdOpenlitespeed "$@" ;; -p|--postfix) cmdPostfix "$@" ;; -w|--worker) cmdWorker "$@" ;; -s|--site) cmdSite "$@" ;; --metric) cmdMetric "$@" ;; --wp) cmdWordpress "$@" ;; --sftp) cmdSftp "$@" ;; --cron) cmdCron "$@" ;; --shell) printTitle " Shell $@" cmdShell "$@" ;; --log) printTitle " Log $@" cmdLog "$@" ;; --describe) printTitle " Describe $@" cmdDescribe "$@" ;; --delete) printTitle " Delete $@ $fontRed[DANGER]$fontReset" cmdDelete "$@" ;; -b|--backup) cmdBackup "$@" ;; --restore) cmdRestore "$@" ;; --storage) cmdStorage "$@" ;; --script) cmdScript "$@" ;; --install) cmdInstall "$@" ;; --test) cmdTest "$@" ;; --malware) cmdMalware "$@" ;; --help) cmdHelp "$@" ;; dev) appDev "$@" ;; esac local status=$? printFooter return "$status" }