Project

General

Profile

Download (13.8 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
31 6b07c15a Matthew Grooms
##|+PRIV
32
##|*IDENT=page-firewall-trafficshaper
33
##|*NAME=Firewall: Traffic Shaper page
34
##|*DESCR=Allow access to the 'Firewall: Traffic Shaper' page.
35
##|*MATCH=firewall_shaper.php*
36
##|-PRIV
37
38
39 5b237745 Scott Ullrich
require("guiconfig.inc");
40
41 1b2c6c29 Ermal Luçi
if($_GET['reset'] <> "") {
42
        mwexec("killall -9 pfctl php");
43 8f8a97c8 Ermal Luçi
	exit;
44 1b2c6c29 Ermal Luçi
}
45
46 fce82460 Ermal Luçi
$pgtitle = array("Firewall","Traffic Shaper");
47 09eafb8b Scott Ullrich
48 9d5b21c6 Ermal Luçi
$shaperIFlist = get_configured_interface_with_descr();
49 197bfe96 Ermal Luçi
read_altq_config();
50
/* 
51
 * The whole logic in these code maybe can be specified.
52
 * If you find a better way contact me :).
53
 */
54 57b89461 Scott Ullrich
55 197bfe96 Ermal Luçi
if ($_GET) {
56
	if ($_GET['queue'])
57
        	$qname = trim($_GET['queue']);
58
        if ($_GET['interface'])
59
                $interface = trim($_GET['interface']);
60
        if ($_GET['action'])
61
                $action = $_GET['action'];
62
}
63
if ($_POST) {
64
	if ($_POST['name'])
65
        	$qname = trim($_POST['name']);
66
        if ($_POST['interface'])
67
                $interface = trim($_POST['interface']);
68
	if ($_POST['parentqueue'])
69
		$parentqueue = trim($_POST['parentqueue']);
70 57b89461 Scott Ullrich
}
71
72 197bfe96 Ermal Luçi
if ($interface) {
73
	$altq = $altq_list_queues[$interface];
74
	if ($altq) {
75
		$queue =& $altq->find_queue($interface, $qname);
76
	} else $addnewaltq = true;
77 57b89461 Scott Ullrich
}
78
79 197bfe96 Ermal Luçi
$dontshow = false;
80
$newqueue = false;
81 92125c97 Ermal Luçi
$output_form = "";
82 5b237745 Scott Ullrich
83 197bfe96 Ermal Luçi
if ($_GET) {
84
	switch ($action) {
85
	case "delete":
86
			if ($queue) {
87
				$queue->delete_queue();
88
				write_config();
89
				touch($d_shaperconfdirty_path);
90
			}
91
			header("Location: firewall_shaper.php");
92
			exit;
93
		break;
94 26dfbf80 Ermal Luçi
	case "resetall":
95
			foreach ($altq_list_queues as $altq)
96
				$altq->delete_all();
97
			unset($altq_list_queues);
98
			$altq_list_queues = array();
99
			$tree = "<ul class=\"tree\" >";
100
			$tree .= get_interface_list_to_show();
101
			$tree .= "</ul>";
102
			unset($config['shaper']['queue']);
103
			unset($queue);
104
			unset($altq);
105
			$can_add = false;
106
			$can_enable = false;
107
			$dontshow = true;
108
			foreach ($config['filter']['rule'] as $key => $rule) {
109
				if (isset($rule['wizard']) && $rule['wizard'] == "yes")
110
					unset($config['filter']['rule'][$key]);
111
			}
112
			write_config();
113
			
114
			$retval = 0;
115
                        $savemsg = get_std_save_message($retval);
116
117
                        config_lock();
118
                        $retval = filter_configure();
119
                        config_unlock();
120
121
                        if (stristr($retval, "error") <> true)
122
	                        $savemsg = get_std_save_message($retval);
123
                        else
124
       	                	$savemsg = $retval;
125
			
126
			$output_form = $default_shaper_message;
127
128
		break;
129 197bfe96 Ermal Luçi
	case "add":
130
			/* XXX: Find better way because we shouldn't know about this */
131
		if ($altq) {
132
	                switch ($altq->GetScheduler()) {
133
         	        case "PRIQ":
134
                	        $q = new priq_queue();
135
                        	break;
136 c563b7a8 Ermal Luçi
			case "FAIRQ":
137
				$q = new fairq_queue();
138
				break;
139 197bfe96 Ermal Luçi
                        case "HFSC":
140
                         	$q = new hfsc_queue();
141
                        	break;
142
                        case "CBQ":
143
                                $q = new cbq_queue();
144
                        	break;
145
                        default:
146
                                /* XXX: Happens when sched==NONE?! */
147
				$q = new altq_root_queue();
148
                        	break;
149
        		}
150
		} else if ($addnewaltq) {
151
			$q = new altq_root_queue();
152
		} else 
153
			$input_errors[] = "Could not create new queue/discipline!";
154
155
			if ($q) {
156
				$q->SetInterface($interface);
157 92125c97 Ermal Luçi
				$output_form .= $q->build_form();
158
				$output_form .= "<input type=\"hidden\" name=\"parentqueue\" id=\"parentqueue\"";
159
				$output_form .= " value=\"".$qname."\">";
160 bdb0d479 Ermal Luçi
				$newjavascript = $q->build_javascript();
161 197bfe96 Ermal Luçi
                unset($q);
162
				$newqueue = true;
163
			}
164
		break;
165
		case "show":
166
			if ($queue)  
167 92125c97 Ermal Luçi
                        $output_form .= $queue->build_form();
168 197bfe96 Ermal Luçi
			else
169
					$input_errors[] = "Queue not found!";
170
		break;
171
		case "enable":
172
			if ($queue) {
173
					$queue->SetEnabled("on");
174 92125c97 Ermal Luçi
					$output_form .= $queue->build_form();
175 197bfe96 Ermal Luçi
					write_config();
176
					touch($d_shaperconfdirty_path);
177
			} else
178
					$input_errors[] = "Queue not found!";
179
		break;
180
		case "disable":
181
			if ($queue) {
182
					$queue->SetEnabled("");
183 92125c97 Ermal Luçi
					$output_form .= $queue->build_form();
184 197bfe96 Ermal Luçi
					write_config();
185
					touch($d_shaperconfdirty_path);
186
			} else
187
					$input_errors[] = "Queue not found!";
188
		break;
189
		default:
190 92125c97 Ermal Luçi
			$output_form .= "<p class=\"pgtitle\">" . $default_shaper_msg."</p>";
191 197bfe96 Ermal Luçi
			$dontshow = true;
192
			break;
193 5b237745 Scott Ullrich
	}
194 197bfe96 Ermal Luçi
} else if ($_POST) {
195
	unset($input_errors);
196 5b237745 Scott Ullrich
197 197bfe96 Ermal Luçi
	if ($addnewaltq) {
198
		$altq =& new altq_root_queue();
199
		$altq->SetInterface($interface);
200 92125c97 Ermal Luçi
		
201
		switch ($altq->GetBwscale()) {
202
				case "Mb":
203
					$factor = 1000 * 1000;
204
					brak;
205
				case "Kb":
206
					$factor = 1000;
207
					break;
208
				case "b":
209
					$factor = 1;
210
					break;
211
				case "Gb":
212
					$factor = 1000 * 1000 * 1000;
213
					break;
214
				case "%": /* We don't use it for root_XXX queues. */
215
				default: /* XXX assume Kb by default. */
216
					$factor = 1000;
217
					break;
218
			} 
219
		$altq->SetAvailableBandwidth($altq->GetBandwidth() * $factor);
220 197bfe96 Ermal Luçi
		$altq->ReadConfig($_POST);
221 92125c97 Ermal Luçi
		$altq->validate_input($_POST, &$input_errors);
222
		if (!$input_errors) {
223
			unset($tmppath);
224
			$tmppath[] = $altq->GetInterface();
225
			$altq->SetLink(&$tmppath);	
226
			$altq->wconfig();
227
			write_config();
228
			touch($d_shaperconfdirty_path);
229
			$can_enable = true;
230 fce82460 Ermal Luçi
                        $can_add = true;
231 92125c97 Ermal Luçi
		}
232 48d418e8 Ermal Luçi
		read_altq_config();
233 92125c97 Ermal Luçi
		$output_form .= $altq->build_form();
234
235 197bfe96 Ermal Luçi
	} else if ($parentqueue) { /* Add a new queue */
236
		$qtmp =& $altq->find_queue($interface, $parentqueue);
237
		if ($qtmp) {
238
			$tmppath =& $qtmp->GetLink();
239
			array_push($tmppath, $qname);
240 cedae3d3 Ermal Luçi
			$tmp =& $qtmp->add_queue($interface, $_POST, $tmppath, &$input_errors);
241 92125c97 Ermal Luçi
			if (!$input_errors) {
242
				array_pop($tmppath);
243
				$tmp->wconfig();
244
				$can_enable = true;
245 96d1d4ad Ermal Luçi
				if ($tmp->CanHaveChilds() && $can_enable) {
246 fce82460 Ermal Luçi
					if ($tmp->GetDefault() <> "")
247 96d1d4ad Ermal Luçi
                             			$can_add = false;
248
                        		else
249
                             			$can_add = true;
250
				} else
251 92125c97 Ermal Luçi
					$can_add = false;
252
				write_config();
253
				touch($d_shaperconfdirty_path);
254
				$can_enable = true;
255
				if ($altq->GetScheduler() != "PRIQ") /* XXX */
256 fce82460 Ermal Luçi
					if ($tmp->GetDefault() <> "")
257 96d1d4ad Ermal Luçi
                                                $can_add = false;
258
                                        else
259
                                                $can_add = true;
260 92125c97 Ermal Luçi
			}
261 48d418e8 Ermal Luçi
			read_altq_config();
262 92125c97 Ermal Luçi
			$output_form .= $tmp->build_form();			
263 197bfe96 Ermal Luçi
		} else
264
			$input_errors[] = "Could not add new queue.";
265
	} else if ($_POST['apply']) {
266 92125c97 Ermal Luçi
			write_config();
267 0df08a41 Scott Ullrich
268 92125c97 Ermal Luçi
			$retval = 0;
269
			$savemsg = get_std_save_message($retval);
270
			
271
			config_lock();
272
			$retval = filter_configure();
273
			config_unlock();
274
			
275
			if (stristr($retval, "error") <> true)
276
					$savemsg = get_std_save_message($retval);
277
			else
278
					$savemsg = $retval;
279 5b237745 Scott Ullrich
280 96b777d6 Ermal Luçi
 		/* reset rrd queues */
281
                system("rm -f /var/db/rrd/*queuedrops.rrd");
282
                system("rm -f /var/db/rrd/*queues.rrd");
283 197bfe96 Ermal Luçi
			enable_rrd_graphing();
284 1f276138 Scott Ullrich
285 197bfe96 Ermal Luçi
            unlink($d_shaperconfdirty_path);
286 92125c97 Ermal Luçi
			
287
			if ($queue) {
288
				$output_form .= $queue->build_form();
289
				$dontshow = false;
290
			}
291
			else {
292
				$output_form .= $default_shaper_message;
293
				$dontshow = true;
294
			}
295 1f276138 Scott Ullrich
296 197bfe96 Ermal Luçi
	} else if ($queue) {
297
                $queue->validate_input($_POST, &$input_errors);
298
                if (!$input_errors) {
299 92125c97 Ermal Luçi
                            $queue->update_altq_queue_data($_POST);
300
                            $queue->wconfig();
301 197bfe96 Ermal Luçi
							write_config();
302 92125c97 Ermal Luçi
				touch($d_shaperconfdirty_path);
303
				$dontshow = false;
304
                } 
305 48d418e8 Ermal Luçi
		read_altq_config();
306
		$output_form .= $queue->build_form();
307 92125c97 Ermal Luçi
	} else  {
308
		$output_form .= "<p class=\"pgtitle\">" . $default_shaper_msg."</p>";
309
		$dontshow = true;
310
	}
311 0ceb8927 Bill Marquette
} else {
312 92125c97 Ermal Luçi
	$output_form .= "<p class=\"pgtitle\">" . $default_shaper_msg."</p>";
313 197bfe96 Ermal Luçi
	$dontshow = true;
314
}
315 0ceb8927 Bill Marquette
316 fce82460 Ermal Luçi
if ($queue) {
317
                        if ($queue->GetEnabled())
318
                                $can_enable = true;
319
                        else
320
                                $can_enable = false;
321 58dc3a03 Ermal Luçi
                        if ($queue->CanHaveChilds() && $can_enable) { 
322
                                if ($altq->GetQname() <> $queue->GetQname() && $queue->GetDefault() <> "")
323 fce82460 Ermal Luçi
                                        $can_add = false;
324
                                else
325
                                        $can_add = true;
326
                        } else
327
                                $can_add = false;
328
}
329
330
$tree = "<ul class=\"tree\" >";
331
if (is_array($altq_list_queues)) {
332 a843b04f Ermal Luçi
        foreach ($altq_list_queues as $tmpaltq) {
333
                $tree .= $tmpaltq->build_tree();
334 fce82460 Ermal Luçi
        }
335
$tree .=  get_interface_list_to_show();
336
}
337
$tree .= "</ul>";
338 0ceb8927 Bill Marquette
339 197bfe96 Ermal Luçi
if (!$dontshow || $newqueue) {
340 0ceb8927 Bill Marquette
341 92125c97 Ermal Luçi
$output_form .= "<tr><td width=\"22%\" valign=\"top\" class=\"vncellreq\">";
342
$output_form .= "Queue Actions";
343
$output_form .= "</td><td valign=\"top\" class=\"vncellreq\" width=\"78%\">";
344 197bfe96 Ermal Luçi
345 92125c97 Ermal Luçi
$output_form .= "<input type=\"submit\" name=\"Submit\" value=\"" . gettext("Save") . "\" class=\"formbtn\" />";
346 197bfe96 Ermal Luçi
if ($can_add || $addnewaltq) {
347 92125c97 Ermal Luçi
	$output_form .= "<a href=\"firewall_shaper.php?interface=";
348
	$output_form .= $interface; 
349
	if ($queue) {
350
		$output_form .= "&queue=" . $queue->GetQname();
351
	}
352
	$output_form .= "&action=add\">";
353 58dc3a03 Ermal Luçi
	$output_form .= "<input type=\"button\" class=\"formbtn\" name=\"add\" value=\"Add new queue\">";
354 92125c97 Ermal Luçi
	$output_form .= "</a>";
355
	$output_form .= "<a href=\"firewall_shaper.php?interface=";
356
	$output_form .= $interface . "&queue=";
357
	if ($queue) {
358
		$output_form .= "&queue=" . $queue->GetQname();
359
	}
360
	$output_form .= "&action=delete\">";
361 37f5fcf6 Ermal Luçi
	$output_form .= "<input type=\"button\" class=\"formbtn\" name=\"delete\"";
362 92125c97 Ermal Luçi
	if ($queue)
363 58dc3a03 Ermal Luçi
		$output_form .= " value=\"Delete this queue\">";
364 92125c97 Ermal Luçi
	else
365 37f5fcf6 Ermal Luçi
		$output_form .= " value=\"Disable shaper on interface\">";
366 92125c97 Ermal Luçi
	$output_form .= "</a>";  
367 5b237745 Scott Ullrich
}
368 92125c97 Ermal Luçi
$output_form .= "</td></tr>";
369
$output_form .= "</div>";
370 197bfe96 Ermal Luçi
} 
371
else 
372 92125c97 Ermal Luçi
	$output_form .= "</div>";
373
374
$output = "<div id=\"shaperarea\" style=\"position:relative\">";
375
if (!$dontshow) {
376 5e1531d9 Ermal Luçi
if ($queue || $altq || $newqueue) {
377 92125c97 Ermal Luçi
	$output .= "<tr><td valign=\"top\" class=\"vncellreq\"><br>";
378
	$output .= "Enable/Disable";
379
	$output .= "</td><td class=\"vncellreq\">";
380
	$output .= " <input type=\"checkbox\" id=\"enabled\" name=\"enabled\"";
381
	if ($queue)
382
		if ($queue->GetEnabled())
383
       			$output .=  " CHECKED";
384
	else if ($altq)
385
		if ($altq->GetEnabled())
386
			$output .= " CHECKED";
387
	$output .= " ><span class=\"vexpl\"> Enable/Disable queue and its childs</span>";
388
	$output .= "</td></tr>";
389
}
390
}
391
$output .= $output_form;
392 52380979 Scott Ullrich
393 58dc3a03 Ermal Luçi
//$pgtitle = "Firewall: Shaper: By Interface View";
394 52380979 Scott Ullrich
395 197bfe96 Ermal Luçi
include("head.inc");
396 5b237745 Scott Ullrich
?>
397 92125c97 Ermal Luçi
398
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" >
399 197bfe96 Ermal Luçi
<link rel="stylesheet" type="text/css" media="all" href="./tree/tree.css" />
400
<script type="text/javascript" src="./tree/tree.js"></script>
401 92125c97 Ermal Luçi
<?php
402
if ($queue) {
403
        echo "<script type=\"text/javascript\">";
404
        echo $queue->build_javascript();
405
        echo "</script>";
406
}
407 bdb0d479 Ermal Luçi
echo $newjavascript;
408 5b237745 Scott Ullrich
409 92125c97 Ermal Luçi
include("fbegin.inc"); 
410
?>
411 197bfe96 Ermal Luçi
<div id="inputerrors"></div>
412
<?php if ($input_errors) print_input_errors($input_errors); ?>
413
414 92125c97 Ermal Luçi
<form action="firewall_shaper.php" method="post" id="iform" name="iform">
415 197bfe96 Ermal Luçi
416 5b237745 Scott Ullrich
<?php if ($savemsg) print_info_box($savemsg); ?>
417
<?php if (file_exists($d_shaperconfdirty_path)): ?><p>
418
<?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>
419
<?php endif; ?>
420
<table width="100%" border="0" cellpadding="0" cellspacing="0">
421
  <tr><td>
422 52380979 Scott Ullrich
<?php
423
	$tab_array = array();
424 502c545d Ermal Luçi
	$tab_array[0] = array("By Interface", true, "firewall_shaper.php");
425
	$tab_array[1] = array("By Queue", false, "firewall_shaper_queues.php");
426 6d0c07ea Ermal Luçi
	$tab_array[2] = array("Limiter", false, "firewall_shaper_vinterface.php");
427 f63d5b66 Helder Pereira
	$tab_array[3] = array("Layer7", false, "firewall_shaper_layer7.php");
428
	$tab_array[4] = array("Wizards", false, "firewall_shaper_wizards.php");
429 52380979 Scott Ullrich
	display_top_tabs($tab_array);
430 197bfe96 Ermal Luçi
?>
431 5b237745 Scott Ullrich
  </td></tr>
432
  <tr>
433 d732f186 Bill Marquette
    <td>
434
	<div id="mainarea">
435
              <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
436 26dfbf80 Ermal Luçi
<?php if (count($altq_list_queues) > 0): ?>
437
                        <tr class="tabcont"><td width="25%" align="left">
438
                                <a href="firewall_shaper.php?action=resetall" >
439
                                        <input type="button" value="Remove Shaper" class="formbtn">
440
                                </a>
441
                        </td><td width="75%"> </td></tr>
442
<? endif; ?>
443 197bfe96 Ermal Luçi
			<tr>
444
			<td width="25%" valign="top" algin="left">
445
			<?php
446
				echo $tree; 
447
			?>
448
			</td>
449
			<td width="75%" valign="top" align="center">
450
			<table>
451
			<?
452
				echo $output;
453
			?>	
454
			</table>
455 e295675f Scott Ullrich
456 197bfe96 Ermal Luçi
		      </td></tr>
457 d732f186 Bill Marquette
                    </table>
458
		</div>
459
	  </td>
460 5b237745 Scott Ullrich
	</tr>
461
</table>
462
            </form>
463 197bfe96 Ermal Luçi
<?php include("fend.inc"); 
464
?>
465 5b237745 Scott Ullrich
</body>
466
</html>