Project

General

Profile

Download (11.5 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 6d0c07ea Ermal Luçi
$pgtitle = array("Firewall","Traffic Shaper", "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
        	$qname = trim($_GET['queue']);
66
        if ($_GET['pipe'])
67
                $pipe = trim($_GET['pipe']);
68
        if ($_GET['action'])
69
                $action = $_GET['action'];
70
}
71
if ($_POST) {
72
	if ($_POST['name'])
73
        	$qname = trim($_POST['name']);
74
        if ($_POST['pipe'])
75 d3e5e7df Ermal Luçi
        	$pipe = trim($_POST['pipe']);
76
	else
77
		$pipe = trim($_POST['name']);
78 585a8faf Ermal Luçi
	if ($_POST['parentqueue'])
79
		$parentqueue = trim($_POST['parentqueue']);
80
}
81
82
if ($pipe) {
83
	$dnpipe = $dummynet_pipe_list[$pipe];
84
	if ($dnpipe) {
85
		$queue =& $dnpipe->find_queue($pipe, $qname);
86
	} else $addnewpipe = true;
87
}
88
89
$dontshow = false;
90
$newqueue = false;
91
$output_form = "";
92
93
if ($_GET) {
94
	switch ($action) {
95
	case "delete":
96
			if ($queue) {
97
				$queue->delete_queue();
98
				write_config();
99 a368a026 Ermal Lu?i
				mark_subsystem_dirty('shaper');
100 585a8faf Ermal Luçi
			}
101
			header("Location: firewall_shaper_vinterface.php");
102
			exit;
103
		break;
104
	case "resetall":
105
			foreach ($dummynet_pipe_list as $dn)
106 d3e5e7df Ermal Luçi
				$dn->delete_queue();
107 585a8faf Ermal Luçi
			unset($dummynet_pipe_list);
108
			$dummynet_pipe_list = array();
109
			unset($config['dnshaper']['queue']);
110
			unset($queue);
111
			unset($pipe);
112
			$can_add = false;
113
			$can_enable = false;
114
			$dontshow = true;
115
			foreach ($config['filter']['rule'] as $key => $rule) {
116
				if (isset($rule['dnpipe']))
117
					unset($config['filter']['rule'][$key]['dnpipe']);
118
				if (isset($rule['pdnpipe']))
119
					unset($config['filter']['rule'][$key]['pdnpipe']);
120
			}
121
			write_config();
122
			
123
			$retval = 0;
124
                        $retval = filter_configure();
125 0027de0a Ermal Lu?i
                        $savemsg = get_std_save_message($retval);
126 585a8faf Ermal Luçi
127
                        if (stristr($retval, "error") <> true)
128
	                        $savemsg = get_std_save_message($retval);
129
                        else
130
       	                	$savemsg = $retval;
131
			
132
			$output_form = $dn_default_shaper_message;
133
134
		break;
135
	case "add":
136
		if ($dnpipe) {
137 d3e5e7df Ermal Luçi
			$q = new dnqueue_class();
138
			$q->SetPipe($pipe);
139
			$output_form .= "<input type=\"hidden\" name=\"parentqueue\" id=\"parentqueue\"";
140
			$output_form .= " value=\"".$pipe."\">";
141 585a8faf Ermal Luçi
		} else if ($addnewpipe) {
142
			$q = new dnpipe_class();
143
			$q->SetQname($pipe);
144
		} else 
145
			$input_errors[] = "Could not create new queue/discipline!";
146
147
			if ($q) {
148
				$output_form .= $q->build_form();
149
                unset($q);
150
				$newqueue = true;
151
			}
152
		break;
153 d3e5e7df Ermal Luçi
	case "show":
154
		if ($queue)  
155
                       $output_form .= $queue->build_form();
156
		else
157
			$input_errors[] = "Queue not found!";
158 585a8faf Ermal Luçi
		break;
159 d3e5e7df Ermal Luçi
	case "enable":
160
		if ($queue) {
161
				$queue->SetEnabled("on");
162
				$output_form .= $queue->build_form();
163
				write_config();
164 a368a026 Ermal Lu?i
				mark_subsystem_dirty('shaper');
165 d3e5e7df Ermal Luçi
		} else
166
				$input_errors[] = "Queue not found!";
167 585a8faf Ermal Luçi
		break;
168 d3e5e7df Ermal Luçi
	case "disable":
169
		if ($queue) {
170
				$queue->SetEnabled("");
171
				$output_form .= $queue->build_form();
172
				write_config();
173 a368a026 Ermal Lu?i
				mark_subsystem_dirty('shaper');
174 d3e5e7df Ermal Luçi
		} else
175
				$input_errors[] = "Queue not found!";
176
		break;
177
	default:
178
		$output_form .= "<p class=\"pgtitle\">" . $dn_default_shaper_msg."</p>";
179
		$dontshow = true;
180 585a8faf Ermal Luçi
		break;
181
	}
182
} else if ($_POST) {
183
	unset($input_errors);
184
185
	if ($addnewpipe) {
186
		$dnpipe =& new dnpipe_class();
187
		
188
		$dnpipe->ReadConfig($_POST);
189
		$dnpipe->validate_input($_POST, &$input_errors);
190
		if (!$input_errors) {
191
			unset($tmppath);
192
			$tmppath[] = $dnpipe->GetQname();
193
			$dnpipe->SetLink(&$tmppath);	
194
			$dnpipe->wconfig();
195
			write_config();
196 a368a026 Ermal Lu?i
			mark_subsystem_dirty('shaper');
197 585a8faf Ermal Luçi
			$can_enable = true;
198 d3e5e7df Ermal Luçi
       		     	$can_add = true;
199 585a8faf Ermal Luçi
		}
200 d3e5e7df Ermal Luçi
		read_dummynet_config();
201 585a8faf Ermal Luçi
		$output_form .= $dnpipe->build_form();
202
203
	} else if ($parentqueue) { /* Add a new queue */
204
		if ($dnpipe) {
205
			$tmppath =& $dnpipe->GetLink();
206
			array_push($tmppath, $qname);
207
			$tmp =& $dnpipe->add_queue($pipe, $_POST, $tmppath, &$input_errors);
208
			if (!$input_errors) {
209
				array_pop($tmppath);
210
				$tmp->wconfig();
211
				write_config();
212
				$can_enable = true;
213 d3e5e7df Ermal Luçi
                		$can_add = false;
214 a368a026 Ermal Lu?i
				mark_subsystem_dirty('shaper');
215 585a8faf Ermal Luçi
				$can_enable = true;
216
			}
217 d3e5e7df Ermal Luçi
			read_dummynet_config();
218 585a8faf Ermal Luçi
			$output_form .= $tmp->build_form();			
219
		} else
220
			$input_errors[] = "Could not add new queue.";
221
	} else if ($_POST['apply']) {
222
			write_config();
223
224
			$retval = 0;
225
			$retval = filter_configure();
226 0027de0a Ermal Lu?i
			$savemsg = get_std_save_message($retval);
227 585a8faf Ermal Luçi
			
228
			if (stristr($retval, "error") <> true)
229
					$savemsg = get_std_save_message($retval);
230
			else
231
					$savemsg = $retval;
232
233 d3e5e7df Ermal Luçi
 		/* XXX: TODO Make dummynet pretty graphs */ 
234
		//	enable_rrd_graphing();
235 585a8faf Ermal Luçi
236 a368a026 Ermal Lu?i
			clear_subsystem_dirty('shaper');
237 585a8faf Ermal Luçi
			
238
			if ($queue) {
239
				$output_form .= $queue->build_form();
240
				$dontshow = false;
241
			}
242
			else {
243
				$output_form .= $dn_default_shaper_message;
244
				$dontshow = true;
245
			}
246
247
	} else if ($queue) {
248
                $queue->validate_input($_POST, &$input_errors);
249
                if (!$input_errors) {
250 d3e5e7df Ermal Luçi
                            	$queue->update_dn_data($_POST);
251
                            	$queue->wconfig();
252
				write_config();
253 a368a026 Ermal Lu?i
				mark_subsystem_dirty('shaper');
254 585a8faf Ermal Luçi
				$dontshow = false;
255
                } 
256 d3e5e7df Ermal Luçi
		read_dummynet_config();
257
		$output_form .= $queue->build_form();
258 585a8faf Ermal Luçi
	} else  {
259
		$output_form .= "<p class=\"pgtitle\">" . $dn_default_shaper_msg."</p>";
260
		$dontshow = true;
261
	}
262
} else {
263
	$output_form .= "<p class=\"pgtitle\">" . $dn_default_shaper_msg."</p>";
264
	$dontshow = true;
265
}
266
267
if ($queue) {
268
                        if ($queue->GetEnabled())
269
                                $can_enable = true;
270
                        else
271
                                $can_enable = false;
272 70b139a3 Chris Buechler
                        if ($queue->CanHaveChildren()) { 
273 d3e5e7df Ermal Luçi
                       		$can_add = true;
274 585a8faf Ermal Luçi
                        } else
275
                                $can_add = false;
276
}
277
278
$tree = "<ul class=\"tree\" >";
279
if (is_array($dummynet_pipe_list)) {
280
        foreach ($dummynet_pipe_list as $tmpdn) {
281
                $tree .= $tmpdn->build_tree();
282
        }
283
}
284
$tree .= "</ul>";
285
286
if (!$dontshow || $newqueue) {
287
288
$output_form .= "<tr><td width=\"22%\" valign=\"top\" class=\"vncellreq\">";
289
$output_form .= "Queue Actions";
290
$output_form .= "</td><td valign=\"top\" class=\"vncellreq\" width=\"78%\">";
291
292
$output_form .= "<input type=\"submit\" name=\"Submit\" value=\"" . gettext("Save") . "\" class=\"formbtn\" />";
293
if ($can_add || $addnewaltq) {
294
	$output_form .= "<a href=\"firewall_shaper_vinterface.php?pipe=";
295
	$output_form .= $pipe; 
296
	if ($queue) {
297
		$output_form .= "&queue=" . $queue->GetQname();
298
	}
299
	$output_form .= "&action=add\">";
300
	$output_form .= "<input type=\"button\" class=\"formbtn\" name=\"add\" value=\"Add new queue\">";
301
	$output_form .= "</a>";
302
}
303 d3e5e7df Ermal Luçi
$output_form .= "<a href=\"firewall_shaper_vinterface.php?pipe=";
304
$output_form .= $pipe . "&queue=";
305
if ($queue) {
306
	$output_form .= "&queue=" . $queue->GetQname();
307
}
308
$output_form .= "&action=delete\">";
309
$output_form .= "<input type=\"button\" class=\"formbtn\" name=\"delete\"";
310
if ($queue)
311
	$output_form .= " value=\"Delete this queue\">";
312
else
313
	$output_form .= " value=\"Delete virtual interface\">";
314
$output_form .= "</a>";  
315 585a8faf Ermal Luçi
$output_form .= "</td></tr>";
316
$output_form .= "</div>";
317
} 
318
else 
319
	$output_form .= "</div>";
320
321
$output = "<div id=\"shaperarea\" style=\"position:relative\">";
322
$output .= $output_form;
323
324
include("head.inc");
325
?>
326
327
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" >
328
<link rel="stylesheet" type="text/css" media="all" href="./tree/tree.css" />
329
<script type="text/javascript" src="./tree/tree.js"></script>
330 b7d124fe Ermal Luçi
<script type="text/javascript">
331
function show_source_port_range() {
332
        document.getElementById("sprtable").style.display = '';
333 12a72ca1 Ermal Luçi
	document.getElementById("sprtable1").style.display = '';
334
	document.getElementById("sprtable2").style.display = '';
335 cc72f352 Ermal Luçi
	document.getElementById("sprtable5").style.display = '';
336
	document.getElementById("sprtable4").style.display = 'none';
337
	document.getElementById("showadvancedboxspr").innerHTML='';
338 b7d124fe Ermal Luçi
}
339
</script>
340
341 585a8faf Ermal Luçi
<?php
342
include("fbegin.inc"); 
343
?>
344
<div id="inputerrors"></div>
345
<?php if ($input_errors) print_input_errors($input_errors); ?>
346
347
<form action="firewall_shaper_vinterface.php" method="post" id="iform" name="iform">
348
349
<?php if ($savemsg) print_info_box($savemsg); ?>
350 a368a026 Ermal Lu?i
<?php if (is_subsystem_dirty('shaper')): ?><p>
351 585a8faf Ermal Luçi
<?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>
352
<?php endif; ?>
353
<table width="100%" border="0" cellpadding="0" cellspacing="0">
354
  <tr><td>
355
<?php
356
	$tab_array = array();
357
	$tab_array[0] = array("By Interface", false, "firewall_shaper.php");
358
	$tab_array[1] = array("By Queue", false, "firewall_shaper_queues.php");
359 6d0c07ea Ermal Luçi
	$tab_array[2] = array("Limiter", true, "firewall_shaper_vinterface.php");
360 f63d5b66 Helder Pereira
	$tab_array[3] = array("Layer7", false, "firewall_shaper_layer7.php");
361
	$tab_array[4] = array("Wizards", false, "firewall_shaper_wizards.php");
362 585a8faf Ermal Luçi
	display_top_tabs($tab_array);
363
?>
364
  </td></tr>
365
  <tr>
366
    <td>
367
	<div id="mainarea">
368
              <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
369
<?php if (count($dummynet_pipe_list) > 0): ?>
370
                        <tr class="tabcont"><td width="25%" align="left">
371
                        </td><td width="75%"> </td></tr>
372
<? endif; ?>
373
			<tr>
374
			<td width="25%" valign="top" algin="left">
375
			<?php
376
				echo $tree; 
377
			?>
378 d3e5e7df Ermal Luçi
			<br/><br/>
379 585a8faf Ermal Luçi
			<a href="firewall_shaper_vinterface.php?pipe=new&action=add">
380 9bb1524c Ermal Luçi
			<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="Create new limiter" width="17" height="17" border="0">  Create new limiter
381
			</a><br/>
382 585a8faf Ermal Luçi
			</td>
383
			<td width="75%" valign="top" align="center">
384
			<table>
385
			<?
386
				echo $output;
387
			?>	
388
			</table>
389
390
		      </td></tr>
391
                    </table>
392
		</div>
393
	  </td>
394
	</tr>
395
</table>
396
            </form>
397
<?php include("fend.inc"); 
398
?>
399
</body>
400
</html>