13 prepare_connect_commands
()
16 local skip
=yes cval found
=no
18 if [ "$skip" = "yes" -a "$line" = "# S-T-A-R-T" ]; then
22 if [ "$skip" = "no" -a "$line" = "# S-T-O-P" ]; then
26 [ "$skip" = "yes" ] && continue
28 [ -z "${line###*}" ] && continue
30 # First endpoint string/regexp match is sufficient for us.
31 cval
=`echo $line | cut -s -d' ' -f1`
32 if [ -z "${1##$cval}" ]; then
34 # Don't be too smart at the moment, just be able to handle
35 # the known-good case ;-)
37 echo $line | cut
-s -d' ' -f6 > $CMDS1
39 echo $line | cut
-s -d' ' -f7 >> $CMDS1
41 cat "$CMDS1" > "$CMDS2"
42 # ...and MAC addresses
43 cat "$CMDS1" > "$CMDS3"
46 done < `dirname $0`/cisco.secrets.php
47 [ "$found" = "yes" ] && return
48 echo "E!connector could not find credentials for $1" >> "$FILE2"
52 prepare_fetch_commands
()
54 printf 'term len 0\nshow vlan brief\nquit\n' >> $CMDS1
55 printf 'term len 0\nshow int status\nquit\n' >> $CMDS2
56 printf 'term len 0\nshow mac-address-table dynamic\nquit\n' >> $CMDS3
59 prepare_push_commands
()
61 printf 'term len 0\nconf t\n' >> $CMDS1
62 while read portname vlanid
; do
63 if [ -z "$portname" -o -z "$vlanid" ]; then
64 echo "E!could not parse input in connector" >> "$FILE2"
67 if [ "$vlanid" = "trunk" ]; then
68 echo "E!trunking is not allowed" >> "$FILE2"
71 printf "int $portname\nswi access vlan $vlanid\nexit\n" >> $CMDS1
72 echo "I!Port $portname@$ENDPOINT has been assigned to VLAN $vlanid" >> "$FILE2"
74 printf "end\nwri\nquit\n" >> $CMDS1
79 nc
$ENDPOINT 23 < $CMDS1 > "$OUT1"
80 if fgrep
-q '% Bad passwords' "$OUT1"; then
81 echo "E!password mismatch while trying to connect to $ENDPOINT" >> "$FILE2"
84 nc
$ENDPOINT 23 < $CMDS2 > "$OUT2"
85 nc
$ENDPOINT 23 < $CMDS3 > "$OUT3"
86 cat "$OUT1" | fgrep
' active ' |
sed -E 's/^([[:digit:]]+)[[:space:]]+(.+)[[:space:]]+active (.*)/\1=\2/;s/[[:space:]]+$//' > $FILE1
87 cat "$OUT2" |
egrep '^(Et|Fa|Gi|Te)' |
sed -E 's/^([A-Za-z/0-9]+).+(connected|notconnect|disabled) +/\1=\2,/;s/,(trunk|([0-9]+)) .*$/,\1/' > $FILE2
89 # Here we need to distinguish between different platforms and IOS version,
90 # cause they produce output in different formats.
91 if [ "$SW" = "Cisco+IOS+12.0" ]; then
92 cat "$OUT3" |
tr -d '\r' | fgrep Dynamic |
sed -E 's/ +Dynamic +([0-9]+) +(.+)/=\1@\2/;s/FastEthernet/Fa/;s/GigabitEthernet/Gi/' > "$FILE3"
93 elif [ "$SW" = "Cisco+IOS+12.2" ]; then
95 Cisco
+Catalyst
+35*|Cisco
+Catalyst
+37*|Cisco
+Catalyst
+29*|Cisco
+Catalyst
+49*)
96 cat "$OUT3" |
tr -d '\r' | fgrep DYNAMIC | \
97 sed -E 's/ +([0-9]+) +(.+) DYNAMIC +(.+)/\2=\1@\3/;s/FastEthernet/Fa/;s/GigabitEthernet/Gi/' > "$FILE3"
105 nc
$ENDPOINT 23 < $CMDS1 >/dev
/null
110 [ -f "$CMDS1" ] && rm -f "$CMDS1"
111 [ -f "$CMDS2" ] && rm -f "$CMDS2"
112 [ -f "$CMDS3" ] && rm -f "$CMDS3"
113 [ -f "$OUT1" ] && rm -f "$OUT1"
114 [ -f "$OUT2" ] && rm -f "$OUT2"
115 [ -f "$OUT3" ] && rm -f "$OUT3"
120 # This one is for VLAN list.
121 CMDS1
=`mktemp /tmp/cisco.connector.XXXX`
122 # And this one holds ports list...
123 CMDS2
=`mktemp /tmp/cisco.connector.XXXX`
124 # ...and one more for MAC address table
125 CMDS3
=`mktemp /tmp/cisco.connector.XXXX`
126 # The following are buffers to hold the whole switch output
128 OUT1
=`mktemp /tmp/cisco.connector.XXXX`
129 OUT2
=`mktemp /tmp/cisco.connector.XXXX`
130 OUT3
=`mktemp /tmp/cisco.connector.XXXX`
131 [ -f "$CMDS1" -a -f "$CMDS2" -a -f "$CMDS3" -a -f "$OUT1" -a -f "$OUT2" -a -f "$OUT3" ] && return
132 echo "E!connector cannot create tempfiles" >> "$FILE2"
140 prepare_connect_commands
$ENDPOINT
141 prepare_fetch_commands
147 prepare_connect_commands
$ENDPOINT
148 prepare_push_commands
153 echo "E!unknown command for connector" >> "$FILE2"