forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremote.sh
More file actions
109 lines (100 loc) · 2.5 KB
/
remote.sh
File metadata and controls
109 lines (100 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
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
}