Project

General

Profile

Download (12.7 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	firewall_shaper_vinterface.php
5
	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

    
20
	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
/*
32
	pfSense_BUILDER_BINARIES:	/usr/bin/killall
33
	pfSense_MODULE:	shaper
34
*/
35

    
36
##|+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
require("guiconfig.inc");
44
require_once("functions.inc");
45
require_once("filter.inc");
46
require_once("shaper.inc");
47

    
48
if($_GET['reset'] <> "") {
49
	/* XXX: Huh, why are we killing php? */
50
	mwexec("/usr/bin/killall -9 pfctl php");
51
	exit;
52
}
53

    
54
$pgtitle = array(gettext("Firewall"),gettext("Traffic Shaper"), gettext("Limiter"));
55
$statusurl = "status_queues.php";
56

    
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 = htmlspecialchars(trim($_GET['queue']));
66
        if ($_GET['pipe'])
67
                $pipe = htmlspecialchars(trim($_GET['pipe']));
68
        if ($_GET['action'])
69
                $action = htmlspecialchars($_GET['action']);
70
}
71
if ($_POST) {
72
	if ($_POST['name'])
73
        	$qname = htmlspecialchars(trim($_POST['name']));
74
	else if ($_POST['newname'])
75
        	$qname = htmlspecialchars(trim($_POST['newname']));
76
        if ($_POST['pipe'])
77
        	$pipe = htmlspecialchars(trim($_POST['pipe']));
78
	else
79
		$pipe = htmlspecialchars(trim($qname));
80
	if ($_POST['parentqueue'])
81
		$parentqueue = htmlspecialchars(trim($_POST['parentqueue']));
82
}
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
			if (is_array($config['filter']['rule'])) {
100
				foreach ($config['filter']['rule'] as $rule) {
101
					if ($rule['dnpipe'] == $queue->GetName() || $rule['pdnpipe'] == $queue->GetName())
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[] = sprintf(gettext("No queue with name %s was found!"),$qname);
115
			$output_form .= "<p class=\"pgtitle\">" . $dn_default_shaper_msg."</p>";
116
			$dontshow = true;
117
		}
118
		break;
119
	case "resetall":
120
		foreach ($dummynet_pipe_list as $dn)
121
			$dn->delete_queue();
122
		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
		$savemsg = get_std_save_message($retval);
141

    
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
			$q = new dnqueue_class();
153
			$q->SetPipe($pipe);
154
			$output_form .= "<input type=\"hidden\" name=\"parentqueue\" id=\"parentqueue\"";
155
			$output_form .= " value=\"".$pipe."\">";
156
		} else if ($addnewpipe) {
157
			$q = new dnpipe_class();
158
			$q->SetQname($pipe);
159
		} else 
160
			$input_errors[] = gettext("Could not create new queue/discipline!");
161

    
162
		if ($q) {
163
			$output_form .= $q->build_form();
164
			unset($q);
165
			$newqueue = true;
166
		}
167
		break;
168
	case "show":
169
		if ($queue)  
170
                       $output_form .= $queue->build_form();
171
		else
172
			$input_errors[] = gettext("Queue not found!");
173
		break;
174
	case "enable":
175
		if ($queue) {
176
			$queue->SetEnabled("on");
177
			$output_form .= $queue->build_form();
178
			$queue->wconfig();
179
			write_config();
180
			mark_subsystem_dirty('shaper');
181
		} else
182
			$input_errors[] = gettext("Queue not found!");
183
		break;
184
	case "disable":
185
		if ($queue) {
186
			$queue->SetEnabled("");
187
			$output_form .= $queue->build_form();
188
			$queue->wconfig();
189
			write_config();
190
			mark_subsystem_dirty('shaper');
191
		} else
192
			$input_errors[] = gettext("Queue not found!");
193
		break;
194
	default:
195
		$output_form .= "<p class=\"pgtitle\">" . $dn_default_shaper_msg."</p>";
196
		$dontshow = true;
197
		break;
198
	}
199
} else if ($_POST) {
200
	unset($input_errors);
201

    
202
	if ($addnewpipe) {
203
		if (!empty($dummynet_pipe_list[$qname]))
204
			$input_errors[] = gettext("You cannot name a child queue with the same name as a parent limiter");
205
		else {
206
			$dnpipe =& new dnpipe_class();
207
			
208
			$dnpipe->ReadConfig($_POST);
209
			$dnpipe->validate_input($_POST, &$input_errors);
210
			if (!$input_errors) {
211
				$number = dnpipe_find_nextnumber();
212
				$dnpipe->SetNumber($number);
213
				unset($tmppath);
214
				$tmppath[] = $dnpipe->GetQname();
215
				$dnpipe->SetLink(&$tmppath);	
216
				$dnpipe->wconfig();
217
				write_config();
218
				mark_subsystem_dirty('shaper');
219
				$can_enable = true;
220
				$can_add = true;
221
			}
222
			
223
			read_dummynet_config();
224
			$output_form .= $dnpipe->build_form();
225
		}
226
	} else if ($parentqueue) { /* Add a new queue */
227
		if (!empty($dummynet_pipe_list[$qname]))
228
			$input_errors[] = gettext("You cannot name a child queue with the same name as a parent limiter");
229
		else if ($dnpipe) {
230
			$tmppath =& $dnpipe->GetLink();
231
			array_push($tmppath, $qname);
232
			$tmp =& $dnpipe->add_queue($pipe, $_POST, $tmppath, &$input_errors);
233
			if (!$input_errors) {
234
				array_pop($tmppath);
235
				$tmp->wconfig();
236
				write_config();
237
				$can_enable = true;
238
                		$can_add = false;
239
				mark_subsystem_dirty('shaper');
240
				$can_enable = true;
241
			}
242
			read_dummynet_config();
243
			$output_form .= $tmp->build_form();			
244
		} else
245
			$input_errors[] = gettext("Could not add new queue.");
246
	} else if ($_POST['apply']) {
247
			write_config();
248

    
249
			$retval = 0;
250
			$retval = filter_configure();
251
			$savemsg = get_std_save_message($retval);
252
			
253
			if (stristr($retval, "error") <> true)
254
					$savemsg = get_std_save_message($retval);
255
			else
256
					$savemsg = $retval;
257

    
258
 		/* XXX: TODO Make dummynet pretty graphs */ 
259
		//	enable_rrd_graphing();
260

    
261
			clear_subsystem_dirty('shaper');
262
			
263
			if ($queue) {
264
				$output_form .= $queue->build_form();
265
				$dontshow = false;
266
			}
267
			else {
268
				$output_form .= $dn_default_shaper_message;
269
				$dontshow = true;
270
			}
271

    
272
	} else if ($queue) {
273
                $queue->validate_input($_POST, &$input_errors);
274
                if (!$input_errors) {
275
			$queue->update_dn_data($_POST);
276
			$queue->wconfig();
277
			write_config();
278
			mark_subsystem_dirty('shaper');
279
			$dontshow = false;
280
                } 
281
		read_dummynet_config();
282
		$output_form .= $queue->build_form();
283
	} else  {
284
		$output_form .= "<p class=\"pgtitle\">" . $dn_default_shaper_msg."</p>";
285
		$dontshow = true;
286
	}
287
} else {
288
	$output_form .= "<p class=\"pgtitle\">" . $dn_default_shaper_msg."</p>";
289
	$dontshow = true;
290
}
291

    
292
if ($queue) {
293
                        if ($queue->GetEnabled())
294
                                $can_enable = true;
295
                        else
296
                                $can_enable = false;
297
                        if ($queue->CanHaveChildren()) { 
298
                       		$can_add = true;
299
                        } else
300
                                $can_add = false;
301
}
302

    
303
$tree = "<ul class=\"tree\" >";
304
if (is_array($dummynet_pipe_list)) {
305
        foreach ($dummynet_pipe_list as $tmpdn) {
306
                $tree .= $tmpdn->build_tree();
307
        }
308
}
309
$tree .= "</ul>";
310

    
311
if (!$dontshow || $newqueue) {
312

    
313
$output_form .= "<tr><td width=\"22%\" valign=\"top\" class=\"vncellreq\">";
314
$output_form .= gettext("Queue Actions");
315
$output_form .= "</td><td valign=\"top\" class=\"vncellreq\" width=\"78%\">";
316

    
317
$output_form .= "<input type=\"submit\" name=\"Submit\" value=\"" . gettext("Save") . "\" class=\"formbtn\" />";
318
if ($can_add || $addnewaltq) {
319
	$output_form .= "<a href=\"firewall_shaper_vinterface.php?pipe=";
320
	$output_form .= $pipe; 
321
	if ($queue) {
322
		$output_form .= "&queue=" . $queue->GetQname();
323
	}
324
	$output_form .= "&action=add\">";
325
	$output_form .= "<input type=\"button\" class=\"formbtn\" name=\"add\" value=\"" . gettext("Add new queue") ."\">";
326
	$output_form .= "</a>";
327
}
328
$output_form .= "<a href=\"firewall_shaper_vinterface.php?pipe=";
329
$output_form .= $pipe . "&queue=";
330
if ($queue) {
331
	$output_form .= "&queue=" . $queue->GetQname();
332
}
333
$output_form .= "&action=delete\">";
334
$output_form .= "<input type=\"button\" class=\"formbtn\" name=\"delete\"";
335
if ($queue)
336
	$output_form .= " value=\"" . gettext("Delete this queue") ."\">";
337
else
338
	$output_form .= " value=\"" . gettext("Delete virtual interface") ."\">";
339
$output_form .= "</a>";  
340
$output_form .= "</td></tr>";
341
$output_form .= "</div>";
342
} 
343
else 
344
	$output_form .= "</div>";
345

    
346
$output = "<div id=\"shaperarea\" style=\"position:relative\">";
347
$output .= $output_form;
348

    
349
include("head.inc");
350
?>
351

    
352
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" >
353
<link rel="stylesheet" type="text/css" media="all" href="./tree/tree.css" />
354
<script type="text/javascript" src="./tree/tree.js"></script>
355
<script type="text/javascript">
356
function show_source_port_range() {
357
        document.getElementById("sprtable").style.display = '';
358
	document.getElementById("sprtable1").style.display = '';
359
	document.getElementById("sprtable2").style.display = '';
360
	document.getElementById("sprtable5").style.display = '';
361
	document.getElementById("sprtable4").style.display = 'none';
362
	document.getElementById("showadvancedboxspr").innerHTML='';
363
}
364
</script>
365

    
366
<?php
367
include("fbegin.inc"); 
368
?>
369
<div id="inputerrors"></div>
370
<?php if ($input_errors) print_input_errors($input_errors); ?>
371

    
372
<form action="firewall_shaper_vinterface.php" method="post" id="iform" name="iform">
373

    
374
<?php if ($savemsg) print_info_box($savemsg); ?>
375
<?php if (is_subsystem_dirty('shaper')): ?><p>
376
<?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>
377
<?php endif; ?>
378
<table width="100%" border="0" cellpadding="0" cellspacing="0">
379
  <tr><td>
380
<?php
381
	$tab_array = array();
382
	$tab_array[0] = array(gettext("By Interface"), false, "firewall_shaper.php");
383
	$tab_array[1] = array(gettext("By Queue"), false, "firewall_shaper_queues.php");
384
	$tab_array[2] = array(gettext("Limiter"), true, "firewall_shaper_vinterface.php");
385
	$tab_array[3] = array(gettext("Layer7"), false, "firewall_shaper_layer7.php");
386
	$tab_array[4] = array(gettext("Wizards"), false, "firewall_shaper_wizards.php");
387
	display_top_tabs($tab_array);
388
?>
389
  </td></tr>
390
  <tr>
391
    <td>
392
	<div id="mainarea">
393
              <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
394
<?php if (count($dummynet_pipe_list) > 0): ?>
395
                        <tr class="tabcont"><td width="25%" align="left">
396
                        </td><td width="75%"> </td></tr>
397
<?php endif; ?>
398
			<tr>
399
			<td width="25%" valign="top" algin="left">
400
			<?php
401
				echo $tree; 
402
			?>
403
			<br/><br/>
404
			<a href="firewall_shaper_vinterface.php?pipe=new&action=add">
405
			<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");?>
406
			</a><br/>
407
			</td>
408
			<td width="75%" valign="top" align="center">
409
			<table>
410
			<?
411
				echo $output;
412
			?>	
413
			</table>
414

    
415
		      </td></tr>
416
                    </table>
417
		</div>
418
	  </td>
419
	</tr>
420
</table>
421
            </form>
422
<?php include("fend.inc"); 
423
?>
424
</body>
425
</html>
(75-75/249)