Projet

Général

Profil

Télécharger (13,3 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / firewall_shaper_vinterface.php @ 6b71ebb7

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
$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
        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->GetQname() || $rule['pdnpipe'] == $queue->GetQname())
102
						$input_errors[] = gettext("This pipe/queue is referenced in filter rules, please remove references from there before deleting.");
103
				}
104
			}
105
			if (!$input_errors) {
106
				$queue->delete_queue();
107
				if (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 .= $dn_default_shaper_msg;
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
		if (write_config()) {
137
			$retval = 0;
138
			$retval = filter_configure();
139
			$savemsg = get_std_save_message($retval);
140

    
141
			if (stristr($retval, "error") <> true)
142
				$savemsg = get_std_save_message($retval);
143
			else
144
				$savemsg = $retval;
145
		} else
146
			$savemsg = gettext("Unable to write config.xml (Access Denied?)");
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
			$newjavascript = $q->build_javascript();
165
			unset($q);
166
			$newqueue = true;
167
		}
168
		break;
169
	case "show":
170
		if ($queue)  
171
                       $output_form .= $queue->build_form();
172
		else
173
			$input_errors[] = gettext("Queue not found!");
174
		break;
175
	case "enable":
176
		if ($queue) {
177
			$queue->SetEnabled("on");
178
			$output_form .= $queue->build_form();
179
			$queue->wconfig();
180
			if (write_config())
181
				mark_subsystem_dirty('shaper');
182
		} else
183
			$input_errors[] = gettext("Queue not found!");
184
		break;
185
	case "disable":
186
		if ($queue) {
187
			$queue->SetEnabled("");
188
			$output_form .= $queue->build_form();
189
			$queue->wconfig();
190
			if (write_config())
191
				mark_subsystem_dirty('shaper');
192
		} else
193
			$input_errors[] = gettext("Queue not found!");
194
		break;
195
	default:
196
		$output_form .= $dn_default_shaper_msg;
197
		$dontshow = true;
198
		break;
199
	}
