Project

General

Profile

Download (12.6 KB) Statistics
| Branch: | Tag: | Revision:
1 585a8faf Ermal Luçi
<?php
2
/* $Id$ */
3
/*
4 a368a026 Ermal Lu?i
	firewall_shaper_vinterface.php
5 585a8faf Ermal Luçi
	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 70b139a3 Chris Buechler
20 585a8faf Ermal Luçi
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30
*/
31 7ac5a4cb Scott Ullrich
/*
32
	pfSense_BUILDER_BINARIES:	/usr/bin/killall
33
	pfSense_MODULE:	shaper
34
*/
35 585a8faf Ermal Luçi
36 6b07c15a Matthew Grooms
##|+PRIV
37
##|*IDENT=page-firewall-trafficshaper-limiter
38
##|*NAME=Firewall: Traffic Shaper: Limiter page
39
##|*DESCR=Allow access to the 'Firewall: Traffic Shaper: Limiter' page.
40
##|*MATCH=firewall_shaper_vinterface.php*
41
##|-PRIV
42
43 585a8faf Ermal Luçi
require("guiconfig.inc");
44 7a927e67 Scott Ullrich
require_once("functions.inc");
45
require_once("filter.inc");
46
require_once("shaper.inc");
47 585a8faf Ermal Luçi
48
if($_GET['reset'] <> "") {
49 7ac5a4cb Scott Ullrich
	/* XXX: Huh, why are we killing php? */
50
	mwexec("/usr/bin/killall -9 pfctl php");
51 585a8faf Ermal Luçi
	exit;
52
}
53
54 bb6e50d3 Rafael Lucas
$pgtitle = array(gettext("Firewall"),gettext("Traffic Shaper"), gettext("Limiter"));
55 b9b9b4d8 jim-p
$statusurl = "status_queues.php";
56 585a8faf Ermal Luçi
57
read_dummynet_config();
58
/* 
59
 * The whole logic in these code maybe can be specified.
60
 * If you find a better way contact me :).
61
 */
