gluon-status-page-api: use sse-multiplex
This commit is contained in:
parent
fa504dae8d
commit
90a64ca87f
@ -12,7 +12,7 @@ define Package/gluon-status-page-api
|
|||||||
SECTION:=gluon
|
SECTION:=gluon
|
||||||
CATEGORY:=Gluon
|
CATEGORY:=Gluon
|
||||||
TITLE:=API for gluon-status-page
|
TITLE:=API for gluon-status-page
|
||||||
DEPENDS:=+gluon-core +uhttpd +gluon-neighbour-info +gluon-announced +libiwinfo +libjson-c
|
DEPENDS:=+gluon-core +uhttpd +sse-multiplex +gluon-neighbour-info +gluon-announced +libiwinfo +libjson-c
|
||||||
endef
|
endef
|
||||||
|
|
||||||
define Build/Prepare
|
define Build/Prepare
|
||||||
@ -21,9 +21,9 @@ define Build/Prepare
|
|||||||
endef
|
endef
|
||||||
|
|
||||||
define Package/gluon-status-page-api/install
|
define Package/gluon-status-page-api/install
|
||||||
$(INSTALL_DIR) $(1)/lib/gluon/status-page/www/cgi-bin/dyn
|
$(INSTALL_DIR) $(1)/lib/gluon/status-page/providers
|
||||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/neighbours-batadv $(1)/lib/gluon/status-page/www/cgi-bin/dyn/
|
$(INSTALL_BIN) $(PKG_BUILD_DIR)/neighbours-batadv $(1)/lib/gluon/status-page/providers/
|
||||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/stations $(1)/lib/gluon/status-page/www/cgi-bin/dyn/
|
$(INSTALL_BIN) $(PKG_BUILD_DIR)/stations $(1)/lib/gluon/status-page/providers/
|
||||||
$(CP) ./files/* $(1)/
|
$(CP) ./files/* $(1)/
|
||||||
endef
|
endef
|
||||||
|
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
echo 'Access-Control-Allow-Origin: *'
|
||||||
|
|
||||||
|
CMD='exec /lib/gluon/status-page/providers/neighbours-batadv'
|
||||||
|
|
||||||
|
exec /usr/sbin/sse-multiplex "$CMD"
|
@ -1,7 +1,13 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
|
badrequest() {
|
||||||
|
echo 'Status: 400 Bad Request'
|
||||||
|
echo
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
echo 'Access-Control-Allow-Origin: *'
|
echo 'Access-Control-Allow-Origin: *'
|
||||||
|
|
||||||
batctl if | cut -d: -f1 | grep -qxF "$QUERY_STRING" || exit 1
|
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
|
||||||
|
@ -0,0 +1,15 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
badrequest() {
|
||||||
|
echo 'Status: 400 Bad Request'
|
||||||
|
echo
|
||||||
|
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'"
|
||||||
|
|
||||||
|
exec /usr/sbin/sse-multiplex "$CMD"
|
@ -1,5 +1,7 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
echo "Access-Control-Allow-Origin: *"
|
echo 'Access-Control-Allow-Origin: *'
|
||||||
|
|
||||||
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"
|
||||||
|
2
package/gluon-status-page-api/src/neighbours-batadv.c
Executable file → Normal file
2
package/gluon-status-page-api/src/neighbours-batadv.c
Executable file → Normal file
@ -50,8 +50,8 @@ static json_object *neighbours(void) {
|
|||||||
int main(void) {
|
int main(void) {
|
||||||
struct json_object *obj;
|
struct json_object *obj;
|
||||||
|
|
||||||
printf("Access-Control-Allow-Origin: *\n");
|
|
||||||
printf("Content-type: text/event-stream\n\n");
|
printf("Content-type: text/event-stream\n\n");
|
||||||
|
fflush(stdout);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
obj = neighbours();
|
obj = neighbours();
|
||||||
|
29
package/gluon-status-page-api/src/stations.c
Executable file → Normal file
29
package/gluon-status-page-api/src/stations.c
Executable file → Normal file
@ -1,15 +1,10 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdbool.h>
|
|
||||||
#include <json-c/json.h>
|
#include <json-c/json.h>
|
||||||
#include <iwinfo.h>
|
#include <iwinfo.h>
|
||||||
#include <net/if.h>
|
#include <net/if.h>
|
||||||
|
|
||||||
#define STR(x) #x
|
|
||||||
#define XSTR(x) STR(x)
|
|
||||||
|
|
||||||
#define BATIF_PREFIX "/sys/class/net/bat0/lower_"
|
|
||||||
|
|
||||||
static struct json_object *get_stations(const struct iwinfo_ops *iw, const char *ifname) {
|
static struct json_object *get_stations(const struct iwinfo_ops *iw, const char *ifname) {
|
||||||
int len;
|
int len;
|
||||||
@ -45,34 +40,16 @@ static void badrequest() {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool interface_is_valid(const char *ifname) {
|
int main(int argc, char *argv[]) {
|
||||||
if (strlen(ifname) > IF_NAMESIZE)
|
if (argc != 2)
|
||||||
return false;
|
|
||||||
|
|
||||||
if (strchr(ifname, '/') != NULL)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
char *path = alloca(1 + strlen(BATIF_PREFIX) + strlen(ifname));
|
|
||||||
sprintf(path, "%s%s", BATIF_PREFIX, ifname);
|
|
||||||
|
|
||||||
return access(path, F_OK) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(void) {
|
|
||||||
char *ifname = getenv("QUERY_STRING");
|
|
||||||
|
|
||||||
if (ifname == NULL)
|
|
||||||
badrequest();
|
|
||||||
|
|
||||||
if (!interface_is_valid(ifname))
|
|
||||||
badrequest();
|
badrequest();
|
||||||
|
|
||||||
|
const char *ifname = argv[1];
|
||||||
const struct iwinfo_ops *iw = iwinfo_backend(ifname);
|
const struct iwinfo_ops *iw = iwinfo_backend(ifname);
|
||||||
|
|
||||||
if (iw == NULL)
|
if (iw == NULL)
|
||||||
badrequest();
|
badrequest();
|
||||||
|
|
||||||
printf("Access-Control-Allow-Origin: *\n");
|
|
||||||
printf("Content-type: text/event-stream\n\n");
|
printf("Content-type: text/event-stream\n\n");
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
Loading…
Reference in New Issue
Block a user