Project

General

Profile

Download (13.2 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
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
8
	All rights reserved.
9

    
10
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12

    
13
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15

    
16
	2. Redistributions in binary form must reproduce the above copyright
17
	   notice, this list of conditions and the following disclaimer in the
18
	   documentation and/or other materials provided with the distribution.
19

    
20

    
21
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
22
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
23
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
25
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
	POSSIBILITY OF SUCH DAMAGE.
31
*/
32
/*
33
	pfSense_BUILDER_BINARIES:	/usr/bin/killall
34
	pfSense_MODULE:	shaper
35
*/
36

    
37
##|+PRIV
38
##|*IDENT=page-firewall-trafficshaper-limiter
39
##|*NAME=Firewall: Traffic Shaper: Limiter page
40
##|*DESCR=Allow access to the 'Firewall: Traffic Shaper: Limiter' page.
41
##|*MATCH=firewall_shaper_vinterface.php*
42
##|-PRIV
43

    
44
require("guiconfig.inc");
45
require_once("functions.inc");
46
require_once("filter.inc");
47
require_once("shaper.inc");
48

    
49
if ($_GET['reset'] <> "") {
50
	mwexec("/usr/bin/killall -9 pfctl");
51
	exit;
52
}
53

    
54
$pgtitle = array(gettext("Firewall"),gettext("Traffic Shaper"), gettext("Limiter"));
55
$shortcut_section = "trafficshaper-limiters";
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
	}
67
	if ($_GET['pipe']) {
68
		$pipe = htmlspecialchars(trim($_GET['pipe']));
69
	}
70
	if ($_GET['action']) {
71
		$action = htmlspecialchars($_GET['action']);
72
	}
