Project

General

Profile

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