Lines 7-80
Link Here
|
7 |
require "netams.cgi"; |
7 |
require "netams.cgi"; |
8 |
|
8 |
|
9 |
$toppane= "<b>Quotas Management</b>"; |
9 |
$toppane= "<b>Quotas Management</b>"; |
10 |
|
10 |
|
11 |
netams_send("show quota list"); |
11 |
netams_send("show quota list"); |
12 |
$result=netams_read(); @s_units=split("\n", $result); |
12 |
$result=netams_read(); @s_units=split("\n", $result); |
13 |
shift @s_units; |
13 |
shift @s_units; |
|
|
14 |
shift @s_units; |
14 |
$p1="<b>Here the list of units with quota management ACTIVE:</b><br>"; |
15 |
$p1="<b>Here the list of units with quota management ACTIVE:</b><br>"; |
15 |
|
16 |
|
16 |
@s=split(/ /, $s_units[0]); %pairs=@s; |
17 |
foreach $s (@s_units) { |
17 |
foreach $s (keys %pairs) { |
18 |
@s=split(/\s/, $s); |
18 |
$p1.="<a href='$url?action=quotas&oid=".$pairs{$s}."'>".$s."</a> "; |
19 |
$pairs{$s[0]}=$s[1]; |
|
|
20 |
$p1.="<a href='$url?action=quotas&oid=".$s[1]."'>".$s[0]."</a> "; |
19 |
} |
21 |
} |
20 |
$p1 .= "<br><hr>"; |
22 |
$p1 .= "<br><hr>"; |
21 |
|
23 |
|
22 |
if (($oid ne "000000") and (%pairs > 0) ) { |
24 |
if (($oid ne "000000") and (%pairs > 0)) { |
23 |
|
25 |
|
24 |
# first process something if submitted |
26 |
# first process something if submitted |
25 |
if ($cgi->param("act") ne "") { |
27 |
if ($cgi->param("act") ne "") { |
26 |
netams_send("service quota 0"); |
28 |
netams_cmds(("enable","configure terminal","service quota","set oid $oid active","exit","exit","disable")); |
27 |
$result=netams_read(); |
|
|
28 |
netams_send("set oid $oid active"); |
29 |
$result=netams_read(); |
30 |
netams_send("exit"); $result=netams_read(); |
31 |
} |
29 |
} |
32 |
|
30 |
|
33 |
if ($cgi->param("deact") ne "") { |
31 |
if ($cgi->param("deact") ne "") { |
34 |
netams_send("service quota 0"); |
32 |
netams_cmds(("enable","configure terminal","service quota","set oid $oid inactive","exit","exit","disable")); |
35 |
$result=netams_read(); |
|
|
36 |
netams_send("set oid $oid inactive"); |
37 |
$result=netams_read(); |
38 |
netams_send("exit"); $result=netams_read(); |
39 |
} |
33 |
} |
40 |
|
34 |
|
41 |
if ($cgi->param("soft") ne "") { |
35 |
if ($cgi->param("soft") ne "") { |
42 |
netams_send("service quota 0"); |
|
|
43 |
$result=netams_read(); |
44 |
$soft_val=$cgi->param("soft_val"); |
36 |
$soft_val=$cgi->param("soft_val"); |
45 |
if ($soft_val > -1 and $soft_val <101) { |
37 |
if ($soft_val > -1 and $soft_val <101) { |
46 |
netams_send("set oid $oid soft-treshold $soft_val"); |
38 |
netams_cmds(("enable","configure terminal","service quota","set oid $oid soft-treshold $soft_val","exit","exit","disable")); |
47 |
$result=netams_read(); |
|
|
48 |
} |
39 |
} |
49 |
netams_send("exit"); $result=netams_read(); |
|
|
50 |
} |
40 |
} |
51 |
|
41 |
|
52 |
if ($cgi->param("notify") ne "") { |
42 |
if ($cgi->param("notify") ne "") { |
53 |
netams_send("service quota 0"); |
43 |
my @cmds = ("enable","configure terminal","service quota"); |
54 |
$result=netams_read(); |
|
|
55 |
|
44 |
|
56 |
$s=$cgi->param("notify_soft_owner"); if (defined $s) { $s="{owner}"; } |
45 |
$s=$cgi->param("notify_soft_owner"); if (defined $s) { $s="{owner}"; } |
57 |
$sn=$cgi->param("notify_soft_name"); |
46 |
$sn=$cgi->param("notify_soft_name"); |
58 |
netams_send("set oid $oid notify soft {none}"); $result=netams_read(); |
47 |
push(@cmds,("set oid $oid notify soft {none}", "set oid $oid notify soft $s $sn")); |
59 |
netams_send("set oid $oid notify soft $s $sn"); $result=netams_read(); |
|
|
60 |
|
48 |
|
61 |
$s=$cgi->param("notify_hard_owner"); if (defined $s) { $s="{owner}"; } |
49 |
$s=$cgi->param("notify_hard_owner"); if (defined $s) { $s="{owner}"; } |
62 |
$sn=$cgi->param("notify_hard_name"); |
50 |
$sn=$cgi->param("notify_hard_name"); |
63 |
netams_send("set oid $oid notify hard {none}"); $result=netams_read(); |
51 |
push(@cmds,("set oid $oid notify hard {none}", "set oid $oid notify hard $s $sn")); |
64 |
netams_send("set oid $oid notify hard $s $sn"); $result=netams_read(); |
|
|
65 |
|
52 |
|
66 |
$s=$cgi->param("notify_return_owner"); if (defined $s) { $s="{owner}"; } |
53 |
$s=$cgi->param("notify_return_owner"); if (defined $s) { $s="{owner}"; } |
67 |
$sn=$cgi->param("notify_return_name"); |
54 |
$sn=$cgi->param("notify_return_name"); |
68 |
netams_send("set oid $oid notify return {none}"); $result=netams_read(); |
55 |
push(@cmds,("set oid $oid notify return {none}", "set oid $oid notify return $s $sn")); |
69 |
netams_send("set oid $oid notify return $s $sn"); $result=netams_read(); |
56 |
|
70 |
|
57 |
push(@cmds,("exit","exit","disable")); |
71 |
netams_send("exit"); $result=netams_read(); |
58 |
netams_cmds(@cmds); |
72 |
} |
59 |
} |
73 |
|
60 |
|
74 |
if ($cgi->param("quotas") ne "") { |
61 |
if ($cgi->param("quotas") ne "") { |
75 |
netams_send("service quota 0"); |
|
|
76 |
$result=netams_read(); |
77 |
|
78 |
if (($t=$cgi->param("h_in"))!=0) { $x.="hour $t in "; } |
62 |
if (($t=$cgi->param("h_in"))!=0) { $x.="hour $t in "; } |
79 |
if (($t=$cgi->param("h_out"))!=0) { $x.="hour $t out "; } |
63 |
if (($t=$cgi->param("h_out"))!=0) { $x.="hour $t out "; } |
80 |
if (($t=$cgi->param("h_sum"))!=0) { $x.="hour $t sum "; } |
64 |
if (($t=$cgi->param("h_sum"))!=0) { $x.="hour $t sum "; } |
Lines 94-115
Link Here
|
94 |
$x =~ s/-1/0/g; |
78 |
$x =~ s/-1/0/g; |
95 |
|
79 |
|
96 |
if ($x ne "") { |
80 |
if ($x ne "") { |
97 |
netams_send("set oid $oid $x"); |
81 |
netams_cmds(("enable","configure terminal","service quota","set oid $oid $x","exit","exit","disable")); |
98 |
$result=netams_read(); |
|
|
99 |
} |
82 |
} |
100 |
|
|
|
101 |
netams_send("exit"); $result=netams_read(); |
102 |
} |
83 |
} |
103 |
#netams_send("service quota 0"); |
84 |
#netams_send("service quota 0"); |
104 |
#$result=netams_read(); |
85 |
#$result=netams_read(); |
105 |
$cmd="show quota oid ".$oid; netams_send($cmd); |
86 |
$cmd="show quota oid ".$oid; netams_send($cmd); |
106 |
$result=netams_readline(); @s_qu=split("\n", $result); |
87 |
$result=netams_read(); @s_qu=split("\n", $result); |
107 |
$p2 = "Current unit quota control status follows: <pre>$result</pre>\n"; |
88 |
$p2 = "Current unit quota control status follows: <pre>$result</pre>\n"; |
108 |
$p2 =~ s/{owner}/[owner]/g; |
89 |
# $p2 =~ s/{owner}/[owner]/g; |
109 |
|
90 |
|
110 |
%pairs2 = reverse %pairs; |
91 |
%pairs2 = reverse %pairs; |
111 |
|
92 |
if (-1 == index($s_qu[1], "ACTIVE")) {# -1 eq NOT, other=YES |
112 |
if (-1 == index($s_qu[0], "ACTIVE")) {# -1 eq NOT, other=YES |
|
|
113 |
$p1.="Current state for <b>".$pairs2{$oid}." [$oid]</b> is <b>INACTIVE</b>. <input type=submit name=act value='ACTIVATE IT'><br><hr>\n"; |
93 |
$p1.="Current state for <b>".$pairs2{$oid}." [$oid]</b> is <b>INACTIVE</b>. <input type=submit name=act value='ACTIVATE IT'><br><hr>\n"; |
114 |
} |
94 |
} |
115 |
else { |
95 |
else { |
Lines 118-139
Link Here
|
118 |
|
98 |
|
119 |
if ($s_qu[1] ne "") { # we have something here |
99 |
if ($s_qu[1] ne "") { # we have something here |
120 |
|
100 |
|
121 |
$j=index($s_qu[0], "soft-treshold:"); |
101 |
$j=index($s_qu[1], "soft-treshold:"); |
122 |
$j=substr($s_qu[0], $j+14, 5); $j=$j+0; |
102 |
$j=substr($s_qu[1], $j+14, 5); $j=$j+0; |
123 |
$p3="Current soft treshold is <b>$j%</b>. It means that after reaching of $j percents of some quota, the notification message could be sent.<br> You can specify another value here: <input type=text name=soft_val value=$j size=4><input type=submit name=soft value=Apply><br><hr>"; |
103 |
$p3="Current soft treshold is <b>$j%</b>. It means that after reaching of $j percents of some quota, the notification message could be sent.<br> You can specify another value here: <input type=text name=soft_val value=$j size=4><input type=submit name=soft value=Apply><br><hr>"; |
124 |
|
104 |
|
125 |
$nss_s="checked" if (index($s_qu[1], "soft {owner}")!=-1); |
105 |
$nss_s="checked" if (index($s_qu[2], "soft owner")!=-1); |
126 |
$nhs_s="checked" if (index($s_qu[1], "hard {owner}")!=-1); |
106 |
$nhs_s="checked" if (index($s_qu[2], "hard owner")!=-1); |
127 |
$nrs_s="checked" if (index($s_qu[1], "return {owner}")!=-1); |
107 |
$nrs_s="checked" if (index($s_qu[2], "return owner")!=-1); |
128 |
|
108 |
|
129 |
$j=index($s_qu[1], "soft"); if (defined $nss_s) { $j+=13; } else { $j+=5; } |
109 |
$j=index($s_qu[2], "soft"); if (defined $nss_s) { $j+=11; } else { $j+=3; } |
130 |
$k=index($s_qu[1], ",", $j); $nso_s=substr($s_qu[1], $j, $k-$j); |
110 |
$k=index($s_qu[2], ",", $j); $nso_s=substr($s_qu[2], $j, $k-$j); |
131 |
|
111 |
|
132 |
$j=index($s_qu[1], "hard"); if (defined $nhs_s) { $j+=13; } else { $j+=5; } |
112 |
$j=index($s_qu[2], "hard"); if (defined $nhs_s) { $j+=11; } else { $j+=3; } |
133 |
$k=index($s_qu[1], ",", $j); $nho_s=substr($s_qu[1], $j, $k-$j); |
113 |
$k=index($s_qu[2], ",", $j); $nho_s=substr($s_qu[2], $j, $k-$j); |
134 |
|
114 |
|
135 |
$j=index($s_qu[1], "return"); if (defined $nrs_s) { $j+=15; } else { $j+=7; } |
115 |
$j=index($s_qu[2], "return"); if (defined $nrs_s) { $j+=12; } else { $j+=5; } |
136 |
$nro_s=substr($s_qu[1], $j); |
116 |
$nro_s=substr($s_qu[2], $j); |
137 |
|
117 |
|
138 |
$p4="Users and unit owners to be notified on quota actions. Select <b>owner</b> and/or type an existing <b>user</b> name.<br>\n"; |
118 |
$p4="Users and unit owners to be notified on quota actions. Select <b>owner</b> and/or type an existing <b>user</b> name.<br>\n"; |
139 |
$p4.="<table border=1 width=80% cellpadding=3 cellspacing=0><tr align=center bgcolor=#cccccc><td><b>Soft reach</b></td><td><b>Hard reach</b></td><td><b>Return</b></td><td rowspan=2 valign=center><input type=submit name=notify value=Apply></td></tr>"; |
119 |
$p4.="<table border=1 width=80% cellpadding=3 cellspacing=0><tr align=center bgcolor=#cccccc><td><b>Soft reach</b></td><td><b>Hard reach</b></td><td><b>Return</b></td><td rowspan=2 valign=center><input type=submit name=notify value=Apply></td></tr>"; |
Lines 142-151
Link Here
|
142 |
$p4.="<td>owner <input type=checkbox $nrs_s name=notify_return_owner><br>user: <input type=text name=notify_return_name value='".$nro_s."' size=10></td></tr></table>"; |
122 |
$p4.="<td>owner <input type=checkbox $nrs_s name=notify_return_owner><br>user: <input type=text name=notify_return_name value='".$nro_s."' size=10></td></tr></table>"; |
143 |
$p4.="<br><hr>\n"; |
123 |
$p4.="<br><hr>\n"; |
144 |
|
124 |
|
145 |
$q_h_in=q_getval($result, "HOUR in:"); $q_h_out=q_getval($result, "HOUR out:"); $q_h_sum=q_getval($result, "HOUR sum:"); |
125 |
$q_h_in=q_getval($result, "HOUR","in"); $q_h_out=q_getval($result, "HOUR","out"); $q_h_sum=q_getval($result, "HOUR","sum"); |
146 |
$q_d_in=q_getval($result, "DAY in:"); $q_d_out=q_getval($result, "DAY out:"); $q_d_sum=q_getval($result, "DAY sum:"); |
126 |
$q_d_in=q_getval($result, "DAY","in"); $q_d_out=q_getval($result, "DAY","out"); $q_d_sum=q_getval($result, "DAY","sum"); |
147 |
$q_w_in=q_getval($result, "WEEK in:"); $q_w_out=q_getval($result, "WEEK out:"); $q_w_sum=q_getval($result, "WEEK sum:"); |
127 |
$q_w_in=q_getval($result, "WEEK","in"); $q_w_out=q_getval($result, "WEEK","out"); $q_w_sum=q_getval($result, "WEEK","sum"); |
148 |
$q_m_in=q_getval($result, "MONTH in:"); $q_m_out=q_getval($result, "MONTH out:"); $q_m_sum=q_getval($result, "MONTH sum:"); |
128 |
$q_m_in=q_getval($result, "MONTH","in"); $q_m_out=q_getval($result, "MONTH","out"); $q_m_sum=q_getval($result, "MONTH","sum"); |
149 |
|
129 |
|
150 |
$p5="You can change quota values here. Please specify '-1' if you wish to skip this quota.<br>\n"; |
130 |
$p5="You can change quota values here. Please specify '-1' if you wish to skip this quota.<br>\n"; |
151 |
$p5.="<table border=1 width=80% cellpadding=3 cellspacing=0><tr align=center bgcolor=#cccccc><td> </td><td><b>IN</b></td><td><b>OUT</b></td><td><b>SUM</b></td><td rowspan=6 valign=center><input type=submit name=quotas value=Apply></td></tr>"; |
131 |
$p5.="<table border=1 width=80% cellpadding=3 cellspacing=0><tr align=center bgcolor=#cccccc><td> </td><td><b>IN</b></td><td><b>OUT</b></td><td><b>SUM</b></td><td rowspan=6 valign=center><input type=submit name=quotas value=Apply></td></tr>"; |
Lines 173-183
Link Here
|
173 |
sub q_getval(){ |
153 |
sub q_getval(){ |
174 |
$s1=shift; |
154 |
$s1=shift; |
175 |
$s2=shift; |
155 |
$s2=shift; |
176 |
$j=index($s1, $s2); |
156 |
$s3=shift; |
177 |
if ($j == -1) { return 0; } |
157 |
my @s=grep(/^\s+$s2\s+$s3:.+hardquota/,split("\n",$s1)); |
178 |
$j2=index($s1, "hardquota ", $j); |
158 |
return 0 if $#s<0; |
179 |
$j=$j2+10; |
159 |
$s[0] =~ /quota\s(\d+(\.\d+)?[KMG]?)/; |
180 |
$j2=index($s1, ' ratio', $j); |
160 |
return $1; |
181 |
$r=substr($s1, $j, $j2-$j); |
|
|
182 |
return "'$r'"; |
183 |
} |
161 |
} |