test_actions.sh 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. #!/bin/bash
  2. # Define some variables
  3. source /etc/profile.d/vesta.sh
  4. V_BIN="$VESTA/bin"
  5. V_TEST="$VESTA/test"
  6. # Define functions
  7. random() {
  8. MATRIX='0123456789'
  9. LENGTH=$1
  10. while [ ${n:=1} -le $LENGTH ]; do
  11. rand="$rand${MATRIX:$(($RANDOM%${#MATRIX})):1}"
  12. let n+=1
  13. done
  14. echo "$rand"
  15. }
  16. echo_result() {
  17. echo -en "$1"
  18. echo -en '\033[60G'
  19. echo -n '['
  20. if [ "$2" -ne 0 ]; then
  21. echo -n 'FAILED'
  22. echo -n ']'
  23. echo -ne '\r\n'
  24. echo ">>> $4"
  25. echo ">>> RETURN VALUE $2"
  26. cat $3
  27. else
  28. echo -n ' OK '
  29. echo -n ']'
  30. fi
  31. echo -ne '\r\n'
  32. }
  33. # Create random username
  34. user="testu_$(random 4)"
  35. while [ ! -z "$(grep "^$user:" /etc/passwd)" ]; do
  36. user="tmp_$(random 4)"
  37. done
  38. # Create random tmpfile
  39. tmpfile=$(mktemp -p /tmp )
  40. #----------------------------------------------------------#
  41. # User #
  42. #----------------------------------------------------------#
  43. # Add user
  44. cmd="v_add_user $user $user $user@vestacp.com default Super Test"
  45. $cmd > $tmpfile 2>> $tmpfile
  46. echo_result "USER: Adding new user $user" "$?" "$tmpfile" "$cmd"
  47. # Change user password
  48. cmd="v_change_user_password $user t3st_p4ssw0rd"
  49. $cmd > $tmpfile 2>> $tmpfile
  50. echo_result "USER: Changing password" "$?" "$tmpfile" "$cmd"
  51. # Change user contact
  52. cmd="v_change_user_contact $user tester@vestacp.com"
  53. $cmd > $tmpfile 2>> $tmpfile
  54. echo_result "USER: Changing email" "$?" "$tmpfile" "$cmd"
  55. # Change system shell
  56. cmd="v_change_user_shell $user bash"
  57. $cmd > $tmpfile 2>> $tmpfile
  58. echo_result "USER: Changing system shell to /bin/bash" "$?" "$tmpfile" "$cmd"
  59. # Change name servers
  60. cmd="v_change_user_ns $user ns0.com ns1.com ns2.com ns3.com"
  61. $cmd > $tmpfile 2>> $tmpfile
  62. echo_result "USER: Changing nameservers" "$?" "$tmpfile" "$cmd"
  63. #----------------------------------------------------------#
  64. # Cron #
  65. #----------------------------------------------------------#
  66. # Add cron job
  67. cmd="v_add_cron_job $user 1 1 1 1 1 echo"
  68. $cmd > $tmpfile 2>> $tmpfile
  69. echo_result "CRON: Adding cron job" "$?" "$tmpfile" "$cmd"
  70. # Suspend cron job
  71. cmd="v_suspend_cron_job $user 1"
  72. $cmd > $tmpfile 2>> $tmpfile
  73. echo_result "CRON: Suspending cron job" "$?" "$tmpfile" "$cmd"
  74. # Unsuspend cron job
  75. cmd="v_unsuspend_cron_job $user 1"
  76. $cmd > $tmpfile 2>> $tmpfile
  77. echo_result "CRON: Unsuspending cron job" "$?" "$tmpfile" "$cmd"
  78. # Delete cron job
  79. cmd="v_delete_cron_job $user 1"
  80. $cmd > $tmpfile 2>> $tmpfile
  81. echo_result "CRON: Deleting cron job" "$?" "$tmpfile" "$cmd"
  82. # Add cron job
  83. cmd="v_add_cron_job $user 1 1 1 1 1 echo 1"
  84. $cmd > $tmpfile 2>> $tmpfile
  85. echo_result "CRON: Adding cron job" "$?" "$tmpfile" "$cmd"
  86. # Add cron job
  87. cmd="v_add_cron_job $user 1 1 1 1 1 echo 1"
  88. $cmd > $tmpfile 2>> $tmpfile
  89. if [ "$?" -eq 4 ]; then
  90. retval=0
  91. else
  92. retval=1
  93. fi
  94. echo_result "CRON: Dublicate cron job check" "$retval" "$tmpfile" "$cmd"
  95. # Add second cron job
  96. cmd="v_add_cron_job $user 2 2 2 2 2 echo 2"
  97. $cmd > $tmpfile 2>> $tmpfile
  98. echo_result "CRON: Adding second cron job" "$?" "$tmpfile" "$cmd"
  99. # Rebuild cron jobs
  100. cmd="v_rebuild_cron_jobs $user"
  101. $cmd > $tmpfile 2>> $tmpfile
  102. echo_result "CRON: Rebuilding cron jobs" "$?" "$tmpfile" "$cmd"
  103. #----------------------------------------------------------#
  104. # IP #
  105. #----------------------------------------------------------#
  106. # List network interfaces
  107. cmd="v_list_sys_interfaces plain"
  108. interface=$($cmd 2> $tmpfile | head -n 1)
  109. if [ -z "$interface" ]; then
  110. echo_result "IP: Listing network interfaces" "1" "$tmpfile" "$cmd"
  111. else
  112. echo_result "IP: Listing network interfaces" "0" "$tmpfile" "$cmd"
  113. fi
  114. # Add ip address
  115. cmd="v_add_sys_ip 198.18.0.123 255.255.255.255 $interface $user"
  116. $cmd > $tmpfile 2>> $tmpfile
  117. echo_result "IP: Adding ip 198.18.0.123" "$?" "$tmpfile" "$cmd"
  118. # Add dublicate ip
  119. $cmd > $tmpfile 2>> $tmpfile
  120. if [ "$?" -eq 4 ]; then
  121. retval=0
  122. else
  123. retval=1
  124. fi
  125. echo_result "IP: Dublicate ip address check" "$retval" "$tmpfile" "$cmd"
  126. # Delete ip address
  127. cmd="v_delete_sys_ip 198.18.0.123"
  128. $cmd > $tmpfile 2>> $tmpfile
  129. echo_result "IP: Deleting ip 198.18.0.123" "$?" "$tmpfile" "$cmd"
  130. # Add ip address
  131. cmd="v_add_sys_ip 198.18.0.125 255.255.255.255 $interface $user"
  132. $cmd > $tmpfile 2>> $tmpfile
  133. echo_result "IP: Adding ip 198.18.0.125" "$?" "$tmpfile" "$cmd"
  134. #----------------------------------------------------------#
  135. # WEB #
  136. #----------------------------------------------------------#
  137. # Add web domain
  138. domain="test-$(random 4).vestacp.com"
  139. cmd="v_add_web_domain $user $domain 198.18.0.125"
  140. $cmd > $tmpfile 2>> $tmpfile
  141. echo_result "WEB: Adding domain $domain on 198.18.0.125" "$?" "$tmpfile" "$cmd"
  142. # Add dublicate
  143. $cmd > $tmpfile 2>> $tmpfile
  144. if [ "$?" -eq 4 ]; then
  145. retval=0
  146. else
  147. retval=1
  148. fi
  149. echo_result "WEB: Dublicate web domain check" "$retval" "$tmpfile" "$cmd"
  150. # Add web domain alias
  151. cmd="v_add_web_domain_alias $user $domain v3.$domain"
  152. $cmd > $tmpfile 2>> $tmpfile
  153. echo_result "WEB: Adding alias v3.$domain" "$?" "$tmpfile" "$cmd"
  154. # Alias dublicate
  155. $cmd > $tmpfile 2>> $tmpfile
  156. if [ "$?" -eq 4 ]; then
  157. retval=0
  158. else
  159. retval=1
  160. fi
  161. echo_result "WEB: Dublicate web alias check" "$retval" "$tmpfile" "$cmd"
  162. # Add web domain elog
  163. cmd="v_add_web_domain_elog $user $domain"
  164. $cmd > $tmpfile 2>> $tmpfile
  165. echo_result "WEB: Enabling error logging support" "$?" "$tmpfile" "$cmd"
  166. # Disabling cgi
  167. cmd="v_delete_web_domain_cgi $user $domain"
  168. $cmd > $tmpfile 2>> $tmpfile
  169. echo_result "WEB: Disabling cgi support" "$?" "$tmpfile" "$cmd"
  170. # Add web domain stats
  171. cmd="v_add_web_domain_stats $user $domain webalizer"
  172. $cmd > $tmpfile 2>> $tmpfile
  173. echo_result "WEB: Enabling webalizer" "$?" "$tmpfile" "$cmd"
  174. # Add web domain stats
  175. cmd="v_add_web_domain_stats_user $user $domain test m3g4p4ssw0rd"
  176. $cmd > $tmpfile 2>> $tmpfile
  177. echo_result "WEB: Adding webalizer uzer" "$?" "$tmpfile" "$cmd"
  178. # Add web domain nginx
  179. cmd="v_add_web_domain_nginx $user $domain"
  180. $cmd > $tmpfile 2>> $tmpfile
  181. echo_result "WEB: Enabling nginx support" "$?" "$tmpfile" "$cmd"
  182. # Suspend web domain
  183. cmd="v_suspend_web_domain $user $domain"
  184. $cmd > $tmpfile 2>> $tmpfile
  185. echo_result "WEB: Suspending web domain" "$?" "$tmpfile" "$cmd"
  186. # Unsuspend web domain
  187. cmd="v_unsuspend_web_domain $user $domain"
  188. $cmd > $tmpfile 2>> $tmpfile
  189. echo_result "WEB: Unsuspending web domain" "$?" "$tmpfile" "$cmd"
  190. # Add web domain ssl
  191. cp $V_TEST/ssl/crt /tmp/$domain.crt
  192. cp $V_TEST/ssl/key /tmp/$domain.key
  193. cmd="v_add_web_domain_ssl $user $domain /tmp"
  194. $cmd > $tmpfile 2>> $tmpfile
  195. echo_result "WEB: Adding ssl support" "$?" "$tmpfile" "$cmd"
  196. # Rebuild web domains
  197. cmd="v_rebuild_web_domains $user"
  198. $cmd > $tmpfile 2>> $tmpfile
  199. echo_result "WEB: rebuilding web domains" "$?" "$tmpfile" "$cmd"
  200. #----------------------------------------------------------#
  201. # DNS #
  202. #----------------------------------------------------------#
  203. # Add dns domain
  204. cmd="v_add_dns_domain $user $domain 198.18.0.125"
  205. $cmd > $tmpfile 2>> $tmpfile
  206. echo_result "DNS: Adding dns domain $domain" "$?" "$tmpfile" "$cmd"
  207. # Add dublicate
  208. $cmd > $tmpfile 2>> $tmpfile
  209. if [ "$?" -eq 4 ]; then
  210. retval=0
  211. else
  212. retval=1
  213. fi
  214. echo_result "DNS: Dublicate domain check" "$retval" "$tmpfile" "$cmd"
  215. # Add dns domain record
  216. cmd="v_add_dns_domain_record $user $domain test A 198.18.0.125 20"
  217. $cmd > $tmpfile 2>> $tmpfile
  218. echo_result "DNS: Adding dns domain record" "$?" "$tmpfile" "$cmd"
  219. # Add dublicate
  220. $cmd > $tmpfile 2>> $tmpfile
  221. if [ "$?" -eq 4 ]; then
  222. retval=0
  223. else
  224. retval=1
  225. fi
  226. echo_result "DNS: Dublicate record check" "$retval" "$tmpfile" "$cmd"
  227. # Delete dns domain record
  228. cmd="v_delete_dns_domain_record $user $domain 20"
  229. $cmd > $tmpfile 2>> $tmpfile
  230. echo_result "DNS: Deleteing dns domain record" "$?" "$tmpfile" "$cmd"
  231. # Change exp
  232. cmd="v_change_dns_domain_exp $user $domain 2020-01-01"
  233. $cmd > $tmpfile 2>> $tmpfile
  234. echo_result "DNS: Changing expiriation date" "$?" "$tmpfile" "$cmd"
  235. # Change ip
  236. cmd="v_change_dns_domain_ip $user $domain 127.0.0.1"
  237. $cmd > $tmpfile 2>> $tmpfile
  238. echo_result "DNS: Changing domain ip" "$?" "$tmpfile" "$cmd"
  239. # Suspend dns domain
  240. cmd="v_suspend_dns_domain $user $domain"
  241. $cmd > $tmpfile 2>> $tmpfile
  242. echo_result "DNS: Suspending domain" "$?" "$tmpfile" "$cmd"
  243. # Unuspend dns domain
  244. cmd="v_unsuspend_dns_domain $user $domain"
  245. $cmd > $tmpfile 2>> $tmpfile
  246. echo_result "DNS: Unsuspending domain" "$?" "$tmpfile" "$cmd"
  247. # Rebuild dns domain
  248. cmd="v_rebuild_dns_domains $user"
  249. $cmd > $tmpfile 2>> $tmpfile
  250. echo_result "DNS: Rebuilding domain" "$?" "$tmpfile" "$cmd"
  251. # Add mail domain
  252. cmd="v_add_mail_domain $user $domain"
  253. $cmd > $tmpfile 2>> $tmpfile
  254. echo_result "Adding mail domain $domain" "$?" "$tmpfile" "$cmd"
  255. # Add mysql database
  256. database=d$(random 4)
  257. cmd="v_add_database $user $database $database dbp4ssw0rd mysql"
  258. $cmd > $tmpfile 2>> $tmpfile
  259. echo_result "Adding mysql database $database" "$?" "$tmpfile" "$cmd"
  260. # Add pgsql database
  261. database=d$(random 4)
  262. cmd="v_add_database $user $database $database dbp4ssw0rd pgsql"
  263. $cmd > $tmpfile 2>> $tmpfile
  264. echo_result "Adding pgsql database $database" "$?" "$tmpfile" "$cmd"
  265. # Rebuild user configs
  266. cmd="v_rebuild_user $user yes"
  267. $cmd > $tmpfile 2>> $tmpfile
  268. echo_result "Rebuilding user config" "$?" "$tmpfile" "$cmd"
  269. # Delete user
  270. cmd="v_delete_user $user"
  271. $cmd > $tmpfile 2>> $tmpfile
  272. echo_result "Deleting user $user" "$?" "$tmpfile" "$cmd"
  273. # Delete ip address
  274. cmd="v_delete_sys_ip 198.18.0.125"
  275. $cmd > $tmpfile 2>> $tmpfile
  276. echo_result "Deleting ip 198.18.0.125" "$?" "$tmpfile" "$cmd"