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 = 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
}
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
} else {
315
	$output_form .= "<p class=\"pgtitle\">" . $default_shaper_msg."</p>";
316
	$dontshow = true;
317
}
318

    
319
if ($queue) {
320
                        if ($queue->GetEnabled())
321
                                $can_enable = true;
322
                        else
323
                                $can_enable = false;
324
                        if ($queue->CanHaveChildren() && $can_enable) { 
325
                                if ($altq->GetQname() <> $queue->GetQname() && $queue->GetDefault() <> "")
326
                                        $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
        foreach ($altq_list_queues as $tmpaltq) {
336
                $tree .= $tmpaltq->build_tree();
337
        }
338
$tree .=  get_interface_list_to_show();
339
}
340
$tree .= "</ul>";
341

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

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

    
348
$output_form .= "<input type=\"submit\" name=\"Submit\" value=\"" . gettext("Save") . "\" class=\"formbtn\" />";
349
if ($can_add || $addnewaltq) {
350
	$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
	$output_form .= "<input type=\"button\" class=\"formbtn\" name=\"add\" value=\"" . gettext("Add new queue") . "\">";
357
	$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
	$output_form .= "<input type=\"button\" class=\"formbtn\" name=\"delete\"";
365
	if ($queue)
366
		$output_form .= " value=\"" . gettext("Delete this queue") . "\">";
367
	else
368
		$output_form .= " value=\"" . gettext("Disable shaper on interface") . "\">";
369
	$output_form .= "</a>";  
370
}
371
$output_form .= "<br /></td></tr>";
372
$output_form .= "</div>";
373
}
374
else 
375
	$output_form .= "</div>";
376

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

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

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

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

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

    
401
<form action="firewall_shaper.php" method="post" id="iform" name="iform">
402

    
403
<?php if ($savemsg) print_info_box($savemsg); ?>
404
<?php if (is_subsystem_dirty('shaper')): ?><p>
405
<?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
<?php endif; ?>
407
<table width="100%" border="0" cellpadding="0" cellspacing="0">
408
  <tr><td>
409
<?php
410
	$tab_array = array();
411
	$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
	display_top_tabs($tab_array);
417
?>
418
  </td></tr>
419
  <tr>
420
    <td>
421
	<div id="mainarea">
422
              <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
423
<?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
                                        <input type="button" value="<?=gettext("Remove Shaper")?>" class="formbtn">
427
                                </a>
428
                        </td><td width="75%"> </td></tr>
429
<? endif; ?>
430
			<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

    
443
		      </td></tr>
444
                    </table>
445
		</div>
446
	  </td>
447
	</tr>
448
</table>
449
            </form>
450
<?php include("fend.inc"); 
451
?>
452
</body>
453
</html>
(61-61/222)