Project

General

Profile

Download (13.8 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	firewall_shaper.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
	pfSense_BUILDER_BINARIES:	/usr/bin/killall
32
	pfSense_MODULE:	shaper
33
*/
34

    
35
##|+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
require("guiconfig.inc");
43
require_once("functions.inc");
44
require_once("filter.inc");
45
require_once("shaper.inc");
46
require_once("rrd.inc");
47

    
48
if($_GET['reset'] <> "") {
49
	/* XXX: Huh, why are we killing php? */
50
	mwexec("killall -9 pfctl php");
51
	exit;
52
}
53

    
54
$pgtitle = array("Firewall","Traffic Shaper");
55

    
56
$shaperIFlist = get_configured_interface_with_descr();
57
read_altq_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
        	$qname = trim($_GET['queue']);
66
        if ($_GET['interface'])
67
                $interface = trim($_GET['interface']);
68
        if ($_GET['action'])
69
                $action = $_GET['action'];
70
}
71
if ($_POST) {
72
	if ($_POST['name'])
73
        	$qname = trim($_POST['name']);
74
        if ($_POST['interface'])
75
                $interface = trim($_POST['interface']);
76
	if ($_POST['parentqueue'])
77
		$parentqueue = trim($_POST['parentqueue']);
78
}
79

    
80
if ($interface) {
81
	$altq = $altq_list_queues[$interface];
82
	if ($altq) {
83
		$queue =& $altq->find_queue($interface, $qname);
84
	} else $addnewaltq = true;
85
}
86

    
87
$dontshow = false;
88
$newqueue = false;
89
$output_form = "";
90

    
91
if ($_GET) {
92
	switch ($action) {
93
	case "delete":
94
			if ($queue) {
95
				$queue->delete_queue();
96
				write_config();
97
				mark_subsystem_dirty('shaper');
98
			}
99
			header("Location: firewall_shaper.php");
100
			exit;
101
		break;
102
	case "resetall":
103
			foreach ($altq_list_queues as $altq)
104
				$altq->delete_all();
105
			unset($altq_list_queues);
106
			$altq_list_queues = array();
107
			$tree = "<ul class=\"tree\" >";
108
			$tree .= get_interface_list_to_show();
109
			$tree .= "</ul>";
110
			unset($config['shaper']['queue']);
111
			unset($queue);
112
			unset($altq);
113
			$can_add = false;
114
			$can_enable = false;
115
			$dontshow = true;
116
			foreach ($config['filter']['rule'] as $key => $rule) {
117
				if (isset($rule['wizard']) && $rule['wizard'] == "yes")
118
					unset($config['filter']['rule'][$key]);
119
			}
120
			write_config();
121
			
122
			$retval = 0;
123
                        $retval |= filter_configure();
124
                        $savemsg = get_std_save_message($retval);
125

    
126
                        if (stristr($retval, "error") <> true)
127
	                        $savemsg = get_std_save_message($retval);
128
                        else
129
       	                	$savemsg = $retval;
130
			
131
			$output_form = $default_shaper_message;
132

    
133
		break;
134
	case "add":
135
			/* XXX: Find better way because we shouldn't know about this */
136
		if ($altq) {
137
	                switch ($altq->GetScheduler()) {
138
         	        case "PRIQ":
139
                	        $q = new priq_queue();
140
                        	break;
141
			case "FAIRQ":
142
				$q = new fairq_queue();
143
				break;
144
                        case "HFSC":
145
                         	$q = new hfsc_queue();
146
                        	break;
147
                        case "CBQ":
148
                                $q = new cbq_queue();
149
                        	break;
150
                        default:
151
                                /* XXX: Happens when sched==NONE?! */
152
				$q = new altq_root_queue();
153
                        	break;
154
        		}
155
		} else if ($addnewaltq) {
156
			$q = new altq_root_queue();
157
		} else 
158
			$input_errors[] = "Could not create new queue/discipline!";
159

    
160
			if ($q) {
161
				$q->SetInterface($interface);
162
				$output_form .= $q->build_form();
163
				$output_form .= "<input type=\"hidden\" name=\"parentqueue\" id=\"parentqueue\"";
164
				$output_form .= " value=\"".$qname."\">";
165
				$newjavascript = $q->build_javascript();
166
                unset($q);
167
				$newqueue = true;
168
			}
169
		break;
170
		case "show":
171
			if ($queue)  
172
                        $output_form .= $queue->build_form();
173
			else
174
					$input_errors[] = "Queue not found!";
175
		break;
176
		case "enable":
177
			if ($queue) {
178
					$queue->SetEnabled("on");
179
					$output_form .= $queue->build_form();
180
					write_config();
181
					mark_subsystem_dirty('shaper');
182
			} else
183
					$input_errors[] = "Queue not found!";
184
		break;
185
		case "disable":
186
			if ($queue) {
187
					$queue->SetEnabled("");
188
					$output_form .= $queue->build_form();
189
					write_config();
190
					mark_subsystem_dirty('shaper');
191
			} else
192
					$input_errors[] = "Queue not found!";
193
		break;
194
		default:
195
			$output_form .= "<p class=\"pgtitle\">" . $default_shaper_msg."</p>";
196
			$dontshow = true;
197
			break;
198
	}
199
} else if ($_POST) {
200
	unset($input_errors);
201

    
202
	if ($addnewaltq) {
203
		$altq =& new altq_root_queue();
204
		$altq->SetInterface($interface);
205
		
206
		switch ($altq->GetBwscale()) {
207
				case "Mb":
208
					$factor = 1000 * 1000;
209
					brak;
210
				case "Kb":
211
					$factor = 1000;
212
					break;
213
				case "b":
214
					$factor = 1;
215
					break;
216
				case "Gb":
217
					$factor = 1000 * 1000 * 1000;
218
					break;
219
				case "%": /* We don't use it for root_XXX queues. */
220
				default: /* XXX assume Kb by default. */
221
					$factor = 1000;
222
					break;
223
			} 
224
		$altq->SetAvailableBandwidth($altq->GetBandwidth() * $factor);
225
		$altq->ReadConfig($_POST);
226
		$altq->validate_input($_POST, &$input_errors);
227
		if (!$input_errors) {
228
			unset($tmppath);
229
			$tmppath[] = $altq->GetInterface();
230
			$altq->SetLink(&$tmppath);	
231
			$altq->wconfig();
232
			write_config();
233
			mark_subsystem_dirty('shaper');
234
			$can_enable = true;
235
                        $can_add = true;
236
		}
237
		read_altq_config();
238
		$output_form .= $altq->build_form();
239

    
240
	} else if ($parentqueue) { /* Add a new queue */
241
		$qtmp =& $altq->find_queue($interface, $parentqueue);
242
		if ($qtmp) {
243
			$tmppath =& $qtmp->GetLink();
244
			array_push($tmppath, $qname);
245
			$tmp =& $qtmp->add_queue($interface, $_POST, $tmppath, &$input_errors);
246
			if (!$input_errors) {
247
				array_pop($tmppath);
248
				$tmp->wconfig();
249
				$can_enable = true;
250
				if ($tmp->CanHaveChildren() && $can_enable) {
251
					if ($tmp->GetDefault() <> "")
252
                             			$can_add = false;
253
                        		else
254
                             			$can_add = true;
255
				} else
256
					$can_add = false;
257
				write_config();
258
				mark_subsystem_dirty('shaper');
259
				$can_enable = true;
260
				if ($altq->GetScheduler() != "PRIQ") /* XXX */
261
					if ($tmp->GetDefault() <> "")
262
                                                $can_add = false;
263
                                        else
264
                                                $can_add = true;
265
			}
266
			read_altq_config();
267
			$output_form .= $tmp->build_form();			
268
		} else
269
			$input_errors[] = "Could not add new queue.";
270
	} else if ($_POST['apply']) {
271
			write_config();
272

    
273
			$retval = 0;
274
			$retval = filter_configure();
275
			$savemsg = get_std_save_message($retval);
276
			
277
			if (stristr($retval, "error") <> true)
278
					$savemsg = get_std_save_message($retval);
279
			else
280
					$savemsg = $retval;
281

    
282
 		/* reset rrd queues */
283
		system("rm -f /var/db/rrd/*queuedrops.rrd");
284
		system("rm -f /var/db/rrd/*queues.rrd");
285
		enable_rrd_graphing();
286

    
287
		clear_subsystem_dirty('shaper');
288
			
289
			if ($queue) {
290
				$output_form .= $queue->build_form();
291
				$dontshow = false;
292
			}
293
			else {
294
				$output_form .= $default_shaper_message;
295
				$dontshow = true;
296
			}
297

    
298
	} else if ($queue) {
299
                $queue->validate_input($_POST, &$input_errors);
300
                if (!$input_errors) {
301
                            $queue->update_altq_queue_data($_POST);
302
                            $queue->wconfig();
303
							write_config();
304
				mark_subsystem_dirty('shaper');
305
				$dontshow = false;
306
                } 
307
		read_altq_config();
308
		$output_form .= $queue->build_form();
309
	} else  {
310
		$output_form .= "<p class=\"pgtitle\">" . $default_shaper_msg."</p>";
311
		$dontshow = true;
312
	}
313
} else {
314
	$output_form .= "<p class=\"pgtitle\">" . $default_shaper_msg."</p>";
315
	$dontshow = true;
316
}
317

    
318
if ($queue) {
319
                        if ($queue->GetEnabled())
320
                                $can_enable = true;
321
                        else
322
                                $can_enable = false;
323
                        if ($queue->CanHaveChildren() && $can_enable) { 
324
                                if ($altq->GetQname() <> $queue->GetQname() && $queue->GetDefault() <> "")
325
                                        $can_add = false;
326
                                else
327
                                        $can_add = true;
328
                        } else
329
                                $can_add = false;
330
}
331

    
332
$tree = "<ul class=\"tree\" >";
333
if (is_array($altq_list_queues)) {
334
        foreach ($altq_list_queues as $tmpaltq) {
335
                $tree .= $tmpaltq->build_tree();
336
        }
337
$tree .=  get_interface_list_to_show();
338
}
339
$tree .= "</ul>";
340

    
341
if (!$dontshow || $newqueue) {
342

    
343
$output_form .= "<tr><td width=\"22%\" valign=\"top\" class=\"vncellreq\">";
344
$output_form .= "Queue Actions";
345
$output_form .= "</td><td valign=\"top\" class=\"vncellreq\" width=\"78%\">";
346

    
347
$output_form .= "<input type=\"submit\" name=\"Submit\" value=\"" . gettext("Save") . "\" class=\"formbtn\" />";
348
if ($can_add || $addnewaltq) {
349
	$output_form .= "<a href=\"firewall_shaper.php?interface=";
350
	$output_form .= $interface; 
351
	if ($queue) {
352
		$output_form .= "&queue=" . $queue->GetQname();
353
	}
354
	$output_form .= "&action=add\">";
355
	$output_form .= "<input type=\"button\" class=\"formbtn\" name=\"add\" value=\"Add new queue\">";
356
	$output_form .= "</a>";
357
	$output_form .= "<a href=\"firewall_shaper.php?interface=";
358
	$output_form .= $interface . "&queue=";
359
	if ($queue) {
360
		$output_form .= "&queue=" . $queue->GetQname();
361
	}
362
	$output_form .= "&action=delete\">";
363
	$output_form .= "<input type=\"button\" class=\"formbtn\" name=\"delete\"";
364
	if ($queue)
365
		$output_form .= " value=\"Delete this queue\">";
366
	else
367
		$output_form .= " value=\"Disable shaper on interface\">";
368
	$output_form .= "</a>";  
369
}
370
$output_form .= "</td></tr>";
371
$output_form .= "</div>";
372
} 
373
else 
374
	$output_form .= "</div>";
