-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gluon-ssid-changer: add this package to automatically change the SSID…
… when no Internet connection
- Loading branch information
Showing
12 changed files
with
403 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
gluon-ssid-changer | ||
================== | ||
|
||
This package adds a script to change the SSID to an Offline-SSID when there is | ||
no connection to any gateway. | ||
This SSID can be generated from the nodes hostname with the first | ||
and last part of the nodename or the mac address, to allow observers to | ||
recognise which node is down. The script is called once a minute by micron.d | ||
and it will change from online to offline-SSID maximum once every (definable) | ||
timeframe. | ||
|
||
You can enable/disable it in the config mode. | ||
|
||
Once every timeframe it checks if there's still a gateway reachable. There can be | ||
selected two algorithms to analyze if a gateway is reacheable: | ||
|
||
- `tq_limit` enabled: define an 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. | ||
- `tq_limit` disabled: there will be only checked, if the gateway is reachable | ||
with: | ||
|
||
batctl gwl -H | ||
|
||
Depending on the connectivity, it will be decided if a change of the SSID is | ||
necessary: There is a variable `switch_timeframe` (for ex. 1440 = 24h) that | ||
defines a time interval after which a successful check that detects an offline | ||
state will result in a single change of the SSID to "FF_Offline_$node_hostname". | ||
Only the first few minutes (also definable in a variable `first`) the | ||
OFFLINE_SSID may also be set. All other minutes a checks will just be counted | ||
and reported in the log and whenever an online state is detected the SSID will | ||
be set back immediately back to normal. when the timeframe is reached, there | ||
will be checked if the node was offline at least half the timeframe, only then | ||
the SSID will be changed. | ||
|
||
site.conf | ||
========= | ||
|
||
Adapt and add this block to your site.conf: | ||
|
||
``` | ||
ssid_changer = { | ||
enabled = true, | ||
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 always may be activated (must be <= switch_timeframe) | ||
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' | ||
tq_limit_enabled = false, -- if false, 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 prevent it from toggeling every minute. | ||
tq_limit_max = 45, -- upper limit, above that the online SSID will be used | ||
tq_limit_min = 35 -- lower limit, below that the offline SSID will be used | ||
}, | ||
``` | ||
|
||
Commandline options | ||
=================== | ||
|
||
You can configure the ssid-changer on the commandline with `uci`, for example | ||
disable it with: | ||
|
||
uci set ssid-changer.settings.enabled='0' | ||
|
||
Or set the timeframe to every three minutes with | ||
|
||
uci set ssid-changer.settings.switch_timeframe='3' | ||
uci set ssid-changer.settings.first='3' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
include $(TOPDIR)/rules.mk | ||
|
||
PKG_NAME:=gluon-ssid-changer | ||
PKG_VERSION:=5 | ||
|
||
include $(TOPDIR)/../package/gluon.mk | ||
|
||
define Package/$(PKG_NAME) | ||
TITLE:=changes the SSID to an Offline-SSID so clients don't connect to an offline WiFi | ||
DEPENDS:=+gluon-core +micrond | ||
endef | ||
|
||
define Package/$(PKG_NAME)/description | ||
Script to change the SSID to an Offline-SSID when there is no connection to | ||
any gateway. This SSID can be generated from the nodes hostname with the first | ||
and last part of the nodename or the mac address, to allow observers to | ||
recognise which node is down. The script is called once a minute by micron.d | ||
and it will change from online to offline-SSID maximum once every (definable) | ||
timeframe. | ||
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))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
config settings 'settings' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* * * * * /lib/gluon/ssid-changer/ssid-changer.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: PACKAGE VERSION\n" | ||
"PO-Revision-Date: 2018-07-29 15:26+0200\n" | ||
"Last-Translator: <[email protected]>\n" | ||
"Language-Team: German\n" | ||
"Language: de\n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: 8bit\n" | ||
"Plural-Forms: nplurals=2; plural=(n != 1);\n" | ||
|
||
msgid "Enabled" | ||
msgstr "Aktiviert" | ||
|
||
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 "" | ||
"Hier kannst du aktivieren, dass dein Knoten automatisch die SSID auf die " | ||
"Offline-SSID ändert, wenn keine Verbindung zu Freifunk Servern besteht.<br /><br />" | ||
"Das verhindert, dass Client-Geräte sich mit einem Knoten verbinden, an dem es " | ||
"derzeit keine nutzbare Interverbindung gibt.<br />" | ||
"Wenn in dieser Firmware der Suffix auf 'nodename' gestellt ist, dann kann man " | ||
"leichter anhand der dann gesendeten Offline-SSID nach einem fehlerhaften Gerät " | ||
"suchen." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
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 "" |
1 change: 1 addition & 0 deletions
1
package/gluon-ssid-changer/luasrc/lib/gluon/config-mode/controller/admin/ssid-changer.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
entry({"admin", "ssid-changer"}, model("admin/ssid-changer"), _("Offline-SSID"), 35) |
41 changes: 41 additions & 0 deletions
41
package/gluon-ssid-changer/luasrc/lib/gluon/config-mode/model/admin/ssid-changer.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
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') | ||
|
||
-- local prefix = s:option(Value, 'prefix', pkg_i18n.translate('First part of the Offline SSID')) | ||
-- prefix:depends(enabled, true) | ||
-- prefix.datatype = 'maxlength(32)' | ||
-- prefix.default = uci:get('ssid-changer', 'settings', 'prefix') | ||
|
||
function f:write() | ||
if enabled.data then | ||
uci:section('ssid-changer', 'settings', 'settings', { | ||
enabled = '1', | ||
-- prefix = prefix.data | ||
-- switch_timeframe = switch_timeframe.data or '1440' | ||
-- tq_limit_max = tq_limit_max.data or '55' | ||
-- first = first.data or '5' | ||
-- prefix = prefix.data or 'FF_Offline_' | ||
-- suffix = suffix.data or 'nodename' | ||
-- tq_limit_min = tq_limit_min.data or '45' | ||
-- tq_limit_enabled = tq_limit_enabled.data or '0' | ||
}) | ||
else | ||
uci:set('ssid-changer', 'settings', 'enabled', '0') | ||
end | ||
|
||
uci:commit('ssid-changer') | ||
end | ||
|
||
return f |
23 changes: 23 additions & 0 deletions
23
package/gluon-ssid-changer/luasrc/lib/gluon/upgrade/500-ssid-changer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/lua | ||
|
||
local site = require 'gluon.site' | ||
|
||
local uci = require('simple-uci').cursor() | ||
|
||
if site.ssid_changer == nil then | ||
-- print('ssid_changer not defined in site.conf') | ||
else | ||
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 |
Oops, something went wrong.