r4073 minor change in UI for recent change: VST form commit on ENTER and hints on...
[racktables] / gateways / deviceconfig / vrp55.connector
CommitLineData
ec523868
DO
1#!/bin/sh
2
3[ $# = 3 ] || exit 1
4
5ENDPOINT=$1
6COMMAND=$2
7WORKFILE=$3
8
9prepare_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 access_password=`echo $line | cut -s -d' ' -f6`
34 [ "$access_password" != "-" ] && echo "$access_password" >> "$SESSION"
35 printf "super\n" >> "$SESSION"
36 enable_password=`echo $line | cut -s -d' ' -f7`
37 [ "$enable_password" != "-" ] && echo $enable_password >> "$SESSION"
38 break
39 fi
40 done < "$MYDIR/switch.secrets.php"
41 [ "$found" = "yes" ] && return
42 exit 3
43}
44
45MYNAME=`basename $0`
3b3ea468 46MYDIR=`dirname $0`
ec523868
DO
47SESSION=`mktemp /tmp/$MYNAME.XXXXXX`
48[ -f "$SESSION" ] || exit 5
49prepare_connect_commands $ENDPOINT
d3da0101 50printf 'screen-length 0 temporary\n' >> "$SESSION"
ec523868
DO
51case $COMMAND in
52get8021q)
53 printf 'display current-configuration\n' >> "$SESSION"
54 outfile="$WORKFILE"
55 ;;
56getlldpstatus)
57 printf 'display lldp neighbor\n' >> "$SESSION"
58 outfile="$WORKFILE"
59 ;;
65e557dd
AA
60getportstatus)
61 printf 'display interface brief\n' >> "$SESSION"
62 outfile="$WORKFILE"
63 ;;
64getmaclist)
65 printf 'display mac-address dynamic\n' >> "$SESSION"
66 outfile="$WORKFILE"
67 ;;
ec523868
DO
68gethndp)
69 printf 'display ndp\n' >> "$SESSION"
70 outfile="$WORKFILE"
71 ;;
72deploy)
73 cat "$WORKFILE" >> "$SESSION"
74 outfile=/dev/null
75 ;;
76*)
77 rm -f "$SESSION"
78 exit 6
79 ;;
80esac
81printf 'quit\n' >> "$SESSION"
82rc=0
3b3ea468 83$MYDIR/nc.pl --putwhen='(^Username:$|^Password:$)|^<[^<>]*>$|^\[[^\[\]]*\]$' --stopwhen='^Now saving the current configuration' -w 30 $ENDPOINT 23 < "$SESSION" > "$outfile" || rc=4
ec523868
DO
84rm -f "$SESSION"
85exit $rc