Project

General

Profile

Download (13.6 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
<?php
2 b46bfcf5 Bill Marquette
/* $Id$ */
3 5b237745 Scott Ullrich
/*
4 197bfe96 Ermal Luçi
	firewall_shaper.php
5
	Copyright (C) 2004, 2005 Scott Ullrich
6
	Copyright (C) 2008 Ermal Lu?i
7
	All rights reserved.
8 b49448ac Scott Ullrich
9 197bfe96 Ermal Luçi
	Redistribution and use in source and binary forms, with or without
10
	modification, are permitted provided that the following conditions are met:
11 b49448ac Scott Ullrich
12 197bfe96 Ermal Luçi
	1. Redistributions of source code must retain the above copyright notice,
13
	   this list of conditions and the following disclaimer.
14 b49448ac Scott Ullrich
15 197bfe96 Ermal Luçi
	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 b49448ac Scott Ullrich
19 197bfe96 Ermal Luçi
	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 5b237745 Scott Ullrich
*/
30 7ac5a4cb Scott Ullrich
/*
31
	pfSense_BUILDER_BINARIES:	/usr/bin/killall
32
	pfSense_MODULE:	shaper
33
*/
34 5b237745 Scott Ullrich
35 6b07c15a Matthew Grooms
##|+PRIV
36
##|*IDENT=page-firewall-trafficshaper
37
##|*NAME=Firewall: Traffic Shaper page
38
##|*DESCR=Allow access to the 'Firewall: Traffic Shaper' page.
39
##|*MATCH=firewall_shaper.php*
40
##|-PRIV
41
42 5b237745 Scott Ullrich
require("guiconfig.inc");
43 7a927e67 Scott Ullrich
require_once("functions.inc");
44
require_once("filter.inc");
45
require_once("shaper.inc");
46 a5f07f09 Ermal Lu?i
require_once("rrd.inc");
47 5b237745 Scott Ullrich
48 1b2c6c29 Ermal Luçi
if($_GET['reset'] <> "") {
49 7ac5a4cb Scott Ullrich
	/* XXX: Huh, why are we killing php? */
50
	mwexec("killall -9 pfctl php");
51 8f8a97c8 Ermal Luçi
	exit;
52 1b2c6c29 Ermal Luçi
}
53
54 4e52fac4 Carlos Eduardo Ramos
$pgtitle = array(gettext("Firewall"),gettext("Traffic Shaper"));
55 b32dd0a6 jim-p
$shortcut_section = "trafficshaper";
56 09eafb8b Scott Ullrich
57 9d5b21c6 Ermal Luçi
$shaperIFlist = get_configured_interface_with_descr();
58 197bfe96 Ermal Luçi
read_altq_config();
59
/* 
60
 * The whole logic in these code maybe can be specified.
61
 * If you find a better way contact me :).
62
 */
63 57b89461 Scott Ullrich
64 197bfe96 Ermal Luçi
if ($_GET) {
65
	if ($_GET['queue'])
66
        	$qname = trim($_GET['queue']);
67
        if ($_GET['interface'])
68 daab67a1 Scott Ullrich
                $interface = htmlspecialchars(trim($_GET['interface']));
69 197bfe96 Ermal Luçi
        if ($_GET['action'])
70 daab67a1 Scott Ullrich
                $action = htmlspecialchars($_GET['action']);
71 197bfe96 Ermal Luçi
}
72
if ($_POST) {
73
	if ($_POST['name'])
74 daab67a1 Scott Ullrich
        	$qname = htmlspecialchars(trim($_POST['name']));
75 197bfe96 Ermal Luçi
        if ($_POST['interface'])
76 daab67a1 Scott Ullrich
                $interface = htmlspecialchars(trim($_POST['interface']));
77 197bfe96 Ermal Luçi
	if ($_POST['parentqueue'])
78 daab67a1 Scott Ullrich
		$parentqueue = htmlspecialchars(trim($_POST['parentqueue']));
79 57b89461 Scott Ullrich
}
80
81 197bfe96 Ermal Luçi
if ($interface) {
82
	$altq = $altq_list_queues[$interface];
83
	if ($altq) {
84
		$queue =& $altq->find_queue($interface, $qname);
85
	} else $addnewaltq = true;
86 57b89461 Scott Ullrich
}
87
88 197bfe96 Ermal Luçi
$dontshow = false;
89
$newqueue = false;
90 92125c97 Ermal Luçi
$output_form = "";
91 5b237745 Scott Ullrich
92 197bfe96 Ermal Luçi
if ($_GET) {
93
	switch ($action) {
94
	case "delete":
95
			if ($queue) {
96
				$queue->delete_queue();
97 3a343d73 jim-p
				if (write_config())
98
					mark_subsystem_dirty('shaper');
99 197bfe96 Ermal Luçi
			}
100
			header("Location: firewall_shaper.php");
101
			exit;
102
		break;
103 26dfbf80 Ermal Luçi
	case "resetall":
104
			foreach ($altq_list_queues as $altq)
105
				$altq->delete_all();
106
			unset($altq_list_queues);
107
			$altq_list_queues = array();
108
			$tree = "<ul class=\"tree\" >";
109
			$tree .= get_interface_list_to_show();
110
			$tree .= "</ul>";
111
			unset($config['shaper']['queue']);
112
			unset($queue);
113
			unset($altq);
114
			$can_add = false;
115
			$can_enable = false;
116
			$dontshow = true;
117
			foreach ($config['filter']['rule'] as $key => $rule) {
118
				if (isset($rule['wizard']) && $rule['wizard'] == "yes")
119
					unset($config['filter']['rule'][$key]);
120
			}
121 3a343d73 jim-p
			if (write_config()) {
122
				$retval = 0;
123
				$retval |= filter_configure();
124
				$savemsg = get_std_save_message($retval);
125 26dfbf80 Ermal Luçi
126 3a343d73 jim-p
				if (stristr($retval, "error") <> true)
127
					$savemsg = get_std_save_message($retval);
128
				else
129
					$savemsg = $retval;
130
			} else {
131
				$savemsg = gettext("Unable to write config.xml (Access Denied?)");
132
			}
133 26dfbf80 Ermal Luçi
			$output_form = $default_shaper_message;
134
135
		break;
136 197bfe96 Ermal Luçi
	case "add":
137
			/* XXX: Find better way because we shouldn't know about this */
138
		if ($altq) {
139
	                switch ($altq->GetScheduler()) {
140
         	        case "PRIQ":
141
                	        $q = new priq_queue();
142
                        	break;
143 c563b7a8 Ermal Luçi
			case "FAIRQ":
144
				$q = new fairq_queue();
145
				break;
146 197bfe96 Ermal Luçi
                        case "HFSC":
147
                         	$q = new hfsc_queue();
148
                        	break;
149
                        case "CBQ":
150
                                $q = new cbq_queue();
151
                        	break;
152
                        default:
153
                                /* XXX: Happens when sched==NONE?! */
154
				$q = new altq_root_queue();
155
                        	break;
156
        		}
157
		} else if ($addnewaltq) {
158
			$q = new altq_root_queue();
159
		} else 
160 1c52312d Jeann
			$input_errors[] = gettext("Could not create new queue/discipline!");
161 197bfe96 Ermal Luçi
162
			if ($q) {
163
				$q->SetInterface($interface);
164 92125c97 Ermal Luçi
				$output_form .= $q->build_form();
165
				$output_form .= "<input type=\"hidden\" name=\"parentqueue\" id=\"parentqueue\"";
166
				$output_form .= " value=\"".$qname."\">";
167 bdb0d479 Ermal Luçi
				$newjavascript = $q->build_javascript();
168 197bfe96 Ermal Luçi
                unset($q);
169
				$newqueue = true;
170
			}
171
		break;
172
		case "show":
173
			if ($queue)  
174 92125c97 Ermal Luçi
                        $output_form .= $queue->build_form();
175 197bfe96 Ermal Luçi
			else
176 1c52312d Jeann
					$input_errors[] = gettext("Queue not found!");
177 197bfe96 Ermal Luçi
		break;
178
		case "enable":
179
			if ($queue) {
180
					$queue->SetEnabled("on");
181 92125c97 Ermal Luçi
					$output_form .= $queue->build_form();
182 3a343d73 jim-p
					if (write_config())
183
						mark_subsystem_dirty('shaper');
184 197bfe96 Ermal Luçi
			} else
185 1c52312d Jeann
					$input_errors[] = gettext("Queue not found!");
186 197bfe96 Ermal Luçi
		break;
187
		case "disable":
188
			if ($queue) {
189
					$queue->SetEnabled("");
190 92125c97 Ermal Luçi
					$output_form .= $queue->build_form();
191 3a343d73 jim-p
					if (write_config())
192
						mark_subsystem_dirty('shaper');
193 197bfe96 Ermal Luçi
			} else
194 1c52312d Jeann
					$input_errors[] = gettext("Queue not found!");
195 197bfe96 Ermal Luçi
		break;
196
		default:
197 92125c97 Ermal Luçi
			$output_form .= "<p class=\"pgtitle\">" . $default_shaper_msg."</p>";
198 197bfe96 Ermal Luçi
			$dontshow = true;
199
			break;
200 5b237745 Scott Ullrich
	}
201 197bfe96 Ermal Luçi
} else if ($_POST) {
202
	unset($input_errors);
203 5b237745 Scott Ullrich
204 197bfe96 Ermal Luçi
	if ($addnewaltq) {
205
		$altq =& new altq_root_queue();
206
		$altq->SetInterface($interface);
207 92125c97 Ermal Luçi
		
208
		switch ($altq->GetBwscale()) {
209
				case "Mb":
210
					$factor = 1000 * 1000;
211
					brak;
212
				case "Kb":
213
					$factor = 1000;
214
					break;
215
				case "b":
216
					$factor = 1;
217
					break;
218
				case "Gb":
219
					$factor = 1000 * 1000 * 1000;
220
					break;
221
				case "%": /* We don't use it for root_XXX queues. */
222
				default: /* XXX assume Kb by default. */
223
					$factor = 1000;
224
					break;
225
			} 
226
		$altq->SetAvailableBandwidth($altq->GetBandwidth() * $factor);
227 197bfe96 Ermal Luçi
		$altq->ReadConfig($_POST);
228 92125c97 Ermal Luçi
		$altq->validate_input($_POST, &$input_errors);
229
		if (!$input_errors) {
230
			unset($tmppath);
231
			$tmppath[] = $altq->GetInterface();
232
			$altq->SetLink(&$tmppath);	
233
			$altq->wconfig();
234 3a343d73 jim-p
			if (write_config())
235
				mark_subsystem_dirty('shaper');
236 92125c97 Ermal Luçi
			$can_enable = true;
237 fce82460 Ermal Luçi
                        $can_add = true;
238 92125c97 Ermal Luçi
		}
239 48d418e8 Ermal Luçi
		read_altq_config();
240 92125c97 Ermal Luçi
		$output_form .= $altq->build_form();
241
242 197bfe96 Ermal Luçi
	} else if ($parentqueue) { /* Add a new queue */
243
		$qtmp =& $altq->find_queue($interface, $parentqueue);
244
		if ($qtmp) {
245
			$tmppath =& $qtmp->GetLink();
246
			array_push($tmppath, $qname);
247 cedae3d3 Ermal Luçi
			$tmp =& $qtmp->add_queue($interface, $_POST, $tmppath, &$input_errors);
248 92125c97 Ermal Luçi
			if (!$input_errors) {
249
				array_pop($tmppath);
250
				$tmp->wconfig();
251
				$can_enable = true;
252 70b139a3 Chris Buechler
				if ($tmp->CanHaveChildren() && $can_enable) {
253 fce82460 Ermal Luçi
					if ($tmp->GetDefault() <> "")
254 96d1d4ad Ermal Luçi
                             			$can_add = false;
255
                        		else
256
                             			$can_add = true;
257
				} else
258 92125c97 Ermal Luçi
					$can_add = false;
259 3a343d73 jim-p
				if (write_config())
260
					mark_subsystem_dirty('shaper');
261 92125c97 Ermal Luçi
				$can_enable = true;
262
				if ($altq->GetScheduler() != "PRIQ") /* XXX */
263 fce82460 Ermal Luçi
					if ($tmp->GetDefault() <> "")
264 96d1d4ad Ermal Luçi
                                                $can_add = false;
265
                                        else
266
                                                $can_add = true;
267 92125c97 Ermal Luçi
			}
268 48d418e8 Ermal Luçi
			read_altq_config();
269 92125c97 Ermal Luçi
			$output_form .= $tmp->build_form();			
270 197bfe96 Ermal Luçi
		} else
271 2f8fe6af Carlos Eduardo Ramos
			$input_errors[] = gettext("Could not add new queue.");
272 197bfe96 Ermal Luçi
	} else if ($_POST['apply']) {
273 92125c97 Ermal Luçi
			write_config();
274 0df08a41 Scott Ullrich
275 92125c97 Ermal Luçi
			$retval = 0;
276
			$retval = filter_configure();
277 0027de0a Ermal Lu?i
			$savemsg = get_std_save_message($retval);
278 92125c97 Ermal Luçi
			
279
			if (stristr($retval, "error") <> true)
280
					$savemsg = get_std_save_message($retval);
281
			else
282
					$savemsg = $retval;
283 5b237745 Scott Ullrich
284 96b777d6 Ermal Luçi
 		/* reset rrd queues */
285 7ac5a4cb Scott Ullrich
		system("rm -f /var/db/rrd/*queuedrops.rrd");
286
		system("rm -f /var/db/rrd/*queues.rrd");
287
		enable_rrd_graphing();
288 1f276138 Scott Ullrich
289 a368a026 Ermal Lu?i
		clear_subsystem_dirty('shaper');
290 92125c97 Ermal Luçi
			
291
			if ($queue) {
292
				$output_form .= $queue->build_form();
293
				$dontshow = false;
294
			}
295
			else {
296
				$output_form .= $default_shaper_message;
297
				$dontshow = true;
298
			}
299 1f276138 Scott Ullrich
300 197bfe96 Ermal Luçi
	} else if ($queue) {
301
                $queue->validate_input($_POST, &$input_errors);
302
                if (!$input_errors) {
303 92125c97 Ermal Luçi
                            $queue->update_altq_queue_data($_POST);
304
                            $queue->wconfig();
305 3a343d73 jim-p
				if (write_config())
306
					mark_subsystem_dirty('shaper');
307 92125c97 Ermal Luçi
				$dontshow = false;
308
                } 
309 48d418e8 Ermal Luçi
		read_altq_config();
310
		$output_form .= $queue->build_form();
311 92125c97 Ermal Luçi
	} else  {
312
		$output_form .= "<p class=\"pgtitle\">" . $default_shaper_msg."</p>";
313
		$dontshow = true;
314
	}
315 5f471c95 Ermal
	mwexec("killall qstats");
316 0ceb8927 Bill Marquette
} else {
317 92125c97 Ermal Luçi
	$output_form .= "<p class=\"pgtitle\">" . $default_shaper_msg."</p>";
318 197bfe96 Ermal Luçi
	$dontshow = true;
319
}
320 0ceb8927 Bill Marquette
321 fce82460 Ermal Luçi
if ($queue) {
322
                        if ($queue->GetEnabled())
323
                                $can_enable = true;
324
                        else
325
                                $can_enable = false;
326 70b139a3 Chris Buechler
                        if ($queue->CanHaveChildren() && $can_enable) { 
327 58dc3a03 Ermal Luçi
                                if ($altq->GetQname() <> $queue->GetQname() && $queue->GetDefault() <> "")
328 fce82460 Ermal Luçi
                                        $can_add = false;
329
                                else
330
                                        $can_add = true;
331
                        } else
332
                                $can_add = false;
333
}
334
335
$tree = "<ul class=\"tree\" >";
336
if (is_array($altq_list_queues)) {
337 a843b04f Ermal Luçi
        foreach ($altq_list_queues as $tmpaltq) {
338
                $tree .= $tmpaltq->build_tree();
339 fce82460 Ermal Luçi
        }
340
$tree .=  get_interface_list_to_show();
341
}
342
$tree .= "</ul>";
343 0ceb8927 Bill Marquette
344 197bfe96 Ermal Luçi
if (!$dontshow || $newqueue) {
345 0ceb8927 Bill Marquette
346 f5e511d3 Ermal
$output_form .= "<tr><td width=\"22%\" valign=\"center\" class=\"vncellreq\">";
347 270f81d9 Renato Botelho
$output_form .= "<br />" . gettext("Queue Actions") . "<br />";
348 f5e511d3 Ermal
$output_form .= "</td><td valign=\"center\" class=\"vncellreq\" width=\"78%\"><br />";
349 197bfe96 Ermal Luçi
350 92125c97 Ermal Luçi
$output_form .= "<input type=\"submit\" name=\"Submit\" value=\"" . gettext("Save") . "\" class=\"formbtn\" />";
351 197bfe96 Ermal Luçi
if ($can_add || $addnewaltq) {
352 92125c97 Ermal Luçi
	$output_form .= "<a href=\"firewall_shaper.php?interface=";
353
	$output_form .= $interface; 
354
	if ($queue) {
355
		$output_form .= "&queue=" . $queue->GetQname();
356
	}
357
	$output_form .= "&action=add\">";
358 2f8fe6af Carlos Eduardo Ramos
	$output_form .= "<input type=\"button\" class=\"formbtn\" name=\"add\" value=\"" . gettext("Add new queue") . "\">";
359 92125c97 Ermal Luçi
	$output_form .= "</a>";
360
	$output_form .= "<a href=\"firewall_shaper.php?interface=";
361
	$output_form .= $interface . "&queue=";
362
	if ($queue) {
363
		$output_form .= "&queue=" . $queue->GetQname();
364
	}
365
	$output_form .= "&action=delete\">";
366 37f5fcf6 Ermal Luçi
	$output_form .= "<input type=\"button\" class=\"formbtn\" name=\"delete\"";
367 92125c97 Ermal Luçi
	if ($queue)
368 34f79120 Vinicius Coque
		$output_form .= " value=\"" . gettext("Delete this queue") . "\">";
369 92125c97 Ermal Luçi
	else
370 34f79120 Vinicius Coque
		$output_form .= " value=\"" . gettext("Disable shaper on interface") . "\">";
371 92125c97 Ermal Luçi
	$output_form .= "</a>";  
372 5b237745 Scott Ullrich
}
373 f5e511d3 Ermal
$output_form .= "<br /></td></tr>";
374 92125c97 Ermal Luçi
$output_form .= "</div>";
375 f5e511d3 Ermal
}
376 197bfe96 Ermal Luçi
else 
377 92125c97 Ermal Luçi
	$output_form .= "</div>";
378
379
$output = "<div id=\"shaperarea\" style=\"position:relative\">";
380
$output .= $output_form;
381 52380979 Scott Ullrich
382 58dc3a03 Ermal Luçi
//$pgtitle = "Firewall: Shaper: By Interface View";
383 52380979 Scott Ullrich
384 197bfe96 Ermal Luçi
include("head.inc");
385 5b237745 Scott Ullrich
?>
386 92125c97 Ermal Luçi
387
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" >
388 197bfe96 Ermal Luçi
<link rel="stylesheet" type="text/css" media="all" href="./tree/tree.css" />
389
<script type="text/javascript" src="./tree/tree.js"></script>
390 92125c97 Ermal Luçi
<?php
391 1309fadd Ermal
if ($queue)
392 92125c97 Ermal Luçi
        echo $queue->build_javascript();
393 bdb0d479 Ermal Luçi
echo $newjavascript;
394 5b237745 Scott Ullrich
395 92125c97 Ermal Luçi
include("fbegin.inc"); 
396
?>
397 197bfe96 Ermal Luçi
<div id="inputerrors"></div>
398
<?php if ($input_errors) print_input_errors($input_errors); ?>
399
400 92125c97 Ermal Luçi
<form action="firewall_shaper.php" method="post" id="iform" name="iform">
401 197bfe96 Ermal Luçi
402 5b237745 Scott Ullrich
<?php if ($savemsg) print_info_box($savemsg); ?>
403 a368a026 Ermal Lu?i
<?php if (is_subsystem_dirty('shaper')): ?><p>
404 e336a195 Vinicius Coque
<?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>
405 5b237745 Scott Ullrich
<?php endif; ?>
406
<table width="100%" border="0" cellpadding="0" cellspacing="0">
407
  <tr><td>
408 52380979 Scott Ullrich
<?php
409
	$tab_array = array();
410 1c52312d Jeann
	$tab_array[0] = array(gettext("By Interface"), true, "firewall_shaper.php");
411
	$tab_array[1] = array(gettext("By Queue"), false, "firewall_shaper_queues.php");
412
	$tab_array[2] = array(gettext("Limiter"), false, "firewall_shaper_vinterface.php");
413
	$tab_array[3] = array(gettext("Layer7"), false, "firewall_shaper_layer7.php");
414
	$tab_array[4] = array(gettext("Wizards"), false, "firewall_shaper_wizards.php");
415 52380979 Scott Ullrich
	display_top_tabs($tab_array);
416 197bfe96 Ermal Luçi
?>
417 5b237745 Scott Ullrich
  </td></tr>
418
  <tr>
419 d732f186 Bill Marquette
    <td>
420
	<div id="mainarea">
421
              <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
422 26dfbf80 Ermal Luçi
<?php if (count($altq_list_queues) > 0): ?>
423
                        <tr class="tabcont"><td width="25%" align="left">
424
                                <a href="firewall_shaper.php?action=resetall" >
425 34f79120 Vinicius Coque
                                        <input type="button" value="<?=gettext("Remove Shaper")?>" class="formbtn">
426 26dfbf80 Ermal Luçi
                                </a>
427
                        </td><td width="75%"> </td></tr>
428 ee9933b6 Renato Botelho
<?php endif; ?>
429 197bfe96 Ermal Luçi
			<tr>
430
			<td width="25%" valign="top" algin="left">
431
			<?php
432
				echo $tree; 
433
			?>
434
			</td>
435
			<td width="75%" valign="top" align="center">
436
			<table>
437
			<?
438
				echo $output;
439
			?>	
440
			</table>
441 e295675f Scott Ullrich
442 197bfe96 Ermal Luçi
		      </td></tr>
443 d732f186 Bill Marquette
                    </table>
444
		</div>
445
	  </td>
446 5b237745 Scott Ullrich
	</tr>
447
</table>
448
            </form>
449 197bfe96 Ermal Luçi
<?php include("fend.inc"); 
450
?>
451 5b237745 Scott Ullrich
</body>
452
</html>