-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #840 from germanferrero/new-align-screen
New align screen
- Loading branch information
Showing
14 changed files
with
235 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"lime-app": { | ||
"read": { | ||
"ubus": { | ||
"iwinfo": [ "assoclist" ] | ||
} | ||
}, | ||
"write": { | ||
"ubus": { | ||
"iwinfo": [ "assoclist" ] | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
packages/shared-state-bat_hosts/files/usr/lib/lua/bat-hosts.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
local shared_state = require("shared-state") | ||
local utils = require("lime.utils") | ||
|
||
local bat_hosts = {} | ||
|
||
function bat_hosts.bathost_deserialize(hostname_plus_iface) | ||
local partial_hostname = hostname_plus_iface | ||
local iface | ||
for _, ifname in ipairs(utils.get_ifnames()) do | ||
local serialized_ifname = string.gsub(ifname, "%W", "_") | ||
serialized_ifname = utils.literalize(serialized_ifname) | ||
local replaced_hostname = hostname_plus_iface:gsub("_"..serialized_ifname, "") | ||
-- hostname don't have underscores see utils.is_valid_hostname | ||
replaced_hostname = replaced_hostname:gsub("_", "-") | ||
if #replaced_hostname < #partial_hostname then | ||
partial_hostname = replaced_hostname | ||
iface = ifname | ||
end | ||
end | ||
return partial_hostname, iface | ||
end | ||
|
||
function bat_hosts.get_bathost(mac, outgoing_iface) | ||
local sharedState = shared_state.SharedState:new('bat-hosts') | ||
local bathosts = sharedState:get() | ||
local bathost = bathosts[mac:lower()] | ||
if bathost == nil and outgoing_iface then | ||
local ipv6ll = utils.mac2ipv6linklocal(mac) .. "%" .. outgoing_iface | ||
sharedState:sync({ ipv6ll }) | ||
bathosts = sharedState:get() | ||
bathost = bathosts[mac:lower()] | ||
end | ||
if bathost == nil then | ||
return | ||
end | ||
local hostname, iface = bat_hosts.bathost_deserialize(bathost.data) | ||
return { hostname = hostname, iface = iface } | ||
end | ||
|
||
return bat_hosts |
55 changes: 55 additions & 0 deletions
55
packages/shared-state-bat_hosts/files/usr/libexec/rpcd/bat-hosts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/usr/bin/env lua | ||
--[[ | ||
Copyright (C) 2013-2020 LibreMesh.org | ||
This is free software, licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 | ||
Copyright 2020 German Ferrero <germanferrero@altermundi.net> | ||
]]-- | ||
|
||
local ubus = require "ubus" | ||
local json = require 'luci.jsonc' | ||
local utils = require 'lime.utils' | ||
local bat_hosts = require 'bat-hosts' | ||
|
||
local conn = ubus.connect() | ||
if not conn then | ||
error("Failed to connect to ubus") | ||
end | ||
|
||
local function get_bathost(msg) | ||
if not msg.mac or not utils.is_valid_mac(msg.mac) then | ||
utils.printJson({ status = "error", message = "invalid mac" }) | ||
return | ||
end | ||
|
||
if msg.outgoing_iface and not utils.has_value(utils.get_ifnames(), msg.outgoing_iface) then | ||
utils.printJson({ status = "error", message = "invalid outgoing interface" }) | ||
return | ||
end | ||
local bathost = bat_hosts.get_bathost(msg.mac, msg.outgoing_iface) | ||
local result = {} | ||
if bathost.hostname ~= nil then | ||
result.status = "ok" | ||
result.bathost = bathost | ||
else | ||
result.status = "error" | ||
result.error = "Couldn't retrieve hostname" | ||
end | ||
utils.printJson(result) | ||
end | ||
|
||
local methods = { | ||
get_bathost = { mac = 'value', outgoing_iface = 'value'} | ||
} | ||
|
||
if arg[1] == 'list' then | ||
utils.printJson(methods) | ||
end | ||
|
||
if arg[1] == 'call' then | ||
local msg = utils.rpcd_readline() or '{}' | ||
msg = json.parse(msg) | ||
if arg[2] == 'get_bathost' then get_bathost(msg) | ||
else utils.printJson({ error = "Method not found" }) | ||
end | ||
end |
15 changes: 15 additions & 0 deletions
15
packages/shared-state-bat_hosts/files/usr/share/acl.d/bat-hosts.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"lime-app": { | ||
"description": "lime-app public access", | ||
"read": { | ||
"ubus": { | ||
"bat-hosts": [ "*" ] | ||
} | ||
}, | ||
"write": { | ||
"ubus": { | ||
"bat-hosts": [ "*" ] | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
local bat_hosts = require('bat-hosts') | ||
local utils = require('lime.utils') | ||
local test_utils = require('tests.utils') | ||
local shared_state = require('shared-state') | ||
|
||
it('test get_bathost #bathost', function() | ||
shared_state.DATA_DIR = test_utils.setup_test_dir() | ||
local sharedState = shared_state.SharedState:new('bat-hosts') | ||
sharedState:insert({ | ||
["02:95:39:ab:cd:00"] = "LiMe_abcd00_wlan1_mesh", | ||
["52:00:00:ab:cd:a0"] = "LiMe_abcd01_wlan2_mesh_17", | ||
["d6:67:58:8e:cd:92"] = "LiMe_abcd02_wlan0_adhoc_29", | ||
["12:00:00:00:00:00"] = "LiMe_abcd03_wlan1_adhoc" | ||
}) | ||
local ifaces = {'wlan1-mesh', 'wlan2-mesh', 'wlan2-mesh_17', 'wlan0-adhoc_29', 'wlan1-adhoc'} | ||
stub(utils, "get_ifnames", function () return ifaces end) | ||
assert.is.same({hostname='LiMe-abcd00', iface='wlan1-mesh'}, bat_hosts.get_bathost('02:95:39:ab:cd:00')) | ||
assert.is.same({hostname='LiMe-abcd01', iface='wlan2-mesh_17'}, bat_hosts.get_bathost('52:00:00:ab:cd:a0')) | ||
assert.is.same({hostname='LiMe-abcd02', iface='wlan0-adhoc_29'}, bat_hosts.get_bathost('d6:67:58:8e:cd:92')) | ||
assert.is.same({hostname='LiMe-abcd03', iface='wlan1-adhoc'}, bat_hosts.get_bathost('12:00:00:00:00:00')) | ||
local ipv6ll = utils.mac2ipv6linklocal('52:00:00:ab:cd:00') .. '%wlan1-mesh' | ||
local dataTypeOfSync = nil | ||
local urlsOfSync = nil | ||
local function syncMock (self, urls) | ||
dataTypeOfSync = self.dataType | ||
urlsOfSync = urls | ||
self:insert({['52:00:00:ab:cd:00'] = "Lime_abcd04_wlan1_mesh"}) | ||
end | ||
stub(shared_state.SharedState, "sync", syncMock) | ||
local bathost = bat_hosts.get_bathost('52:00:00:ab:cd:00', 'wlan1-mesh') | ||
assert.is.same(urlsOfSync, { ipv6ll }) | ||
assert.is.equal(dataTypeOfSync, 'bat-hosts') | ||
assert.is.same({hostname='Lime-abcd04', iface='wlan1-mesh'}, bathost) | ||
assert.is_nil(bat_hosts.get_bathost('00:aa:bb:cc:dd:00', 'wlan1')) | ||
assert.is_nil(bat_hosts.get_bathost('00:aa:bb:cc:dd:00')) | ||
end) |
34 changes: 34 additions & 0 deletions
34
packages/shared-state-bat_hosts/tests/test_ubus_bat_hosts.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
local bat_hosts = require "bat-hosts" | ||
local test_utils = require "tests.utils" | ||
|
||
local test_file_name = "packages/shared-state-bat_hosts/files/usr/libexec/rpcd/bat-hosts" | ||
local ubus_bat_hosts = test_utils.load_lua_file_as_function(test_file_name) | ||
|
||
local rpcd_call = test_utils.rpcd_call | ||
|
||
describe('ubus-bat-hosts tests #ubusbathosts', function() | ||
it('test get_bathost', function() | ||
stub(bat_hosts, "get_bathost", | ||
function() return { hostname = 'lime', iface = 'wlan1-mesh' } end | ||
) | ||
local response = rpcd_call(ubus_bat_hosts, {'call', 'get_bathost'}, '{}') | ||
assert.is.equal("error", response.status) | ||
assert.is.equal("invalid mac", response.message) | ||
local response = rpcd_call(ubus_bat_hosts, | ||
{'call', 'get_bathost'}, '{"mac":"02:95:39:ab:cd:00"}') | ||
assert.is.equal("ok", response.status) | ||
assert.is.same({ hostname = 'lime', iface = 'wlan1-mesh' }, response.bathost) | ||
|
||
|
||
stub(utils, "get_ifnames", function() return {'wlan1-mesh'} end) | ||
local response = rpcd_call(ubus_bat_hosts, | ||
{'call', 'get_bathost'}, '{"mac":"02:95:39:ab:cd:00", "outgoing_iface":"foo"}') | ||
assert.is.equal("error", response.status) | ||
assert.is.equal("invalid outgoing interface", response.message) | ||
|
||
local response = rpcd_call(ubus_bat_hosts, | ||
{'call', 'get_bathost'}, '{"mac":"02:95:39:ab:cd:00", "outgoing_iface":"wlan1-mesh"}') | ||
assert.is.equal("ok", response.status) | ||
assert.is.same({ hostname = 'lime', iface = 'wlan1-mesh' }, response.bathost) | ||
end) | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.