From a7d7f4baa888bbccc17ac2020ff98994236c8af0 Mon Sep 17 00:00:00 2001 From: Roger Pueyo Centelles Date: Fri, 7 Dec 2018 17:47:22 +0100 Subject: [PATCH 1/2] luci-app-bmx7: fix bmx7-info script's indentation Signed-off-by: Roger Pueyo Centelles --- luci-app-bmx7/files/www/cgi-bin/bmx7-info | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/luci-app-bmx7/files/www/cgi-bin/bmx7-info b/luci-app-bmx7/files/www/cgi-bin/bmx7-info index 8c501c5..c3f4418 100755 --- a/luci-app-bmx7/files/www/cgi-bin/bmx7-info +++ b/luci-app-bmx7/files/www/cgi-bin/bmx7-info @@ -1,7 +1,7 @@ #!/bin/sh # Copyright © 2011 Pau Escrich # Contributors Jo-Philipp Wich -# Roger Pueyo Centelles +# Roger Pueyo Centelles # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -34,13 +34,12 @@ else QUERY="${QUERY_STRING%%=*}" echo "Content-type: application/json" echo "" - fi check_path() { - [ -d "$1" ] && path=$(cd $1; pwd) - [ -f "$1" ] && path=$(cd $1/..; pwd) - [ $(echo "$path" | grep -c "^$BMX7_DIR") -ne 1 ] && exit 1 + [ -d "$1" ] && path=$(cd $1; pwd) + [ -f "$1" ] && path=$(cd $1/..; pwd) + [ $(echo "$path" | grep -c "^$BMX7_DIR") -ne 1 ] && exit 1 } print_mem() { @@ -52,19 +51,19 @@ print_mem() { print_query() { # If the query is a directory [ -d "$BMX7_DIR/$1" ] && - { + { # If /all has not been specified [ -z "$QALL" ] && { total=$(ls $BMX7_DIR/$1 | wc -w) i=1 - echo -n "{ \"$1\": [ " - for f in $(ls $BMX7_DIR/$1); do + echo -n "{ \"$1\": [ " + for f in $(ls $BMX7_DIR/$1); do echo -n "{ \"name\": \"$f\" }" [ $i -lt $total ] && echo -n ',' i=$(( $i + 1 )) - done - echo -n " ] }" + done + echo -n " ] }" # If /all has been specified, printing all the files together } || { @@ -80,7 +79,7 @@ print_query() { done echo -n " ]" } - } + } # If the query is a file, just printing the file [ -f "$BMX7_DIR/$1" ] && cat "$BMX7_DIR/$1"; From 3e259f8ec58f982ce565533f14006102ec9f6565 Mon Sep 17 00:00:00 2001 From: Roger Pueyo Centelles Date: Fri, 7 Dec 2018 18:04:10 +0100 Subject: [PATCH 2/2] luci-app-bmx7: fix bmx7-info script's "$info" call 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 --- luci-app-bmx7/files/www/cgi-bin/bmx7-info | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/luci-app-bmx7/files/www/cgi-bin/bmx7-info b/luci-app-bmx7/files/www/cgi-bin/bmx7-info index c3f4418..7388ed1 100755 --- a/luci-app-bmx7/files/www/cgi-bin/bmx7-info +++ b/luci-app-bmx7/files/www/cgi-bin/bmx7-info @@ -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