Skip to content

Commit e59dc7b

Browse files
committed
Bug fix and features
Fixed multiple domain issue with create_http_https_site_certbot.sh script Fixed issue with create_http_https_site_path_cert.sh script creating blank .pem and .key files Added prompt to delete .pem and .key files in delete_site.sh as well as warning that it does not delete Lets Encrypt certs Fixed wording on request_cerbot_cert.sh script
1 parent b45c21e commit e59dc7b

File tree

5 files changed

+61
-54
lines changed

5 files changed

+61
-54
lines changed

dirstructure/opt/aegis-waf/scripts/create_http_https_site_certbot_cert.sh

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,33 @@ if [ ! -f "/usr/local/nginx/conf/ssl/dhparam.pem" ]; then
1010

1111
#GET INPUTS
1212
read -p "Enter a site name: " SITE
13-
read -p "Enter a domain(s) for the Site (Multiple domains must be separated by a space): " DOMAIN
13+
read -p "Enter a PRIMARY ROOT domain for the Site without www. in front of it (Example: domain.tld OR host.domain.tld): " DOMAIN
14+
read -p "Enter any additional sub-domains separated by a comma (Example: www.domain.tld). Leave blank and press enter if none: " SECDOMAIN
1415
read -p "Enter a destination url including http(s):// (Example: http://www.domain.tld for HTTP Only or https://www.domain.tld for HTTPS) Do NOT include a Port Number: " DESTINATION
1516
read -p "Enter a Destination Port Number for the Site (Example: 80 for http or 443 for https):" PORT
1617
read -p "Enter SSL Protocols you wish to enable separated by a space (Example: TLSv1.1 TLSv1.2 TLSv1.3):" SSLPROTOCOLS
1718

19+
#IF SECDOMAIN IS EMPTY THEN SET ALLDOMAIN TO $DOMAIN IF NOT SET ALLDOMAIN TO $DOMAIN AND $SECDOMAIN (CERTBOT)
20+
if [ -z "$SECDOMAIN" ]
21+
then
22+
ALLDOMAIN=$DOMAIN
23+
24+
else
25+
ALLDOMAIN="$DOMAIN,$SECDOMAIN"
26+
27+
fi
28+
29+
#IF SECDOMAIN IS EMPTY THEN SET ALLDOMAINNGINX TO $DOMAIN IF NOT SET ALLDOMAINNGINX TO $DOMAIN AND $SECDOMAIN (NGINX)
30+
if [ -z "$SECDOMAIN" ]
31+
then
32+
ALLDOMAINNGINX=$DOMAIN
33+
34+
else
35+
ALLDOMAINNGINX="$DOMAIN $SECDOMAIN"
36+
37+
fi
38+
39+
1840
#START CONFIGURATION
1941
echo "Creating Nginx Logs Directory"
2042
#CREATE NGINX LOGS DIRECTORY
@@ -96,7 +118,7 @@ fi
96118

97119
echo "Configuring Nginx HTTP Conf File Domain"
98120
#REPLACE ALL INSTANCES OF THE-DOMAIN WITH DOMAIN VARIABLE ON NGINX CONFIG FILE
99-
/bin/sed -i -e "s/THE-DOMAIN/$DOMAIN/g" "/usr/local/nginx/conf/sites-available/$SITE.conf"
121+
/bin/sed -i -e "s/THE-DOMAIN/$ALLDOMAINNGINX/g" "/usr/local/nginx/conf/sites-available/$SITE.conf"
100122

101123
if [ $? -eq 0 ]; then
102124
echo "Done"
@@ -160,6 +182,8 @@ else
160182
exit
161183
fi
162184

185+
186+
163187
#=== DO NOT ENABLE BELOW UNLESS TROUBLESHOOTING ===
164188
#echo "Pausing for 5 seconds waiting for Nginx"
165189
#sleep 5
@@ -180,8 +204,8 @@ fi
180204

181205

