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 b9b9b4d8 jim-p
$statusurl = "status_queues.php";
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
                $interface = trim($_GET['interface']);
69
        if ($_GET['action'])
70
                $action = $_GET['action'];
71
}
72
if ($_POST) {
73
	if ($_POST['name'])
74
        	$qname = trim($_POST['name']);
75
        if ($_POST['interface'])
76
                $interface = trim($_POST['interface']);
77
	if ($_POST['parentqueue'])
78
		$parentqueue = 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
				write_config();
98 a368a026 Ermal Lu?i
				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
			write_config();
122
			
123
			$retval = 0;
124 0027de0a Ermal Lu?i
                        $retval |= filter_configure();
125 26dfbf80 Ermal Luçi
                        $savemsg = get_std_save_message($retval);
126
127
                        if (stristr($retval, "error") <> true)
128
	                        $savemsg = get_std_save_message($retval);
129
                        else
130
       	                	$savemsg = $retval;
131
			
132
			$output_form = $default_shaper_message;
133
134
		break;
135 197bfe96 Ermal Luçi
	case "add":
136
			/* XXX: Find better way because we shouldn't know about this */
137
		if ($altq) {
138
	                switch ($altq->GetScheduler()) {
139
         	        case "PRIQ":
140
                	        $q = new priq_queue();
141
                        	break;
142 c563b7a8 Ermal Luçi
			case "FAIRQ":
143
				$q = new fairq_queue();
144
				break;
145 197bfe96 Ermal Luçi
                        case "HFSC":
146
                         	$q = new hfsc_queue();
147
                        	break;
148
                        case "CBQ":
149
                                $q = new cbq_queue();
150
                        	break;
151
                        default:
152
                                /* XXX: Happens when sched==NONE?! */
153
				$q = new altq_root_queue();
154
                        	break;
155
        		}
156
		} else if ($addnewaltq) {
157
			$q = new altq_root_queue();
158
		} else 
159 1c52312d Jeann
			$input_errors[] = gettext("Could not create new queue/discipline!");
160 197bfe96 Ermal Luçi
161
			if ($q) {
162
				$q->SetInterface($interface);
163 92125c97 Ermal Luçi
				$output_form .= $q->build_form();
164
				$output_form .= "<input type=\"hidden\" name=\"parentqueue\" id=\"parentqueue\"";
165
				$output_form .= " value=\"".$qname."\">";
166 bdb0d479 Ermal Luçi
				$newjavascript = $q->build_javascript();
167 197bfe96 Ermal Luçi
                unset($q);
168
				$newqueue = true;
169
			}
170
		break;
171
		case "show":
172
			if ($queue)  
173 92125c97 Ermal Luçi
                        $output_form .= $queue->build_form();
174 197bfe96 Ermal Luçi
			else
175 1c52312d Jeann
					$input_errors[] = gettext("Queue not found!");
176 197bfe96 Ermal Luçi
		break;
177
		case "enable":
178
			if ($queue) {
179
					$queue->SetEnabled("on");
180 92125c97 Ermal Luçi
					$output_form .= $queue->build_form();
181 197bfe96 Ermal Luçi
					write_config();
182 a368a026 Ermal Lu?i
					mark_subsystem_dirty('shaper');
183 197bfe96 Ermal Luçi
			} else
184 1c52312d Jeann
					$input_errors[] = gettext("Queue not found!");
185 197bfe96 Ermal Luçi
		break;
186
		case "disable":
187
			if ($queue) {
188
					$queue->SetEnabled("");
189 92125c97 Ermal Luçi
					$output_form .= $queue->build_form();
190 197bfe96 Ermal Luçi
					write_config();
191 a368a026 Ermal Lu?i
					mark_subsystem_dirty('shaper');
192 197bfe96 Ermal Luçi
			} else
193 1c52312d Jeann
					$input_errors[] = gettext("Queue not found!");
194 197bfe96 Ermal Luçi
		break;
195
		default:
196 92125c97 Ermal Luçi
			$output_form .= "<p class=\"pgtitle\">" . $default_shaper_msg."</p>";
197 197bfe96 Ermal Luçi
			$dontshow = true;
198
			break;
199 5b237745 Scott Ullrich
	}
200 197bfe96 Ermal Luçi
} else if ($_POST) {
201
	unset($input_errors);
202 5b237745 Scott Ullrich
203 197bfe96 Ermal Luçi
	if ($addnewaltq) {
204
		$altq =& new altq_root_queue();
205
		$altq->SetInterface($interface);
206 92125c97 Ermal Luçi
		
207
		switch ($altq->GetBwscale()) {
208
				case "Mb":
209
					$factor = 1000 * 1000;
210
					brak;
211
				case "Kb":
212
					$factor = 1000;
213
					break;
214
				case "b":
215
					$factor = 1;
216
					break;
217
				case "Gb":
218
					$factor = 1000 * 1000 * 1000;
219
					break;
220
				case "%": /* We don't use it for root_XXX queues. */
221
				default: /* XXX assume Kb by default. */
222
					$factor = 1000;
223
					break;
224
			} 
225
		$altq->SetAvailableBandwidth($altq->GetBandwidth() * $factor);
226 197bfe96 Ermal Luçi
		$altq->ReadConfig($_POST);
227 92125c97 Ermal Luçi
		$altq->validate_input($_POST, &$input_errors);
228
		if (!$input_errors) {
229
			unset($tmppath);
230
			$tmppath[] = $altq->GetInterface();
231
			$altq->SetLink(&$tmppath);	
232
			$altq->wconfig();
233
			write_config();
234 a368a026 Ermal Lu?i
			mark_subsystem_dirty('shaper');
235 92125c97 Ermal Luçi
			$can_enable = true;
236 fce82460 Ermal Luçi
                        $can_add = true;
237 92125c97 Ermal Luçi
		}
238 48d418e8 Ermal Luçi
		read_altq_config();
239 92125c97 Ermal Luçi
		$output_form .= $altq->build_form();
240
241 197bfe96 Ermal Luçi
	} else if ($parentqueue) { /* Add a new queue */
242
		$qtmp =& $altq->find_queue($interface, $parentqueue);
243
		if ($qtmp) {
244
			$tmppath =& $qtmp->GetLink();
245
			array_push($tmppath, $qname);
246 cedae3d3 Ermal Luçi
			$tmp =& $qtmp->add_queue($interface, $_POST, $tmppath, &$input_errors);
247 92125c97 Ermal Luçi
			if (!$input_errors) {
248
				array_pop($tmppath);
249
				$tmp->wconfig();
250
				$can_enable = true;
251 70b139a3 Chris Buechler
				if ($tmp->CanHaveChildren() && $can_enable) {
252 fce82460 Ermal Luçi
					if ($tmp->GetDefault() <> "")
253 96d1d4ad Ermal Luçi
                             			$can_add = false;
254
                        		else
255
                             			$can_add = true;
256
				} else
257 92125c97 Ermal Luçi
					$can_add = false;
258
				write_config();
259 a368a026 Ermal Lu?i
				mark_subsystem_dirty('shaper');
260 92125c97 Ermal Luçi
				$can_enable = true;
261
				if ($altq->GetScheduler() != "PRIQ") /* XXX */
262 fce82460 Ermal Luçi
					if ($tmp->GetDefault() <> "")
263 96d1d4ad Ermal Luçi
                                                $can_add = false;
264
                                        else
265
                                                $can_add = true;
266 92125c97 Ermal Luçi
			}
267 48d418e8 Ermal Luçi
			read_altq_config();
268 92125c97 Ermal Luçi
			$output_form .= $tmp->build_form();			
269 197bfe96 Ermal Luçi
		} else
270 2f8fe6af Carlos Eduardo Ramos
			$input_errors[] = gettext("Could not add new queue.");
271 197bfe96 Ermal Luçi
	} else if ($_POST['apply']) {
272 92125c97 Ermal Luçi
			write_config();
273 0df08a41 Scott Ullrich
274 92125c97 Ermal Luçi
			$retval = 0;
275
			$retval = filter_configure();
276 0027de0a Ermal Lu?i
			$savemsg = get_std_save_message($retval);
277 92125c97 Ermal Luçi
			
278
			if (stristr($retval, "error") <> true)
279
					$savemsg = get_std_save_message($retval);
280
			else
281
					$savemsg = $retval;
282 5b237745 Scott Ullrich
283 96b777d6 Ermal Luçi
 		/* reset rrd queues */
284 7ac5a4cb Scott Ullrich
		system("rm -f /var/db/rrd/*queuedrops.rrd");
285
		system("rm -f /var/db/rrd/*queues.rrd");
286
		enable_rrd_graphing();
287 1f276138 Scott Ullrich
288 a368a026 Ermal Lu?i
		clear_subsystem_dirty('shaper');
289 92125c97 Ermal Luçi
			
290
			if ($queue) {
291
				$output_form .= $queue->build_form();
292
				$dontshow = false;
293
			}
294
			else {
295
				$output_form .= $default_shaper_message;
296
				$dontshow = true;
297
			}
298 1f276138 Scott Ullrich
299 197bfe96 Ermal Luçi
	} else if ($queue) {
300
                $queue->validate_input($_POST, &$input_errors);
301
                if (!$input_errors) {
302 92125c97 Ermal Luçi
                            $queue->update_altq_queue_data($_POST);
303
                            $queue->wconfig();
304 197bfe96 Ermal Luçi
							write_config();
305 a368a026 Ermal Lu?i
				mark_subsystem_dirty('shaper');
306 92125c97 Ermal Luçi
				$dontshow = false;
307
                } 
308 48d418e8 Ermal Luçi
		read_altq_config();
309
		$output_form .= $queue->build_form();
310 92125c97 Ermal Luçi
	} else  {
311
		$output_form .= "<p class=\"pgtitle\">" . $default_shaper_msg."</p>";
312
		$dontshow = true;
313
	}
314 0ceb8927 Bill Marquette
} else {
315 92125c97 Ermal Luçi
	$output_form .= "<p class=\"pgtitle\">" . $default_shaper_msg."</p>";
316 197bfe96 Ermal Luçi
	$dontshow = true;
317
}
318 0ceb8927 Bill Marquette
319 fce82460 Ermal Luçi
if ($queue) {
320
                        if ($queue->GetEnabled())
321
                                $can_enable = true;
322
                        else
323
                                $can_enable = false;
324 70b139a3 Chris Buechler
                        if ($queue->CanHaveChildren() && $can_enable) { 
325 58dc3a03 Ermal Luçi
                                if ($altq->GetQname() <> $queue->GetQname() && $queue->GetDefault() <> "")
326 fce82460 Ermal Luçi
                                        $can_add = false;
327
                                else
328
                                        $can_add = true;
329
                        } else
330
                                $can_add = false;
331
}
332
333
$tree = "<ul class=\"tree\" >";
334
if (is_array($altq_list_queues)) {
335 a843b04f Ermal Luçi
        foreach ($altq_list_queues as $tmpaltq) {
336
                $tree .= $tmpaltq->build_tree();
337 fce82460 Ermal Luçi
        }
338
$tree .=  get_interface_list_to_show();
339
}
340
$tree .= "</ul>";
341 0ceb8927 Bill Marquette
342 197bfe96 Ermal Luçi
if (!$dontshow || $newqueue) {
343 0ceb8927 Bill Marquette
344 f5e511d3 Ermal
$output_form .= "<tr><td width=\"22%\" valign=\"center\" class=\"vncellreq\">";
345 270f81d9 Renato Botelho
$output_form .= "<br />" . gettext("Queue Actions") . "<br />";
346 f5e511d3 Ermal
$output_form .= "</td><td valign=\"center\" class=\"vncellreq\" width=\"78%\"><br />";
347 197bfe96 Ermal Luçi
348 92125c97 Ermal Luçi
$output_form .= "<input type=\"submit\" name=\"Submit\" value=\"" . gettext("Save") . "\" class=\"formbtn\" />";
349 197bfe96 Ermal Luçi
if ($can_add || $addnewaltq) {
350 92125c97 Ermal Luçi
	$output_form .= "<a href=\"firewall_shaper.php?interface=";
351
	$output_form .= $interface; 
352
	if ($queue) {
353
		$output_form .= "&queue=" . $queue->GetQname();
354
	}
355
	$output_form .= "&action=add\">";
356 2f8fe6af Carlos Eduardo Ramos
	$output_form .= "<input type=\"button\" class=\"formbtn\" name=\"add\" value=\"" . gettext("Add new queue") . "\">";
357 92125c97 Ermal Luçi
	$output_form .= "</a>";
358
	$output_form .= "<a href=\"firewall_shaper.php?interface=";
359
	$output_form .= $interface . "&queue=";
360
	if ($queue) {
361
		$output_form .= "&queue=" . $queue->GetQname();
362
	}
363
	$output_form .= "&action=delete\">";
364 37f5fcf6 Ermal Luçi
	$output_form .= "<input type=\"button\" class=\"formbtn\" name=\"delete\"";
365 92125c97 Ermal Luçi
	if ($queue)
366 34f79120 Vinicius Coque
		$output_form .= " value=\"" . gettext("Delete this queue") . "\">";
367 92125c97 Ermal Luçi
	else
368 34f79120 Vinicius Coque
		$output_form .= " value=\"" . gettext("Disable shaper on interface") . "\">";
369 92125c97 Ermal Luçi
	$output_form .= "</a>";  
370 5b237745 Scott Ullrich
}
371 f5e511d3 Ermal
$output_form .= "<br /></td></tr>";
372 92125c97 Ermal Luçi
$output_form .= "</div>";
373 f5e511d3 Ermal
}
374 197bfe96 Ermal Luçi
else 
375 92125c97 Ermal Luçi
	$output_form .= "</div>";
