Files
gniza4cp/lib/accounts.sh
shuki 1459bd1b8b Initial commit: gniza backup & disaster recovery CLI + WHM plugin
Full-featured cPanel backup tool with SSH, S3, and Google Drive support.
Includes WHM plugin with Tailwind/DaisyUI UI, multi-remote management,
decoupled schedules, and account restore workflows.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-04 02:39:39 +02:00

63 lines
1.7 KiB
Bash

#!/usr/bin/env bash
# gniza/lib/accounts.sh — cPanel account discovery, include/exclude filtering
get_all_accounts() {
if [[ -f /etc/trueuserdomains ]]; then
awk '{print $2}' /etc/trueuserdomains | sort -u
elif command -v whmapi1 &>/dev/null; then
whmapi1 listaccts --output=jsonpretty 2>/dev/null \
| grep -oP '"user"\s*:\s*"\K[^"]+' | sort -u
else
die "Cannot discover cPanel accounts: /etc/trueuserdomains not found and whmapi1 unavailable"
fi
}
filter_accounts() {
local all_accounts="$1"
local filtered=()
# Build exclude list
local -A excludes
if [[ -n "$EXCLUDE_ACCOUNTS" ]]; then
IFS=',' read -ra exc_arr <<< "$EXCLUDE_ACCOUNTS"
for acc in "${exc_arr[@]}"; do
acc=$(echo "$acc" | xargs) # trim whitespace
[[ -n "$acc" ]] && excludes["$acc"]=1
done
fi
# If INCLUDE_ACCOUNTS is set, only include those
if [[ -n "$INCLUDE_ACCOUNTS" ]]; then
IFS=',' read -ra inc_arr <<< "$INCLUDE_ACCOUNTS"
for acc in "${inc_arr[@]}"; do
acc=$(echo "$acc" | xargs)
[[ -n "$acc" && -z "${excludes[$acc]:-}" ]] && filtered+=("$acc")
done
else
while IFS= read -r acc; do
[[ -n "$acc" && -z "${excludes[$acc]:-}" ]] && filtered+=("$acc")
done <<< "$all_accounts"
fi
printf '%s\n' "${filtered[@]}"
}
get_backup_accounts() {
local all; all=$(get_all_accounts)
filter_accounts "$all"
}
get_account_homedir() {
local user="$1"
if [[ -f /etc/passwd ]]; then
getent passwd "$user" | cut -d: -f6
else
echo "/home/$user"
fi
}
account_exists() {
local user="$1"
id "$user" &>/dev/null
}