200
} else if ($_POST) {
201
	unset($input_errors);
202

    
203
	if ($addnewpipe) {
204
		if (!empty($dummynet_pipe_list[$qname]))
205
			$input_errors[] = gettext("You cannot name a child queue with the same name as a parent limiter");
206
		else {
207
			$dnpipe =& new dnpipe_class();
208
			
209
			$dnpipe->ReadConfig($_POST);
210
			$dnpipe->validate_input($_POST, &$input_errors);
211
			if (!$input_errors) {
212
				$number = dnpipe_find_nextnumber();
213
				$dnpipe->SetNumber($number);
214
				unset($tmppath);
215
				$tmppath[] = $dnpipe->GetQname();
216
				$dnpipe->SetLink(&$tmppath);	
217
				$dnpipe->wconfig();
218
				if (write_config())
219
					mark_subsystem_dirty('shaper');
220
				$can_enable = true;
221
				$can_add = true;
222
			}
223

    
224
			read_dummynet_config();
225
			$output_form .= $dnpipe->build_form();
226
			$newjavascript = $dnpipe->build_javascript();
227
		}
228
	} else if ($parentqueue) { /* Add a new queue */
229
		if (!empty($dummynet_pipe_list[$qname]))
230
			$input_errors[] = gettext("You cannot name a child queue with the same name as a parent limiter");
231
		else if ($dnpipe) {
232
			$tmppath =& $dnpipe->GetLink();
233
			array_push($tmppath, $qname);
234
			$tmp =& $dnpipe->add_queue($pipe, $_POST, $tmppath, &$input_errors);
235
			if (!$input_errors) {
236
				array_pop($tmppath);
237
				$tmp->wconfig();
238
				if (write_config()) {
239
					$can_enable = true;
240
					$can_add = false;
241
					mark_subsystem_dirty('shaper');
242
				}
243
			}
244
			read_dummynet_config();
245
			$output_form .= $tmp->build_form();
246
		} else
247
			$input_errors[] = gettext("Could not add new queue.");
248
	} else if ($_POST['apply']) {
249
			write_config();
250

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

    
260
 		/* XXX: TODO Make dummynet pretty graphs */ 
261
		//	enable_rrd_graphing();
262

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

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

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

    
305
$tree = "<ul class=\"tree\" >";
306
$rowIndex = 0;
307
if (is_array($dummynet_pipe_list)) {
308
        foreach ($dummynet_pipe_list as $tmpdn) {
309
			$rowIndex++;
310
                $tree .= $tmpdn->build_tree();
311
        }
312
}
313
if ($rowIndex == 0)
314
	$tree .= "<li></li>";
315
$tree .= "</ul>";
316

    
317
if (!$dontshow || $newqueue) {
318

    
319
$output_form .= "<tr><td width=\"22%\" valign=\"top\" class=\"vncellreq\">";
320
$output_form .= gettext("Queue Actions");
321
$output_form .= "</td><td valign=\"top\" class=\"vncellreq\" width=\"78%\">";
322

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

    
352
$output = "<table summary=\"output form\">";
353
$output .= $output_form;
354
$closehead = false;
355
include("head.inc");
356
?>
357
<link rel="stylesheet" type="text/css" media="all" href="./tree/tree.css" />
358
<script type="text/javascript" src="./tree/tree.js"></script>
359
<script type="text/javascript">
360
//<![CDATA[
361
function show_source_port_range() {
362
        document.getElementById("sprtable").style.display = '';
363
	document.getElementById("sprtable1").style.display = '';
364
	document.getElementById("sprtable2").style.display = '';
365
	document.getElementById("sprtable5").style.display = '';
366
	document.getElementById("sprtable4").style.display = 'none';
367
	document.getElementById("showadvancedboxspr").innerHTML='';
368
}
369
//]]>
370
</script>
371
</head>
372

    
373
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
374

    
375
<?php
376
if ($queue)
377
	echo $queue->build_javascript();
378
else
379
	echo $newjavascript;
380

    
381
include("fbegin.inc"); 
382
?>
383
<div id="inputerrors"></div>
384
<?php if ($input_errors) print_input_errors($input_errors); ?>
385

    
386
<form action="firewall_shaper_vinterface.php" method="post" id="iform" name="iform">
387

    
388
<?php if ($savemsg) print_info_box($savemsg); ?>
389
<?php if (is_subsystem_dirty('shaper')): ?><p>
390
<?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>
391
<?php endif; ?>
392
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="traffic shaper limiter">
393
  <tr><td>
394
<?php
395
	$tab_array = array();
396
	$tab_array[0] = array(gettext("By Interface"), false, "firewall_shaper.php");
397
	$tab_array[1] = array(gettext("By Queue"), false, "firewall_shaper_queues.php");
398
	$tab_array[2] = array(gettext("Limiter"), true, "firewall_shaper_vinterface.php");
399
	$tab_array[3] = array(gettext("Layer7"), false, "firewall_shaper_layer7.php");
400
	$tab_array[4] = array(gettext("Wizards"), false, "firewall_shaper_wizards.php");
401
	display_top_tabs($tab_array);
402
?>
403
  </td></tr>
404
  <tr>
405
    <td>
406
	<div id="mainarea">
407
              <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="main area">
408
<?php if (count($dummynet_pipe_list) > 0): ?>
409
                        <tr class="tabcont"><td width="25%" align="left">
410
                        </td><td width="75%"> </td></tr>
411
<?php endif; ?>
412
			<tr>
413
			<td width="25%" valign="top" align="left">
414
			<?php
415
				echo $tree; 
416
			?>
417
			<br/><br/>
418
			<a href="firewall_shaper_vinterface.php?pipe=new&amp;action=add">
419
			<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");?>
420
			</a><br/>
421
			</td>
422
			<td width="75%" valign="top" align="center">
423
			<div id="shaperarea" style="position:relative">
424
			<?php
425
				echo $output;
426
			?>	
427
			</div>
428

    
429
		      </td></tr>
430
                    </table>
431
		</div>
432
	  </td>
433
	</tr>
434
</table>
435
</form>
436
<script type='text/javascript'>
437
//<![CDATA[
438
<?php
439
	$totalrows = 0;
440
	if (is_array($config['dnshaper']) && is_array($config['dnshaper']['queue'])) 
441
		$totalrows = count($config['dnshaper']['queue']);
442
	echo "totalrows = {$totalrows}";
443
?>
444
//]]>
445
</script>
446
<?php include("fend.inc"); ?>
447
</body>
448
</html>
(76-76/246)