You didn’t say what’s the info you want to get when listing the web domains but if you want to see the user, the domain, the alias and the ip, take a look to this:
for user in $(v-list-users plain | cut -f1);do v-list-web-domains $user json | jq --arg user "$user" -r 'to_entries[] | "\($user)|\(.key)|\(.value.ALIAS)|\(.value.IP)"';done | column -t -s '|' -N USER,DOMAIN,ALIAS,IP
If you are going to use the command via rest api, remember that your command should start by v-. If you add it with a new name like v-list-web-domains-etfz it won’t be overwritten on next update so it should be safe to use.
source /etc/hestiacp/hestia.conf
source $HESTIA/func/main.sh
source_conf "$HESTIA/conf/hestia.conf"
IFS=$'\n'
i=1
objects=$(/usr/local/hestia/bin/v-list-users plain | cut -f1 | wc -l)
echo "{"
for user in $(/usr/local/hestia/bin/v-list-users plain | cut -f1); do
echo -n "\"$user\": "
/usr/local/hestia/bin/v-list-web-domains $user json
if [ "$i" -lt "$objects" ]; then
echo ','
else
echo
fi
((i++))
done
echo '}'
Unfortunately, it is rather slow, with each user taking around 0.1 s to process. With a couple of dozen users this means the request takes several seconds. It might actually be faster just to use the existing API to first list all users, and then list all user domains concurrently, which I can do more easily in my application.
If you want something faster and json output, I made this script to check web.conf files directly:
echo "{"
for i in /usr/local/hestia/data/users/*; do
user="$(basename "$i")"
web="$i/web.conf"
input_file="$web"
if ! grep -q 'DOMAIN' "$input_file" &>/dev/null; then
continue
fi
json_output+="\"$user\": ["
while IFS= read -r line; do
declare -A values
for pair in $line; do
key="${pair%%=*}"
value="${pair#*=}"
value="${value//\'/}"
values[$key]="$value"
done
domain="${values[DOMAIN]}"
json_line="{ \"$domain\": {"
for key in "${!values[@]}"; do
json_line+="\"$key\": \"${values[$key]}\", "
done
json_line="${json_line%, } }},"
json_output+="$json_line"
unset values
done <"$input_file"
json_output="$(sed -E 's/\}\},$/\}\}\],/' <<<"$json_output")"
done
json_output="${json_output%,}"
echo "$json_output"
echo "}"
Edit: to avoid json corruption, I’ve added a check just in case the user doesn’t have web domains assigned.