1
|
<?php
|
2
|
/* $Id$ */
|
3
|
/*
|
4
|
firewall_shaper_queues.php
|
5
|
Copyright (C) 2004, 2005 Scott Ullrich
|
6
|
Copyright (C) 2008 Ermal Lu?i
|
7
|
All rights reserved.
|
8
|
|
9
|
Redistribution and use in source and binary forms, with or without
|
10
|
modification, are permitted provided that the following conditions are met:
|
11
|
|
12
|
1. Redistributions of source code must retain the above copyright notice,
|
13
|
this list of conditions and the following disclaimer.
|
14
|
|
15
|
2. Redistributions in binary form must reproduce the above copyright
|
16
|
notice, this list of conditions and the following disclaimer in the
|
17
|
documentation and/or other materials provided with the distribution.
|
18
|
|
19
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
20
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
21
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
22
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
23
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
24
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
25
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
26
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
27
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
28
|
POSSIBILITY OF SUCH DAMAGE.
|
29
|
*/
|
30
|
|
31
|
##|+PRIV
|
32
|
##|*IDENT=page-firewall-trafficshaper-queues
|
33
|
##|*NAME=Firewall: Traffic Shaper: Queues page
|
34
|
##|*DESCR=Allow access to the 'Firewall: Traffic Shaper: Queues' page.
|
35
|
##|*MATCH=firewall_shaper_queues.php*
|
36
|
##|-PRIV
|
37
|
|
38
|
|
39
|
require("guiconfig.inc");
|
40
|
|
41
|
if($_GET['reset'] <> "") {
|
42
|
mwexec("killall -9 pfctl php");
|
43
|
exit;
|
44
|
}
|
45
|
|
46
|
read_altq_config();
|
47
|
$qlist =& get_unique_queue_list();
|
48
|
|
49
|
if (!is_array($qlist))
|
50
|
$qlist = array();
|
51
|
|
52
|
$tree = "<ul class=\"tree\" >";
|
53
|
foreach ($qlist as $queue => $qkey) {
|
54
|
$tree .= "<li><a href=\"firewall_shaper_queues.php?queue={$queue}&action=show\" >{$queue}</a></li>";
|
55
|
}
|
56
|
$tree .= "</ul>";
|
57
|
|
58
|
if ($_GET) {
|
59
|
if ($_GET['queue'])
|
60
|
$qname = trim($_GET['queue']);
|
61
|
if ($_GET['interface'])
|
62
|
$interface = trim($_GET['interface']);
|
63
|
if ($_GET['action'])
|
64
|
$action = $_GET['action'];
|
65
|
|
66
|
switch ($action) {
|
67
|
case "delete":
|
68
|
$altq =& $altq_list_queues[$interface];
|
69
|
$qtmp =& $altq->find_queue("", $qname);
|
70
|
if ($qtmp) {
|
71
|
$qtmp->delete_queue();
|
72
|
write_config();
|
73
|
touch($d_shaperconfdirty_path);
|
74
|
}
|
75
|
header("Location: firewall_shaper_queues.php");
|
76
|
exit;
|
77
|
break;
|
78
|
case "add":
|
79
|
/*
|
80
|
* XXX: WARNING: This returns the first it finds.
|
81
|
* Maybe the user expects something else?!
|
82
|
*/
|
83
|
foreach ($altq_list_queues as $altq) {
|
84
|
$qtmp =& $altq->find_queue("", $qname);
|
85
|
if ($qtmp) {
|
86
|
$copycfg = array();
|
87
|
$qtmp->copy_queue($interface, &$copycfg);
|
88
|
$aq =& $altq_list_queues[$interface];
|
89
|
if ($qname == $qtmp->GetInterface()) {
|
90
|
$config['shaper']['queue'][] = $copycfg;
|
91
|
} else if ($aq) {
|
92
|
$tmp1 =& $qtmp->find_parentqueue($interface, $qname);
|
93
|
if ($tmp1)
|
94
|
$tmp =& $aq->find_queue($interface, $tmp1->GetQname());
|
95
|
|
96
|
if ($tmp)
|
97
|
$link =& get_reference_to_me_in_config($tmp->GetLink());
|
98
|
else
|
99
|
$link =& get_reference_to_me_in_config($aq->GetLink());
|
100
|
$link['queue'][] = $copycfg;
|
101
|
} else {
|
102
|
$newroot = array();
|
103
|
$newroot['name'] = $interface;
|
104
|
$newroot['interface'] = $interface;
|
105
|
$newroot['scheduler'] = $altq->GetScheduler();
|
106
|
$newroot['queue'] = array();
|
107
|
$newroot['queue'][] = $copycfg;
|
108
|
$config['shaper']['queue'][] = $newroot;
|
109
|
}
|
110
|
write_config();
|
111
|
touch($d_shaperconfdirty_path);
|
112
|
break;
|
113
|
}
|
114
|
}
|
115
|
|
116
|
header("Location: firewall_shaper_queues.php?queue=".$qname."&action=show");
|
117
|
exit;
|
118
|
break;
|
119
|
case "show":
|
120
|
foreach ($config['interfaces'] as $if => $ifdesc) {
|
121
|
$altq = $altq_list_queues[$if];
|
122
|
if ($altq) {
|
123
|
$qtmp =& $altq->find_queue("", $qname);
|
124
|
if ($qtmp)
|
125
|
$output .= $qtmp->build_shortform();
|
126
|
else
|
127
|
$output .= build_iface_without_this_queue($if, $qname);
|
128
|
} else {
|
129
|
if (!is_altq_capable($ifdesc['if']))
|
130
|
continue;
|
131
|
if (!isset($ifdesc['enable']) && $if != "lan" && $if != "wan")
|
132
|
continue;
|
133
|
$output .= build_iface_without_this_queue($if, $qname);
|
134
|
}
|
135
|
}
|
136
|
break;
|
137
|
}
|
138
|
}
|
139
|
|
140
|
if ($_POST['apply']) {
|
141
|
write_config();
|
142
|
|
143
|
$retval = 0;
|
144
|
$savemsg = get_std_save_message($retval);
|
145
|
/* Setup pf rules since the user may have changed the optimization value */
|
146
|
|
147
|
config_lock();
|
148
|
$retval = filter_configure();
|
149
|
config_unlock();
|
150
|
if (stristr($retval, "error") <> true)
|
151
|
$savemsg = get_std_save_message($retval);
|
152
|
else
|
153
|
$savemsg = $retval;
|
154
|
|
155
|
/* reset rrd queues */
|
156
|
system("rm -f /var/db/rrd/*queuedrops.rrd");
|
157
|
system("rm -f /var/db/rrd/*queues.rrd");
|
158
|
enable_rrd_graphing();
|
159
|
|
160
|
unlink($d_shaperconfdirty_path);
|
161
|
}
|
162
|
|
163
|
$pgtitle = "Firewall: Shaper: By Queues View";
|
164
|
|
165
|
include("head.inc");
|
166
|
?>
|
167
|
<link rel="stylesheet" type="text/css" media="all" href="./tree/tree.css" />
|
168
|
<script type="text/javascript" src="./tree/tree.js"></script>
|
169
|
|
170
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
171
|
<?php include("fbegin.inc"); ?>
|
172
|
<div id="inputerrors"></div>
|
173
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
174
|
<form action="firewall_shaper_queues.php" method="post" name="iform" id="iform">
|
175
|
<?php if ($savemsg) print_info_box($savemsg); ?>
|
176
|
<?php if (file_exists($d_shaperconfdirty_path)): ?><p>
|
177
|
<?php print_info_box_np("The traffic shaper configuration has been changed.<br>You must apply the changes in order for them to take effect.");?><br>
|
178
|
<?php endif; ?>
|
179
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
180
|
<tr><td>
|
181
|
<?php
|
182
|
$tab_array = array();
|
183
|
$tab_array[0] = array("By Interface", false, "firewall_shaper.php");
|
184
|
$tab_array[1] = array("By Queue", true, "firewall_shaper_queues.php");
|
185
|
$tab_array[2] = array("Limiter", false, "firewall_shaper_vinterface.php");
|
186
|
$tab_array[3] = array("Wizards", false, "firewall_shaper_wizards.php");
|
187
|
display_top_tabs($tab_array);
|
188
|
?>
|
189
|
</td></tr>
|
190
|
<tr>
|
191
|
<td valign="top">
|
192
|
<div id="mainarea">
|
193
|
<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
|
194
|
<tr>
|
195
|
<td width="30%" valign="top" algin="left">
|
196
|
<? echo $tree; ?>
|
197
|
</td>
|
198
|
<td width="70%" valign="top" align="center">
|
199
|
<?
|
200
|
if ($qname)
|
201
|
echo "<pr class=\"pgtitle\">" . $qname . "</pr><br />";
|
202
|
echo "<table align=\"center\" class=\"tabcont\" width=\"80%\" border=\"0\" cellpadding=\"4\" cellspacing=\"0\">";
|
203
|
echo $output;
|
204
|
echo "</table>";
|
205
|
?>
|
206
|
</td></tr>
|
207
|
</table>
|
208
|
|
209
|
</td></tr>
|
210
|
</div>
|
211
|
</td>
|
212
|
</tr>
|
213
|
</table>
|
214
|
</form>
|
215
|
<?php include("fend.inc");
|
216
|
?>
|
217
|
</body>
|
218
|
</html>
|