Throttler.pm dependencies
[hband-tools.git] / routerscript / DSG-1210-48
blob012258d940eb2f39be59291d82f57ce58e0c720e
1 #!/bin/bash
3 act=
5 while [ -n "$1" ]
6 do
7 case "$1" in
8 --help)
9 echo "Usage: ${0##*/} [-u user] [-p password] [-h host_address]
10 --list-ports
11 --enable-port <num>
12 --disable-port <num>
13 --MAC-table"
14 exit
16 -u) shift
17 user=$1
19 -p) shift
20 pass=$1
22 -h) shift
23 switch_host=$1
25 --enable-port)
26 shift
27 act=port
28 port=$1
29 speed=5
31 --disable-port)
32 shift
33 act=port
34 port=$1
35 speed=6
37 --list-ports)
38 act=list
40 --[Mm][Aa][Cc]-table)
41 act=mactable
44 echo "Unknown option: $1" >&2
45 exit 1
47 esac
48 shift
49 done
51 set -u
53 if [ "$act" = port ]
54 then
55 if [ "$port" -gt 0 ]
56 then
57 port=$(printf %02d $[$port-1])
58 else
59 echo "Invalid port number: $port" >&2
60 exit 1
65 fetch()
67 local fnc=$1
68 shift
69 curl -isS "http://$switch_host/iss/specific/$fnc.js?Gambit=$gambit" "$@"
73 gambit=`curl -isS http://$switch_host/ -d "Password=$pass&currlang=0&Login=$user&BrowsingPage=index_dlink.htm&changlang=0" | grep -iEom1 "Gambit=[a-z]+" | cut -d= -f2-`
74 if [ -z "$gambit" ]
75 then
76 echo "Could not acquire token." >&2
77 exit 1
81 case "$act" in
82 list)
83 fetch PortSetting | \
84 while read line
86 if [ "${line:0:1}" = "[" ]
87 then
88 set -- ${line//[]\',[]/ }
89 [ "$3" = 6 ] && adm_status="disabled" || adm_status="enabled"
90 [ "$2" = 8 ] && status="down" || status="up"
91 printf "Port %02d %8s %4s\n" $1 $adm_status $status
93 done
95 mactable)
96 fetch DynamicForwarding | \
97 perl -ne '
98 use Data::Dumper;
99 if(/^var DynamicForwarding/)
101 s/\x27//g;
102 while(/\[([^[]+?)\]/)
104 push @T, [split /,/, $1];
105 $_ = $'\'';
107 for my $r (sort { $a->[1] <=> $b->[1]; } @T)
109 $str_port = $r->[1] == $prev_port ? "" : $r->[1];
110 $prev_port = $r->[1];
111 printf "%2s\t%s\n", $str_port, $r->[2];
115 port)
116 if fetch PortSetting -d "FormName=portset&port_f=$port&port_t=$port&speed=$speed&mdi=0&flow=0&post_url=cgi_port.&Gambit=$gambit" | grep -q Page-Exit
117 then
118 echo Ok.
119 else
120 echo Error.
123 esac