Developing lightweight computation at the DSG edge

node.lua 6.27 KB
Newer Older
1
--[[
2
3
  qMp - Quick Mesh Project - https://www.qmp.cat
  Copyright © 2011-2017 Fundació Privada per a la Xarxa Oberta, Lliure i Neutral, guifi.net
4

5
6
7
8
  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.
9

10
11
12
13
  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.
14

15
16
  You should have received a copy of the GNU General Public License
  along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18
--]]

19
20
package.path = package.path .. ";/etc/qmp/?.lua"

21
local sys = require "luci.sys"
22
local http = require "luci.http"
23
local uci = luci.model.uci.cursor()
24
local qmpinfo = require "qmpinfo"
25
local util = require "luci.util"
26

27
28
29
30
31
32
33
34
35
36
37
38
devices = qmpinfo.get_devices()

devname = uci:get("qmp","node","device_name")
devid = uci:get("qmp","node","device_id")

if (devname == nil or devname == '') then
  devname = "qMp"
end

if (devid == nil or devid == '') then
  devid = "0000"
end
39

40
m = Map("qmp", "qMp node settings", translate("This page allows to configure the basic node settings, like the device identification, location and contact details.") .. "<br/> <br/>" .. translate("You can check the on-line documentation at <a href=\"https://www.qmp.cat/Web_interface\">https://www.qmp.cat/Web_interface</a> for more information about the different options."))
41

42
device_section = m:section(NamedSection, "node", "qmp", translate("Device identification"), translate("The following settings are used to identify the device all over the mesh network."))
43
44
device_section.addremove = False

45
device_name = device_section:option(Value,"device_name", translate("Device name"), translate("Use only alphanumeric characters, dots, dashes and underscores."))
46
47
device_name.datatype = "hostname"
device_name.optional = false
48
49
50
device_name.rmempty = false
device_name.default = "qMp"

51
52
53
54
55
56
57
58
59
60
61
62
device_id = device_section:option(Value,"device_id", translate("Device ID"), translate("The ID of this device in the mesh network (optional). Use hexadecimal characters only."))
device_id:depends("community_name","Guifi.net")
device_id.datatype = "string"
device_id.optional = false
device_id.rmempty = false

append_id = device_section:option(ListValue, "append_id", translate("Append ID"),translatef("Append the device ID to the device name (e.g., %s-%s)", devname, devid))
append_id:value("0", translate ("No"))
append_id:value("1", translate("Yes"))
append_id.default = "1"
append_id.optional = false
append_id.rmempty = false
63

64
community_name = device_section:option(Value, "community_name", translate ("Community Network name"), translate("Select a predefined community network from the list, type your own name or leave it blank."))
65
66
67
68
69
70
community_name.datatype="string"
community_name:value("Bogotá Mesh","Bogotá Mesh")
community_name:value("DigitalMerthyr","Digital Merthyr")
community_name:value("Guifi.net","Guifi.net")
community_name:value("NYCMesh","NYC Mesh")

71
guifimesh_name = device_section:option(Value, "mesh_name", translate ("Mesh Network name"), translate("Select a predefined community subnetwork or type your own name (optional)."))
72
73
74
75
76
77
78
79
80
81
82
guifimesh_name:depends("community_name","Guifi.net")
guifimesh_name.datatype="string"
guifimesh_name:value("GuifiBaix", "Baix Llobregat (GuifiBaix)")
guifimesh_name:value("Bellvitge", "Bellvitge (HW)")
guifimesh_name:value("GraciaSenseFils", "Gràcia Sense Fils (GSF)")
guifimesh_name:value("PoblenouSenseFils", "Poblenou Sense Fils (P9SF)")
guifimesh_name:value("Quesa", "Quesa (QUESA)")
guifimesh_name:value("Raval", "Raval (RAV)")
guifimesh_name:value("GuifiSants", "Sants-Les Corts-UPC (GS)")
guifimesh_name:value("SantAndreu", "Sant Andreu (SAND)")
guifimesh_name:value("Vallcarca", "Vallcarca (VKK)")
83
84
guifimesh_name:value("Herguijuela", "La Herguijuela (LHer)")
guifimesh_name:value("CepedaLaMora", "Cepeda la Mora (CPD)")
85

86
primary_device = device_section:option(Value,"primary_device", translate("Primary network interface"), translate("The name of the node's primary network interface. The last four digits of this device's MAC address will be appended to the node name."))
87
primary_device.datatype = "network"
88
89
90
91
92
93
94
95
primary_device.optional = false
primary_device.rmempty = false
primary_device.default = "eth0"
for k,v in pairs (devices) do
  for l,w in pairs(v) do
    primary_device:value(w, w)
  end
end
96
97


98
99
location_section = m:section(NamedSection, "node", "qmp", translate("Device location"), translate("The following settings are used to geolocate the device on tools like <a href=\"http://libremap.guifi.net\">LibreMap</a>."))
location_section.addremove = False
100

101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
geopos_lat = location_section:option(Value,"latitude", translate("Latitude"), translate("Use a dot as the decimal separator (ex.: 7.51)"))
geopos_lat.datatype = "range(-90, 90)"
geopos_lat.optional = true
geopos_lat.rmempty = false
geopos_lat.default = "0"

geopos_lon = location_section:option(Value,"longitude", translate("Longitude"), translate("Use a dot as the decimal separator (ex.: 76.83)"))
geopos_lon.datatype = "range(-180, 180)"
geopos_lon.optional = true
geopos_lon.rmempty = false
geopos_lon.default = "0"

geopos_elv = location_section:option(Value,"elevation", translate("Elevation"), translate("Node elevation, relative to the ground level, in meters (optional). Use a dot as the decimal separator (ex.: 20.5)"))
geopos_elv.datatype = "range(-11034, 300000)"
geopos_elv.optional = true
geopos_elv.rmempty = false
geopos_elv.default = "0"

contact_section = m:section(NamedSection, "node", "qmp", translate("Contact information"), translate("The contact information can be used to reach the owner of a node."))
120
121
122
contact_section.addremove = False

contact = contact_section:option(Value,"contact", translate("Contact e-mail"), translate("An e-mail to contact you if needed (optional)."))
123
124
125
126
127
contact.datatype = string
contact.optional = true
contact.rmempty = false
contact.default = "admin@qmp.cat"

128
129
130
------------
-- Commit --
------------
131
132
function m.on_commit(self,map)
	http.redirect("/luci-static/resources/qmp/wait_short.html")
133
134
	uci:commit("qmp")
	luci.sys.call('/etc/qmp/qmp_control.sh configure_system > /tmp/qmp_control_system.log &')
135
136
137
end

return m