Project

General

Profile

Download (13.2 KB) Statistics
| Branch: | Tag: | Revision:
1 585a8faf Ermal Luçi
<?php
2
/* $Id$ */
3
/*
4 a368a026 Ermal Lu?i
	firewall_shaper_vinterface.php
5 585a8faf Ermal Luçi
	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 70b139a3 Chris Buechler
20 585a8faf Ermal Luçi
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30
*/
31 7ac5a4cb Scott Ullrich
/*
32
	pfSense_BUILDER_BINARIES:	/usr/bin/killall
33
	pfSense_MODULE:	shaper
34
*/
35 585a8faf Ermal Luçi
36 6b07c15a Matthew Grooms
##|+PRIV
37
##|*IDENT=page-firewall-trafficshaper-limiter
38
##|*NAME=Firewall: Traffic Shaper: Limiter page
39
##|*DESCR=Allow access to the 'Firewall: Traffic Shaper: Limiter' page.
40
##|*MATCH=firewall_shaper_vinterface.php*
41
##|-PRIV
42
43 585a8faf Ermal Luçi
require("guiconfig.inc");
44 7a927e67 Scott Ullrich
require_once("functions.inc");
45
require_once("filter.inc");
46
require_once("shaper.inc");
47 585a8faf Ermal Luçi
48
if($_GET['reset'] <> "") {
49 4aea91d8 Ermal
	mwexec("/usr/bin/killall -9 pfctl");
50 585a8faf Ermal Luçi
	exit;
51
}
52
53 bb6e50d3 Rafael Lucas
$pgtitle = array(gettext("Firewall"),gettext("Traffic Shaper"), gettext("Limiter"));
54 d71fc5d3 jim-p
$shortcut_section = "trafficshaper-limiters";
55 585a8faf Ermal Luçi
56
read_dummynet_config();
57
/* 
58
 * The whole logic in these code maybe can be specified.
59
 * If you find a better way contact me :).
60
 */
