Project

General

Profile

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