Projet

Général

Profil

Télécharger (13,6 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / firewall_shaper.php @ fab1cd2f

1
<?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
	pfSense_BUILDER_BINARIES:	/usr/bin/killall
32
	pfSense_MODULE:	shaper
33
*/
34

    
35
##|+PRIV
36
##|*IDENT=page-firewall-trafficshaper
37
##|*NAME=Firewall: Traffic Shaper page
38
##|*DESCR=Allow access to the 'Firewall: Traffic Shaper' page.
39
##|*MATCH=firewall_shaper.php*
40
##|-PRIV
41

    
42
require("guiconfig.inc");
43
require_once("functions.inc");
44
require_once("filter.inc");
45
require_once("shaper.inc");
46
require_once("rrd.inc");
47

    
48
if($_GET['reset'] <> "") {
49
	/* XXX: Huh, why are we killing php? */
50
	mwexec("killall -9 pfctl php");
51
	exit;
52
}
53

    
54
$pgtitle = array(gettext("Firewall"),gettext("Traffic Shaper"));
55
$shortcut_section = "trafficshaper";
56

    
57
$shaperIFlist = get_configured_interface_with_descr();
58
read_altq_config();
59
/* 
60
 * The whole logic in these code maybe can be specified.
61
 * If you find a better way contact me :).
62
 */
63

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

    
81
if ($interface) {
82
	$altq = $altq_list_queues[$interface];
83
	if ($altq) {
84
		$queue =& $altq->find_queue($interface, $qname);
85
	} else $addnewaltq = 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
				if (write_config())
98
					mark_subsystem_dirty('shaper');
99
			}
100
			header("Location: firewall_shaper.php");
101
			exit;
102
		break;
103
	case "resetall":
104
			foreach ($altq_list_queues as $altq)
105
				$altq->delete_all();
106
			unset($altq_list_queues);
107
			$altq_list_queues = array();
108
			$tree = "<ul class=\"tree\" >";
109
			$tree .= get_interface_list_to_show();
110
			$tree .= "</ul>";
111
			unset($config['shaper']['queue']);
112
			unset($queue);
113
			unset($altq);
114
			$can_add = false;
115
			$can_enable = false;
116
			$dontshow = true;
117
			foreach ($config['filter']['rule'] as $key => $rule) {
118
				if (isset($rule['wizard']) && $rule['wizard'] == "yes")
119
					unset($config['filter']['rule'][$key]);
120
			}
121
			if (write_config()) {
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
			} else {
131
				$savemsg = gettext("Unable to write config.xml (Access Denied?)");
132
			}
133
			$output_form = $default_shaper_message;
134

    
135
		break;
136
	case "add":
137
			/* XXX: Find better way because we shouldn't know about this */
138
		if ($altq) {
139
	                switch ($altq->GetScheduler()) {
140
         	        case "PRIQ":
141
                	        $q = new priq_queue();
142
                        	break;
143
			case "FAIRQ":
144
				$q = new fairq_queue();
145
				break;
146
                        case "HFSC":
147
                         	$q = new hfsc_queue();
148
                        	break;
149
                        case "CBQ":
150
                                $q = new cbq_queue();
151
                        	break;
152
                        default:
153
                                /* XXX: Happens when sched==NONE?! */
154
				$q = new altq_root_queue();
155
                        	break;
156
        		}
157
		} else if ($addnewaltq) {
158
			$q = new altq_root_queue();
159
		} else 
160
			$input_errors[] = gettext("Could not create new queue/discipline!");
161

    
162
			if ($q) {
163
				$q->SetInterface($interface);
164
				$output_form .= $q->build_form();
165
				$output_form .= "<input type=\"hidden\" name=\"parentqueue\" id=\"parentqueue\"";
166
				$output_form .= " value=\"".$qname."\" />";
167
				$newjavascript = $q->build_javascript();
168
                unset($q);
169
				$newqueue = true;
170
			}
171
		break;
172
		case "show":
173
			if ($queue)  
174
                        $output_form .= $queue->build_form();
175
			else
176
					$input_errors[] = gettext("Queue not found!");
177
		break;
178
		case "enable":
179
			if ($queue) {
180
					$queue->SetEnabled("on");
181
					$output_form .= $queue->build_form();
182
					if (write_config())
183
						mark_subsystem_dirty('shaper');
184
			} else
185
					$input_errors[] = gettext("Queue not found!");
186
		break;
187
		case "disable":
188
			if ($queue) {
189
					$queue->SetEnabled("");
190
					$output_form .= $queue->build_form();
191
					if (write_config())
192
						mark_subsystem_dirty('shaper');
193
			} else
194
					$input_errors[] = gettext("Queue not found!");
195
		break;
196
		default:
197
			$output_form .= $default_shaper_msg;
198
			$dontshow = true;
199
			break;
200
	}
