Project

General

Profile

Download (12 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("Firewall","Traffic Shaper", "Limiter");
55

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

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

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

    
88
$dontshow = false;
89
$newqueue = false;
90
$output_form = "";
91

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

    
126
                        if (stristr($retval, "error") <> true)
127
	                        $savemsg = get_std_save_message($retval);
128
                        else
129
       	                	$savemsg = $retval;
130
			
131
			$output_form = $dn_default_shaper_message;
132

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

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

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

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

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

    
232
 		/* XXX: TODO Make dummynet pretty graphs */ 
233
		//	enable_rrd_graphing();
234

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

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

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

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

    
285
if (!$dontshow || $newqueue) {
286

    
287
$output_form .= "<tr><td width=\"22%\" valign=\"top\" class=\"vncellreq\">";
288
$output_form .= "Queue Actions";
289
$output_form .= "</td><td valign=\"top\" class=\"vncellreq\" width=\"78%\">";
290

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

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

    
336
include("head.inc");
337
?>
338

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

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

    
359
<form action="firewall_shaper_vinterface.php" method="post" id="iform" name="iform">
360

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

    
402
		      </td></tr>
403
                    </table>
404
		</div>
405
	  </td>
406
	</tr>
407
</table>
408
            </form>
409
<?php include("fend.inc"); 
410
?>
411
</body>
412
</html>
(64-64/218)