Skip to content
Snippets Groups Projects
Unverified Commit fdf823a3 authored by Matthias Schiffer's avatar Matthias Schiffer
Browse files

gluon-status-page-api: merge back into gluon-status-page

All Access-Control-Allow-Origin are removed to improve users' privacy. As
the status page API is thus not useful without the status page anymore,
merge them back into a single package.

The status-page-api respondd provider is removed as well.

Fixes #1194
parent 88906f23
No related branches found
No related tags found
No related merge requests found
Showing
with 44 additions and 155 deletions
include $(TOPDIR)/rules.mk
PKG_NAME:=gluon-status-page-api
PKG_VERSION:=1
PKG_RELEASE:=1
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
PKG_BUILD_DEPENDS := respondd
include ../gluon.mk
define Package/gluon-status-page-api
SECTION:=gluon
CATEGORY:=Gluon
TITLE:=API for gluon-status-page
DEPENDS:=+gluon-core +uhttpd +sse-multiplex +gluon-neighbour-info +gluon-respondd +libiwinfo +libjson-c +libnl-tiny +libubus-lua +libbatadv
endef
define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
$(CP) ./src/* $(PKG_BUILD_DIR)/
endef
define Build/Compile
$(call Build/Compile/Default)
$(call GluonSrcDiet,./luasrc,$(PKG_BUILD_DIR)/luadest/)
endef
define Package/gluon-status-page-api/install
$(INSTALL_DIR) $(1)/lib/gluon/status-page/providers
$(INSTALL_BIN) $(PKG_BUILD_DIR)/neighbours-batadv $(1)/lib/gluon/status-page/providers/
$(INSTALL_BIN) $(PKG_BUILD_DIR)/stations $(1)/lib/gluon/status-page/providers/
$(INSTALL_DIR) $(1)/lib/gluon/respondd
$(CP) $(PKG_BUILD_DIR)/respondd.so $(1)/lib/gluon/respondd/status-page-api.so
$(CP) ./files/* $(1)/
$(CP) $(PKG_BUILD_DIR)/luadest/* $(1)/
endef
$(eval $(call BuildPackage,gluon-status-page-api))
#!/bin/sh
cat <<EOF
Access-Control-Allow-Origin: *
Content-type: application/json
EOF
exec gluon-neighbour-info -d ::1 -p 1001 -t 1 -c 1 -r nodeinfo
#!/bin/sh
uci -q batch <<-EOF
delete uhttpd.main.listen_http
add_list uhttpd.main.listen_http=0.0.0.0:80
add_list uhttpd.main.listen_http=[::]:80
delete uhttpd.main.listen_https
set uhttpd.main.home=/lib/gluon/status-page/www
EOF
RAM=$(awk '/MemTotal/ {print $2}' /proc/meminfo)
if [ $RAM -lt $((48*1024)) ]; then
uci set uhttpd.main.max_requests=16
else
uci set uhttpd.main.max_requests=32
fi
#!/usr/bin/lua
util = require 'gluon.util'
fs = require 'nixio.fs'
json = require 'jsonc'
ubus = require 'ubus'
io.write("Access-Control-Allow-Origin: *\n")
io.write("Content-type: application/json\n\n")
local uconn = ubus.connect()
if not uconn then
error("Failed to connect to ubusd")
end
list = util.get_mesh_devices(uconn)
ubus.close(uconn)
interfaces = {}
for _,ifname in ipairs(list) do
pcall(function()
local address = util.trim(fs.readfile('/sys/class/net/' .. ifname .. '/address'))
interfaces[ifname] = { address = address }
end)
end
io.write(json.stringify(interfaces))
/*
Copyright (c) 2016, Matthias Schiffer <mschiffer@universe-factory.net>
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>
static struct json_object * respondd_provider_nodeinfo(void) {
struct json_object *ret = json_object_new_object();
struct json_object *software = json_object_new_object();
struct json_object *software_status_page = json_object_new_object();
json_object_object_add(software_status_page, "api", json_object_new_int(1));
json_object_object_add(software, "status-page", software_status_page);
json_object_object_add(ret, "software", software);
return ret;
}
const struct respondd_provider_info respondd_providers[] = {
{"nodeinfo", respondd_provider_nodeinfo},
{}
};
...@@ -12,19 +12,20 @@ define Package/gluon-status-page ...@@ -12,19 +12,20 @@ define Package/gluon-status-page
SECTION:=gluon SECTION:=gluon
CATEGORY:=Gluon CATEGORY:=Gluon
TITLE:=Status page showing information about the node TITLE:=Status page showing information about the node
DEPENDS:=+gluon-web +gluon-status-page-api DEPENDS:=+gluon-web +gluon-neighbour-info +gluon-respondd +uhttpd +sse-multiplex +libiwinfo +libjson-c +libnl-tiny +libbatadv
endef endef
define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
endef
define Build/Compile define Build/Compile
$(call Build/Compile/Default)
$(call GluonSrcDiet,./luasrc,$(PKG_BUILD_DIR)/luadest/) $(call GluonSrcDiet,./luasrc,$(PKG_BUILD_DIR)/luadest/)
$(call GluonBuildI18N,gluon-status-page,i18n) $(call GluonBuildI18N,gluon-status-page,i18n)
endef endef
define Package/gluon-status-page/install define Package/gluon-status-page/install
$(INSTALL_DIR) $(1)/lib/gluon/status-page/providers
$(INSTALL_BIN) $(PKG_BUILD_DIR)/{neighbours-batadv,stations} $(1)/lib/gluon/status-page/providers/
$(CP) ./files/* $(1)/ $(CP) ./files/* $(1)/
$(CP) $(PKG_BUILD_DIR)/luadest/* $(1)/ $(CP) $(PKG_BUILD_DIR)/luadest/* $(1)/
......
#!/bin/sh #!/bin/sh
echo 'Access-Control-Allow-Origin: *'
CMD='exec /lib/gluon/status-page/providers/neighbours-batadv' CMD='exec /lib/gluon/status-page/providers/neighbours-batadv'
exec /usr/sbin/sse-multiplex "$CMD" exec /usr/sbin/sse-multiplex "$CMD"
...@@ -6,8 +6,6 @@ badrequest() { ...@@ -6,8 +6,6 @@ badrequest() {
exit 1 exit 1
} }
echo 'Access-Control-Allow-Origin: *'
batctl if | cut -d: -f1 | grep -qxF "$QUERY_STRING" || badrequest batctl if | cut -d: -f1 | grep -qxF "$QUERY_STRING" || badrequest
exec /usr/bin/gluon-neighbour-info -s neighbour -i "$QUERY_STRING" -d ff02::2:1001 -p 1001 -r nodeinfo exec /usr/bin/gluon-neighbour-info -s neighbour -i "$QUERY_STRING" -d ff02::2:1001 -p 1001 -r nodeinfo
...@@ -6,8 +6,6 @@ badrequest() { ...@@ -6,8 +6,6 @@ badrequest() {
exit 1 exit 1
} }
echo 'Access-Control-Allow-Origin: *'
batctl if | cut -d: -f1 | grep -qxF "$QUERY_STRING" || badrequest batctl if | cut -d: -f1 | grep -qxF "$QUERY_STRING" || badrequest
CMD="exec /lib/gluon/status-page/providers/stations '$QUERY_STRING'" CMD="exec /lib/gluon/status-page/providers/stations '$QUERY_STRING'"
......
#!/bin/sh #!/bin/sh
echo 'Access-Control-Allow-Origin: *'
CMD='exec gluon-neighbour-info -s "" -l -d ::1 -p 1001 -t 3 -r statistics' CMD='exec gluon-neighbour-info -s "" -l -d ::1 -p 1001 -t 3 -r statistics'
exec /usr/sbin/sse-multiplex "$CMD" exec /usr/sbin/sse-multiplex "$CMD"
#!/usr/bin/lua #!/usr/bin/lua
local uci = require('simple-uci').cursor() local uci = require('simple-uci').cursor()
local function get_mem_total()
for line in io.lines('/proc/meminfo') do
local match = line:match('^MemTotal:%s+(%d+)')
if match then
return tonumber(match)
end
end
end
local max_requests = 32
if get_mem_total() < 48*1024 then
max_requests = 16
end
uci:section('uhttpd', 'uhttpd', 'main', {
listen_http = { '0.0.0.0:80', '[::]:80' },
listen_https = {},
home = '/lib/gluon/status-page/www',
max_requests = max_requests,
})
uci:save('uhttpd')
for _, zone in ipairs({'mesh', 'local_client'}) do for _, zone in ipairs({'mesh', 'local_client'}) do
uci:section('firewall', 'rule', zone .. '_http', { uci:section('firewall', 'rule', zone .. '_http', {
src = zone, src = zone,
......
...@@ -29,13 +29,10 @@ ifeq ($(origin LIBBATADV_CFLAGS) $(origin LIBBATADV_LDLIBS), undefined undefined ...@@ -29,13 +29,10 @@ ifeq ($(origin LIBBATADV_CFLAGS) $(origin LIBBATADV_LDLIBS), undefined undefined
LIBBATADV_LDLIBS += $(shell $(PKG_CONFIG) --libs $(LIBBATADV_NAME)) LIBBATADV_LDLIBS += $(shell $(PKG_CONFIG) --libs $(LIBBATADV_NAME))
endif endif
all: neighbours-batadv stations respondd.so all: neighbours-batadv stations
neighbours-batadv: neighbours-batadv.c neighbours-batadv: neighbours-batadv.c
$(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS_JSONC) $(LIBNL_CFLAGS) $(LIBBATADV_CFLAGS) $(LDFLAGS) $(LDFLAGS_JSONC) $(LIBNL_LDLIBS) $(LIBBATADV_LDLIBS) -Wall -o $@ $^ $(LDLIBS) $(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS_JSONC) $(LIBNL_CFLAGS) $(LIBBATADV_CFLAGS) $(LDFLAGS) $(LDFLAGS_JSONC) $(LIBNL_LDLIBS) $(LIBBATADV_LDLIBS) -Wall -o $@ $^ $(LDLIBS)
stations: stations.c stations: stations.c
$(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS_JSONC) $(LDFLAGS) $(LDFLAGS_JSONC) -Wall -o $@ $^ $(LDLIBS) -liwinfo $(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS_JSONC) $(LDFLAGS) $(LDFLAGS_JSONC) -Wall -o $@ $^ $(LDLIBS) -liwinfo
respondd.so: respondd.c
$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -shared -fPIC -o $@ $^ $(LDLIBS)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment