test_actions.sh 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. #!/bin/bash
  2. # Define some variables
  3. source /etc/profile.d/hestia.sh
  4. V_BIN="$HESTIA/bin"
  5. V_TEST="$HESTIA/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. echo $tmpfile
  41. #----------------------------------------------------------#
  42. # User #
  43. #----------------------------------------------------------#
  44. # Add user
  45. cmd="v-add-user $user $user $user@hestiacp.com default Super Test"
  46. $cmd > $tmpfile 2>> $tmpfile
  47. echo_result "USER: Adding new user $user" "$?" "$tmpfile" "$cmd"
  48. # Change user password
  49. cmd="v-change-user-password $user t3st-p4ssw0rd"
  50. $cmd > $tmpfile 2>> $tmpfile
  51. echo_result "USER: Changing password" "$?" "$tmpfile" "$cmd"
  52. # Change user contact
  53. cmd="v-change-user-contact $user tester@hestiacp.com"
  54. $cmd > $tmpfile 2>> $tmpfile
  55. echo_result "USER: Changing email" "$?" "$tmpfile" "$cmd"
  56. # Change system shell
  57. cmd="v-change-user-shell $user bash"
  58. $cmd > $tmpfile 2>> $tmpfile
  59. echo_result "USER: Changing system shell to /bin/bash" "$?" "$tmpfile" "$cmd"
  60. # Change name servers
  61. cmd="v-change-user-ns $user ns0.com ns1.com ns2.com ns3.com"
  62. $cmd > $tmpfile 2>> $tmpfile
  63. echo_result "USER: Changing nameservers" "$?" "$tmpfile" "$cmd"
  64. #----------------------------------------------------------#
  65. # Cron #
  66. #----------------------------------------------------------#
  67. # Add cron job
  68. cmd="v-add-cron-job $user 1 1 1 1 1 echo"
  69. $cmd > $tmpfile 2>> $tmpfile
  70. echo_result "CRON: Adding cron job" "$?" "$tmpfile" "$cmd"
  71. # Suspend cron job
  72. cmd="v-suspend-cron-job $user 1"
  73. $cmd > $tmpfile 2>> $tmpfile
  74. echo_result "CRON: Suspending cron job" "$?" "$tmpfile" "$cmd"
  75. # Unsuspend cron job
  76. cmd="v-unsuspend-cron-job $user 1"
  77. $cmd > $tmpfile 2>> $tmpfile
  78. echo_result "CRON: Unsuspending cron job" "$?" "$tmpfile" "$cmd"
  79. # Delete cron job
  80. cmd="v-delete-cron-job $user 1"
  81. $cmd > $tmpfile 2>> $tmpfile
  82. echo_result "CRON: Deleting cron job" "$?" "$tmpfile" "$cmd"
  83. # Add cron job
  84. cmd="v-add-cron-job $user 1 1 1 1 1 echo 1"
  85. $cmd > $tmpfile 2>> $tmpfile
  86. echo_result "CRON: Adding cron job" "$?" "$tmpfile" "$cmd"
  87. # Add cron job
  88. cmd="v-add-cron-job $user 1 1 1 1 1 echo 1"
  89. $cmd > $tmpfile 2>> $tmpfile
  90. if [ "$?" -eq 4 ]; then
  91. retval=0
  92. else
  93. retval=1
  94. fi
  95. echo_result "CRON: Duplicate cron job check" "$retval" "$tmpfile" "$cmd"
  96. # Add second cron job
  97. cmd="v-add-cron-job $user 2 2 2 2 2 echo 2"
  98. $cmd > $tmpfile 2>> $tmpfile
  99. echo_result "CRON: Adding second cron job" "$?" "$tmpfile" "$cmd"
  100. # Rebuild cron jobs
  101. cmd="v-rebuild-cron-jobs $user"
  102. $cmd > $tmpfile 2>> $tmpfile
  103. echo_result "CRON: Rebuilding cron jobs" "$?" "$tmpfile" "$cmd"
  104. #----------------------------------------------------------#
  105. # IP #
  106. #----------------------------------------------------------#
  107. # List network interfaces
  108. cmd="v-list-sys-interfaces plain"
  109. interface=$($cmd 2> $tmpfile | head -n 1)
  110. if [ -z "$interface" ]; then
  111. echo_result "IP: Listing network interfaces" "1" "$tmpfile" "$cmd"
  112. else
  113. echo_result "IP: Listing network interfaces" "0" "$tmpfile" "$cmd"
  114. fi
  115. # Add ip address
  116. cmd="v-add-sys-ip 198.18.0.123 255.255.255.255 $interface $user"
  117. $cmd > $tmpfile 2>> $tmpfile
  118. echo_result "IP: Adding ip 198.18.0.123" "$?" "$tmpfile" "$cmd"
  119. # Add duplicate ip
  120. $cmd > $tmpfile 2>> $tmpfile
  121. if [ "$?" -eq 4 ]; then
  122. retval=0
  123. else
  124. retval=1
  125. fi
  126. echo_result "IP: Duplicate ip address check" "$retval" "$tmpfile" "$cmd"
  127. # Delete ip address
  128. cmd="v-delete-sys-ip 198.18.0.123"
  129. $cmd > $tmpfile 2>> $tmpfile
  130. echo_result "IP: Deleting ip 198.18.0.123" "$?" "$tmpfile" "$cmd"
  131. # Add ip address
  132. cmd="v-add-sys-ip 198.18.0.125 255.255.255.255 $interface $user"
  133. $cmd > $tmpfile 2>> $tmpfile
  134. echo_result "IP: Adding ip 198.18.0.125" "$?" "$tmpfile" "$cmd"
  135. #----------------------------------------------------------#
  136. # WEB #
  137. #----------------------------------------------------------#
  138. # Add web domain
  139. domain="test-$(random 4).hestiacp.com"
  140. cmd="v-add-web-domain $user $domain 198.18.0.125"
  141. $cmd > $tmpfile 2>> $tmpfile
  142. echo_result "WEB: Adding domain $domain on 198.18.0.125" "$?" "$tmpfile" "$cmd"
  143. # Add duplicate
  144. $cmd > $tmpfile 2>> $tmpfile
  145. if [ "$?" -eq 4 ]; then
  146. retval=0
  147. else
  148. retval=1
  149. fi
  150. echo_result "WEB: Duplicate web domain check" "$retval" "$tmpfile" "$cmd"
  151. # Add web domain alias
  152. cmd="v-add-web-domain-alias $user $domain v3.$domain"
  153. $cmd > $tmpfile 2>> $tmpfile
  154. echo_result "WEB: Adding alias v3.$domain" "$?" "$tmpfile" "$cmd"
  155. # Alias duplicate
  156. $cmd > $tmpfile 2>> $tmpfile
  157. if [ "$?" -eq 4 ]; then
  158. retval=0
  159. else
  160. retval=1
  161. fi
  162. echo_result "WEB: Duplicate web alias check" "$retval" "$tmpfile" "$cmd"
  163. # Add web domain stats
  164. cmd="v-add-web-domain-stats $user $domain awstats"
  165. $cmd > $tmpfile 2>> $tmpfile
  166. echo_result "WEB: Enabling awstats" "$?" "$tmpfile" "$cmd"
  167. # Add web domain stats
  168. cmd="v-add-web-domain-stats-user $user $domain test m3g4p4ssw0rd"
  169. $cmd > $tmpfile 2>> $tmpfile
  170. echo_result "WEB: Adding awstats uzer" "$?" "$tmpfile" "$cmd"
  171. # Suspend web domain
  172. cmd="v-suspend-web-domain $user $domain"
  173. $cmd > $tmpfile 2>> $tmpfile
  174. echo_result "WEB: Suspending web domain" "$?" "$tmpfile" "$cmd"
  175. # Unsuspend web domain
  176. cmd="v-unsuspend-web-domain $user $domain"
  177. $cmd > $tmpfile 2>> $tmpfile
  178. echo_result "WEB: Unsuspending web domain" "$?" "$tmpfile" "$cmd"
  179. # Add web domain ssl
  180. cp $HESTIA/ssl/certificate.crt /tmp/$domain.crt
  181. cp $HESTIA/ssl/certificate.key /tmp/$domain.key
  182. cmd="v-add-web-domain-ssl $user $domain /tmp"
  183. $cmd > $tmpfile 2>> $tmpfile
  184. echo_result "WEB: Adding ssl support" "$?" "$tmpfile" "$cmd"
  185. # Rebuild web domains
  186. cmd="v-rebuild-web-domains $user"
  187. $cmd > $tmpfile 2>> $tmpfile
  188. echo_result "WEB: rebuilding web domains" "$?" "$tmpfile" "$cmd"
  189. #----------------------------------------------------------#
  190. # DNS #
  191. #----------------------------------------------------------#
  192. # Add dns domain
  193. cmd="v-add-dns-domain $user $domain 198.18.0.125"
  194. $cmd > $tmpfile 2>> $tmpfile
  195. echo_result "DNS: Adding dns domain $domain" "$?" "$tmpfile" "$cmd"
  196. # Add duplicate
  197. $cmd > $tmpfile 2>> $tmpfile
  198. if [ "$?" -eq 4 ]; then
  199. retval=0
  200. else
  201. retval=1
  202. fi
  203. echo_result "DNS: Duplicate domain check" "$retval" "$tmpfile" "$cmd"
  204. # Add dns record
  205. cmd="v-add-dns-record $user $domain test A 198.18.0.125 20"
  206. $cmd > $tmpfile 2>> $tmpfile
  207. echo_result "DNS: Adding dns record" "$?" "$tmpfile" "$cmd"
  208. # Add duplicate
  209. $cmd > $tmpfile 2>> $tmpfile
  210. if [ "$?" -eq 4 ]; then
  211. retval=0
  212. else
  213. retval=1
  214. fi
  215. echo_result "DNS: Duplicate record check" "$retval" "$tmpfile" "$cmd"
  216. # Delete dns record
  217. cmd="v-delete-dns-record $user $domain 20"
  218. $cmd > $tmpfile 2>> $tmpfile
  219. echo_result "DNS: Deleteing dns record" "$?" "$tmpfile" "$cmd"
  220. # Change exp
  221. cmd="v-change-dns-domain-exp $user $domain 2020-01-01"
  222. $cmd > $tmpfile 2>> $tmpfile
  223. echo_result "DNS: Changing expiriation date" "$?" "$tmpfile" "$cmd"
  224. # Change ip
  225. cmd="v-change-dns-domain-ip $user $domain 127.0.0.1"
  226. $cmd > $tmpfile 2>> $tmpfile
  227. echo_result "DNS: Changing domain ip" "$?" "$tmpfile" "$cmd"
  228. # Suspend dns domain
  229. cmd="v-suspend-dns-domain $user $domain"
  230. $cmd > $tmpfile 2>> $tmpfile
  231. echo_result "DNS: Suspending domain" "$?" "$tmpfile" "$cmd"
  232. # Unuspend dns domain
  233. cmd="v-unsuspend-dns-domain $user $domain"
  234. $cmd > $tmpfile 2>> $tmpfile
  235. echo_result "DNS: Unsuspending domain" "$?" "$tmpfile" "$cmd"
  236. # Rebuild dns domain
  237. cmd="v-rebuild-dns-domains $user"
  238. $cmd > $tmpfile 2>> $tmpfile
  239. echo_result "DNS: Rebuilding domain" "$?" "$tmpfile" "$cmd"
  240. # Add mail domain
  241. cmd="v-add-mail-domain $user $domain"
  242. $cmd > $tmpfile 2>> $tmpfile
  243. echo_result "Adding mail domain $domain" "$?" "$tmpfile" "$cmd"
  244. # Add mysql database
  245. database=d$(random 4)
  246. cmd="v-add-database $user $database $database dbp4ssw0rd mysql"
  247. $cmd > $tmpfile 2>> $tmpfile
  248. echo_result "Adding mysql database $database" "$?" "$tmpfile" "$cmd"
  249. # Add pgsql database
  250. # database=d$(random 4)
  251. # cmd="v-add-database $user $database $database dbp4ssw0rd pgsql"
  252. # $cmd > $tmpfile 2>> $tmpfile
  253. # echo_result "Adding pgsql database $database" "$?" "$tmpfile" "$cmd"
  254. # Rebuild user configs
  255. cmd="v-rebuild-user $user yes"
  256. $cmd > $tmpfile 2>> $tmpfile
  257. echo_result "Rebuilding user config" "$?" "$tmpfile" "$cmd"
  258. # Delete user
  259. cmd="v-delete-user $user"
  260. $cmd > $tmpfile 2>> $tmpfile
  261. echo_result "Deleting user $user" "$?" "$tmpfile" "$cmd"
  262. # Delete ip address
  263. cmd="v-delete-sys-ip 198.18.0.125"
  264. $cmd > $tmpfile 2>> $tmpfile
  265. echo_result "Deleting ip 198.18.0.125" "$?" "$tmpfile" "$cmd"