| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- send_api_cmd() {
- if [ -z $PORT ]; then
- PORT=8083
- fi
- if [ -z $USER ]; then
- USER=admin
- fi
- auth="user=$USER&password=$PASSWORD&returncode=yes"
- cmd="cmd=$1"
- args="arg1=$2&arg2=$3&arg3=$4&arg4=$5&arg5=$6&arg6=$7&arg7=$8&arg8=$9"
- answer=$(curl -s -k --data "$auth&$cmd&$args" https://$HOST:$PORT/api/)
- if [ "$answer" != '0' ]; then
- return 1
- else
- return 0
- fi
- }
- send_ssh_cmd() {
- if [ -z $PORT ]; then
- PORT=22
- fi
- if [ -z $USER ]; then
- USER=admin
- fi
- if [ -z "$IDENTITY_FILE" ] && [ "$USER" = 'root' ]; then
- IDENTITY_FILE="/root/.ssh/id_rsa"
- fi
- if [ -z "$IDENTITY_FILE" ]; then
- IDENTITY_FILE="/home/$USER/.ssh/id_rsa"
- fi
- if [ "$USER" = 'root' ]; then
- args="$VESTA/bin/$1 \"$2\" \"$3\" \"$4\" \"$5\""
- else
- args="sudo $VESTA/bin/$1 \"$2\" \"$3\" \"$4\" \"$5\""
- fi
- ssh -i $IDENTITY_FILE $USER@$HOST -p $PORT "$args" > /dev/null 2>&1
- if [ "$?" -ne '0' ]; then
- return 1
- else
- return 0
- fi
- }
- scp_cmd() {
- if [ -z $PORT ]; then
- PORT=22
- fi
- if [ -z $USER ]; then
- USER=admin
- fi
- if [ -z "$IDENTITY_FILE" ]; then
- IDENTITY_FILE="/home/admin/.ssh/id_rsa"
- fi
- scp -P $PORT -i $IDENTITY_FILE $1 $USER@$HOST:$2 > /dev/null 2>&1
- if [ "$?" -ne '0' ]; then
- return 1
- else
- return 0
- fi
- }
- is_dnshost_new() {
- if [ -e "$VESTA/conf/dns-cluster.conf" ]; then
- check_host=$(grep "HOST='$host'" $VESTA/conf/dns-cluster.conf)
- if [ ! -z "$check_host" ]; then
- echo "Error: dns host $host exists"
- log_event "$E_EXISTS" "$EVENT"
- exit $E_EXISTS
- fi
- fi
- }
- is_dnshost_alive() {
- HOST=$host
- PORT=$port
- USER=$user
- PASSWORD=$password
- # Switch on connection type
- case $type in
- ssh) send_cmd="send_ssh_cmd" ;;
- *) send_cmd="send_api_cmd" ;;
- esac
- # Check host connection
- $send_cmd v-list-sys-config
- if [ $? -ne 0 ]; then
- echo "Error: $type connection to $HOST failed"
- log_event "$E_CONNECT $EVENT"
- exit $E_CONNECT
- fi
- # Check recipient dns user
- if [ -z "$DNS_USER" ]; then
- DNS_USER='dns-cluster'
- fi
- if [ ! -z "$verbose" ]; then
- echo "DNS_USER: $DNS_USER"
- fi
- $send_cmd v-list-user $DNS_USER
- if [ $? -ne 0 ]; then
- echo "Error: dns user $DNS_USER doesn't exist"
- log_event "$E_NOTEXIST $EVENT"
- exit $E_NOTEXIST
- fi
- }
- remote_dns_health_check() {
- # Define tmp mail vars
- subj="DNS sync failed"
- email=$(grep CONTACT $VESTA/data/users/admin/user.conf | cut -f 2 -d \')
- send_mail="$VESTA/web/inc/mail-wrapper.php"
- tmpfile=$(mktemp)
- # Starting health-check
- for str in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do
- # Get host values
- eval $str
- # Check connection type
- if [ -z "TYPE" ]; then
- TYPE='api'
- fi
- # Switch on connection type
- case $TYPE in
- ssh) send_cmd="send_ssh_cmd" ;;
- *) send_cmd="send_api_cmd" ;;
- esac
- # Check host connection
- $send_cmd v-list-sys-config
- if [ $? -ne 0 ]; then
- echo "$(basename $0) $*" > $tmpfile
- echo -e "Error: $TYPE connection to $HOST failed.\n" >> $tmpfile
- echo -n "Remote dns host has been suspended." >> $tmpfile
- echo -n "After resolving issue run " >> $tmpfile
- echo -e "following commands:\n" >> $tmpfile
- echo "v-unsuspend-remote-dns-host $HOST" >> $tmpfile
- echo "v-sync-dns-clustert $HOST" >> $tmpfile
- echo -e "\n\n--\nVesta Control Panel\n$(hostname)" >> $tmpfile
- cat $tmpfile | $send_mail -s "$subj" $email
- log_event "$E_CONNECT $EVENT"
- dconf="../../../conf/dns-cluster"
- update_object_value "$dconf" 'HOST' "$HOST" '$SUSPENDED' 'yes'
- fi
- # Remove tmp file
- rm -f $tmpfile
- done
- }
|