Skip to content

Commit 83989c8

Browse files
committed
gluon-ssid-changer: add this package to automatically change the SSID when no Internet connection
1 parent c1b9ea2 commit 83989c8

File tree

12 files changed

+410
-0
lines changed

12 files changed

+410
-0
lines changed

docs/package/gluon-ssid-changer.rst

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
gluon-ssid-changer
2+
==================
3+
4+
This package adds a script to change the SSID when there is no connection to any
5+
gateway. This Offline-SSID can be generated from the node's hostname with the
6+
first and last part of the node name or the MAC address allowing observers to
7+
recognize which node does not have a connection to a gateway. This script is
8+
called once every minute by ``micron.d`` and check gateway-connectivity. It will
9+
change the SSID to the Offline-SSID after the node lost gateway connectivity for
10+
several consecutive checks. As soon as the gateway-connectivity is back it
11+
toggles back to the original SSID.
12+
13+
You can enable/disable it in the config mode.
14+
15+
It checks if a gateway is reachable in an interval. Different algorithms can be
16+
selected to determine whether a gateway is reachable:
17+
18+
- ``tq_limit_enabled=true``: (not working with BATMAN\_V) define an upper and
19+
lower bound to toggle the SSID. As long as the TQ stays in-between those
20+
bounds the SSID will not be changed.
21+
- ``tq_limit_enabled=false``: there will be only checked, if the gateway is
22+
reachable with:
23+
24+
::
25+
26+
batctl gwl -H
27+
28+
The SSID is always changed back to normal every minute as soon as the
29+
gateway-connectivity is back, The parameter ``switch_timeframe`` defines how
30+
long it will record the gateway-connectivity. **Only** if the gateway is not
31+
reachable during at least half the checks within ``switch_timeframe`` minutes,
32+
the SSID will be changed to "FF\_Offline\_$node\_hostname".
33+
34+
The parameter ``first`` defines a learning phase after reboot (in minutes)
35+
during which the SSID may be changed to the Offline-SSID **every minute**.
36+
37+
site.conf
38+
=========
39+
40+
Adapt and add this block to your ``site.conf``:
41+
42+
::
43+
44+
ssid_changer = {
45+
enabled = true,
46+
switch_timeframe = 30, -- only once every timeframe (in minutes) the SSID will change to the Offline-SSID
47+
-- set to 1440 to change once a day
48+
-- set to 1 minute to change every time the router gets offline
49+
first = 5, -- the first few minutes directly after reboot within which an Offline-SSID may be
50+
-- activated every minute (must be <= switch_timeframe)
51+
prefix = 'FF_Offline_', -- use something short to leave space for the nodename (no '~' allowed!)
52+
suffix = 'nodename', -- generate the SSID with either 'nodename', 'mac' or to use only the prefix: 'none'
53+
54+
tq_limit_enabled = false, -- if false, the offline SSID will only be set if there is no gateway reacheable
55+
-- upper and lower limit to turn the offline_ssid on and off
56+
-- in-between these two values the SSID will never be changed to prevent it from
57+
-- toggeling every minute.
58+
tq_limit_max = 45, -- upper limit, above that the online SSID will be used
59+
tq_limit_min = 35 -- lower limit, below that the offline SSID will be used
60+
},
61+
62+
Commandline options
63+
===================
64+
65+
You can configure the ssid-changer on the commandline with ``uci``, for example
66+
disable it with:
67+
68+
::
69+
70+
uci set ssid-changer.settings.enabled='0'
71+
72+
Or set the timeframe to every three minutes with
73+
74+
::
75+
76+
uci set ssid-changer.settings.switch_timeframe='3'
77+
uci set ssid-changer.settings.first='3'

package/gluon-ssid-changer/Makefile

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
include $(TOPDIR)/rules.mk
2+
3+
PKG_NAME:=gluon-ssid-changer
4+
PKG_VERSION:=5
5+
6+
include $(TOPDIR)/../package/gluon.mk
7+
8+
define Package/$(PKG_NAME)
9+
TITLE:=changes the SSID to an Offline-SSID so clients don't connect to an offline WiFi
10+
DEPENDS:=+gluon-core +micrond
11+
endef
12+
13+
define Package/$(PKG_NAME)/description
14+
Script to change the SSID to an Offline-SSID when there is no connection to
15+
any gateway. This SSID can be generated from the nodes hostname with the first
16+
and last part of the nodename or the mac address, to allow observers to
17+
recognise which node is down. The script is called once a minute by micron.d
18+
and it will change from online to offline-SSID maximum once every (definable)
19+
timeframe.
20+
endef
21+
22+
23+
define Build/Compile
24+
$(call Gluon/Build/Compile)
25+
./gluonShellDiet.sh shsrc/ssid-changer.sh > $(PKG_BUILD_DIR)/ssid-changer.sh
26+
endef
27+
28+
define Package/$(PKG_NAME)/install
29+
$(Gluon/Build/Install)
30+
31+
$(INSTALL_DIR) $(1)/lib/gluon/ssid-changer
32+
$(INSTALL_BIN) $(PKG_BUILD_DIR)/ssid-changer.sh $(1)/lib/gluon/ssid-changer/
33+
endef
34+
35+
36+
$(eval $(call BuildPackageGluon,$(PKG_NAME)))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
need_boolean({'ssid_changer', 'enabled'}, false)
2+
need_number({'ssid_changer', 'switch_timeframe'}, false)
3+
need_number({'ssid_changer', 'first'}, false)
4+
need_string({'ssid_changer', 'prefix'}, false)
5+
need_one_of({'ssid_changer', 'suffix'}, {'nodename', 'mac', 'none'}, false)
6+
if need_boolean({'ssid_changer','tq_limit_enabled'}, false) then
7+
need_number({'ssid_changer', 'tq_limit_max'}, false)
8+
need_number({'ssid_changer', 'tq_limit_min'}, false)
9+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
config settings 'settings'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* * * * * /lib/gluon/ssid-changer/ssid-changer.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
3+
# This script requires a file as argument in which it will remove all comment lines that start with a hash '#'
4+
5+
sed '/^\s*\#[^!].*/d; /^\s*\#$/d' $1

