raspap-webgui-mirror/installers/configauth.sh

48 lines
1.3 KiB
Bash
Raw Normal View History

2019-11-15 09:01:57 +00:00
#!/bin/bash
2019-11-17 10:17:57 +00: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
2019-11-17 18:20:25 +00:00
auth=$2
interface=$3
if [ "$auth" = 1 ]; then
2019-11-17 19:08:39 +00:00
echo "Enabling auth-user-pass in OpenVPN client.conf"
line='auth-user-pass'
if grep -q "$line" $file; then
echo "Updating $line"
sudo sed -i "s/$line/$line login.conf/g" $file
else
echo "Adding $line"
sudo sed -i "$ a $line login.conf" $file
fi
2019-11-15 09:01:57 +00:00
fi
2019-11-17 10:17:57 +00:00
# Generate iptables entries to place into rc.local file.
# #RASPAP is for uninstall script
2019-11-17 19:08:39 +00:00
echo "Checking iptables rules for $interface"
2019-11-17 18:20:25 +00:00
2019-11-17 10:17:57 +00:00
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
2019-11-17 19:08:39 +00:00
if grep "$line" /etc/rc.local > /dev/null; then
2020-03-15 11:02:20 +00:00
echo "$line: Line already added"
else
2019-11-17 19:08:39 +00:00
sudo sed -i "s/^exit 0$/$line\nexit 0/" /etc/rc.local
echo "Adding rule: $line"
fi
2019-11-17 10:17:57 +00:00
done
# Force a reload of new settings in /etc/rc.local
sudo systemctl restart rc-local.service
sudo systemctl daemon-reload