r4324 added RHEL6
[racktables] / gateways / deviceconfig / ios12.connector
1 #!/bin/sh
2
3 [ $# = 3 ] || exit 1
4
5 ENDPOINT=$1
6 COMMAND=$2
7 WORKFILE=$3
8
9 prepare_connect_commands()
10 {
11 [ $# = 1 ] || exit 2
12 local skip=yes cval found=no MYDIR=`dirname $0`
13 while read line; do
14 if [ "$skip" = "yes" -a "$line" = "# S-T-A-R-T" ]; then
15 skip=no
16 continue
17 fi
18 if [ "$skip" = "no" -a "$line" = "# S-T-O-P" ]; then
19 skip=yes
20 continue
21 fi
22 [ "$skip" = "yes" ] && continue
23 # ignore comments
24 [ -z "${line###*}" ] && continue
25
26 # First endpoint string/regexp match is sufficient for us.
27 cval=`echo $line | cut -s -d' ' -f1`
28 if [ -z "${1##$cval}" ]; then
29 found=yes
30 username=`echo $line | cut -s -d' ' -f5`
31 [ "$username" != "-" ] && echo $username > $SESSION
32 # access password
33 echo $line | cut -s -d' ' -f6 >> $SESSION
34 enable_password=`echo $line | cut -s -d' ' -f7`
35 [ "$enable_password" != "-" ] && {
36 echo en >> $SESSION
37 echo $enable_password >> $SESSION
38 }
39 break
40 fi
41 done < "$MYDIR/switch.secrets.php"
42 [ "$found" = "yes" ] && return
43 exit 3
44 }
45
46 MYNAME=`basename $0`
47 SESSION=`mktemp /tmp/$MYNAME.XXXXXX`
48 [ -f "$SESSION" ] || exit 5
49 prepare_connect_commands $ENDPOINT
50 case $COMMAND in
51 get8021q)
52 printf 'term len 0\nshow run\n! END OF CONFIG\nshow vlan brief\n! END OF VLAN LIST\n' >> "$SESSION"
53 outfile="$WORKFILE"
54 ;;
55 getcdpstatus)
56 printf 'term len 0\nshow cdp neighbors detail\n' >> "$SESSION"
57 outfile="$WORKFILE"
58 ;;
59 getlldpstatus)
60 printf 'term len 0\nshow lldp neighbors\n' >> "$SESSION"
61 outfile="$WORKFILE"
62 ;;
63 getportstatus)
64 printf 'term len 0\nshow int status\n' >> "$SESSION"
65 outfile="$WORKFILE"
66 ;;
67 getmaclist)
68 printf 'term len 0\nshow mac address-table dynamic\n' >> "$SESSION"
69 outfile="$WORKFILE"
70 ;;
71 deploy)
72 cat "$WORKFILE" >> "$SESSION"
73 outfile=/dev/null
74 ;;
75 *)
76 rm -f "$SESSION"
77 exit 6
78 ;;
79 esac
80 printf 'quit\n' >> "$SESSION"
81 rc=0
82 nc -w 30 $ENDPOINT 23 < "$SESSION" > "$outfile" || rc=4
83 rm -f "$SESSION"
84 exit $rc