62
63
if ($_GET) {
64
	if ($_GET['queue'])
65 daab67a1 Scott Ullrich
        	$qname = htmlspecialchars(trim($_GET['queue']));
66 585a8faf Ermal Luçi
        if ($_GET['pipe'])
67 daab67a1 Scott Ullrich
                $pipe = htmlspecialchars(trim($_GET['pipe']));
68 585a8faf Ermal Luçi
        if ($_GET['action'])
69 daab67a1 Scott Ullrich
                $action = htmlspecialchars($_GET['action']);
70 585a8faf Ermal Luçi
}
71
if ($_POST) {
72
	if ($_POST['name'])
73 daab67a1 Scott Ullrich
        	$qname = htmlspecialchars(trim($_POST['name']));
74 1cbe86f0 Ermal
	else if ($_POST['newname'])
75 6be14e38 Ermal
        	$qname = htmlspecialchars(trim($_POST['newname']));
76 585a8faf Ermal Luçi
        if ($_POST['pipe'])
77 daab67a1 Scott Ullrich
        	$pipe = htmlspecialchars(trim($_POST['pipe']));
78 d3e5e7df Ermal Luçi
	else
79 1cbe86f0 Ermal
		$pipe = htmlspecialchars(trim($qname));
80 585a8faf Ermal Luçi
	if ($_POST['parentqueue'])
81 daab67a1 Scott Ullrich
		$parentqueue = htmlspecialchars(trim($_POST['parentqueue']));
82 585a8faf Ermal Luçi
}
83
84
if ($pipe) {
85
	$dnpipe = $dummynet_pipe_list[$pipe];
86
	if ($dnpipe) {
87
		$queue =& $dnpipe->find_queue($pipe, $qname);
88
	} else $addnewpipe = true;
89
}
90
91
$dontshow = false;
92
$newqueue = false;
93
$output_form = "";
94
95
if ($_GET) {
96
	switch ($action) {
97
	case "delete":
98
			if ($queue) {
99 1cbe86f0 Ermal
				if (is_array($config['filter']['rule'])) {
100
					foreach ($config['filter']['rule'] as $rule) {
101
						if ($rule['dnpipe'] == $queue->GetNumber() || $rule['pdnpipe'] == $queue->GetNumber())
102
							$input_errors[] = gettext("This pipe/queue is referenced in filter rules, please remove references from there before deleteing.");
103
					}
104
				}
105
				if (!$input_errors) {
106
					$queue->delete_queue();
107
					write_config();
108
					mark_subsystem_dirty('shaper');
109
					header("Location: firewall_shaper_vinterface.php");
110
					exit;
111
				}
112
				$output_form .= $queue->build_form();
113
			} else {
114
				$input_errors[] = gettext("No queue with name {$qname} was found!");
115
				$output_form .= "<p class=\"pgtitle\">" . $dn_default_shaper_msg."</p>";
116
				$dontshow = true;
117 585a8faf Ermal Luçi
			}
118
		break;
119
	case "resetall":
120
			foreach ($dummynet_pipe_list as $dn)
121 d3e5e7df Ermal Luçi
				$dn->delete_queue();
122 585a8faf Ermal Luçi
			unset($dummynet_pipe_list);
123
			$dummynet_pipe_list = array();
124
			unset($config['dnshaper']['queue']);
125
			unset($queue);
126
			unset($pipe);
127
			$can_add = false;
128
			$can_enable = false;
129
			$dontshow = true;
130
			foreach ($config['filter']['rule'] as $key => $rule) {
131
				if (isset($rule['dnpipe']))
132
					unset($config['filter']['rule'][$key]['dnpipe']);
133
				if (isset($rule['pdnpipe']))
134
					unset($config['filter']['rule'][$key]['pdnpipe']);
135
			}
136
			write_config();
137
			
138
			$retval = 0;
139
                        $retval = filter_configure();
140 0027de0a Ermal Lu?i
                        $savemsg = get_std_save_message($retval);
141 585a8faf Ermal Luçi
142
                        if (stristr($retval, "error") <> true)
143
	                        $savemsg = get_std_save_message($retval);
144
                        else
145
       	                	$savemsg = $retval;
146
			
147
			$output_form = $dn_default_shaper_message;
148
149
		break;
150
	case "add":
151
		if ($dnpipe) {
152 d3e5e7df Ermal Luçi
			$q = new dnqueue_class();
153
			$q->SetPipe($pipe);
154
			$output_form .= "<input type=\"hidden\" name=\"parentqueue\" id=\"parentqueue\"";
155
			$output_form .= " value=\"".$pipe."\">";
156 585a8faf Ermal Luçi
		} else if ($addnewpipe) {
157
			$q = new dnpipe_class();
158
			$q->SetQname($pipe);
159
		} else 
160 d8a8bb73 Rafael Lucas
			$input_errors[] = gettext("Could not create new queue/discipline!");
161 585a8faf Ermal Luçi
162
			if ($q) {
163
				$output_form .= $q->build_form();
164
                unset($q);
165
				$newqueue = true;
166
			}
167
		break;
168 d3e5e7df Ermal Luçi
	case "show":
169
		if ($queue)  
170
                       $output_form .= $queue->build_form();
171
		else
172 d8a8bb73 Rafael Lucas
			$input_errors[] = gettext("Queue not found!");
173 585a8faf Ermal Luçi
		break;
174 d3e5e7df Ermal Luçi
	case "enable":
175
		if ($queue) {
176
				$queue->SetEnabled("on");
177
				$output_form .= $queue->build_form();
178
				write_config();
179 a368a026 Ermal Lu?i
				mark_subsystem_dirty('shaper');
180 d3e5e7df Ermal Luçi
		} else
181 d8a8bb73 Rafael Lucas
				$input_errors[] = gettext("Queue not found!");
182 585a8faf Ermal Luçi
		break;
183 d3e5e7df Ermal Luçi
	case "disable":
184
		if ($queue) {
185
				$queue->SetEnabled("");
186
				$output_form .= $queue->build_form();
187
				write_config();
188 a368a026 Ermal Lu?i
				mark_subsystem_dirty('shaper');
189 d3e5e7df Ermal Luçi
		} else
190 d8a8bb73 Rafael Lucas
				$input_errors[] = gettext("Queue not found!");
191 d3e5e7df Ermal Luçi
		break;
192
	default:
193
		$output_form .= "<p class=\"pgtitle\">" . $dn_default_shaper_msg."</p>";
194
		$dontshow = true;
195 585a8faf Ermal Luçi
		break;
196
	}
197
} else if ($_POST) {
198
	unset($input_errors);
199
200
	if ($addnewpipe) {
201
		$dnpipe =& new dnpipe_class();
202
		
203
		$dnpipe->ReadConfig($_POST);
204
		$dnpipe->validate_input($_POST, &$input_errors);
205
		if (!$input_errors) {
206
			unset($tmppath);
207
			$tmppath[] = $dnpipe->GetQname();
208
			$dnpipe->SetLink(&$tmppath);	
209
			$dnpipe->wconfig();
210
			write_config();
211 a368a026 Ermal Lu?i
			mark_subsystem_dirty('shaper');
212 585a8faf Ermal Luçi
			$can_enable = true;
213 d3e5e7df Ermal Luçi
       		     	$can_add = true;
214 585a8faf Ermal Luçi
		}
215 d3e5e7df Ermal Luçi
		read_dummynet_config();
216 585a8faf Ermal Luçi
		$output_form .= $dnpipe->build_form();
217
218
	} else if ($parentqueue) { /* Add a new queue */
219
		if ($dnpipe) {
220
			$tmppath =& $dnpipe->GetLink();
221
			array_push($tmppath, $qname);
222
			$tmp =& $dnpipe->add_queue($pipe, $_POST, $tmppath, &$input_errors);
223
			if (!$input_errors) {
224
				array_pop($tmppath);
225
				$tmp->wconfig();
226
				write_config();
227
				$can_enable = true;
228 d3e5e7df Ermal Luçi
                		$can_add = false;
229 a368a026 Ermal Lu?i
				mark_subsystem_dirty('shaper');
230 585a8faf Ermal Luçi
				$can_enable = true;
231
			}
232 d3e5e7df Ermal Luçi
			read_dummynet_config();
233 585a8faf Ermal Luçi
			$output_form .= $tmp->build_form();			
234
		} else
235 d8a8bb73 Rafael Lucas
			$input_errors[] = gettext("Could not add new queue.");
236 585a8faf Ermal Luçi
	} else if ($_POST['apply']) {
237
			write_config();
238
239
			$retval = 0;
240
			$retval = filter_configure();
241 0027de0a Ermal Lu?i
			$savemsg = get_std_save_message($retval);
242 585a8faf Ermal Luçi
			
243
			if (stristr($retval, "error") <> true)
244
					$savemsg = get_std_save_message($retval);
245
			else
246
					$savemsg = $retval;
247
248 d3e5e7df Ermal Luçi
 		/* XXX: TODO Make dummynet pretty graphs */ 
249
		//	enable_rrd_graphing();
250 585a8faf Ermal Luçi
251 a368a026 Ermal Lu?i
			clear_subsystem_dirty('shaper');
252 585a8faf Ermal Luçi
			
253
			if ($queue) {
254
				$output_form .= $queue->build_form();
255
				$dontshow = false;
256
			}
257
			else {
258
				$output_form .= $dn_default_shaper_message;
259
				$dontshow = true;
260
			}
261
262
	} else if ($queue) {
263
                $queue->validate_input($_POST, &$input_errors);
264
                if (!$input_errors) {
265 d3e5e7df Ermal Luçi
                            	$queue->update_dn_data($_POST);
266
                            	$queue->wconfig();
267
				write_config();
268 a368a026 Ermal Lu?i
				mark_subsystem_dirty('shaper');
269 585a8faf Ermal Luçi
				$dontshow = false;
270
                } 
271 d3e5e7df Ermal Luçi
		read_dummynet_config();
272
		$output_form .= $queue->build_form();
273 585a8faf Ermal Luçi
	} else  {
274
		$output_form .= "<p class=\"pgtitle\">" . $dn_default_shaper_msg."</p>";
275
		$dontshow = true;
276
	}
277
} else {
278
	$output_form .= "<p class=\"pgtitle\">" . $dn_default_shaper_msg."</p>";
279
	$dontshow = true;
280
}
281
282
if ($queue) {
283
                        if ($queue->GetEnabled())
284
                                $can_enable = true;
285
                        else
286
                                $can_enable = false;
287 70b139a3 Chris Buechler
                        if ($queue->CanHaveChildren()) { 
288 d3e5e7df Ermal Luçi
                       		$can_add = true;
289 585a8faf Ermal Luçi
                        } else
290
                                $can_add = false;
291
}
292
293
$tree = "<ul class=\"tree\" >";
294
if (is_array($dummynet_pipe_list)) {
295
        foreach ($dummynet_pipe_list as $tmpdn) {
296
                $tree .= $tmpdn->build_tree();
297
        }
298
}
299
$tree .= "</ul>";
300
301
if (!$dontshow || $newqueue) {
302
303
$output_form .= "<tr><td width=\"22%\" valign=\"top\" class=\"vncellreq\">";
304 d8a8bb73 Rafael Lucas
$output_form .= gettext("Queue Actions");
305 585a8faf Ermal Luçi
$output_form .= "</td><td valign=\"top\" class=\"vncellreq\" width=\"78%\">";
306
307
$output_form .= "<input type=\"submit\" name=\"Submit\" value=\"" . gettext("Save") . "\" class=\"formbtn\" />";
308
if ($can_add || $addnewaltq) {
309
	$output_form .= "<a href=\"firewall_shaper_vinterface.php?pipe=";
310
	$output_form .= $pipe; 
311
	if ($queue) {
312
		$output_form .= "&queue=" . $queue->GetQname();
313
	}
314
	$output_form .= "&action=add\">";
315 0af92804 Carlos Eduardo Ramos
	$output_form .= "<input type=\"button\" class=\"formbtn\" name=\"add\" value=\"" . gettext("Add new queue") ."\">";
316 585a8faf Ermal Luçi
	$output_form .= "</a>";
317
}
318 d3e5e7df Ermal Luçi
$output_form .= "<a href=\"firewall_shaper_vinterface.php?pipe=";
319
$output_form .= $pipe . "&queue=";
320
if ($queue) {
321
	$output_form .= "&queue=" . $queue->GetQname();
322
}
323
$output_form .= "&action=delete\">";
324
$output_form .= "<input type=\"button\" class=\"formbtn\" name=\"delete\"";
325
if ($queue)
326 0af92804 Carlos Eduardo Ramos
	$output_form .= " value=\"" . gettext("Delete this queue") ."\">";
327 d3e5e7df Ermal Luçi
else
328 0af92804 Carlos Eduardo Ramos
	$output_form .= " value=\"" . gettext("Delete virtual interface") ."\">";
329 d3e5e7df Ermal Luçi
$output_form .= "</a>";  
330 585a8faf Ermal Luçi
$output_form .= "</td></tr>";
331
$output_form .= "</div>";
332
} 
333
else 
334
	$output_form .= "</div>";
