Files
SODEW/sodew-bash-main/libs/commands/router.sh
T
2026-08-18 09:40:08 +02:00

737 lines
21 KiB
Bash

# Prints a confirmation and returns 0 if confirmed.
# $1 (query): query
function cmdRouterConfirm() {
local query="$1" confirmation
printRow
read -r -p "${fontYellow}Warning!${fontReset} $query (y/n): " confirmation
[[ "$confirmation" =~ ^[Yy]$ ]]
}
function cmdK3s() {
local action="${1:-}"
shift || true
case "$action" in
install)
printTitle " $k3sLabel Install"
if cmdRouterConfirm "Are you sure you want to$fontRed INSTALL$fontBlue ALL$fontReset resources to k3s?"; then
cmdMariadbInstall
cmdRedisInstall
cmdOpenlitespeedInstall
cmdPostfixInstall
cmdWorkerInstall
cmdMetricInstall
fi
;;
uninstall)
printTitle " $k3sLabel Uninstall"
if cmdRouterConfirm "Are you sure you want to$fontRed UNINSTALL$fontBlue ALL$fontReset resources from k3s?"; then
printRow
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)
printTitle " $mariadbLabel Install"
if cmdRouterConfirm "Are you sure you want to$fontRed INSTALL$fontBlue MariaDB$fontReset resources to k3s?"; then
cmdMariadbInstall
fi
;;
update)
printTitle " $mariadbLabel Update"
if cmdRouterConfirm "Are you sure you want to$fontRed UPDATE$fontBlue MariaDB$fontReset resources in k3s?"; then
cmdMariadbUpdate
fi
;;
uninstall)
printTitle " $mariadbLabel Uninstall"
if cmdRouterConfirm "Are you sure you want to$fontRed UNINSTALL$fontBlue MariaDB$fontReset resources from k3s?"; then
printRow
cmdMariadbUninstall
fi
;;
info)
printTitle " $mariadbLabel Info"
cmdMariadbInfo
;;
status)
printTitle " $mariadbLabel Status"
cmdMariadbStatus
;;
replica)
printTitle " $mariadbLabel Replica rebuild"
if cmdRouterConfirm "Are you sure you want to$fontRed REBUILD$fontBlue MariaDB replica$fontReset?"; then
cmdMariadbReplicaRebuild
fi
;;
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)
printTitle " $redisLabel Install"
if cmdRouterConfirm "Are you sure you want to$fontRed INSTALL$fontBlue Redis$fontReset resources to k3s?"; then
cmdRedisInstall
fi
;;
update)
printTitle " $redisLabel Update"
if cmdRouterConfirm "Are you sure you want to$fontRed UPDATE$fontBlue Redis$fontReset resources in k3s?"; then
cmdRedisUpdate
fi
;;
uninstall)
printTitle " $redisLabel Uninstall"
if cmdRouterConfirm "Are you sure you want to$fontRed UNINSTALL$fontBlue Redis$fontReset resources from k3s?"; then
printRow
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)
printTitle " $openlitespeedLabel Install"
if cmdRouterConfirm "Are you sure you want to$fontRed INSTALL$fontBlue OpenLiteSpeed$fontReset resources to k3s?"; then
cmdOpenlitespeedInstall
fi
;;
update)
printTitle " $openlitespeedLabel Update"
if cmdRouterConfirm "Are you sure you want to$fontRed UPDATE$fontBlue OpenLiteSpeed$fontReset resources in k3s?"; then
cmdOpenlitespeedUpdate
fi
;;
uninstall)
printTitle " $openlitespeedLabel Uninstall"
if cmdRouterConfirm "Are you sure you want to$fontRed UNINSTALL$fontBlue OpenLiteSpeed$fontReset resources from k3s?"; then
printRow
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"
cmdOpenlitespeedVhostAliasSet "$@"
;;
restart)
printTitle " $openlitespeedLabel Restart"
cmdOpenlitespeedRestart
;;
php_kill)
printTitle " $openlitespeedLabel Kill PHP $@"
cmdOpenlitespeedPhpKill "$@"
;;
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)
printTitle " $postfixLabel Install"
if cmdRouterConfirm "Are you sure you want to$fontRed INSTALL$fontBlue Postfix$fontReset resources to k3s?"; then
cmdPostfixInstall
fi
;;
update)
printTitle " $postfixLabel Update"
if cmdRouterConfirm "Are you sure you want to$fontRed UPDATE$fontBlue Postfix$fontReset resources in k3s?"; then
cmdPostfixUpdate
fi
;;
uninstall)
printTitle " $postfixLabel Uninstall"
if cmdRouterConfirm "Are you sure you want to$fontRed UNINSTALL$fontBlue Postfix$fontReset resources from k3s?"; then
printRow
cmdPostfixUninstall
fi
;;
info)
printTitle " $postfixLabel Info"
cmdPostfixInfo
;;
status)
printTitle " $postfixLabel Status"
cmdPostfixMtaDnsCheck
;;
user)
printTitle " $postfixLabel User list"
cmdPostfixUser
;;
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)
printTitle " $workerLabel Install"
if cmdRouterConfirm "Are you sure you want to$fontRed INSTALL$fontBlue Worker$fontReset resources to k3s?"; then
cmdWorkerInstall
fi
;;
update)
printTitle " $workerLabel Update"
if cmdRouterConfirm "Are you sure you want to$fontRed UPDATE$fontBlue Worker$fontReset resources in k3s?"; then
cmdWorkerUpdate
fi
;;
uninstall)
printTitle " $workerLabel Uninstall"
if cmdRouterConfirm "Are you sure you want to$fontRed UNINSTALL$fontBlue Worker$fontReset resources from k3s?"; then
printRow
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)
printTitle " $workerLabel Task list"
cmdWorkerTaskList
;;
down)
printInfo " $workerLabel Put on pause..."
workerAgentStop
;;
up)
printInfo " $workerLabel Resuming from pause..."
workerAgentStart
;;
*)
printTitle " $workerLabel"
printRow
printWarning "Unsupported or empty command: $action"
cmdHelpWorker
;;
esac
}
function cmdMetric() {
local action="${1:-}"
shift || true
case "$action" in
install)
printTitle " $metricLabel Install"
if cmdRouterConfirm "Are you sure you want to$fontRed INSTALL$fontBlue Metric$fontReset resources to k3s?"; then
cmdMetricInstall
fi
;;
update)
printTitle " $metricLabel Update"
if cmdRouterConfirm "Are you sure you want to$fontRed UPDATE$fontBlue Metric$fontReset resources in k3s?"; then
cmdMetricUpdate
fi
;;
uninstall)
printTitle " $metricLabel Uninstall"
if cmdRouterConfirm "Are you sure you want to$fontRed UNINSTALL$fontBlue Metric$fontReset resources from k3s?"; then
printRow
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 $*"
cmdSftpAccessEnable "$@"
;;
disable)
printTitle " $systemLabel SFTP Access disable $*"
cmdSftpAccessDisable "$@"
;;
reset_pass)
printTitle " $systemLabel SFTP Reset pass"
cmdSftpPasswordSet "$@"
;;
support)
printTitle " $systemLabel SFTP Adding support"
if cmdRouterConfirm "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?"; then
cmdSftpAddingSupport
fi
;;
*)
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() {
local action="${1:-}"
shift || true
case "$action" in
run)
printTitle " $backupLabel Backup of target"
cmdBackupRun "$@"
;;
list)
printTitle " $backupLabel List of backups on local storage"
cmdBackupList
;;
size)
printTitle " $backupLabel List of Backup Sizes"
cmdBackupSize
;;
# remove)
# printTitle " $backupLabel Remove of backups on local storage"
# cmdStorageBackupRemove
# ;;
*)
printTitle " $backupLabel"
printRow
printWarning "Unsupported or empty command: $action"
cmdHelpBackup
;;
esac
}
function cmdRestore() {
local action="${1:-}"
shift || true
case "$action" in
run)
printTitle " $restoreLabel Backup of target"
restoreRun "$@"
;;
*)
printTitle " $restoreLabel"
printRow
printWarning "Unsupported or empty command: $action"
cmdHelpRestore
;;
esac
}
function cmdStorage() {
local action="${1:-}"
shift || true
case "$action" in
list)
printTitle " $storageLabel List of backups on external storage"
cmdStorageBackupList
;;
compare)
printTitle " $storageLabel Comparison table"
cmdStorageBackupCompare
;;
size)
printTitle " $storageLabel List of Backup Sizes on external storage"
cmdStorageBackupSize
;;
sync)
printTitle " $storageLabel Synchronization with external storage"
cmdStorageBackupSync "$@"
;;
remove)
printTitle " $storageLabel Remove of backups on external storage"
cmdStorageBackupRemove
;;
*)
printTitle " $storageLabel"
printRow
printWarning "Unsupported or empty command: $action"
cmdHelpStorage
;;
esac
}
# Dispatches a named script sub-command and redirects output to a timestamped log file.
# $1 (option): script name (backup, mariadb-dump, worker-observer, metric-kube, metric-sites, diag-report-ai-short, diag-report-ai-full).
function cmdScript() {
cmdScriptRun "$@"
}
function cmdInstall() {
printTitle " $ks3Label Full install"
if cmdRouterConfirm "Are you sure you want to$fontRed INSTALL$fontReset $fontBlue FULL infrastrutute$fontReset?"; then
cmdInstallFull
fi
}
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"
printRow
printWarning "Unsupported or empty command: $action"
cmdHelpTest
;;
esac
}
function cmdMalware() {
local action="${1:-}"
shift || true
case "$action" in
check)
printTitle " $malwareLabel Check"
cmdScriptMalwareCheck
;;
remove)
printTitle " $malwareLabel Remove"
cmdScriptMalwareRemove
;;
*)
printTitle " $malwareLabel"
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) cmdShell "$@" ;;
--log) cmdLog "$@" ;;
--describe) cmdDescribe "$@" ;;
--delete) cmdDelete "$@" ;;
--backup) cmdBackup "$@" ;;
--restore) cmdRestore "$@" ;;
--storage) cmdStorage "$@" ;;
--script) cmdScript "$@" ;;
--install) cmdInstall "$@" ;;
--test) cmdTest "$@" ;;
--malware) cmdMalware "$@" ;;
--help) cmdHelp "$@" ;;
dev) appDev "$@" ;;
esac
local status=$?
printFooter
return "$status"
}