182206
echo "Requesting Letsencrypt Certificate"
183-
#Request Letsencrypt Certificate
184-
/usr/bin/certbot certonly --noninteractive --webroot --agree-tos --register-unsafely-without-email -d ${DOMAIN} -w /var/www/html/$SITE
207+
#Request Letsencrypt Certificate with ALLDOMAIN variable
208+
/usr/bin/certbot certonly --noninteractive --webroot --agree-tos --register-unsafely-without-email -d ${ALLDOMAIN} -w /var/www/html/$SITE
185209

186210
if [ $? -eq 0 ]; then
187211
echo "Done"
@@ -213,9 +237,20 @@ else
213237
exit
214238
fi
215239

216-
echo "Configuring Nginx HTTPS Conf File Domain"
217-
#REPLACE ALL INSTANCES OF THE-DOMAIN WITH DOMAIN VARIABLE ON NGINX CONFIG FILE
218-
/bin/sed -i -e "s/THE-DOMAIN/$DOMAIN/g" "/usr/local/nginx/conf/sites-available/$SITE-ssl.conf"
240+
echo "Configuring Nginx HTTPS Conf File server_name Domain"
241+
#REPLACE ALL INSTANCES OF THE-DOMAIN WITH ALLDOMAINNGINX VARIABLE ON NGINX CONFIG FILE
242+
/bin/sed -i -e "s/THE-DOMAIN/$ALLDOMAINNGINX/g" "/usr/local/nginx/conf/sites-available/$SITE-ssl.conf"
243+
244+
if [ $? -eq 0 ]; then
245+
echo "Done"
246+
else
247+
echo "Error occured. Stopped processing!"
248+
exit
249+
fi
250+
251+
echo "Configuring Nginx HTTPS Conf File ssl_certificate and ssl_certificate_key Domain"
252+
#REPLACE ALL INSTANCES OF THE-DOMAIN WITH ALLDOMAINNGINX VARIABLE ON NGINX CONFIG FILE
253+
/bin/sed -i -e "s/THE-PRIMARY-DOMAIN/$DOMAIN/g" "/usr/local/nginx/conf/sites-available/$SITE-ssl.conf"
219254

220255
if [ $? -eq 0 ]; then
221256
echo "Done"

dirstructure/opt/aegis-waf/scripts/create_http_https_site_path_cert.sh

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -249,30 +249,6 @@ else
249249
exit
250250
fi
251251

252-
echo "Inserting SSL Certificate Contents into SSL Certificate File"
253-
254-
#/bin/sed -i -e "s,THE-PEM,$PEM,g" "/usr/local/nginx/conf/ssl/${SITE}.pem"
255-
/bin/echo "$PEM" >> /usr/local/nginx/conf/ssl/${SITE}.pem
256-
257-
if [ $? -eq 0 ]; then
258-
echo "Done"
259-
else
260-
echo "Error occured. Stopped processing!"
261-
exit
262-
fi
263-
264-
echo "Inserting SSL Certificate Key Contents into SSL Certificate Key File"
265-
266-
#/bin/sed -i -e "s,THE-KEY,$KEY,g" "/usr/local/nginx/conf/ssl/${SITE}.key"
267-
/bin/echo "$KEY" >> /usr/local/nginx/conf/ssl/${SITE}.key
268-
269-
if [ $? -eq 0 ]; then
270-
echo "Done"
271-
else
272-
echo "Error occured. Stopped processing!"
273-
exit
274-
fi
275-
276252

277253
echo "Enabling HTTPS site in Nginx"
278254
#CREATE HARD LINK FROM NGINX SITES-AVAILABLE TO NGINX SITES-ENABLED

dirstructure/opt/aegis-waf/scripts/delete_site.sh

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#!/bin/bash
22

3+
echo "WARNING" | boxes -d stone -p a2v1
4+
echo "This script will NOT delete any Lets Encrypt certificates."
5+
echo "Lets encrypt certificates must be manually removed from their respective /etc/letsencrypt/live/domain.tld directories"
6+
echo "This script will prompt you to delete ONLY manually entered certificate and key files"
7+
38
#GET INPUTS
49
read -p "Enter a site name to permanently delete: " SITE
510

