diff --git a/bin/v-add-remote-dns-host b/bin/v-add-remote-dns-host new file mode 100755 index 000000000..1e1ecc3dd --- /dev/null +++ b/bin/v-add-remote-dns-host @@ -0,0 +1,74 @@ +#!/bin/bash +# info: add new remote dns host +# options: HOST PORT USER PASSWORD [TYPE] [DNS_USER] +# +# The function adds remote dns server to the dns cluster. + + +#----------------------------------------------------------# +# Variable&Function # +#----------------------------------------------------------# + +# Argument defenition +host=$1 +port=$2 +user=$3 +password=$4 +type=${5-api} +dns_user=${6-dns-cluster} + +# Includes +source $VESTA/conf/vesta.conf +source $VESTA/func/main.sh +source $VESTA/func/remote.sh + +# Hiding passwords +A4='******' + + +#----------------------------------------------------------# +# Verifications # +#----------------------------------------------------------# + +args_usage='HOST PORT USER PASSWORD [TYPE] [DNS_USER]' +check_args '4' "$#" "$args_usage" +validate_format 'host' 'port' 'user' 'password' 'type' 'dns_user' +is_system_enabled "$DNS_SYSTEM" +is_dnshost_new +is_dnshost_alive + + +#----------------------------------------------------------# +# Action # +#----------------------------------------------------------# + +# Concatentating db host string +str="HOST='$host' USER='$user' PASSWORD='$password' DNS_USER='$dns_user'" +str="$str TYPE='$type' SUSPENDED='no' TIME='$TIME' DATE='$DATE'" + +# Adding host to dns-cluster.conf +echo "$str" >> $VESTA/conf/dns-cluster.conf +chmod 660 $VESTA/conf/dns-cluster.conf + +# Enabling DNS_CLUSTER +if [ -z "$(grep DNS_CLUSTER $VESTA/conf/vesta.conf)" ]; then + sed -i "s/^STATS_/DNS_CLUSTER='yes'\nSTATS_/g" $VESTA/conf/vesta.conf +else + sed -i "s/DNS_CLUSTER=.*/DNS_CLUSTER='yes'/g" $VESTA/conf/vesta.conf +fi + +# Sync current zones +$BIN/v-sync-dns-cluster +return_code=$? +if [ "$return_code" -ne 0 ]; then + exit $return_code +fi + +#----------------------------------------------------------# +# Vesta # +#----------------------------------------------------------# + +# Logging +log_event "$OK" "$EVENT" + +exit diff --git a/bin/v-delete-remote-dns-domains b/bin/v-delete-remote-dns-domains new file mode 100755 index 000000000..5faa910b4 --- /dev/null +++ b/bin/v-delete-remote-dns-domains @@ -0,0 +1,121 @@ +#!/bin/bash +# info: delete remote dns domains +# options: [HOST] +# The function deletes remote dns domains. + + +#----------------------------------------------------------# +# Variable&Function # +#----------------------------------------------------------# + +# Argument defenition +host=$1 + +# Includes +source $VESTA/conf/vesta.conf +source $VESTA/func/main.sh +source $VESTA/func/remote.sh + + +#----------------------------------------------------------# +# Verifications # +#----------------------------------------------------------# + +is_system_enabled "$DNS_CLUSTER" 'DNS_CLUSTER' + +if [ ! -e "$VESTA/conf/dns-cluster.conf" ]; then + echo "Error: dns-cluster.conf doesn't exist" + log_event "$E_NOTEXIST $EVENT" + exit $E_NOTEXIST +fi + +number_of_proc=$(ps auxf | grep -v grep | grep $VESTA/bin/$SCRIPT | wc -l) +if [ "$number_of_proc" -gt 2 ]; then + echo "Error: another sync process already exists" + log_event "$E_EXISTS $EVENT" + exit $E_EXISTS +fi + + +#----------------------------------------------------------# +# Action # +#----------------------------------------------------------# + +old_ifs="$IFS" +IFS=$'\n' + +if [ -z $host ]; then + hosts=$(cat $VESTA/conf/dns-cluster.conf) +else + hosts=$(grep "HOST='$host'" $VESTA/conf/dns-cluster.conf) +fi + +# Starting cluster loop +for cluster_str in $hosts; do + + # Get host values + eval $cluster_str + + # Check connection type + if [ -z "TYPE" ]; then + TYPE='api' + fi + + # Print hostname + if [ ! -z "$verbose" ]; then + echo "HOSTNAME: $HOSTNAME" + echo "TYPE: $TYPE" + 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 "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 + + # Clean source records + $send_cmd v-delete-dns-domains-src $DNS_USER $HOSTNAME no + if [ $? -ne 0 ]; then + echo "Error: $TYPE connection to $HOST failed (cleanup)" + log_event "$E_CONNECT $EVENT" + exit $E_CONNECT + fi + + # Rebuild dns zones + $send_cmd v-rebuild-dns-domains $DNS_USER + if [ $? -ne 0 ]; then + echo "Error: $TYPE connection to $HOST failed (rebuild)" + log_event "$E_CONNECT $EVENT" + exit $E_CONNECT + fi + +done + + +#----------------------------------------------------------# +# Vesta # +#----------------------------------------------------------# + +exit diff --git a/bin/v-delete-remote-dns-host b/bin/v-delete-remote-dns-host new file mode 100755 index 000000000..9eaa980c2 --- /dev/null +++ b/bin/v-delete-remote-dns-host @@ -0,0 +1,56 @@ +#!/bin/bash +# info: delete remote dns host +# options: HOST +# +# The function for deleting the remote dns host from vesta configuration. + + +#----------------------------------------------------------# +# Variable&Function # +#----------------------------------------------------------# + +# Argument defenition +host=$1 + +# Includes +source $VESTA/conf/vesta.conf +source $VESTA/func/main.sh + + +#----------------------------------------------------------# +# Verifications # +#----------------------------------------------------------# + +check_args '1' "$#" 'HOST' +validate_format 'host' +is_system_enabled "$DNS_CLUSTER" 'DNS_CLUSTER' +is_object_valid "../../conf/dns-cluster" 'HOST' "$host" + + +#----------------------------------------------------------# +# Action # +#----------------------------------------------------------# + +# Deleting domains +$BIN/v-delete-remote-dns-domains $host >>/dev/null 2>&1 + +# Deleting server +sed -i "/HOST='$host' /d" $VESTA/conf/dns-cluster.conf + +# Disabling DNS_CLUSTER +check_cluster=$(grep HOST $VESTA/conf/dns-cluster.conf |wc -l) +if [ "$check_cluster" -eq '0' ]; then + rm -f $VESTA/conf/dns-cluster.conf + sed -i "/DNS_CLUSTER=/d" $VESTA/conf/vesta.conf +fi + + +#----------------------------------------------------------# +# Vesta # +#----------------------------------------------------------# + +# Logging +log_history "deleted $type database server $host" '' 'admin' +log_event "$OK" "$EVENT" + +exit diff --git a/bin/v-sync-dns-cluster b/bin/v-sync-dns-cluster index 61051af45..4eaaa6256 100755 --- a/bin/v-sync-dns-cluster +++ b/bin/v-sync-dns-cluster @@ -21,7 +21,7 @@ source $VESTA/func/remote.sh # Verifications # #----------------------------------------------------------# -is_system_enabled "$DNS_CLUSTER" +is_system_enabled "$DNS_CLUSTER" 'DNS_CLUSTER' if [ ! -e "$VESTA/conf/dns-cluster.conf" ]; then echo "Error: dns-cluster.conf doesn't exist" diff --git a/func/main.sh b/func/main.sh index 7940241aa..0f3bc6abb 100644 --- a/func/main.sh +++ b/func/main.sh @@ -87,7 +87,7 @@ check_args() { # Subsystem checker is_system_enabled() { if [ -z "$1" ] || [ "$1" = no ]; then - echo "Error: subsystem disabled" + echo "Error: $2 is disabled in the vesta.conf" log_event "$E_DISABLED" "$EVENT" exit $E_DISABLED fi diff --git a/func/remote.sh b/func/remote.sh index 2a2ab249e..be3013810 100644 --- a/func/remote.sh +++ b/func/remote.sh @@ -61,3 +61,49 @@ scp_cmd() { 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 +}