61
62
if ($_GET) {
63
	if ($_GET['queue'])
64 daab67a1 Scott Ullrich
        	$qname = htmlspecialchars(trim($_GET['queue']));
65 585a8faf Ermal Luçi
        if ($_GET['pipe'])
66 daab67a1 Scott Ullrich
                $pipe = htmlspecialchars(trim($_GET['pipe']));
67 585a8faf Ermal Luçi
        if ($_GET['action'])
68 daab67a1 Scott Ullrich
                $action = htmlspecialchars($_GET['action']);
69 585a8faf Ermal Luçi
}
70
if ($_POST) {
71
	if ($_POST['name'])
72 daab67a1 Scott Ullrich
        	$qname = htmlspecialchars(trim($_POST['name']));
73 1cbe86f0 Ermal
	else if ($_POST['newname'])
74 6be14e38 Ermal
        	$qname = htmlspecialchars(trim($_POST['newname']));
75 585a8faf Ermal Luçi
        if ($_POST['pipe'])
76 daab67a1 Scott Ullrich
        	$pipe = htmlspecialchars(trim($_POST['pipe']));
77 d3e5e7df Ermal Luçi
	else
78 1cbe86f0 Ermal
		$pipe = htmlspecialchars(trim($qname));
79 585a8faf Ermal Luçi
	if ($_POST['parentqueue'])
80 daab67a1 Scott Ullrich
		$parentqueue = htmlspecialchars(trim($_POST['parentqueue']));
81 585a8faf Ermal Luçi
}
82
83
if ($pipe) {
84
	$dnpipe = $dummynet_pipe_list[$pipe];
85
	if ($dnpipe) {
86
		$queue =& $dnpipe->find_queue($pipe, $qname);
87
	} else $addnewpipe = true;
88
}
89
90
$dontshow = false;
91
$newqueue = false;
92
$output_form = "";
93
94
if ($_GET) {
95
	switch ($action) {
96
	case "delete":
97 85a236e9 Ermal
		if ($queue) {
98
			if (is_array($config['filter']['rule'])) {
99
				foreach ($config['filter']['rule'] as $rule) {
100 184c7952 bcyrill
					if ($rule['dnpipe'] == $queue->GetQname() || $rule['pdnpipe'] == $queue->GetQname())
101 9aca7390 Chris Buechler
						$input_errors[] = gettext("This pipe/queue is referenced in filter rules, please remove references from there before deleting.");
102 1cbe86f0 Ermal
				}
103 585a8faf Ermal Luçi
			}
104 85a236e9 Ermal
			if (!$input_errors) {
105
				$queue->delete_queue();
106 3a343d73 jim-p
				if (write_config())
107
					mark_subsystem_dirty('shaper');
108 85a236e9 Ermal
				header("Location: firewall_shaper_vinterface.php");
109
				exit;
110
			}
111
			$output_form .= $queue->build_form();
112
		} else {
113
			$input_errors[] = sprintf(gettext("No queue with name %s was found!"),$qname);
114 a8f63907 Colin Fleming
			$output_form .= $dn_default_shaper_msg;
115 85a236e9 Ermal
			$dontshow = true;
116
		}
117 585a8faf Ermal Luçi
		break;
118
	case "resetall":
119 85a236e9 Ermal
		foreach ($dummynet_pipe_list as $dn)
120
			$dn->delete_queue();
121
		unset($dummynet_pipe_list);
122
		$dummynet_pipe_list = array();
123
		unset($config['dnshaper']['queue']);
124
		unset($queue);
125
		unset($pipe);
126
		$can_add = false;
127
		$can_enable = false;
128
		$dontshow = true;
129
		foreach ($config['filter']['rule'] as $key => $rule) {
130
			if (isset($rule['dnpipe']))
131
				unset($config['filter']['rule'][$key]['dnpipe']);
132
			if (isset($rule['pdnpipe']))
133
				unset($config['filter']['rule'][$key]['pdnpipe']);
134
		}
135 3a343d73 jim-p
		if (write_config()) {
136
			$retval = 0;
137
			$retval = filter_configure();
138 85a236e9 Ermal
			$savemsg = get_std_save_message($retval);
139
140 3a343d73 jim-p
			if (stristr($retval, "error") <> true)
141
				$savemsg = get_std_save_message($retval);
142
			else
143
				$savemsg = $retval;
144
		} else
145
			$savemsg = gettext("Unable to write config.xml (Access Denied?)");
146 85a236e9 Ermal
		$output_form = $dn_default_shaper_message;
147 585a8faf Ermal Luçi
148
		break;
149
	case "add":
150
		if ($dnpipe) {
151 d3e5e7df Ermal Luçi
			$q = new dnqueue_class();
152
			$q->SetPipe($pipe);
153
			$output_form .= "<input type=\"hidden\" name=\"parentqueue\" id=\"parentqueue\"";
154 2174be22 Colin Fleming
			$output_form .= " value=\"".$pipe."\" />";
155 585a8faf Ermal Luçi
		} else if ($addnewpipe) {
156
			$q = new dnpipe_class();
157
			$q->SetQname($pipe);
158
		} else 
159 d8a8bb73 Rafael Lucas
			$input_errors[] = gettext("Could not create new queue/discipline!");
160 585a8faf Ermal Luçi
161 85a236e9 Ermal
		if ($q) {
162
			$output_form .= $q->build_form();
163 09a49064 bcyrill
			$newjavascript = $q->build_javascript();
164 85a236e9 Ermal
			unset($q);
165
			$newqueue = true;
166
		}
167 585a8faf Ermal Luçi
		break;
168 d3e5e7df Ermal Luçi
	case "show":
169
		if ($queue)  
170
                       $output_form .= $queue->build_form();
171
		else
172 d8a8bb73 Rafael Lucas
			$input_errors[] = gettext("Queue not found!");
173 585a8faf Ermal Luçi
		break;
174 d3e5e7df Ermal Luçi
	case "enable":
175
		if ($queue) {
176 85a236e9 Ermal
			$queue->SetEnabled("on");
177
			$output_form .= $queue->build_form();
178
			$queue->wconfig();
179 3a343d73 jim-p
			if (write_config())
180
				mark_subsystem_dirty('shaper');
181 d3e5e7df Ermal Luçi
		} else
182 85a236e9 Ermal
			$input_errors[] = gettext("Queue not found!");
183 585a8faf Ermal Luçi
		break;
184 d3e5e7df Ermal Luçi
	case "disable":
185
		if ($queue) {
186 85a236e9 Ermal
			$queue->SetEnabled("");
187
			$output_form .= $queue->build_form();
188
			$queue->wconfig();
189 3a343d73 jim-p
			if (write_config())
190
				mark_subsystem_dirty('shaper');
191 d3e5e7df Ermal Luçi
		} else
192 85a236e9 Ermal
			$input_errors[] = gettext("Queue not found!");
193 d3e5e7df Ermal Luçi
		break;
194
	default:
195 a8f63907 Colin Fleming
		$output_form .= $dn_default_shaper_msg;
196 d3e5e7df Ermal Luçi
		$dontshow = true;
197 585a8faf Ermal Luçi
		break;
198
	}
199
} else if ($_POST) {
200
	unset($input_errors);
201
202
	if ($addnewpipe) {
203 85a236e9 Ermal
		if (!empty($dummynet_pipe_list[$qname]))
204
			$input_errors[] = gettext("You cannot name a child queue with the same name as a parent limiter");
205
		else {
206
			$dnpipe =& new dnpipe_class();
207
			
208
			$dnpipe->ReadConfig($_POST);
209 ea51e9f8 Renato Botelho
			$dnpipe->validate_input($_POST, $input_errors);
210 85a236e9 Ermal
			if (!$input_errors) {
211
				$number = dnpipe_find_nextnumber();
212
				$dnpipe->SetNumber($number);
213
				unset($tmppath);
214
				$tmppath[] = $dnpipe->GetQname();
215 ea51e9f8 Renato Botelho
				$dnpipe->SetLink($tmppath);	
216 85a236e9 Ermal
				$dnpipe->wconfig();
217 3a343d73 jim-p
				if (write_config())
218
					mark_subsystem_dirty('shaper');
219 85a236e9 Ermal
				$can_enable = true;
220
				$can_add = true;
221
			}
222 3a343d73 jim-p
223 85a236e9 Ermal
			read_dummynet_config();
224
			$output_form .= $dnpipe->build_form();
225 2c7bdd05 bcyrill
			$newjavascript = $dnpipe->build_javascript();
226 585a8faf Ermal Luçi
		}
227
	} else if ($parentqueue) { /* Add a new queue */
228 85a236e9 Ermal
		if (!empty($dummynet_pipe_list[$qname]))
229
			$input_errors[] = gettext("You cannot name a child queue with the same name as a parent limiter");
230
		else if ($dnpipe) {
231 585a8faf Ermal Luçi
			$tmppath =& $dnpipe->GetLink();
232
			array_push($tmppath, $qname);
233 ea51e9f8 Renato Botelho
			$tmp =& $dnpipe->add_queue($pipe, $_POST, $tmppath, $input_errors);
234 585a8faf Ermal Luçi
			if (!$input_errors) {
235
				array_pop($tmppath);
236
				$tmp->wconfig();
237 3a343d73 jim-p
				if (write_config()) {
238
					$can_enable = true;
239
					$can_add = false;
240
					mark_subsystem_dirty('shaper');
241
				}
242 585a8faf Ermal Luçi
			}
243 d3e5e7df Ermal Luçi
			read_dummynet_config();
244 3a343d73 jim-p
			$output_form .= $tmp->build_form();
245 585a8faf Ermal Luçi
		} else
246 d8a8bb73 Rafael Lucas
			$input_errors[] = gettext("Could not add new queue.");
247 585a8faf Ermal Luçi
	} else if ($_POST['apply']) {
248
			write_config();
249
250
			$retval = 0;
251
			$retval = filter_configure();
252 0027de0a Ermal Lu?i
			$savemsg = get_std_save_message($retval);
253 585a8faf Ermal Luçi
			
254
			if (stristr($retval, "error") <> true)
255
					$savemsg = get_std_save_message($retval);
256
			else
257
					$savemsg = $retval;
258
259 d3e5e7df Ermal Luçi
 		/* XXX: TODO Make dummynet pretty graphs */ 
260
		//	enable_rrd_graphing();
261 585a8faf Ermal Luçi
262 a368a026 Ermal Lu?i
			clear_subsystem_dirty('shaper');
263 585a8faf Ermal Luçi
			
264
			if ($queue) {
265
				$output_form .= $queue->build_form();
266
				$dontshow = false;
267
			}
268
			else {
269
				$output_form .= $dn_default_shaper_message;
270
				$dontshow = true;
271
			}
272
273
	} else if ($queue) {
274 ea51e9f8 Renato Botelho
                $queue->validate_input($_POST, $input_errors);
275 585a8faf Ermal Luçi
                if (!$input_errors) {
276 85a236e9 Ermal
			$queue->update_dn_data($_POST);
277
			$queue->wconfig();
278 3a343d73 jim-p
			if (write_config())
279
				mark_subsystem_dirty('shaper');
280 85a236e9 Ermal
			$dontshow = false;
281 585a8faf Ermal Luçi
                } 
282 d3e5e7df Ermal Luçi
		read_dummynet_config();
283
		$output_form .= $queue->build_form();
284 585a8faf Ermal Luçi
	} else  {
285 a8f63907 Colin Fleming
		$output_form .= $dn_default_shaper_msg;
286 585a8faf Ermal Luçi
		$dontshow = true;
287
	}
288
} else {
289 a8f63907 Colin Fleming
	$output_form .= $dn_default_shaper_msg;
290 585a8faf Ermal Luçi
	$dontshow = true;
291
}
292
293
if ($queue) {
294
                        if ($queue->GetEnabled())
295
                                $can_enable = true;
296
                        else
297
                                $can_enable = false;
298 70b139a3 Chris Buechler
                        if ($queue->CanHaveChildren()) { 
299 d3e5e7df Ermal Luçi
                       		$can_add = true;
300 585a8faf Ermal Luçi
                        } else
301
                                $can_add = false;
302
}
303
304
$tree = "<ul class=\"tree\" >";
305
if (is_array($dummynet_pipe_list)) {
306
        foreach ($dummynet_pipe_list as $tmpdn) {
307
                $tree .= $tmpdn->build_tree();
308
        }
309
}
310
$tree .= "</ul>";
311
312
if (!$dontshow || $newqueue) {
313
314
$output_form .= "<tr><td width=\"22%\" valign=\"top\" class=\"vncellreq\">";
315 d8a8bb73 Rafael Lucas
$output_form .= gettext("Queue Actions");
316 585a8faf Ermal Luçi
$output_form .= "</td><td valign=\"top\" class=\"vncellreq\" width=\"78%\">";
317
318
$output_form .= "<input type=\"submit\" name=\"Submit\" value=\"" . gettext("Save") . "\" class=\"formbtn\" />";
319
if ($can_add || $addnewaltq) {
320
	$output_form .= "<a href=\"firewall_shaper_vinterface.php?pipe=";
321
	$output_form .= $pipe; 
322
	if ($queue) {
323 2174be22 Colin Fleming
		$output_form .= "&amp;queue=" . $queue->GetQname();
324 585a8faf Ermal Luçi
	}
325 2174be22 Colin Fleming
	$output_form .= "&amp;action=add\">";
326
	$output_form .= "<input type=\"button\" class=\"formbtn\" name=\"add\" value=\"" . gettext("Add new queue") ."\" />";
327 585a8faf Ermal Luçi
	$output_form .= "</a>";
328
}
329 d3e5e7df Ermal Luçi
$output_form .= "<a href=\"firewall_shaper_vinterface.php?pipe=";
330 09a49064 bcyrill
$output_form .= $pipe;
331 d3e5e7df Ermal Luçi
if ($queue) {
332 2174be22 Colin Fleming
	$output_form .= "&amp;queue=" . $queue->GetQname();
333 d3e5e7df Ermal Luçi
}
334 2174be22 Colin Fleming
$output_form .= "&amp;action=delete\">";
335 d3e5e7df Ermal Luçi
$output_form .= "<input type=\"button\" class=\"formbtn\" name=\"delete\"";
336
if ($queue)
337 2174be22 Colin Fleming
	$output_form .= " value=\"" . gettext("Delete this queue") ."\" />";
338 d3e5e7df Ermal Luçi
else
339 2174be22 Colin Fleming
	$output_form .= " value=\"" . gettext("Delete virtual interface") ."\" />";
340 d3e5e7df Ermal Luçi
$output_form .= "</a>";  
341 585a8faf Ermal Luçi
$output_form .= "</td></tr>";
342 a8f63907 Colin Fleming
$output_form .= "</table>";
343 585a8faf Ermal Luçi
} 
344
else 
345 a8f63907 Colin Fleming
	$output_form .= "</table>";
