v-update-letsencrypt-ssl 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. lecounter=0
  19. # Checking user certificates
  20. for user in $($BIN/v-list-users plain |cut -f 1); do
  21. USER_DATA=$VESTA/data/users/$user
  22. for domain in $(search_objects 'web' 'LETSENCRYPT' 'yes' 'DOMAIN'); do
  23. crt_data=$(openssl x509 -text -in $USER_DATA/ssl/$domain.crt)
  24. not_after=$(echo "$crt_data" |grep "Not After" |cut -f 2,3,4 -d :)
  25. expiration=$(date -d "$not_after" +%s)
  26. now=$(date +%s)
  27. seconds_valid=$((expiration - now))
  28. days_valid=$((seconds_valid / 86400))
  29. if [[ "$days_valid" -lt 31 ]]; then
  30. if [ $lecounter -gt 0 ]; then
  31. sleep 10
  32. fi
  33. ((lecounter++))
  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. aliases=$(echo "$aliases" |sed -e ':a;N;$!ba;s/\n/,/g')
  39. msg=$($BIN/v-add-letsencrypt-domain $user $domain $aliases)
  40. if [ $? -ne 0 ]; then
  41. echo "$domain $msg"
  42. fi
  43. fi
  44. done
  45. done
  46. #----------------------------------------------------------#
  47. # Vesta #
  48. #----------------------------------------------------------#
  49. # No Logging
  50. #log_event "$OK" "$EVENT"
  51. exit