diff --git a/package/gluon-config-mode-core/Makefile b/package/gluon-config-mode-core/Makefile index c55ebedd..52a4f0e1 100644 --- a/package/gluon-config-mode-core/Makefile +++ b/package/gluon-config-mode-core/Makefile @@ -17,7 +17,7 @@ define Package/gluon-config-mode-core SECTION:=gluon CATEGORY:=Gluon TITLE:=Luci based config mode for user friendly setup of new mesh nodes - DEPENDS:=gluon-setup-mode-virtual +gluon-luci-theme +gluon-lock-password $(GLUON_I18N_PACKAGES) + DEPENDS:=gluon-setup-mode-virtual +gluon-luci-theme +gluon-lock-password +pretty-hostname $(GLUON_I18N_PACKAGES) PROVIDES:=gluon-config-mode-core-virtual endef diff --git a/package/gluon-config-mode-core/luasrc/usr/lib/lua/luci/controller/gluon-config-mode/index.lua b/package/gluon-config-mode-core/luasrc/usr/lib/lua/luci/controller/gluon-config-mode/index.lua index 43c96340..0a6a5495 100644 --- a/package/gluon-config-mode-core/luasrc/usr/lib/lua/luci/controller/gluon-config-mode/index.lua +++ b/package/gluon-config-mode-core/luasrc/usr/lib/lua/luci/controller/gluon-config-mode/index.lua @@ -51,6 +51,7 @@ function action_reboot() 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)) @@ -68,7 +69,7 @@ function action_reboot() end end - local hostname = uci:get_first("system", "system", "hostname") + local hostname = pretty_hostname.get(uci) luci.template.render("gluon/config-mode/reboot", { diff --git a/package/gluon-config-mode-hostname/luasrc/lib/gluon/config-mode/wizard/0100-hostname.lua b/package/gluon-config-mode-hostname/luasrc/lib/gluon/config-mode/wizard/0100-hostname.lua index cf8bbf89..2ffde723 100644 --- a/package/gluon-config-mode-hostname/luasrc/lib/gluon/config-mode/wizard/0100-hostname.lua +++ b/package/gluon-config-mode-hostname/luasrc/lib/gluon/config-mode/wizard/0100-hostname.lua @@ -1,5 +1,6 @@ local cbi = require "luci.cbi" local i18n = require "luci.i18n" +local pretty_hostname = require "pretty_hostname" local uci = luci.model.uci.cursor() local M = {} @@ -7,14 +8,12 @@ local M = {} function M.section(form) local s = form:section(cbi.SimpleSection, nil, nil) local o = s:option(cbi.Value, "_hostname", i18n.translate("Node name")) - o.value = uci:get_first("system", "system", "hostname") + o.value = pretty_hostname.get(uci) o.rmempty = false - o.datatype = "hostname" end function M.handle(data) - uci:set("system", uci:get_first("system", "system"), "hostname", data._hostname) - uci:save("system") + pretty_hostname.set(uci, data._hostname) uci:commit("system") end diff --git a/package/gluon-config-mode-mesh-vpn/luasrc/lib/gluon/config-mode/reboot/0100-mesh-vpn.lua b/package/gluon-config-mode-mesh-vpn/luasrc/lib/gluon/config-mode/reboot/0100-mesh-vpn.lua index da1f6407..993ff295 100644 --- a/package/gluon-config-mode-mesh-vpn/luasrc/lib/gluon/config-mode/reboot/0100-mesh-vpn.lua +++ b/package/gluon-config-mode-mesh-vpn/luasrc/lib/gluon/config-mode/reboot/0100-mesh-vpn.lua @@ -11,8 +11,10 @@ else local site = require 'gluon.site_config' local sysconfig = require 'gluon.sysconfig' + local pretty_hostname = require 'pretty_hostname' + local pubkey = util.trim(util.exec("/etc/init.d/fastd show_key " .. "mesh_vpn")) - local hostname = uci:get_first("system", "system", "hostname") + local hostname = pretty_hostname.get(uci) local contact = uci:get_first("gluon-node-info", "owner", "contact") local msg = i18n.translate('gluon-config-mode:pubkey') diff --git a/package/gluon-core/Makefile b/package/gluon-core/Makefile index 10c4dd31..2b9cfb47 100644 --- a/package/gluon-core/Makefile +++ b/package/gluon-core/Makefile @@ -13,7 +13,7 @@ define Package/gluon-core SECTION:=gluon CATEGORY:=Gluon TITLE:=Base files of Gluon - DEPENDS:=+gluon-site +libgluonutil +lua-platform-info +lua-hash +luci-base +luci-lib-jsonc +odhcp6c +firewall + DEPENDS:=+gluon-site +libgluonutil +lua-platform-info +lua-hash +luci-base +luci-lib-jsonc +odhcp6c +firewall +pretty-hostname endef define Package/gluon-core/description diff --git a/package/gluon-core/luasrc/lib/gluon/upgrade/030-system b/package/gluon-core/luasrc/lib/gluon/upgrade/030-system index 0086a5dc..90ad1ba5 100755 --- a/package/gluon-core/luasrc/lib/gluon/upgrade/030-system +++ b/package/gluon-core/luasrc/lib/gluon/upgrade/030-system @@ -1,5 +1,6 @@ #!/usr/bin/lua +local pretty_hostname = require 'pretty_hostname' local sysconfig = require 'gluon.sysconfig' -- Initial @@ -10,7 +11,7 @@ if not sysconfig.gluon_version then local system = uci:get_first('system', 'system') - uci:set('system', system, 'hostname', (site.hostname_prefix or '') .. util.node_id()) + pretty_hostname.set(uci, (site.hostname_prefix or '') .. util.node_id()) uci:set('system', system, 'timezone', site.timezone) uci:save('system') diff --git a/package/gluon-luci-admin/Makefile b/package/gluon-luci-admin/Makefile index 8c3d8154..7b5f632a 100644 --- a/package/gluon-luci-admin/Makefile +++ b/package/gluon-luci-admin/Makefile @@ -18,7 +18,7 @@ define Package/gluon-luci-admin SECTION:=gluon CATEGORY:=Gluon TITLE:=Luci based simple administration interface for mesh nodes - DEPENDS:=gluon-config-mode-core-virtual + DEPENDS:=gluon-config-mode-core-virtual +pretty-hostname endef define Build/Prepare diff --git a/package/gluon-luci-admin/files/usr/lib/lua/luci/view/admin/info.htm b/package/gluon-luci-admin/files/usr/lib/lua/luci/view/admin/info.htm index 3fd4fec0..03f3f2ca 100644 --- a/package/gluon-luci-admin/files/usr/lib/lua/luci/view/admin/info.htm +++ b/package/gluon-luci-admin/files/usr/lib/lua/luci/view/admin/info.htm @@ -3,6 +3,7 @@ local uci = require('luci.model.uci').cursor() local util = require 'luci.util' local i18n = require 'luci.i18n' + local pretty_hostname = require 'pretty_hostname' local gluon_luci = require "gluon.luci" local site = require 'gluon.site_config' @@ -21,7 +22,7 @@ } local values = { - hostname = uci:get_first('system', 'system', 'hostname'), + hostname = pretty_hostname.get(uci), primary_mac = sysconfig.primary_mac, model = platform.get_model(), version = util.trim(fs.readfile('/lib/gluon/gluon-version')), diff --git a/package/gluon-luci-theme/Makefile b/package/gluon-luci-theme/Makefile index 72c92edd..6e65db3c 100644 --- a/package/gluon-luci-theme/Makefile +++ b/package/gluon-luci-theme/Makefile @@ -16,7 +16,7 @@ define Package/gluon-luci-theme SECTION:=gluon CATEGORY:=Gluon TITLE:=Luci theme for Gluon - DEPENDS:= + DEPENDS:=+pretty-hostname endef define Package/gluon-luci-theme/description diff --git a/package/gluon-luci-theme/files/usr/lib/lua/luci/view/themes/gluon/header.htm b/package/gluon-luci-theme/files/usr/lib/lua/luci/view/themes/gluon/header.htm index 68d114b5..7e894603 100644 --- a/package/gluon-luci-theme/files/usr/lib/lua/luci/view/themes/gluon/header.htm +++ b/package/gluon-luci-theme/files/usr/lib/lua/luci/view/themes/gluon/header.htm @@ -16,10 +16,12 @@ $Id$ local sys = require "luci.sys" local http = require "luci.http" local disp = require "luci.dispatcher" + local uci = require("luci.model.uci").cursor() local fs = require "nixio.fs" local gluon_luci = require "gluon.luci" + local pretty_hostname = require "pretty_hostname" - local hostname = sys.hostname() + local hostname = pretty_hostname.get(uci) local release = fs.readfile("/lib/gluon/release") local request = disp.context.path diff --git a/package/gluon-respondd/Makefile b/package/gluon-respondd/Makefile index 85c718e2..c6cc71e4 100644 --- a/package/gluon-respondd/Makefile +++ b/package/gluon-respondd/Makefile @@ -12,7 +12,7 @@ define Package/gluon-respondd SECTION:=gluon CATEGORY:=Gluon TITLE:=Provides node information to the network - DEPENDS:=+gluon-core +libplatforminfo +libgluonutil +respondd + DEPENDS:=+gluon-core +libplatforminfo +libgluonutil +libuci +respondd endef define Build/Prepare diff --git a/package/gluon-respondd/src/Makefile b/package/gluon-respondd/src/Makefile index eddbe260..f26b59a2 100644 --- a/package/gluon-respondd/src/Makefile +++ b/package/gluon-respondd/src/Makefile @@ -3,4 +3,4 @@ all: respondd.so CFLAGS += -Wall respondd.so: respondd.c - $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -shared -fPIC -D_GNU_SOURCE -o $@ $^ $(LDLIBS) -lgluonutil -lplatforminfo + $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -shared -fPIC -D_GNU_SOURCE -o $@ $^ $(LDLIBS) -lgluonutil -lplatforminfo -luci diff --git a/package/gluon-respondd/src/respondd.c b/package/gluon-respondd/src/respondd.c index be3c9a7a..2b7a18f9 100644 --- a/package/gluon-respondd/src/respondd.c +++ b/package/gluon-respondd/src/respondd.c @@ -29,12 +29,12 @@ #include #include #include +#include #include #include #include -#include #include @@ -67,12 +67,29 @@ static struct json_object * get_site_code(void) { } static struct json_object * get_hostname(void) { - struct utsname utsname; + struct json_object *ret = NULL; - if (uname(&utsname)) - return NULL; + struct uci_context *ctx = uci_alloc_context(); + ctx->flags &= ~UCI_FLAG_STRICT; - return gluonutil_wrap_string(utsname.nodename); + char section[] = "system.@system[0]"; + struct uci_ptr ptr; + if (uci_lookup_ptr(ctx, &ptr, section, true)) + goto error; + + struct uci_section *s = ptr.s; + + const char *hostname = uci_lookup_option_string(ctx, s, "pretty_hostname"); + + if (!hostname) + hostname = uci_lookup_option_string(ctx, s, "hostname"); + + ret = gluonutil_wrap_string(hostname); + +error: + uci_free_context(ctx); + + return ret; } static struct json_object * respondd_provider_nodeinfo(void) {