346 585a8faf Ermal Luçi
347 a8f63907 Colin Fleming
$output = "<table summary=\"output form\">";
348 585a8faf Ermal Luçi
$output .= $output_form;
349 2174be22 Colin Fleming
$closehead = false;
350 585a8faf Ermal Luçi
include("head.inc");
351
?>
352
<link rel="stylesheet" type="text/css" media="all" href="./tree/tree.css" />
353
<script type="text/javascript" src="./tree/tree.js"></script>
354 b7d124fe Ermal Luçi
<script type="text/javascript">
355 2174be22 Colin Fleming
//<![CDATA[
356 b7d124fe Ermal Luçi
function show_source_port_range() {
357
        document.getElementById("sprtable").style.display = '';
358 12a72ca1 Ermal Luçi
	document.getElementById("sprtable1").style.display = '';
359
	document.getElementById("sprtable2").style.display = '';
360 cc72f352 Ermal Luçi
	document.getElementById("sprtable5").style.display = '';
361
	document.getElementById("sprtable4").style.display = 'none';
362
	document.getElementById("showadvancedboxspr").innerHTML='';
363 b7d124fe Ermal Luçi
}
364 2174be22 Colin Fleming
//]]>
365 b7d124fe Ermal Luçi
</script>
366 2174be22 Colin Fleming
</head>
367
368
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
369 b7d124fe Ermal Luçi
370 585a8faf Ermal Luçi
<?php
371 c9ba2f8a Ermal
if ($queue)
372
	echo $queue->build_javascript();
