diff --git a/net/dynapoint/Makefile b/net/dynapoint/Makefile new file mode 100644 index 0000000000..ca32cd1dc1 --- /dev/null +++ b/net/dynapoint/Makefile @@ -0,0 +1,47 @@ +# +# Copyright (C) 2016 Tobias Ilte +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# + +include $(TOPDIR)/rules.mk + +PKG_NAME:=dynapoint +PKG_RELEASE:=1 + +PKG_MAINTAINER:=Tobias Ilte +PKG_LICENSE:=GPL-3.0+ + +include $(INCLUDE_DIR)/package.mk + +define Package/$(PKG_NAME) + SECTION:=net + CATEGORY:=Network + SUBMENU:=wireless + DEPENDS:=+lua +libubus-lua +libuci-lua +libubox-lua +luci-lib-nixio + TITLE:=Dynamic access point manager +endef + +define Package/$(PKG_NAME)/description + Dynapoint uses LUA scripts to allow dynamic access point creation + and deletion depending on changes of certain network conditions. +endef + +define Package/$(PKG_NAME)/conffiles +/etc/config/dynapoint +endef + +define Build/Compile +endef + +define Package/$(PKG_NAME)/install + $(INSTALL_DIR) $(1)/usr/sbin + $(INSTALL_BIN) ./src/dynapoint.lua $(1)/usr/sbin/ + $(INSTALL_DIR) $(1)/etc/init.d + $(INSTALL_BIN) ./src/dynapoint.init $(1)/etc/init.d/dynapoint + $(INSTALL_DIR) $(1)/etc/config + $(INSTALL_DATA) ./src/dynapoint.config $(1)/etc/config/dynapoint +endef + +$(eval $(call BuildPackage,$(PKG_NAME))) diff --git a/net/dynapoint/src/dynapoint.config b/net/dynapoint/src/dynapoint.config new file mode 100644 index 0000000000..0578cf0b89 --- /dev/null +++ b/net/dynapoint/src/dynapoint.config @@ -0,0 +1,9 @@ +config rule 'internet' + list hosts 'http://www.example.com' + list hosts 'http://www.google.com' + option interval '60' + option timeout '5' + option offline_threshold '3' + option add_hostname_to_ssid '0' + option use_curl '0' + option curl_interface 'eth0' diff --git a/net/dynapoint/src/dynapoint.init b/net/dynapoint/src/dynapoint.init new file mode 100644 index 0000000000..ff105d325e --- /dev/null +++ b/net/dynapoint/src/dynapoint.init @@ -0,0 +1,15 @@ +#!/bin/sh /etc/rc.common + +START=99 + +USE_PROCD=1 +PROG=/usr/sbin/dynapoint.lua +CONFFILE=/etc/config/dynapoint + +start_service() { + procd_open_instance + procd_set_param command $PROG + procd_set_param file $CONFFILE + procd_set_param respawn + procd_close_instance +} diff --git a/net/dynapoint/src/dynapoint.lua b/net/dynapoint/src/dynapoint.lua new file mode 100644 index 0000000000..4d2e456a8a --- /dev/null +++ b/net/dynapoint/src/dynapoint.lua @@ -0,0 +1,203 @@ +#!/usr/bin/lua + +--[[ + +Copyright (C) 2016 Tobias Ilte + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +--]] + + +require "uci" +require "ubus" +require "uloop" +log = require "nixio" + +--open sys-logging +log.openlog("DynaPoint", "ndelay", "cons", "nowait"); + +local uci_cursor = uci.cursor() + +-- get all config sections with the given type +function getConfType(conf_file,type) + local ifce={} + uci_cursor:foreach(conf_file,type,function(s) ifce[s[".index"]]=s end) + return ifce +end + +ubus = ubus.connect() +if not ubus then + error("Failed to connect to ubusd") +end +ubus:call("network", "reload", {}) + +local interval = uci_cursor:get("dynapoint", "internet", "interval") +local timeout = uci_cursor:get("dynapoint", "internet", "timeout") +local offline_threshold = tonumber(uci_cursor:get("dynapoint", "internet", "offline_threshold")) +local hosts = uci_cursor:get("dynapoint", "internet", "hosts") +local numhosts = #hosts +local curl = tonumber(uci_cursor:get("dynapoint", "internet", "use_curl")) +if (curl == 1) then + curl_interface = uci_cursor:get("dynapoint", "internet", "curl_interface") +end +if (tonumber(uci_cursor:get("dynapoint", "internet", "add_hostname_to_ssid")) == 1 ) then + localhostname = uci_cursor:get("system", "system", "hostname") +end + +local table_names_rule = {} +local table_names_not_rule = {} +local ssids_with_hostname = {} +local ssids_not_rule = {} + +function get_dynapoint_sections(t) + for pos,val in pairs(t) do + if (type(val)=="table") then + get_dynapoint_sections(val); + elseif (type(val)=="string") then + if (pos == "dynapoint_rule") then + if (val == "internet") then + table_names_rule[#table_names_rule+1] = t[".name"] + elseif (val == "!internet") then + table_names_not_rule[#table_names_not_rule+1] = t[".name"] + if (localhostname) then + ssids_not_rule[#ssids_not_rule+1] = t[".ssid"] + ssids_with_hostname[#ssids_with_hostname+1] = t[".ssid"].."_"..localhostname + end + end + end + end + end +end + + +--print(table.getn(hosts)) + +get_dynapoint_sections(getConfType("wireless","wifi-iface")) + +-- revert all non-persistent ssid uci-changes regarding sections affecting dynapoint +for i = 1, #table_names_not_rule do + uci_cursor:revert("wireless", table_names_not_rule[i], "ssid") +end + + +local online = true + +if (#table_names_rule > 0) then + if (tonumber(uci_cursor:get("wireless", table_names_rule[1], "disabled")) == 1) then + online = false + end +else + log.syslog("info","Not properly configured. Please add