From dcb32b460bc2433d0ef09c01679cb3f0fe7794b4 Mon Sep 17 00:00:00 2001 From: Christof Schulze Date: Wed, 4 May 2016 22:12:39 +0200 Subject: [PATCH] rewrite stations in lua --- .../status-page/www/cgi-bin/dyn/stations | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/package/gluon-status-page-api/files/lib/gluon/status-page/www/cgi-bin/dyn/stations b/package/gluon-status-page-api/files/lib/gluon/status-page/www/cgi-bin/dyn/stations index 42f96eb7..67a9405b 100755 --- a/package/gluon-status-page-api/files/lib/gluon/status-page/www/cgi-bin/dyn/stations +++ b/package/gluon-status-page-api/files/lib/gluon/status-page/www/cgi-bin/dyn/stations @@ -1,15 +1,20 @@ -#!/bin/sh +#!/usr/bin/lua +local mesh = require 'gluon.mesh' +local querystring = os.getenv("QUERY_STRING") -badrequest() { - echo 'Status: 400 Bad Request' - echo - exit 1 -} +print('Access-Control-Allow-Origin: *\n') -echo 'Access-Control-Allow-Origin: *' +for interface, _ in pairs(mesh.interfaces()) do + if querystring + then + if string.find(interface, querystring) + then + os.execute("/usr/sbin/sse-multiplex /lib/gluon/status-page/providers/stations " .. querystring ); + os.exit(0) + end + end +end -lua -e 'mesh = require(gluon.mesh); for interface, _ in ipairs(mesh.interfaces()) do print(interface .. "\n"); end;' | grep -qxF "$QUERY_STRING" || badrequest -CMD="exec /lib/gluon/status-page/providers/stations '$QUERY_STRING'" - -exec /usr/sbin/sse-multiplex "$CMD" +print("Status: 400 Bad Request\n") +os.exit(1)