375

    
376
$output = "<div id=\"shaperarea\" style=\"position:relative\">";
377
if (!$dontshow) {
378
if ($queue || $altq || $newqueue) {
379
	$output .= "<tr><td valign=\"top\" class=\"vncellreq\"><br>";
380
	$output .= "Enable/Disable";
381
	$output .= "</td><td class=\"vncellreq\">";
382
	$output .= " <input type=\"checkbox\" id=\"enabled\" name=\"enabled\" value=\"enabled\"";
383
	if ($queue)
384
		if ($queue->GetEnabled())
385
       			$output .=  " CHECKED";
386
	else if ($altq)
387
		if ($altq->GetEnabled())
388
			$output .= " CHECKED";
389
	$output .= " ><span class=\"vexpl\"> Enable/Disable queue and its childs</span>";
390
	$output .= "</td></tr>";
391
}
392
}
393
$output .= $output_form;
394

    
395
//$pgtitle = "Firewall: Shaper: By Interface View";
396

    
397
include("head.inc");
398
?>
399

    
400
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" >
401
<link rel="stylesheet" type="text/css" media="all" href="./tree/tree.css" />
402
<script type="text/javascript" src="./tree/tree.js"></script>
403
<?php
404
if ($queue) {
405
        echo "<script type=\"text/javascript\">";
406
        echo $queue->build_javascript();
407
        echo "</script>";
408
}
409
echo $newjavascript;
410

    
411
include("fbegin.inc"); 
412
?>
413
<div id="inputerrors"></div>
414
<?php if ($input_errors) print_input_errors($input_errors); ?>
415

    
416
<form action="firewall_shaper.php" method="post" id="iform" name="iform">
417

    
418
<?php if ($savemsg) print_info_box($savemsg); ?>
419
<?php if (is_subsystem_dirty('shaper')): ?><p>
420
<?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>
421
<?php endif; ?>
422
<table width="100%" border="0" cellpadding="0" cellspacing="0">
423
  <tr><td>
