pagination of vcenter queries
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2026-02-13 14:04:28 +11:00
parent 1b052b93b6
commit 5cd8f9c2a1
2 changed files with 293 additions and 326 deletions

View File

@@ -1,6 +1,8 @@
#!/bin/bash
USER="vctp"
GROUP="dtms"
CONFIG_FILE="/etc/dtms/vctp.yml"
DEFAULT_PORT=9443
# Path to the custom sudoers file
SUDOERS_FILE="/etc/sudoers.d/${USER}"
@@ -28,15 +30,35 @@ getent passwd "$USER" >/dev/null || useradd -r -g "$GROUP" -m -s /bin/bash -c "v
# set group ownership on vctp data directory if not already done
[ "$(stat -c "%G" /var/lib/vctp)" = "$GROUP" ] || chgrp -R "$GROUP" /var/lib/vctp
# Resolve effective application port from existing config (if present).
# Falls back to 9443 when the config file is missing/empty or bind_port is invalid.
APP_PORT="$DEFAULT_PORT"
if [ -s "$CONFIG_FILE" ]; then
CONFIGURED_PORT="$(awk '
/^[[:space:]]*#/ { next }
/^[[:space:]]*bind_port[[:space:]]*:/ {
line=$0
sub(/^[[:space:]]*bind_port[[:space:]]*:[[:space:]]*/, "", line)
sub(/[[:space:]]*#.*/, "", line)
gsub(/["'\''[:space:]]/, "", line)
if (line ~ /^[0-9]+$/) {
print line
exit
}
}
' "$CONFIG_FILE")"
if [ -n "$CONFIGURED_PORT" ] && [ "$CONFIGURED_PORT" -ge 1 ] && [ "$CONFIGURED_PORT" -le 65535 ]; then
APP_PORT="$CONFIGURED_PORT"
fi
fi
# Check if firewalld is installed and active
if command -v systemctl >/dev/null 2>&1 && systemctl is-enabled firewalld >/dev/null 2>&1 && systemctl is-active firewalld >/dev/null 2>&1; then
echo "Firewalld is enabled and running. Adding necessary ports..."
echo "Firewalld is enabled and running. Opening vCTP port ${APP_PORT}/tcp..."
# Open HTTPS port (443/tcp)
firewall-cmd --permanent --add-service=https >/dev/null 2>&1
# Open custom application port (9443/tcp)
firewall-cmd --permanent --add-port=9443/tcp >/dev/null 2>&1
# Open effective application port.
firewall-cmd --permanent --add-port="${APP_PORT}/tcp" >/dev/null 2>&1
# Reload firewalld to apply changes
firewall-cmd --reload >/dev/null 2>&1