├── .gitignore
├── luci-app-dynapoint
├── luasrc
│ ├── view
│ │ └── dynapoint
│ │ │ ├── cbi_checkbox.htm
│ │ │ └── cbi_color.htm
│ ├── controller
│ │ └── dynapoint.lua
│ └── model
│ │ └── cbi
│ │ └── dynapoint.lua
├── root
│ └── etc
│ │ └── uci-defaults
│ │ └── 40_luci-dynapoint
├── Makefile
├── po
│ ├── templates
│ │ └── dynapoint.pot
│ └── de
│ │ └── dynapoint.po
└── LICENSE
├── dynapoint
├── src
│ ├── dynapoint.config
│ ├── dynapoint.init
│ └── dynapoint.lua
├── Makefile
└── LICENSE
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | .settings/
2 | .buildpath
3 | .project
4 |
--------------------------------------------------------------------------------
/luci-app-dynapoint/luasrc/view/dynapoint/cbi_checkbox.htm:
--------------------------------------------------------------------------------
1 | <%+cbi/valueheader%>
2 |
3 |
4 |
5 |
6 | <%+cbi/valuefooter%>
7 |
--------------------------------------------------------------------------------
/luci-app-dynapoint/luasrc/controller/dynapoint.lua:
--------------------------------------------------------------------------------
1 | module("luci.controller.dynapoint", package.seeall)
2 |
3 | function index()
4 | if not nixio.fs.access("/etc/config/dynapoint") then
5 | return
6 | end
7 | entry({"admin", "services", "dynapoint"}, cbi("dynapoint/dynapoint"), _("DynaPoint"))
8 | end
9 |
--------------------------------------------------------------------------------
/dynapoint/src/dynapoint.config:
--------------------------------------------------------------------------------
1 | config rule 'internet'
2 | list hosts 'http://www.example.com'
3 | list hosts 'http://www.google.com'
4 | option interval '60'
5 | option timeout '5'
6 | option offline_threshold '3'
7 | option add_hostname_to_ssid '0'
8 | option use_curl '0'
9 | option curl_interface 'eth0'
10 |
11 |
--------------------------------------------------------------------------------
/dynapoint/src/dynapoint.init:
--------------------------------------------------------------------------------
1 | #!/bin/sh /etc/rc.common
2 |
3 | START=99
4 |
5 | USE_PROCD=1
6 | PROG=/usr/sbin/dynapoint.lua
7 | CONFFILE=/etc/config/dynapoint
8 |
9 | start_service() {
10 | procd_open_instance
11 | procd_set_param command $PROG
12 | procd_set_param file $CONFFILE
13 | procd_set_param respawn
14 | procd_close_instance
15 | }
16 |
17 |
--------------------------------------------------------------------------------
/luci-app-dynapoint/root/etc/uci-defaults/40_luci-dynapoint:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | # needed for "Save and Apply" to restart dynapoint
4 | uci -q batch <<-EOF >/dev/null
5 | delete ucitrack.@dynapoint[-1]
6 | add ucitrack dynapoint
7 | set ucitrack.@dynapoint[-1].init="dynapoint"
8 | commit dynapoint
9 | EOF
10 |
11 | rm -f /tmp/luci-indexcache
12 | exit 0
13 |
--------------------------------------------------------------------------------
/luci-app-dynapoint/luasrc/view/dynapoint/cbi_color.htm:
--------------------------------------------------------------------------------
1 | <%+cbi/valueheader%>
2 |
3 |
4 | <%
5 | if (self:cfgvalue(section) == translate("Disabled")) then
6 | %>
7 |
8 | <%=self:cfgvalue(section)%>
9 |
10 | <%
11 | else
12 | %>
13 | <%=self:cfgvalue(section)%>
14 | <%
15 | end
16 | %>
17 |
18 | <%+cbi/valuefooter%>
19 |
--------------------------------------------------------------------------------
/dynapoint/Makefile:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (C) 2016 LEDE project (Tobias Ilte)
3 | #
4 | # This is free software, licensed under the GNU General Public License v3.
5 |
6 | include $(TOPDIR)/rules.mk
7 |
8 | PKG_NAME:=dynapoint
9 | PKG_VERSION:=1.0
10 | PKG_RELEASE:=2
11 | PKG_MAINTAINER:=Tobias Ilte
12 | PKG_LICENSE:=GPL-3.0+
13 | PKG_LICENSE_FILES:=LICENSE
14 |
15 | include $(INCLUDE_DIR)/package.mk
16 |
17 | define Package/$(PKG_NAME)
18 | SECTION:=net
19 | CATEGORY:=Network
20 | SUBMENU:=wireless
21 | DEPENDS:=+lua +libubus-lua +libuci-lua +libubox-lua +luci-lib-nixio
22 | MAINTAINER:=Tobias Ilte
23 | TITLE:=Dynamic access point manager
24 | endef
25 |
26 | define Package/$(PKG_NAME)/description
27 | Dynapoint uses LUA scripts to allow dynamic access point creation
28 | and deletion depending on changes of certain network conditions.
29 | endef
30 |
31 | define Package/$(PKG_NAME)/conffiles
32 | /etc/config/dynapoint
33 | endef
34 |
35 | define Build/Compile
36 | true
37 | endef
38 |
39 | define Package/$(PKG_NAME)/install
40 | $(INSTALL_DIR) $(1)/usr/sbin
41 | $(INSTALL_BIN) ./src/dynapoint.lua $(1)/usr/sbin/
42 | $(INSTALL_DIR) $(1)/etc/init.d
43 | $(INSTALL_BIN) ./src/dynapoint.init $(1)/etc/init.d/dynapoint
44 | $(INSTALL_DIR) $(1)/etc/config
45 | $(INSTALL_DATA) ./src/dynapoint.config $(1)/etc/config/dynapoint
46 | endef
47 |
48 | $(eval $(call BuildPackage,$(PKG_NAME)))
49 |
50 |
--------------------------------------------------------------------------------
/luci-app-dynapoint/Makefile:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (C) 2016 LEDE project (Tobias Ilte)
3 | #
4 | # This is free software, licensed under the GNU General Public License v3.
5 |
6 | include $(TOPDIR)/rules.mk
7 |
8 | PKG_NAME:=luci-app-dynapoint
9 | PKG_VERSION:=1.0
10 | PKG_RELEASE:=1
11 | PKG_MAINTAINER:=Tobias Ilte
12 | PKG_LICENSE:=GPL-3.0+
13 | PKG_LICENSE_FILES:=LICENSE
14 |
15 | include $(INCLUDE_DIR)/package.mk
16 |
17 | define Package/$(PKG_NAME)
18 | SECTION:=LuCI
19 | CATEGORY:=LuCI
20 | SUBMENU:=3. Applications
21 | TITLE:=LuCI Support for DynaPoint
22 | DEPENDS:=+lua +luci-base +dynapoint
23 | MAINTAINER:=Tobias Ilte
24 | PKGARCH:=all
25 | endef
26 |
27 | define Package/$(PKG_NAME)/description
28 | Makes access point ssids dependable on certain network conditions.
29 | endef
30 |
31 | define Build/Compile
32 | endef
33 |
34 | define Package/$(PKG_NAME)/install
35 | $(INSTALL_DIR) $(1)/etc/uci-defaults
36 | $(INSTALL_BIN) ./root/etc/uci-defaults/40_luci-dynapoint $(1)/etc/uci-defaults/40_luci-dynapoint
37 | $(INSTALL_DIR) $(1)/usr/lib/lua/luci/model/cbi/dynapoint
38 | $(INSTALL_DATA) ./luasrc/model/cbi/dynapoint.lua $(1)/usr/lib/lua/luci/model/cbi/dynapoint/dynapoint.lua
39 | $(INSTALL_DIR) $(1)/usr/lib/lua/luci/controller
40 | $(INSTALL_DATA) ./luasrc/controller/dynapoint.lua $(1)/usr/lib/lua/luci/controller/dynapoint.lua
41 | $(INSTALL_DIR) $(1)/usr/lib/lua/luci/view/dynapoint
42 | $(INSTALL_DATA) ./luasrc/view/dynapoint/cbi_checkbox.htm $(1)/usr/lib/lua/luci/view/dynapoint/cbi_checkbox.htm
43 | $(INSTALL_DATA) ./luasrc/view/dynapoint/cbi_color.htm $(1)/usr/lib/lua/luci/view/dynapoint/cbi_color.htm
44 | endef
45 |
46 | $(eval $(call BuildPackage,$(PKG_NAME)))
47 |
--------------------------------------------------------------------------------
/luci-app-dynapoint/po/templates/dynapoint.pot:
--------------------------------------------------------------------------------
1 | msgid ""
2 | msgstr "Content-Type: text/plain; charset=UTF-8"
3 |
4 | msgid "Activate this wVIF if status is:"
5 | msgstr ""
6 |
7 | msgid "Append hostname to ssid"
8 | msgstr ""
9 |
10 | msgid "Append the router's hostname to the SSID when connectivity check fails"
11 | msgstr ""
12 |
13 | msgid "Check Internet connectivity via HTTP header download"
14 | msgstr ""
15 |
16 | msgid "Configuration"
17 | msgstr ""
18 |
19 | msgid "Curl is currently not installed."
20 | msgstr ""
21 |
22 | msgid "Device"
23 | msgstr ""
24 |
25 | msgid "Disabled"
26 | msgstr ""
27 |
28 | msgid "DynaPoint"
29 | msgstr ""
30 |
31 | msgid "Dynamic Access Point Manager"
32 | msgstr ""
33 |
34 | msgid "Enabled"
35 | msgstr ""
36 |
37 | msgid ""
38 | "Failure counter after how many failed download attempts, the state is "
39 | "considered as offline"
40 | msgstr ""
41 |
42 | msgid "List of Wireless Virtual Interfaces (wVIF)"
43 | msgstr ""
44 |
45 | msgid "List of host addresses"
46 | msgstr ""
47 |
48 | msgid ""
49 | "List of host addresses (url or IP) to track and request http headers from"
50 | msgstr ""
51 |
52 | msgid "Mode"
53 | msgstr ""
54 |
55 | msgid "Not used by DynaPoint"
56 | msgstr ""
57 |
58 | msgid "Offline"
59 | msgstr ""
60 |
61 | msgid "Online"
62 | msgstr ""
63 |
64 | msgid "SSID"
65 | msgstr ""
66 |
67 | msgid "Switch_to_offline threshold"
68 | msgstr ""
69 |
70 | msgid "Test-run interval"
71 | msgstr ""
72 |
73 | msgid "Time interval in seconds to re-start a new test run"
74 | msgstr ""
75 |
76 | msgid "Use curl"
77 | msgstr ""
78 |
79 | msgid "Use curl instead of wget"
80 | msgstr ""
81 |
82 | msgid "Use curl instead of wget for testing the connectivity."
83 | msgstr ""
84 |
85 | msgid "Used interface"
86 | msgstr ""
87 |
88 | msgid "Which interface should curl use. (Use ifconfig to find out)"
89 | msgstr ""
90 |
91 | msgid "WiFi Status"
92 | msgstr ""
93 |
--------------------------------------------------------------------------------
/luci-app-dynapoint/po/de/dynapoint.po:
--------------------------------------------------------------------------------
1 | msgid ""
2 | msgstr ""
3 | "Project-Id-Version: PACKAGE VERSION\n"
4 | "PO-Revision-Date: 2016-08-31 15:51+0200\n"
5 | "Language-Team: German\n"
6 | "Language: de\n"
7 | "MIME-Version: 1.0\n"
8 | "Content-Type: text/plain; charset=UTF-8\n"
9 | "Content-Transfer-Encoding: 8bit\n"
10 | "Plural-Forms: nplurals=2; plural=(n != 1);\n"
11 |
12 | msgid "Activate this wVIF if status is:"
13 | msgstr "Aktiviere diese drahtlose Schnittstelle wenn:"
14 |
15 | msgid "Append hostname to ssid"
16 | msgstr "Anfügen des hostname zur SSID"
17 |
18 | msgid "Append the router's hostname to the SSID when connectivity check fails"
19 | msgstr ""
20 | "Fügt den hostname des routers zur SSID an, wenn die Verbindungsüberprüfung "
21 | "fehl schlägt"
22 |
23 | msgid "Check Internet connectivity via HTTP header download"
24 | msgstr "Testen der Internetverfügbarkeit via HTTP header download"
25 |
26 | msgid "Configuration"
27 | msgstr "Konfiguration"
28 |
29 | msgid "Curl is currently not installed."
30 | msgstr "Curl ist momentan nicht installiert."
31 |
32 | msgid "Device"
33 | msgstr "Gerät"
34 |
35 | msgid "Disabled"
36 | msgstr "Deaktiviert"
37 |
38 | msgid "DynaPoint"
39 | msgstr ""
40 |
41 | msgid "Dynamic Access Point Manager"
42 | msgstr ""
43 |
44 | msgid "Enabled"
45 | msgstr "Aktiviert"
46 |
47 | msgid ""
48 | "Failure counter after how many failed download attempts, the state is "
49 | "considered as offline"
50 | msgstr ""
51 | "Anzahl der fehlgeschlagenen Downloadversuche, nach denen die Verbindung als offline angesehen wird"
52 |
53 | msgid "List of Wireless Virtual Interfaces (wVIF)"
54 | msgstr "Liste der Drahtlosen virtuellen Schnittstellen"
55 |
56 | msgid "List of host addresses"
57 | msgstr "Liste der Zieladressen"
58 |
59 | msgid ""
60 | "List of host addresses (url or IP) to track and request http headers from"
61 | msgstr "Liste der Zieladressen (URL oder IP) für den HTTP header download"
62 |
63 | msgid "Mode"
64 | msgstr "Modus"
65 |
66 | msgid "Not used by DynaPoint"
67 | msgstr "Nicht von DynaPoint benutzt"
68 |
69 | msgid "Offline"
70 | msgstr "Offline"
71 |
72 | msgid "Online"
73 | msgstr "Online"
74 |
75 | msgid "SSID"
76 | msgstr ""
77 |
78 | msgid "Switch_to_offline threshold"
79 | msgstr "Offline-Schwelle"
80 |
81 | msgid "Test-run interval"
82 | msgstr "Testlaufintervall"
83 |
84 | msgid "Time interval in seconds to re-start a new test run"
85 | msgstr "Zeitintervall in Sekunden für einen Testlauf"
86 |
87 | msgid "Use curl"
88 | msgstr "Curl benutzen"
89 |
90 | msgid "Use curl instead of wget"
91 | msgstr "Curl anstatt wget benutzen"
92 |
93 | msgid "Use curl instead of wget for testing the connectivity."
94 | msgstr "Curl anstatt wget benutzen, um die Internetverbindung zu überprüfen."
95 |
96 | msgid "Used interface"
97 | msgstr "Benutztes interface"
98 |
99 | msgid "Which interface should curl use. (Use ifconfig to find out)"
100 | msgstr ""
101 | "Welches Interface von curl benutzt werden soll. (ifconfig benutzen, um das "
102 | "herauszufinden"
103 |
104 | msgid "WiFi Status"
105 | msgstr ""
106 |
--------------------------------------------------------------------------------
/luci-app-dynapoint/luasrc/model/cbi/dynapoint.lua:
--------------------------------------------------------------------------------
1 | local uci = require "luci.model.uci".cursor()
2 | local a = require "luci.model.ipkg"
3 | local DISP = require "luci.dispatcher"
4 |
5 | local wlcursor = luci.model.uci.cursor_state()
6 | local wireless = wlcursor:get_all("wireless")
7 | local ifaces = {}
8 |
9 | for k, v in pairs(wireless) do
10 | if v[".type"] == "wifi-iface" then
11 | table.insert(ifaces, v)
12 | end
13 | end
14 |
15 | m = Map("dynapoint")
16 | m:chain("wireless")
17 |
18 | s = m:section(NamedSection, "internet", "rule", translate("Configuration"), translate("Check Internet connectivity via HTTP header download"))
19 |
20 | hosts = s:option(DynamicList, "hosts", translate("List of host addresses"), translate("List of host addresses (url or IP) to track and request http headers from"))
21 | hosts.datatype = "string"
22 |
23 | interval = s:option(Value, "interval", translate("Test-run interval"), translate("Time interval in seconds to re-start a new test run"))
24 | interval.datatype = "uinteger"
25 | interval.default = "30"
26 |
27 | offline_treshold = s:option(Value, "offline_threshold", translate("Switch_to_offline threshold"), translate("Failure counter after how many failed download attempts, the state is considered as offline"))
28 | offline_treshold.datatype = "uinteger"
29 | offline_treshold.default = "1"
30 |
31 | add_hostname_to_ssid = s:option(Flag, "add_hostname_to_ssid", translate("Append hostname to ssid"), translate("Append the router's hostname to the SSID when connectivity check fails"))
32 | add_hostname_to_ssid.rmempty = false
33 |
34 |
35 | if (a.installed("curl") == true) then
36 | use_curl = s:option(Flag, "use_curl", translate("Use curl"), translate("Use curl instead of wget for testing the connectivity."))
37 | use_curl.rmempty = false
38 |
39 | curl_interface = s:option(Value, "curl_interface", translate("Used interface"), translate("Which interface should curl use. (Use ifconfig to find out)"))
40 | curl_interface.datatype = "string"
41 | curl_interface:depends("use_curl","1")
42 | curl_interface.placeholder = "eth0"
43 | else
44 | use_curl = s:option(Flag, "use_curl", translate("Use curl instead of wget"), translate("Curl is currently not installed.")
45 | .." Please install the package in the "
46 | ..[[]]
48 | .. "Software Section" .. [[]]
49 | .. "."
50 | )
51 | use_curl.rmempty = false
52 | use_curl.template = "dynapoint/cbi_checkbox"
53 | end
54 |
55 | m1 = Map("wireless", "DynaPoint", translate("Dynamic Access Point Manager"))
56 |
57 | aps = m1:section(TypedSection, "wifi-iface", translate("List of Wireless Virtual Interfaces (wVIF)"))
58 | aps.addremove = false
59 | aps.anonymous = true
60 | aps.template = "cbi/tblsection"
61 |
62 | status = aps:option(DummyValue, "disabled", translate("WiFi Status"))
63 | status.template = "dynapoint/cbi_color"
64 |
65 | function status.cfgvalue(self,section)
66 | local val = m1:get(section, "disabled")
67 | if val == "1" then return translate("Disabled") end
68 | if (val == nil or val == "0") then return translate("Enabled") end
69 | return val
70 | end
71 |
72 | device = aps:option(DummyValue, "device", translate("Device"))
73 | function device.cfgvalue(self,section)
74 | local dev = m1:get(section, "device")
75 | local val = m1:get(dev, "hwmode")
76 | if val == "11a" then return dev .. " (5 GHz)" else
77 | return dev .. " (2,4 GHz)"
78 | end
79 | return val
80 | end
81 |
82 |
83 |
84 |
85 |
86 | mode = aps:option(DummyValue, "mode", translate("Mode"))
87 |
88 | ssid = aps:option(DummyValue, "ssid", translate("SSID"))
89 |
90 |
91 | action = aps:option(ListValue, "dynapoint_rule", translate("Activate this wVIF if status is:"))
92 | action.widget="select"
93 | action:value("internet",translate("Online"))
94 | action:value("!internet",translate("Offline"))
95 | action:value("",translate("Not used by DynaPoint"))
96 | action.default = ""
97 |
98 | return m1,m
99 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ```
2 | ( (
3 | )\ ) )\ ) )
4 | (()/( ( ) (()/( ( ( /(
5 | /(_)) )\ ) ( ( /( /(_)) ( )\ ( )\())
6 | (_))_ (()/( )\ ) )(_))(_)) )\((_) )\ ) (_))/
7 | | \ )(_)) _(_/( ((_)_ | _ \ ((_)(_) _(_/( | |_
8 | | |) || || || ' \))/ _` || _// _ \| || ' \))| _|
9 | |___/ \_, ||_||_| \__,_||_| \___/|_||_||_| \__|
10 | |__/
11 | ```
12 |
13 | Dynamic Access Point creation with LEDE Linux [www.lede-project.org]
14 |
15 | ### What is DynaPoint about?
16 |
17 | In today's Freifunk networks it is quite common to have multiple access points connected to the actual Freifunk router (by Ethernet) in order to provide a dedicated wireless access network for all kinds of clients in addition to the Freifunk mesh network. Such access point setups are quite static once configured in LEDE and are prone to the following challenges in practice: The wireless access network is announced as soon as the ap interface is up and running, regardless of e.g. its state of internet connectivity. To inform a non-technical user of the circumstance that the router is up & running but no internet connectivity is available yet, different browser/dns based redirect approaches to inform about the non-internet-connectivity by a web site have been tested over time with little success in terms of robustness and usability.
18 | The goal of DynaPoint is that the configuration of an LEDE access interface via UCI/Luci is extended in such a way, that the wireless interface bring up via UBUS depends on a set of network conditions - so does the ability for the user to connect to it with its client device and his expectations.
19 |
20 | An example scenario would look like this:
21 |
22 | 1. as soon as the Freifunk ap is up and running bring up the access ssid: "maintainance-mode"
23 | 2. using wget (or optional curl), we try to reach a reasonable set of hosts on the internet via http
24 | (2a. optional testing other condidtions)
25 | 3. in case of all checks been working we create the access point network with ssid "freifunk.net" and stop announcing the ssid: "freifunk-maintainance-mode"
26 | 4. cyclic test the conditions of internet accessibility in a regular manner and in case the reachability changes, switch off the access point network with ssid "freifunk.net" and switch on the ssid: "freifunk-maintenance-mode"
27 |
28 | With this kind of dynamic access ssid creation, the expectations about the connectivity to a certain ssid are glued to the actual ssid itself, rather than todays approach to create a single accesspoint ssid where current network connectivity can only be tested in the second step after having connected to it.
29 |
30 | ### How to install DynaPoint ?
31 |
32 | 1. Add `src-git dynapoint https://github.com/thuehn/dynapoint.git` to your feeds.conf
33 | 2. Run `./scripts/feeds update dynapoint`
34 | 3. Run `./scripts/feeds install dynapoint`
35 | 4. Run `make menuconfig` and select dynapoint under network / wireless
36 | 5. in case you use Luci as web interface, you can add dynapoint integration by adding luci-app-dynapoint in Luci apps section
37 | 6. Run `make package/feeds/dynapoint/dynapoint/install`
38 |
39 | ### How to use Dynapoint?
40 | Example of how to use it in /etc/config/wireless:
41 |
42 | ```
43 | config wifi-iface
44 | option device 'radio0'
45 | option network 'lan2'
46 | option mode 'ap'
47 | option encryption 'none'
48 | option ssid 'access.freifunk.net'
49 | option dynapoint_rule 'internet'
50 |
51 | config wifi-iface
52 | option device 'radio0'
53 | option network 'lan2'
54 | option mode 'ap'
55 | option encryption 'none'
56 | option ssid 'freifunk_maintenance-mode'
57 | option dynapoint_rule '!internet'
58 | ```
59 |
60 | Example configuration in /etc/config/dynapoint:
61 |
62 | ```
63 | config rule 'internet'
64 | list hosts 'http://www.example.com'
65 | list hosts 'http://www.google.com'
66 | option interval '60'
67 | option timeout '5'
68 | option offline_threshold '3'
69 | option add_hostname_to_ssid '0'
70 | option use_curl '0'
71 | option curl_interface 'eth0'
72 | ```
73 | Configuration options explained:
74 |
75 | * hosts: Addresses for checking the availability
76 | * interval: How often to check Internet connection in seconds
77 | * timeout: Timeout in seconds when trying to check availability of host
78 | * offline_trheshold: After how many times of checking, the connection is considered offline
79 | * add_hostname_to_ssid: Append the router's hostname to the SSID when connectivity check fails
80 | * use_curl: Use curl instead of wget for testing the connectivity
81 |
82 |
--------------------------------------------------------------------------------
/dynapoint/src/dynapoint.lua:
--------------------------------------------------------------------------------
1 | #!/usr/bin/lua
2 |
3 | --[[
4 |
5 | Copyright (C) 2016 Tobias Ilte
6 |
7 | This program is free software: you can redistribute it and/or modify
8 | it under the terms of the GNU General Public License as published by
9 | the Free Software Foundation, either version 3 of the License, or
10 | (at your option) any later version.
11 |
12 | This program is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | GNU General Public License for more details.
16 |
17 | You should have received a copy of the GNU General Public License
18 | along with this program. If not, see .
19 |
20 | --]]
21 |
22 |
23 | require "uci"
24 | require "ubus"
25 | require "uloop"
26 | log = require "nixio"
27 |
28 | --open sys-logging
29 | log.openlog("DynaPoint", "ndelay", "cons", "nowait");
30 |
31 | local uci_cursor = uci.cursor()
32 |
33 | -- get all config sections with the given type
34 | function getConfType(conf_file,type)
35 | local ifce={}
36 | uci_cursor:foreach(conf_file,type,function(s) ifce[s[".index"]]=s end)
37 | return ifce
38 | end
39 |
40 | ubus = ubus.connect()
41 | if not ubus then
42 | error("Failed to connect to ubusd")
43 | end
44 | ubus:call("network", "reload", {})
45 |
46 | local interval = uci_cursor:get("dynapoint", "internet", "interval")
47 | local timeout = uci_cursor:get("dynapoint", "internet", "timeout")
48 | local offline_threshold = tonumber(uci_cursor:get("dynapoint", "internet", "offline_threshold"))
49 | local hosts = uci_cursor:get("dynapoint", "internet", "hosts")
50 | local numhosts = #hosts
51 | local curl = tonumber(uci_cursor:get("dynapoint", "internet", "use_curl"))
52 | if (curl == 1) then
53 | curl_interface = uci_cursor:get("dynapoint", "internet", "curl_interface")
54 | end
55 | function get_system_sections(t)
56 | for pos,val in pairs(t) do
57 | if (type(val)=="table") then
58 | get_system_sections(val);
59 | elseif (type(val)=="string") then
60 | if (pos == "hostname") then
61 | localhostname = val
62 | end
63 | end
64 | end
65 | end
66 | if (tonumber(uci_cursor:get("dynapoint", "internet", "add_hostname_to_ssid")) == 1 ) then
67 | get_system_sections(getConfType("system","system"))
68 | if (not localhostname) then
69 | error("Failed to obtain system hostname")
70 | end
71 | end
72 |
73 | local table_names_rule = {}
74 | local table_names_not_rule = {}
75 | local ssids_with_hostname = {}
76 | local ssids_not_rule = {}
77 |
78 | function get_dynapoint_sections(t)
79 | for pos,val in pairs(t) do
80 | if (type(val)=="table") then
81 | get_dynapoint_sections(val);
82 | elseif (type(val)=="string") then
83 | if (pos == "dynapoint_rule") then
84 | if (val == "internet") then
85 | table_names_rule[#table_names_rule+1] = t[".name"]
86 | elseif (val == "!internet") then
87 | table_names_not_rule[#table_names_not_rule+1] = t[".name"]
88 | if (localhostname) then
89 | ssids_not_rule[#ssids_not_rule+1] = uci_cursor:get("wireless", t[".name"], "ssid")
90 | ssids_with_hostname[#ssids_with_hostname+1] = uci_cursor:get("wireless", t[".name"], "ssid").."_"..localhostname
91 | end
92 | end
93 | end
94 | end
95 | end
96 | end
97 |
98 | --print(table.getn(hosts))
99 |
100 | get_dynapoint_sections(getConfType("wireless","wifi-iface"))
101 |
102 | -- revert all non-persistent ssid uci-changes regarding sections affecting dynapoint
103 | for i = 1, #table_names_not_rule do
104 | uci_cursor:revert("wireless", table_names_not_rule[i], "ssid")
105 | end
106 |
107 |
108 | local online = true
109 |
110 | if (#table_names_rule > 0) then
111 | if (tonumber(uci_cursor:get("wireless", table_names_rule[1], "disabled")) == 1) then
112 | online = false
113 | end
114 | else
115 | log.syslog("info","Not properly configured. Please add