Project

General

Profile

Download (11.8 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 = trim($_GET['queue']);
66
        if ($_GET['pipe'])
67
                $pipe = trim($_GET['pipe']);
68
        if ($_GET['action'])
69
                $action = $_GET['action'];
70
}
71
if ($_POST) {
72
	if ($_POST['name'])
73
        	$qname = trim($_POST['name']);
74
        if ($_POST['pipe'])
75
        	$pipe = trim($_POST['pipe']);
76
	else
77
		$pipe = trim($_POST['name']);
78
	if ($_POST['parentqueue'])
79
		$parentqueue = trim($_POST['parentqueue']);
80
}
81

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
321
$output = "<div id=\"shaperarea\" style=\"position:relative\">";
322
$output .= $output_form;
323

    
324
include("head.inc");
325
?>
326

    
327
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" >
328
<link rel="stylesheet" type="text/css" media="all" href="./tree/tree.css" />
329
<script type="text/javascript" src="./tree/tree.js"></script>
330
<script type="text/javascript">
331
function show_source_port_range() {
332
        document.getElementById("sprtable").style.display = '';
333
	document.getElementById("sprtable1").style.display = '';
334
	document.getElementById("sprtable2").style.display = '';
335
	document.getElementById("sprtable5").style.display = '';
336
	document.getElementById("sprtable4").style.display = 'none';
337
	document.getElementById("showadvancedboxspr").innerHTML='';
338
}
339
</script>
340

    
341
<?php
342
include("fbegin.inc"); 
343
?>
344
<div id="inputerrors"></div>
345
<?php if ($input_errors) print_input_errors($input_errors); ?>
346

    
347
<form action="firewall_shaper_vinterface.php" method="post" id="iform" name="iform">
348

    
349
<?php if ($savemsg) print_info_box($savemsg); ?>
350
<?php if (is_subsystem_dirty('shaper')): ?><p>
351
<?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>
352
<?php endif; ?>
353
<table width="100%" border="0" cellpadding="0" cellspacing="0">
354
  <tr><td>
355
<?php
356
	$tab_array = array();
357
	$tab_array[0] = array(gettext("By Interface"), false, "firewall_shaper.php");
358
	$tab_array[1] = array(gettext("By Queue"), false, "firewall_shaper_queues.php");
359
	$tab_array[2] = array(gettext("Limiter"), true, "firewall_shaper_vinterface.php");
360
	$tab_array[3] = array(gettext("Layer7"), false, "firewall_shaper_layer7.php");
361
	$tab_array[4] = array(gettext("Wizards"), false, "firewall_shaper_wizards.php");
362
	display_top_tabs($tab_array);
363
?>
364
  </td></tr>
365
  <tr>
366
    <td>
367
	<div id="mainarea">
368
              <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
369
<?php if (count($dummynet_pipe_list) > 0): ?>
370
                        <tr class="tabcont"><td width="25%" align="left">
371
                        </td><td width="75%"> </td></tr>
372
<?php endif; ?>
373
			<tr>
374
			<td width="25%" valign="top" algin="left">
375
			<?php
376
				echo $tree; 
377
			?>
378
			<br/><br/>
379
			<a href="firewall_shaper_vinterface.php?pipe=new&action=add">
380
			<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");?>
381
			</a><br/>
382
			</td>
383
			<td width="75%" valign="top" align="center">
384
			<table>
385
			<?
386
				echo $output;
387
			?>	
388
			</table>
389

    
390
		      </td></tr>
391
                    </table>
392
		</div>
393
	  </td>
394
	</tr>
395
</table>
396
            </form>
397
<?php include("fend.inc"); 
398
?>
399
</body>
400
</html>
(64-64/222)