376
377
$output = "<div id=\"shaperarea\" style=\"position:relative\">";
378
$output .= $output_form;
379 52380979 Scott Ullrich
380 58dc3a03 Ermal Luçi
//$pgtitle = "Firewall: Shaper: By Interface View";
381 52380979 Scott Ullrich
382 197bfe96 Ermal Luçi
include("head.inc");
383 5b237745 Scott Ullrich
?>
384 92125c97 Ermal Luçi
385
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" >
386 197bfe96 Ermal Luçi
<link rel="stylesheet" type="text/css" media="all" href="./tree/tree.css" />
387
<script type="text/javascript" src="./tree/tree.js"></script>
388 92125c97 Ermal Luçi
<?php
389
if ($queue) {
390
        echo "<script type=\"text/javascript\">";
391
        echo $queue->build_javascript();
392
        echo "</script>";
393
}
394 bdb0d479 Ermal Luçi
echo $newjavascript;
395 5b237745 Scott Ullrich
396 92125c97 Ermal Luçi
include("fbegin.inc"); 
397
?>
398 197bfe96 Ermal Luçi
<div id="inputerrors"></div>
399
<?php if ($input_errors) print_input_errors($input_errors); ?>
400
401 92125c97 Ermal Luçi
<form action="firewall_shaper.php" method="post" id="iform" name="iform">
402 197bfe96 Ermal Luçi
403 5b237745 Scott Ullrich
<?php if ($savemsg) print_info_box($savemsg); ?>
404 a368a026 Ermal Lu?i
<?php if (is_subsystem_dirty('shaper')): ?><p>
405 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>
406 5b237745 Scott Ullrich
<?php endif; ?>
407
<table width="100%" border="0" cellpadding="0" cellspacing="0">
408
  <tr><td>
