Skip to content
This repository has been archived by the owner on Oct 30, 2019. It is now read-only.

Webterminal: Added SSL support with existing LE certificates. #130

Merged
merged 9 commits into from
Mar 13, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions package/opt/hassbian/suites/files/webterminalsslhelper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
# Helper script for using LE certificates with Webterminal (shellinabox)
if [ -d "/etc/letsencrypt/live" ]; then
CERTDIR="/etc/letsencrypt/live/"
elif [ -d "/home/homeassistant/dehydrated/certs" ]; then
CERTDIR="/home/homeassistant/dehydrated/certs/"
else
CERTDIR=""
fi
FULLCHAIN=$(find "$CERTDIR" -type f | grep fullchain)
PRIVKEY=$(find "$CERTDIR" -type f | grep privkey)
DOMAIN=$(ls "$CERTDIR")
cat $FULLCHAIN $PRIVKEY > /var/lib/shellinabox/certificate-"$DOMAIN".pem

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double quote to prevent globbing and word splitting.

chown shellinabox:shellinabox -R /var/lib/shellinabox/
service shellinabox restart
exit 0
46 changes: 42 additions & 4 deletions package/opt/hassbian/suites/webterminal.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,53 @@ function webterminal-show-copyright-info {
}

function webterminal-install-package {


if [ "$ACCEPT" == "true" ]; then # True if `-y` flag is used.
if [ -d "/etc/letsencrypt/live" ] || [ -d "/home/homeassistant/dehydrated/certs" ]; then
SSL="Y"
else
SSL="N"
fi
else
echo ""
echo -n "Do you use SSL (https) with Home Assistant? [N/y] : "
read -r SSL
if [ ! "$SSL" ]; then
SSL="N"
fi
fi

echo "Installing packages."
sudo apt-get install -y openssl shellinabox

echo "Changing config."
sudo sed -i 's/--no-beep/--no-beep --disable-ssl/g' /etc/default/shellinabox
if [ "$SSL" == "y" ] || [ "$SSL" == "Y" ]; then
echo "No need to change default configuration, skipping this step..."
echo "Checking cert directory..."
if [ -d "/etc/letsencrypt/live" ]; then
CERTDIR="/etc/letsencrypt/live/"
elif [ -d "/home/homeassistant/dehydrated/certs" ]; then
CERTDIR="/home/homeassistant/dehydrated/certs/"
else
CERTDIR=""
fi
echo "Setting cert fullchain location..."
FULLCHAIN=$(find "$CERTDIR" -type f | grep fullchain)
echo "Setting cert privkey location..."
PRIVKEY=$(find "$CERTDIR" -type f | grep privkey)
DOMAIN=$(ls "$CERTDIR")
echo "Merging files and adding to correct dir..."
cat $FULLCHAIN $PRIVKEY > /var/lib/shellinabox/certificate-"$DOMAIN".pem

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double quote to prevent globbing and word splitting.

chown shellinabox:shellinabox -R /var/lib/shellinabox/
echo "Adding crong job to copy certs..."
(crontab -l ; echo "0 1 1 * * bash /opt/hassbian/suites/files/webterminalsslhelper.sh")| crontab -
else
sed -i 's/--no-beep/--no-beep --disable-ssl/g' /etc/default/shellinabox
fi

echo "Reloading and starting the service."
sudo service shellinabox reload
sudo service shellinabox restart
service shellinabox reload
service shellinabox restart

ip_address=$(ifconfig | grep "inet.*broadcast" | grep -v 0.0.0.0 | awk '{print $2}')

Expand Down