Project

General

Profile

Download (11.9 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

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

    
51
$pgtitle = array("Firewall","Traffic Shaper", "Limiter");
52

    
53
read_dummynet_config();
54
/* 
55
 * The whole logic in these code maybe can be specified.
56
 * If you find a better way contact me :).
57
 */
58

    
59
if ($_GET) {
60
	if ($_GET['queue'])
61
        	$qname = trim($_GET['queue']);
62
        if ($_GET['pipe'])
63
                $pipe = trim($_GET['pipe']);
64
        if ($_GET['action'])
65
                $action = $_GET['action'];
66
}
67
if ($_POST) {
68
	if ($_POST['name'])
69
        	$qname = trim($_POST['name']);
70
        if ($_POST['pipe'])
71
        	$pipe = trim($_POST['pipe']);
72
	else
73
		$pipe = trim($_POST['name']);
74
	if ($_POST['parentqueue'])
75
		$parentqueue = trim($_POST['parentqueue']);
76
}
77

    
78
if ($pipe) {
79
	$dnpipe = $dummynet_pipe_list[$pipe];
80
	if ($dnpipe) {
81
		$queue =& $dnpipe->find_queue($pipe, $qname);
82
	} else $addnewpipe = true;
83
}
84

    
85
$dontshow = false;
86
$newqueue = false;
87
$output_form = "";
88

    
89
if ($_GET) {
90
	switch ($action) {
91
	case "delete":
92
			if ($queue) {
93
				$queue->delete_queue();
94
				write_config();
95
				mark_subsystem_dirty('shaper');
96
			}
97
			header("Location: firewall_shaper_vinterface.php");
98
			exit;
99
		break;
100
	case "resetall":
101
			foreach ($dummynet_pipe_list as $dn)
102
				$dn->delete_queue();
103
			unset($dummynet_pipe_list);
104
			$dummynet_pipe_list = array();
105
			unset($config['dnshaper']['queue']);
106
			unset($queue);
107
			unset($pipe);
108
			$can_add = false;
109
			$can_enable = false;
110
			$dontshow = true;
111
			foreach ($config['filter']['rule'] as $key => $rule) {
112
				if (isset($rule['dnpipe']))
113
					unset($config['filter']['rule'][$key]['dnpipe']);
114
				if (isset($rule['pdnpipe']))
115
					unset($config['filter']['rule'][$key]['pdnpipe']);
116
			}
117
			write_config();
118
			
119
			$retval = 0;
120
                        $retval = filter_configure();
121
                        $savemsg = get_std_save_message($retval);
122

    
123
                        if (stristr($retval, "error") <> true)
124
	                        $savemsg = get_std_save_message($retval);
125
                        else
126
       	                	$savemsg = $retval;
127
			
128
			$output_form = $dn_default_shaper_message;
129

    
130
		break;
131
	case "add":
132
		if ($dnpipe) {
133
			$q = new dnqueue_class();
134
			$q->SetPipe($pipe);
135
			$output_form .= "<input type=\"hidden\" name=\"parentqueue\" id=\"parentqueue\"";
136
			$output_form .= " value=\"".$pipe."\">";
137
		} else if ($addnewpipe) {
138
			$q = new dnpipe_class();
139
			$q->SetQname($pipe);
140
		} else 
141
			$input_errors[] = "Could not create new queue/discipline!";
142

    
143
			if ($q) {
144
				$output_form .= $q->build_form();
145
                unset($q);
146
				$newqueue = true;
147
			}
148
		break;
149
	case "show":
150
		if ($queue)  
151
                       $output_form .= $queue->build_form();
152
		else
153
			$input_errors[] = "Queue not found!";
154
		break;
155
	case "enable":
156
		if ($queue) {
157
				$queue->SetEnabled("on");
158
				$output_form .= $queue->build_form();
159
				write_config();
160
				mark_subsystem_dirty('shaper');
161
		} else
162
				$input_errors[] = "Queue not found!";
163
		break;
164
	case "disable":
165
		if ($queue) {
166
				$queue->SetEnabled("");
167
				$output_form .= $queue->build_form();
168
				write_config();
169
				mark_subsystem_dirty('shaper');
170
		} else
171
				$input_errors[] = "Queue not found!";
172
		break;
173
	default:
174
		$output_form .= "<p class=\"pgtitle\">" . $dn_default_shaper_msg."</p>";
175
		$dontshow = true;
176
		break;
177
	}
178
} else if ($_POST) {
179
	unset($input_errors);
180

    
181
	if ($addnewpipe) {
182
		$dnpipe =& new dnpipe_class();
183
		
184
		$dnpipe->ReadConfig($_POST);
185
		$dnpipe->validate_input($_POST, &$input_errors);
186
		if (!$input_errors) {
187
			unset($tmppath);
188
			$tmppath[] = $dnpipe->GetQname();
189
			$dnpipe->SetLink(&$tmppath);	
190
			$dnpipe->wconfig();
191
			write_config();
192
			mark_subsystem_dirty('shaper');
193
			$can_enable = true;
194
       		     	$can_add = true;
195
		}
196
		read_dummynet_config();
197
		$output_form .= $dnpipe->build_form();
198

    
199
	} else if ($parentqueue) { /* Add a new queue */
200
		if ($dnpipe) {
201
			$tmppath =& $dnpipe->GetLink();
202
			array_push($tmppath, $qname);
203
			$tmp =& $dnpipe->add_queue($pipe, $_POST, $tmppath, &$input_errors);
204
			if (!$input_errors) {
205
				array_pop($tmppath);
206
				$tmp->wconfig();
207
				write_config();
208
				$can_enable = true;
209
                		$can_add = false;
210
				mark_subsystem_dirty('shaper');
211
				$can_enable = true;
212
			}
213
			read_dummynet_config();
214
			$output_form .= $tmp->build_form();			
215
		} else
216
			$input_errors[] = "Could not add new queue.";
217
	} else if ($_POST['apply']) {
218
			write_config();
219

    
220
			$retval = 0;
221
			$retval = filter_configure();
222
			$savemsg = get_std_save_message($retval);
223
			
224
			if (stristr($retval, "error") <> true)
225
					$savemsg = get_std_save_message($retval);
226
			else
227
					$savemsg = $retval;
228

    
229
 		/* XXX: TODO Make dummynet pretty graphs */ 
230
		//	enable_rrd_graphing();
231

    
232
			clear_subsystem_dirty('shaper');
233
			
234
			if ($queue) {
235
				$output_form .= $queue->build_form();
236
				$dontshow = false;
237
			}
238
			else {
239
				$output_form .= $dn_default_shaper_message;
240
				$dontshow = true;
241
			}
242

    
243
	} else if ($queue) {
244
                $queue->validate_input($_POST, &$input_errors);
245
                if (!$input_errors) {
246
                            	$queue->update_dn_data($_POST);
247
                            	$queue->wconfig();
248
				write_config();
249
				mark_subsystem_dirty('shaper');
250
				$dontshow = false;
251
                } 
252
		read_dummynet_config();
253
		$output_form .= $queue->build_form();
254
	} else  {
255
		$output_form .= "<p class=\"pgtitle\">" . $dn_default_shaper_msg."</p>";
256
		$dontshow = true;
257
	}
258
} else {
259
	$output_form .= "<p class=\"pgtitle\">" . $dn_default_shaper_msg."</p>";
260
	$dontshow = true;
261
}
262

    
263
if ($queue) {
264
                        if ($queue->GetEnabled())
265
                                $can_enable = true;
266
                        else
267
                                $can_enable = false;
268
                        if ($queue->CanHaveChildren()) { 
269
                       		$can_add = true;
270
                        } else
271
                                $can_add = false;
272
}
273

    
274
$tree = "<ul class=\"tree\" >";
275
if (is_array($dummynet_pipe_list)) {
276
        foreach ($dummynet_pipe_list as $tmpdn) {
277
                $tree .= $tmpdn->build_tree();
278
        }
279
}
280
$tree .= "</ul>";
281

    
282
if (!$dontshow || $newqueue) {
283

    
284
$output_form .= "<tr><td width=\"22%\" valign=\"top\" class=\"vncellreq\">";
285
$output_form .= "Queue Actions";
286
$output_form .= "</td><td valign=\"top\" class=\"vncellreq\" width=\"78%\">";
287

    
288
$output_form .= "<input type=\"submit\" name=\"Submit\" value=\"" . gettext("Save") . "\" class=\"formbtn\" />";
289
if ($can_add || $addnewaltq) {
290
	$output_form .= "<a href=\"firewall_shaper_vinterface.php?pipe=";
291
	$output_form .= $pipe; 
292
	if ($queue) {
293
		$output_form .= "&queue=" . $queue->GetQname();
294
	}
295
	$output_form .= "&action=add\">";
296
	$output_form .= "<input type=\"button\" class=\"formbtn\" name=\"add\" value=\"Add new queue\">";
297
	$output_form .= "</a>";
298
}
299
$output_form .= "<a href=\"firewall_shaper_vinterface.php?pipe=";
300
$output_form .= $pipe . "&queue=";
301
if ($queue) {
302
	$output_form .= "&queue=" . $queue->GetQname();
303
}
304
$output_form .= "&action=delete\">";
305
$output_form .= "<input type=\"button\" class=\"formbtn\" name=\"delete\"";
306
if ($queue)
307
	$output_form .= " value=\"Delete this queue\">";
308
else
309
	$output_form .= " value=\"Delete virtual interface\">";
310
$output_form .= "</a>";  
311
$output_form .= "</td></tr>";
312
$output_form .= "</div>";
313
} 
314
else 
315
	$output_form .= "</div>";
316

    
317
$output = "<div id=\"shaperarea\" style=\"position:relative\">";
318
if (!$dontshow) {
319
if ($queue || $dnpipe || $newqueue) {
320
	$output .= "<tr><td valign=\"top\" class=\"vncellreq\"><br>";
321
	$output .= "Enable/Disable";
322
	$output .= "</td><td class=\"vncellreq\">";
323
	$output .= " <input type=\"checkbox\" id=\"enabled\" name=\"enabled\"";
324
	if ($queue)
325
		if ($queue->GetEnabled() <> "")
326
       			$output .=  " CHECKED";
327
	$output .= " ><span class=\"vexpl\"> Enable/Disable queue and its children.</span>";
328
	$output .= "</td></tr>";
329
}
330
}
331
$output .= $output_form;
332

    
333
include("head.inc");
334
?>
335

    
336
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" >
337
<link rel="stylesheet" type="text/css" media="all" href="./tree/tree.css" />
338
<script type="text/javascript" src="./tree/tree.js"></script>
339
<script type="text/javascript">
340
function show_source_port_range() {
341
        document.getElementById("sprtable").style.display = '';
342
	document.getElementById("sprtable1").style.display = '';
343
	document.getElementById("sprtable2").style.display = '';
344
	document.getElementById("sprtable5").style.display = '';
345
	document.getElementById("sprtable4").style.display = 'none';
346
	document.getElementById("showadvancedboxspr").innerHTML='';
347
}
348
</script>
349

    
350
<?php
351
include("fbegin.inc"); 
352
?>
353
<div id="inputerrors"></div>
354
<?php if ($input_errors) print_input_errors($input_errors); ?>
355

    
356
<form action="firewall_shaper_vinterface.php" method="post" id="iform" name="iform">
357

    
358
<?php if ($savemsg) print_info_box($savemsg); ?>
359
<?php if (is_subsystem_dirty('shaper')): ?><p>
360
<?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>
361
<?php endif; ?>
362
<table width="100%" border="0" cellpadding="0" cellspacing="0">
363
  <tr><td>
364
<?php
365
	$tab_array = array();
366
	$tab_array[0] = array("By Interface", false, "firewall_shaper.php");
367
	$tab_array[1] = array("By Queue", false, "firewall_shaper_queues.php");
368
	$tab_array[2] = array("Limiter", true, "firewall_shaper_vinterface.php");
369
	$tab_array[3] = array("Layer7", false, "firewall_shaper_layer7.php");
370
	$tab_array[4] = array("Wizards", false, "firewall_shaper_wizards.php");
371
	display_top_tabs($tab_array);
372
?>
373
  </td></tr>
374
  <tr>
375
    <td>
376
	<div id="mainarea">
377
              <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
378
<?php if (count($dummynet_pipe_list) > 0): ?>
379
                        <tr class="tabcont"><td width="25%" align="left">
380
                        </td><td width="75%"> </td></tr>
381
<? endif; ?>
382
			<tr>
383
			<td width="25%" valign="top" algin="left">
384
			<?php
385
				echo $tree; 
386
			?>
387
			<br/><br/>
388
			<a href="firewall_shaper_vinterface.php?pipe=new&action=add">
389
			<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="Create new limiter" width="17" height="17" border="0">  Create new limiter
390
			</a><br/>
391
			</td>
392
			<td width="75%" valign="top" align="center">
393
			<table>
394
			<?
395
				echo $output;
396
			?>	
397
			</table>
398

    
399
		      </td></tr>
400
                    </table>
401
		</div>
402
	  </td>
403
	</tr>
404
</table>
405
            </form>
406
<?php include("fend.inc"); 
407
?>
408
</body>
409
</html>
(63-63/215)