package/gluon-ssid-changer/i18n/de.po

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
msgid ""
2+
msgstr ""
3+
"Project-Id-Version: PACKAGE VERSION\n"
4+
"PO-Revision-Date: 2018-07-29 15:26+0200\n"
5+
"Last-Translator: <[email protected]>\n"
6+
"Language-Team: German\n"
7+
"Language: de\n"
8+
"MIME-Version: 1.0\n"
9+
"Content-Type: text/plain; charset=UTF-8\n"
10+
"Content-Transfer-Encoding: 8bit\n"
11+
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
12+
13+
msgid "Enabled"
14+
msgstr "Aktiviert"
15+
16+
msgid ""
17+
"Here you can enable to automatically change the SSID to the Offline-SSID "
18+
"when the node has no connection to the selected Gateway."
19+
msgstr ""
20+
"Hier kannst du aktivieren, dass dein Knoten automatisch die SSID auf die "
21+
"Offline-SSID ändert, wenn keine Verbindung zu Freifunk Servern besteht.<br /><br />"
22+
"Das verhindert, dass Client-Geräte sich mit einem Knoten verbinden, an dem es "
23+
"derzeit keine nutzbare Interverbindung gibt.<br />"
24+
"Wenn in dieser Firmware der Suffix auf 'nodename' gestellt ist, dann kann man "
25+
"leichter anhand der dann gesendeten Offline-SSID nach einem fehlerhaften Gerät "
26+
"suchen."
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
msgid ""
2+
msgstr "Content-Type: text/plain; charset=UTF-8"
3+
4+
msgid "Enabled"
5+
msgstr ""
6+
7+
msgid ""
8+
"Here you can enable to automatically change the SSID to the Offline-SSID "
9+
"when the node has no connection to the selected Gateway."
10+
msgstr ""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
entry({"admin", "ssid-changer"}, model("admin/ssid-changer"), _("Offline-SSID"), 35)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
local uci = require('simple-uci').cursor()
2+
local util = require 'gluon.util'
3+
4+
local pkg_i18n = i18n 'gluon-ssid-changer'
5+
6+
local f = Form(pkg_i18n.translate('Offline-SSID'))
7+
8+
local s = f:section(Section, nil, pkg_i18n.translate(
9+
'Here you can enable to automatically change the SSID to the Offline-SSID '
10+
.. 'when the node has no connection to the selected Gateway.'
11+
))
12+
13+
local enabled = s:option(Flag, 'enabled', pkg_i18n.translate('Enabled'))
14+
enabled.default = uci:get_bool('ssid-changer', 'settings', 'enabled')
15+
16+
-- local prefix = s:option(Value, 'prefix', pkg_i18n.translate('First part of the Offline SSID'))
17+
-- prefix:depends(enabled, true)
18+
-- prefix.datatype = 'maxlength(32)'
19+
-- prefix.default = uci:get('ssid-changer', 'settings', 'prefix')
20+
21+
function f:write()
22+
if enabled.data then
23+
uci:section('ssid-changer', 'settings', 'settings', {
24+
enabled = '1',
25+
-- prefix = prefix.data
26+
-- switch_timeframe = switch_timeframe.data or '1440'
27+
-- tq_limit_max = tq_limit_max.data or '55'
28+
-- first = first.data or '5'
29+
-- prefix = prefix.data or 'FF_Offline_'
30+
-- suffix = suffix.data or 'nodename'
31+
-- tq_limit_min = tq_limit_min.data or '45'
32+
-- tq_limit_enabled = tq_limit_enabled.data or '0'
33+
})
34+
else
35+
uci:set('ssid-changer', 'settings', 'enabled', '0')
36+
end
37+
38+
uci:commit('ssid-changer')
39+
end
40+
41+
return f
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/lua
2+
3+
local site = require 'gluon.site'
4+
5+
local uci = require('simple-uci').cursor()
6+
7+
if site.ssid_changer == nil then
8+
-- print('ssid_changer not defined in site.conf')
9+
else
10+
local site_enabled = site.ssid_changer.enabled() or '1'
11+
12+
uci:section('ssid-changer', 'settings', 'settings', {
13+
enabled = uci:get('ssid-changer', 'settings', 'enabled') or site_enabled,
14+
switch_timeframe = site.ssid_changer.switch_timeframe() or '30',
15+
first = site.ssid_changer.first() or '5',
16+
prefix = site.ssid_changer.prefix() or 'FF_Offline_',
17+
suffix = site.ssid_changer.suffix() or 'nodename',
18+
tq_limit_enabled = site.ssid_changer.tq_limit_enabled() or false,
19+
tq_limit_max = site.ssid_changer.tq_limit_max() or 45,
20+
tq_limit_min = site.ssid_changer.tq_limit_min() or 35,
21+
})
22+
uci:save('ssid-changer')
23+
end

0 commit comments

Comments
 (0)