v-update-letsencrypt-ssl 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. crt_data=$(openssl x509 -text -in "$crt")
  27. expire=$(echo "$crt_data" |grep "Not After")
  28. expire=$(echo "$expire" |cut -f 2,3,4 -d :)
  29. expire=$(date -d "$expire" +%s)
  30. now=$(date +%s)
  31. expire=$((expire - now))
  32. expire=$((expire / 86400))
  33. domain=$(basename $crt |sed -e "s/.crt$//")
  34. if [[ "$expire" -lt 31 ]]; then
  35. aliases=$(echo "$crt_data" |grep DNS:)
  36. aliases=$(echo "$aliases" |sed -e "s/DNS://g" -e "s/,//")
  37. aliases=$(echo "$aliases" |tr ' ' '\n' |sed "/^$/d")
  38. aliases=$(echo "$aliases" |grep -v "^$domain$")
  39. if [ ! -z "$aliases" ]; then
  40. aliases=$(echo "$aliases" |sed -e ':a;N;$!ba;s/\n/,/g')
  41. $BIN/v-add-letsencrypt-domain $user $domain $aliases
  42. else
  43. $BIN/v-add-letsencrypt-domain $user $domain
  44. fi
  45. fi
  46. done
  47. done
  48. #----------------------------------------------------------#
  49. # Vesta #
  50. #----------------------------------------------------------#
  51. # No Logging
  52. #log_event "$OK" "$EVENT"
  53. exit