Project

General

Profile

Download (13.6 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(gettext("Firewall"),gettext("Traffic Shaper"));
55
$statusurl = "status_queues.php";
56

    
57
$shaperIFlist = get_configured_interface_with_descr();
58
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

    
64
if ($_GET) {
65
	if ($_GET['queue'])
66
        	$qname = trim($_GET['queue']);
67
        if ($_GET['interface'])
68
                $interface = htmlspecialchars(trim($_GET['interface']));
69
        if ($_GET['action'])
70
                $action = htmlspecialchars($_GET['action']);
71
}
72
if ($_POST) {
73
	if ($_POST['name'])
74
        	$qname = htmlspecialchars(trim($_POST['name']));
75
        if ($_POST['interface'])
76
                $interface = htmlspecialchars(trim($_POST['interface']));
77
	if ($_POST['parentqueue'])
78
		$parentqueue = htmlspecialchars(trim($_POST['parentqueue']));
79
}
80

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

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

    
92
if ($_GET) {
93
	switch ($action) {
94
	case "delete":
95
			if ($queue) {
96
				$queue->delete_queue();
97
				write_config();
98
				mark_subsystem_dirty('shaper');
99
			}
100
			header("Location: firewall_shaper.php");
101
			exit;
102
		break;
103
	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
                        $retval |= filter_configure();
125
                        $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
	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
			case "FAIRQ":
143
				$q = new fairq_queue();
144
				break;
145
                        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
			$input_errors[] = gettext("Could not create new queue/discipline!");
160

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

    
203
	if ($addnewaltq) {
204
		$altq =& new altq_root_queue();
205
		$altq->SetInterface($interface);
206
		
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
		$altq->ReadConfig($_POST);
227
		$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
			mark_subsystem_dirty('shaper');
235
			$can_enable = true;
236
                        $can_add = true;
237
		}
238
		read_altq_config();
239
		$output_form .= $altq->build_form();
240

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

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

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

    
288
		clear_subsystem_dirty('shaper');
289
			
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

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

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

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

    
343
if (!$dontshow || $newqueue) {
344

    
345
$output_form .= "<tr><td width=\"22%\" valign=\"center\" class=\"vncellreq\">";
346
$output_form .= "<br />" . gettext("Queue Actions") . "<br />";
347
$output_form .= "</td><td valign=\"center\" class=\"vncellreq\" width=\"78%\"><br />";
348

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

    
378
$output = "<div id=\"shaperarea\" style=\"position:relative\">";
379
$output .= $output_form;
380

    
381
//$pgtitle = "Firewall: Shaper: By Interface View";
382

    
383
include("head.inc");
384
?>
385

    
386
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" >
387
<link rel="stylesheet" type="text/css" media="all" href="./tree/tree.css" />
388
<script type="text/javascript" src="./tree/tree.js"></script>
389
<?php
390
if ($queue)
391
        echo $queue->build_javascript();
392
echo $newjavascript;
393

    
394
include("fbegin.inc"); 
395
?>
396
<div id="inputerrors"></div>
397
<?php if ($input_errors) print_input_errors($input_errors); ?>
398

    
399
<form action="firewall_shaper.php" method="post" id="iform" name="iform">
400

    
401
<?php if ($savemsg) print_info_box($savemsg); ?>
402
<?php if (is_subsystem_dirty('shaper')): ?><p>
403
<?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>
404
<?php endif; ?>
405
<table width="100%" border="0" cellpadding="0" cellspacing="0">
406
  <tr><td>
407
<?php
408
	$tab_array = array();
409
	$tab_array[0] = array(gettext("By Interface"), true, "firewall_shaper.php");
410
	$tab_array[1] = array(gettext("By Queue"), false, "firewall_shaper_queues.php");
411
	$tab_array[2] = array(gettext("Limiter"), false, "firewall_shaper_vinterface.php");
412
	$tab_array[3] = array(gettext("Layer7"), false, "firewall_shaper_layer7.php");
413
	$tab_array[4] = array(gettext("Wizards"), false, "firewall_shaper_wizards.php");
414
	display_top_tabs($tab_array);
415
?>
416
  </td></tr>
417
  <tr>
418
    <td>
419
	<div id="mainarea">
420
              <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
421
<?php if (count($altq_list_queues) > 0): ?>
422
                        <tr class="tabcont"><td width="25%" align="left">
423
                                <a href="firewall_shaper.php?action=resetall" >
424
                                        <input type="button" value="<?=gettext("Remove Shaper")?>" class="formbtn">
425
                                </a>
426
                        </td><td width="75%"> </td></tr>
427
<?php endif; ?>
428
			<tr>
429
			<td width="25%" valign="top" algin="left">
430
			<?php
431
				echo $tree; 
432
			?>
433
			</td>
434
			<td width="75%" valign="top" align="center">
435
			<table>
436
			<?
437
				echo $output;
438
			?>	
439
			</table>
440

    
441
		      </td></tr>
442
                    </table>
443
		</div>
444
	  </td>
445
	</tr>
446
</table>
447
            </form>
448
<?php include("fend.inc"); 
449
?>
450
</body>
451
</html>
(71-71/245)