373 fbfed5ba Ermal
else
374
	echo $newjavascript;
375 c9ba2f8a Ermal
376 585a8faf Ermal Luçi
include("fbegin.inc"); 
377
?>
378
<div id="inputerrors"></div>
379
<?php if ($input_errors) print_input_errors($input_errors); ?>
380
381
<form action="firewall_shaper_vinterface.php" method="post" id="iform" name="iform">
382
383
<?php if ($savemsg) print_info_box($savemsg); ?>
384 a368a026 Ermal Lu?i
<?php if (is_subsystem_dirty('shaper')): ?><p>
385 2174be22 Colin Fleming
<?php print_info_box_np(gettext("The traffic shaper configuration has been changed.")."<br/>".gettext("You must apply the changes in order for them to take effect."));?><br/></p>
386 585a8faf Ermal Luçi
<?php endif; ?>
387 2174be22 Colin Fleming
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="traffic shaper limiter">
388 585a8faf Ermal Luçi
  <tr><td>
389
<?php
390
	$tab_array = array();
391 d8a8bb73 Rafael Lucas
	$tab_array[0] = array(gettext("By Interface"), false, "firewall_shaper.php");
392
	$tab_array[1] = array(gettext("By Queue"), false, "firewall_shaper_queues.php");
393
	$tab_array[2] = array(gettext("Limiter"), true, "firewall_shaper_vinterface.php");
