v-update-letsencrypt-ssl 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. lecounter=0
  25. for domain in $(search_objects 'web' 'LETSENCRYPT' 'yes' 'DOMAIN'); do
  26. # Working on Web domain check - if is suspended
  27. webSuspended=$(grep "DOMAIN='$domain'" $USER_DATA/web.conf |grep "SUSPENDED='no")
  28. if [ ! -z "$webSuspended" ]; then
  29. continue;
  30. fi;
  31. # Working on DNS domain check - if is suspended
  32. dnsSuspended=$(grep "DOMAIN='$domain'" $USER_DATA/dns.conf |grep "SUSPENDED='no")
  33. if [ ! -z "$dnsSuspended" ]; then
  34. continue;
  35. fi;
  36. #dunno if this is needed, but i will ut it in the same way as web and dns
  37. # Working on MAIL domain check - if is suspended
  38. mailSuspended=$(grep "DOMAIN='$domain'" $USER_DATA/mail.conf |grep "SUSPENDED='no")
  39. if [ ! -z "$mailSuspended" ]; then
  40. continue;
  41. fi
  42. crt="$VESTA/data/users/$user/ssl/$domain.crt"
  43. crt_data=$(openssl x509 -text -in "$crt")
  44. expire=$(echo "$crt_data" |grep "Not After")
  45. expire=$(echo "$expire" |cut -f 2,3,4 -d :)
  46. expire=$(date -d "$expire" +%s)
  47. now=$(date +%s)
  48. expire=$((expire - now))
  49. expire=$((expire / 86400))
  50. domain=$(basename $crt |sed -e "s/.crt$//")
  51. if [[ "$expire" -lt 31 ]]; then
  52. aliases=$(echo "$crt_data" |grep DNS:)
  53. aliases=$(echo "$aliases" |sed -e "s/DNS://g" -e "s/,//")
  54. aliases=$(echo "$aliases" |tr ' ' '\n' |sed "/^$/d")
  55. aliases=$(echo "$aliases" |grep -v "^$domain$")
  56. if [ ! -z "$aliases" ]; then
  57. aliases=$(echo "$aliases" |sed -e ':a;N;$!ba;s/\n/,/g')
  58. msg=$($BIN/v-add-letsencrypt-domain $user $domain $aliases)
  59. if [ $? -ne 0 ]; then
  60. echo "$domain $msg"
  61. fi
  62. else
  63. msg==$($BIN/v-add-letsencrypt-domain $user $domain)
  64. if [ $? -ne 0 ]; then
  65. echo "$domain $msg"
  66. fi
  67. fi
  68. if [ $lecounter -gt 0 ]; then
  69. sleep 10
  70. fi
  71. ((lecounter++))
  72. fi
  73. done
  74. done
  75. #----------------------------------------------------------#
  76. # Vesta #
  77. #----------------------------------------------------------#
  78. # No Logging
  79. #log_event "$OK" "$EVENT"
  80. exit