Project

General

Profile

Download (13.7 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

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

    
50
$pgtitle = array("Firewall","Traffic Shaper");
51

    
52
$shaperIFlist = get_configured_interface_with_descr();
53
read_altq_config();
54
/* 
55
 * The whole logic in these code maybe can be specified.
56
 * If you find a better way contact me :).
57
 */
58

    
59
if ($_GET) {
60
	if ($_GET['queue'])
61
        	$qname = trim($_GET['queue']);
62
        if ($_GET['interface'])
63
                $interface = trim($_GET['interface']);
64
        if ($_GET['action'])
65
                $action = $_GET['action'];
66
}
67
if ($_POST) {
68
	if ($_POST['name'])
69
        	$qname = trim($_POST['name']);
70
        if ($_POST['interface'])
71
                $interface = trim($_POST['interface']);
72
	if ($_POST['parentqueue'])
73
		$parentqueue = trim($_POST['parentqueue']);
74
}
75

    
76
if ($interface) {
77
	$altq = $altq_list_queues[$interface];
78
	if ($altq) {
79
		$queue =& $altq->find_queue($interface, $qname);
80
	} else $addnewaltq = true;
81
}
82

    
83
$dontshow = false;
84
$newqueue = false;
85
$output_form = "";
86

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

    
122
                        if (stristr($retval, "error") <> true)
123
	                        $savemsg = get_std_save_message($retval);
124
                        else
125
       	                	$savemsg = $retval;
126
			
127
			$output_form = $default_shaper_message;
128

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

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

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

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

    
269
			$retval = 0;
270
			$retval = filter_configure();
271
			$savemsg = get_std_save_message($retval);
272
			
273
			if (stristr($retval, "error") <> true)
274
					$savemsg = get_std_save_message($retval);
275
			else
276
					$savemsg = $retval;
277

    
278
 		/* reset rrd queues */
279
		system("rm -f /var/db/rrd/*queuedrops.rrd");
280
		system("rm -f /var/db/rrd/*queues.rrd");
281
		enable_rrd_graphing();
282

    
283
		clear_subsystem_dirty('shaper');
284
			
285
			if ($queue) {
286
				$output_form .= $queue->build_form();
287
				$dontshow = false;
288
			}
289
			else {
290
				$output_form .= $default_shaper_message;
291
				$dontshow = true;
292
			}
293

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

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

    
328
$tree = "<ul class=\"tree\" >";
329
if (is_array($altq_list_queues)) {
330
        foreach ($altq_list_queues as $tmpaltq) {
331
                $tree .= $tmpaltq->build_tree();
332
        }
333
$tree .=  get_interface_list_to_show();
334
}
335
$tree .= "</ul>";
336

    
337
if (!$dontshow || $newqueue) {
338

    
339
$output_form .= "<tr><td width=\"22%\" valign=\"top\" class=\"vncellreq\">";
340
$output_form .= "Queue Actions";
341
$output_form .= "</td><td valign=\"top\" class=\"vncellreq\" width=\"78%\">";
342

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

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

    
391
//$pgtitle = "Firewall: Shaper: By Interface View";
392

    
393
include("head.inc");
394
?>
395

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

    
407
include("fbegin.inc"); 
408
?>
409
<div id="inputerrors"></div>
410
<?php if ($input_errors) print_input_errors($input_errors); ?>
411

    
412
<form action="firewall_shaper.php" method="post" id="iform" name="iform">
413

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

    
454
		      </td></tr>
455
                    </table>
456
		</div>
457
	  </td>
458
	</tr>
459
</table>
460
            </form>
461
<?php include("fend.inc"); 
462
?>
463
</body>
464
</html>
(62-62/218)