Skip to content

Commit

Permalink
Merge pull request #114 from freifunk-gluon/fixes_for_ssid_changer
Browse files Browse the repository at this point in the history
ffac-ssid-changer: switch to ubus call to reload hostapd and fix OWE offline ssid
  • Loading branch information
rotanid authored Jun 10, 2024
2 parents bd78c4c + 946e6a0 commit 01d54ad
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions ffac-ssid-changer/shsrc/ssid-changer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ SETTINGS_DEBUG_LOGGING="$(uci -q get ssid-changer.settings.debug_log_enabled)"
pgrep -f autoupdater >/dev/null && safety_exit 'autoupdater running'
UT=$(sed 's/\..*//g' /proc/uptime)
[ "$UT" -gt 60 ] || safety_exit 'less than one minute'
[ "$(find /var/run -name "hostapd-phy*" | wc -l)" -gt 0 ] || safety_exit 'no hostapd-phy*'
[ "$(find /var/run -name "hostapd-*" | wc -l)" -gt 0 ] || safety_exit 'no hostapd-*'

# only once every timeframe minutes the SSID will change to the Offline-SSID
# (set to 1 minute to change immediately every time the router gets offline)
Expand Down Expand Up @@ -132,8 +132,8 @@ if [ "$CHECK" -gt 0 ] || [ "$DISABLED" = '1' ]; then
log_debug "node is online"
LOOP=1
# check status for all physical devices
for HOSTAPD in /var/run/hostapd-phy*; do
[ -e "$HOSTAPD" ] || break # handle the case of no hostapd-phy* files
for HOSTAPD in /var/run/hostapd-*; do
[ -e "$HOSTAPD" ] || break # handle the case of no hostapd-* files
# shellcheck disable=SC2086 # ONLINE_SSIDs has multiple lines
ONLINE_SSID="$(echo $ONLINE_SSIDs | awk -F '~' -v l=$((LOOP*2)) '{print $l}')"
LOOP=$((LOOP+1))
Expand Down Expand Up @@ -178,8 +178,8 @@ elif [ "$CHECK" -eq 0 ]; then
if [ "$OFF_COUNT" -ge $((T / 2)) ]; then
# node was offline more times than half of switch_timeframe (or than $FIRST)
LOOP=1
for HOSTAPD in /var/run/hostapd-phy*; do
[ -e "$HOSTAPD" ] || break # handle the case of no hostapd-phy* files
for HOSTAPD in /var/run/hostapd-*; do
[ -e "$HOSTAPD" ] || break # handle the case of no hostapd-* files
# shellcheck disable=SC2086 # ONLINE_SSIDs has multiple lines
ONLINE_SSID="$(echo $ONLINE_SSIDs | awk -F '~' -v l=$((LOOP*2)) '{print $l}')"
LOOP=$((LOOP+1))
Expand All @@ -198,7 +198,7 @@ elif [ "$CHECK" -eq 0 ]; then
logger -s -t "ffac-ssid-changer" -p 5 "could not set to offline state: did neither find SSID '$ONLINE_SSID' nor '$OFFLINE_SSID'. Please reboot"
fi
if [ "$OWE" = true ]; then
CURRENT_SSID_OWE="$(grep "^ssid=$OFFLINE_SSID_OWE" "$HOSTAPD" | cut -d"=" -f2)"
CURRENT_SSID_OWE="$(grep "^ssid=$ONLINE_SSID_OWE" "$HOSTAPD" | cut -d"=" -f2)"
if [ "$CURRENT_SSID_OWE" = "$ONLINE_SSID_OWE" ]; then
# set offline
logger -s -t "ffac-ssid-changer" -p 5 "$MSG""$OFF_COUNT times offline, SSID is $CURRENT_SSID_OWE, change to $OFFLINE_SSID_OWE"
Expand All @@ -216,8 +216,9 @@ elif [ "$CHECK" -eq 0 ]; then
fi
if [ $HUP_NEEDED = 1 ]; then
# send HUP to all hostapd to load the new SSID
killall -HUP hostapd
# HUP does not work with openwrt-23.05 somehow, use ubus reload
# to load the new SSID
ubus call hostapd reload
## check for nonmatching hostapd-pidfiles
if [ -f /lib/gluon/eulenfunk-hotfix/check_hostapd.sh ] ; then
sleep 2 # settle down
Expand Down

0 comments on commit 01d54ad

Please sign in to comment.