1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
#/bin/bash
ACTION=$1
INPUT=$2
load () {
IFS=' '
ps_status=`ps -A | grep "ampr-ripd" | awk '{ print $1,$4 }'`
read -a status_array <<< "$ps_status"
d_status=''
r_count=''
if [ -f "/usr/sbin/ampr-ripd" ]
then
d_status+="Installed, "
if [ ${status_array[0]} ]
then
d_status+="running PID ${status_array[0]}"
else
d_status+="not running"
fi
else
d_status+="Not Installed"
fi
status="{\"rstatus\":\"$d_status\"}"
rcount=`ip route list table default | grep -c "tun44"`
if [ $rcount -ne 0 ]
then
status+=",{\"rstatus\":\"Routes: $rcount\"}"
fi
statics=`ip route list table main | grep "44." | awk '{ print $1","$3 }'`
IFS=','
static=''
while read -ra data; do
[ -n "$static" ] && static+=','
static+="{\"enet\":\"${data[0]}\",\"egw\":\"${data[1]}\"}"
done <<< "$statics"
bypasses=`ip route list table default | grep -v "tun44" | awk '{ print $1","$3 }'`
IFS=','
bypass=''
while read -ra data; do
[ -n "$bypass" ] && bypass+=','
bypass+="{\"enet\":\"${data[0]}\",\"egw\":\"${data[1]}\"}"
done <<< "$bypasses"
encaps=`ip route list table default | grep "tun44" | awk '{ print $1","$3 }'`
IFS=','
encap=''
while read -ra data; do
[ -n "$encap" ] && encap+=','
encap+="{\"enet\":\"${data[0]}\",\"egw\":\"${data[1]}\"}"
done <<< "$encaps"
echo "{\"success\":\"1\",\"data\":{\"ripd-status\":[$status],\"static\":[$static],\"bypass\":[$bypass],\"encap\":[$encap]}}"
}
delete () {
echo "{\"success\":\"0\"}"
}
apply () {
echo "{\"success\":\"0\"}"
}
case "$ACTION" in
load)
load
;;
delete)
delete
;;
apply)
apply
;;
esac
|