Developing lightweight computation at the DSG edge

Commit 91f5392a authored by p4u's avatar p4u
Browse files

Introduces a new way to enable/disable the existing services managed by qMp.

The VPN, Captive Portal, Maps, etc. Can be controled from the web interface (configuration/services).
Adds a new section in the qMp config file to specify which services should run and which ones not.
parent 36acf3f1
......@@ -124,15 +124,13 @@ configure() {
# This function is executed in each boot
startup() {
# Set HostName
. $QMP_DIR/qmp_functions.sh
. $QMP_DIR/qmp_system.sh
qmp_set_hosts
[ $(qmp_uci_get services.bwtest) -eq 1 ] && qmp_enable_netserver
# Run hooks
exechooks anyboot
# Start/Stop netserver
$QMP_DIR/qmp_control.sh apply_netserver
# Generate current qmp key
logread | md5sum | awk '{print $1}' > $QMP_KEY
}
......
......@@ -36,6 +36,19 @@ config 'qmp' 'node'
# Temporay key file for session (autogenerated in each boot).
option key '/tmp/qmp_key'
# -----------------------------
# Node services to be started
# -----------------------------
config 'qmp' 'services'
option vpn 0
option captive_portal 0
option b6m 1
option altermap 1
option gwck 1
option auto_upgrade 0
option mesh_dns 0
option bwtest 1
# -----------------------------
# Firmware upgrade system
......@@ -107,9 +120,6 @@ config 'qmp' 'networks'
# Metric for WAN interfaces (dhcp client).
option wan_metric '2048'
# Enable bandwidth tests.
option netserver '1'
# -----------------------------
# Wireless general configuration
......
......@@ -30,6 +30,7 @@ QMP_PATH="/etc/qmp"
. $QMP_PATH/qmp_wireless.sh
. $QMP_PATH/qmp_network.sh
. $QMP_PATH/qmp_update.sh
. $QMP_PATH/qmp_system.sh
offer_default_gw() {
qmp_gw_default offer $1
......@@ -65,13 +66,12 @@ configure_gw() {
qmp_gw_apply
}
apply_netserver() {
[ "$(qmp_uci_get networks.netserver)" == "1" ] && qmp_enable_netserver || qmp_disable_netserver
apply_services() {
qmp_set_services
}
configure_network() {
qmp_configure
[ -f "/etc/init.d/olsrd" ] && /etc/init.d/olsrd restart
bmx6 -c --configReload || /etc/init.d/bmx6 restart
/etc/init.d/network reload
if /etc/init.d/gwck enabled
......@@ -79,12 +79,12 @@ configure_network() {
/etc/init.d/gwck restart
fi
/etc/init.d/dnsmasq restart
apply_netserver
qmp_restart_firewall
}
configure_system() {
qmp_configure_system
apply_services
/etc/init.d/uhttpd restart
}
......@@ -118,7 +118,6 @@ configure_all() {
configure_system
configure_wifi
configure_network
apply_netserver
}
safe_apply() {
......@@ -190,7 +189,7 @@ help() {
echo ""
echo "Other:"
echo " apply_netserver : Start/stop nerserver depending on qmp configuration"
echo " apply_services : Start/stop services depending on qmp configuration"
echo " enable_ns_ppt : Enable POE passtrought from NanoStation M2/5 devices. Be careful with this option!"
echo " upgrade [URL] : Upgrade system. By default to the last version, but image url can be provided to force"
echo " hard_reboot : Performs a hard reboot (using kernel sysrq)"
......
......@@ -39,6 +39,7 @@ fi
. $QMP_PATH/qmp_common.sh
[ -z "$SOURCE_GW" ] && . $QMP_PATH/qmp_gw.sh
[ -z "$SOURCE_NET" ] && . $QMP_PATH/qmp_network.sh
[ -z "$SOURCE_SYS" ] && . $QMP_PATH/qmp_system.sh
# requires ip ipv6calc awk sed grep
......@@ -818,53 +819,6 @@ qmp_configure_bmx6() {
# /etc/init.d/$conf restart
}
qmp_set_hosts() {
echo "Configuring /etc/hosts file with qmpadmin entry"
local ip=$(uci get bmx6.general.tun4Address | cut -d'/' -f1)
local hn=$(uci get system.@system[0].hostname)
if [ -z "$ip" -o -z "$hn" ]; then
echo "Cannot get IP or HostName"
return
fi
if [ $(cat /etc/hosts | grep -c "^$ip.*qmpadmin") -eq 0 ]; then
cat /etc/hosts | grep -v qmpadmin > /tmp/hosts.tmp
echo "$ip $hn admin.qmp qmpadmin" >> /tmp/hosts.tmp
cp /tmp/hosts.tmp /etc/hosts
fi
echo "done"
}
qmp_configure_system() {
if qmp_uci_test qmp.node.community_node_id; then
local community_node_id=$(qmp_get_id)
else
local community_node_id=$(qmp_get_id)
qmp_uci_set node.community_node_id $community_node_id
fi
local community_id="$(qmp_uci_get node.community_id)"
[ -z "$community_id" ] && community_id="qmp" && qmp_uci_set node.community_id $community_id
# set hostname
uci set system.@system[0].hostname=${community_id}${community_node_id}
uci commit system
echo "${community_id}${community_node_id}" > /proc/sys/kernel/hostname
# enable IPv6 in httpd:
uci set uhttpd.main.listen_http="80"
uci set uhttpd.main.listen_https="443"
uci commit uhttpd
/etc/init.d/uhttpd restart
# configuring hosts
qmp_set_hosts
}
qmp_restart_firewall() {
/etc/init.d/firewall restart
}
......@@ -881,6 +835,7 @@ qmp_configure_initial() {
qmp_configure() {
qmp_configure_system
qmp_set_services
qmp_hooks_exec preconf
qmp_check_force_internet
qmp_configure_network
......
......@@ -30,6 +30,7 @@ QMPINFO="/etc/qmp/qmpinfo"
SOURCE_NET=1
[ -z "$SOURCE_COMMON" ] && . $QMP_PATH/qmp_common.sh
[ -z "$SOURCE_FUNCTIONS" ] && . $QMP_PATH/qmp_functions.sh
[ -z "$SOURCE_SYS" ] && . $QMP_PATH/qmp_system.sh
# Adds the iptables mss clamping rule for descovering maximum MSS
# <device> [remove]
......@@ -60,17 +61,6 @@ qmp_configure_prepare_network() {
uci commit network
}
qmp_enable_netserver() {
qmp_uci_set networks.netserver 1
killall -9 netserver
netserver -6 -p 12865
}
qmp_disable_netserver() {
qmp_uci_set networks.netserver 0
killall -9 netserver || true
}
## DISABLED
# Publish or unpublish lan HNA depending on qmp configuration
qmp_publish_lan() {
......
#!/bin/sh
#/etc/rc.common
# Copyright (C) 2011 Fundacio Privada per a la Xarxa Oberta, Lliure i Neutral guifi.net
#
# 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 2 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, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# The full GNU General Public License is included in this distribution in
# the file called "COPYING".
#
# Contributors:
# Axel Neumann
# Pau Escrich <p4u@dabax.net>
# Simó Albert i Beltran
#
QMP_PATH="/etc/qmp"
SOURCE_SYS=1
. $QMP_PATH/qmp_common.sh
[ -z "$SOURCE_GW" ] && . $QMP_PATH/qmp_gw.sh
[ -z "$SOURCE_NET" ] && . $QMP_PATH/qmp_network.sh
qmp_configure_system() {
if qmp_uci_test qmp.node.community_node_id; then
local community_node_id=$(qmp_get_id)
else
local community_node_id=$(qmp_get_id)
qmp_uci_set node.community_node_id $community_node_id
fi
local community_id="$(qmp_uci_get node.community_id)"
[ -z "$community_id" ] && community_id="qmp" && qmp_uci_set node.community_id $community_id
# set hostname
uci set system.@system[0].hostname=${community_id}${community_node_id}
uci commit system
echo "${community_id}${community_node_id}" > /proc/sys/kernel/hostname
uci set uhttpd.main.listen_http="80"
uci set uhttpd.main.listen_https="443"
uci commit uhttpd
/etc/init.d/uhttpd restart
# configuring hosts
qmp_set_hosts
}
qmp_set_hosts() {
qmp_log "Configuring /etc/hosts file with qmpadmin entry"
local ip=$(uci get bmx6.general.tun4Address | cut -d'/' -f1)
local hn=$(uci get system.@system[0].hostname)
if [ -z "$ip" -o -z "$hn" ]; then
echo "Cannot get IP or HostName"
return
fi
if [ $(cat /etc/hosts | grep -c "^$ip.*qmpadmin") -eq 0 ]; then
cat /etc/hosts | grep -v qmpadmin > /tmp/hosts.tmp
echo "$ip $hn admin.qmp qmpadmin" >> /tmp/hosts.tmp
cp /tmp/hosts.tmp /etc/hosts
fi
}
# -----------------------------------
# Services section
# -----------------------------------
qmp_enable_netserver() {
qmp_log Enabling service netserver
qmp_disable_service netserver
killall -9 netserver 2>/dev/null
netserver -6 -p 12865
return 0
}
qmp_disable_netserver() {
qmp_log Disabling service netserver
qmp_disable_service netserver
killall -9 netserver 2>/dev/null
return 0
}
qmp_enable_service() {
qmp_log Enabling service $1
/etc/init.d/$1 start
/etc/init.d/$1 enable
return 0
}
qmp_disable_service() {
qmp_log Disabling service $1
/etc/init.d/$1 stop 2>/dev/null
/etc/init.d/$1 disable
return 0
}
qmp_list_services() {
echo "$(uci show qmp.services | cut -d. -f3 | cut -d= -f1 | grep .)"
}
qmp_set_services() {
local s
for s in $(qmp_list_services); do
[ "$s" == "vpn" ] && [ -e /etc/init.d/synctincvpn ] && {
[ $(qmp_uci_get services.$s) -eq 1 ] && \
qmp_enable_service synctincvpn || qmp_disable_service synctincvpn
}
[ "$s" == "captive_portal" ] && [ -e /etc/init.d/tinyproxy ] && {
[ $(qmp_uci_get services.$s) -eq 1 ] && \
qmp_enable_service tinyproxy || qmp_disable_service tinyproxy
}
[ "$s" == "altermap" ] && [ -e /etc/init.d/altermap-agent ] && {
[ $(qmp_uci_get services.$s) -eq 1 ] && \
qmp_enable_service altermap-agent || qmp_disable_service altermap-agent
}
[ "$s" == "b6m" ] && [ -e /etc/init.d/b6m-spread ] && {
[ $(qmp_uci_get services.$s) -eq 1 ] && \
qmp_enable_service b6m-spread || qmp_disable_service b6m-spread
}
[ "$s" == "gwck" ] && [ -e /etc/init.d/gwck ] && {
[ $(qmp_uci_get services.$s) -eq 1 ] && \
qmp_enable_service gwck || qmp_disable_service gwck
}
[ "$s" == "auto_upgrade" ] && {
true
}
[ "$s" == "mesh_dns" ] && {
true
}
[ "$s" == "bwtest" ] && [ -n "$(which netserver)" ] && {
[ $(qmp_uci_get services.$s) -eq 1 ] && \
qmp_enable_netserver || qmp_disable_netserver
}
done
uci commit qmp
}
......@@ -43,6 +43,7 @@ function index()
entry({"qmp","configuration","network","advanced"}, cbi("qmp/network_adv"), "Advanced networking", 1).dependent=false
entry({"qmp","configuration","wifi"}, cbi("qmp/wireless"), "WiFi", 3).dependent=false
entry({"qmp","configuration","node"}, cbi("qmp/node"), "Node", 4).dependent=false
entry({"qmp","configuration","services"}, cbi("qmp/services"), "Services", 5).dependent=false
entry({"qmp","tools"}, call("action_tools"), "Tools", 5).dependent=false
entry({"qmp","tools","tools"}, call("action_tools"), "Tools", 1).dependent=false
......
--[[
Copyright (C) 2011 Fundacio Privada per a la Xarxa Oberta, Lliure i Neutral guifi.net
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 2 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, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
The full GNU General Public License is included in this distribution in
the file called "COPYING".
--]]
require("luci.sys")
local http = require "luci.http"
local m = Map("qmp", "Quick Mesh Project")
local section = m:section(NamedSection, "services", "qmp", translate("Services"), translate("System services control"))
section.addremove = False
-- Option: VPN
local vpn = section:option(Flag, "vpn", translate("Management VPN"),
translate("The Management VPN is used to control the nodes in remote from a central point"))
vpn.default=0
-- Option: Captive Portal
local cp = section:option(Flag, "captive_portal", translate("Captive Portal"),
translate("The captive portal is a small http proxy used to show a HTML page the first time someone connects to the node's Access Point"))
cp.default=0
-- Option: b6m
local b6m = section:option(Flag, "b6m", translate("BMX6 map"),
translate("The b6m is a real time descentralized geopositioning map based on OpenStreetMaps (Internet access only required for the OSM but not for the status/topology)"))
b6m.default=0
-- Option: altermap
local alt = section:option(Flag, "altermap", translate("Altermap"),
translate("AlterMap is a centralized geopositioning map. Internet and the previous creation of the node in the map page are required (http://map.qmp.cat)"))
alt.default=0
-- Option: gwck
local gwck = section:option(Flag, "gwck", translate("Gateway Checker"),
translate("GWCK is a tool automatic discover and publish Internet access among the Mesh network"))
gwck.default=0
-- Option: bwtest
local bwt = section:option(Flag, "bwtest", translate("Bandwidth test"),
translate("If enabled, the node will be available to perform bandwidth test from other locations"))
bwt.default=0
function m.on_commit(self,map)
luci.sys.call('/etc/qmp/qmp_control.sh apply_services > /tmp/qmp_apply_services.log &')
http.redirect("/luci-static/resources/qmp/wait_short.html")
end
return m
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment