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
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
20
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
23
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
	POSSIBILITY OF SUCH DAMAGE.
29
*/
30

    
31
##|+PRIV
32
##|*IDENT=page-firewall-trafficshaper-limiter
33
##|*NAME=Firewall: Traffic Shaper: Limiter page
34
##|*DESCR=Allow access to the 'Firewall: Traffic Shaper: Limiter' page.
35
##|*MATCH=firewall_shaper_vinterface.php*
36
##|-PRIV
37

    
38

    
39
require("guiconfig.inc");
40

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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