Developing lightweight computation at the DSG edge

Commit aaa02770 authored by Pau Escrich's avatar Pau Escrich
Browse files

Create a standalone package for mesh-dns (renamed to bmx6-mdns)

Create a LUCI web interface to manage it
Some small improvements
parent d1422a7a
# 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:
# Pau Escrich <p4u@dabax.net>
#
include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/kernel.mk
PKG_NAME:=bmx6-mdns
PKG_RELEASE:=1
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
QMP_CODENAME:=Kalimotxo
QMP_RELEASE:=4.0
QMP_BUILDDATE:=$(shell date +%Y%m%d_%H%M)
include $(INCLUDE_DIR)/package.mk
define Package/bmx6-mdns
TITLE:=bmx6 distributed DNS
SECTION:=net
CATEGORY:=Network
URL:=http://qmp.cat
DEPENDS:=+bmx6-sms
endef
define Package/bmx6-mdns/description
Distributed DNS system using bmx6 sms plugin
endef
define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
endef
define Build/Configure
endef
define Build/Compile
endef
define Package/bmx6-mdns/install
$(INSTALL_DIR) $(1)/etc/mdns
$(INSTALL_DIR) $(1)/etc/init.d/
$(CP) ./files/etc/init.d/mdns $(1)/etc/init.d/
chmod 755 $(1)/etc/init.d/mdns
$(CP) ./files/etc/mdns/* $(1)/etc/mdns
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/model/cbi/qmp
$(CP) ./files/luci/bmx6-mdns.lua $(1)/usr/lib/lua/luci/model/cbi/qmp/mdns.lua
endef
$(eval $(call BuildPackage,bmx6-mdns))
......@@ -25,20 +25,32 @@ STOP=99
MDNS_DIR="/etc/mdns"
HOSTF="$MDNS_DIR/hosts"
MY_DOMAINS="$MDNS_DIR/public"
DOMAINS4="qmp"
DOMAINS6="qm6"
SMSF="/var/run/bmx6/sms/sendSms/mdns"
SMSTMP="/tmp/sms-mdns.tmp"
SMSR="/var/run/bmx6/sms/rcvdSms"
DNSMASQ="/etc/dnsmasq.conf"
DNSMASQ_PID="/var/run/dnsmasq.pid"
[ ! -d $MDNS_DIR ] && mkdir $MDNS_DIR
[ ! -f $HOSTF ] && touch $HOSTF
[ ! -f $MY_DOMAINS ] && touch $MY_DOMAINS
[ ! -f $MDNS_DIR/domain4 ] && touch $MDNS_DIR/domain4
[ ! -f $MDNS_DIR/domain6 ] && touch $MDNS_DIR/domain6
[ ! -f $SMSF ] && touch $SMSF
DOMAINS4="$(cat $MDNS_DIR/domain4)"
DOMAINS6="$(cat $MDNS_DIR/domain6)"
# Optional
IPV4=""
IPV6=""
start() {
if ! cat /etc/crontabs/root | grep mdns > /dev/null; then
echo "10 * * * * /etc/init.d/mdns reload > /tmp/log/mdns.log" >> /etc/crontabs/root
int=$(echo "0x$(dd if=/dev/urandom bs=1 count=1 2>&- | hexdump | \
if read line; then echo ${line#* }; fi)" | awk '{print ($1 % 60)}')
int=${int:-10}
echo "$int * * * * /etc/init.d/mdns reload > /tmp/log/mdns.log" >> /etc/crontabs/root
/etc/init.d/cron enable
/etc/init.d/cron start
fi
......@@ -200,9 +212,8 @@ publish_my_domains() {
echo -e "$ext_domains" >> $HOSTF
sed '/./!d' -i $SMSTMP $HOSTF
[ -f $SMSF ] && \
[ $(md5sum $SMSTMP $SMSF | awk '{print $1}' | uniq | wc -l) -eq 1 ] || \
cp -f $SMSTMP $SMSF
[ $(md5sum $SMSTMP $SMSF | awk '{print $1}' | uniq | wc -l) -gt 1 ] && cp -f $SMSTMP $SMSF
}
get_domains() {
......
--[[
LuCI - Lua Configuration Interface
Copyright 2008 Steven Barth <steven@midlink.org>
Copyright 2008-2013 Jo-Philipp Wich <xm@subsignal.org>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
$Id$
]]--
local fs = require "nixio.fs"
local globalfile = "/etc/mdns/public"
local dom4file = "/etc/mdns/domain4"
local dom6file = "/etc/mdns/domain6"
local hostfile = "/etc/mdns/hosts"
f = SimpleForm("mesh-dns", translate("Mesh DNS"), translate( "Distributed DNS system using the bmx6 packets to encode domains."))
d4 = f:field(Value, "dom4", translate("IPv4 domain extension"), translate("Only IPv4 domains with this extension will be considered valid"))
d4.rmempty = false
function d4.cfgvalue()
return fs.readfile(dom4file) or ""
end
d6 = f:field(Value, "dom6", translate("IPv6 domain extension"), translate("Only IPv6 domains with this extension will be considered valid"))
d6.rmempty = false
function d6.cfgvalue()
return fs.readfile(dom6file) or ""
end
t = f:field(TextValue, "mdns", translate("Domains to publish"), translate("Syntax: IP@domain<br/>Examples:\
<pre>proxy1.qmp@10.1.2.3<br/>proxy1.qm6@fd00:1714:1714:1677:120b::23c1</pre><br/>\
A line with a single domain name is published as own domain with the node's IP."))
t.rmempty = false
t.rows = 20
function t.cfgvalue()
return fs.readfile(globalfile) or ""
end
function f.handle(self, state, data)
if state == FORM_VALID then
if data.mdns then
fs.writefile(globalfile, data.mdns:gsub("\r\n", "\n"))
luci.sys.call("/etc/init.d/mdns reload >/dev/null")
end
if data.dom4 then
fs.writefile(dom4file, data.dom4:gsub("\r\n", "\n"))
end
if data.dom6 then
fs.writefile(dom6file, data.dom6:gsub("\r\n", "\n"))
end
end
return true
end
hosts = fs.readfile(hostfile) or ""
h = f:field(DummyValue, "hosts", translate("Current obtained domains"), "<pre>"..hosts.."</pre>")
h.rmempty = false
h.rows = 20
return f
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