v-list-sys-webmail 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/bin/bash
  2. # info: listing available webmail clients
  3. # options: [FORMAT]
  4. # labels: hestia mail
  5. #
  6. # example: v-list-sys-webmail
  7. #
  8. # List available webmail clients
  9. #----------------------------------------------------------#
  10. # Variable&Function #
  11. #----------------------------------------------------------#
  12. # Argument definition
  13. format=${1-shell}
  14. # Includes
  15. # shellcheck source=/usr/local/hestia/func/main.sh
  16. source $HESTIA/func/main.sh
  17. # shellcheck source=/usr/local/hestia/conf/hestia.conf
  18. source $HESTIA/conf/hestia.conf
  19. # JSON list function
  20. json_list() {
  21. i=1
  22. objects=$(echo -e "${WEBMAIL_SYSTEM//,/\\n}" |wc -l)
  23. echo '['
  24. for client in ${WEBMAIL_SYSTEM//,/ };do
  25. if [ "$i" -ne "$objects" ]; then
  26. echo -e "\t\"$client\","
  27. else
  28. echo -e "\t\"$client\""
  29. fi
  30. (( ++i))
  31. done
  32. echo ']'
  33. }
  34. # SHELL list function
  35. shell_list() {
  36. echo "Webmail Client"
  37. echo "--------"
  38. for client in ${WEBMAIL_SYSTEM//,/ };do
  39. echo "$client"
  40. done
  41. }
  42. # PLAIN list function
  43. plain_list() {
  44. for client in ${WEBMAIL_SYSTEM//,/ };do
  45. echo "$client"
  46. done
  47. }
  48. # CSV list function
  49. csv_list() {
  50. echo "CLIENT"
  51. for client in ${WEBMAIL_SYSTEM//,/ };do
  52. echo "$client"
  53. done
  54. }
  55. #----------------------------------------------------------#
  56. # Action #
  57. #----------------------------------------------------------#
  58. # Listing data
  59. case $format in
  60. json) json_list ;;
  61. plain) plain_list ;;
  62. csv) csv_list ;;
  63. shell) shell_list ;;
  64. esac
  65. #----------------------------------------------------------#
  66. # Hestia #
  67. #----------------------------------------------------------#
  68. exit