Skip to content
Snippets Groups Projects
Unverified Commit 34450c68 authored by lemoer's avatar lemoer Committed by GitHub
Browse files

Merge pull request #2915 from ffgraz/info

Add ethernet module, add get_switch_type, make info shared, display switch type in info
parents 905ed49a 65a61930
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/lua #!/usr/bin/lua
local uci = require('simple-uci').cursor() local info = require 'gluon.info'
local pretty_hostname = require 'pretty_hostname'
local site = require 'gluon.site' local values = info.get_info_pretty(function(str) return str end)
local sysconfig = require 'gluon.sysconfig'
local platform = require 'gluon.platform'
local util = require 'gluon.util'
local has_vpn, vpn = pcall(require, 'gluon.mesh-vpn')
local pubkey
if has_vpn and vpn.enabled() then
local _, active_vpn = vpn.get_active_provider()
if active_vpn ~= nil then
pubkey = active_vpn.public_key()
end
end
local values = {
{ 'Hostname', pretty_hostname.get(uci) },
{ 'MAC address', sysconfig.primary_mac },
{ 'Hardware model', platform.get_model() },
{ 'Gluon version / Site version', util.trim(util.readfile('/lib/gluon/gluon-version'))
.. ' / ' .. util.trim(util.readfile('/lib/gluon/site-version')) },
{ 'Firmware release', util.trim(util.readfile('/lib/gluon/release')) },
{ 'Site', site.site_name() },
{ 'Domain', uci:get('gluon', 'core', 'domain') or 'n/a' },
{ 'Public VPN key', pubkey or 'n/a' },
}
local padTo = 24 local padTo = 24
for _, info in ipairs(values) do for _, value in ipairs(values) do
local labelLen = string.len(info[1]) + 1 local labelLen = string.len(value[1]) + 1
print(info[1] .. ':' .. string.rep(' ', padTo - labelLen), info[2]) print(value[1] .. ':' .. string.rep(' ', padTo - labelLen), value[2])
end end
local util = require 'gluon.util'
local unistd = require 'posix.unistd'
local dirent = require 'posix.dirent'
local uci = require('simple-uci').cursor()
local M = {}
local function has_devtype(iface_dir, devtype)
return util.file_contains_line(iface_dir..'/uevent', 'DEVTYPE='..devtype)
end
local function is_physical(iface_dir)
return unistd.access(iface_dir .. '/device') == 0
end
local function is_swconfig()
local has = false
uci:foreach("system", "switch", function()
has = true
end)
uci:foreach("system", "switch_vlan", function()
has = true
end)
return has
end
local function interfaces_raw()
local eth_ifaces = {}
local ifaces_dir = '/sys/class/net/'
for iface in dirent.files(ifaces_dir) do
if iface ~= '.' and iface ~= '..' then
local iface_dir = ifaces_dir .. iface
if is_physical(iface_dir) and not has_devtype(iface_dir, 'wlan') then
table.insert(eth_ifaces, iface)
end
end
end
return eth_ifaces
end
-- In comparison to interfaces_raw, this skips non-DSA ports on DSA devices,
-- as for ex. hap ac² has a special eth0 that shouldn't be touched
function M.interfaces()
local intfs = interfaces_raw()
if M.get_switch_type() == 'dsa' then
local new_intfs = {}
for _, intf in ipairs(intfs) do
if has_devtype('/sys/class/net/' .. intf, 'dsa') then
table.insert(new_intfs, intf)
end
end
return new_intfs
end
return intfs
end
function M.is_vlan(intf)
return has_devtype('/sys/class/net/' .. intf, 'vlan')
end
function M.get_switch_type()
if is_swconfig() then
return 'swconfig'
end
for _, intf in ipairs(interfaces_raw()) do
if has_devtype('/sys/class/net/' .. intf, 'dsa') then
return 'dsa'
end
end
return 'none'
end
return M
local uci = require('simple-uci').cursor()
local pretty_hostname = require 'pretty_hostname'
local site = require 'gluon.site'
local sysconfig = require 'gluon.sysconfig'
local platform = require 'gluon.platform'
local util = require 'gluon.util'
local has_vpn, vpn = pcall(require, 'gluon.mesh-vpn')
local ethernet = require 'gluon.ethernet'
local pubkey
if has_vpn and vpn.enabled() then
local _, active_vpn = vpn.get_active_provider()
if active_vpn ~= nil then
pubkey = active_vpn.public_key()
end
end
local M = {}
function M.get_info()
return {
hostname = pretty_hostname.get(uci),
mac_address = sysconfig.primary_mac,
hardware_model = platform.get_model(),
gluon_version = util.trim(util.readfile('/lib/gluon/gluon-version')),
site_version = util.trim(util.readfile('/lib/gluon/site-version')),
firmware_release = util.trim(util.readfile('/lib/gluon/release')),
site = site.site_name(),
domain = uci:get('gluon', 'core', 'domain'),
public_vpn_key = pubkey,
switch_type = ethernet.get_switch_type(),
}
end
function M.get_info_pretty(_)
local data = M.get_info()
return {
{ _('Hostname'), data.hostname },
{ _('MAC address'), data.mac_address },
{ _('Hardware model'), data.hardware_model },
{ _('Gluon version') .. " / " .. _('Site version'), data.gluon_version .. " / " .. data.site_version },
{ _('Firmware release'), data.firmware_release },
{ _('Site'), data.site },
{ _('Domain'), data.domain or 'n/a' },
{ _('Public VPN key'), data.public_vpn_key or 'n/a' },
{ _('Switch type'), data.switch_type },
}
end
return M
<%- <%-
local uci = require('simple-uci').cursor() local info = require 'gluon.info'
local pretty_hostname = require 'pretty_hostname'
local site = require 'gluon.site' local values = info.get_info_pretty(translate)
local sysconfig = require 'gluon.sysconfig'
local platform = require 'gluon.platform'
local util = require "gluon.util"
local has_vpn, vpn = pcall(require, 'gluon.mesh-vpn')
local _ = translate
local pubkey
if has_vpn and vpn.enabled() then
local _, active_vpn = vpn.get_active_provider()
if active_vpn ~= nil then
pubkey = active_vpn.public_key()
end
end
local values = {
{ _('Hostname'), pretty_hostname.get(uci) },
{ _('MAC address'), sysconfig.primary_mac },
{ _('Hardware model'), platform.get_model() },
{ _('Gluon version') .. " / " .. _('Site version'), util.trim(util.readfile('/lib/gluon/gluon-version'))
.. " / " .. util.trim(util.readfile('/lib/gluon/site-version')) },
{ _('Firmware release'), util.trim(util.readfile('/lib/gluon/release')) },
{ _('Site'), site.site_name() },
{ _('Public VPN key'), pubkey },
}
-%> -%>
<h2><%:Information%></h2> <h2><%:Information%></h2>
<% for _, v in ipairs(values) do %> <% for _, v in ipairs(values) do %>
......
...@@ -77,6 +77,12 @@ msgstr "Passwort gelöscht." ...@@ -77,6 +77,12 @@ msgstr "Passwort gelöscht."
msgid "Public VPN key" msgid "Public VPN key"
msgstr "Öffentlicher VPN-Schlüssel" msgstr "Öffentlicher VPN-Schlüssel"
msgid "Domain"
msgstr "Domäne"
msgid "Switch type"
msgstr "Switch Typ"
msgid "Remote access" msgid "Remote access"
msgstr "Remotezugriff" msgstr "Remotezugriff"
......
...@@ -64,6 +64,12 @@ msgstr "" ...@@ -64,6 +64,12 @@ msgstr ""
msgid "Public VPN key" msgid "Public VPN key"
msgstr "" msgstr ""
msgid "Domain"
msgstr ""
msgid "Switch type"
msgstr ""
msgid "Remote access" msgid "Remote access"
msgstr "" msgstr ""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment