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