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
##|+PRIV
33
##|*IDENT=page-firewall-trafficshaper-limiter
34
##|*NAME=Firewall: Traffic Shaper: Limiter page
35
##|*DESCR=Allow access to the 'Firewall: Traffic Shaper: Limiter' page.
36
##|*MATCH=firewall_shaper_vinterface.php*
37
##|-PRIV
38

    
39

    
40
require("guiconfig.inc");
41

    
42
if($_GET['reset'] <> "") {
43
        mwexec("killall -9 pfctl php");
44
	exit;
45
}
46

    
47
$pgtitle = array("Firewall","Traffic Shaper", "Limiter");
48

    
49
read_dummynet_config();
50
/* 
51
 * The whole logic in these code maybe can be specified.
52
 * If you find a better way contact me :).
53
 */
54

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

    
74
if ($pipe) {
75
	$dnpipe = $dummynet_pipe_list[$pipe];
76
	if ($dnpipe) {
77
		$queue =& $dnpipe->find_queue($pipe, $qname);
78
	} else $addnewpipe = true;
79
}
80

    
81
$dontshow = false;
82
$newqueue = false;
83
$output_form = "";
84

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

    
119
                        if (stristr($retval, "error") <> true)
120
	                        $savemsg = get_std_save_message($retval);
121
                        else
122
       	                	$savemsg = $retval;
123
			
124
			$output_form = $dn_default_shaper_message;
125

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

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

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

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

    
216
			$retval = 0;
217
			$retval = filter_configure();
218
			$savemsg = get_std_save_message($retval);
219
			
220
			if (stristr($retval, "error") <> true)
221
					$savemsg = get_std_save_message($retval);
222
			else
223
					$savemsg = $retval;
224

    
225
 		/* XXX: TODO Make dummynet pretty graphs */ 
226
		//	enable_rrd_graphing();
227

    
228
			clear_subsystem_dirty('shaper');
229
			
230
			if ($queue) {
231
				$output_form .= $queue->build_form();
232
				$dontshow = false;
233
			}
234
			else {
235
				$output_form .= $dn_default_shaper_message;
236
				$dontshow = true;
237
			}
238

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

    
259
if ($queue) {
260
                        if ($queue->GetEnabled())
261
                                $can_enable = true;
262
                        else
263
                                $can_enable = false;
264
                        if ($queue->CanHaveChildren()) { 
265
                       		$can_add = true;
266
                        } else
267
                                $can_add = false;
268
}
269

    
270
$tree = "<ul class=\"tree\" >";
271
if (is_array($dummynet_pipe_list)) {
272
        foreach ($dummynet_pipe_list as $tmpdn) {
273
                $tree .= $tmpdn->build_tree();
274
        }
275
}
276
$tree .= "</ul>";
277

    
278
if (!$dontshow || $newqueue) {
279

    
280
$output_form .= "<tr><td width=\"22%\" valign=\"top\" class=\"vncellreq\">";
281
$output_form .= "Queue Actions";
282
$output_form .= "</td><td valign=\"top\" class=\"vncellreq\" width=\"78%\">";
283

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

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

    
329
include("head.inc");
330
?>
331

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

    
346
<?php
347
include("fbegin.inc"); 
348
?>
349
<div id="inputerrors"></div>
350
<?php if ($input_errors) print_input_errors($input_errors); ?>
351

    
352
<form action="firewall_shaper_vinterface.php" method="post" id="iform" name="iform">
353

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

    
395
		      </td></tr>
396
                    </table>
397
		</div>
398
	  </td>
399
	</tr>
400
</table>
401
            </form>
402
<?php include("fend.inc"); 
403
?>
404
</body>
405
</html>
(63-63/217)