diff --git a/docs/index.rst b/docs/index.rst
index 037679ae..4aab3cbc 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -65,6 +65,7 @@ Several Freifunk communities in Germany use Gluon as the foundation of their Fre
package/gluon-ebtables-source-filter
package/gluon-hoodselector
package/gluon-mesh-batman-adv
+ package/gluon-offline-ssid
package/gluon-radv-filterd
package/gluon-scheduled-domain-switch
package/gluon-web-admin
diff --git a/docs/package/gluon-ssid-changer.rst b/docs/package/gluon-offline-ssid.rst
similarity index 86%
rename from docs/package/gluon-ssid-changer.rst
rename to docs/package/gluon-offline-ssid.rst
index 10dc7a6d..7f29510e 100644
--- a/docs/package/gluon-ssid-changer.rst
+++ b/docs/package/gluon-offline-ssid.rst
@@ -1,11 +1,11 @@
-gluon-ssid-changer
+gluon-offline-ssid
==================
This package adds a script to change the SSID when there is no connection to any
gateway. This Offline-SSID can be generated from the node's hostname with the
first and last part of the node name or the MAC address allowing observers to
recognize which node does not have a connection to a gateway. This script is
-called once every minute by ``micron.d`` and check gateway-connectivity. It will
+called once every minute by ``micrond`` and check gateway-connectivity. It will
change the SSID to the Offline-SSID after the node lost gateway connectivity for
several consecutive checks. As soon as the gateway-connectivity is back it
toggles back to the original SSID.
@@ -41,14 +41,14 @@ Adapt and add this block to your ``site.conf``:
::
- ssid_changer = {
- enabled = true,
+ offline_ssid = {
+ disabled = false,
switch_timeframe = 30, -- only once every timeframe (in minutes) the SSID will change to the Offline-SSID
-- set to 1440 to change once a day
-- 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 may be
-- activated every minute (must be <= switch_timeframe)
- prefix = 'FF_Offline_', -- use something short to leave space for the nodename (no '~' allowed!)
+ prefix = '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'
tq_limit_enabled = false, -- if false, the offline SSID will only be set if there is no gateway reacheable
@@ -62,16 +62,16 @@ Adapt and add this block to your ``site.conf``:
Commandline options
===================
-You can configure the ssid-changer on the commandline with ``uci``, for example
+You can configure the offline-ssid on the commandline with ``uci``, for example
disable it with:
::
- uci set ssid-changer.settings.enabled='0'
+ uci set gluon-offline-ssid.settings.disabled='1'
Or set the timeframe to every three minutes with
::
- uci set ssid-changer.settings.switch_timeframe='3'
- uci set ssid-changer.settings.first='3'
+ uci set gluon-offline-ssid.settings.switch_timeframe='3'
+ uci set gluon-offline-ssid.settings.first='3'
diff --git a/package/gluon-ssid-changer/Makefile b/package/gluon-offline-ssid/Makefile
similarity index 62%
rename from package/gluon-ssid-changer/Makefile
rename to package/gluon-offline-ssid/Makefile
index bda435e1..4690ec53 100644
--- a/package/gluon-ssid-changer/Makefile
+++ b/package/gluon-offline-ssid/Makefile
@@ -1,9 +1,9 @@
include $(TOPDIR)/rules.mk
-PKG_NAME:=gluon-ssid-changer
-PKG_VERSION:=5
+PKG_NAME:=gluon-offline-ssid
+PKG_VERSION:=7
-include $(TOPDIR)/../package/gluon.mk
+include ../gluon.mk
define Package/$(PKG_NAME)
TITLE:=changes the SSID to an Offline-SSID so clients don't connect to an offline WiFi
@@ -19,18 +19,4 @@ define Package/$(PKG_NAME)/description
most.
endef
-
-define Build/Compile
- $(call Gluon/Build/Compile)
- ./gluonShellDiet.sh shsrc/ssid-changer.sh > $(PKG_BUILD_DIR)/ssid-changer.sh
-endef
-
-define Package/$(PKG_NAME)/install
- $(Gluon/Build/Install)
-
- $(INSTALL_DIR) $(1)/lib/gluon/ssid-changer
- $(INSTALL_BIN) $(PKG_BUILD_DIR)/ssid-changer.sh $(1)/lib/gluon/ssid-changer/
-endef
-
-
$(eval $(call BuildPackageGluon,$(PKG_NAME)))
diff --git a/package/gluon-offline-ssid/check_site.lua b/package/gluon-offline-ssid/check_site.lua
new file mode 100644
index 00000000..821f2edd
--- /dev/null
+++ b/package/gluon-offline-ssid/check_site.lua
@@ -0,0 +1,9 @@
+need_boolean({'offline_ssid', 'disabled'}, false)
+need_number({'offline_ssid', 'switch_timeframe'}, false)
+need_number({'offline_ssid', 'first'}, false)
+need_string({'offline_ssid', 'prefix'}, false)
+need_one_of({'offline_ssid', 'suffix'}, {'nodename', 'mac', 'none'}, false)
+if need_boolean({'offline_ssid','tq_limit_enabled'}, false) then
+ need_number({'offline_ssid', 'tq_limit_max'}, false)
+ need_number({'offline_ssid', 'tq_limit_min'}, false)
+end
diff --git a/package/gluon-ssid-changer/files/etc/config/ssid-changer b/package/gluon-offline-ssid/files/etc/config/gluon-offline-ssid
similarity index 100%
rename from package/gluon-ssid-changer/files/etc/config/ssid-changer
rename to package/gluon-offline-ssid/files/etc/config/gluon-offline-ssid
diff --git a/package/gluon-offline-ssid/files/usr/lib/micron.d/gluon-offline-ssid b/package/gluon-offline-ssid/files/usr/lib/micron.d/gluon-offline-ssid
new file mode 100644
index 00000000..1813f186
--- /dev/null
+++ b/package/gluon-offline-ssid/files/usr/lib/micron.d/gluon-offline-ssid
@@ -0,0 +1 @@
+* * * * * /usr/bin/gluon-offline-ssid.lua
diff --git a/package/gluon-offline-ssid/luasrc/lib/gluon/upgrade/500-gluon-offline-ssid b/package/gluon-offline-ssid/luasrc/lib/gluon/upgrade/500-gluon-offline-ssid
new file mode 100755
index 00000000..d1351156
--- /dev/null
+++ b/package/gluon-offline-ssid/luasrc/lib/gluon/upgrade/500-gluon-offline-ssid
@@ -0,0 +1,21 @@
+#!/usr/bin/lua
+
+local site = require 'gluon.site'
+
+local uci = require('simple-uci').cursor()
+
+if site.offline_ssid ~= nil then
+ local site_disabled = site.offline_ssid.disabled() or '0'
+
+ uci:section('gluon-offline-ssid', 'settings', 'settings', {
+ disabled = uci:get('gluon-offline-ssid', 'settings', 'disabled') or site_disabled,
+ switch_timeframe = site.offline_ssid.switch_timeframe() or '30',
+ first = site.offline_ssid.first() or '5',
+ prefix = site.offline_ssid.prefix() or 'Offline_',
+ suffix = site.offline_ssid.suffix() or 'nodename',
+ tq_limit_enabled = site.offline_ssid.tq_limit_enabled() or false,
+ tq_limit_max = site.offline_ssid.tq_limit_max() or 45,
+ tq_limit_min = site.offline_ssid.tq_limit_min() or 35,
+ })
+ uci:save('gluon-offline-ssid')
+end
diff --git a/package/gluon-offline-ssid/luasrc/usr/bin/gluon-offline-ssid.lua b/package/gluon-offline-ssid/luasrc/usr/bin/gluon-offline-ssid.lua
new file mode 100644
index 00000000..bdd07593
--- /dev/null
+++ b/package/gluon-offline-ssid/luasrc/usr/bin/gluon-offline-ssid.lua
@@ -0,0 +1,219 @@
+#!/usr/bin/lua
+
+local uci = require("simple-uci").cursor()
+local util = require 'gluon.util'
+
+local function safety_exit(t)
+ io.write(t .. ", exiting with error code 2")
+ os.exit(2)
+end
+
+local function logger(m)
+ os.execute('logger -s -t "gluon-offline-ssid" -p 5 "' .. m .. '"')
+end
+
+local function file_exists(name)
+ local f = io.open(name, "r")
+ return f ~= nil and io.close(f)
+end
+
+local ut = util.get_uptime()
+if ut < 60 then
+ safety_exit('less than one minute')
+end
+
+-- only once every timeframe minutes the ssid will change to the offline-ssid
+-- (set to 1 minute if you want to change immediately every time the router gets offline)
+local minutes = tonumber(uci:get('gluon-offline-ssid', 'settings', 'switch_timeframe') or '30')
+
+-- the first few minutes directly after reboot within which an offline-ssid always may be activated
+-- (must be <= switch_timeframe)
+local first = tonumber(uci:get('gluon-offline-ssid', 'settings', 'first') or '5')
+
+-- the offline-ssid will start with this prefix use something short to leave space for the nodename
+-- (no '~' allowed!)
+local prefix = uci:get('gluon-offline-ssid', 'settings', 'prefix') or 'Offline_'
+
+local disabled = uci:get('gluon-offline-ssid', 'settings', 'disabled') == '1' or false
+if disabled then
+ print("offline-ssid is disabled")
+end
+local phys = { length = 0 }
+uci:foreach('wireless', 'wifi-device', function(config)
+ local phy = util.find_phy(config)
+ if phy then
+ phys[config['.name']] = phy
+ phys['length'] = phys['length'] + 1
+ end
+end)
+if phys['length'] == 0 then
+ safety_exit('no hostapd-phys')
+end
+
+local ssids = { }
+uci:foreach('wireless', 'wifi-iface', function(config)
+ if config['mode'] == 'ap' and config['network'] == 'client' then
+ local ssid = config['ssid']
+ if ssid then
+ table.insert(ssids, { ssid = ssid , phy = phys[config['device']] })
+ end
+ end
+end)
+if #ssids == 0 then
+ safety_exit('no ssids')
+end
+
+-- generate the ssid with either 'nodename', 'mac' or to use only the prefix set to 'none'
+local settings_suffix = uci:get('gluon-offline-ssid', 'settings', 'suffix') or 'nodename'
+
+local suffix
+if settings_suffix == 'nodename' then
+ local pretty_hostname = require 'pretty_hostname'
+ suffix = pretty_hostname.get(uci)
+ -- 32 would be possible as well
+ if ( string.len(suffix) > 30 - string.len(prefix) ) then
+ -- calculate the length of the first part of the node identifier in the offline-ssid
+ local half = math.floor((28 - string.len(prefix) ) / 2)
+ -- jump to this charakter for the last part of the name
+ local skip = string.len(suffix) - half
+ -- use the first and last part of the nodename for nodes with long name
+ suffix = string.sub(suffix,0,half) .. '...' .. string.sub(suffix, skip)
+ end
+elseif settings_suffix == 'mac' then
+ local sysconfig = require 'gluon.sysconfig'
+ suffix = sysconfig.primary_mac
+else
+ -- 'none'
+ suffix = ''
+end
+local offline_ssid = prefix .. suffix
+
+-- temp file to count the offline incidents during switch_timeframe
+local tmp = '/tmp/offline-ssid-count'
+local off_count = '0'
+if not file_exists(tmp) then
+ assert(io.open(tmp, 'w')):write('0')
+else
+ off_count = tonumber(util.readfile(tmp))
+end
+
+-- if tq_limit_enabled is 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
+-- in-between these two values the ssid will never be changed to preven it from toggeling every minute.
+local tq_limit_enabled = tonumber(uci:get('gluon-offline-ssid', 'settings', 'tq_limit_enabled') or '0')
+
+local check
+local msg
+if ( tq_limit_enabled == 1 ) then
+ -- upper limit, above that the online ssid will be used
+ local tq_limit_max = tonumber(uci:get('gluon-offline-ssid', 'settings', 'tq_limit_max') or '45')
+ -- lower limit, below that the offline ssid will be used
+ local tq_limit_min = tonumber(uci:get('gluon-offline-ssid', 'settings', 'tq_limit_min') or '35')
+ -- grep the connection quality of the currently used gateway
+ local gateway_tq = util.exec('batctl gwl | grep -e "^=>" -e "^\\*" | awk -F \'[()]\' \'{print $2}\' | tr -d " "')
+ if ( gateway_tq == '' ) then
+ -- there is no gateway
+ gateway_tq = 0
+ end
+ msg = "tq is " .. gateway_tq
+
+ if ( gateway_tq >= tq_limit_max ) then
+ check = 1
+ elseif ( gateway_tq < tq_limit_min ) then
+ check = 0
+ else
+ -- get a clean run if we are in-between the grace period
+ print(msg .. ", do nothing")
+ os.exit(0)
+ end
+else
+ msg = ""
+ check = os.execute('batctl gwl -H | grep -v "gateways in range"')
+end
+
+local up = ut / 60
+local m = math.floor(up % minutes)
+
+-- debug:
+print("uptime in minutes:"..up..", every "..minutes.." minutes, countdown:"..m)
+
+local hup_needed = 0
+local ssid_grep = 'grep "^ssid='
+
+-- debug:
+-- check=0 -- set this to set the node always offline
+
+if check > 0 or disabled then
+ print("node is online")
+ -- check status for all physical devices
+ for _, ssid in ipairs(ssids) do
+ local hostapd = '/var/run/hostapd-' .. ssid.phy .. '.conf'
+
+ -- first grep for online-SSID in hostapd file
+ if os.execute(ssid_grep .. ssid.ssid .. '" ' .. hostapd) == 0 then
+ print("current ssid is correct")
+ break
+ else
+ -- set online
+ -- debug: grep for offline_ssid in hostapd file
+ if os.execute(ssid_grep .. offline_ssid .. '" ' .. hostapd) ~= 0 then
+ logger('misconfiguration: did neither find ssid ' .. ssid.ssid .. ' nor ' .. offline_ssid .. '. please reboot')
+ end
+
+ local current_ssid = util.trim(util.exec(ssid_grep .. '" ' .. hostapd .. ' | cut -d"=" -f2'))
+ -- TODO: replace ~ in current_ssid and ssid.ssid
+
+ logger(msg .. ' - ssid is ' .. current_ssid .. ', change to ' .. ssid.ssid)
+ os.execute('sed -i "s~^ssid=' .. current_ssid .. '~ssid=' .. ssid.ssid .. '~" ' .. hostapd)
+ hup_needed = 1
+ end
+ end
+elseif check == 0 then
+ print("node is considered offline")
+ if up < first or m == 0 then
+ -- set ssid offline, only if uptime is less than first or exactly a multiplicative of switch_timeframe
+ local t = minutes
+ if up < first then
+ t = first
+ end
+ if off_count >= t / 2 then
+ -- node was offline more times than half of switch_timeframe (or than first)
+ for _, ssid in ipairs(ssids) do
+ local hostapd = '/var/run/hostapd-' .. ssid.phy .. '.conf'
+ local current_ssid = util.trim(util.exec(ssid_grep .. '" ' .. hostapd .. ' | cut -d"=" -f2'))
+
+ -- first grep for offline_ssid in hostapd file
+ if os.execute(ssid_grep .. offline_ssid .. '" ' .. hostapd) == 0 then
+ print('ssid ' .. current_ssid .. ' is correct')
+ break
+ else
+ -- set offline
+ -- debug: grep for online-SSID in hostapd file
+ if os.execute(ssid_grep .. ssid.ssid .. '" ' .. hostapd) == 0 then
+ logger('misconfiguration: did neither find ssid '
+ .. ssid.ssid .. ' nor ' .. offline_ssid .. '. please reboot')
+ end
+
+ logger(msg .. ' - ' .. off_count .. ' times offline, ssid is '
+ .. current_ssid .. ', change to ' .. offline_ssid)
+ os.execute('sed -i "s~^ssid=' .. ssid.ssid .. '~ssid=' .. offline_ssid .. '~" ' .. hostapd)
+ hup_needed = 1
+ end
+ end
+ end
+ -- else print("minute ' .. m .. ', just count ' .. off_count .. '")
+ end
+
+ assert(io.open(tmp, 'w')):write(off_count + 1)
+end
+
+if hup_needed == 1 then
+ -- send hup to all hostapd to load the new ssid
+ os.execute('killall -hup hostapd')
+ print("hup!")
+end
+
+if m == 0 then
+ -- set counter to 0 if the timeframe is over
+ assert(io.open(tmp, 'w')):write('0')
+end
diff --git a/package/gluon-ssid-changer/check_site.lua b/package/gluon-ssid-changer/check_site.lua
deleted file mode 100644
index ab4c2a62..00000000
--- a/package/gluon-ssid-changer/check_site.lua
+++ /dev/null
@@ -1,9 +0,0 @@
-need_boolean({'ssid_changer', 'enabled'}, false)
-need_number({'ssid_changer', 'switch_timeframe'}, false)
-need_number({'ssid_changer', 'first'}, false)
-need_string({'ssid_changer', 'prefix'}, false)
-need_one_of({'ssid_changer', 'suffix'}, {'nodename', 'mac', 'none'}, false)
-if need_boolean({'ssid_changer','tq_limit_enabled'}, false) then
- need_number({'ssid_changer', 'tq_limit_max'}, false)
- need_number({'ssid_changer', 'tq_limit_min'}, false)
-end
diff --git a/package/gluon-ssid-changer/files/usr/lib/micron.d/ssid-changer b/package/gluon-ssid-changer/files/usr/lib/micron.d/ssid-changer
deleted file mode 100644
index e3a99fa4..00000000
--- a/package/gluon-ssid-changer/files/usr/lib/micron.d/ssid-changer
+++ /dev/null
@@ -1 +0,0 @@
-* * * * * /lib/gluon/ssid-changer/ssid-changer.sh
diff --git a/package/gluon-ssid-changer/gluonShellDiet.sh b/package/gluon-ssid-changer/gluonShellDiet.sh
deleted file mode 100755
index 1cb74ad6..00000000
--- a/package/gluon-ssid-changer/gluonShellDiet.sh
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/bin/sh
-
-# This script requires a file as argument in which it will remove all comment lines that start with a hash '#'
-
-sed '/^\s*\#[^!].*/d; /^\s*\#$/d' $1
diff --git a/package/gluon-ssid-changer/i18n/gluon-ssid-changer.pot b/package/gluon-ssid-changer/i18n/gluon-ssid-changer.pot
deleted file mode 100644
index 16db87db..00000000
--- a/package/gluon-ssid-changer/i18n/gluon-ssid-changer.pot
+++ /dev/null
@@ -1,10 +0,0 @@
-msgid ""
-msgstr "Content-Type: text/plain; charset=UTF-8"
-
-msgid "Enabled"
-msgstr ""
-
-msgid ""
-"Here you can enable to automatically change the SSID to the Offline-SSID "
-"when the node has no connection to the selected Gateway."
-msgstr ""
diff --git a/package/gluon-ssid-changer/luasrc/lib/gluon/config-mode/controller/admin/ssid-changer.lua b/package/gluon-ssid-changer/luasrc/lib/gluon/config-mode/controller/admin/ssid-changer.lua
deleted file mode 100644
index d84d3cef..00000000
--- a/package/gluon-ssid-changer/luasrc/lib/gluon/config-mode/controller/admin/ssid-changer.lua
+++ /dev/null
@@ -1 +0,0 @@
-entry({"admin", "ssid-changer"}, model("admin/ssid-changer"), _("Offline-SSID"), 35)
diff --git a/package/gluon-ssid-changer/luasrc/lib/gluon/config-mode/model/admin/ssid-changer.lua b/package/gluon-ssid-changer/luasrc/lib/gluon/config-mode/model/admin/ssid-changer.lua
deleted file mode 100644
index 282164c1..00000000
--- a/package/gluon-ssid-changer/luasrc/lib/gluon/config-mode/model/admin/ssid-changer.lua
+++ /dev/null
@@ -1,28 +0,0 @@
-local uci = require('simple-uci').cursor()
-local util = require 'gluon.util'
-
-local pkg_i18n = i18n 'gluon-ssid-changer'
-
-local f = Form(pkg_i18n.translate('Offline-SSID'))
-
-local s = f:section(Section, nil, pkg_i18n.translate(
- 'Here you can enable to automatically change the SSID to the Offline-SSID '
- .. 'when the node has no connection to the selected Gateway.'
-))
-
-local enabled = s:option(Flag, 'enabled', pkg_i18n.translate('Enabled'))
-enabled.default = uci:get_bool('ssid-changer', 'settings', 'enabled')
-
-function f:write()
- if enabled.data then
- uci:section('ssid-changer', 'settings', 'settings', {
- enabled = '1'
- })
- else
- uci:set('ssid-changer', 'settings', 'enabled', '0')
- end
-
- uci:commit('ssid-changer')
-end
-
-return f
diff --git a/package/gluon-ssid-changer/luasrc/lib/gluon/upgrade/500-ssid-changer b/package/gluon-ssid-changer/luasrc/lib/gluon/upgrade/500-ssid-changer
deleted file mode 100755
index 34db9649..00000000
--- a/package/gluon-ssid-changer/luasrc/lib/gluon/upgrade/500-ssid-changer
+++ /dev/null
@@ -1,21 +0,0 @@
-#!/usr/bin/lua
-
-local site = require 'gluon.site'
-
-local uci = require('simple-uci').cursor()
-
-if site.ssid_changer ~= nil then
- local site_enabled = site.ssid_changer.enabled() or '1'
-
- uci:section('ssid-changer', 'settings', 'settings', {
- enabled = uci:get('ssid-changer', 'settings', 'enabled') or site_enabled,
- switch_timeframe = site.ssid_changer.switch_timeframe() or '30',
- first = site.ssid_changer.first() or '5',
- prefix = site.ssid_changer.prefix() or 'FF_Offline_',
- suffix = site.ssid_changer.suffix() or 'nodename',
- tq_limit_enabled = site.ssid_changer.tq_limit_enabled() or false,
- tq_limit_max = site.ssid_changer.tq_limit_max() or 45,
- tq_limit_min = site.ssid_changer.tq_limit_min() or 35,
- })
- uci:save('ssid-changer')
-end
diff --git a/package/gluon-ssid-changer/shsrc/ssid-changer.sh b/package/gluon-ssid-changer/shsrc/ssid-changer.sh
deleted file mode 100755
index cf0f73dd..00000000
--- a/package/gluon-ssid-changer/shsrc/ssid-changer.sh
+++ /dev/null
@@ -1,180 +0,0 @@
-#!/bin/sh
-
-#################
-# safety checks #
-#################
-safety_exit() {
- echo $1, exiting with error code 2
- exit 2
-}
-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*'
-
-# 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)
-MINUTES="$(uci -q get ssid-changer.settings.switch_timeframe)"
-: ${MINUTES:=30}
-
-# the first few minutes directly after reboot within which an Offline-SSID always may be activated
-# (must be <= switch_timeframe)
-FIRST="$(uci -q get ssid-changer.settings.first)"
-: ${FIRST:=5}
-
-# the Offline-SSID will start with this prefix use something short to leave space for the nodename
-# (no '~' allowed!)
-PREFIX="$(uci -q get ssid-changer.settings.prefix)"
-: ${PREFIX:='FF_Offline_'}
-
-if [ "$(uci -q get ssid-changer.settings.enabled)" = '0' ]; then
- DISABLED='1'
-else
- DISABLED='0'
-fi
-
-# generate the ssid with either 'nodename', 'mac' or to use only the prefix set to 'none'
-SETTINGS_SUFFIX="$(uci -q get ssid-changer.settings.suffix)"
-: ${SETTINGS_SUFFIX:='nodename'}
-
-if [ $SETTINGS_SUFFIX = 'nodename' ]; then
- SUFFIX="$(uname -n)"
- # 32 would be possible as well
- if [ ${#SUFFIX} -gt $((30 - ${#PREFIX})) ]; then
- # calculate the length of the first part of the node identifier in the offline-ssid
- HALF=$(( (28 - ${#PREFIX} ) / 2 ))
- # jump to this charakter for the last part of the name
- SKIP=$(( ${#SUFFIX} - $HALF ))
- # use the first and last part of the nodename for nodes with long name
- SUFFIX=${SUFFIX:0:$HALF}...${SUFFIX:$SKIP:${#SUFFIX}}
- fi
-elif [ $SETTINGS_SUFFIX = 'mac' ]; then
- SUFFIX="$(uci -q get network.bat0.macaddr | /bin/sed 's/://g')"
-else
- # 'none'
- SUFFIX=''
-fi
-
-OFFLINE_SSID="$PREFIX$SUFFIX"
-
-# get all SSIDs (replace \' with TICX and back to keep a possible tic in an SSID)
-ONLINE_SSIDs="$(uci show | grep wireless.client_radio[0-9]\. | grep ssid | awk -F '=' '{print $2}' | sed "s/\\\'/TICX/g" | tr \' \~ | sed "s/TICX/\\\'/g" ) "
-# if for whatever reason ONLINE_SSIDs is NULL:
-: ${ONLINE_SSIDs:="~FREIFUNK~"}
-
-# temp file to count the offline incidents during switch_timeframe
-TMP=/tmp/ssid-changer-count
-if [ ! -f $TMP ]; then echo "0">$TMP; fi
-OFF_COUNT=$(cat $TMP)
-
-TQ_LIMIT_ENABLED="$(uci -q get ssid-changer.settings.tq_limit_enabled)"
-# 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
-# in-between these two values the SSID will never be changed to preven it from toggeling every Minute.
-: ${TQ_LIMIT_ENABLED:='0'}
-
-if [ $TQ_LIMIT_ENABLED = 1 ]; then
- TQ_LIMIT_MAX="$(uci -q get ssid-changer.settings.tq_limit_max)"
- # upper limit, above that the online SSID will be used
- : ${TQ_LIMIT_MAX:='45'}
- TQ_LIMIT_MIN="$(uci -q get ssid-changer.settings.tq_limit_min)"
- # lower limit, below that the offline SSID will be used
- : ${TQ_LIMIT_MIN:='35'}
- # grep the connection quality of the currently used gateway
- GATEWAY_TQ=$(batctl gwl | grep -e "^=>" -e "^\*" | awk -F '[('')]' '{print $2}' | tr -d " ")
- if [ ! $GATEWAY_TQ ]; then
- # there is no gateway
- GATEWAY_TQ=0
- fi
-
- MSG="TQ is $GATEWAY_TQ, "
-
- if [ $GATEWAY_TQ -ge $TQ_LIMIT_MAX ]; then
- CHECK=1
- elif [ $GATEWAY_TQ -lt $TQ_LIMIT_MIN ]; then
- CHECK=0
- else
- # this is just get a clean run if we are in-between the grace periode
- echo "TQ is $GATEWAY_TQ, do nothing"
- exit 0
- fi
-else
- MSG=""
- CHECK="$(batctl gwl -H|grep -v "gateways in range"|wc -l)"
-fi
-
-UP=$(($UT / 60))
-M=$(($UP % $MINUTES))
-
-HUP_NEEDED=0
-if [ "$CHECK" -gt 0 ] || [ "$DISABLED" = '1' ]; then
- echo "node is online"
- LOOP=1
- # check status for all physical devices
- for HOSTAPD in $(ls /var/run/hostapd-phy*); do
- ONLINE_SSID="$(echo $ONLINE_SSIDs | awk -F '~' -v l=$((LOOP*2)) '{print $l}')"
- LOOP=$((LOOP+1))
- CURRENT_SSID="$(grep "^ssid=$ONLINE_SSID" $HOSTAPD | cut -d"=" -f2)"
- if [ "$CURRENT_SSID" = "$ONLINE_SSID" ]; then
- echo "SSID $CURRENT_SSID is correct, nothing to do"
- break
- fi
- CURRENT_SSID="$(grep "^ssid=$OFFLINE_SSID" $HOSTAPD | cut -d"=" -f2)"
- if [ "$CURRENT_SSID" = "$OFFLINE_SSID" ]; then
- # set online
- logger -s -t "gluon-ssid-changer" -p 5 $MSG"SSID is $CURRENT_SSID, change to $ONLINE_SSID"
- sed -i "s~^ssid=$CURRENT_SSID~ssid=$ONLINE_SSID~" $HOSTAPD
- # HUP here would be to early for dualband devices
- HUP_NEEDED=1
- else
- 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
- done
-elif [ "$CHECK" -eq 0 ]; then
- echo "node is considered offline"
- if [ $UP -lt $FIRST ] || [ $M -eq 0 ]; then
- # set SSID offline, only if uptime is less than FIRST or exactly a multiplicative of switch_timeframe
- if [ $UP -lt $FIRST ]; then
- T=$FIRST
- else
- T=$MINUTES
- fi
- #echo minute $M, check if $OFF_COUNT is more than half of $T
- 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 $(ls /var/run/hostapd-phy*); do
- ONLINE_SSID="$(echo $ONLINE_SSIDs | awk -F '~' -v l=$((LOOP*2)) '{print $l}')"
- LOOP=$((LOOP+1))
- CURRENT_SSID="$(grep "^ssid=$OFFLINE_SSID" $HOSTAPD | cut -d"=" -f2)"
- if [ "$CURRENT_SSID" = "$OFFLINE_SSID" ]; then
- echo "SSID $CURRENT_SSID is correct, nothing to do"
- break
- fi
- CURRENT_SSID="$(grep "^ssid=$ONLINE_SSID" $HOSTAPD | cut -d"=" -f2)"
- if [ "$CURRENT_SSID" = "$ONLINE_SSID" ]; then
- # set offline
- logger -s -t "gluon-ssid-changer" -p 5 $MSG"$OFF_COUNT times offline, SSID is $CURRENT_SSID, change to $OFFLINE_SSID"
- sed -i "s~^ssid=$ONLINE_SSID~ssid=$OFFLINE_SSID~" $HOSTAPD
- HUP_NEEDED=1
- else
- 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
- done
- fi
- #else echo minute $M, just count $OFF_COUNT
- fi
- echo "$(($OFF_COUNT + 1))">$TMP
-fi
-
-if [ $HUP_NEEDED = 1 ]; then
- # send HUP to all hostapd to load the new SSID
- killall -HUP hostapd
- HUP_NEEDED=0
- echo "HUP!"
-fi
-
-if [ $M -eq 0 ]; then
- # set counter to 0 if the timeframe is over
- echo "0">$TMP
-fi
diff --git a/package/gluon-web-offline-ssid/Makefile b/package/gluon-web-offline-ssid/Makefile
new file mode 100644
index 00000000..2351df75
--- /dev/null
+++ b/package/gluon-web-offline-ssid/Makefile
@@ -0,0 +1,13 @@
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=gluon-web-offline-ssid
+PKG_VERSION:=1
+
+include ../gluon.mk
+
+define Package/$(PKG_NAME)
+ TITLE:=adds an option to enable and disable the offline-ssid changer in advanced config mode
+ DEPENDS:=+gluon-web-admin +micrond +gluon-offline-ssid
+endef
+
+$(eval $(call BuildPackageGluon,$(PKG_NAME)))
diff --git a/package/gluon-ssid-changer/i18n/de.po b/package/gluon-web-offline-ssid/i18n/de.po
similarity index 82%
rename from package/gluon-ssid-changer/i18n/de.po
rename to package/gluon-web-offline-ssid/i18n/de.po
index cc198764..2f3767d0 100644
--- a/package/gluon-ssid-changer/i18n/de.po
+++ b/package/gluon-web-offline-ssid/i18n/de.po
@@ -10,12 +10,12 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
-msgid "Enabled"
-msgstr "Aktiviert"
+msgid "Disabled"
+msgstr "Deaktiviert"
msgid ""
-"Here you can enable to automatically change the SSID to the Offline-SSID "
-"when the node has no connection to the selected Gateway."
+"Here you can control the automatic change of the SSID to the Offline-SSID "
+"when the node has no connection to the selected gateway."
msgstr ""
"Hier kannst du aktivieren, dass dein Knoten automatisch die SSID auf die "
"Offline-SSID ändert, wenn keine Verbindung zu Freifunk Servern besteht.
"
diff --git a/package/gluon-web-offline-ssid/i18n/gluon-web-offline-ssid.pot b/package/gluon-web-offline-ssid/i18n/gluon-web-offline-ssid.pot
new file mode 100644
index 00000000..9eef5672
--- /dev/null
+++ b/package/gluon-web-offline-ssid/i18n/gluon-web-offline-ssid.pot
@@ -0,0 +1,10 @@
+msgid ""
+msgstr "Content-Type: text/plain; charset=UTF-8"
+
+msgid "Disabled"
+msgstr ""
+
+msgid ""
+"Here you can control the automatic change of the SSID to the Offline-SSID "
+"when the node has no connection to the selected gateway."
+msgstr ""
diff --git a/package/gluon-web-offline-ssid/luasrc/lib/gluon/config-mode/controller/admin/offline-ssid.lua b/package/gluon-web-offline-ssid/luasrc/lib/gluon/config-mode/controller/admin/offline-ssid.lua
new file mode 100644
index 00000000..d710b8ba
--- /dev/null
+++ b/package/gluon-web-offline-ssid/luasrc/lib/gluon/config-mode/controller/admin/offline-ssid.lua
@@ -0,0 +1,3 @@
+package 'gluon-web-offline-ssid'
+
+entry({"admin", "offline-ssid"}, model("admin/offline-ssid"), _("Offline-SSID"), 35)
diff --git a/package/gluon-web-offline-ssid/luasrc/lib/gluon/config-mode/model/admin/offline-ssid.lua b/package/gluon-web-offline-ssid/luasrc/lib/gluon/config-mode/model/admin/offline-ssid.lua
new file mode 100644
index 00000000..e5206206
--- /dev/null
+++ b/package/gluon-web-offline-ssid/luasrc/lib/gluon/config-mode/model/admin/offline-ssid.lua
@@ -0,0 +1,25 @@
+local uci = require('simple-uci').cursor()
+
+local pkg_i18n = i18n 'gluon-web-offline-ssid'
+
+local f = Form(pkg_i18n.translate('Offline-SSID'))
+
+local s = f:section(Section, nil, pkg_i18n.translate(
+ 'Here you can control the automatic change of the SSID to the Offline-SSID '
+ .. 'when the node has no connection to the selected gateway.'
+))
+
+local disabled = s:option(Flag, 'disabled', pkg_i18n.translate('Disabled'))
+disabled.default = uci:get_bool('gluon-offline-ssid', 'settings', 'disabled')
+
+function f:write()
+ if disabled.data then
+ uci:set('gluon-offline-ssid', 'settings', 'disabled', '1')
+ else
+ uci:set('gluon-offline-ssid', 'settings', 'disabled', '0')
+ end
+
+ uci:commit('gluon-offline-ssid')
+end
+
+return f