201
} else if ($_POST) {
202
	unset($input_errors);
203

    
204
	if ($addnewaltq) {
205
		$altq =& new altq_root_queue();
206
		$altq->SetInterface($interface);
207
		
208
		switch ($altq->GetBwscale()) {
209
				case "Mb":
210
					$factor = 1000 * 1000;
211
					brak;
212
				case "Kb":
213
					$factor = 1000;
214
					break;
215
				case "b":
216
					$factor = 1;
217
					break;
218
				case "Gb":
219
					$factor = 1000 * 1000 * 1000;
220
					break;
221
				case "%": /* We don't use it for root_XXX queues. */
222
				default: /* XXX assume Kb by default. */
223
					$factor = 1000;
224
					break;
225
			} 
226
		$altq->SetAvailableBandwidth($altq->GetBandwidth() * $factor);
227
		$altq->ReadConfig($_POST);
228
		$altq->validate_input($_POST, $input_errors);
229
		if (!$input_errors) {
230
			unset($tmppath);
231
			$tmppath[] = $altq->GetInterface();
232
			$altq->SetLink($tmppath);	
233
			$altq->wconfig();
234
			if (write_config())
235
				mark_subsystem_dirty('shaper');
236
			$can_enable = true;
237
                        $can_add = true;
238
		}
239
		read_altq_config();
240
		$output_form .= $altq->build_form();
241

    
242
	} else if ($parentqueue) { /* Add a new queue */
243
		$qtmp =& $altq->find_queue($interface, $parentqueue);
244
		if ($qtmp) {
245
			$tmppath =& $qtmp->GetLink();
246
			array_push($tmppath, $qname);
247
			$tmp =& $qtmp->add_queue($interface, $_POST, $tmppath, $input_errors);
248
			if (!$input_errors) {
249
				array_pop($tmppath);
250
				$tmp->wconfig();
251
				$can_enable = true;
252
				if ($tmp->CanHaveChildren() && $can_enable) {
253
					if ($tmp->GetDefault() <> "")
254
                             			$can_add = false;
255
                        		else
256
                             			$can_add = true;
257
				} else
258
					$can_add = false;
259
				if (write_config())
260
					mark_subsystem_dirty('shaper');
261
				$can_enable = true;
262
				if ($altq->GetScheduler() != "PRIQ") /* XXX */
263
					if ($tmp->GetDefault() <> "")
264
                                                $can_add = false;
265
                                        else
266
                                                $can_add = true;
267
			}
268
			read_altq_config();
269
			$output_form .= $tmp->build_form();			
270
		} else
271
			$input_errors[] = gettext("Could not add new queue.");
272
	} else if ($_POST['apply']) {
273
			write_config();
274

    
275
			$retval = 0;
276
			$retval = filter_configure();
277
			$savemsg = get_std_save_message($retval);
278
			
279
			if (stristr($retval, "error") <> true)
280
					$savemsg = get_std_save_message($retval);
281
			else
282
					$savemsg = $retval;
283

    
284
 		/* reset rrd queues */
285
		system("rm -f /var/db/rrd/*queuedrops.rrd");
286
		system("rm -f /var/db/rrd/*queues.rrd");
287
		enable_rrd_graphing();
288

    
289
		clear_subsystem_dirty('shaper');
290
			
291
			if ($queue) {
292
				$output_form .= $queue->build_form();
293
				$dontshow = false;
294
			}
295
			else {
296
				$output_form .= $default_shaper_message;
297
				$dontshow = true;
298
			}
299

    
300
	} else if ($queue) {
301
                $queue->validate_input($_POST, $input_errors);
302
                if (!$input_errors) {
303
                            $queue->update_altq_queue_data($_POST);
304
                            $queue->wconfig();
305
				if (write_config())
306
					mark_subsystem_dirty('shaper');
307
				$dontshow = false;
308
                } 
309
		read_altq_config();
310
		$output_form .= $queue->build_form();
311
	} else  {
312
		$output_form .= $default_shaper_msg;
313
		$dontshow = true;
314
	}
315
	mwexec("killall qstats");
316
} else {
317
	$output_form .= $default_shaper_msg;
318
	$dontshow = true;
319
}
320

    
321
if ($queue) {
322
                        if ($queue->GetEnabled())
323
                                $can_enable = true;
324
                        else
325
                                $can_enable = false;
326
                        if ($queue->CanHaveChildren() && $can_enable) { 
327
                                if ($altq->GetQname() <> $queue->GetQname() && $queue->GetDefault() <> "")
328
                                        $can_add = false;
329
                                else
330
                                        $can_add = true;
331
                        } else
332
                                $can_add = false;
333
}
334

    
335
$tree = "<ul class=\"tree\" >";
336
if (is_array($altq_list_queues)) {
337
        foreach ($altq_list_queues as $tmpaltq) {
338
                $tree .= $tmpaltq->build_tree();
339
        }
340
$tree .=  get_interface_list_to_show();
341
}
342
$tree .= "</ul>";
343

    
344
if (!$dontshow || $newqueue) {
345

    
346
$output_form .= "<tr><td width=\"22%\" valign=\"middle\" class=\"vncellreq\">";
347
$output_form .= "<br />" . gettext("Queue Actions") . "<br />";
348
$output_form .= "</td><td valign=\"middle\" class=\"vncellreq\" width=\"78%\"><br />";
349

    
350
$output_form .= "<input type=\"submit\" name=\"Submit\" value=\"" . gettext("Save") . "\" class=\"formbtn\" />";
351
if ($can_add || $addnewaltq) {
352
	$output_form .= "<a href=\"firewall_shaper.php?interface=";
353
	$output_form .= $interface; 
354
	if ($queue) {
355
		$output_form .= "&amp;queue=" . $queue->GetQname();
356
	}
357
	$output_form .= "&amp;action=add\">";
358
	$output_form .= "<input type=\"button\" class=\"formbtn\" name=\"add\" value=\"" . gettext("Add new queue") . "\" />";
359
	$output_form .= "</a>";
360
}
361
$output_form .= "<a href=\"firewall_shaper.php?interface=";
362
$output_form .= $interface . "&amp;queue=";
363
if ($queue) {
364
	$output_form .= "&amp;queue=" . $queue->GetQname();
365
}
366
$output_form .= "&amp;action=delete\">";
367
$output_form .= "<input type=\"button\" class=\"formbtn\" name=\"delete\"";
368
if ($queue)
369
	$output_form .= " value=\"" . gettext("Delete this queue") . "\" />";
370
else
371
	$output_form .= " value=\"" . gettext("Disable shaper on interface") . "\" />";
372
$output_form .= "</a>";
373
$output_form .= "<br /></td></tr>";
374
$output_form .= "</table>";
375
}
376
else 
377
	$output_form .= "</table>";
