v-update-letsencrypt-ssl 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 $VESTA/func/main.sh
  14. source $VESTA/conf/vesta.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=$VESTA/data/users/$user
  23. # Checking user certificates
  24. for domain in $(search_objects 'web' 'LETSENCRYPT' 'yes' 'DOMAIN'); do
  25. crt="$VESTA/data/users/$user/ssl/$domain.crt"
  26. # Checking certificate issuer
  27. crt_data=$(openssl x509 -text -in "$crt")
  28. expire=$(echo "$crt_data" |grep "Not After")
  29. expire=$(echo "$expire" |cut -f 2,3,4 -d :)
  30. expire=$(date -d "$expire" +%s)
  31. now=$(date +%s)
  32. expire=$((expire - now))
  33. expire=$((expire / 86400))
  34. domain=$(basename $crt |sed -e "s/.crt$//")
  35. if [[ "$expire" -lt 31 ]]; then
  36. aliases=$(echo "$crt_data" |grep DNS:)
  37. aliases=$(echo "$aliases" |sed -e "s/DNS://g" -e "s/,//")
  38. aliases=$(echo "$aliases" |tr ' ' '\n' |sed "/^$/d")
  39. aliases=$(echo "$aliases" |grep -v "^$domain$")
  40. if [ ! -z "$aliases" ]; then
  41. aliases=$(echo "$aliases" |sed -e ':a;N;$!ba;s/\n/,/g')
  42. $BIN/v-add-letsencrypt-domain $user $domain $aliases
  43. else
  44. $BIN/v-add-letsencrypt-domain $user $domain
  45. fi
  46. fi
  47. done
  48. done
  49. #----------------------------------------------------------#
  50. # Vesta #
  51. #----------------------------------------------------------#
  52. # No Logging
  53. #log_event "$OK" "$EVENT"
  54. exit