luci-app-bmx7: fix bmx7-info script's "$info" call 431/head
authorRoger Pueyo Centelles <roger.pueyo@guifi.net>
Fri, 7 Dec 2018 17:04:10 +0000 (18:04 +0100)
committerRoger Pueyo Centelles <roger.pueyo@guifi.net>
Fri, 7 Dec 2018 17:04:10 +0000 (18:04 +0100)
This commit fixes a bug in bmx7-info script's "$info" call when no
interfaces are being used by BMX7, or when no links have been
established. In those cases, the generated JSON output struct contained
extra commas, which made it invalid.

Closes #430

Signed-off-by: Roger Pueyo Centelles <roger.pueyo@guifi.net>
luci-app-bmx7/files/www/cgi-bin/bmx7-info

index c3f4418ac4b4bbce44446b04f4352ab1508a2b05..7388ed12c37e384fadab3e5a8c969d5e2ab78a51 100755 (executable)
@@ -82,7 +82,7 @@ print_query() {
        }
 
        # If the query is a file, just printing the file
-       [ -f "$BMX7_DIR/$1" ] && cat "$BMX7_DIR/$1";
+       [ -f "$BMX7_DIR/$1" ] && [ -s "$BMX7_DIR/$1" ] && cat "$BMX7_DIR/$1" && return 0 || return 1
 }
 
 if [ "${QUERY##*/}" == "all" ]; then
@@ -94,10 +94,8 @@ if [ "$QUERY" == '$info' ]; then
        echo '{ "info": [ '
        print_query status
        echo -n ","
-       print_query interfaces
-       echo -n ","
-       print_query links
-       echo -n ","
+       print_query interfaces && echo -n "," || echo -n '{ "interfaces": "" },'
+       print_query links && echo -n "," || echo -n '{ "links": "" },'
        print_mem
        echo "] }"
 fi