73
}
74
if ($_POST) {
75
	if ($_POST['name']) {
76
		$qname = htmlspecialchars(trim($_POST['name']));
77
	} else if ($_POST['newname']) {
78
		$qname = htmlspecialchars(trim($_POST['newname']));
79
	}
80
	if ($_POST['pipe']) {
81
		$pipe = htmlspecialchars(trim($_POST['pipe']));
82
	} else {
83
		$pipe = htmlspecialchars(trim($qname));
84
	}
85
	if ($_POST['parentqueue']) {
86
		$parentqueue = htmlspecialchars(trim($_POST['parentqueue']));
87
	}
88
}
89

    
90
if ($pipe) {
91
	$dnpipe = $dummynet_pipe_list[$pipe];
92
	if ($dnpipe) {
93
		$queue =& $dnpipe->find_queue($pipe, $qname);
94
	} else {
95
		$addnewpipe = true;
96
	}
97
}
98

    
99
$dontshow = false;
100
$newqueue = false;
101
$output_form = "";
102

    
103
if ($_GET) {
104
	switch ($action) {
105
		case "delete":
106
			if ($queue) {
107
				if (is_array($config['filter']['rule'])) {
108
					foreach ($config['filter']['rule'] as $rule) {
109
						if ($rule['dnpipe'] == $queue->GetQname() || $rule['pdnpipe'] == $queue->GetQname()) {
110
							$input_errors[] = gettext("This pipe/queue is referenced in filter rules, please remove references from there before deleting.");
111
						}
112
					}
113
				}
114
				if (!$input_errors) {
115
					$queue->delete_queue();
116
					if (write_config()) {
117
						mark_subsystem_dirty('shaper');
118
					}
119
					header("Location: firewall_shaper_vinterface.php");
120
					exit;
121
				}
122
				$output_form .= $queue->build_form();
123
			} else {
124
				$input_errors[] = sprintf(gettext("No queue with name %s was found!"),$qname);
125
				$output_form .= $dn_default_shaper_msg;
126
				$dontshow = true;
127
			}
128
			break;
129
		case "resetall":
130
			foreach ($dummynet_pipe_list as $dn) {
131
				$dn->delete_queue();
132
			}
133
			unset($dummynet_pipe_list);
134
			$dummynet_pipe_list = array();
135
			unset($config['dnshaper']['queue']);
136
			unset($queue);
137
			unset($pipe);
138
			$can_add = false;
139
			$can_enable = false;
140
			$dontshow = true;
141
			foreach ($config['filter']['rule'] as $key => $rule) {
142
				if (isset($rule['dnpipe'])) {
143
					unset($config['filter']['rule'][$key]['dnpipe']);
144
				}
145
				if (isset($rule['pdnpipe'])) {
146
					unset($config['filter']['rule'][$key]['pdnpipe']);
147
				}
148
			}
149
			if (write_config()) {
150
				$retval = 0;
151
				$retval = filter_configure();
152
				$savemsg = get_std_save_message($retval);
153

    
154
				if (stristr($retval, "error") <> true) {
155
					$savemsg = get_std_save_message($retval);
156
				} else {
157
					$savemsg = $retval;
158
				}
159
			} else {
160
				$savemsg = gettext("Unable to write config.xml (Access Denied?)");
161
			}
162
			$output_form = $dn_default_shaper_message;
163

    
164
			break;
165
		case "add":
166
			if ($dnpipe) {
167
				$q = new dnqueue_class();
168
				$q->SetPipe($pipe);
169
				$output_form .= "<input type=\"hidden\" name=\"parentqueue\" id=\"parentqueue\"";
170
				$output_form .= " value=\"".$pipe."\" />";
171
			} else if ($addnewpipe) {
172
				$q = new dnpipe_class();
173
				$q->SetQname($pipe);
174
			} else {
175
				$input_errors[] = gettext("Could not create new queue/discipline!");
176
			}
177

    
178
			if ($q) {
179
				$output_form .= $q->build_form();
180
				$newjavascript = $q->build_javascript();
181
				unset($q);
182
				$newqueue = true;
183
			}
184
			break;
185
		case "show":
186
			if ($queue) {
187
			   $output_form .= $queue->build_form();
188
			} else {
189
				$input_errors[] = gettext("Queue not found!");
190
			}
191
			break;
192
		case "enable":
193
			if ($queue) {
194
				$queue->SetEnabled("on");
195
				$output_form .= $queue->build_form();
196
				$queue->wconfig();
197
				if (write_config()) {
198
					mark_subsystem_dirty('shaper');
199
				}
200
			} else {
201
				$input_errors[] = gettext("Queue not found!");
202
			}
203
			break;
204
		case "disable":
205
			if ($queue) {
206
				$queue->SetEnabled("");
207
				$output_form .= $queue->build_form();
208
				$queue->wconfig();
209
				if (write_config()) {
210
					mark_subsystem_dirty('shaper');
211
				}
212
			} else {
213
				$input_errors[] = gettext("Queue not found!");
214
			}
215
			break;
216
		default:
217
			$output_form .= $dn_default_shaper_msg;
218
			$dontshow = true;
219
			break;
220
	}
221
} else if ($_POST) {
222
	unset($input_errors);
223

    
224
	if ($addnewpipe) {
225
		if (!empty($dummynet_pipe_list[$qname])) {
226
			$input_errors[] = gettext("You cannot name a child queue with the same name as a parent limiter");
227
		} else {
228
			$dnpipe =& new dnpipe_class();
229

    
230
			$dnpipe->ReadConfig($_POST);
231
			$dnpipe->validate_input($_POST, $input_errors);
232
			if (!$input_errors) {
233
				$number = dnpipe_find_nextnumber();
234
				$dnpipe->SetNumber($number);
235
				unset($tmppath);
236
				$tmppath[] = $dnpipe->GetQname();
237
				$dnpipe->SetLink($tmppath);
238
				$dnpipe->wconfig();
239
				if (write_config()) {
240
					mark_subsystem_dirty('shaper');
241
				}
242
				$can_enable = true;
243
				$can_add = true;
244
			}
245

    
246
			read_dummynet_config();
247
			$output_form .= $dnpipe->build_form();
248
			$newjavascript = $dnpipe->build_javascript();
249
		}
250
	} else if ($parentqueue) { /* Add a new queue */
251
		if (!empty($dummynet_pipe_list[$qname])) {
252
			$input_errors[] = gettext("You cannot name a child queue with the same name as a parent limiter");
253
		} else if ($dnpipe) {
254
			$tmppath =& $dnpipe->GetLink();
255
			array_push($tmppath, $qname);
256
			$tmp =& $dnpipe->add_queue($pipe, $_POST, $tmppath, $input_errors);
257
			if (!$input_errors) {
258
				array_pop($tmppath);
259
				$tmp->wconfig();
260
				if (write_config()) {
261
					$can_enable = true;
262
					$can_add = false;
263
					mark_subsystem_dirty('shaper');
264
				}
265
			}
266
			read_dummynet_config();
267
			$output_form .= $tmp->build_form();
268
		} else {
269
			$input_errors[] = gettext("Could not add new queue.");
270
		}
271
	} else if ($_POST['apply']) {
272
		write_config();
273

    
274
		$retval = 0;
275
		$retval = filter_configure();
276
		$savemsg = get_std_save_message($retval);
277

    
278
		if (stristr($retval, "error") <> true) {
279
			$savemsg = get_std_save_message($retval);
280
		} else {
281
			$savemsg = $retval;
282
		}
283

    
284
		/* XXX: TODO Make dummynet pretty graphs */
285
		//	enable_rrd_graphing();
286

    
287
		clear_subsystem_dirty('shaper');
288

    
289
		if ($queue) {
290
			$output_form .= $queue->build_form();
291
			$dontshow = false;
292
		} else {
293
			$output_form .= $dn_default_shaper_message;
294
			$dontshow = true;
295
		}
296
	} else if ($queue) {
297
		$queue->validate_input($_POST, $input_errors);
298
		if (!$input_errors) {
299
			$queue->update_dn_data($_POST);
300
			$queue->wconfig();
301
			if (write_config()) {
302
				mark_subsystem_dirty('shaper');
303
			}
304
			$dontshow = false;
305
		}
306
		read_dummynet_config();
307
		$output_form .= $queue->build_form();
308
	} else  {
309
		$output_form .= $dn_default_shaper_msg;
310
		$dontshow = true;
311
	}
312
} else {
313
	$output_form .= $dn_default_shaper_msg;
314
	$dontshow = true;
315
}
316

    
317
if ($queue) {
318
	if ($queue->GetEnabled()) {
319
		$can_enable = true;
320
	} else {
321
		$can_enable = false;
322
	}
323
	if ($queue->CanHaveChildren()) {
324
		$can_add = true;
325
	} else {
326
		$can_add = false;
327
	}
328
}
329

    
330
$tree = "<ul class=\"tree\" >";
331
if (is_array($dummynet_pipe_list)) {
332
	foreach ($dummynet_pipe_list as $tmpdn) {
333
		$tree .= $tmpdn->build_tree();
334
	}
335
}
336
$tree .= "</ul>";
337

    
338
if (!$dontshow || $newqueue) {
339

    
340
$output_form .= "<tr><td width=\"22%\" valign=\"top\" class=\"vncellreq\">";
341
$output_form .= gettext("Queue Actions");
342
$output_form .= "</td><td valign=\"top\" class=\"vncellreq\" width=\"78%\">";
343

    
344
$output_form .= "<input type=\"submit\" name=\"Submit\" value=\"" . gettext("Save") . "\" class=\"formbtn\" />";
345
if ($can_add || $addnewaltq) {
346
	$output_form .= "<a href=\"firewall_shaper_vinterface.php?pipe=";
347
	$output_form .= $pipe;
348
	if ($queue) {
349
		$output_form .= "&amp;queue=" . $queue->GetQname();
350
	}
351
	$output_form .= "&amp;action=add\">";
352
	$output_form .= "<input type=\"button\" class=\"formbtn\" name=\"add\" value=\"" . gettext("Add new queue") ."\" />";
353
	$output_form .= "</a>";
354
}
355
$output_form .= "<a href=\"firewall_shaper_vinterface.php?pipe=";
356
$output_form .= $pipe;
357
if ($queue) {
358
	$output_form .= "&amp;queue=" . $queue->GetQname();
359
}
360
$output_form .= "&amp;action=delete\">";
361
$output_form .= "<input type=\"button\" class=\"formbtn\" name=\"delete\"";
362
if ($queue) {
363
	$output_form .= " value=\"" . gettext("Delete this queue") ."\" />";
364
} else {
365
	$output_form .= " value=\"" . gettext("Delete Limiter") ."\" />";
366
}
367
$output_form .= "</a>";
368
$output_form .= "</td></tr>";
369
$output_form .= "</table>";
370
} else {
371
	$output_form .= "</table>";
372
}
373

    
374
$output = "<table summary=\"output form\">";
375
$output .= $output_form;
376
$closehead = false;
377
include("head.inc");
378
?>
379
<link rel="stylesheet" type="text/css" media="all" href="./tree/tree.css" />
380
<script type="text/javascript" src="./tree/tree.js"></script>
381
<script type="text/javascript">
382
//<![CDATA[
383
function show_source_port_range() {
384
	document.getElementById("sprtable").style.display = '';
385
	document.getElementById("sprtable1").style.display = '';
386
	document.getElementById("sprtable2").style.display = '';
387
	document.getElementById("sprtable5").style.display = '';
388
	document.getElementById("sprtable4").style.display = 'none';
389
	document.getElementById("showadvancedboxspr").innerHTML='';
390
}
391
//]]>
392
</script>
393
</head>
394

    
395
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
396

    
397
<?php
398
if ($queue) {
399
	echo $queue->build_javascript();
400
} else {
401
	echo $newjavascript;
402
}
403

    
404
include("fbegin.inc");
405
?>
406
<div id="inputerrors"></div>
407
<?php if ($input_errors) print_input_errors($input_errors); ?>
408

    
409
<form action="firewall_shaper_vinterface.php" method="post" id="iform" name="iform">
410

    
411
<?php if ($savemsg) print_info_box($savemsg); ?>
412
<?php if (is_subsystem_dirty('shaper')): ?><p>
413
<?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 /></p>
414
<?php endif; ?>
415
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="traffic shaper limiter">
416
	<tr><td>
