Project

General

Profile

Download (13 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
	Originally part of m0n0wall (http://m0n0.ch/wall)
10
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
11
	All rights reserved.
12 b49448ac Scott Ullrich
13 197bfe96 Ermal Luçi
	Redistribution and use in source and binary forms, with or without
14
	modification, are permitted provided that the following conditions are met:
15 b49448ac Scott Ullrich
16 197bfe96 Ermal Luçi
	1. Redistributions of source code must retain the above copyright notice,
17
	   this list of conditions and the following disclaimer.
18 b49448ac Scott Ullrich
19 197bfe96 Ermal Luçi
	2. Redistributions in binary form must reproduce the above copyright
20
	   notice, this list of conditions and the following disclaimer in the
21
	   documentation and/or other materials provided with the distribution.
22 b49448ac Scott Ullrich
23 197bfe96 Ermal Luçi
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
24
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
25
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
27
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
	POSSIBILITY OF SUCH DAMAGE.
33 5b237745 Scott Ullrich
*/
34
35
require("guiconfig.inc");
36
37 176735aa Scott Ullrich
$pgtitle = array("Firewall","Traffic Shape");
38
39 12bcdc89 Scott Ullrich
if (!is_array($config['shaper']['queue'])) {
40
	$config['shaper']['queue'] = array();
41 5b237745 Scott Ullrich
}
42 09eafb8b Scott Ullrich
43 197bfe96 Ermal Luçi
read_altq_config();
44
$tree = "<ul class=\"tree\" >";
45
if (is_array($altq_list_queues)) {
46
	foreach ($altq_list_queues as $altq) {
47
        	$tree .= $altq->build_tree();
48
        }
49
$tree .=  get_interface_list_to_show();
50
}
51
$tree .= "</ul>";
52 5b237745 Scott Ullrich
53 197bfe96 Ermal Luçi
/* 
54
 * The whole logic in these code maybe can be specified.
55
 * If you find a better way contact me :).
56
 */
57 57b89461 Scott Ullrich
58 197bfe96 Ermal Luçi
if ($_GET) {
59
	if ($_GET['queue'])
60
        	$qname = trim($_GET['queue']);
61
        if ($_GET['interface'])
62
                $interface = trim($_GET['interface']);
63
        if ($_GET['action'])
64
                $action = $_GET['action'];
65
}
66
if ($_POST) {
67
	if ($_POST['name'])
68
        	$qname = trim($_POST['name']);
69
        if ($_POST['interface'])
70
                $interface = trim($_POST['interface']);
71
	if ($_POST['parentqueue'])
72
		$parentqueue = trim($_POST['parentqueue']);
73 57b89461 Scott Ullrich
}
74
75 197bfe96 Ermal Luçi
if ($interface) {
76
	$altq = $altq_list_queues[$interface];
77
	if ($altq) {
78
		$queue =& $altq->find_queue($interface, $qname);
79
		if ($queue) {
80
			if ($queue->GetEnabled())
81
				$can_enable = true;
82
			else
83
				$can_enable = false;
84 96d1d4ad Ermal Luçi
			if ($queue->CanHaveChilds() && $can_enable) {
85
				if ($queue->GetDefault() <> "")
86
					$can_add = false;
87
				else
88
					$can_add = true;
89
			} else
90 197bfe96 Ermal Luçi
				$can_add = false;
91
		}
92
	} else $addnewaltq = true;
93 57b89461 Scott Ullrich
}
94
95 197bfe96 Ermal Luçi
$dontshow = false;
96
$newqueue = false;
97 92125c97 Ermal Luçi
$output_form = "";
98 5b237745 Scott Ullrich
99 197bfe96 Ermal Luçi
if ($_GET) {
100
	switch ($action) {
101
	case "delete":
102
			if ($queue) {
103
				$queue->delete_queue();
104
				write_config();
105
				touch($d_shaperconfdirty_path);
106
			}
107
			header("Location: firewall_shaper.php");
108
			exit;
109
		break;
110 26dfbf80 Ermal Luçi
	case "resetall":
111
			foreach ($altq_list_queues as $altq)
112
				$altq->delete_all();
113
			unset($altq_list_queues);
114
			$altq_list_queues = array();
115
			$tree = "<ul class=\"tree\" >";
116
			$tree .= get_interface_list_to_show();
117
			$tree .= "</ul>";
118
			unset($config['shaper']['queue']);
119
			unset($queue);
120
			unset($altq);
121
			$can_add = false;
122
			$can_enable = false;
123
			$dontshow = true;
124
			foreach ($config['filter']['rule'] as $key => $rule) {
125
				if (isset($rule['wizard']) && $rule['wizard'] == "yes")
126
					unset($config['filter']['rule'][$key]);
127
			}
128
			write_config();
129
			
130
			$retval = 0;
131
                        $savemsg = get_std_save_message($retval);
132
133
                        config_lock();
134
                        $retval = filter_configure();
135
                        config_unlock();
136
137
                        if (stristr($retval, "error") <> true)
138
	                        $savemsg = get_std_save_message($retval);
139
                        else
140
       	                	$savemsg = $retval;
141
			
142
			$output_form = $default_shaper_message;
143
144
		break;
145 197bfe96 Ermal Luçi
	case "add":
146
			/* XXX: Find better way because we shouldn't know about this */
147
		if ($altq) {
148
	                switch ($altq->GetScheduler()) {
149
         	        case "PRIQ":
150
                	        $q = new priq_queue();
151
                        	break;
152
                        case "HFSC":
153
                         	$q = new hfsc_queue();
154
                        	break;
155
                        case "CBQ":
156
                                $q = new cbq_queue();
157
                        	break;
158
                        default:
159
                                /* XXX: Happens when sched==NONE?! */
160
				$q = new altq_root_queue();
161
                        	break;
162
        		}
163
		} else if ($addnewaltq) {
164
			$q = new altq_root_queue();
165
		} else 
166
			$input_errors[] = "Could not create new queue/discipline!";
167
168
			if ($q) {
169
				$q->SetInterface($interface);
170 92125c97 Ermal Luçi
				$output_form .= $q->build_form();
171
				$output_form .= "<input type=\"hidden\" name=\"parentqueue\" id=\"parentqueue\"";
172
				$output_form .= " value=\"".$qname."\">";
173 197bfe96 Ermal Luçi
                unset($q);
174
				$newqueue = true;
175
			}
176
		break;
177
		case "show":
178
			if ($queue)  
179 92125c97 Ermal Luçi
                        $output_form .= $queue->build_form();
180 197bfe96 Ermal Luçi
			else
181
					$input_errors[] = "Queue not found!";
182
		break;
183
		case "enable":
184
			if ($queue) {
185
					$queue->SetEnabled("on");
186 92125c97 Ermal Luçi
					$output_form .= $queue->build_form();
187 197bfe96 Ermal Luçi
					write_config();
188
					touch($d_shaperconfdirty_path);
189
			} else
190
					$input_errors[] = "Queue not found!";
191
		break;
192
		case "disable":
193
			if ($queue) {
194
					$queue->SetEnabled("");
195 92125c97 Ermal Luçi
					$output_form .= $queue->build_form();
196 197bfe96 Ermal Luçi
					write_config();
197
					touch($d_shaperconfdirty_path);
198
			} else
199
					$input_errors[] = "Queue not found!";
200
		break;
201
		default:
202 92125c97 Ermal Luçi
			$output_form .= "<p class=\"pgtitle\">" . $default_shaper_msg."</p>";
203 197bfe96 Ermal Luçi
			$dontshow = true;
204
			break;
205 5b237745 Scott Ullrich
	}
206 197bfe96 Ermal Luçi
} else if ($_POST) {
207
	unset($input_errors);
208 5b237745 Scott Ullrich
209 197bfe96 Ermal Luçi
	if ($addnewaltq) {
210
		$altq =& new altq_root_queue();
211
		$altq->SetInterface($interface);
212 92125c97 Ermal Luçi
		
213
		switch ($altq->GetBwscale()) {
214
				case "Mb":
215
					$factor = 1000 * 1000;
216
					brak;
217
				case "Kb":
218
					$factor = 1000;
219
					break;
220
				case "b":
221
					$factor = 1;
222
					break;
223
				case "Gb":
224
					$factor = 1000 * 1000 * 1000;
225
					break;
226
				case "%": /* We don't use it for root_XXX queues. */
227
				default: /* XXX assume Kb by default. */
228
					$factor = 1000;
229
					break;
230
			} 
231
		$altq->SetAvailableBandwidth($altq->GetBandwidth() * $factor);
232 197bfe96 Ermal Luçi
		$altq->ReadConfig($_POST);
233 92125c97 Ermal Luçi
		$altq->validate_input($_POST, &$input_errors);
234
		if (!$input_errors) {
235
			unset($tmppath);
236
			$tmppath[] = $altq->GetInterface();
237
			$altq->SetLink(&$tmppath);	
238
			$altq->wconfig();
239
			write_config();
240
			touch($d_shaperconfdirty_path);
241
			$can_enable = true;
242 96d1d4ad Ermal Luçi
			if ($queue->GetDefault() <> "")
243
                             $can_add = false;
244
                        else
245
                             $can_add = true;
246 92125c97 Ermal Luçi
		}
247
		$output_form .= $altq->build_form();
248
249 197bfe96 Ermal Luçi
	} else if ($parentqueue) { /* Add a new queue */
250
		$qtmp =& $altq->find_queue($interface, $parentqueue);
251
		if ($qtmp) {
252
			$tmppath =& $qtmp->GetLink();
253
			array_push($tmppath, $qname);
254 cedae3d3 Ermal Luçi
			$tmp =& $qtmp->add_queue($interface, $_POST, $tmppath, &$input_errors);
255 92125c97 Ermal Luçi
			if (!$input_errors) {
256
				array_pop($tmppath);
257
				$tmp->wconfig();
258
				$can_enable = true;
259 96d1d4ad Ermal Luçi
				if ($tmp->CanHaveChilds() && $can_enable) {
260
					if ($queue->GetDefault() <> "")
261
                             			$can_add = false;
262
                        		else
263
                             			$can_add = true;
264
				} else
265 92125c97 Ermal Luçi
					$can_add = false;
266
				write_config();
267
				touch($d_shaperconfdirty_path);
268
				$can_enable = true;
269
				if ($altq->GetScheduler() != "PRIQ") /* XXX */
270 96d1d4ad Ermal Luçi
					if ($queue->GetDefault() <> "")
271
                                                $can_add = false;
272
                                        else
273
                                                $can_add = true;
274 92125c97 Ermal Luçi
			}
275
			$output_form .= $tmp->build_form();			
276 197bfe96 Ermal Luçi
		} else
277
			$input_errors[] = "Could not add new queue.";
278
	} else if ($_POST['apply']) {
279 92125c97 Ermal Luçi
			write_config();
280 0df08a41 Scott Ullrich
281 92125c97 Ermal Luçi
			$retval = 0;
282
			$savemsg = get_std_save_message($retval);
283
			
284
			config_lock();
285
			$retval = filter_configure();
286
			config_unlock();
287
			
288
			if (stristr($retval, "error") <> true)
289
					$savemsg = get_std_save_message($retval);
290
			else
291
					$savemsg = $retval;
292 5b237745 Scott Ullrich
293 197bfe96 Ermal Luçi
			enable_rrd_graphing();
294 1f276138 Scott Ullrich
295 197bfe96 Ermal Luçi
            unlink($d_shaperconfdirty_path);
296 92125c97 Ermal Luçi
			
297
			if ($queue) {
298
				$output_form .= $queue->build_form();
299
				$dontshow = false;
300
			}
301
			else {
302
				$output_form .= $default_shaper_message;
303
				$dontshow = true;
304
			}
305 1f276138 Scott Ullrich
306 197bfe96 Ermal Luçi
	} else if ($queue) {
307
                $queue->validate_input($_POST, &$input_errors);
308
                if (!$input_errors) {
309 92125c97 Ermal Luçi
                            $queue->update_altq_queue_data($_POST);
310
                            $queue->wconfig();
311 197bfe96 Ermal Luçi
							write_config();
312 92125c97 Ermal Luçi
				touch($d_shaperconfdirty_path);
313
				$dontshow = false;
314
                } 
315
				$output_form .= $queue->build_form();
316
	} else  {
317
		$output_form .= "<p class=\"pgtitle\">" . $default_shaper_msg."</p>";
318
		$dontshow = true;
319
	}
320 0ceb8927 Bill Marquette
} else {
321 92125c97 Ermal Luçi
	$output_form .= "<p class=\"pgtitle\">" . $default_shaper_msg."</p>";
322 197bfe96 Ermal Luçi
	$dontshow = true;
323
}
324
	
325 0ceb8927 Bill Marquette
326 197bfe96 Ermal Luçi
	
327 0ceb8927 Bill Marquette
328 197bfe96 Ermal Luçi
if (!$dontshow || $newqueue) {
329 0ceb8927 Bill Marquette
330 92125c97 Ermal Luçi
$output_form .= "<tr><td width=\"22%\" valign=\"top\" class=\"vncellreq\">";
331
$output_form .= "Queue Actions";
332
$output_form .= "</td><td valign=\"top\" class=\"vncellreq\" width=\"78%\">";
333 197bfe96 Ermal Luçi
334 92125c97 Ermal Luçi
$output_form .= "<input type=\"submit\" name=\"Submit\" value=\"" . gettext("Save") . "\" class=\"formbtn\" />";
335 197bfe96 Ermal Luçi
if ($can_add || $addnewaltq) {
336 92125c97 Ermal Luçi
	$output_form .= "<a href=\"firewall_shaper.php?interface=";
337
	$output_form .= $interface; 
338
	if ($queue) {
339
		$output_form .= "&queue=" . $queue->GetQname();
340
	}
341
	$output_form .= "&action=add\">";
342 37f5fcf6 Ermal Luçi
	$output_form .= "<input type=\"button\" class=\"formbtn\" name=\"add\" value=\"Add Queue\">";
343 92125c97 Ermal Luçi
	$output_form .= "</a>";
344
	$output_form .= "<a href=\"firewall_shaper.php?interface=";
345
	$output_form .= $interface . "&queue=";
346
	if ($queue) {
347
		$output_form .= "&queue=" . $queue->GetQname();
348
	}
349
	$output_form .= "&action=delete\">";
350 37f5fcf6 Ermal Luçi
	$output_form .= "<input type=\"button\" class=\"formbtn\" name=\"delete\"";
351 92125c97 Ermal Luçi
	if ($queue)
352 37f5fcf6 Ermal Luçi
		$output_form .= " value=\"Delete a queue\">";
353 92125c97 Ermal Luçi
	else
354 37f5fcf6 Ermal Luçi
		$output_form .= " value=\"Disable shaper on interface\">";
355 92125c97 Ermal Luçi
	$output_form .= "</a>";  
356 5b237745 Scott Ullrich
}
357 92125c97 Ermal Luçi
$output_form .= "</td></tr>";
358
$output_form .= "</div>";
359 197bfe96 Ermal Luçi
} 
360
else 
361 92125c97 Ermal Luçi
	$output_form .= "</div>";
362
363
$output = "<div id=\"shaperarea\" style=\"position:relative\">";
364
if (!$dontshow) {
365
if ($queue || $altq) {
366
	$output .= "<tr><td valign=\"top\" class=\"vncellreq\"><br>";
367
	$output .= "Enable/Disable";
368
	$output .= "</td><td class=\"vncellreq\">";
369
	$output .= " <input type=\"checkbox\" id=\"enabled\" name=\"enabled\"";
370
	if ($queue)
371
		if ($queue->GetEnabled())
372
       			$output .=  " CHECKED";
373
	else if ($altq)
374
		if ($altq->GetEnabled())
375
			$output .= " CHECKED";
376
	$output .= " ><span class=\"vexpl\"> Enable/Disable queue and its childs</span>";
377
	$output .= "</td></tr>";
378
}
379
}
380
$output .= $output_form;
381 52380979 Scott Ullrich
382 197bfe96 Ermal Luçi
$pgtitle = "Firewall: Shaper: By Interface View";
383 52380979 Scott Ullrich
384 197bfe96 Ermal Luçi
include("head.inc");
385 5b237745 Scott Ullrich
?>
386 92125c97 Ermal Luçi
387
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" >
388 197bfe96 Ermal Luçi
<link rel="stylesheet" type="text/css" media="all" href="./tree/tree.css" />
389
<script type="text/javascript" src="./tree/tree.js"></script>
390 92125c97 Ermal Luçi
<?php
391
if ($queue) {
392
        echo "<script type=\"text/javascript\">";
393
        echo $queue->build_javascript();
394
        echo "</script>";
395
}
396 5b237745 Scott Ullrich
397 92125c97 Ermal Luçi
include("fbegin.inc"); 
398
?>
399 197bfe96 Ermal Luçi
<div id="inputerrors"></div>
400
<?php if ($input_errors) print_input_errors($input_errors); ?>
401
402 92125c97 Ermal Luçi
<form action="firewall_shaper.php" method="post" id="iform" name="iform">
403 197bfe96 Ermal Luçi
404 5b237745 Scott Ullrich
<?php if ($savemsg) print_info_box($savemsg); ?>
405
<?php if (file_exists($d_shaperconfdirty_path)): ?><p>
406
<?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>
407
<?php endif; ?>
408
<table width="100%" border="0" cellpadding="0" cellspacing="0">
409
  <tr><td>
410 52380979 Scott Ullrich
<?php
411
	$tab_array = array();
412 502c545d Ermal Luçi
	$tab_array[0] = array("By Interface", true, "firewall_shaper.php");
413
	$tab_array[1] = array("By Queue", false, "firewall_shaper_queues.php");
414
	$tab_array[2] = array("EZ Shaper wizard", false, "wizard.php?xml=traffic_shaper_wizard.xml");
415 52380979 Scott Ullrich
	display_top_tabs($tab_array);
416 197bfe96 Ermal Luçi
?>
417 5b237745 Scott Ullrich
  </td></tr>
418
  <tr>
419 d732f186 Bill Marquette
    <td>
420
	<div id="mainarea">
421
              <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
422 26dfbf80 Ermal Luçi
<?php if (count($altq_list_queues) > 0): ?>
423
                        <tr class="tabcont"><td width="25%" align="left">
424
                                <a href="firewall_shaper.php?action=resetall" >
425
                                        <input type="button" value="Remove Shaper" class="formbtn">
426
                                </a>
427
                        </td><td width="75%"> </td></tr>
428
<? endif; ?>
429 197bfe96 Ermal Luçi
			<tr>
430
			<td width="25%" valign="top" algin="left">
431
			<?php
432
				echo $tree; 
433
			?>
434
			</td>
435
			<td width="75%" valign="top" align="center">
436
			<table>
437
			<?
438
				echo $output;
439
			?>	
440
			</table>
441 e295675f Scott Ullrich
442 197bfe96 Ermal Luçi
		      </td></tr>
443 d732f186 Bill Marquette
                    </table>
444
		</div>
445
	  </td>
446 5b237745 Scott Ullrich
	</tr>
447
</table>
448
            </form>
449 197bfe96 Ermal Luçi
<?php include("fend.inc"); 
450
?>
451 5b237745 Scott Ullrich
</body>
452
</html>