1
0
mirror of https://github.com/billz/raspap-webgui.git synced 2023-10-10 13:37:24 +02:00
raspap-webgui/installers/configauth.sh

45 lines
1.1 KiB
Bash
Raw Normal View History

2019-11-15 10:01:57 +01:00
#!/bin/bash
2019-11-17 11:17:57 +01:00
#
# Updates openvpn client.conf with auth credentials,
# adds iptables rules to forward traffic from tun0
# to configured wireless interface
# @author billz
# license: GNU General Public License v3.0
file=$1
interface=$2
2019-11-15 10:01:57 +01:00
2019-11-16 10:15:39 +01:00
echo "Enabling auth credentials in OpenVPN client.conf"
2019-11-15 10:01:57 +01:00
line='auth-user-pass'
if grep -q "$line" $file; then
2019-11-16 10:15:39 +01:00
echo "Updating $line"
2019-11-15 10:01:57 +01:00
sudo sed -i "s/$line/$line login.conf/g" $file
else
2019-11-16 10:15:39 +01:00
echo "Adding $line"
2019-11-15 10:01:57 +01:00
sudo sed -i "$ a $line login.conf" $file
fi
2019-11-17 11:17:57 +01:00
echo "Adding iptables rules for $interface"
# Generate iptables entries to place into rc.local file.
# #RASPAP is for uninstall script
lines=(
"iptables -t nat -A POSTROUTING -o tun0 -j MASQUERADE #RASPAP"
"iptables -A FORWARD -i tun0 -o $interface -m state --state RELATED,ESTABLISHED -j ACCEPT #RASPAP"
"iptables -A FORWARD -i wlan0 -o tun0 -j ACCEPT #RASPAP"
)
for line in "${lines[@]}"; do
if grep "$line" /etc/rc.local > /dev/null; then
# iptables rule exists
else
sudo sed -i "s/^exit 0$/$line\nexit 0/" /etc/rc.local
fi
done
# Force a reload of new settings in /etc/rc.local
sudo systemctl restart rc-local.service
sudo systemctl daemon-reload