Commit | Line | Data |
---|---|---|
d30547bf DO |
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 | access_password=`echo $line | cut -s -d' ' -f6` | |
34 | [ "$access_password" != "-" ] && echo "$access_password" >> "$SESSION" | |
35 | break | |
36 | fi | |
37 | done < "$MYDIR/switch.secrets.php" | |
38 | [ "$found" = "yes" ] && return | |
39 | exit 3 | |
40 | } | |
41 | ||
42 | MYNAME=`basename $0` | |
43 | SESSION=`mktemp /tmp/$MYNAME.XXXX` | |
44 | [ -f "$SESSION" ] || exit 5 | |
45 | prepare_connect_commands $ENDPOINT | |
46 | case $COMMAND in | |
db64180c | 47 | get8021q) |
d30547bf DO |
48 | printf 'disable clipaging\nshow configuration "vlan"\n' >> "$SESSION" |
49 | outfile="$WORKFILE" | |
50 | ;; | |
51 | getlldpstatus) | |
52 | printf 'disable clipaging\nshow lldp neighbors detailed\n' >> "$SESSION" | |
53 | outfile="$WORKFILE" | |
54 | ;; | |
55 | deploy) | |
56 | cat "$WORKFILE" >> "$SESSION" | |
57 | outfile=/dev/null | |
58 | ;; | |
59 | *) | |
64701a49 DO |
60 | rm -f "$SESSION" |
61 | exit 6 | |
62 | ;; | |
d30547bf DO |
63 | esac |
64 | # quit, but don't save, if asked | |
65 | printf 'quit\nn\n' >> "$SESSION" | |
64701a49 DO |
66 | rc=0 |
67 | nc -w30 $ENDPOINT 23 < "$SESSION" > "$outfile" || rc=4 | |
d30547bf | 68 | rm -f "$SESSION" |
64701a49 | 69 | exit $rc |