test_actions.sh 8.9 KB

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