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
This commit is contained in:
Matthias Schiffer 2018-02-26 02:05:07 +01:00
parent 88906f238b
commit fdf823a3a2
No known key found for this signature in database
GPG Key ID: 16EF3F64CB201D9C
17 changed files with 44 additions and 167 deletions

View File

@ -1,42 +0,0 @@
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))

View File

@ -1,8 +0,0 @@
#!/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

View File

@ -1,18 +0,0 @@
#!/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

View File

@ -1,24 +0,0 @@
#!/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))

View File

@ -1,12 +0,0 @@
#!/usr/bin/lua
local uci = require('simple-uci').cursor()
for _, zone in ipairs({'mesh', 'local_client'}) do
uci:section('firewall', 'rule', zone .. '_http', {
src = zone,
dest_port = '80',
proto = 'tcp',
target = 'ACCEPT',
})
end
uci:save('firewall')

View File

@ -1,47 +0,0 @@
/*
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},
{}
};

View File

@ -12,19 +12,20 @@ define Package/gluon-status-page
SECTION:=gluon
CATEGORY:=Gluon
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
define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
endef
define Build/Compile
$(call Build/Compile/Default)
$(call GluonSrcDiet,./luasrc,$(PKG_BUILD_DIR)/luadest/)
$(call GluonBuildI18N,gluon-status-page,i18n)
endef
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) $(PKG_BUILD_DIR)/luadest/* $(1)/

View File

@ -1,7 +1,5 @@
#!/bin/sh
echo 'Access-Control-Allow-Origin: *'
CMD='exec /lib/gluon/status-page/providers/neighbours-batadv'
exec /usr/sbin/sse-multiplex "$CMD"

View File

@ -6,8 +6,6 @@ badrequest() {
exit 1
}
echo 'Access-Control-Allow-Origin: *'
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

View File

@ -6,8 +6,6 @@ badrequest() {
exit 1
}
echo 'Access-Control-Allow-Origin: *'
batctl if | cut -d: -f1 | grep -qxF "$QUERY_STRING" || badrequest
CMD="exec /lib/gluon/status-page/providers/stations '$QUERY_STRING'"

View File

@ -1,7 +1,5 @@
#!/bin/sh
echo 'Access-Control-Allow-Origin: *'
CMD='exec gluon-neighbour-info -s "" -l -d ::1 -p 1001 -t 3 -r statistics'
exec /usr/sbin/sse-multiplex "$CMD"

View File

@ -0,0 +1,38 @@
#!/usr/bin/lua
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
uci:section('firewall', 'rule', zone .. '_http', {
src = zone,
dest_port = '80',
proto = 'tcp',
target = 'ACCEPT',
})
end
uci:save('firewall')

View File

@ -29,13 +29,10 @@ ifeq ($(origin LIBBATADV_CFLAGS) $(origin LIBBATADV_LDLIBS), undefined undefined
LIBBATADV_LDLIBS += $(shell $(PKG_CONFIG) --libs $(LIBBATADV_NAME))
endif
all: neighbours-batadv stations respondd.so
all: neighbours-batadv stations
neighbours-batadv: neighbours-batadv.c
$(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS_JSONC) $(LIBNL_CFLAGS) $(LIBBATADV_CFLAGS) $(LDFLAGS) $(LDFLAGS_JSONC) $(LIBNL_LDLIBS) $(LIBBATADV_LDLIBS) -Wall -o $@ $^ $(LDLIBS)
stations: stations.c
$(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS_JSONC) $(LDFLAGS) $(LDFLAGS_JSONC) -Wall -o $@ $^ $(LDLIBS) -liwinfo
respondd.so: respondd.c
$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -shared -fPIC -o $@ $^ $(LDLIBS)