package/gluon-*/luasrc: fix lua indentation
This commit is contained in:
parent
5ccbaed6f5
commit
c05abb4179
@ -23,6 +23,8 @@ indent_size = 2
|
|||||||
indent_style = space
|
indent_style = space
|
||||||
indent_size = 2
|
indent_size = 2
|
||||||
|
|
||||||
|
[*.lua]
|
||||||
|
|
||||||
[*.md]
|
[*.md]
|
||||||
indent_style = space
|
indent_style = space
|
||||||
indent_size = 4
|
indent_size = 4
|
||||||
|
@ -6,17 +6,17 @@ local file = '/etc/dropbear/authorized_keys'
|
|||||||
local keys = {}
|
local keys = {}
|
||||||
|
|
||||||
local function load_keys()
|
local function load_keys()
|
||||||
for line in io.lines(file) do
|
for line in io.lines(file) do
|
||||||
keys[line] = true
|
keys[line] = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
pcall(load_keys)
|
pcall(load_keys)
|
||||||
|
|
||||||
local f = io.open(file, 'a')
|
local f = io.open(file, 'a')
|
||||||
for _, key in ipairs(site.authorized_keys()) do
|
for _, key in ipairs(site.authorized_keys()) do
|
||||||
if not keys[key] then
|
if not keys[key] then
|
||||||
f:write(key .. '\n')
|
f:write(key .. '\n')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
f:close()
|
f:close()
|
||||||
|
@ -10,11 +10,11 @@ return function(form, uci)
|
|||||||
|
|
||||||
local msg = pkg_i18n.translate(
|
local msg = pkg_i18n.translate(
|
||||||
'Your internet connection can be used to establish a ' ..
|
'Your internet connection can be used to establish a ' ..
|
||||||
'VPN connection with other nodes. ' ..
|
'VPN 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(Section, nil, msg)
|
local s = form:section(Section, nil, msg)
|
||||||
|
@ -131,9 +131,9 @@ function M.get_mesh_devices(uconn)
|
|||||||
local dump = uconn:call("network.interface", "dump", {})
|
local dump = uconn:call("network.interface", "dump", {})
|
||||||
local devices = {}
|
local devices = {}
|
||||||
for _, interface in ipairs(dump.interface) do
|
for _, interface in ipairs(dump.interface) do
|
||||||
if ( (interface.proto == "gluon_mesh") and interface.up ) then
|
if ( (interface.proto == "gluon_mesh") and interface.up ) then
|
||||||
table.insert(devices, interface.device)
|
table.insert(devices, interface.device)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return devices
|
return devices
|
||||||
end
|
end
|
||||||
|
@ -6,13 +6,13 @@ local site = require 'gluon.site'
|
|||||||
local private_key = uci:get("network_gluon-old", 'wg_mesh', "private_key")
|
local private_key = uci:get("network_gluon-old", 'wg_mesh', "private_key")
|
||||||
|
|
||||||
if not private_key or not private_key:match("^" .. ("[%a%d+/]"):rep(42) .. "[AEIMQUYcgkosw480]=$") then
|
if not private_key or not private_key:match("^" .. ("[%a%d+/]"):rep(42) .. "[AEIMQUYcgkosw480]=$") then
|
||||||
private_key = "generate"
|
private_key = "generate"
|
||||||
end
|
end
|
||||||
|
|
||||||
uci:section('network', 'interface', 'wg_mesh', {
|
uci:section('network', 'interface', 'wg_mesh', {
|
||||||
proto = 'wireguard',
|
proto = 'wireguard',
|
||||||
fwmark = 1,
|
fwmark = 1,
|
||||||
private_key = private_key,
|
private_key = private_key,
|
||||||
})
|
})
|
||||||
|
|
||||||
uci:section('network', 'interface', 'mesh_wg_mesh', {
|
uci:section('network', 'interface', 'mesh_wg_mesh', {
|
||||||
@ -22,17 +22,17 @@ uci:section('network', 'interface', 'mesh_wg_mesh', {
|
|||||||
|
|
||||||
-- Clean up previous configuration
|
-- Clean up previous configuration
|
||||||
uci:delete_all('wgpeerselector', 'peer', function(peer)
|
uci:delete_all('wgpeerselector', 'peer', function(peer)
|
||||||
return peer.preserve ~= '1'
|
return peer.preserve ~= '1'
|
||||||
end)
|
end)
|
||||||
|
|
||||||
for name, peer in pairs(site.mesh_vpn.wireguard.peers()) do
|
for name, peer in pairs(site.mesh_vpn.wireguard.peers()) do
|
||||||
uci:section("wgpeerselector", "peer", name, {
|
uci:section("wgpeerselector", "peer", name, {
|
||||||
enabled = true,
|
enabled = true,
|
||||||
endpoint = peer.endpoint,
|
endpoint = peer.endpoint,
|
||||||
public_key = peer.public_key,
|
public_key = peer.public_key,
|
||||||
allowed_ips = { "fe80::1/128" },
|
allowed_ips = { "fe80::1/128" },
|
||||||
ifname = 'wg_mesh',
|
ifname = 'wg_mesh',
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
uci:save("wgpeerselector")
|
uci:save("wgpeerselector")
|
||||||
|
@ -4,28 +4,24 @@ local uci = require('simple-uci').cursor()
|
|||||||
|
|
||||||
-- Allow incoming respondd replies to queries on WAN
|
-- Allow incoming respondd replies to queries on WAN
|
||||||
-- If the query was via multicast, the response isn't matched by --state RELATED
|
-- If the query was via multicast, the response isn't matched by --state RELATED
|
||||||
uci:section('firewall', 'rule', 'wan_respondd_reply',
|
uci:section('firewall', 'rule', 'wan_respondd_reply', {
|
||||||
{
|
name = 'wan_respondd_reply',
|
||||||
name = 'wan_respondd_reply',
|
src = 'wan',
|
||||||
src = 'wan',
|
src_ip = 'fe80::/64',
|
||||||
src_ip = 'fe80::/64',
|
src_port = '1001',
|
||||||
src_port = '1001',
|
dest_port = '32768:61000', -- see /proc/sys/net/ipv4/ip_local_port_range
|
||||||
dest_port = '32768:61000', -- see /proc/sys/net/ipv4/ip_local_port_range
|
proto = 'udp',
|
||||||
proto = 'udp',
|
target = 'ACCEPT',
|
||||||
target = 'ACCEPT',
|
})
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
uci:section('firewall', 'rule', 'mesh_respondd_reply',
|
uci:section('firewall', 'rule', 'mesh_respondd_reply', {
|
||||||
{
|
name = 'mesh_respondd_reply',
|
||||||
name = 'mesh_respondd_reply',
|
src = 'mesh',
|
||||||
src = 'mesh',
|
src_ip = 'fe80::/64',
|
||||||
src_ip = 'fe80::/64',
|
src_port = '1001',
|
||||||
src_port = '1001',
|
dest_port = '32768:61000', -- see /proc/sys/net/ipv4/ip_local_port_range
|
||||||
dest_port = '32768:61000', -- see /proc/sys/net/ipv4/ip_local_port_range
|
proto = 'udp',
|
||||||
proto = 'udp',
|
target = 'ACCEPT',
|
||||||
target = 'ACCEPT',
|
})
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
uci:save('firewall')
|
uci:save('firewall')
|
||||||
|
@ -5,6 +5,6 @@ local uci = require('simple-uci').cursor()
|
|||||||
local config = 'gluon-node-info'
|
local config = 'gluon-node-info'
|
||||||
|
|
||||||
if not uci:get_first(config, 'system') then
|
if not uci:get_first(config, 'system') then
|
||||||
uci:section(config, 'system')
|
uci:section(config, 'system')
|
||||||
uci:save(config)
|
uci:save(config)
|
||||||
end
|
end
|
||||||
|
@ -12,63 +12,63 @@ local util = require 'gluon.util'
|
|||||||
local new_servers = ''
|
local new_servers = ''
|
||||||
|
|
||||||
local function append_server(server)
|
local function append_server(server)
|
||||||
new_servers = new_servers .. 'nameserver ' .. server .. '\n'
|
new_servers = new_servers .. 'nameserver ' .. server .. '\n'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function handled_interfaces()
|
local function handled_interfaces()
|
||||||
local interfaces = {}
|
local interfaces = {}
|
||||||
|
|
||||||
for _, path in ipairs(util.glob('/lib/gluon/wan-dnsmasq/interface.d/*')) do
|
for _, path in ipairs(util.glob('/lib/gluon/wan-dnsmasq/interface.d/*')) do
|
||||||
for interface in io.lines(path) do
|
for interface in io.lines(path) do
|
||||||
table.insert(interfaces, interface)
|
table.insert(interfaces, interface)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return interfaces
|
return interfaces
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function handle_interface(status)
|
local function handle_interface(status)
|
||||||
local ifname = status.device
|
local ifname = status.device
|
||||||
local servers = status.inactive['dns-server']
|
local servers = status.inactive['dns-server']
|
||||||
|
|
||||||
for _, server in ipairs(servers) do
|
for _, server in ipairs(servers) do
|
||||||
if server:match('^fe80:') then
|
if server:match('^fe80:') then
|
||||||
append_server(server .. '%' .. ifname)
|
append_server(server .. '%' .. ifname)
|
||||||
else
|
else
|
||||||
append_server(server)
|
append_server(server)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function append_interface_servers(iface)
|
local function append_interface_servers(iface)
|
||||||
handle_interface(ubus:call('network.interface.' .. iface, 'status', {}))
|
handle_interface(ubus:call('network.interface.' .. iface, 'status', {}))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local static = uci:get_first('gluon-wan-dnsmasq', 'static', 'server')
|
local static = uci:get_first('gluon-wan-dnsmasq', 'static', 'server')
|
||||||
|
|
||||||
if type(static) == 'table' and #static > 0 then
|
if type(static) == 'table' and #static > 0 then
|
||||||
for _, server in ipairs(static) do
|
for _, server in ipairs(static) do
|
||||||
append_server(server)
|
append_server(server)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
for _, interface in ipairs(handled_interfaces()) do
|
for _, interface in ipairs(handled_interfaces()) do
|
||||||
pcall(append_interface_servers, interface)
|
pcall(append_interface_servers, interface)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local old_servers = util.readfile(RESOLV_CONF)
|
local old_servers = util.readfile(RESOLV_CONF)
|
||||||
|
|
||||||
if new_servers ~= old_servers then
|
if new_servers ~= old_servers then
|
||||||
stat.mkdir('/var/gluon')
|
stat.mkdir('/var/gluon')
|
||||||
stat.mkdir('/var/gluon/wan-dnsmasq')
|
stat.mkdir('/var/gluon/wan-dnsmasq')
|
||||||
|
|
||||||
local f = io.open(RESOLV_CONF .. '.tmp', 'w')
|
local f = io.open(RESOLV_CONF .. '.tmp', 'w')
|
||||||
f:write(new_servers)
|
f:write(new_servers)
|
||||||
f:close()
|
f:close()
|
||||||
|
|
||||||
os.rename(RESOLV_CONF .. '.tmp', RESOLV_CONF)
|
os.rename(RESOLV_CONF .. '.tmp', RESOLV_CONF)
|
||||||
end
|
end
|
||||||
|
@ -179,7 +179,7 @@ local function dispatch(config, http, request)
|
|||||||
renderer.render_layout("error/404", {
|
renderer.render_layout("error/404", {
|
||||||
message =
|
message =
|
||||||
"No page is registered at '/" .. table.concat(request, "/") .. "'.\n" ..
|
"No page is registered at '/" .. table.concat(request, "/") .. "'.\n" ..
|
||||||
"If this URL belongs to an extension, make sure it is properly installed.\n",
|
"If this URL belongs to an extension, make sure it is properly installed.\n",
|
||||||
}, 'gluon-web')
|
}, 'gluon-web')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -58,7 +58,7 @@ return function(config, env)
|
|||||||
-- Now finally render the thing
|
-- Now finally render the thing
|
||||||
local stat, err = pcall(template)
|
local stat, err = pcall(template)
|
||||||
assert(stat, "Failed to execute template '" .. name .. "'.\n" ..
|
assert(stat, "Failed to execute template '" .. name .. "'.\n" ..
|
||||||
"A runtime error occurred: " .. tostring(err or "(nil)"))
|
"A runtime error occurred: " .. tostring(err or "(nil)"))
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Render a certain template.
|
--- Render a certain template.
|
||||||
|
Loading…
Reference in New Issue
Block a user