r3337 fdry5PickVLANSubcommand(): fill "portdata" list with port_name as key
[racktables] / gateways / deviceconfig / fdry5.connector
CommitLineData
737e04fc
DO
1#!/bin/sh
2
3[ $# = 2 ] || exit 1
4
5ENDPOINT=$1
6OUT1=$2
7
8prepare_connect_commands()
9{
10 [ $# = 1 ] || exit 2
11 local skip=yes cval found=no MYDIR=`dirname $0`
12 while read line; do
13 if [ "$skip" = "yes" -a "$line" = "# S-T-A-R-T" ]; then
14 skip=no
15 continue
16 fi
17 if [ "$skip" = "no" -a "$line" = "# S-T-O-P" ]; then
18 skip=yes
19 continue
20 fi
21 [ "$skip" = "yes" ] && continue
22 # ignore comments
23 [ -z "${line###*}" ] && continue
24
25 # First endpoint string/regexp match is sufficient for us.
26 cval=`echo $line | cut -s -d' ' -f1`
27 if [ -z "${1##$cval}" ]; then
28 found=yes
29 username=`echo $line | cut -s -d' ' -f5`
30 [ "$username" != "-" ] && echo $username > $CMDS1
31 # access password
32 access_password=`echo $line | cut -s -d' ' -f6`
33 [ "$access_password" != "-" ] && echo "$access_password" >> $CMDS1
34 printf "en\r\n" >> $CMDS1
35 enable_password=`echo $line | cut -s -d' ' -f7`
36 [ "$enable_password" != "-" ] && echo $enable_password >> $CMDS1
37 break
38 fi
0f86f02c 39 done < "$MYDIR/switch.secrets.php"
737e04fc
DO
40 [ "$found" = "yes" ] && return
41 exit 3
42}
43
44CMDS1=`mktemp /tmp/fdry5.connector.XXXX`
45[ -f "$CMDS1" ] || exit 5
46prepare_connect_commands $ENDPOINT
47printf 'skip-page-display\r\nshow running-config\r\nexit\r\nexit\r\n' >> $CMDS1
48cat $CMDS1 | nc -i 1 $ENDPOINT 23 > "$OUT1"
49if fgrep -q '% Bad passwords' "$OUT1"; then
50 rm -f "$CMDS1"
51 exit 4
52fi
53rm -f "$CMDS1"
54exit 0