2023-08-07 15:05:54 +00:00
|
|
|
|
set -o pipefail
|
|
|
|
|
|
2023-10-04 15:17:06 +00:00
|
|
|
|
alias localip="ip addr show | grep -E '(ens|eth)' | grep -oP '"'(?<=inet\s)\d+(\.\d+){3}'"' | head -1"
|
2024-01-12 16:54:15 +00:00
|
|
|
|
ip=$(localip)
|
|
|
|
|
|
|
|
|
|
logs() {
|
|
|
|
|
if test $# -eq 0
|
|
|
|
|
then
|
|
|
|
|
lnav $(pwd | cut -d '/' -f1-5)/{logs,document_errors}
|
|
|
|
|
else
|
|
|
|
|
for site in $(find /home -maxdepth 3 -name "*$1*")
|
|
|
|
|
do cd $site
|
|
|
|
|
lnav logs
|
|
|
|
|
done
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
monitor() {
|
|
|
|
|
file=gatus.yaml
|
|
|
|
|
echo 'customer-endpoint: &customer
|
|
|
|
|
interval: 10m
|
|
|
|
|
conditions:
|
|
|
|
|
- "[STATUS] == 200"
|
|
|
|
|
endpoints:' >$file
|
|
|
|
|
for user in $(list users)
|
|
|
|
|
do group="$(hestia v-list-user $user | head -3 | cut -d':' -f2 | tr -s ' ' | sed 'N;s/\n/:/;N;s/\n / (/;s/$/)/')"
|
|
|
|
|
for domain in $(hestia v-list-web-domains $user | grep "$ip" | awk '{print $1}')
|
|
|
|
|
do echo '- name: "'$domain'"
|
|
|
|
|
<<: *customer
|
|
|
|
|
group: "'$group'"
|
|
|
|
|
url: "https://'$domain'"' >>$file
|
|
|
|
|
done
|
|
|
|
|
for domain in $(hestia v-list-mail-domains $user | tail +3 | awk '{print $1}')
|
|
|
|
|
do echo '- name: "Mail '$domain'"
|
|
|
|
|
<<: *customer
|
|
|
|
|
group: "'$group'"
|
|
|
|
|
url: "https://mail.'$domain'"' >>$file
|
|
|
|
|
done
|
|
|
|
|
done
|
|
|
|
|
}
|
2023-10-04 15:17:06 +00:00
|
|
|
|
|
|
|
|
|
letsencrypt() {
|
2023-11-04 18:12:48 +00:00
|
|
|
|
if test $# -eq 0
|
|
|
|
|
then
|
2023-10-04 15:17:06 +00:00
|
|
|
|
for user in $(list users)
|
2023-11-04 18:12:48 +00:00
|
|
|
|
do letsencrypt "$user"
|
2023-10-04 15:17:06 +00:00
|
|
|
|
done
|
2023-11-04 18:12:48 +00:00
|
|
|
|
else
|
|
|
|
|
(
|
|
|
|
|
IFS=$'\n'
|
|
|
|
|
for user
|
2023-11-07 09:58:02 +00:00
|
|
|
|
do
|
|
|
|
|
for domain in $(hestia v-list-dns-domains $user | tail +3 | awk '{print $1}')
|
|
|
|
|
do hestia v-add-remote-dns-domain $user $domain
|
|
|
|
|
done
|
|
|
|
|
for domain in $(hestia v-list-mail-domains $user | tail +3 | awk '{print $1}')
|
|
|
|
|
do hestia v-list-mail-domain-ssl $user $domain | grep -q . || hestia v-add-letsencrypt-domain $user $domain '' yes
|
|
|
|
|
done
|
2024-01-12 16:54:15 +00:00
|
|
|
|
for domain in $(hestia v-list-web-domains $user | grep "$ip" | awk '{print $1}')
|
2023-11-07 09:58:02 +00:00
|
|
|
|
do #echo commented out due to command echoing in hestia alias
|
2023-11-04 18:12:48 +00:00
|
|
|
|
#echo "Checking $user $domain" >&2
|
|
|
|
|
hestia v-list-web-domain $user $domain | grep -q REDIRECT && continue
|
2023-11-07 09:58:02 +00:00
|
|
|
|
#hestia v-list-mail-domain-ssl $user $domain | grep -q . || hestia v-add-letsencrypt-domain $user $domain '' yes
|
2024-01-12 16:54:15 +00:00
|
|
|
|
hestia v-list-web-domain-ssl $user $domain | grep . >/dev/null && continue
|
2023-11-04 18:12:48 +00:00
|
|
|
|
#echo "Generating Certificate" >&2
|
|
|
|
|
hestia v-add-letsencrypt-domain $user $domain $(hestia v-list-web-domain $user $domain | grep ALIAS | tr -s ' ' | cut -d' ' -f2- | tr ' ' ',')
|
|
|
|
|
done
|
2024-01-12 16:54:15 +00:00
|
|
|
|
echo "Waiting an hour to not trigger letsencrypt rate limits..."
|
|
|
|
|
time=0
|
|
|
|
|
while test $time -lt 2000
|
|
|
|
|
do sleep 100
|
|
|
|
|
sudo -v
|
|
|
|
|
time=$((time + 100))
|
|
|
|
|
done
|
2023-11-04 18:12:48 +00:00
|
|
|
|
done
|
|
|
|
|
)
|
|
|
|
|
fi
|
2023-10-04 15:17:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-07 15:05:54 +00:00
|
|
|
|
list() {
|
|
|
|
|
type="$1"
|
|
|
|
|
shift
|
|
|
|
|
if test $# -eq 0 && echo $type | grep -q -- '-domains$'
|
2023-10-04 15:17:06 +00:00
|
|
|
|
then for user in $(list users)
|
|
|
|
|
do if test -t 1
|
|
|
|
|
then echo "[4m$user[0m" && list "$type" "$user"
|
|
|
|
|
else list "$type" "$user" | sed "s|^|$user |"
|
|
|
|
|
fi
|
|
|
|
|
done
|
2023-08-07 15:05:54 +00:00
|
|
|
|
else if test -t 1
|
2023-10-04 15:17:06 +00:00
|
|
|
|
then sudo "$HESTIA/bin/v-list-$type" "$@" | column -t
|
2024-01-12 16:54:15 +00:00
|
|
|
|
else sudo "$HESTIA/bin/v-list-$type" "$@" | tail +3 | $(if test $type = users; then echo "grep -v yes"; else echo cat; fi) | awk '{print $1}'
|
2023-10-04 15:17:06 +00:00
|
|
|
|
fi
|
2023-08-07 15:05:54 +00:00
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hestia() {
|
2023-10-04 15:17:06 +00:00
|
|
|
|
test $# -eq 0 && cd "$HESTIA" && return 0
|
2023-11-07 09:58:02 +00:00
|
|
|
|
test "$1" = "-x" && shift && set -x
|
2023-08-07 15:05:54 +00:00
|
|
|
|
command=$1
|
|
|
|
|
shift
|
2024-01-12 16:54:15 +00:00
|
|
|
|
echo '>' sudo "$(which $command)" "$@" >&2
|
2023-11-07 09:58:02 +00:00
|
|
|
|
export SHELLOPTS
|
|
|
|
|
sudo --preserve-env=SHELLOPTS timeout 30s $(which $command) "$@"
|
|
|
|
|
set +x
|
2023-08-07 15:05:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
accessible() {
|
|
|
|
|
dir=/home/*/web/$1/public_html
|
|
|
|
|
sudo chmod -v 755 $dir
|
|
|
|
|
sudo chown -v :sudo $dir
|
|
|
|
|
}
|