Project

General

Profile

Download (11.8 KB) Statistics
| Branch: | Tag: | Revision:
1 585a8faf Ermal Luçi
<?php
2
/* $Id$ */
3
/*
4
	firewall_shaper.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 6b07c15a Matthew Grooms
##|+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 585a8faf Ermal Luçi
require("guiconfig.inc");
40
41
if($_GET['reset'] <> "") {
42
        mwexec("killall -9 pfctl php");
43
	exit;
44
}
45
46 6d0c07ea Ermal Luçi
$pgtitle = array("Firewall","Traffic Shaper", "Limiter");
47 585a8faf Ermal Luçi
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 d3e5e7df Ermal Luçi
        	$pipe = trim($_POST['pipe']);
67
	else
68
		$pipe = trim($_POST['name']);
69 585a8faf Ermal Luçi
	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
				touch($d_shaperconfdirty_path);
91
			}
92
			header("Location: firewall_shaper_vinterface.php");
93
			exit;
94
		break;
95
	case "resetall":
96
			foreach ($dummynet_pipe_list as $dn)
97 d3e5e7df Ermal Luçi
				$dn->delete_queue();
98 585a8faf Ermal Luçi
			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
                        $savemsg = get_std_save_message($retval);
116
117
                        config_lock();
118
                        $retval = filter_configure();
119
                        config_unlock();
120
121
                        if (stristr($retval, "error") <> true)
122
	                        $savemsg = get_std_save_message($retval);
123
                        else
124
       	                	$savemsg = $retval;
125
			
126
			$output_form = $dn_default_shaper_message;
127
128
		break;
129
	case "add":
130
		if ($dnpipe) {
131 d3e5e7df Ermal Luçi
			$q = new dnqueue_class();
132
			$q->SetPipe($pipe);
133
			$output_form .= "<input type=\"hidden\" name=\"parentqueue\" id=\"parentqueue\"";
134
			$output_form .= " value=\"".$pipe."\">";
135 585a8faf Ermal Luçi
		} else if ($addnewpipe) {
136
			$q = new dnpipe_class();
137
			$q->SetQname($pipe);
138
		} else 
139
			$input_errors[] = "Could not create new queue/discipline!";
140
141
			if ($q) {
142
				$output_form .= $q->build_form();
143
                unset($q);
144
				$newqueue = true;
145
			}
146
		break;
147 d3e5e7df Ermal Luçi
	case "show":
148
		if ($queue)  
149
                       $output_form .= $queue->build_form();
150
		else
151
			$input_errors[] = "Queue not found!";
152 585a8faf Ermal Luçi
		break;
153 d3e5e7df Ermal Luçi
	case "enable":
154
		if ($queue) {
155
				$queue->SetEnabled("on");
156
				$output_form .= $queue->build_form();
157
				write_config();
158
				touch($d_shaperconfdirty_path);
159
		} else
160
				$input_errors[] = "Queue not found!";
161 585a8faf Ermal Luçi
		break;
162 d3e5e7df Ermal Luçi
	case "disable":
163
		if ($queue) {
164
				$queue->SetEnabled("");
165
				$output_form .= $queue->build_form();
166
				write_config();
167
				touch($d_shaperconfdirty_path);
168
		} else
169
				$input_errors[] = "Queue not found!";
170
		break;
171
	default:
172
		$output_form .= "<p class=\"pgtitle\">" . $dn_default_shaper_msg."</p>";
173
		$dontshow = true;
174 585a8faf Ermal Luçi
		break;
175
	}
176
} else if ($_POST) {
177
	unset($input_errors);
178
179
	if ($addnewpipe) {
180
		$dnpipe =& new dnpipe_class();
181
		
182
		$dnpipe->ReadConfig($_POST);
183
		$dnpipe->validate_input($_POST, &$input_errors);
184
		if (!$input_errors) {
185
			unset($tmppath);
186
			$tmppath[] = $dnpipe->GetQname();
187
			$dnpipe->SetLink(&$tmppath);	
188
			$dnpipe->wconfig();
189
			write_config();
190
			touch($d_shaperconfdirty_path);
191
			$can_enable = true;
192 d3e5e7df Ermal Luçi
       		     	$can_add = true;
193 585a8faf Ermal Luçi
		}
194 d3e5e7df Ermal Luçi
		read_dummynet_config();
195 585a8faf Ermal Luçi
		$output_form .= $dnpipe->build_form();
196
197
	} else if ($parentqueue) { /* Add a new queue */
