diff --git a/package/gluon-config-mode-core/Makefile b/package/gluon-config-mode-core/Makefile index c55ebedd80f9a2461df609cd0394dac8c1d65909..52a4f0e13d5fba9973579fc268bcc40a254b45c6 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 43c96340499f436f49c1f6e7669bbae4cdb8b5dc..0a6a54950f57682af33f9847e99910247c8fa696 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 cf8bbf89188a923d834e2e8c35769c56dc2a0d5d..2ffde723701fba05a81147b24f282a0cd7bc21d0 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 da1f640728b66c350e908de2d900528685163187..993ff295597c22bae22929b46caa0086499e73f6 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 10c4dd31331b935dc09fba2bf74a851232e47200..2b9cfb47f19bdf241568df97d076f289e545ad20 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 0086a5dca3ba9b3a0822eece2157bb8a0dd6467f..90ad1ba5e1ddd3f31c05bd51e7bfa1fb8e79b453 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 8c3d8154967aeaa703f0a131d6cd1daf498ff3fa..7b5f632a310607cc4d461d8d525034b75fc6d049 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 3fd4fec015c09fa236ec19a4e2ef60455a8a4178..03f3f2cab135e79bea9d985133e6ca26b6532c3f 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 72c92edd1dcc450e425585f5c8288729ca56f4e0..6e65db3c7ae3b925167c4959bd10e383a5febeb2 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 68d114b5ce0502b92a991e459805f0d63d09cfb9..7e8946035f131eae35bf2da5f0f3795c1c35556e 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 85c718e2326416286f168319ec3afca4a919f940..c6cc71e4f7cbd13d0c25d3f9d42b3fbac2dd386b 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 eddbe260dd2ae623be859b105c17253b6d6f4ef7..f26b59a218392192961e04014d71ee2026072aa5 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 be3c9a7a0a68638ee58322892f56574dc4a47d6e..2b7a18f9323822111b92a077505dbf5a8de8f8b0 100644 --- a/package/gluon-respondd/src/respondd.c +++ b/package/gluon-respondd/src/respondd.c @@ -29,12 +29,12 @@ #include <json-c/json.h> #include <libgluonutil.h> #include <libplatforminfo.h> +#include <uci.h> #include <stdio.h> #include <string.h> #include <unistd.h> -#include <sys/utsname.h> #include <sys/vfs.h> @@ -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; + + 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"); - return gluonutil_wrap_string(utsname.nodename); + 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) {