417
<?php
418
	$tab_array = array();
419
	$tab_array[0] = array(gettext("By Interface"), false, "firewall_shaper.php");
420
	$tab_array[1] = array(gettext("By Queue"), false, "firewall_shaper_queues.php");
421
	$tab_array[2] = array(gettext("Limiter"), true, "firewall_shaper_vinterface.php");
422
	$tab_array[3] = array(gettext("Layer7"), false, "firewall_shaper_layer7.php");
423
	$tab_array[4] = array(gettext("Wizards"), false, "firewall_shaper_wizards.php");
424
	display_top_tabs($tab_array);
425
?>
426
	</td></tr>
427
	<tr>
428
		<td>
429
			<div id="mainarea">
430
				<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="main area">
431
<?php if (count($dummynet_pipe_list) > 0): ?>
432
					<tr class="tabcont">
433
						<td width="25%" align="left"></td>
434
						<td width="75%"> </td>
435
					</tr>
436
<?php endif; ?>
437
					<tr>
438
						<td width="25%" valign="top" align="left">
439
							<?php
440
								echo $tree;
441
							?>
442
							<br /><br />
443
							<a href="firewall_shaper_vinterface.php?pipe=new&amp;action=add">
444
								<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="<?=gettext("Create new limiter");?>" width="17" height="17" border="0" alt="add" />&nbsp;<?=gettext("Create new limiter");?>
445
							</a>
446
							<br />
447
						</td>
448
						<td width="75%" valign="top" align="center">
449
							<div id="shaperarea" style="position:relative">
450
								<?php
451
									echo $output;
452
								?>
453
							</div>
454
						</td>
455
					</tr>
456
				</table>
457
			</div>
458
		</td>
459
	</tr>
460
</table>
461
</form>
462
<script type='text/javascript'>
463
//<![CDATA[
464
<?php
465
	$totalrows = 0;
466
	if (is_array($config['dnshaper']) && is_array($config['dnshaper']['queue'])) {
467
		$totalrows = count($config['dnshaper']['queue']);
468
	}
469
	echo "totalrows = {$totalrows}";
470
?>
471
//]]>
472
</script>
473
<?php include("fend.inc"); ?>
474
</body>
475
</html>
(78-78/252)