394
	$tab_array[3] = array(gettext("Layer7"), false, "firewall_shaper_layer7.php");
395
	$tab_array[4] = array(gettext("Wizards"), false, "firewall_shaper_wizards.php");
396 585a8faf Ermal Luçi
	display_top_tabs($tab_array);
397
?>
398
  </td></tr>
399
  <tr>
400
    <td>
401
	<div id="mainarea">
402 2174be22 Colin Fleming
              <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="main area">
403 585a8faf Ermal Luçi
<?php if (count($dummynet_pipe_list) > 0): ?>
404
                        <tr class="tabcont"><td width="25%" align="left">
405
                        </td><td width="75%"> </td></tr>
406 ee9933b6 Renato Botelho
<?php endif; ?>
407 585a8faf Ermal Luçi
			<tr>
408 2174be22 Colin Fleming
			<td width="25%" valign="top" align="left">
409 585a8faf Ermal Luçi
			<?php
410
				echo $tree; 
411
			?>
412 d3e5e7df Ermal Luçi
			<br/><br/>
413 2174be22 Colin Fleming
			<a href="firewall_shaper_vinterface.php?pipe=new&amp;action=add">
414 a8f63907 Colin Fleming
			<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="<?=gettext("Create new limiter");?>" width="17" height="17" border="0" alt="add" />&nbsp;<?=gettext("Create new limiter");?>
415 9bb1524c Ermal Luçi
			</a><br/>
416 585a8faf Ermal Luçi
			</td>
417
			<td width="75%" valign="top" align="center">
418 a8f63907 Colin Fleming
			<div id="shaperarea" style="position:relative">
419 2174be22 Colin Fleming
			<?php
420 585a8faf Ermal Luçi
				echo $output;
421
			?>	
422 a8f63907 Colin Fleming
			</div>
423 585a8faf Ermal Luçi
424
		      </td></tr>
425
                    </table>
426
		</div>
427
	  </td>
428
	</tr>
429
</table>
430 c9ba2f8a Ermal
</form>
431
<script type='text/javascript'>
432 2174be22 Colin Fleming
//<![CDATA[
433 c9ba2f8a Ermal
<?php
434
	$totalrows = 0;
435
	if (is_array($config['dnshaper']) && is_array($config['dnshaper']['queue'])) 
436
		$totalrows = count($config['dnshaper']['queue']);
437
	echo "totalrows = {$totalrows}";
438 585a8faf Ermal Luçi
?>
439 2174be22 Colin Fleming
//]]>
440 c9ba2f8a Ermal
</script>
441
<?php include("fend.inc"); ?>
442 585a8faf Ermal Luçi
</body>
443
</html>