198
		if ($dnpipe) {
199
			$tmppath =& $dnpipe->GetLink();
200
			array_push($tmppath, $qname);
201
			$tmp =& $dnpipe->add_queue($pipe, $_POST, $tmppath, &$input_errors);
202
			if (!$input_errors) {
203
				array_pop($tmppath);
204
				$tmp->wconfig();
205
				write_config();
206
				$can_enable = true;
207 d3e5e7df Ermal Luçi
                		$can_add = false;
208 585a8faf Ermal Luçi
				touch($d_shaperconfdirty_path);
209
				$can_enable = true;
210
			}
211 d3e5e7df Ermal Luçi
			read_dummynet_config();
212 585a8faf Ermal Luçi
			$output_form .= $tmp->build_form();			
213
		} else
214
			$input_errors[] = "Could not add new queue.";
215
	} else if ($_POST['apply']) {
216
			write_config();
217
218
			$retval = 0;
219
			$savemsg = get_std_save_message($retval);
220
			
221
			config_lock();
222
			$retval = filter_configure();
223
			config_unlock();
224
			
225
			if (stristr($retval, "error") <> true)
226
					$savemsg = get_std_save_message($retval);
227
			else
228
					$savemsg = $retval;
229
230 d3e5e7df Ermal Luçi
 		/* XXX: TODO Make dummynet pretty graphs */ 
231
		//	enable_rrd_graphing();
232 585a8faf Ermal Luçi
233
            unlink($d_shaperconfdirty_path);
234
			
235
			if ($queue) {
236
				$output_form .= $queue->build_form();
237
				$dontshow = false;
238
			}
239
			else {
240
				$output_form .= $dn_default_shaper_message;
241
				$dontshow = true;
242
			}
243
244
	} else if ($queue) {
245
                $queue->validate_input($_POST, &$input_errors);
246
                if (!$input_errors) {
247 d3e5e7df Ermal Luçi
                            	$queue->update_dn_data($_POST);
248
                            	$queue->wconfig();
249
				write_config();
250 585a8faf Ermal Luçi
				touch($d_shaperconfdirty_path);
251
				$dontshow = false;
252
                } 
253 d3e5e7df Ermal Luçi
		read_dummynet_config();
254
		$output_form .= $queue->build_form();
255 585a8faf Ermal Luçi
	} else  {
256
		$output_form .= "<p class=\"pgtitle\">" . $dn_default_shaper_msg."</p>";
257
		$dontshow = true;
258
	}
259
} else {
260
	$output_form .= "<p class=\"pgtitle\">" . $dn_default_shaper_msg."</p>";
261
	$dontshow = true;
262
}
263
264
if ($queue) {
265
                        if ($queue->GetEnabled())
266
                                $can_enable = true;
267
                        else
268
                                $can_enable = false;
269
                        if ($queue->CanHaveChilds()) { 
270 d3e5e7df Ermal Luçi
                       		$can_add = true;
271 585a8faf Ermal Luçi
                        } else
272
                                $can_add = false;
273
}
274
275
$tree = "<ul class=\"tree\" >";
276
if (is_array($dummynet_pipe_list)) {
277
        foreach ($dummynet_pipe_list as $tmpdn) {
278
                $tree .= $tmpdn->build_tree();
279
        }
280
}
281
$tree .= "</ul>";
282
283
if (!$dontshow || $newqueue) {
284
285
$output_form .= "<tr><td width=\"22%\" valign=\"top\" class=\"vncellreq\">";
286
$output_form .= "Queue Actions";
287
$output_form .= "</td><td valign=\"top\" class=\"vncellreq\" width=\"78%\">";
288
289
$output_form .= "<input type=\"submit\" name=\"Submit\" value=\"" . gettext("Save") . "\" class=\"formbtn\" />";
290
if ($can_add || $addnewaltq) {
291
	$output_form .= "<a href=\"firewall_shaper_vinterface.php?pipe=";
292
	$output_form .= $pipe; 
293
	if ($queue) {
294
		$output_form .= "&queue=" . $queue->GetQname();
295
	}
296
	$output_form .= "&action=add\">";
297
	$output_form .= "<input type=\"button\" class=\"formbtn\" name=\"add\" value=\"Add new queue\">";
298
	$output_form .= "</a>";
299
}
300 d3e5e7df Ermal Luçi
$output_form .= "<a href=\"firewall_shaper_vinterface.php?pipe=";
301
$output_form .= $pipe . "&queue=";
302
if ($queue) {
303
	$output_form .= "&queue=" . $queue->GetQname();
304
}
305
$output_form .= "&action=delete\">";
306
$output_form .= "<input type=\"button\" class=\"formbtn\" name=\"delete\"";
307
if ($queue)
308
	$output_form .= " value=\"Delete this queue\">";
309
else
310
	$output_form .= " value=\"Delete virtual interface\">";
311
$output_form .= "</a>";  
312 585a8faf Ermal Luçi
$output_form .= "</td></tr>";
313
$output_form .= "</div>";
314
} 
315
else 
316
	$output_form .= "</div>";
