diff --git a/gluon-config-mode-zip/Makefile b/gluon-config-mode-zip/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..893afe3b8f9f5fa96f6de2a8a35df306f079a1c9 --- /dev/null +++ b/gluon-config-mode-zip/Makefile @@ -0,0 +1,43 @@ +include $(TOPDIR)/rules.mk + +PKG_NAME:=gluon-config-mode-plz +PKG_VERSION:=1 + +PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) +PKG_BUILD_DEPENDS := respondd + +include $(GLUONDIR)/include/package.mk + +PKG_CONFIG_DEPENDS += $(GLUON_I18N_CONFIG) + + +define Package/gluon-config-mode-zip + SECTION:=gluon + CATEGORY:=Gluon + TITLE:=Set ZIP-Code location of a node + DEPENDS:=gluon-config-mode-core-virtual +gluon-node-info +endef + +define Build/Prepare + mkdir -p $(PKG_BUILD_DIR) + $(CP) ./src/* $(PKG_BUILD_DIR)/ +endef + +define Build/Configure +endef + +define Build/Compile + $(call Build/Compile/Default) + $(call GluonBuildI18N,gluon-config-mode-zip,i18n) + $(call GluonSrcDiet,./luasrc,$(PKG_BUILD_DIR)/luadest/) +endef + +define Package/gluon-config-mode-zip/install + $(INSTALL_DIR) $(1)/lib/gluon/respondd + $(CP) $(PKG_BUILD_DIR)/respondd.so $(1)/lib/gluon/respondd/node-info-zip.so + + $(CP) $(PKG_BUILD_DIR)/luadest/* $(1)/ + $(call GluonInstallI18N,gluon-config-mode-zip,$(1)) +endef + +$(eval $(call BuildPackage,gluon-config-mode-zip)) diff --git a/gluon-config-mode-zip/i18n/de.po b/gluon-config-mode-zip/i18n/de.po new file mode 100644 index 0000000000000000000000000000000000000000..fe349327ba3279a79cf654ddcf73bba4ca9006ac --- /dev/null +++ b/gluon-config-mode-zip/i18n/de.po @@ -0,0 +1,24 @@ +msgid "" +msgstr "" +"Project-Id-Version: gluon-config-mode-zip\n" +"PO-Revision-Date: 2016-12-19 02:18+0100\n" +"Last-Translator: Philippe Käufer <freifunk@philhil.de>\n" +"Language-Team: German\n" +"Language: de\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +msgid "gluon-config-mode:zip-help" +"Some nice Text about the ZIP-Code " +"and how it help for subnetting." +msgstr "" +"Ein Netter Text warum die PLZ benötigt " +"wird." + +msgid "ZIP-Code" +msgstr "PLZ" + +msgid "e.g. %s" +msgstr "z.B. %s" diff --git a/gluon-config-mode-zip/i18n/gluon-config-mode-zip.pot b/gluon-config-mode-zip/i18n/gluon-config-mode-zip.pot new file mode 100644 index 0000000000000000000000000000000000000000..64d409fc25d674d06e906cb21fa0dafc047357e5 --- /dev/null +++ b/gluon-config-mode-zip/i18n/gluon-config-mode-zip.pot @@ -0,0 +1,13 @@ +msgid "" +msgstr "Content-Type: text/plain; charset=UTF-8" + +msgid "gluon-config-mode:zip-help" +"Some nice Text about the ZIP-Code " +"and how it help for subnetting." +msgstr "" + +msgid "ZIP-Code" +msgstr "" + +msgid "e.g. %s" +msgstr "" diff --git a/gluon-config-mode-zip/luasrc/lib/gluon/config-mode/wizard/0450-geo-location.lua b/gluon-config-mode-zip/luasrc/lib/gluon/config-mode/wizard/0450-geo-location.lua new file mode 100644 index 0000000000000000000000000000000000000000..3ce1e7df55cb5bc433fc9a40f6bc142e80401435 --- /dev/null +++ b/gluon-config-mode-zip/luasrc/lib/gluon/config-mode/wizard/0450-geo-location.lua @@ -0,0 +1,27 @@ +local cbi = require "luci.cbi" +local i18n = require "luci.i18n" +local uci = luci.model.uci.cursor() + +local M = {} + +function M.section(form) + local text = i18n.translate("gluon-config-mode:zip-help") + + local s = form:section(cbi.SimpleSection, nil, text) + + local o = s:option(cbi.Value, "_zip", "ZIP-Code") + o.value = uci:get_first("gluon-node-info", "location", "zip") + o.rmempty = false + o.datatype = "float" + o.description = i18n.translatef("e.g. %s", "70499") +end + +function M.handle(data) + local sname = uci:get_first("gluon-node-info", "location") + uci:set("gluon-node-info", sname, "zip", data._zip:trim()) + uci:save("gluon-node-info") + uci:commit("gluon-node-info") + +end + +return M diff --git a/gluon-config-mode-zip/src/Makefile b/gluon-config-mode-zip/src/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..3ddc8a5861d74e13d521fda69a845efa66d0090f --- /dev/null +++ b/gluon-config-mode-zip/src/Makefile @@ -0,0 +1,6 @@ +all: respondd.so + +CFLAGS += -Wall + +respondd.so: respondd.c + $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -shared -fPIC -D_GNU_SOURCE -o $@ $^ $(LDLIBS) -lgluonutil -luci diff --git a/gluon-config-mode-zip/src/respondd.c b/gluon-config-mode-zip/src/respondd.c new file mode 100644 index 0000000000000000000000000000000000000000..b9a7ea96e6b643d8078ec1ccb8d19a1c1a62cb09 --- /dev/null +++ b/gluon-config-mode-zip/src/respondd.c @@ -0,0 +1,104 @@ +/* + Copyright (c) 2016, Matthias Schiffer <mschiffer@universe-factory.net> and Philippe Käufer <freifunk@philhil.de> + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include <respondd.h> + +#include <json-c/json.h> +#include <libgluonutil.h> + +#include <uci.h> + +#include <stdlib.h> +#include <string.h> + + +static struct uci_section * get_first_section(struct uci_package *p, const char *type) { + struct uci_element *e; + uci_foreach_element(&p->sections, e) { + struct uci_section *s = uci_to_section(e); + if (!strcmp(s->type, type)) + return s; + } + + return NULL; +} + +static struct json_object * get_number(struct uci_context *ctx, struct uci_section *s, const char *name) { + const char *val = uci_lookup_option_string(ctx, s, name); + if (!val || !*val) + return NULL; + + char *end; + double d = strtod(val, &end); + if (*end) + return NULL; + + struct json_object *jso = json_object_new_double(d); + json_object_set_serializer(jso, json_object_double_to_json_string, "%.8f", NULL); + return jso; +} + +static void maybe_add_number(struct uci_context *ctx, struct uci_section *s, const char *name, struct json_object *parent) { + struct json_object *jso = get_number(ctx, s, name); + if (jso) + json_object_object_add(parent, name, jso); +} + +static struct json_object * get_location(struct uci_context *ctx, struct uci_package *p) { + struct uci_section *s = get_first_section(p, "location"); + if (!s) + return NULL; + + struct json_object *ret = json_object_new_object(); + + maybe_add_number(ctx, s, "zip", ret); + + return ret; +} + +static struct json_object * respondd_provider_nodeinfo_zip(void) { + struct json_object *ret = json_object_new_object(); + + struct uci_context *ctx = uci_alloc_context(); + ctx->flags &= ~UCI_FLAG_STRICT; + + struct uci_package *p; + if (!uci_load(ctx, "gluon-node-info", &p)) { + struct json_object *location = get_location(ctx, p); + if (location) + json_object_object_add(ret, "location", location); + } + + uci_free_context(ctx); + + return ret; +} + + +const struct respondd_provider_info respondd_providers[] = { + {"nodeinfo-zip", respondd_provider_nodeinfo_zip}, + {} +};