@@ -66,22 +71,13 @@ else
6671
echo There was an error removing Modsecurity .conf file. Error was $?
6772
fi
6873

69-
echo "Removing certificate .pem file"
70-
#Remove certificate .pem file
71-
/bin/rm -rf /usr/local/nginx/conf/ssl/${SITE}.pem
72-
73-
if [ $? -eq 0 ]; then
74-
echo Done
75-
else
76-
echo There was an error removing .pem file. Error was $?
77-
fi
78-
79-
echo "Removing key .key file"
80-
#Remove key .key file
81-
/bin/rm -rf /usr/local/nginx/conf/ssl/${SITE}.key
74+
while true; do
75+
read -p "Do you wish remove the SSL Certificate and Key Files? (Enter y or Y. Warning!! Entering y or Y will remove the certificate and key files which may break other sites that use those files)" yn
76+
case $yn in
77+
[Yy]* ) echo "Removing SSL Certificate and Key Files"; /bin/rm -rf /usr/local/nginx/conf/ssl/${SITE}.pem; /bin/rm -rf /usr/local/nginx/conf/ssl/${SITE}.key;
78+
echo "Done. Reload Nginx for changes to take effect!"; break;;
79+
[Nn]* ) echo "Done. Reload Nginx for changes to take effect!;"; break;;
80+
* ) echo "Please answer yes or no.";;
81+
esac
82+
done
8283

83-
if [ $? -eq 0 ]; then
84-
echo Done. Reload Nginx for changes to take effect!
85-
else
86-
echo There was an error removing .key file. Error was $?
87-
fi

dirstructure/opt/aegis-waf/scripts/request_certbot_cert.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ if [ ! -f "/usr/local/nginx/conf/ssl/dhparam.pem" ]; then
1010

1111
#GET INPUTS
1212
read -p "Enter a certificate name: " CERTNAME
13-
read -p "Enter a PRIMARY domain for the Site: " DOMAIN
14-
read -p "Enter any additional sub-domains separated by a comma (Leave blank if none): " SECDOMAIN
13+
read -p "Enter a PRIMARY ROOT domain for the Site without www. in front of it (Example: domain.tld OR host.domain.tld): " DOMAIN
14+
read -p "Enter any additional sub-domains separated by a comma (Example: www.domain.tld). Leave blank and press enter if none: " SECDOMAIN
1515

1616
#START CONFIGURATION
1717

@@ -73,7 +73,7 @@ then
7373
ALLDOMAIN=$DOMAIN
7474

7575
else
76-
ALLDOMAIN=$DOMAIN,$SECDOMAIN
76+
ALLDOMAIN="$DOMAIN,$SECDOMAIN"
7777

7878
fi
7979

dirstructure/opt/aegis-waf/templates/https_template_site_certbot.conf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ server {
99
access_log /usr/local/nginx/logs/THE-SITE/THE-SITE_access.log;
1010
error_log /usr/local/nginx/logs/THE-SITE/THE-SITE_error.log warn;
1111
#SSL LETS ENCRYPT CERTIFICATE CONFIG
12-
ssl_certificate /etc/letsencrypt/live/THE-SITE/fullchain.pem;
13-
ssl_certificate_key /etc/letsencrypt/live/THE-SITE/privkey.pem;
12+
ssl_certificate /etc/letsencrypt/live/THE-PRIMARY-DOMAIN/fullchain.pem;
13+
ssl_certificate_key /etc/letsencrypt/live/THE-PRIMARY-DOMAIN/privkey.pem;
1414
# Turn on OCSP stapling as recommended at
1515
# https://community.letsencrypt.org/t/integration-guide/13123
1616
# requires nginx version >= 1.3.7

0 commit comments

Comments
 (0)