Przeglądaj źródła

remote dns host management

Serghey Rodin 12 lat temu
rodzic
commit
bab24899ea

+ 74 - 0
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

+ 121 - 0
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

+ 56 - 0
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

+ 1 - 1
bin/v-sync-dns-cluster

@@ -21,7 +21,7 @@ source $VESTA/func/remote.sh
 #                    Verifications                         #
 #                    Verifications                         #
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
-is_system_enabled "$DNS_CLUSTER"
+is_system_enabled "$DNS_CLUSTER" 'DNS_CLUSTER'
 
 
 if [ ! -e "$VESTA/conf/dns-cluster.conf" ]; then
 if [ ! -e "$VESTA/conf/dns-cluster.conf" ]; then
     echo "Error: dns-cluster.conf doesn't exist"
     echo "Error: dns-cluster.conf doesn't exist"

+ 1 - 1
func/main.sh

@@ -87,7 +87,7 @@ check_args() {
 # Subsystem checker
 # Subsystem checker
 is_system_enabled() {
 is_system_enabled() {
     if [ -z "$1" ] || [ "$1" = no ]; then
     if [ -z "$1" ] || [ "$1" = no ]; then
-        echo "Error: subsystem disabled"
+        echo "Error: $2 is disabled in the vesta.conf"
         log_event "$E_DISABLED" "$EVENT"
         log_event "$E_DISABLED" "$EVENT"
         exit $E_DISABLED
         exit $E_DISABLED
     fi
     fi

+ 46 - 0
func/remote.sh

@@ -61,3 +61,49 @@ scp_cmd() {
         return 0
         return 0
     fi
     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
+}