317
318
$output = "<div id=\"shaperarea\" style=\"position:relative\">";
319
if (!$dontshow) {
320
if ($queue || $dnpipe || $newqueue) {
321
	$output .= "<tr><td valign=\"top\" class=\"vncellreq\"><br>";
322
	$output .= "Enable/Disable";
323
	$output .= "</td><td class=\"vncellreq\">";
324
	$output .= " <input type=\"checkbox\" id=\"enabled\" name=\"enabled\"";
325
	if ($queue)
326
		if ($queue->GetEnabled() <> "")
327
       			$output .=  " CHECKED";
328
	$output .= " ><span class=\"vexpl\"> Enable/Disable queue and its childs</span>";
329
	$output .= "</td></tr>";
330
}
331
}
332
$output .= $output_form;
333
334
include("head.inc");
335
?>
336
337
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" >
338
<link rel="stylesheet" type="text/css" media="all" href="./tree/tree.css" />
339
<script type="text/javascript" src="./tree/tree.js"></script>
340 b7d124fe Ermal Luçi
<script type="text/javascript">
341
function show_source_port_range() {
342
        document.getElementById("sprtable").style.display = '';
343 12a72ca1 Ermal Luçi
	document.getElementById("sprtable1").style.display = '';
344
	document.getElementById("sprtable2").style.display = '';
345 cc72f352 Ermal Luçi
	document.getElementById("sprtable5").style.display = '';
346
	document.getElementById("sprtable4").style.display = 'none';
347
	document.getElementById("showadvancedboxspr").innerHTML='';
348 b7d124fe Ermal Luçi
}
349
</script>
350
351 585a8faf Ermal Luçi
<?php
352
include("fbegin.inc"); 
353
?>
354
<div id="inputerrors"></div>
355
<?php if ($input_errors) print_input_errors($input_errors); ?>
356
357
<form action="firewall_shaper_vinterface.php" method="post" id="iform" name="iform">
358
359
<?php if ($savemsg) print_info_box($savemsg); ?>
360
<?php if (file_exists($d_shaperconfdirty_path)): ?><p>
361
<?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>
362
<?php endif; ?>
363
<table width="100%" border="0" cellpadding="0" cellspacing="0">
364
  <tr><td>
365
<?php
366
	$tab_array = array();
367
	$tab_array[0] = array("By Interface", false, "firewall_shaper.php");
368
	$tab_array[1] = array("By Queue", false, "firewall_shaper_queues.php");
369 6d0c07ea Ermal Luçi
	$tab_array[2] = array("Limiter", true, "firewall_shaper_vinterface.php");
370 585a8faf Ermal Luçi
	$tab_array[3] = 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 d3e5e7df Ermal Luçi
			<br/><br/>
388 585a8faf Ermal Luçi
			<a href="firewall_shaper_vinterface.php?pipe=new&action=add">
389 9bb1524c Ermal Luçi
			<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 585a8faf Ermal Luçi
			</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>