335
336
$output = "<div id=\"shaperarea\" style=\"position:relative\">";
337
$output .= $output_form;
338
339
include("head.inc");
340
?>
341
342
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" >
343
<link rel="stylesheet" type="text/css" media="all" href="./tree/tree.css" />
344
<script type="text/javascript" src="./tree/tree.js"></script>
345 b7d124fe Ermal Luçi
<script type="text/javascript">
346
function show_source_port_range() {
347
        document.getElementById("sprtable").style.display = '';
348 12a72ca1 Ermal Luçi
	document.getElementById("sprtable1").style.display = '';
349
	document.getElementById("sprtable2").style.display = '';
350 cc72f352 Ermal Luçi
	document.getElementById("sprtable5").style.display = '';
351
	document.getElementById("sprtable4").style.display = 'none';
352
	document.getElementById("showadvancedboxspr").innerHTML='';
353 b7d124fe Ermal Luçi
}
354
</script>
355
356 585a8faf Ermal Luçi
<?php
357
include("fbegin.inc"); 
358
?>
359
<div id="inputerrors"></div>
360
<?php if ($input_errors) print_input_errors($input_errors); ?>
361
362
<form action="firewall_shaper_vinterface.php" method="post" id="iform" name="iform">
363
364
<?php if ($savemsg) print_info_box($savemsg); ?>
365 a368a026 Ermal Lu?i
<?php if (is_subsystem_dirty('shaper')): ?><p>
366 a38cb9d0 Vinicius Coque
<?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>
367 585a8faf Ermal Luçi
<?php endif; ?>
368
<table width="100%" border="0" cellpadding="0" cellspacing="0">
369
  <tr><td>
