Skip to content
Snippets Groups Projects
Commit f73cbbda authored by rubo77's avatar rubo77
Browse files

set settings on upgrade and configurable with uci

- add option to disable ssid-changer
- add option to use mac as offline suffix instead of nodename
parent cc0f3dd8
No related branches found
No related tags found
No related merge requests found
...@@ -12,24 +12,22 @@ Adapt and add this block to your site.conf: ...@@ -12,24 +12,22 @@ Adapt and add this block to your site.conf:
``` ```
ssid_changer = { ssid_changer = {
switch_timeframe = 1, -- only once every timeframe (in minutes) the SSID will change to OFFLINE switch_timeframe = 1, -- only once every timeframe (in minutes) the SSID will change to OFFLINE
-- set to 1440 to change once a day -- set to 1440 to change once a day
-- set to 1 minute to change every time the router gets offline -- set to 1 minute to change every time the router gets offline
first = 5, -- the first few minutes directly after reboot within which an Offline-SSID always may be activated first = 5, -- the first few minutes directly after reboot within which an Offline-SSID always may be activated
prefix = 'FF_OFFLINE_', -- use something short to leave space for the nodename (no '~' allowed!) prefix = 'FF_OFFLINE_', -- use something short to leave space for the nodename (no '~' allowed!)
suffix = 'nodename', -- generate the ssid with either 'nodename', 'mac' or to use only the prefix: 'none' suffix = 'nodename', -- generate the SSID with either 'nodename', 'mac' or to use only the prefix: 'none'
limits = { tq_limit_enabled = 0, -- if false, the offline SSID will only be set if there is no gateway reacheable
disabled = false, -- if true, the offline ssid will only be set if there is no gateway reacheable -- upper and lower limit to turn the offline_ssid on and off
-- upper and lower limit to turn the offline_ssid on and off -- in-between these two values the SSID will never be changed to prevent it from toggeling every minute.
-- in-between these two values the SSID will never be changed to preven it from toggeling every Minute. tq_limit_max = '55', -- upper limit, above that the online SSID will be used
tq_max = '55', -- upper limit, above that the online SSID will be used tq_limit_min = '45' -- lower limit, below that the offline SSID will be used
tq_min = '45' -- lower limit, below that the offline SSID will be used
},
}, },
``` ```
if limits are disabled, then it will be only checked, if the gateway is reachable with if tq_limit is disabled, then it will be only checked, if the gateway is reachable with
batctl gwl -H batctl gwl -H
......
config main 'settings'
#!/bin/sh #!/bin/sh
MINUTES=1440 # only once every timeframe the SSID will change to OFFLINE (set to 1 minute to change every time the router gets offline) # only once every timeframe the SSID will change to OFFLINE (set to 1 minute to change every time the router gets offline)
FIRST=5 # the first few minutes directly after reboot within which an Offline-SSID always may be activated MINUTES="$(uci get ssid-changer.settings.switch_timeframe -q)"
OFFLINE_PREFIX='FF_OFFLINE_' # use something short to leave space for the nodename (no '~' allowed!) # the first few minutes directly after reboot within which an Offline-SSID always may be activated
: ${MINUTES:=1}
ONLINE_SSID="$(uci get wireless.client_radio0.ssid -q)" FIRST="$(uci get ssid-changer.settings.first -q)"
: ${ONLINE_SSID:="FREIFUNK"} # if for whatever reason ONLINE_SSID is NULL # use something short to leave space for the nodename (no '~' allowed!)
: ${FIRST:=5}
PREFIX="$(uci get ssid-changer.settings.prefix -q)"
# generate the ssid with either 'nodename', 'mac' or to use only the prefix: 'none'
: ${PREFIX:='FF_OFFLINE_'}
SETTINGS_SUFFIX="$(uci get ssid-changer.settings.suffix -q)"
# generate an Offline SSID with the first and last part of the nodename to allow owner to recognise wich node is down TQ_LIMIT_ENABLED="$(uci get ssid-changer.settings.tq_limit_disabled -q)"
NODENAME="$(uname -n)" : ${TQ_LIMIT_ENABLED:='0'} # if true, the offline ssid will only be set if there is no gateway reacheable
if [ ${#NODENAME} -gt $((30 - ${#OFFLINE_PREFIX})) ]; then # 32 would be possible as well # upper and lower limit to turn the offline_ssid on and off
HALF=$(( (28 - ${#OFFLINE_PREFIX} ) / 2 )) # calculate the length of the first part of the node identifier in the offline-ssid # in-between these two values the SSID will never be changed to preven it from toggeling every Minute.
SKIP=$(( ${#NODENAME} - $HALF )) # jump to this charakter for the last part of the name
OFFLINE_SSID=$OFFLINE_PREFIX${NODENAME:0:$HALF}...${NODENAME:$SKIP:${#NODENAME}} # use the first and last part of the nodename for nodes with long name TQ_LIMIT_MAX="$(uci get ssid-changer.settings.tq_limit_max -q)"
: ${TQ_LIMIT_MAX:='55'} # upper limit, above that the online SSID will be used
TQ_LIMIT_MIN="$(uci get ssid-changer.settings.tq_limit_min -q)"
: ${TQ_LIMIT_MIN:='45'} # lower limit, below that the offline SSID will be used
if [ "$(uci get ssid-changer.settings.enabled -q)" = '0' ]; then
DISABLED='1'
else else
OFFLINE_SSID="$OFFLINE_PREFIX$NODENAME" # great! we are able to use the full nodename in the offline ssid DISABLED='0'
fi fi
# maximum simplified, no more ttvn rating if [ $SETTINGS_SUFFIX = 'nodename' ]; then
CHECK=$(batctl gwl -H|grep -v "gateways in range"|wc -l) SUFFIX="$(uname -n)"
if [ ${#SUFFIX} -gt $((30 - ${#PREFIX})) ]; then # 32 would be possible as well
HALF=$(( (28 - ${#PREFIX} ) / 2 )) # calculate the length of the first part of the node identifier in the offline-ssid
SKIP=$(( ${#SUFFIX} - $HALF )) # jump to this charakter for the last part of the name
SUFFIX=${SUFFIX:0:$HALF}...${SUFFIX:$SKIP:${#SUFFIX}} # use the first and last part of the nodename for nodes with long name
fi
elif [ $SETTINGS_SUFFIX = 'mac' ]; then
SUFFIX="$(uci get network.bat0.macaddr -q)"
else
SUFFIX=''
fi
OFFLINE_SSID="$PREFIX$SUFFIX"
# TODO: ffac tq limits has to be implemented here if enabled
TQ_LIMIT_ENABLED=0 # disabled for now
ONLINE_SSID="$(uci get wireless.client_radio0.ssid -q)"
: ${ONLINE_SSID:="FREIFUNK"} # if for whatever reason ONLINE_SSID is NULL
CHECK="$(batctl gwl -H|grep -v "gateways in range"|wc -l)"
HUP_NEEDED=0 HUP_NEEDED=0
if [ $CHECK -gt 0 ]; then if [ "$CHECK" -gt 0 ] || [ "$DISABLED" = '1' ]; then
echo "node is online" echo "node is online"
for HOSTAPD in $(ls /var/run/hostapd-phy*); do # check status for all physical devices for HOSTAPD in $(ls /var/run/hostapd-phy*); do # check status for all physical devices
CURRENT_SSID="$(grep "^ssid=$ONLINE_SSID" $HOSTAPD | cut -d"=" -f2)" CURRENT_SSID="$(grep "^ssid=$ONLINE_SSID" $HOSTAPD | cut -d"=" -f2)"
...@@ -31,14 +64,14 @@ if [ $CHECK -gt 0 ]; then ...@@ -31,14 +64,14 @@ if [ $CHECK -gt 0 ]; then
fi fi
CURRENT_SSID="$(grep "^ssid=$OFFLINE_SSID" $HOSTAPD | cut -d"=" -f2)" CURRENT_SSID="$(grep "^ssid=$OFFLINE_SSID" $HOSTAPD | cut -d"=" -f2)"
if [ "$CURRENT_SSID" = "$OFFLINE_SSID" ]; then if [ "$CURRENT_SSID" = "$OFFLINE_SSID" ]; then
logger -s -t "gluon-offline-ssid" -p 5 "SSID is $CURRENT_SSID, change to $ONLINE_SSID" logger -s -t "gluon-ssid-changer" -p 5 "SSID is $CURRENT_SSID, change to $ONLINE_SSID"
sed -i "s~^ssid=$CURRENT_SSID~ssid=$ONLINE_SSID~" $HOSTAPD sed -i "s~^ssid=$CURRENT_SSID~ssid=$ONLINE_SSID~" $HOSTAPD
HUP_NEEDED=1 # HUP here would be to early for dualband devices HUP_NEEDED=1 # HUP here would be to early for dualband devices
else else
echo "There is something wrong, did not find SSID $ONLINE_SSID or $OFFLINE_SSID" logger -s -t "gluon-ssid-changer" -p 5 "could not set to online state: did neither find SSID '$ONLINE_SSID' nor '$OFFLINE_SSID'. Please reboot"
fi fi
done done
elif [ $CHECK -eq 0 ]; then elif [ "$CHECK" -eq 0 ]; then
echo "node is considered offline" echo "node is considered offline"
UP=$(cat /proc/uptime | sed 's/\..*//g') UP=$(cat /proc/uptime | sed 's/\..*//g')
if [ $(($UP / 60)) -lt $FIRST ] || [ $(($UP / 60 % $MINUTES)) -eq 0 ]; then if [ $(($UP / 60)) -lt $FIRST ] || [ $(($UP / 60 % $MINUTES)) -eq 0 ]; then
...@@ -50,11 +83,11 @@ elif [ $CHECK -eq 0 ]; then ...@@ -50,11 +83,11 @@ elif [ $CHECK -eq 0 ]; then
fi fi
CURRENT_SSID="$(grep "^ssid=$ONLINE_SSID" $HOSTAPD | cut -d"=" -f2)" CURRENT_SSID="$(grep "^ssid=$ONLINE_SSID" $HOSTAPD | cut -d"=" -f2)"
if [ "$CURRENT_SSID" = "$ONLINE_SSID" ]; then if [ "$CURRENT_SSID" = "$ONLINE_SSID" ]; then
logger -s -t "gluon-offline-ssid" -p 5 "SSID is $CURRENT_SSID, change to $OFFLINE_SSID" logger -s -t "gluon-ssid-changer" -p 5 "SSID is $CURRENT_SSID, change to $OFFLINE_SSID"
sed -i "s~^ssid=$ONLINE_SSID~ssid=$OFFLINE_SSID~" $HOSTAPD sed -i "s~^ssid=$ONLINE_SSID~ssid=$OFFLINE_SSID~" $HOSTAPD
HUP_NEEDED=1 HUP_NEEDED=1
else else
echo "There is something wrong: did neither find SSID '$ONLINE_SSID' nor '$OFFLINE_SSID'" logger -s -t "gluon-ssid-changer" -p 5 "could not set to offline state: did neither find SSID '$ONLINE_SSID' nor '$OFFLINE_SSID'. Please reboot"
fi fi
done done
fi fi
......
#!/usr/bin/lua
local site = require 'gluon.site_config'
local legacy_uci = require 'luci.model.uci'
local uci = legacy_uci.cursor()
-- LEDE: local uci = require('simple-uci').cursor()
if not uci:get('ssid-changer', 'settings', 'enabled') then
uci:section('ssid-changer', 'main', 'settings', {
enabled = '1',
switch_timeframe = site.switch_timeframe or '1',
first = site.first or '5',
prefix = site.prefix or 'FF_OFFLINE_',
suffix = site.suffix or 'nodename',
tq_limit_enabled = site.tq_limit_enabled or '0',
tq_limit_max = site.tq_limit_max or '55',
tq_limit_min = site.tq_limit_min or '45',
})
end
uci:save('ssid-changer')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment