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

Automated ssid and country code updates

This commit is contained in:
Federico Frigo 2021-10-19 18:51:44 +02:00
parent d0c14824e1
commit fd1c48b710
2 changed files with 41 additions and 25 deletions

View File

@ -12,6 +12,7 @@ interface=uap0
wpa=2 wpa=2
wpa_pairwise=CCMP wpa_pairwise=CCMP
country_code=IT country_code=IT
ignore_broadcast_ssid=0
## Rapberry Pi 3 specific to on board WLAN/WiFi ## Rapberry Pi 3 specific to on board WLAN/WiFi
#ieee80211n=1 # 802.11n support (Raspberry Pi 3) #ieee80211n=1 # 802.11n support (Raspberry Pi 3)
#wmm_enabled=1 # QoS support (Raspberry Pi 3) #wmm_enabled=1 # QoS support (Raspberry Pi 3)
@ -22,4 +23,3 @@ country_code=IT
## RaspAP bridge AP mode (disabled by default) ## RaspAP bridge AP mode (disabled by default)
#bridge=br0 #bridge=br0
ignore_broadcast_ssid=0

View File

@ -10,27 +10,26 @@ DAEMONPATH="/lib/systemd/system/raspapd.service"
OPENVPNENABLED=$(pidof openvpn | wc -l) OPENVPNENABLED=$(pidof openvpn | wc -l)
positional=() positional=()
while [[ $# -gt 0 ]] while [[ $# -gt 0 ]]; do
do key="$1"
key="$1"
case $key in case $key in
-i|--interface) -i | --interface)
interface="$2" interface="$2"
shift # past argument shift # past argument
shift # past value shift # past value
;; ;;
-s|--seconds) -s | --seconds)
seconds="$2" seconds="$2"
shift shift
shift shift
;; ;;
-a|--action) -a | --action)
action="$2" action="$2"
shift shift
shift shift
;; ;;
esac esac
done done
set -- "${positional[@]}" set -- "${positional[@]}"
@ -48,6 +47,24 @@ if [ "${action}" = "stop" ]; then
exit 0 exit 0
fi fi
HOSTAPD_CONF="/etc/hostapd/hostapd.conf"
old_ssid=$(grep ^ssid $HOSTAPD_CONF | cut -d "=" -f 2)
new_ssid="isobox-$(cat /proc/cpuinfo | grep Serial | cut -d ' ' -f 2)"
if [[ "$old_ssid" != "$new_ssid" ]]; then
sed -i "s/$old_ssid/$new_ssid/" $HOSTAPD_CONF
echo "Updated ssid: $new_ssid"
fi
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
sed -i "s/$old_country_code/$new_country_code/" $HOSTAPD_CONF
echo "Updated country code: $new_country_code"
fi
if [ -f "$DAEMONPATH" ] && [ ! -z "$interface" ]; then if [ -f "$DAEMONPATH" ] && [ ! -z "$interface" ]; then
echo "Changing RaspAP Daemon --interface to $interface" echo "Changing RaspAP Daemon --interface to $interface"
sed -i "s/\(--interface \)[[:alnum:]]*/\1$interface/" "$DAEMONPATH" sed -i "s/\(--interface \)[[:alnum:]]*/\1$interface/" "$DAEMONPATH"
@ -57,7 +74,7 @@ if [ -r "$CONFIGFILE" ]; then
declare -A config declare -A config
while IFS=" = " read -r key value; do while IFS=" = " read -r key value; do
config["$key"]="$value" config["$key"]="$value"
done < "$CONFIGFILE" done <"$CONFIGFILE"
if [ "${config[BridgedEnable]}" = 1 ]; then if [ "${config[BridgedEnable]}" = 1 ]; then
if [ "${interface}" = "br0" ]; then if [ "${interface}" = "br0" ]; then
@ -79,7 +96,7 @@ if [ -r "$CONFIGFILE" ]; then
echo "Disabling systemd-networkd" echo "Disabling systemd-networkd"
systemctl disable 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 if [ $? == 0 ]; then
echo "Removing br0 interface..." echo "Removing br0 interface..."
ip link set down br0 ip link set down br0
@ -89,7 +106,7 @@ if [ -r "$CONFIGFILE" ]; then
if [ "${config[WifiAPEnable]}" = 1 ]; then if [ "${config[WifiAPEnable]}" = 1 ]; then
if [ "${interface}" = "uap0" ]; 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 if [ $? == 0 ]; then
echo "Removing uap0 interface..." echo "Removing uap0 interface..."
iw dev uap0 del iw dev uap0 del
@ -127,4 +144,3 @@ if [ "${config[WifiAPEnable]}" = 1 ]; then
fi fi
echo "RaspAP service start DONE" echo "RaspAP service start DONE"