370
<?php
371
	$tab_array = array();
372 d8a8bb73 Rafael Lucas
	$tab_array[0] = array(gettext("By Interface"), false, "firewall_shaper.php");
373
	$tab_array[1] = array(gettext("By Queue"), false, "firewall_shaper_queues.php");
374
	$tab_array[2] = array(gettext("Limiter"), true, "firewall_shaper_vinterface.php");
375
	$tab_array[3] = array(gettext("Layer7"), false, "firewall_shaper_layer7.php");
376
	$tab_array[4] = array(gettext("Wizards"), false, "firewall_shaper_wizards.php");
377 585a8faf Ermal Luçi
	display_top_tabs($tab_array);
378
?>
379
  </td></tr>
380
  <tr>
381
    <td>
382
	<div id="mainarea">
383
              <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
384
<?php if (count($dummynet_pipe_list) > 0): ?>
385
                        <tr class="tabcont"><td width="25%" align="left">
386
                        </td><td width="75%"> </td></tr>
387 ee9933b6 Renato Botelho
<?php endif; ?>
388 585a8faf Ermal Luçi
			<tr>
389
			<td width="25%" valign="top" algin="left">
390
			<?php
391
				echo $tree; 
392
			?>
393 d3e5e7df Ermal Luçi
			<br/><br/>
394 585a8faf Ermal Luçi
			<a href="firewall_shaper_vinterface.php?pipe=new&action=add">
395 d8a8bb73 Rafael Lucas
			<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="<?=gettext("Create new limiter");?>" width="17" height="17" border="0"><?=gettext("Create new limiter");?>
396 9bb1524c Ermal Luçi
			</a><br/>
397 585a8faf Ermal Luçi
			</td>
398
			<td width="75%" valign="top" align="center">
399
			<table>
400
			<?
401
				echo $output;
402
			?>	
403
			</table>
404
405
		      </td></tr>
406
                    </table>
407
		</div>
408
	  </td>
409
	</tr>
410
</table>
411
            </form>
412
<?php include("fend.inc"); 
413
?>
414
</body>
415
</html>