forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_actions.sh
More file actions
executable file
·133 lines (100 loc) · 2.92 KB
/
Copy pathtest_actions.sh
File metadata and controls
executable file
·133 lines (100 loc) · 2.92 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/bash
# Define some variables
source /etc/profile.d/vesta.sh
V_BIN="$VESTA/bin"
V_TEST="$VESTA/test"
# Define functions
random() {
MATRIX='0123456789'
LENGTH=$1
while [ ${n:=1} -le $LENGTH ]; do
rand="$rand${MATRIX:$(($RANDOM%${#MATRIX})):1}"
let n+=1
done
echo "$rand"
}
echo_result() {
echo -en "$1"
echo -en '\033[60G'
echo -n '['
if [ "$2" -ne 0 ]; then
echo -n 'FAILED'
echo -n ']'
echo -ne '\r\n'
echo ">>> $4"
echo ">>> RETURN VALUE $2"
cat $3
else
echo -n ' OK '
echo -n ']'
fi
echo -ne '\r\n'
}
# Create random username
user="tmp_$(random 4)"
while [ ! -z "$(grep "^$user:" /etc/passwd)" ]; do
user="tmp_$(random 4)"
done
# Create random tmpfile
tmpfile=$(mktemp -p /tmp )
# Add new user
cmd="v_add_user $user $user $user@vestacp.com default Super Test"
$cmd > $tmpfile 2>> $tmpfile
echo_result "Adding new user $user" "$?" "$tmpfile" "$cmd"
# Change system shell
cmd="v_change_user_shell $user bash"
$cmd > $tmpfile 2>> $tmpfile
echo_result "Changing system shell to /bin/bash" "$?" "$tmpfile" "$cmd"
# Change name servers
cmd="v_change_user_ns $user ns0.com ns1.com ns2.com ns3.com"
$cmd > $tmpfile 2>> $tmpfile
echo_result "Changing nameservers" "$?" "$tmpfile" "$cmd"
# Add cron job
cmd="v_add_cron_job $user 1 1 1 1 1 echo"
$cmd > $tmpfile 2>> $tmpfile
echo_result "Adding cron job" "$?" "$tmpfile" "$cmd"
# Suspend cron job
cmd="v_suspend_cron_job $user 1"
$cmd > $tmpfile 2>> $tmpfile
echo_result "Suspending cron job" "$?" "$tmpfile" "$cmd"
# Unsuspend cron job
cmd="v_unsuspend_cron_job $user 1"
$cmd > $tmpfile 2>> $tmpfile
echo_result "Unsuspending cron job" "$?" "$tmpfile" "$cmd"
# Delete cron job
cmd="v_delete_cron_job $user 1"
$cmd > $tmpfile 2>> $tmpfile
echo_result "Deleting cron job" "$?" "$tmpfile" "$cmd"
# Add cron job
cmd="v_add_cron_job $user 1 1 1 1 1 echo 1"
$cmd > $tmpfile 2>> $tmpfile
echo_result "Adding cron job" "$?" "$tmpfile" "$cmd"
# Add cron job
cmd="v_add_cron_job $user 1 1 1 1 1 echo 1"
$cmd > $tmpfile 2>> $tmpfile
if [ "$?" -eq 4 ]; then
retval=0
else
retval=1
fi
echo_result "Dublicate cron job check" "$retval" "$tmpfile" "$cmd"
# List network interfaces
cmd="v_list_sys_interfaces plain"
interface=$($cmd 2> $tmpfile | head -n 1)
if [ -z "$interface" ]; then
echo_result "Listing network interfaces" "1" "$tmpfile" "$cmd"
else
echo_result "Listing network interfaces" "0" "$tmpfile" "$cmd"
fi
# Add new ip address
cmd="v_add_sys_ip 198.18.0.123 255.255.255.255 $interface $user"
$cmd > $tmpfile 2>> $tmpfile
echo_result "Adding ip 198.18.0.123" "$?" "$tmpfile" "$cmd"
# Delete ip address
cmd="v_delete_sys_ip 198.18.0.123"
$cmd > $tmpfile 2>> $tmpfile
echo_result "Deleting ip 198.18.0.123" "$?" "$tmpfile" "$cmd"
# Delete new user
cmd="v_delete_user $user"
$cmd > $tmpfile 2>> $tmpfile
echo_result "Deleting user $user" "$?" "$tmpfile" "$cmd"