424
<?php
425
	$tab_array = array();
426
	$tab_array[0] = array("By Interface", true, "firewall_shaper.php");
427
	$tab_array[1] = array("By Queue", false, "firewall_shaper_queues.php");
428
	$tab_array[2] = array("Limiter", false, "firewall_shaper_vinterface.php");
429
	$tab_array[3] = array("Layer7", false, "firewall_shaper_layer7.php");
430
	$tab_array[4] = array("Wizards", false, "firewall_shaper_wizards.php");
431
	display_top_tabs($tab_array);
432
?>
433
  </td></tr>
434
  <tr>
435
    <td>
436
	<div id="mainarea">
437
              <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
438
<?php if (count($altq_list_queues) > 0): ?>
439
                        <tr class="tabcont"><td width="25%" align="left">
440
                                <a href="firewall_shaper.php?action=resetall" >
441
                                        <input type="button" value="Remove Shaper" class="formbtn">
442
                                </a>
443
                        </td><td width="75%"> </td></tr>
444
<? endif; ?>
445
			<tr>
446
			<td width="25%" valign="top" algin="left">
447
			<?php
448
				echo $tree; 
449
			?>
450
			</td>
451
			<td width="75%" valign="top" align="center">
452
			<table>
453
			<?
454
				echo $output;
455
			?>	
456
			</table>
457

    
458
		      </td></tr>
459
                    </table>
460
		</div>
461
	  </td>
462
	</tr>
463
</table>
464
            </form>
465
<?php include("fend.inc"); 
466
?>
467
</body>
468
</html>
(60-60/215)