v-update-letsencrypt-ssl 2.1 KB

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