Skip to content
Snippets Groups Projects
Unverified Commit 31d3f08f authored by Matthias Schiffer's avatar Matthias Schiffer
Browse files

treewide: convert all LuCI-based packages to gluon-web

parent e4b74be5
No related branches found
No related tags found
No related merge requests found
Showing
with 126 additions and 1022 deletions
--[[
Copyright 2013 Nils Schneider <nils@nilsschneider.net>
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$
]]--
module("luci.controller.gluon-config-mode.index", package.seeall)
function index()
local uci_state = luci.model.uci.cursor_state()
if uci_state:get_first("gluon-setup-mode", "setup_mode", "running", "0") == "1" then
local root = node()
if not root.target then
root.target = alias("gluon-config-mode")
root.index = true
end
page = node()
page.lock = true
page.target = alias("gluon-config-mode")
page.subindex = true
page.index = false
page = node("gluon-config-mode")
page.title = _("Wizard")
page.target = alias("gluon-config-mode", "wizard")
page.order = 5
page.sysauth = "root"
page.sysauth_authenticator = function() return "root" end
page.index = true
entry({"gluon-config-mode", "wizard"}, cbi("gluon-config-mode/wizard")).index = true
entry({"gluon-config-mode", "reboot"}, call("action_reboot"))
end
end
function action_reboot()
local uci = luci.model.uci.cursor()
uci:set("gluon-setup-mode", uci:get_first("gluon-setup-mode", "setup_mode"), "configured", "1")
uci:save("gluon-setup-mode")
uci:commit("gluon-setup-mode")
local gluon_luci = require "gluon.luci"
local fs = require "nixio.fs"
local util = require "nixio.util"
local pretty_hostname = require "pretty_hostname"
local parts_dir = "/lib/gluon/config-mode/reboot/"
local files = util.consume(fs.dir(parts_dir))
table.sort(files)
local parts = {}
for _, entry in ipairs(files) do
if entry:sub(1, 1) ~= '.' then
local f = dofile(parts_dir .. '/' .. entry)
if f ~= nil then
table.insert(parts, f)
end
end
end
local hostname = pretty_hostname.get(uci)
luci.template.render("gluon/config-mode/reboot",
{
parts = parts,
hostname = hostname,
escape = gluon_luci.escape,
urlescape = gluon_luci.urlescape,
}
)
if nixio.fork() == 0 then
-- Replace stdout with /dev/null
nixio.dup(nixio.open('/dev/null', 'w'), nixio.stdout)
-- Sleep a little so the browser can fetch everything required to
-- display the reboot page, then reboot the device.
nixio.nanosleep(1)
nixio.execp("reboot")
end
end
local wizard_dir = "/lib/gluon/config-mode/wizard/"
local i18n = luci.i18n
local uci = require("simple-uci").cursor()
local fs = require "nixio.fs"
local util = require "nixio.util"
local f, s
local wizard = {}
local files = {}
if fs.access(wizard_dir) then
files = util.consume(fs.dir(wizard_dir))
table.sort(files)
end
for _, entry in ipairs(files) do
if entry:sub(1, 1) ~= '.' then
table.insert(wizard, dofile(wizard_dir .. '/' .. entry))
end
end
f = SimpleForm("wizard")
f.reset = false
f.template = "gluon/cbi/config-mode"
for _, s in ipairs(wizard) do
s.section(f)
end
function f.handle(self, state, data)
if state == FORM_VALID then
for _, s in ipairs(wizard) do
s.handle(data)
end
luci.http.redirect(luci.dispatcher.build_url("gluon-config-mode", "reboot"))
end
return true
end
return f
local cbi = require "luci.cbi" return function(form, uci)
local i18n = require "luci.i18n"
local uci = require("simple-uci").cursor()
local site = require 'gluon.site_config' local site = require 'gluon.site_config'
local M = {} local location = uci:get_first("gluon-node-info", "location")
local function show_altitude() local function show_altitude()
if ((site.config_mode or {}).geo_location or {}).show_altitude ~= false then if ((site.config_mode or {}).geo_location or {}).show_altitude ~= false then
return true return true
end end
if uci:get_first("gluon-node-info", "location", "altitude") then
return true return uci:get_bool("gluon-node-info", location, "altitude")
end
return false
end end
function M.section(form) local text = translate(
local text = i18n.translate('If you want the location of your node to ' 'If you want the location of your node to ' ..
.. 'be displayed on the map, you can enter its coordinates here.') 'be displayed on the map, you can enter its coordinates here.'
)
if show_altitude() then if show_altitude() then
text = text .. ' ' .. i18n.translate("gluon-config-mode:altitude-help") text = text .. ' ' .. translate("gluon-config-mode:altitude-help")
end end
local s = form:section(cbi.SimpleSection, nil, text)
local s = form:section(Section, nil, text)
local o local o
o = s:option(cbi.Flag, "_location", i18n.translate("Show node on the map")) local share_location = s:option(Flag, "location", translate("Show node on the map"))
o.default = uci:get_first("gluon-node-info", "location", "share_location", o.disabled) share_location.default = uci:get_bool("gluon-node-info", location, "share_location")
o.rmempty = false function share_location:write(data)
uci:set("gluon-node-info", location, "share_location", data)
end
o = s:option(cbi.Value, "_latitude", i18n.translate("Latitude")) o = s:option(Value, "latitude", translate("Latitude"), translatef("e.g. %s", "53.873621"))
o.default = uci:get_first("gluon-node-info", "location", "latitude") o.default = uci:get("gluon-node-info", location, "latitude")
o:depends("_location", "1") o:depends(share_location, true)
o.rmempty = false
o.datatype = "float" o.datatype = "float"
o.description = i18n.translatef("e.g. %s", "53.873621") function o:write(data)
uci:set("gluon-node-info", location, "latitude", data)
end
o = s:option(cbi.Value, "_longitude", i18n.translate("Longitude")) o = s:option(Value, "longitude", translate("Longitude"), translatef("e.g. %s", "10.689901"))
o.default = uci:get_first("gluon-node-info", "location", "longitude") o.default = uci:get("gluon-node-info", location, "longitude")
o:depends("_location", "1") o:depends(share_location, true)
o.rmempty = false
o.datatype = "float" o.datatype = "float"
o.description = i18n.translatef("e.g. %s", "10.689901") function o:write(data)
uci:set("gluon-node-info", location, "longitude", data)
end
if show_altitude() then if show_altitude() then
o = s:option(cbi.Value, "_altitude", i18n.translate("gluon-config-mode:altitude-label")) o = s:option(Value, "altitude", translate("gluon-config-mode:altitude-label"), translatef("e.g. %s", "11.51"))
o.default = uci:get_first("gluon-node-info", "location", "altitude") o.default = uci:get("gluon-node-info", location, "altitude")
o:depends("_location", "1") o:depends(share_location, true)
o.rmempty = true
o.datatype = "float" o.datatype = "float"
o.description = i18n.translatef("e.g. %s", "11.51") o.optional = true
end function o:write(data)
if data then
end uci:set("gluon-node-info", location, "altitude", data)
function M.handle(data)
local sname = uci:get_first("gluon-node-info", "location")
uci:set("gluon-node-info", sname, "share_location", data._location)
if data._location and data._latitude ~= nil and data._longitude ~= nil then
uci:set("gluon-node-info", sname, "latitude", data._latitude:trim())
uci:set("gluon-node-info", sname, "longitude", data._longitude:trim())
if data._altitude ~= nil then
uci:set("gluon-node-info", sname, "altitude", data._altitude:trim())
else else
uci:delete("gluon-node-info", sname, "altitude") uci:delete("gluon-node-info", location, "altitude")
end end
end end
uci:save("gluon-node-info")
uci:commit("gluon-node-info")
end end
return M return {'gluon-node-info'}
end
local cbi = require "luci.cbi" return function(form, uci)
local i18n = require "luci.i18n"
local pretty_hostname = require "pretty_hostname" local pretty_hostname = require "pretty_hostname"
local uci = require("simple-uci").cursor()
local M = {} local s = form:section(Section)
local o = s:option(Value, "hostname", translate("Node name"))
o.default = pretty_hostname.get(uci)
function M.section(form) function o:write(data)
local s = form:section(cbi.SimpleSection, nil, nil) pretty_hostname.set(uci, data)
local o = s:option(cbi.Value, "_hostname", i18n.translate("Node name"))
o.value = pretty_hostname.get(uci)
o.rmempty = false
end end
function M.handle(data) return {'system'}
pretty_hostname.set(uci, data._hostname)
uci:commit("system")
end end
return M
...@@ -2,32 +2,27 @@ local uci = require("simple-uci").cursor() ...@@ -2,32 +2,27 @@ local uci = require("simple-uci").cursor()
local meshvpn_enabled = uci:get_bool("fastd", "mesh_vpn", "enabled") local meshvpn_enabled = uci:get_bool("fastd", "mesh_vpn", "enabled")
if not meshvpn_enabled then if not meshvpn_enabled then
return nil return
else end
local i18n = require "luci.i18n"
local util = require "luci.util" local lutil = require "gluon.web.util"
local gluon_luci = require 'gluon.luci'
local site = require 'gluon.site_config' local site = require 'gluon.site_config'
local sysconfig = require 'gluon.sysconfig' local sysconfig = require 'gluon.sysconfig'
local util = require "gluon.util"
local pretty_hostname = require 'pretty_hostname' local pretty_hostname = require 'pretty_hostname'
local pubkey = util.trim(util.exec("/etc/init.d/fastd show_key " .. "mesh_vpn")) local pubkey = util.trim(lutil.exec("/etc/init.d/fastd show_key mesh_vpn"))
local hostname = pretty_hostname.get(uci) local hostname = pretty_hostname.get(uci)
local contact = uci:get_first("gluon-node-info", "owner", "contact") local contact = uci:get_first("gluon-node-info", "owner", "contact")
local msg = i18n.translate('gluon-config-mode:pubkey') local msg = translate('gluon-config-mode:pubkey')
return function () renderer.render_string(msg, {
luci.template.render_string(msg, {
pubkey = pubkey, pubkey = pubkey,
hostname = hostname, hostname = hostname,
site = site, site = site,
sysconfig = sysconfig, sysconfig = sysconfig,
contact = contact, contact = contact,
escape = gluon_luci.escape,
urlescape = gluon_luci.urlescape,
}) })
end
end
local cbi = require "luci.cbi" return function(form, uci)
local i18n = require "luci.i18n" local msg = translate(
local uci = require("simple-uci").cursor() 'Your internet connection can be used to establish an ' ..
local M = {}
function M.section(form)
local msg = i18n.translate('Your internet connection can be used to establish an ' ..
'encrypted connection with other nodes. ' .. 'encrypted connection with other nodes. ' ..
'Enable this option if there are no other nodes reachable ' .. 'Enable this option if there are no other nodes reachable ' ..
'over WLAN in your vicinity or you want to make a part of ' .. 'over WLAN in your vicinity or you want to make a part of ' ..
'your connection\'s bandwidth available for the network. You can limit how ' .. 'your connection\'s bandwidth available for the network. You can limit how ' ..
'much bandwidth the node will use at most.') 'much bandwidth the node will use at most.'
local s = form:section(cbi.SimpleSection, nil, msg) )
local o
o = s:option(cbi.Flag, "_meshvpn", i18n.translate("Use internet connection (mesh VPN)")) local s = form:section(Section, nil, msg)
o.default = uci:get_bool("fastd", "mesh_vpn", "enabled") and o.enabled or o.disabled
o.rmempty = false
o = s:option(cbi.Flag, "_limit_enabled", i18n.translate("Limit bandwidth")) local o
o:depends("_meshvpn", "1")
o.default = uci:get_bool("simple-tc", "mesh_vpn", "enabled") and o.enabled or o.disabled
o.rmempty = false
o = s:option(cbi.Value, "_limit_ingress", i18n.translate("Downstream (kbit/s)"))
o:depends("_limit_enabled", "1")
o.value = uci:get("simple-tc", "mesh_vpn", "limit_ingress")
o.rmempty = false
o.datatype = "uinteger"
o = s:option(cbi.Value, "_limit_egress", i18n.translate("Upstream (kbit/s)")) local meshvpn = s:option(Flag, "meshvpn", translate("Use internet connection (mesh VPN)"))
o:depends("_limit_enabled", "1") meshvpn.default = uci:get_bool("fastd", "mesh_vpn", "enabled")
o.value = uci:get("simple-tc", "mesh_vpn", "limit_egress") function meshvpn:write(data)
o.rmempty = false uci:set("fastd", "mesh_vpn", "enabled", data)
o.datatype = "uinteger"
end end
function M.handle(data) local limit = s:option(Flag, "limit_enabled", translate("Limit bandwidth"))
uci:set("fastd", "mesh_vpn", "enabled", data._meshvpn) limit:depends(meshvpn, true)
uci:save("fastd") limit.default = uci:get_bool("simple-tc", "mesh_vpn", "enabled")
uci:commit("fastd") function limit:write(data)
-- checks for nil needed due to o:depends(...)
if data._limit_enabled ~= nil then
uci:set("simple-tc", "mesh_vpn", "interface") uci:set("simple-tc", "mesh_vpn", "interface")
uci:set("simple-tc", "mesh_vpn", "enabled", data._limit_enabled) uci:set("simple-tc", "mesh_vpn", "enabled", data)
uci:set("simple-tc", "mesh_vpn", "ifname", "mesh-vpn") uci:set("simple-tc", "mesh_vpn", "ifname", "mesh-vpn")
if data._limit_ingress ~= nil then
uci:set("simple-tc", "mesh_vpn", "limit_ingress", data._limit_ingress:trim())
end end
if data._limit_egress ~= nil then o = s:option(Value, "limit_ingress", translate("Downstream (kbit/s)"))
uci:set("simple-tc", "mesh_vpn", "limit_egress", data._limit_egress:trim()) o:depends(limit, true)
o.default = uci:get("simple-tc", "mesh_vpn", "limit_ingress")
o.datatype = "uinteger"
function o:write(data)
uci:set("simple-tc", "mesh_vpn", "limit_ingress", data)
end end
uci:save("simple-tc") o = s:option(Value, "limit_egress", translate("Upstream (kbit/s)"))
uci:commit("simple-tc") o:depends(limit, true)
end o.default = uci:get("simple-tc", "mesh_vpn", "limit_egress")
o.datatype = "uinteger"
function o:write(data)
uci:set("simple-tc", "mesh_vpn", "limit_egress", data)
end end
return M return {'fastd', 'simple-tc'}
end
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<%=luci.i18n.context.lang%>" lang="<%=luci.i18n.context.lang%>">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><%:Upgrading firmware%></title>
<link rel="stylesheet" type="text/css" media="screen" href="<%=media%>/cascade.css" />
</head>
<body>
<div id="maincontainer">
<div id="maincontent">
<p>
<%:The firmware is currently being upgraded.%>
<strong><%:Don't switch off the device in any circumstance!%></strong>
<%:The upgrade will take a few minutes. When it is finished, your node will reboot automatically.%>
</p>
</div>
</div>
</body>
</html>
--[[
LuCI - Lua Configuration Interface
Copyright 2008 Steven Barth <steven@midlink.org>
Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
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$
]]--
module("luci.controller.admin.index", package.seeall)
function index()
local uci_state = luci.model.uci.cursor_state()
-- Disable gluon-luci-admin when setup mode is not enabled
if uci_state:get_first('gluon-setup-mode', 'setup_mode', 'running', '0') ~= '1' then
return
end
local root = node()
if not root.lock then
root.target = alias("admin")
root.index = true
end
local page = entry({"admin"}, alias("admin", "index"), _("Advanced settings"), 10)
page.sysauth = "root"
page.sysauth_authenticator = function() return "root" end
page.index = true
entry({"admin", "index"}, template("admin/info"), _("Information"), 1)
entry({"admin", "remote"}, cbi("admin/remote"), _("Remote access"), 10)
end
--[[
LuCI - Lua Configuration Interface
Copyright 2008 Steven Barth <steven@midlink.org>
Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
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$
]]--
module("luci.controller.admin.upgrade", package.seeall)
function index()
local has_platform = nixio.fs.access("/lib/upgrade/platform.sh")
if has_platform then
entry({"admin", "upgrade"}, call("action_upgrade"), _("Upgrade firmware"), 90)
entry({"admin", "upgrade", "reboot"}, template("admin/upgrade_reboot"), nil, nil)
end
end
function action_upgrade()
local tmpfile = "/tmp/firmware.img"
-- Install upload handler
local file
luci.http.setfilehandler(
function(meta, chunk, eof)
if not nixio.fs.access(tmpfile) and not file and chunk and #chunk > 0 then
file = io.open(tmpfile, "w")
end
if file and chunk then
file:write(chunk)
end
if file and eof then
file:close()
end
end
)
-- Determine state
local step = tonumber(luci.http.formvalue("step") or 1)
if step ~= 1 and not luci.dispatcher.test_post_security() then
nixio.fs.unlink(tmpfile)
return
end
local has_image = nixio.fs.access(tmpfile)
local has_support = image_supported(tmpfile)
-- Step 1: file upload, error on unsupported image format
if not has_image or not has_support or step == 1 then
-- If there is an image but user has requested step 1
-- or type is not supported, then remove it.
if has_image then
nixio.fs.unlink(tmpfile)
end
luci.template.render("admin/upgrade", {
bad_image=(has_image and not has_support or false)
} )
-- Step 2: present uploaded file, show checksum, confirmation
elseif step == 2 then
luci.template.render("admin/upgrade_confirm", {
checksum=image_checksum(tmpfile),
filesize=nixio.fs.stat(tmpfile).size,
flashsize=storage_size(),
keepconfig=luci.http.formvalue("keepcfg") == "1"
} )
elseif step == 3 then
local keepcfg = luci.http.formvalue("keepcfg") == "1"
fork_exec("/sbin/sysupgrade %s %q" % { keepcfg and "" or "-n", tmpfile })
luci.http.redirect(luci.dispatcher.build_url("admin", "upgrade", "reboot"))
end
end
function fork_exec(command)
local pid = nixio.fork()
if pid > 0 then
return
elseif pid == 0 then
-- change to root dir
nixio.chdir("/")
-- patch stdin, out, err to /dev/null
local null = nixio.open("/dev/null", "w+")
if null then
nixio.dup(null, nixio.stderr)
nixio.dup(null, nixio.stdout)
nixio.dup(null, nixio.stdin)
if null:fileno() > 2 then
null:close()
end
end
-- replace with target command
nixio.exec("/bin/sh", "-c", command)
end
end
function image_supported(tmpfile)
-- XXX: yay...
return ( 0 == os.execute(
"/sbin/sysupgrade -T %q >/dev/null"
% tmpfile
) )
end
function storage_size()
local size = 0
if nixio.fs.access("/proc/mtd") then
for l in io.lines("/proc/mtd") do
local d, s, e, n = l:match('^([^%s]+)%s+([^%s]+)%s+([^%s]+)%s+"([^%s]+)"')
if n == "linux" then
size = tonumber(s, 16)
break
end
end
elseif nixio.fs.access("/proc/partitions") then
for l in io.lines("/proc/partitions") do
local x, y, b, n = l:match('^%s*(%d+)%s+(%d+)%s+([^%s]+)%s+([^%s]+)')
if b and n and not n:match('[0-9]') then
size = tonumber(b) * 1024
break
end
end
end
return size
end
function image_checksum(tmpfile)
return (luci.sys.exec("md5sum %q" % tmpfile):match("^([^%s]+)"))
end
--[[
LuCI - Lua Configuration Interface
Copyright 2013 Nils Schneider <nils@nilsschneider.net>
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$
]]--
module("luci.controller.admin.autoupdater", package.seeall)
function index()
entry({"admin", "autoupdater"}, cbi("admin/autoupdater"), _("Automatic updates"), 80)
end
module("luci.controller.admin.mesh_vpn_fastd", package.seeall)
function index()
entry({"admin", "mesh_vpn_fastd"}, cbi("admin/mesh_vpn_fastd"), _("Mesh VPN"), 20)
end
local uci = require("simple-uci").cursor()
local util = luci.util
local f = SimpleForm('mesh_vpn', translate('Mesh VPN'))
local s = f:section(SimpleSection)
local o = s:option(Value, 'mode')
o.template = "gluon/cbi/mesh-vpn-fastd-mode"
local methods = uci:get('fastd', 'mesh_vpn', 'method')
if util.contains(methods, 'null') then
o.default = 'performance'
else
o.default = 'security'
end
function f.handle(self, state, data)
if state == FORM_VALID then
local site = require 'gluon.site_config'
local methods = {}
if data.mode == 'performance' then
table.insert(methods, 'null')
end
for _, method in ipairs(site.fastd_mesh_vpn.methods) do
if method ~= 'null' then
table.insert(methods, method)
end
end
uci:set('fastd', 'mesh_vpn', 'method', methods)
uci:save('fastd')
uci:commit('fastd')
end
end
return f
module("luci.controller.admin.noderole", package.seeall)
function index()
entry({"admin", "noderole"}, cbi("admin/noderole"), "Node role", 20)
end
--[[
LuCI - Lua Configuration Interface
Copyright 2013 Nils Schneider <nils@nilsschneider.net>
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$
]]--
module("luci.controller.admin.portconfig", package.seeall)
function index()
entry({"admin", "portconfig"}, cbi("admin/portconfig"), _("Network"), 20)
end
--[[
LuCI - Lua Configuration Interface
Copyright 2014 Nils Schneider <nils@nilsschneider.net>
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 uci = require("simple-uci").cursor()
local sysconfig = require 'gluon.sysconfig'
local util = require 'gluon.util'
local wan = uci:get_all("network", "wan")
local wan6 = uci:get_all("network", "wan6")
local dns = uci:get_first("gluon-wan-dnsmasq", "static")
local f = SimpleForm("portconfig", translate("WAN connection"))
local s
local o
s = f:section(SimpleSection, nil, nil)
o = s:option(ListValue, "ipv4", translate("IPv4"))
o:value("dhcp", translate("Automatic (DHCP)"))
o:value("static", translate("Static"))
o:value("none", translate("Disabled"))
o.default = wan.proto
o = s:option(Value, "ipv4_addr", translate("IP address"))
o:depends("ipv4", "static")
o.value = wan.ipaddr
o.datatype = "ip4addr"
o.rmempty = false
o = s:option(Value, "ipv4_netmask", translate("Netmask"))
o:depends("ipv4", "static")
o.value = wan.netmask or "255.255.255.0"
o.datatype = "ip4addr"
o.rmempty = false
o = s:option(Value, "ipv4_gateway", translate("Gateway"))
o:depends("ipv4", "static")
o.value = wan.gateway
o.datatype = "ip4addr"
o.rmempty = false
s = f:section(SimpleSection, nil, nil)
o = s:option(ListValue, "ipv6", translate("IPv6"))
o:value("dhcpv6", translate("Automatic (RA/DHCPv6)"))
o:value("static", translate("Static"))
o:value("none", translate("Disabled"))
o.default = wan6.proto
o = s:option(Value, "ipv6_addr", translate("IP address"))
o:depends("ipv6", "static")
o.value = wan6.ip6addr
o.datatype = "ip6addr"
o.rmempty = false
o = s:option(Value, "ipv6_gateway", translate("Gateway"))
o:depends("ipv6", "static")
o.value = wan6.ip6gw
o.datatype = "ip6addr"
o.rmempty = false
if dns then
s = f:section(SimpleSection, nil, nil)
o = s:option(DynamicList, "dns", translate("Static DNS servers"))
o:write(nil, uci:get("gluon-wan-dnsmasq", dns, "server"))
o.datatype = "ipaddr"
end
s = f:section(SimpleSection, nil, nil)
o = s:option(Flag, "mesh_wan", translate("Enable meshing on the WAN interface"))
o.default = uci:get_bool("network", "mesh_wan", "auto") and o.enabled or o.disabled
o.rmempty = false
if sysconfig.lan_ifname then
o = s:option(Flag, "mesh_lan", translate("Enable meshing on the LAN interface"))
o.default = uci:get_bool("network", "mesh_lan", "auto") and o.enabled or o.disabled
o.rmempty = false
end
if uci:get('system', 'gpio_switch_poe_passthrough') then
s = f:section(SimpleSection, nil, nil)
o = s:option(Flag, "poe_passthrough", translate("Enable PoE passthrough"))
o.default = uci:get_bool("system", "gpio_switch_poe_passthrough", "value") and o.enabled or o.disabled
o.rmempty = false
end
function f.handle(self, state, data)
if state == FORM_VALID then
uci:set("network", "wan", "proto", data.ipv4)
if data.ipv4 == "static" then
uci:set("network", "wan", "ipaddr", data.ipv4_addr:trim())
uci:set("network", "wan", "netmask", data.ipv4_netmask:trim())
uci:set("network", "wan", "gateway", data.ipv4_gateway:trim())
else
uci:delete("network", "wan", "ipaddr")
uci:delete("network", "wan", "netmask")
uci:delete("network", "wan", "gateway")
end
uci:set("network", "wan6", "proto", data.ipv6)
if data.ipv6 == "static" then
uci:set("network", "wan6", "ip6addr", data.ipv6_addr:trim())
uci:set("network", "wan6", "ip6gw", data.ipv6_gateway:trim())
else
uci:delete("network", "wan6", "ip6addr")
uci:delete("network", "wan6", "ip6gw")
end
uci:set("network", "mesh_wan", "auto", data.mesh_wan)
if sysconfig.lan_ifname then
uci:set("network", "mesh_lan", "auto", data.mesh_lan)
local interfaces = uci:get_list("network", "client", "ifname")
for lanif in sysconfig.lan_ifname:gmatch('%S+') do
if data.mesh_lan == '1' then
util.remove_from_set(interfaces, lanif)
else
util.add_to_set(interfaces, lanif)
end
end
uci:set_list("network", "client", "ifname", interfaces)
end
uci:save("network")
uci:commit("network")
if uci:get('system', 'gpio_switch_poe_passthrough') then
uci:set('system', 'gpio_switch_poe_passthrough', 'value', data.poe_passthrough)
uci:save('system')
uci:commit('system')
end
if dns then
if #data.dns > 0 then
uci:set("gluon-wan-dnsmasq", dns, "server", data.dns)
else
uci:delete("gluon-wan-dnsmasq", dns, "server")
end
uci:save("gluon-wan-dnsmasq")
uci:commit("gluon-wan-dnsmasq")
end
end
return true
end
return f
module("luci.controller.admin.privatewifi", package.seeall)
function index()
entry({"admin", "privatewifi"}, cbi("admin/privatewifi"), _("Private WLAN"), 10)
end
local uci = require("simple-uci").cursor()
local util = require 'gluon.util'
local f, s, o, ssid
-- where to read the configuration from
local primary_iface = 'wan_radio0'
local ssid = uci:get('wireless', primary_iface, "ssid")
f = SimpleForm("wifi", translate("Private WLAN"))
s = f:section(SimpleSection, nil, translate(
'Your node can additionally extend your private network by bridging the WAN interface '
.. 'with a separate WLAN. This feature is completely independent of the mesh functionality. '
.. 'Please note that the private WLAN and meshing on the WAN interface should not be enabled '
.. 'at the same time.'
))
o = s:option(Flag, "enabled", translate("Enabled"))
o.default = (ssid and not uci:get_bool('wireless', primary_iface, "disabled")) and o.enabled or o.disabled
o.rmempty = false
o = s:option(Value, "ssid", translate("Name (SSID)"))
o:depends("enabled", '1')
o.datatype = "maxlength(32)"
o.default = ssid
o = s:option(Value, "key", translate("Key"), translate("8-63 characters"))
o:depends("enabled", '1')
o.datatype = "wpakey"
o.default = uci:get('wireless', primary_iface, "key")
function f.handle(self, state, data)
if state == FORM_VALID then
util.iterate_radios(
function(radio, index)
local name = "wan_" .. radio
if data.enabled == '1' then
local macaddr = util.get_wlan_mac(radio, index, 4)
-- set up WAN wifi-iface
uci:section('wireless', "wifi-iface", name,
{
device = radio,
network = "wan",
mode = 'ap',
encryption = 'psk2',
ssid = data.ssid,
key = data.key,
macaddr = macaddr,
disabled = false,
}
)
else
-- disable WAN wifi-iface
uci:set('wireless', name, "disabled", true)
end
end
)
uci:save('wireless')
uci:commit('wireless')
end
end
return f
#!/bin/sh
uci batch <<-EOF
set luci.themes.Gluon=/luci-static/gluon
commit luci
EOF
<%#
LuCI - Lua Configuration Interface
Copyright 2008 Steven Barth <steven@midlink.org>
Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
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$
-%>
</div>
</div>
</body>
</html>
<%#
LuCI - Lua Configuration Interface
Copyright 2008 Steven Barth <steven@midlink.org>
Copyright 2008-2010 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 sys = require "luci.sys"
local http = require "luci.http"
local disp = require "luci.dispatcher"
local uci = require("simple-uci").cursor()
local fs = require "nixio.fs"
local gluon_luci = require "gluon.luci"
local pretty_hostname = require "pretty_hostname"
local hostname = pretty_hostname.get(uci)
local release = fs.readfile("/lib/gluon/release")
local request = disp.context.path
local request2 = disp.context.request
local category = request[1]
local cattree = category and disp.node(category)
local leaf = request2[#request2]
local tree = disp.node()
local node = disp.context.dispatched
local categories = disp.node_childs(tree)
local c = tree
local i, r
-- tag all nodes leading to this page
for i, r in ipairs(request) do
if c.nodes and c.nodes[r] then
c = c.nodes[r]
c._menu_selected = true
end
end
http.prepare_content("application/xhtml+xml")
local function nodeurl(prefix, name, query)
local url = controller .. prefix .. name .. "/"
if query then
url = url .. http.build_querystring(query)
end
return pcdata(url)
end
local function subtree(prefix, node, level)
if not level then
level = 1
end
local childs = disp.node_childs(node)
if #childs > 0 then
%>
<div class="tabmenu<%=level%>">
<ul class="tabmenu l<%=level%>">
<%
local selected_node
local selected_name
local i, v
for i, v in ipairs(childs) do
local nnode = node.nodes[v]
if nnode._menu_selected then
selected_node = nnode
selected_name = v
end
%>
<li class="tabmenu-item-<%=v%><% if nnode._menu_selected or (node.leaf and v == leaf) then %> active<% end %>">
<a href="<%=nodeurl(prefix, v, nnode.query)%>"><%=striptags(translate(nnode.title))%></a>
</li>
<%
end
%>
</ul>
<br style="clear:both" />
<%
if selected_node then
subtree(prefix .. selected_name .. "/", selected_node, level + 1)
end
%>
</div>
<%
end
end
-%>
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<%=luci.i18n.context.lang%>" lang="<%=luci.i18n.context.lang%>">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<link rel="stylesheet" type="text/css" media="screen" href="<%=media%>/cascade.css" />
<% if node and node.css then %><link rel="stylesheet" type="text/css" media="screen" href="<%=resource%>/<%=node.css%>" />
<% end -%>
<% if css then %><style title="text/css">
<%= css %>
</style>
<% end -%>
<script type="text/javascript" src="<%=resource%>/xhr.js"></script>
<title><%=gluon_luci.escape( hostname .. ( (node and node.title) and ' - ' .. translate(node.title) or '')) %> - LuCI</title>
</head>
<body class="lang_<%=luci.i18n.context.lang%>">
<div id="menubar">
<div class="hostinfo">
<%=gluon_luci.escape(hostname)%>
<% if release then %>
/ <%=gluon_luci.escape(release)%>
<% end %>
<span id="xhr_poll_status" style="display:none" onclick="XHR.running() ? XHR.halt() : XHR.run()">
| <%:Auto Refresh%>:
<span id="xhr_poll_status_on"><%:on%></span>
<span id="xhr_poll_status_off" style="display:none"><%:off%></span>
</span>
</div>
<% if #categories > 1 then %>
<ul id="modemenu">
<% for i, r in ipairs(categories) do %>
<li><a<% if request[1] == r then %> class="active"<%end%> href="<%=controller%>/<%=r%>/"><%=striptags(translate(tree.nodes[r].title))%></a></li>
<% end %>
</ul>
<% end %>
<%
if tree.nodes[category] and tree.nodes[category].ucidata then
local ucic = 0
for i, j in pairs(require("simple-uci").cursor():changes()) do
for k, l in pairs(j) do
for m, n in pairs(l) do
ucic = ucic + 1;
end
end
end
-%>
<div id="savemenu">
<% if ucic > 0 then %>
<a class="warning" href="<%=controller%>/<%=category%>/uci/changes/?redir=<%=luci.http.urlencode(luci.http.formvalue("redir") or REQUEST_URI)%>"><%:Unsaved Changes%>: <%=ucic%></a>
<%- else -%>
<a href="#"><%:Changes%>: 0</a>
<% end -%>
</div><% end %>
</div>
<div id="maincontainer">
<% if category then subtree("/" .. category .. "/", cattree) end %>
<div id="maincontent">
<noscript>
<div class="errorbox">
<strong><%:Java Script required!%></strong><br />
<%:You must enable Java Script in your browser or LuCI will not work properly.%>
</div>
</noscript>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment