This commit is contained in:
Tata 2018-08-16 22:16:32 +00:00 committed by GitHub
commit 4d378ddf01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 433 additions and 144 deletions

View File

@ -58,6 +58,7 @@ Several Freifunk communities in Germany use Gluon as the foundation of their Fre
package/gluon-client-bridge
package/gluon-config-mode-domain-select
package/gluon-config-mode-geo-location
package/gluon-ebtables-filter-multicast
package/gluon-ebtables-filter-ra-dhcp
package/gluon-ebtables-limit-arp

View File

@ -0,0 +1,72 @@
gluon-config-mode-geo-location
==============================
This package allows the user to set latitude, longitude and optionally altitude
to be advertised from within the config mode. There are two types of this
package:
It is possible to include **either** ``gluon-config-mode-geo-location`` **or**
``gluon-config-mode-geo-location-with-map`` in the ``site.mk``.
If you want to use ``gluon-config-mode-geo-location-with-map`` together with
the GLUON_FEATURE ``web-wizard`` then you have to exclude
``gluon-config-mode-geo-location``, i.e.:
GLUON_SITE_PACKAGES += \
-gluon-config-mode-geo-location \
gluon-config-mode-geo-location-with-map
gluon-config-mode-geo-location-with-map
---------------------------------------
This package enhances the config mode by providing users a map that can be used
to pick a position. The map requires an internet connection on the users
computer and will be hidden if there is none.
site.conf
^^^^^^^^^
This option is valid for both ``gluon-config-mode-geo-location`` and
``gluon-config-mode-geo-location-with-map``:
config_mode.geo_location.show_altitude \: optional
- ``true`` the altitude section in config mode is shown
- ``false`` the altitude section in config mode is hidden
- defaults to ``false``
The remaining options are only valid for the
``gluon-config-mode-geo-location-with-map`` package:
config_mode.geo_location.map.lon \: optional
- represents the default longitude value to use for the center of the map.
- defaults to ``0.0``
config_mode.geo_location.map.lat \: optional
- represents the default latitude value to use for the center of the map.
- defaults to ``0.0``
The map will center to the position defined in **lat** and **lon**, unless a
location was already defined. The new defined location will become the
new center.
config_mode.geo_location.map.zoom \: optional
- Natural number between ``0-17`` for the zoom level of the map.
- defaults to ``12``
config_mode.geo_location.map.openlayers_js_url \: optional
- ``url`` set an URL for OpenStreetMap layers.
- defaults to ``https://openlayers.org/api/OpenLayers.js``
Example::
config_mode = {
geo_location = {
map = {
lon = 52.951947558,
lat = 7.844238281,
zoom = 12,
openlayers_js_url = 'http://osm.ffnw.de/.static/ol/OpenLayers.js',
},
show_altitude = true,
},
},

View File

@ -6,8 +6,82 @@ PKG_VERSION:=1
include ../gluon.mk
define Package/gluon-config-mode-geo-location
TITLE:=Set geographic location of a node
TITLE:=Set geographic location of a node and share it.
CONFLICTS:=+gluon-config-mode-geo-location-with-map
DEPENDS:=+gluon-config-mode-core +gluon-node-info
endef
define Package/gluon-config-mode-geo-location-with-map
TITLE:=Set geographic location of a node and share it, additionally show a map if internet is available.
CONFLICTS:=+gluon-config-mode-geo-location
DEPENDS:=+gluon-config-mode-core +gluon-node-info +gluon-web-osm
endef
define Build/Configure
$(CP) ./src/* $(PKG_BUILD_DIR)/
$(INSTALL_DIR) $(PKG_BUILD_DIR)/gluon-config-mode-geo-location{,-with-map}/{luasrc/lib/gluon/config-mode/wizard/,i18n/}
endef
define GluonBuildI18N
mkdir -p $(1)
for lang in $$(GLUON_ENABLED_LANGS); do \
if [ -e $(1)/$$$$lang.po ]; then \
rm -f $(1)/$$$$lang.lmo; \
po2lmo $(1)/$$$$lang.po $(1)/$$$$lang.lmo; \
fi; \
done
endef
define GluonInstallI18N
$(INSTALL_DIR) $(1)/lib/gluon/web/i18n
for lang in $$(GLUON_ENABLED_LANGS); do \
if [ -e $(2)/i18n/$$$$lang.lmo ]; then \
$(INSTALL_DATA) $(2)/i18n/$$$$lang.lmo $(1)/lib/gluon/web/i18n/$(PKG_NAME).$$$$lang.lmo; \
fi; \
done
endef
define Build/Compile
$(CC) -E -x c -P $(PKG_BUILD_DIR)/0400-geo-location.lua.in -o $(PKG_BUILD_DIR)/gluon-config-mode-geo-location/luasrc/lib/gluon/config-mode/wizard/0400-geo-location.lua
$(CC) -E -x c -P $(PKG_BUILD_DIR)/gluon-config-mode-geo-location.pot.in -o $(PKG_BUILD_DIR)/gluon-config-mode-geo-location/i18n/gluon-config-mode-geo-location.pot
$(CC) -E -x c -P $(PKG_BUILD_DIR)/check_site.lua.in -o $(PKG_BUILD_DIR)/gluon-config-mode-geo-location/check_site.lua
$(CC) -E -x c -P $(PKG_BUILD_DIR)/de.po.in -o $(PKG_BUILD_DIR)/gluon-config-mode-geo-location/i18n/de.po
$(CC) -E -x c -P $(PKG_BUILD_DIR)/fr.po.in -o $(PKG_BUILD_DIR)/gluon-config-mode-geo-location/i18n/fr.po
$(call GluonSrcDiet,$(PKG_BUILD_DIR)/gluon-config-mode-geo-location/luasrc,$(PKG_BUILD_DIR)/gluon-config-mode-geo-location/luadest/)
$(call GluonBuildI18N,$(PKG_BUILD_DIR)/gluon-config-mode-geo-location/i18n)
$(CC) -DWITHMAP -E -x c -P $(PKG_BUILD_DIR)/0400-geo-location.lua.in -o $(PKG_BUILD_DIR)/gluon-config-mode-geo-location-with-map/luasrc/lib/gluon/config-mode/wizard/0400-geo-location.lua
$(CC) -DWITHMAP -E -x c -P $(PKG_BUILD_DIR)/gluon-config-mode-geo-location.pot.in -o $(PKG_BUILD_DIR)/gluon-config-mode-geo-location-with-map/i18n/gluon-config-mode-geo-location-with-map.pot
$(CC) -DWITHMAP -E -x c -P $(PKG_BUILD_DIR)/check_site.lua.in -o $(PKG_BUILD_DIR)/gluon-config-mode-geo-location-with-map/check_site.lua
$(CC) -DWITHMAP -E -x c -P $(PKG_BUILD_DIR)/de.po.in -o $(PKG_BUILD_DIR)/gluon-config-mode-geo-location-with-map/i18n/de.po
$(CC) -DWITHMAP -E -x c -P $(PKG_BUILD_DIR)/fr.po.in -o $(PKG_BUILD_DIR)/gluon-config-mode-geo-location-with-map/i18n/fr.po
$(call GluonSrcDiet,$(PKG_BUILD_DIR)/gluon-config-mode-geo-location-with-map/luasrc,$(PKG_BUILD_DIR)/gluon-config-mode-geo-location-with-map/luadest/)
$(call GluonBuildI18N,$(PKG_BUILD_DIR)/gluon-config-mode-geo-location-with-map/i18n)
endef
define Package/gluon-config-mode-geo-location/install
$(CP) $(PKG_BUILD_DIR)/gluon-config-mode-geo-location/luadest/* $(1)/
$(call GluonInstallI18N,$(1),$(PKG_BUILD_DIR)/gluon-config-mode-geo-location)
endef
define Package/gluon-config-mode-geo-location-with-map/install
$(CP) $(PKG_BUILD_DIR)/gluon-config-mode-geo-location-with-map/luadest/* $(1)/
$(INSTALL_DIR) $(1)/lib/gluon/config-mode/www/static/
$(LN) /lib/gluon/web/www/static/osm.js $(1)/lib/gluon/config-mode/www/static/osm.js
$(call GluonInstallI18N,$(1),$(PKG_BUILD_DIR)/gluon-config-mode-geo-location-with-map)
endef
define Package/gluon-config-mode-geo-location/postinst
#!/bin/sh
$(call GluonCheckSite,$(PKG_BUILD_DIR)/gluon-config-mode-geo-location/check_site.lua)
endef
define Package/gluon-config-mode-geo-location-with-map/postinst
#!/bin/sh
$(call GluonCheckSite,$(PKG_BUILD_DIR)/gluon-config-mode-geo-location-with-map/check_site.lua)
endef
$(eval $(call BuildPackageGluon,gluon-config-mode-geo-location))
$(eval $(call BuildPackageGluon,gluon-config-mode-geo-location-with-map))

View File

@ -1 +0,0 @@
need_boolean(in_site({'config_mode', 'geo_location', 'show_altitude'}), false)

View File

@ -1,30 +0,0 @@
msgid ""
msgstr ""
"Project-Id-Version: gluon-config-mode-geo-location\n"
"PO-Revision-Date: 2015-03-23 02:18+0100\n"
"Last-Translator: Martin Weinelt <martin@darmstadt.freifunk.net>\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 ""
"If you want the location of your node to be displayed on the map, you can "
"enter its coordinates here."
msgstr ""
"Um deinen Knoten auf der Karte anzeigen zu können, benötigen wir seine "
"Koordinaten. Hier hast du die Möglichkeit, diese zu hinterlegen."
msgid "Latitude"
msgstr "Breitengrad"
msgid "Longitude"
msgstr "Längengrad"
msgid "Show node on the map"
msgstr "Knoten auf der Karte anzeigen"
msgid "e.g. %s"
msgstr "z.B. %s"

View File

@ -1,30 +0,0 @@
msgid ""
msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Project-Id-Version: PACKAGE VERSION\n"
"PO-Revision-Date: 2015-08-12 23:30+0100\n"
"Last-Translator:Tobias Bernot <tqbs@airmail.cc>\n"
"Language-Team: French\n"
"Language: fr\n"
"MIME-Version: 1.0\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
msgid ""
"If you want the location of your node to be displayed on the map, you can "
"enter its coordinates here."
msgstr ""
"Pour Afficher votre nœud sur la Carte nous avons besoin de ses coordonnées. "
"Ici vous pouvez entrer sa position."
msgid "Latitude"
msgstr "Latitude"
msgid "Longitude"
msgstr "Longitude"
msgid "Show node on the map"
msgstr "Afficher le nœud sur la carte"
msgid "e.g. %s"
msgstr "Ex: %s"

View File

@ -1,19 +0,0 @@
msgid ""
msgstr "Content-Type: text/plain; charset=UTF-8"
msgid ""
"If you want the location of your node to be displayed on the map, you can "
"enter its coordinates here."
msgstr ""
msgid "Latitude"
msgstr ""
msgid "Longitude"
msgstr ""
msgid "Show node on the map"
msgstr ""
msgid "e.g. %s"
msgstr ""

View File

@ -1,63 +0,0 @@
return function(form, uci)
local pkg_i18n = i18n 'gluon-config-mode-geo-location'
local site_i18n = i18n 'gluon-site'
local site = require 'gluon.site'
local location = uci:get_first("gluon-node-info", "location")
local function show_altitude()
if site.config_mode.geo_location.show_altitude(true) then
return true
end
return uci:get_bool("gluon-node-info", location, "altitude")
end
local text = site_i18n._translate("gluon-config-mode:geo-location-help") or pkg_i18n.translate(
'If you want the location of your node to ' ..
'be displayed on the map, you can enter its coordinates here.'
)
if show_altitude() then
text = text .. ' ' .. site_i18n.translate("gluon-config-mode:altitude-help")
end
local s = form:section(Section, nil, text)
local o
local share_location = s:option(Flag, "location", pkg_i18n.translate("Show node on the map"))
share_location.default = uci:get_bool("gluon-node-info", location, "share_location")
function share_location:write(data)
uci:set("gluon-node-info", location, "share_location", data)
end
o = s:option(Value, "latitude", pkg_i18n.translate("Latitude"), pkg_i18n.translatef("e.g. %s", "53.873621"))
o.default = uci:get("gluon-node-info", location, "latitude")
o:depends(share_location, true)
o.datatype = "float"
function o:write(data)
uci:set("gluon-node-info", location, "latitude", data)
end
o = s:option(Value, "longitude", pkg_i18n.translate("Longitude"), pkg_i18n.translatef("e.g. %s", "10.689901"))
o.default = uci:get("gluon-node-info", location, "longitude")
o:depends(share_location, true)
o.datatype = "float"
function o:write(data)
uci:set("gluon-node-info", location, "longitude", data)
end
if show_altitude() then
o = s:option(Value, "altitude", site_i18n.translate("gluon-config-mode:altitude-label"), pkg_i18n.translatef("e.g. %s", "11.51"))
o.default = uci:get("gluon-node-info", location, "altitude")
o:depends(share_location, true)
o.datatype = "float"
o.optional = true
function o:write(data)
uci:set("gluon-node-info", location, "altitude", data)
end
end
return {'gluon-node-info'}
end

View File

@ -0,0 +1,142 @@
return function(form, uci)
local pkg_i18n = i18n 'gluon-config-mode-geo-location'
local site_i18n = i18n 'gluon-site'
local site = require 'gluon.site'
local location = uci:get_first("gluon-node-info", "location")
local uci_latitude = uci:get("gluon-node-info", location, "latitude")
local uci_longitude = uci:get("gluon-node-info", location, "longitude")
#ifdef WITHMAP
local function show_lon()
if uci_longitude ~= nil then
return uci_longitude
end
return site.config_mode.geo_location.map.lon(0)
end
local function show_lat()
if uci_latitude ~= nil then
return uci_latitude
end
return site.config_mode.geo_location.map.lat(0)
end
local function site_zoom()
if uci_longitude ~= nil and uci_latitude ~= nil then
return 18
end
return site.config_mode.geo_location.map.zoom(12)
end
local function show_olurl()
return site.config_mode.geo_location.map.openlayers_js_url('https://openlayers.org/api/OpenLayers.js')
end
#endif
-- show altitude if site.json returns true or nil and uci an value. Don't show if site.json returns false or uci nil!
local function show_altitude()
return site.config_mode.geo_location.show_altitude(uci:get("gluon-node-info", location, "altitude") ~= nil)
end
local text = site_i18n._translate("gluon-config-mode:geo-location-help") or pkg_i18n.translate(
'If you want the location of your node to be displayed on the map, you may ' ..
'enter its coordinates here. ' ..
#ifdef WITHMAP
'If your PC is connected to the internet you may also select your position on the map displayed below. ' ..
#endif
'Please keep in mind setting a location can also enhance the network quality.'
)
if show_altitude() then
text = text .. ' ' .. site_i18n.translate("gluon-config-mode:altitude-help")
end
#ifdef WITHMAP
text = text .. [[
</div>
<div id="locationPickerMap" style="position:relative; width:100%; height:400px; margin-bottom:20px !important; display:none; border:1px solid #ccc">
<div target="_blank" style="position:absolute; left:5px; bottom:5px; z-index:1000; color:#aaa; outline: 0">
© <a href="https://openstreetmap.org/copyright">OpenStreetMap</a> contributors
</div>
</div>
<script type="text/javascript" src="/static/osm.js"></script>
<script type="text/javascript">
var latitude=]] .. show_lon() .. ",longitude=" .. show_lat() .. ",zoom=" .. site_zoom() .. [[;
var openLayerSrc = document.createElement("script");
openLayerSrc.type = 'text/javascript';
openLayerSrc.src = "]] .. show_olurl() .. [[?noCache=]] .. os.time() .. [[";
openLayerSrc.onload = openLayerSrc.onreadystatechange = function () {
window.addEventListener("load", showMap, false);
var lpm=document.getElementById("locationPickerMap");
setInterval(function() {
!1 !== findObj("longitude") ? lpm.style.display = "block" : lpm.style.display = "none";
}, 100);
};
document.head.appendChild(openLayerSrc);
</script>
<div>
]]
#endif
local s = form:section(Section, nil, text)
local uci_share_location = uci:get_bool("gluon-node-info", location, "share_location")
local geolocation = s:option(ListValue, "geolocation", pkg_i18n.translate("Geo-Location"))
geolocation:value("static", pkg_i18n.translate("Static location"))
geolocation:value("none", pkg_i18n.translate("Disabled"))
if uci_latitude == nil and uci_longitude == nil and uci_share_location == false then
geolocation.default = "none"
else
geolocation.default = "static"
end
local share_location = s:option(Flag, "sharelocation", pkg_i18n.translate("Share your location to see your router on the map"))
share_location.default = uci_share_location
share_location:depends(geolocation, "static")
local latitude = s:option(Value, "latitude", pkg_i18n.translate("Latitude"), pkg_i18n.translatef("e.g. %s", "50.364931"))
latitude.default = uci_latitude
latitude:depends(geolocation, "static")
latitude.datatype = "float"
local longitude = s:option(Value, "longitude", pkg_i18n.translate("Longitude"), pkg_i18n.translatef("e.g. %s", "7.606417"))
longitude.default = uci_longitude
longitude:depends(geolocation, "static")
longitude.datatype = "float"
local altitude;
if show_altitude() then
altitude = s:option(Value, "altitude", site_i18n.translate("gluon-config-mode:altitude-label"), pkg_i18n.translatef("e.g. %s", "11.51"))
altitude.default = uci:get("gluon-node-info", location, "altitude")
altitude:depends(geolocation, "static")
altitude.datatype = "float"
altitude.optional = true
end
function geolocation:write(data)
if data == "static" then
uci:set("gluon-node-info", location, "latitude", latitude.data)
uci:set("gluon-node-info", location, "longitude", longitude.data)
if show_altitude() then
uci:set("gluon-node-info", location, "altitude", altitude.data)
end
end
if data == "none" then
uci:delete("gluon-node-info", location, "altitude")
uci:delete("gluon-node-info", location, "latitude")
uci:delete("gluon-node-info", location, "longitude")
end
uci:set("gluon-node-info", location, "share_location", share_location.data)
end
return {'gluon-node-info'}
end

View File

@ -0,0 +1,7 @@
need_boolean(in_site({'config_mode', 'geo_location', 'show_altitude'}), false)
#ifdef WITHMAP
need_string(in_site({'config_mode', 'geo_location', 'map', 'openlayers_js_url'}), false)
need_number(in_site({'config_mode', 'geo_location', 'map', 'lon'}), false)
need_number(in_site({'config_mode', 'geo_location', 'map', 'lat'}), false)
need_number(in_site({'config_mode', 'geo_location', 'map', 'zoom'}), false)
#endif

View File

@ -0,0 +1,53 @@
msgid ""
msgstr ""
#ifdef WITHMAP
"Project-Id-Version: gluon-config-mode-geo-location-with-map\n"
#else
"Project-Id-Version: gluon-config-mode-geo-location\n"
#endif
"PO-Revision-Date: 2017-08-22 12:14+0100\n"
"Last-Translator: Jan-Tarek Butt <tarek@ring0.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"
\n
msgid ""
"If you want the location of your node to be displayed on the map, you may "
"enter its coordinates here. "
#ifdef WITHMAP
"If your PC is connected to the internet you may also select your position on the map displayed below. "
#endif
"Please keep in mind setting a location can also enhance the network quality."
msgstr ""
"Um deinen Router auf der Karte anzeigen zu können, benötigen wir seine "
"Koordinaten. Hier hast du die Möglichkeit, "
"die Koordinaten von Hand einzutragen."
#ifdef WITHMAP
"Wenn dein Computer mit dem du den Router einrichtest eine Internetverbindung hat, "
"hast du die Möglichkeit die Position des Routers auf der Karte auszuwählen."
#endif
"Bitte berücksichtige, dass das Setzen einer Position die Netzwerkqualität verbessern kann."
\n
msgid "Geo-Location"
msgstr "Geo-Position"
\n
msgid "Static location"
msgstr "Manuelle Position"
\n
msgid "Disabled"
msgstr "Deaktiviert"
\n
msgid "Share your location to see your router on the map"
msgstr "Position für die Karte freigeben"
\n
msgid "Latitude"
msgstr "Breitengrad"
\n
msgid "Longitude"
msgstr "Längengrad"
\n
msgid "e.g. %s"
msgstr "z.B. %s"

View File

@ -0,0 +1,51 @@
msgid ""
msgstr ""
#ifdef WITHMAP
"Project-Id-Version: gluon-config-mode-geo-location-with-map\n"
#else
"Project-Id-Version: gluon-config-mode-geo-location\n"
#endif
"PO-Revision-Date: 2017-08-22 12:14+0100\n"
"Last-Translator: Jan-Tarek Butt <tarek@ring0.de>\n"
"Language-Team: French\n"
"Language: fr\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"
\n
msgid ""
"If you want the location of your node to be displayed on the map, you may "
"enter its coordinates here. "
#ifdef WITHMAP
"If your PC is connected to the internet you may also select your position on the map displayed below. "
#endif
"Please keep in mind setting a location can also enhance the network quality."
msgstr ""
"Si vous souhaitez que l'emplacement de votre nœud soit affiché sur la carte, vous pouvez "
"entrer ses coordonnées ici."
#ifdef WITHMAP
"Si votre PC est connecté à Internet, vous pouvez également cliquer sur la carte ci-dessous."
#endif
"Gardez à l'esprit que la définition d'un emplacement peut également améliorer la qualité du réseau."
\n
msgid "Geo-Location"
msgstr "Géolocalisation"
\n
msgid "Static location"
msgstr "position manuelle"
\n
msgid "Disabled"
msgstr "Désactivé"
\n
msgid "Share your location to see your router on the map"
msgstr "Partagez votre emplacement pour voir votre routeur sur la carte"
\n
msgid "Latitude"
msgstr "Latitude"
\n
msgid "Longitude"
msgstr "Longitude"
\n
msgid "e.g. %s"
msgstr "Ex: %s"

View File

@ -0,0 +1,32 @@
msgid ""
msgstr "Content-Type: text/plain; charset=UTF-8"
\n
msgid ""
"If you want the location of your node to be displayed on the map, you may "
"enter its coordinates here. "
#ifdef WITHMAP
"If your PC is connected to the internet you may also select your position on the map displayed below. "
#endif
"Please keep in mind setting a location can also enhance the network quality."
msgstr ""
\n
msgid "Geo-Location"
msgstr ""
\n
msgid "Static location"
msgstr ""
\n
msgid "Disabled"
msgstr ""
\n
msgid "Share your location to see your router on the map"
msgstr ""
\n
msgid "Latitude"
msgstr ""
\n
msgid "Longitude"
msgstr ""
\n
msgid "e.g. %s"
msgstr ""