v-update-letsencrypt-ssl 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/bin/bash
  2. # info: update letsencrypt ssl certificates
  3. # options: NONE
  4. #
  5. # The function for renew letsencrypt expired ssl certificate for all users
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Importing system enviroment as we run this script
  10. # mostly by cron wich not read it by itself
  11. source /etc/profile
  12. # Includes
  13. source $HESTIA/func/main.sh
  14. source $HESTIA/conf/hestia.conf
  15. #----------------------------------------------------------#
  16. # Action #
  17. #----------------------------------------------------------#
  18. # Defining user list
  19. users=$($BIN/v-list-users | tail -n+3 | awk '{ print $1 }')
  20. # Checking users
  21. for user in $users; do
  22. USER_DATA=$HESTIA/data/users/$user
  23. # Checking user certificates
  24. lecounter=0
  25. for domain in $(search_objects 'web' 'LETSENCRYPT' 'yes' 'DOMAIN'); do
  26. # Check if Web Domain is suspended
  27. websuspended=$(grep "DOMAIN='$domain'" $USER_DATA/web.conf |grep "SUSPENDED='no")
  28. if [ ! -z "$websuspended" ]; then
  29. continue;
  30. fi;
  31. # Check if DNS is suspended
  32. dnssuspended=$(grep "DOMAIN='$domain'" $USER_DATA/dns.conf |grep "SUSPENDED='no")
  33. if [ ! -z "$dnssuspended" ]; then
  34. continue;
  35. fi;
  36. crt="$HESTIA/data/users/$user/ssl/$domain.crt"
  37. crt_data=$(openssl x509 -text -in "$crt")
  38. expire=$(echo "$crt_data" |grep "Not After")
  39. expire=$(echo "$expire" |cut -f 2,3,4 -d :)
  40. expire=$(date -d "$expire" +%s)
  41. now=$(date +%s)
  42. expire=$((expire - now))
  43. expire=$((expire / 86400))
  44. domain=$(basename $crt |sed -e "s/.crt$//")
  45. if [[ "$expire" -lt 31 ]]; then
  46. aliases=$(echo "$crt_data" |grep DNS:)
  47. aliases=$(echo "$aliases" |sed -e "s/DNS://g" -e "s/,//")
  48. aliases=$(echo "$aliases" |tr ' ' '\n' |sed "/^$/d")
  49. aliases=$(echo "$aliases" |grep -v "^$domain$")
  50. if [ ! -z "$aliases" ]; then
  51. aliases=$(echo "$aliases" |sed -e ':a;N;$!ba;s/\n/,/g')
  52. msg=$($BIN/v-add-letsencrypt-domain $user $domain $aliases)
  53. if [ $? -ne 0 ]; then
  54. echo "$domain $msg"
  55. fi
  56. else
  57. msg==$($BIN/v-add-letsencrypt-domain $user $domain)
  58. if [ $? -ne 0 ]; then
  59. echo "$domain $msg"
  60. fi
  61. fi
  62. fi
  63. if [ $lecounter -gt 0 ]; then
  64. sleep 60
  65. fi
  66. ((lecounter++))
  67. done
  68. done
  69. #----------------------------------------------------------#
  70. # Hestia #
  71. #----------------------------------------------------------#
  72. # No Logging
  73. #log_event "$OK" "$EVENT"
  74. exit