Reverting files to correct ones

This commit is contained in:
Federico Frigo
2022-04-10 20:09:23 +02:00
parent b386f5285a
commit 00fe51f005
12 changed files with 47 additions and 116 deletions

View File

@@ -554,7 +554,7 @@ function _configure_networking() {
echo "Checking iptables rules"
rules=(
"-A POSTROUTING -j MASQUERADE"
"-A POSTROUTING -s 192.168.200.0/24 ! -d 192.168.200.0/24 -j MASQUERADE"
"-A POSTROUTING -s 192.168.50.0/24 ! -d 192.168.50.0/24 -j MASQUERADE"
)
for rule in "${rules[@]}"; do
if grep -- "$rule" $rulesv4 > /dev/null; then

View File

@@ -12,7 +12,7 @@
[Unit]
Description=RaspAP Service Daemon
DefaultDependencies=no
After=network.target
After=multi-user.target
[Service]
Type=oneshot

View File

@@ -10,58 +10,30 @@ DAEMONPATH="/lib/systemd/system/raspapd.service"
OPENVPNENABLED=$(pidof openvpn | wc -l)
positional=()
while [[ $# -gt 0 ]]; do
key="$1"
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-i | --interface)
interface="$2"
shift # past argument
shift # past value
;;
-s | --seconds)
seconds="$2"
shift
shift
;;
-a | --action)
action="$2"
shift
shift
;;
esac
case $key in
-i|--interface)
interface="$2"
shift # past argument
shift # past value
;;
-s|--seconds)
seconds="$2"
shift
shift
;;
-a|--action)
action="$2"
shift
shift
;;
esac
done
set -- "${positional[@]}"
HOSTAPD_CONF="/etc/hostapd/hostapd.conf"
new_country_code=$(curl -s -H "Authorization: Bearer 9da1eb466ed052" https://ipinfo.io/json | jq -r ".country // empty")
old_country_code=$(grep ^country_code $HOSTAPD_CONF | cut -d "=" -f 2)
if [[ ! -z "$new_country_code" ]] && [[ "$old_country_code" != "$new_country_code" ]]; then
sudo sed -i "s/country_code=$old_country_code/country_code=$new_country_code/" /etc/hostapd/hostapd.conf
echo "Updated country code: $new_country_code"
fi
old_ssid=$(grep ^ssid $HOSTAPD_CONF | cut -d "=" -f 2)
rpi_serial=$(cat /proc/cpuinfo | grep Serial | cut -d ' ' -f 2)
new_ssid="isobox-$rpi_serial"
if [[ "$old_ssid" != "$new_ssid" ]]; then
sed -i "s/ssid=$old_ssid/ssid=$new_ssid/" $HOSTAPD_CONF
echo "Updated ssid: $new_ssid"
fi
old_hostname=$(hostname)
new_hostname="isobox-$rpi_serial"
if [[ "$old_hostname" != "$new_hostname" ]]; then
echo $new_hostname >/etc/hostname
sed -i "s/$old_hostname/$new_hostname/" /etc/hosts
hostname $new_hostname
echo "Updated hostname: $new_hostname"
fi
echo "Stopping network services..."
if [ $OPENVPNENABLED -eq 1 ]; then
systemctl stop openvpn-client@client
@@ -85,7 +57,7 @@ if [ -r "$CONFIGFILE" ]; then
declare -A config
while IFS=" = " read -r key value; do
config["$key"]="$value"
done <"$CONFIGFILE"
done < "$CONFIGFILE"
if [ "${config[BridgedEnable]}" = 1 ]; then
if [ "${interface}" = "br0" ]; then
@@ -107,7 +79,7 @@ if [ -r "$CONFIGFILE" ]; then
echo "Disabling systemd-networkd"
systemctl disable systemd-networkd
ip link ls up | grep -q 'br0' &>/dev/null
ip link ls up | grep -q 'br0' &> /dev/null
if [ $? == 0 ]; then
echo "Removing br0 interface..."
ip link set down br0
@@ -117,7 +89,7 @@ if [ -r "$CONFIGFILE" ]; then
if [ "${config[WifiAPEnable]}" = 1 ]; then
if [ "${interface}" = "uap0" ]; then
ip link ls up | grep -q 'uap0' &>/dev/null
ip link ls up | grep -q 'uap0' &> /dev/null
if [ $? == 0 ]; then
echo "Removing uap0 interface..."
iw dev uap0 del
@@ -155,3 +127,4 @@ if [ "${config[WifiAPEnable]}" = 1 ]; then
fi
echo "RaspAP service start DONE"

View File

@@ -158,7 +158,7 @@ function _restore_networking() {
echo "Checking iptables rules"
rules=(
"-A POSTROUTING -j MASQUERADE"
"-A POSTROUTING -s 192.168.200.0/24 ! -d 192.168.200.0/24 -j MASQUERADE"
"-A POSTROUTING -s 192.168.50.0/24 ! -d 192.168.50.0/24 -j MASQUERADE"
)
for rule in "${rules[@]}"; do
if grep -- "$rule" $rulesv4 > /dev/null; then