409 52380979 Scott Ullrich
<?php
410
	$tab_array = array();
411 1c52312d Jeann
	$tab_array[0] = array(gettext("By Interface"), true, "firewall_shaper.php");
412
	$tab_array[1] = array(gettext("By Queue"), false, "firewall_shaper_queues.php");
413
	$tab_array[2] = array(gettext("Limiter"), false, "firewall_shaper_vinterface.php");
414
	$tab_array[3] = array(gettext("Layer7"), false, "firewall_shaper_layer7.php");
415
	$tab_array[4] = array(gettext("Wizards"), false, "firewall_shaper_wizards.php");
416 52380979 Scott Ullrich
	display_top_tabs($tab_array);
417 197bfe96 Ermal Luçi
?>
418 5b237745 Scott Ullrich
  </td></tr>
419
  <tr>
420 d732f186 Bill Marquette
    <td>
421
	<div id="mainarea">
422
              <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
423 26dfbf80 Ermal Luçi
<?php if (count($altq_list_queues) > 0): ?>
424
                        <tr class="tabcont"><td width="25%" align="left">
425
                                <a href="firewall_shaper.php?action=resetall" >
426 34f79120 Vinicius Coque
                                        <input type="button" value="<?=gettext("Remove Shaper")?>" class="formbtn">
427 26dfbf80 Ermal Luçi
                                </a>
428
                        </td><td width="75%"> </td></tr>
429
<? endif; ?>
430 197bfe96 Ermal Luçi
			<tr>
431
			<td width="25%" valign="top" algin="left">
432
			<?php
433
				echo $tree; 
434
			?>
435
			</td>
436
			<td width="75%" valign="top" align="center">
437
			<table>
438
			<?
439
				echo $output;
440
			?>	
441
			</table>
442 e295675f Scott Ullrich
443 197bfe96 Ermal Luçi
		      </td></tr>
444 d732f186 Bill Marquette
                    </table>
445
		</div>
446
	  </td>
447 5b237745 Scott Ullrich
	</tr>
448
</table>
449
            </form>
450 197bfe96 Ermal Luçi
<?php include("fend.inc"); 
451
?>
452 5b237745 Scott Ullrich
</body>
453
</html>