Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
softethervpn_letsencrypt_cert_autoupdate.sh
#!/bin/bash
#
# Copyright (c) 2016 Katsuya SAITO
# This software is released under the MIT License.
# http://opensource.org/licenses/mit-license.php
#
# @(#) softethervpn_letsencrypt_cert_autoupdate.sh ver.0.1.0 2016.02.20
#
# Usage: softethervpn_letsencrypt_cert_autoupdate.sh CommonName WEBROOT PASSWORD MAIL
#
# CommonName: Certificate common name like www.exsample.com
# WEBROOT: HTTP Server Document root path for letsencrypt webroot plugin like /var/www/html
# PASSWORD: SoftErther VPN Serever Administrator's password
# MAIL: Report mail recipient email address like hoge@exsample.com
#
# Description:
#
#
#
#
###############################################################################
# CONFIGER SECTION #----------------------------------------------------------#
readonly LE_CMD_PATH=/usr/local/letsencrypt
readonly VPNCMD_PATH=/usr/local/vpnserver/vpncmd
readonly LOG_FILE=/var/log/vpnserver_cert_renew.log
readonly CN="$1"
readonly WEB_ROOT_PATH="$2"
readonly VPNSV_ADMIN_PASS="$3"
readonly MAIL_TO="$4"
#-----------------------------------------------------------------------------#
# SCRIPT SECTION #------------------------------------------------------------#
if [ $# != 4 ]; then
echo "Error:"
echo "Usage: softethervpn_letsencrypt_cert_autoupdate.sh CommonName WEBROOT PASSWORD MAIL"
echo " CommonName: Certificate common name like www.exsample.com"
echo " WEBROOT: HTTP Server Document root path for letsencrypt webroot plugin like /var/www/html"
echo " PASSWORD: SoftErther VPN Serever Administrator's password"
echo " MAIL: Report mail recipient email address like hoge@exsample.com"
exit 1
fi
today=`date +%F-%a-%T`
echo "# Let's Encrypt Cert autopudate Start: ${today}" >${LOG_FILE}
echo "# Update Log START ---------------------------------------------------------#" >>${LOG_FILE}
${LE_CMD_PATH}/letsencrypt-auto certonly --renew-by-default --webroot -w ${WEB_ROOT_PATH} -d ${CN} >>${LOG_FILE} 2>&1
echo >>${LOG_FILE}
echo "# SoftErther VPN SERVER CERT CHANGE LOG START ------------------------------#" >>${LOG_FILE}
${VPNCMD_PATH} \
localhost:5555 \
/SERVER \
/PASSWORD:${VPNSV_ADMIN_PASS} \
/CMD ServerCertSet \
/LOADCERT:/etc/letsencrypt/live/${CN}/fullchain.pem \
/LOADKEY:/etc/letsencrypt/live/${CN}/privkey.pem >>${LOG_FILE}
echo "#---------------------------- SoftErther VPN SERVER CERT CHANGE LOG END ---#" >>${LOG_FILE}
echo "#------------------------------------------------------------- Update Log END ---#" >>${LOG_FILE}
today=`date +%F-%a-%T`
echo "# Let's Encrypt Cert autopudate End: ${today}" >>${LOG_FILE}
cat ${LOG_FILE} | mail -s "[Soft Erther VPN Server Cert Auto Update] Update Report for ${CN}" ${MAIL_TO}
exit 0
#-----------------------------------------------------------------------------#
@kacchan822

This comment has been minimized.

Copy link
Owner Author

commented Feb 20, 2016

-------- Report Message Sample --------

Subject: [Soft Erther VPN Server Cert Auto Update] Update Report for exsample.com
Date: Sat, 20 Feb 2016 00:00:00 +0900 (JST)
From: root <root@exsample.com>
To: root@exsample.com

# Let's Encrypt Cert autopudate Start: 2016-02-20-Sat-00:00:00
# Update Log START ---------------------------------------------------------#
Updating letsencrypt and virtual environment dependencies......
Requesting root privileges to run with virtualenv: /root/.local/share/letsencrypt/bin/letsencrypt certonly --renew-by-default --webroot -w /var/www/html -d exsample.com
IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at
   /etc/letsencrypt/live/exsample.com/fullchain.pem. Your cert will
   expire on 2016-05-20. To obtain a new version of the certificate in
   the future, simply run Let's Encrypt again.
 - If you like Let's Encrypt, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le


# SoftErther VPN SERVER CERT CHANGE LOG START ------------------------------#
vpncmd コマンド - SoftEther VPN コマンドライン管理ユーティリティ
SoftEther VPN コマンドライン管理ユーティリティ (vpncmd コマンド)
Version 4.19 Build 9599   (Japanese)
Compiled 2015/10/19 20:28:20 by yagi at pc30
Copyright (c) SoftEther VPN Project. All Rights Reserved.

VPN Server "localhost" (ポート 5555) に接続しました。

VPN Server 全体の管理権限があります。

VPN Server>ServerCertSet /LOADCERT:/etc/letsencrypt/live/exsample.com/fullchain.pem /LOADKEY:/etc/letsencrypt/live/exsample.com/privkey.pem
ServerCertSet コマンド - VPN Server の SSL 証明書と秘密鍵の設定
コマンドは正常に終了しました。

#---------------------------- SoftErther VPN SERVER CERT CHANGE LOG END ---#
#------------------------------------------------------------- Update Log END ---#
# Let's Encrypt Cert autopudate End: 2016-02-20-Sat-00:00:00

-------- Report Message Sample --------

@GameVPN

This comment has been minimized.

Copy link

commented Jun 9, 2019

Hello i wan to contact you on skype or discord or any

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.