378

    
379
$output = "<table  summary=\"output form\">";
380
$output .= $output_form;
381

    
382
//$pgtitle = "Firewall: Shaper: By Interface View";
383
$closehead = false;
384
include("head.inc");
385
?>
386
<link rel="stylesheet" type="text/css" media="all" href="./tree/tree.css" />
387
<script type="text/javascript" src="./tree/tree.js"></script>
388
</head>
389

    
390
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" >
391
<?php
392
if ($queue)
393
        echo $queue->build_javascript();
394
echo $newjavascript;
395

    
396
include("fbegin.inc"); 
397
?>
398
<div id="inputerrors"></div>
399
<?php if ($input_errors) print_input_errors($input_errors); ?>
400

    
401
<form action="firewall_shaper.php" method="post" id="iform" name="iform">
402

    
403
<?php if ($savemsg) print_info_box($savemsg); ?>
404
<?php if (is_subsystem_dirty('shaper')): ?><p>
405
<?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 /></p>
406
<?php endif; ?>
407
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="traffic shaper">
408
  <tr><td>
409
<?php
410
	$tab_array = array();
411
	$tab_array[0] = array(gettext("By Interface"), true, "firewall_shaper.php");
412
	$tab_array[1] = array(gettext("By Queue"), false, "firewall_shaper_queues.php");
413
	$tab_array[2] = array(gettext("Limiter"), false, "firewall_shaper_vinterface.php");
414
	$tab_array[3] = array(gettext("Layer7"), false, "firewall_shaper_layer7.php");
415
	$tab_array[4] = array(gettext("Wizards"), false, "firewall_shaper_wizards.php");
416
	display_top_tabs($tab_array);
417
?>
418
  </td></tr>
419
  <tr>
420
    <td>
421
	<div id="mainarea">
422
              <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="main area">
423
<?php if (count($altq_list_queues) > 0): ?>
424
                        <tr class="tabcont"><td width="25%" align="left">
425
                                <a href="firewall_shaper.php?action=resetall" >
426
                                        <input type="button" value="<?=gettext("Remove Shaper")?>" class="formbtn" />
427
                                </a>
428
                        </td><td width="75%"> </td></tr>
429
<?php endif; ?>
430
			<tr>
431
			<td width="25%" valign="top" align="left">
432
			<?php
433
				echo $tree; 
434
			?>
435
			</td>
436
			<td width="75%" valign="top" align="center">
437
			<div id="shaperarea" style="position:relative">
438
			<?php
439
				echo $output;
440
			?>	
441
			</div>
442

    
443
		      </td></tr>
444
                    </table>
445
		</div>
446
	  </td>
447
	</tr>
448
</table>
449
            </form>
450
<?php include("fend.inc"); ?>
451
</body>
452
</html>
(74-74/255)