8c501c56a30edc61d11d639a36136715321ed05a
2 # Copyright © 2011 Pau Escrich
3 # Contributors Jo-Philipp Wich <xm@subsignal.org>
4 # Roger Pueyo Centelles <roger.pueyo@guifi.net>
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with this program; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 # The full GNU General Public License is included in this distribution in
21 # the file called "COPYING".
23 # This script gives information about bmx7
24 # Can be executed from a linux shell: ./bmx7-info -s links
25 # Or from web interfae (with cgi enabled): http://host/cgi-bin/bmx7-info?links
26 # If you ask for a directory you wil get the directory contents in JSON forman
28 BMX7_DIR
="$(uci get bmx7.general.runtimeDir 2>/dev/null)" || BMX7_DIR
="/var/run/bmx7/json"
30 #Checking if shell mode or cgi-bin mode
31 if [ "$1" == "-s" ]; then
34 QUERY
="${QUERY_STRING%%=*}"
35 echo "Content-type: application/json"
41 [ -d "$1" ] && path
=$
(cd $1; pwd)
42 [ -f "$1" ] && path
=$
(cd $1/..
; pwd)
43 [ $
(echo "$path" |
grep -c "^$BMX7_DIR") -ne 1 ] && exit 1
47 echo -n '{ "memory": { "bmx7": "'
48 cat /proc
/$
(cat /var
/run
/bmx
7/pid
)/status |
grep -i VmSize |
tr -s " " | cut
-d " " -f 2,3 |
tr -d "\n"
53 # If the query is a directory
54 [ -d "$BMX7_DIR/$1" ] &&
56 # If /all has not been specified
59 total
=$
(ls $BMX7_DIR/$1 |
wc -w)
61 echo -n "{ \"$1\": [ "
62 for f
in $
(ls $BMX7_DIR/$1); do
63 echo -n "{ \"name\": \"$f\" }"
64 [ $i -lt $total ] && echo -n ','
69 # If /all has been specified, printing all the files together
73 for entry
in "$BMX7_DIR/$1/"*; do
76 ${comma:+echo "$comma"}
85 # If the query is a file, just printing the file
86 [ -f "$BMX7_DIR/$1" ] && cat "$BMX7_DIR/$1";
89 if [ "${QUERY##*/}" == "all" ]; then
94 if [ "$QUERY" == '$info' ]; then
98 print_query interfaces
106 if [ "$QUERY" == '$neighbours' ]; then
108 echo '{ "neighbours": [ '
109 echo '{ "originators": '
110 print_query originators
112 echo '{ "descriptions": '
113 print_query descriptions
117 else if [ "$QUERY" == '$tunnels' ]; then
118 bmx7
-c --jshow tunnels
/r
=0
121 else if [ "$QUERY" == '$originators' ]; then
122 bmx7
-c --jshow originators
/r
=0
126 check_path
"$BMX7_DIR/$QUERY"