Projet

Général

Profil

Télécharger (53,5 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / wizards / traffic_shaper_wizard_multi_all.inc @ a03943d2

1
<?php
2
/*
3
	traffic_shaper_wizard_multi_all.inc
4
	part of pfSense (https://www.pfsense.org/)
5

    
6
	Copyright (C) 2006 Bill Marquette - bill.marquette@gmail.com.
7
	Copyright (C) 2006 Scott Ullrich - sullrich@pfsense.com.
8
	Copyright (C) 2008-2010 Ermal Luçi
9
	All rights reserved.
10

    
11
	Redistribution and use in source and binary forms, with or without
12
	modification, are permitted provided that the following conditions are met:
13

    
14
	1. Redistributions of source code must retain the above copyright notice,
15
	   this list of conditions and the following disclaimer.
16

    
17
	2. Redistributions in binary form must reproduce the above copyright
18
	   notice, this list of conditions and the following disclaimer in the
19
	   documentation and/or other materials provided with the distribution.
20

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

    
33
function step1_stepbeforeformdisplay() {
34
	global $stepid, $savemsg, $pkg;
35

    
36
	$fields =& $pkg['step'][0]['fields']['field'];
37

    
38
	$lans = 0;
39
	$wans = 0;
40

    
41
	$iflisttmp = get_configured_interface_with_descr();
42
	foreach ($iflisttmp as $if => $ifdesc) {
43
		if (!is_altq_capable(get_real_interface($if)))
44
			continue;
45
		if (interface_has_gateway($if) || interface_has_gatewayv6($if))
46
			$wans++;
47
		else
48
			$lans++;
49
	}
50

    
51
	foreach ($fields as &$field) {
52
		if ($field['name'] == 'numberofconnections')
53
			$field['value'] = $wans;
54
		else if ($field['name'] == 'numberoflocalinterfaces')
55
			$field['value'] = $lans;
56
	}
57
}
58

    
59
function step1_submitphpaction() {
60
	global $stepid, $savemsg;
61

    
62
	if (!isset($_POST['numberofconnections'])) {
63
		$savemsg=gettext("You need to specify the number of connections.");
64
		$stepid--;
65
		return;
66
	}
67
	if (intval($_POST['numberofconnections']) < 1) {
68
		$savemsg=gettext("The number of connections should be greater than 1.");
69
		$stepid--;
70
		return;
71
	}
72

    
73
	if (!isset($_POST['numberoflocalinterfaces'])) {
74
		$savemsg=gettext("You need to specify the number of LAN type interfaces.");
75
		$stepid--;
76
		return;
77
	}
78
	if (intval($_POST['numberoflocalinterfaces']) < 1) {
79
		$savemsg=gettext("The number of LAN type interfaces should be greater than 1.");
80
		$stepid--;
81
		return;
82
	}
83
}
84

    
85
function step2_stepbeforeformdisplay() {
86
	global $config, $pkg;
87
	global $stepid, $savemsg;
88

    
89
	$wans = 0;
90
	$lans = 0;
91
	$iflist = array();
92
	$iflisttmp = get_configured_interface_with_descr();
93
	foreach ($iflisttmp as $if => $ifdesc) {
94
		if (!is_altq_capable(get_real_interface($if)))
95
			continue;
96
		if (interface_has_gateway($if) || interface_has_gatewayv6($if))
97
			$wans++;
98
		else
99
			$lans++;
100
		$iflist[$if] = $ifdesc;
101
	}
102
	$numberofconnections = intval($config['ezshaper']['step1']['numberofconnections']);
103
	if ($numberofconnections > $wans) {
104
		$savemsg=gettext("You have less interfaces than number of connections!");
105
		$stepid--;
106
		return;
107
	}
108

    
109
	$numberoflocalinterfaces = intval($config['ezshaper']['step1']['numberoflocalinterfaces']);
110
	if ($numberoflocalinterfaces > $lans) {
111
		$savemsg=gettext("You have less interfaces than number of connections!");
112
		$stepid--;
113
		return;
114
	}
115
	$cfgname = "traffic_shaper_wizard_multi_all.xml";
116

    
117
	$fields =& $pkg['step'][1]['fields']['field'];
118

    
119
	/*
120
	unset($config['ezshaper']['step2']);
121
	$config['ezshaper']['step2'] = array();
122
	write_config();
123
	*/
124
	$fields = array();
125

    
126
	for ($i = 0; $i < $numberoflocalinterfaces; $i++) {
127
		$field = array();
128
		$interface_friendly = $i+1;
129
		$field['name'] = "Setup connection speed and scheduler information for interface LAN #{$interface_friendly}";
130
		$field['type'] = "listtopic";
131
		$fields[] = $field;
132

    
133
		$field = array();
134
		$field['displayname'] = "Interface & Scheduler";
135
		$field['name'] = "local{$i}interface";
136
		$field['type'] = "select";
137
		$field['options']['option'] = array();
138
		foreach ($iflist as $ifname => $ifdescr) {
139
			// Skip wan interfaces here
140
			if (interface_has_gateway($ifname) || interface_has_gatewayv6($ifname))
141
				continue;
142
			$opts = array();
143
			$opts['displayname'] = $ifdescr;
144
			$opts['name'] = $ifname;
145
			$opts['value'] = $ifname;
146
			$field['options']['option'][] = $opts;
147
		}
148
		$field['combinefieldsbegin'] = "true";
149
		$field['bindstofield'] = "ezshaper->step2->local{$i}interface";
150
		$fields[] = $field;
151

    
152
		$field = array();
153
		$field['combinefieldsend'] = "true";
154
		$field['dontdisplayname'] = "true";
155
		$field['dontcombinecells'] = "true";
156
		$field['name'] = "local{$i}downloadscheduler";
157
		$field['type'] = "select";
158
		$field['typehint'] = "Queueing discipline to apply on this local interface.";
159
		$field['options']['option'] = array();
160
		$opts = array();
161
		$opts['name'] = "HFSC";
162
		$opts['value'] = "HFSC";
163
		$field['options']['option'][] = $opts;
164
		$opts = array();
165
		$opts['name'] = "CBQ";
166
		$opts['value'] = "CBQ";
167
		$field['options']['option'][] = $opts;
168
		$opts = array();
169
		$opts['name'] = "PRIQ";
170
		$opts['value'] = "PRIQ";
171
		$field['options']['option'][] = $opts;
172
		$field['bindstofield'] = "ezshaper->step2->local{$i}downloadscheduler";
173
		$fields[] = $field;
174
	}
175

    
176
	for ($i = 0; $i < $numberofconnections; $i++) {
177
		$field = array();
178
		$interface_friendly = $i+1;
179
		$field['name'] = "Setup connection speed and scheduler information for interface WAN#{$interface_friendly}";
180
		$field['type'] = "listtopic";
181
		$fields[] = $field;
182

    
183
		$field = array();
184
		$field['displayname'] = "Interface & Scheduler";
185
		$field['name'] = "conn{$i}interface";
186
		$field['type'] = "select";
187
		$interface_real = $i+1;
188
		$field['options']['option'] = array();
189
		foreach ($iflist as $ifname => $ifdescr) {
190
			// Skip lan interfaces here
191
			if (!interface_has_gateway($ifname) && !interface_has_gatewayv6($ifname))
192
				continue;
193
			$opts = array();
194
			$opts['displayname'] = $ifdescr;
195
			$opts['name'] = $ifname;
196
			$opts['value'] = $ifname;
197
			$field['options']['option'][] = $opts;
198
		}
199
		$field['bindstofield'] = "ezshaper->step2->conn{$i}interface";
200
		$field['combinefieldsbegin'] = "true";
201
		$fields[] = $field;
202

    
203
		$field = array();
204
		$field['combinefieldsend'] = "true";
205
		$field['dontdisplayname'] = "true";
206
		$field['dontcombinecells'] = "true";
207
		$field['name'] = "conn{$i}uploadscheduler";
208
		$field['type'] = "select";
209
		$field['typehint'] = "Queueing discipline to apply on the upload of this connection.";
210
		$field['options']['option'] = array();
211
		$opts = array();
212
		$opts['name'] = "HFSC";
213
		$opts['value'] = "HFSC";
214
		$field['options']['option'][] = $opts;
215
		$opts = array();
216
		$opts['name'] = "CBQ";
217
		$opts['value'] = "CBQ";
218
		$field['options']['option'][] = $opts;
219
		$opts = array();
220
		$opts['name'] = "PRIQ";
221
		$opts['value'] = "PRIQ";
222
		$field['options']['option'][] = $opts;
223
		$field['bindstofield'] = "ezshaper->step2->conn{$i}uploadscheduler";
224
		$fields[] = $field;
225

    
226
		$field = array();
227
		$field['displayname'] = "Upload";
228
		$field['name'] = "conn{$i}upload";
229
		$field['type'] = "input";
230
		$field['bindstofield'] = "ezshaper->step2->conn{$i}upload";
231
		$field['combinefieldsbegin'] = "true";
232
		$fields[] = $field;
233

    
234
		$field = array();
235
		$field['combinefieldsend'] = "true";
236
		$field['dontdisplayname'] = "true";
237
		$field['dontcombinecells'] = "true";
238
		$field['name'] = "conn{$i}uploadspeed";
239
		$field['typehint'] = "Upload bandwidth on this connection.";
240
		$field['type'] = "select";
241
		$field['options']['option'] = array();
242
		$opts = array();
243
		$opts['value'] = "Kb";
244
		$opts['name'] = "Kbit/s";
245
		$field['options']['option'][] = $opts;
246
		$opts = array();
247
		$opts['value'] = "Mb";
248
		$opts['name'] = "Mbit/s";
249
		$field['options']['option'][] = $opts;
250
		$opts = array();
251
		$opts['value'] = "Gb";
252
		$opts['name'] = "Gbit/s";
253
		$field['options']['option'][] = $opts;
254
		$field['bindstofield'] = "ezshaper->step2->conn{$i}uploadspeed";
255
		$fields[] = $field;
256

    
257
		$field = array();
258
		$field['displayname'] = "Download";
259
		$field['name'] = "conn{$i}download";
260
		$field['type'] = "input";
261
		$field['bindstofield'] = "ezshaper->step2->conn{$i}download";
262
		$field['combinefieldsbegin'] = "true";
263
		$fields[] = $field;
264

    
265
		$field = array();
266
		$field['combinefieldsend'] = "true";
267
		$field['dontdisplayname'] = "true";
268
		$field['dontcombinecells'] = "true";
269
		$field['name'] = "conn{$i}downloadspeed";
270
		$field['typehint'] = "Download bandwidth on this connection.";
271
		$field['type'] = "select";
272
		$field['options']['option'] = array();
273
		$opts = array();
274
		$opts['value'] = "Kb";
275
		$opts['name'] = "Kbit/s";
276
		$field['options']['option'][] = $opts;
277
		$opts = array();
278
		$opts['value'] = "Mb";
279
		$opts['name'] = "Mbit/s";
280
		$field['options']['option'][] = $opts;
281
		$opts = array();
282
		$opts['value'] = "Gb";
283
		$opts['name'] = "Gbit/s";
284
		$field['options']['option'][] = $opts;
285
		$field['bindstofield'] = "ezshaper->step2->conn{$i}downloadspeed";
286
		$fields[] = $field;
287
	}
288
	$field = array();
289
	$field['name'] = "Next";
290
	$field['type'] = "submit";
291
	$fields[] = $field;
292
}
293

    
294
function step2_stepsubmitphpaction() {
295
	global $config;
296
	global $stepid, $savemsg;
297
	$sumdownloads = 0;
298

    
299
	/* Input Validation */
300
	$steps = intval($config['ezshaper']['step1']['numberofconnections']);
301
	$localint = intval($config['ezshaper']['step1']['numberoflocalinterfaces']);
302
	for ($i = 0; $i < $steps; $i++) {
303
		for ($j = $i + 1; $j <= $steps; $j++) {
304
			if ($_POST["conn{$i}interface"] == $_POST["conn{$j}interface"]) {
305
				$savemsg=gettext("You cannot select the same interface for connections {$i} and {$j}.");
306
				$stepid--;
307
				return;
308
			}
309
			if (trim($_POST["conn{$i}uploadscheduler"]) != "PRIQ") {
310
				if (!is_numeric($_POST["conn{$i}upload"])) {
311
					$savemsg = gettext("Upload bandwidth of connection {$i} is not valid.");
312
					$stepid--;
313
					return;
314
				}
315
				if (!is_numeric($_POST["conn{$i}download"])) {
316
					$savemsg = gettext("Download bandwidth of connection {$i} is not valid.");
317
					$stepid--;
318
					return;
319
				}
320
				$upbw = $_POST["conn{$i}upload"];
321
				$downbw = $_POST["conn{$i}download"];
322
				if ($upbw < 1 || $downbw < 1) {
323
					$savemsg = gettext("You cannot specify 0 bandwidth!");
324
					$stepid--;
325
					return;
326
				}
327
				if (intval($upbw) < 128 && $_POST["conn{$i}uploadspeed"] == "Kb" && trim($_POST["conn{$i}uploadscheduler"]) == "CBQ") {
328
					$savemsg=gettext("Uploads smaller than 128Kbit/s is not supported for connection {$i} on CBQ scheduler.");
329
					$stepid--;
330
					return;
331
				}
332
			}
333
		}
334
		for ($j = 0; $j < $localint; $j++) {
335
			if ($_POST["conn{$i}interface"] == $_POST["local{$j}interface"]) {
336
				$savemsg=gettext("You cannot select the same interface for local and outside.");
337
				$stepid--;
338
				return;
339
			}
340
		}
341
	}
342
	for ($i = 0; $i < $localint; $i++) {
343
		for ($j = $i + 1; $j < $localint; $j++) {
344
			if ($_POST["local{$i}interface"] == $_POST["local{$j}interface"]) {
345
				$savemsg=gettext("You cannot select the same interface twice on local interfaces.");
346
				$stepid--;
347
				return;
348
			}
349
		}
350
	}
351

    
352
	/* This is necessary since the wizard expects pecnefined fields. */
353
	unset($config['ezshaper']['step2']);
354
	$config['ezshaper']['step2'] = array();
355

    
356
	for ($i = 0; $i < $localint; $i++) {
357
		$config['ezshaper']['step2']["local{$i}downloadscheduler"] = $_POST["local{$i}downloadscheduler"];
358
		$config['ezshaper']['step2']["local{$i}interface"] = $_POST["local{$i}interface"];
359
	}
360

    
361
	for ($i = 0; $i < $steps; $i++) {
362
		$config['ezshaper']['step2']["conn{$i}uploadscheduler"] = $_POST["conn{$i}uploadscheduler"];
363
		$config['ezshaper']['step2']["conn{$i}upload"] = $_POST["conn{$i}upload"];
364
		$config['ezshaper']['step2']["conn{$i}uploadspeed"] = $_POST["conn{$i}uploadspeed"];
365
		$config['ezshaper']['step2']["conn{$i}download"] = $_POST["conn{$i}download"];
366
		$config['ezshaper']['step2']["conn{$i}downloadspeed"] = $_POST["conn{$i}downloadspeed"];
367
		$config['ezshaper']['step2']["conn${i}interface"] = $_POST["conn{$i}interface"];
368
	}
369
}
370

    
371
function step3_stepbeforeformdisplay() {
372
	global $config, $pkg;
373
	global $stepid, $savemsg;
374

    
375
	$cfgname = "traffic_shaper_wizard_multi_all.xml";
376

    
377
	$numberofconnections = intval($config['ezshaper']['step1']['numberofconnections']);
378
	$numberoflocalinterfaces = intval($config['ezshaper']['step1']['numberoflocalinterfaces']);
379

    
380
	$fields =& $pkg['step'][1]['fields']['field'];
381

    
382
	$voipfields =& $pkg['step'][2]['fields']['field'];
383

    
384
	$voipfields = array();
385
	$enablefields = array();
386

    
387
	$field = array();
388
	$field['name'] = "enable";
389
	$field['type'] = "checkbox";
390
	$field['typehint'] = "Prioritize Voice over IP traffic.";
391
	$field['bindstofield'] = "ezshaper->step3->enable";
392
	$field['descritpion'] = "This will raise the priority of VOIP traffic above all other traffic.";
393
	$voipfields[] = $field;
394

    
395
	$field = array();
396
	$field['name'] = "Next";
397
	$field['type'] = "submit";
398
	$voipfields[] = $field;
399

    
400
	$field = array();
401
	$field['name'] = "VOIP specific settings";
402
	$field['type'] = "listtopic";
403
	$voipfields[] = $field;
404

    
405
	$field['name'] = "Provider";
406
	$enablefields[] = "Provider";
407
	$field['type'] = "select";
408
	$field['description'] = "Choose Generic if your provider isn't listed.";
409
	$field['options']['option'] = array();
410
	$opts = array();
411
	$opts['name'] = "Generic (lowdelay)";
412
	$opts['value'] = "Generic";
413
	$field['options']['option'][] = $opts;
414
	$opts = array();
415
	$opts['name'] = "VoicePulse";
416
	$opts['value'] = "VoicePulse";
417
	$field['options']['option'][] = $opts;
418
	$opts = array();
419
	$opts['name'] = "Asterisk/Vonage";
420
	$opts['value'] = "Asterisk";
421
	$field['options']['option'][] = $opts;
422
	$opts = array();
423
	$opts['name'] = "PanasonicTDA";
424
	$opts['value'] = "Panasonic";
425
	$field['options']['option'][] = $opts;
426
	$field['bindstofield'] = "ezshaper->step3->provider";
427
	$voipfields[] = $field;
428

    
429
	$field = array();
430
	$field['displayname'] = "Upstream SIP Server";
431
	$field['name'] = "upstream_sip_server";
432
	$enablefields[] = "upstream_sip_server";
433
	$field['type'] = "inputalias";
434
	$field['description'] = "(Optional) If this is chosen, the provider field will be overridden. This allows you to provide the IP address of the <strong>remote</strong> PBX or SIP Trunk to prioritize.  <br />NOTE: You can also use a Firewall Alias in this location.";
435
	$field['message'] = "IP Address field is non-blank and doesn't look like an IP address.";
436
	$field['bindstofield'] = "ezshaper->step3->address";
437
	$voipfields[] = $field;
438

    
439
	for ($i = 0; $i < $numberofconnections; $i++) {
440
		$field = array();
441
		$interface_friendly = $i+1;
442
		$field['name'] = "Connection WAN #{$interface_friendly}";
443
		$field['type'] = "listtopic";
444
		$voipfields[] = $field;
445

    
446
		$field = array();
447
		$field['displayname'] = "Upload";
448
		$field['name'] = "conn{$i}upload";
449
		$enablefields[] = "conn{$i}upload";
450
		$field['type'] = "input";
451
		$field['bindstofield'] = "ezshaper->step3->conn{$i}upload";
452
		$field['combinefieldsbegin'] = "true";
453
		$voipfields[] = $field;
454

    
455
		$field = array();
456
		$field['combinefieldsend'] = "true";
457
		$field['dontdisplayname'] = "true";
458
		$field['dontcombinecells'] = "true";
459
		$field['name'] = "conn{$i}uploadspeed";
460
		$enablefields[] = "conn{$i}uploadspeed";
461
		$field['typehint'] = "Upload bandwidth guarantee for VOIP phone(s) on connection {$i}.";
462
		$field['type'] = "select";
463
		$field['options']['option'] = array();
464
		$opts = array();
465
		$opts['value'] = "Kb";
466
		$opts['name'] = "Kbit/s";
467
		$field['options']['option'][] = $opts;
468
		$opts = array();
469
		$opts['value'] = "Mb";
470
		$opts['name'] = "Mbit/s";
471
		$field['options']['option'][] = $opts;
472
		$opts = array();
473
		$opts['value'] = "Gb";
474
		$opts['name'] = "Gbit/s";
475
		$field['options']['option'][] = $opts;
476
		$field['bindstofield'] = "ezshaper->step3->conn{$i}uploadspeed";
477
		$voipfields[] = $field;
478
	}
479

    
480
	for ($i = 0; $i < $numberoflocalinterfaces; $i++) {
481
		$field = array();
482
		$interface_friendly = $i+1;
483
		$field['name'] = "Connection LAN #{$interface_friendly}";
484
		$field['type'] = "listtopic";
485
		$voipfields[] = $field;
486

    
487
		$field = array();
488
		$field['displayname'] = "Download";
489
		$field['name'] = "local{$i}download";
490
		$enablefields[] = "local{$i}download";
491
		$field['type'] = "input";
492
		$field['bindstofield'] = "ezshaper->step3->local{$i}download";
493
		$field['combinefieldsbegin'] = "true";
494
		$voipfields[] = $field;
495

    
496
		$field = array();
497
		$field['combinefieldsend'] = "true";
498
		$field['dontdisplayname'] = "true";
499
		$field['dontcombinecells'] = "true";
500
		$field['name'] = "local{$i}downloadspeed";
501
		$enablefields[] = "local{$i}downloadspeed";
502
		$field['typehint'] = "Download bandwidth guarantee for VOIP phone(s) on connections.";
503
		$field['type'] = "select";
504
		$field['options']['option'] = array();
505
		$opts = array();
506
		$opts['value'] = "Kb";
507
		$opts['name'] = "Kbit/s";
508
		$field['options']['option'][] = $opts;
509
		$opts = array();
510
		$opts['value'] = "Mb";
511
		$opts['name'] = "Mbit/s";
512
		$field['options']['option'][] = $opts;
513
		$opts = array();
514
		$opts['value'] = "Gb";
515
		$opts['name'] = "Gbit/s";
516
		$field['options']['option'][] = $opts;
517
		$field['bindstofield'] = "ezshaper->step3->local{$i}downloadspeed";
518
		$voipfields[] = $field;
519
	}
520

    
521
	$field = array();
522
	$field['name'] = "Next";
523
	$field['type'] = "submit";
524
	$voipfields[] = $field;
525
	$voipfields[0]['enablefields'] = implode(",", $enablefields);
526
}
527

    
528
function step3_stepsubmitphpaction() {
529
	global $config;
530
	global $stepid, $savemsg;
531

    
532
	if (!$_POST['enable'])
533
		return;
534

    
535
	if($_POST['address']) {
536
		if(!is_ipaddroralias($_POST['address'])) {
537
			/* item is not an ip or alias.  error out */
538
			$savemsg=gettext("Address must be a valid IP address or Firewall Alias.  Please correct this value to continue.");
539
			$stepid--;
540
			return;
541
		}
542
	}
543

    
544
	$steps = intval($config['ezshaper']['step1']['numberofconnections']);
545
	for ($i = 0; $i < $steps; $i++) {
546
		if ($config['ezshaper']['step2']["conn{$i}uploadscheduler"] == "PRIQ")
547
			continue;
548
		if (!is_numeric($_POST["conn{$i}upload"])) {
549
			$savemsg = gettext("Upload bandwidth of connection {$i} is not valid.");
550
			$stepid--;
551
			return;
552
		}
553
		if ($_POST["conn{$i}uploadspeed"] == "%") {
554
			if (intval($_POST["conn{$i}upload"]) > 80) {
555
				$savemsg=gettext("You cannot set the VoIP upload bandwidth on connection {$i} higher than 80% of the connection.");
556
				$stepid--;
557
				return;
558
			}
559
		} else {
560
			$factor = wizard_get_bandwidthtype_scale($config['ezshaper']['step2']["conn{$i}uploadspeed"]);
561
			$ifbw = $factor * floatval($config['ezshaper']['step2']["conn{$i}upload"]);
562
			$factor = wizard_get_bandwidthtype_scale($_POST["conn{$i}uploadspeed"]);
563
			$input_bw = $factor * floatval($_POST["conn{$i}upload"]);
564
			if ((0.8 * $ifbw) < $input_bw) {
565
				$savemsg=gettext("You cannot set the VoIP upload bandwidth on connection {$i} higher than 80% of the connection.");
566
				$stepid--;
567
				return;
568
			}
569
		}
570
	}
571

    
572
	$localint = intval($config['ezshaper']['step1']['numberoflocalinterfaces']);
573
	for ($i = 0; $i < $localint; $i++) {
574
		if ($config['ezshaper']['step2']["local{$i}downloadscheduler"] == "PRIQ")
575
			continue;
576
		if (!is_numeric($_POST["local{$i}download"])) {
577
			$savemsg = gettext("Download bandwidth of connection {$i} is not valid.");
578
			$stepid--;
579
			return;
580
		}
581
		if ($_POST["local{$i}downloadspeed"] == "%") {
582
			if (intval($_POST["local{$i}download"]) > 80) {
583
				$savemsg=gettext("You cannot set the VoIP download bandwidth on connection {$i} higher than 80% of the connection.");
584
				$stepid--;
585
				return;
586
			}
587
		} else {
588
			for ($j = 0; $j < $steps; $j++) {
589
				$factor = wizard_get_bandwidthtype_scale($config['ezshaper']['step2']["conn{$j}downloadspeed"]);
590
				$ifbw = $factor * floatval($config['ezshaper']['step2']["conn{$j}download"]);
591
				$factor = wizard_get_bandwidthtype_scale($_POST["local{$i}downloadspeed"]);
592
				$input_bw = $factor * floatval($_POST["local{$i}download"]);
593
				if ((0.8 * $ifbw) < $input_bw) {
594
					$savemsg=gettext("You cannot set the VoIP download bandwidth on connection {$j} higher than 80% of the connection.");
595
					$stepid--;
596
					return;
597
				}
598
			}
599
		}
600
	}
601

    
602
	for ($i = 0; $i < $localint; $i++) {
603
		$config['ezshaper']['step3']["local{$i}download"] = $_POST["local{$i}download"];
604
		$config['ezshaper']['step3']["local{$i}downloadspeed"] = $_POST["local{$i}downloadspeed"];
605
	}
606

    
607
	for ($i = 0; $i < $steps; $i++) {
608
		$config['ezshaper']['step3']["conn{$i}upload"] = $_POST["conn{$i}upload"];
609
		$config['ezshaper']['step3']["conn{$i}uploadspeed"] = $_POST["conn{$i}uploadspeed"];
610
	}
611
}
612

    
613
function step4_stepsubmitphpaction() {
614
	global $config;
615
	global $stepid, $savemsg;
616

    
617
	if ( $_POST['enable'] ) {
618
		if(!$_POST['bandwidth']) {
619
			$savemsg="You need to specify a value for bandwidth!";
620
			$stepid--;
621
			return;
622
		}
623
		if(!is_numeric($_POST['bandwidth'])) {
624
			$savemsg="The posted value is not a valid bandwidth.";
625
			$stepid--;
626
			return;
627
		}
628
		if ($_POST['bandwidthspeed'] <> "%") {
629
			$savemsg = gettext("Only percentage bandwidth specification is allowed.");
630
			$stepid--;
631
			return;
632
		}
633
		$bw = $_POST['bandwidth'];
634
		if($bw > 15 || $bw < 2) {
635
			$savemsg="Values should be between 2% and 15%!";
636
			$stepid--;
637
			return;
638
		}
639
		if($_POST['address'] <> "" && !is_ipaddroralias($_POST['address'])) {
640
			/* item is not an ip or alias.  error out */
641
			$savemsg=gettext("Address must be a valid IP address or Firewall Alias.  Please correct this value to continue.");
642
			$stepid--;
643
		}
644
	}
645
}
646

    
647
function step5_stepsubmitphpaction() {
648
	global $stepid, $savemsg;
649
	if ( $_POST['enable'] ) {
650
		if ($_POST['p2pcatchall']) {
651
			if(!is_numeric($_POST['bandwidth'])) {
652
				$savemsg="Posted value is not a valid bandwidth.";
653
				$stepid--;
654
			}
655
			if ($_POST['bandwidthspeed'] <> "%") {
656
				$savemsg = gettext("Only percentage bandwidth specification is allowed.");
657
				$stepid--;
658
				return;
659
			}
660
			$bw = $_POST['bandwidth'];
661
			if($bw > 15 || $bw < 2) {
662
				$savemsg="Values should be between 2% and 15%!";
663
				$stepid--;
664
				return;
665
			}
666
		}
667
	}
668
}
669

    
670
function step8_stepsubmitphpaction() {
671
	global $g, $config;
672

    
673
	/* save the new configuration */
674
	apply_all_choosen_items();
675

    
676
	/* reset rrd queues */
677
	system("rm -f /var/db/rrd/*queuedrops.rrd");
678
	system("rm -f /var/db/rrd/*queues.rrd");
679
	enable_rrd_graphing();
680

    
681
	/* apply the new configuration to the system */
682
	filter_configure();
683

    
684
	/* And we're no longer dirty! */
685
	clear_subsystem_dirty('shaper');
686

    
687
	update_filter_reload_status("Initializing");
688
	header("Location: status_filter_reload.php");
689
	exit;
690
}
691

    
692
function apply_all_choosen_items() {
693
	global $config, $g, $altq_list_queues, $gamesplist, $voiplist, $othersplist, $p2plist;
694

    
695
	require_once("wizardapp.inc");
696

    
697
	/*
698
	 * Wipe previous config.
699
	 * Doing it here makes sense since we can wipe the previous config only after
700
	 * the user decides to do so, finishing the wizard.
701
	 */
702
	if(isset($config['shaper']['queue']))
703
		unset($config['shaper']['queue']);
704
	/* XXX: This is ecnundant, because this should be handled by converter at startup. */
705
	if(isset($config['shaper']['rule']))
706
		unset($config['shaper']['rule']);
707
	foreach ($config['filter']['rule'] as $key => $rule)
708
		if ($rule['wizard'] == "yes")
709
			unset($config['filter']['rule'][$key]);
710

    
711
	/* restart the cached config */
712
	unset($altq_list_queues);
713
	$altq_list_queues = array();
714

    
715
	$steps = intval($config['ezshaper']['step1']['numberofconnections']);
716

    
717
	$interfacelist = array();
718

    
719
	for ($i = 0; $i < $steps; $i++) {
720

    
721
		$tmppath = array();
722
		$altq =& new altq_root_queue();
723

    
724
		$altq->SetInterface($config['ezshaper']['step2']["conn{$i}interface"]);
725
		$interfacelist[] = $config['ezshaper']['step2']["conn{$i}interface"];
726
		$altq->SetScheduler($config['ezshaper']['step2']["conn{$i}uploadscheduler"]);
727
		$altq->SetBandwidth(floatval($config['ezshaper']['step2']["conn{$i}upload"]));
728
		$altq->SetBwscale($config['ezshaper']['step2']["conn{$i}uploadspeed"]);
729
		$altq->SetEnabled("on");
730
		$altq_list_queues[$altq->GetQname()] =& $altq;
731
		array_push($tmppath, $config['ezshaper']['step2']["conn{$i}interface"]);
732
		$altq->SetLink($tmppath);
733
		$altq->wconfig();
734

    
735
		$sched = $config['ezshaper']['step2']["conn{$i}uploadscheduler"];
736
		$voipbw =0;
737
		$voipbwunit = "Kb";
738
		$voip = false;
739
		$penalty = false;
740
		$penaltybw = 0;
741
		$penaltybwunit = "Kb";
742
		$p2p = false;
743
		$p2pcatchall = false;
744
		$p2pcatchbw = 0;
745
		$p2pcatchbwunit = "%";
746
		$games = false;
747
		$otherpriority = false;
748
		$remainbw = 0;
749
		$factor = 0;
750
		$upfactor = wizard_get_bandwidthtype_scale($config['ezshaper']['step2']["conn{$i}uploadspeed"]);
751
		$upbw = floatval($config['ezshaper']['step2']["conn{$i}upload"]) * $upfactor;
752

    
753
		if ($config['ezshaper']['step3']['enable']) {
754
			$voip = true;
755
			$voipbw = $config['ezshaper']['step3']["conn{$i}upload"];
756
			$voipbwunit = $config['ezshaper']['step3']["conn{$i}uploadspeed"];
757
			if ($voipbwunit == "%")
758
				$factor =  $upbw/100;
759
			else
760
				$factor = wizard_get_bandwidthtype_scale($voipbwunit);
761
			$remainbw += $voipbw * $factor;
762
		}
763
		if ($config['ezshaper']['step4']['enable']) {
764
			$penalty = true;
765
			$penaltybw = $config['ezshaper']['step4']['bandwidth'];
766
			$penaltybwunit = $config['ezshaper']['step4']['bandwidthunit'];
767
			if ($penaltybwunit == "%")
768
				$factor = $upbw/100;
769
			else
770
				$factor = wizard_get_bandwidthtype_scale($penaltybwunit);
771
			$remainbw += $penaltybw * $factor;
772
		} else {
773
			$penalty = false;
774
			$penaltybw = 0;
775
		}
776
		if ($config['ezshaper']['step5']['enable']) {
777
			$p2p = true;
778
			if ($config['ezshaper']['step5']['p2pcatchall']) {
779
				$p2pcatchall = true;
780
				$p2pcatchbw = $config['ezshaper']['step5']['bandwidth'];
781
				$p2pcatchbwunit = $config['ezshaper']['step5']['bandwidthunit'];
782
				if ($p2pcatchbwunit == "%")
783
					$factor = $upbw/100;
784
				else
785
					$factor = wizard_get_bandwidthtype_scale($p2pcatchbwunit);
786
				$remainbw += $p2pcatchbw * $factor;
787
			} else {
788
				$p2pcatchall = false;
789
				$p2pcatchbw = 0;
790
			}
791
		} else {
792
			$p2p = false;
793
			$p2pcatchall = false;
794
			$p2pcatchbw = 0;
795
		}
796
		if ($config['ezshaper']['step6']['enable']) {
797
			$games = true;
798
		} else {
799
			$games = false;
800
		}
801

    
802
		if ($config['ezshaper']['step7']['enable']) {
803
			$otherpriority = true;
804
		} else  {
805
			$otherpriority = false;
806
		}
807

    
808
		$remainbw = round($remainbw / $upbw * 100, 2);
809

    
810
		if (intval($remainbw) > 0 && intval($remainbw) > 30) {
811
			$savemsg=gettext("Custom Bandwidths are greater than 30%. Please lower them for the wizard to continue.");
812
			header("Location: wizard.php?xml=traffic_shaper_wizard_multi_all.xml&stepid=2&message={$savemsg}");
813
			exit;
814
		} else {
815
			$remainbw = 100 - $remainbw;
816
		}
817

    
818
		if ($sched != "PRIQ") {
819
			if ($sched == "CBQ")
820
				$q =& new cbq_queue();
821
			else if ($sched == "HFSC")
822
				$q =& new hfsc_queue();
823
			$tmpcf = array();
824
			$tmpcf['name'] = "qInternet";
825
			//$tmpcf['priority'] = 6;
826
			$tmpcf['ecn'] = "on";
827
			$tmpcf['enabled'] = "on";
828
			If ($sched == "CBQ") {
829
				$tmpcf['bandwidth'] = floatval($config['ezshaper']['step2']["conn{$i}upload"]);
830
				$tmpcf['bandwidthtype'] = $config['ezshaper']['step2']["conn{$i}uploadspeed"];
831
			}
832
			else if ($sched == "HFSC") {
833
				$tmpcf['linkshare3'] =
834
					floatval($config['ezshaper']['step2']["conn{$i}upload"]) . $config['ezshaper']['step2']["conn{$i}uploadspeed"];
835
				$tmpcf['upperlimit3'] =
836
					floatval($config['ezshaper']['step2']["conn{$i}upload"]) . $config['ezshaper']['step2']["conn{$i}uploadspeed"];
837
				$tmpcf['upperlimit'] = "on";
838

    
839

    
840
				$tmpcf['linkshare'] = "on";
841
				$tmpcf['bandwidth'] =  floatval($config['ezshaper']['step2']["conn{$i}upload"]);
842
				$tmpcf['bandwidthtype'] = $config['ezshaper']['step2']["conn{$i}uploadspeed"];
843
			}
844
			array_push($tmppath, "qInternet");
845
			$qtmp =& $altq->add_queue($q, $tmpcf, $tmppath, $input_errors);
846
			//array_pop($tmppath);
847
			//echo "qInternet <br />";
848
			//var_dump($input_errors);
849
			$qtmp->wconfig();
850
			$altq =& $qtmp;
851
		}
852

    
853
		if ($sched == "PRIQ")
854
			$q =& new priq_queue();
855
		else if ($sched == "CBQ")
856
			$q =& new cbq_queue();
857
		else if ($sched == "HFSC")
858
			$q =& new hfsc_queue();
859
		$tmpcf = array();
860
		$tmpcf['name'] = "qACK";
861
		$tmpcf['priority'] = 6;
862
		$tmpcf['ecn'] = "on";
863
		$tmpcf['enabled'] = "on";
864
		If ($sched == "CBQ") {
865
			$tmpcf['borrow'] = "on";
866
			$tmpcf['bandwidth'] = $remainbw * 0.2;
867
			$tmpcf['bandwidthtype'] = "%";
868
		}
869
		else if ($sched == "HFSC") {
870
			$lkbw = 0.20 * $remainbw;
871
			$tmpcf['linkshare3'] = "{$lkbw}%";
872
			$tmpcf['linkshare'] = "on";
873
			$tmpcf['bandwidth'] = $lkbw;
874
			$tmpcf['bandwidthtype'] = "%";
875
		}
876
		array_push($tmppath, "qACK");
877
		$qtmp =& $altq->add_queue($q, $tmpcf, $tmppath, $input_errors);
878
		array_pop($tmppath);
879
		//echo "qACK <br />";
880
		//var_dump($input_errors);
881
		$qtmp->wconfig();
882

    
883
		if ($sched == "PRIQ")
884
			$q =& new priq_queue();
885
		else if ($sched == "CBQ")
886
			$q =& new cbq_queue();
887
		else if ($sched == "HFSC")
888
			$q =& new hfsc_queue();
889
		$tmpcf = array();
890
		if ($p2pcatchall)
891
			$tmpcf['name'] = "qOthersDefault";
892
		else
893
			$tmpcf['name'] = "qDefault";
894
		$tmpcf['priority'] = 3;
895
		$tmpcf['enabled'] = "on";
896
		if (!$p2pcatchall)
897
			$tmpcf['default'] = "on";
898
		$tmpcf['ecn'] = "on";
899
		if ($sched == "CBQ") {
900
			$tmpcf['borrow'] = "on";
901
			$tmpcf['bandwidth'] = $remainbw * 0.1; /* 10% bandwidth */
902
			$tmpcf['bandwidthtype'] = "%";
903
		} else if ($sched == "HFSC") {
904
			$tmpcf['bandwidth'] = $remainbw * 0.1; /* 10% bandwidth */
905
			$tmpcf['bandwidthtype'] = "%";
906
		}
907
		array_push($tmppath, $tmpcf['name']);
908
		$qtmp =& $altq->add_queue($q, $tmpcf, $tmppath, $input_errors);
909
		array_pop($tmppath);
910
		//echo "qDefault <br />";
911
			//var_dump($input_errors);
912
			$qtmp->wconfig();
913

    
914
			if ($p2p) {
915
				if ($sched == "PRIQ")
916
					$q =& new priq_queue();
917
				else if ($sched == "CBQ")
918
					$q =& new cbq_queue();
919
				else if ($sched == "HFSC")
920
					$q =& new hfsc_queue();
921
				$tmpcf = array();
922
				$tmpcf['name'] = "qP2P";
923
				$tmpcf['priority'] = 1;
924
				$tmpcf['ecn'] = "on";
925
				$tmpcf['enabled'] = "on";
926
				if ($p2pcatchall) {
927
					if ($sched == "CBQ") {
928
						$tmpcf['borrow'] = "on";
929
						$tmpcf['bandwidth'] = $p2pcatchbw;
930
						$tmpcf['bandwidthtype'] = $p2pcatchbwunit;
931
					} else if ($sched == "HFSC") {
932
						$tmpcf['linkshare'] = "on";
933
						$tmpcf['linkshare3'] = "{$p2pcatchbw}{$p2pcatchbwunit}";
934
						$tmpcf['upperlimit'] = "on";
935
						$tmpcf['upperlimit3'] = "{$p2pcatchbw}{$p2pcatchbwunit}";
936
						$tmpcf['bandwidth'] = $p2pcatchbw;
937
						$tmpcf['bandwidthtype'] = $p2pcatchbwunit;
938
					}
939
					$tmpcf['default'] = "on";
940

    
941
				} else {
942
					if ($sched == "CBQ") {
943
						$tmpcf['borrow'] = "on";
944
						$tmpcf['bandwidth'] = $remainbw * 0.05; /* 5% bandwidth */
945
						$tmpcf['bandwidthtype'] = "%";
946
					} else if ($sched == "HFSC") {
947
						$tmpbw = $remainbw * 0.05; /* 5% bandwidth */
948
						$tmpcf['linkshare'] = "on";
949
						$tmpcf['linkshare3'] = "{$tmpbw}%";
950
						$tmpcf['upperlimit'] = "on";
951
						$tmpcf['upperlimit3'] = "{$tmpbw}%";
952
						$tmpcf['bandwidth'] = $tmpbw;
953
						$tmpcf['bandwidthtype'] = "%";
954
					}
955
				}
956
				array_push($tmppath, "qP2P");
957
				$qtmp =& $altq->add_queue($q, $tmpcf, $tmppath, $input_errors);
958
				array_pop($tmppath);
959
				//echo "qP2P <br />";
960
				//var_dump($input_errors);
961
				$qtmp->wconfig();
962
			}
963

    
964
			if ($voip) {
965
				if ($sched == "PRIQ")
966
					$q =& new priq_queue();
967
				else if ($sched == "CBQ")
968
					$q =& new cbq_queue();
969
				else if ($sched == "HFSC")
970
					$q =& new hfsc_queue();
971
				$tmpcf = array();
972
				$tmpcf['name'] = "qVoIP";
973
				$tmpcf['priority'] = 7;
974
				$tmpcf['ecn'] = "on";
975
				$tmpcf['enabled'] = "on";
976
				if ($sched == "CBQ") {
977
					$tmpcf['borrow'] = "on";
978
					if ($voipbw > 0) {
979
						$tmpcf['bandwidth'] = $voipbw;
980
						$tmpcf['bandwidthtype'] = $voipbwunit;
981
					} else {
982
						$tmpcf['bandwidth'] = $remainbw * 0.2; /* 20% bandwidth */
983
						$tmpcf['bandwidthtype'] = "%";
984
					}
985
				} else if ($sched == "HFSC") {
986
					if ($voipbw > 0) {
987
						$tmpcf['realtime3'] = "{$voipbw}{$voipbwunit}";
988
					} else {
989
						$voipbw = $remainbw * 0.20; /* 20% bandwidth */
990
						$tmpcf['realtime3'] = "{$voipbw}%";
991
					}
992
					$tmpcf['realtime'] = "on";
993
					$tmpcf['bandwidth'] = 32;
994
					$tmpcf['bandwidthtype'] = "Kb";
995
				}
996
				array_push($tmppath, "qVoIP");
997
				$qtmp =& $altq->add_queue($q, $tmpcf, $tmppath, $input_errors);
998
				array_pop($tmppath);
999
				//echo "qVoIP <br />";
1000
				//var_dump($input_errors);
1001
				$qtmp->wconfig();
1002
			}
1003

    
1004
			if ($games) {
1005
				if ($sched == "PRIQ")
1006
					$q =& new priq_queue();
1007
				else if ($sched == "CBQ")
1008
					$q =& new cbq_queue();
1009
				else if ($sched == "HFSC")
1010
					$q =& new hfsc_queue();
1011
				$tmpcf = array();
1012
				$tmpcf['name'] = "qGames";
1013
				$tmpcf['priority'] = 5;
1014
				$tmpcf['enabled'] = "on";
1015
				$tmpcf['ecn'] = "on";
1016
				if ($sched == "CBQ") {
1017
					$tmpcf['borrow'] = "on";
1018
					$tmpcf['bandwidth'] = $remainbw * 0.2; /* 20% bandwidth */
1019
					$tmpcf['bandwidthtype'] = "%";
1020
				} else if ($sched == "HFSC") {
1021
					$gamesbw = $remainbw * 0.2; /* 20% bandwidth */
1022
					$tmpcf['linkshare'] = "on";
1023
					$tmpcf['linkshare3'] = "{$gamesbw}%";
1024
					$tmpcf['bandwidth'] = "{$gamesbw}";
1025
					$tmpcf['bandwidthtype'] = "%";
1026
				}
1027
				array_push($tmppath, "qGames");
1028
				$qtmp =& $altq->add_queue($q, $tmpcf, $tmppath, $input_errors);
1029
				array_pop($tmppath);
1030
				//echo "qGames <br />";
1031
				//var_dump($input_errors);
1032
				$qtmp->wconfig();
1033
			}
1034

    
1035
			if ($otherpriority) {
1036
				if ($sched == "PRIQ")
1037
					$q =& new priq_queue();
1038
				else if ($sched == "CBQ")
1039
					$q =& new cbq_queue();
1040
				else if ($sched == "HFSC")
1041
					$q =& new hfsc_queue();
1042
				$tmpcf = array();
1043
				$tmpcf['name'] = "qOthersHigh";
1044
				$tmpcf['priority'] = 4;
1045
				$tmpcf['ecn'] = "on";
1046
				$tmpcf['enabled'] = "on";
1047
				if ($sched == "CBQ") {
1048
					$tmpcf['borrow'] = "on";
1049
					$tmpcf['bandwidth'] = $remainbw * 0.1; /* 10% bandwidth */
1050
					$tmpcf['bandwidthtype'] = "%";
1051
				} else if ($sched == "HFSC") {
1052
					$tmpcf['linkshare'] = "on";
1053
					$otherbw = $remainbw * 0.1; /* 10% bandwidth */
1054
					$tmpcf['linkshare3'] = "{$otherbw}%";
1055
					$tmpcf['bandwidth'] = $otherbw;
1056
					$tmpcf['bandwidthtype'] = "%";
1057
				}
1058
				array_push($tmppath, "qOthersHigh");
1059
				$qtmp =& $altq->add_queue($q, $tmpcf, $tmppath, $input_errors);
1060
				array_pop($tmppath);
1061
				//echo "qHigh <br />";
1062
				//var_dump($input_errors);
1063
				$qtmp->wconfig();
1064

    
1065

    
1066
				if ($sched == "PRIQ")
1067
					$q =& new priq_queue();
1068
				else if ($sched == "CBQ")
1069
					$q =& new cbq_queue();
1070
				else if ($sched == "HFSC")
1071
					$q =& new hfsc_queue();
1072
				$tmpcf = array();
1073
				$tmpcf['name'] = "qOthersLow";
1074
				$tmpcf['priority'] = 2;
1075
				$tmpcf['ecn'] = "on";
1076
				$tmpcf['enabled'] = "on";
1077
				if ($sched == "CBQ") {
1078
					$tmpcf['borrow'] = "on";
1079
					if ($penalty) {
1080
						$tmpcf['bandwidthtype'] = $penaltybwunit;
1081
						$tmpcf['bandwidth'] = $penaltybw;
1082
					} else {
1083
						$tmpcf['bandwidth'] = $remainbw * 0.05; /* 5% bandwidth */
1084
						$tmpcf['bandwidthtype'] = "%";
1085
					}
1086
				} else if ($sched == "HFSC") {
1087
					if ($penalty) {
1088
						$tmpcf['linkshare3'] = "{$penaltybw}{$penaltybwunit}";
1089
						$tmpcf['bandwidth'] = $penaltybw;
1090
						$tmpcf['bandwidthtype'] = $penaltybwunit;
1091
					} else {
1092
						$lsbw = $remainbw * 0.05;
1093
						$tmpcf['linkshare3'] = "{$lsbw}%"; /* 5% bandwidth */
1094
						$tmpcf['bandwidth'] = $lsbw;
1095
						$tmpcf['bandwidthtype'] = "%";
1096
					}
1097
					$tmpcf['linkshare'] = "on";
1098
				}
1099
				array_push($tmppath, "qOthersLow");
1100
				$qtmp =& $altq->add_queue($q, $tmpcf, $tmppath, $input_errors);
1101
				array_pop($tmppath);
1102
				//echo "qLow <br />";
1103
				//var_dump($input_errors);
1104
				$qtmp->wconfig();
1105
			}
1106
			array_pop($tmppath);
1107
		}
1108

    
1109
	/* LAN bandwidth ----------------------------------------------------------------------------------------- */
1110
	$localint = intval($config['ezshaper']['step1']['numberoflocalinterfaces']);
1111
	$lanbw = 0;
1112
	for ($i = 0; $i < $steps; $i++) {
1113
		$down = wizard_get_bandwidthtype_scale($config['ezshaper']['step2']["conn{$i}downloadspeed"]);
1114
		$input_bw = floatval($config['ezshaper']['step2']["conn{$i}download"]) * $down;
1115
		$lanbw += $input_bw;
1116
	}
1117

    
1118
	for ($i = 0; $i < $localint; $i++) {
1119

    
1120
		$tmppath = array();
1121
		$altq =& new altq_root_queue();
1122

    
1123
		$altq->SetInterface($config['ezshaper']['step2']["local{$i}interface"]);
1124
		$altq->SetScheduler($config['ezshaper']['step2']["local{$i}downloadscheduler"]);
1125
		//$altq->SetBandwidth($lanbw/1000);
1126
		//$altq->SetBwscale("Kb");
1127
		$altq->SetEnabled("on");
1128
		$altq_list_queues[$altq->GetQname()] =& $altq;
1129
		array_push($tmppath, $config['ezshaper']['step2']["local{$i}interface"]);
1130
		$altq->SetLink($tmppath);
1131
		//var_dump($input_errors);
1132
		$altq->wconfig();
1133

    
1134
		$sched = $config['ezshaper']['step2']["local{$i}downloadscheduler"];
1135
		$voipbw =0;
1136
		$voipbwunit = "%";
1137
		$voip = false;
1138
		$penalty = false;
1139
		$penaltybw = 0;
1140
		$penaltybwunit = "%";
1141
		$p2p = false;
1142
		$p2pcatchall = false;
1143
		$p2pcatchbw = 0;
1144
		$games = false;
1145
		$otherpriority = false;
1146
		$remainbw = 0;
1147

    
1148

    
1149
		if ($config['ezshaper']['step3']['enable']) {
1150
			$voip = true;
1151
			$voipbw = $config['ezshaper']['step3']["local{$i}download"];
1152
			$voipbwunit = $config['ezshaper']['step3']["local{$i}downloadspeed"];
1153
			if ($sched != HFSC) {
1154
				if ($penaltybwunit == "%")
1155
					$factor = $lanbw/100;
1156
				else
1157
					$factor = wizard_get_bandwidthtype_scale($voipbwunit);
1158
				$remainbw += floatval($voipbw) * $factor;
1159
			} else
1160
				$remainbw += 32000; /* 32Kbit/s reserved for HFSC linksharing */
1161
		}
1162
		if ($config['ezshaper']['step4']['enable']) {
1163
			$penalty = true;
1164
			$penaltybw = $config['ezshaper']['step4']['bandwidth'];
1165
			$penaltybwunit = $config['ezshaper']['step4']['bandwidthunit'];
1166
			if ($penaltybwunit == "%")
1167
				$factor = $lanbw/100;
1168
			else
1169
				$factor = wizard_get_bandwidthtype_scale($penaltybwunit);
1170
			$remainbw += floatval($penaltybw) * $factor;
1171
		} else {
1172
			$penalty = false;
1173
			$penaltybw = 0;
1174
		}
1175
		if ($config['ezshaper']['step5']['enable']) {
1176
			$p2p = true;
1177
			if ($config['ezshaper']['step5']['p2pcatchall']) {
1178
				$p2pcatchall = true;
1179
				$p2pcatchbw = $config['ezshaper']['step5']['bandwidth'];
1180
				$p2pcatchbwunit = $config['ezshaper']['step5']['bandwidthunit'];
1181
				if ($p2pcatchbwunit == "%")
1182
					$factor = $upbw/100;
1183
				else
1184
					$factor = wizard_get_bandwidthtype_scale($p2pcatchbwunit);
1185
				$remainbw += floatval($p2pcatchbw) * $factor;
1186
			} else {
1187
				$p2pcatchall = false;
1188
				$p2pcatchbw = 0;
1189
			}
1190
		} else {
1191
			$p2p = false;
1192
			$p2pcatchall = false;
1193
			$p2pcatchbw = 0;
1194
		}
1195
		if ($config['ezshaper']['step6']['enable']) {
1196
			$games = true;
1197
		} else {
1198
			$games = false;
1199
		}
1200

    
1201
		if ($config['ezshaper']['step7']['enable']) {
1202
			$otherpriority = true;
1203
		} else  {
1204
			$otherpriority = false;
1205
		}
1206
		$remainbw = round($remainbw / $lanbw * 100, 2);
1207

    
1208
		if (intval($remainbw) > 0 && intval($remainbw) > 40) {
1209
			$savemsg=gettext("Custom Bandwidths are greater than 30%. Please lower them for the wizard to continue.");
1210
			header("Location: wizard.php?xml=traffic_shaper_wizard_multi_all.xml&stepid=2&message={$savemsg}");
1211
			exit;
1212
		} else {
1213
			$remainbw = 100 - $remainbw;
1214
		}
1215

    
1216
		if (!$p2pcatchall) {
1217
			if ($sched == "PRIQ")
1218
				$q =& new priq_queue();
1219
			else if ($sched == "CBQ")
1220
				$q =& new cbq_queue();
1221
			else if ($sched == "HFSC")
1222
				$q =& new hfsc_queue();
1223
			$tmpcf = array();
1224
			$tmpcf['name'] = "qLink";
1225
			$tmpcf['priority'] = 2;
1226
			$tmpcf['enabled'] = "on";
1227
			$tmpcf['default'] = "on";
1228
			$tmpcf['qlimit'] = 500;
1229
			$tmpcf['ecn'] = "on";
1230
			if ($sched == "CBQ") {
1231
				$tmpcf['borrow'] = "on";
1232
				$tmpcf['bandwidth'] = 20; /* 20% bandwidth */
1233
				$tmpcf['bandwidthtype'] = "%";
1234
			} else if ($sched == "HFSC") {
1235
				$tmpcf['bandwidth'] = 20; /* 20% bandwidth */
1236
				$tmpcf['bandwidthtype'] = "%";
1237
			}
1238
			array_push($tmppath, $tmpcf['name']);
1239
			$qtmp =& $altq->add_queue($q, $tmpcf, $tmppath, $input_errors);
1240
			array_pop($tmppath);
1241
			//echo "qDefault <br />";
1242
			//var_dump($input_errors);
1243
			$qtmp->wconfig();
1244
		}
1245

    
1246
		if ($sched != "PRIQ") {
1247
			if ($sched == "CBQ")
1248
				$q =& new cbq_queue();
1249
			else if ($sched == "HFSC")
1250
				$q =& new hfsc_queue();
1251
			$tmpcf = array();
1252
			$tmpcf['name'] = "qInternet";
1253
			//$tmpcf['priority'] = 6;
1254
			$tmpcf['ecn'] = "on";
1255
			$tmpcf['enabled'] = "on";
1256
			If ($sched == "CBQ") {
1257
				$tmpcf['bandwidth'] = $lanbw/1000;
1258
				$tmpcf['bandwidthtype'] = "Kb";
1259
			}
1260
			else if ($sched == "HFSC") {
1261
				$tmpcf['linkshare3'] = $lanbw/1000 . "Kb";
1262
				$tmpcf['upperlimit3'] = $lanbw/1000 . "Kb";
1263
				$tmpcf['upperlimit'] = "on";
1264
				$tmpcf['linkshare'] = "on";
1265
				$tmpcf['bandwidth'] =  $lanbw/1000;
1266
				$tmpcf['bandwidthtype'] = "Kb";
1267
			}
1268
			array_push($tmppath, "qInternet");
1269
			$qtmp =& $altq->add_queue($q, $tmpcf, $tmppath, $input_errors);
1270
			//array_pop($tmppath);
1271
			//echo "qInternet <br />";
1272
			//var_dump($input_errors);
1273
			$qtmp->wconfig();
1274
			$altq =& $qtmp;
1275
		}
1276

    
1277
			if ($sched == "PRIQ")
1278
				$q =& new priq_queue();
1279
			else if ($sched == "CBQ")
1280
				$q =& new cbq_queue();
1281
			else if ($sched == "HFSC")
1282
			$q =& new hfsc_queue();
1283
			$tmpcf = array();
1284
			$tmpcf['name'] = "qACK";
1285
			$tmpcf['priority'] = 6;
1286
			$tmpcf['ecn'] = "on";
1287
			$tmpcf['enabled'] = "on";
1288
			If ($sched == "CBQ") {
1289
				$tmpcf['borrow'] = "on";
1290
				$tmpcf['bandwidth'] = $remainbw * 0.2;
1291
				$tmpcf['bandwidthtype'] = "%";
1292
			}
1293
			else if ($sched == "HFSC") {
1294
				$lkbw = 0.20 * $remainbw;
1295
				$tmpcf['linkshare3'] = "{$lkbw}%";
1296
				$tmpcf['linkshare'] = "on";
1297
				$tmpcf['bandwidth'] = $lkbw;
1298
				$tmpcf['bandwidthtype'] = "%";
1299
			}
1300
			array_push($tmppath, "qACK");
1301
			$qtmp =& $altq->add_queue($q, $tmpcf, $tmppath, $input_errors);
1302
			array_pop($tmppath);
1303
			//echo "qACK <br />";
1304
			//var_dump($input_errors);
1305
			$qtmp->wconfig();
1306

    
1307
			if ($p2p) {
1308
				if ($sched == "PRIQ")
1309
					$q =& new priq_queue();
1310
				else if ($sched == "CBQ")
1311
					$q =& new cbq_queue();
1312
				else if ($sched == "HFSC")
1313
					$q =& new hfsc_queue();
1314
				$tmpcf = array();
1315
				$tmpcf['name'] = "qP2P";
1316
				$tmpcf['priority'] = 1;
1317
				$tmpcf['ecn'] = "on";
1318
				$tmpcf['enabled'] = "on";
1319
				if ($p2pcatchall) {
1320
					if ($sched == "CBQ") {
1321
						$tmpcf['borrow'] = "on";
1322
						$tmpcf['bandwidth'] = $p2pcatchbw;
1323
						$tmpcf['bandwidthtype'] = $p2pcatchbwunit;
1324
					} else if ($sched == "HFSC") {
1325
						$tmpcf['linkshare'] = "on";
1326
						$tmpcf['linkshare3'] = "{$p2pcatchbw}{$p2pcatchbwunit}";
1327
						$tmpcf['upperlimit'] = "on";
1328
						$tmpcf['upperlimit3'] = "{$p2pcatchbw}{$p2pcatchbwunit}";
1329
						$tmpcf['bandwidth'] = $p2pcatchbw;
1330
						$tmpcf['bandwidthtype'] = $p2pcatchbwunit;
1331
					}
1332
					$tmpcf['default'] = "on";
1333
					$tmpcf['qlimit'] = 500;
1334
				} else {
1335
					if ($sched == "CBQ") {
1336
						$tmpcf['borrow'] = "on";
1337
						$tmpcf['bandwidth'] = $remainbw * 0.05; /* 5% bandwidth */
1338
						$tmpcf['bandwidthtype'] = "%";
1339
					} else if ($sched == "HFSC") {
1340
						$tmpbw = $remainbw * 0.05; /* 5% bandwidth */
1341
						$tmpcf['linkshare'] = "on";
1342
						$tmpcf['linkshare3'] = "{$tmpbw}%";
1343
						$tmpcf['upperlimit'] = "on";
1344
						$tmpcf['upperlimit3'] = "{$tmpbw}%";
1345
						$tmpcf['bandwidth'] = $tmpbw;
1346
						$tmpcf['bandwidthtype'] = "%";
1347
					}
1348
				}
1349
				array_push($tmppath, "qP2P");
1350
				$qtmp =& $altq->add_queue($q, $tmpcf, $tmppath, $input_errors);
1351
				array_pop($tmppath);
1352
				//echo "qP2P <br />";
1353
				//var_dump($input_errors);
1354
				$qtmp->wconfig();
1355
			}
1356

    
1357
			if ($voip) {
1358
				if ($sched == "PRIQ")
1359
					$q =& new priq_queue();
1360
				else if ($sched == "CBQ")
1361
					$q =& new cbq_queue();
1362
				else if ($sched == "HFSC")
1363
					$q =& new hfsc_queue();
1364
				$tmpcf = array();
1365
				$tmpcf['name'] = "qVoIP";
1366
				$tmpcf['priority'] = 7;
1367
				$tmpcf['ecn'] = "on";
1368
				$tmpcf['enabled'] = "on";
1369
				if ($sched == "CBQ") {
1370
					$tmpcf['borrow'] = "on";
1371
					if ($voipbw > 0) {
1372
						$tmpcf['bandwidth'] = $voipbw;
1373
						$tmpcf['bandwidthtype'] = $voipbwunit;
1374
					} else {
1375
						$tmpcf['bandwidth'] = $remainbw * 0.2; /* 20% bandwidth */
1376
						$tmpcf['bandwidthtype'] = "%";
1377
					}
1378
				} else if ($sched == "HFSC") {
1379
					if ($voipbw > 0) {
1380
						$tmpcf['realtime3'] = "{$voipbw}{$voipbwunit}";
1381
					} else {
1382
						$voipbw = $remainbw * 0.20; /* 20% bandwidth */
1383
						$tmpcf['realtime3'] = "{$voipbw}%";
1384
					}
1385
					$tmpcf['realtime'] = "on";
1386
					$tmpcf['bandwidth'] = 32;
1387
					$tmpcf['bandwidthtype'] = "Kb";
1388
				}
1389
				array_push($tmppath, "qVoIP");
1390
				$qtmp =& $altq->add_queue($q, $tmpcf, $tmppath, $input_errors);
1391
				array_pop($tmppath);
1392
				//echo "qVoIP <br />";
1393
				//var_dump($input_errors);
1394
				$qtmp->wconfig();
1395
			}
1396

    
1397
			if ($games) {
1398
				if ($sched == "PRIQ")
1399
					$q =& new priq_queue();
1400
				else if ($sched == "CBQ")
1401
					$q =& new cbq_queue();
1402
				else if ($sched == "HFSC")
1403
					$q =& new hfsc_queue();
1404
				$tmpcf = array();
1405
				$tmpcf['name'] = "qGames";
1406
				$tmpcf['priority'] = 5;
1407
				$tmpcf['enabled'] = "on";
1408
				$tmpcf['ecn'] = "on";
1409
				if ($sched == "CBQ") {
1410
					$tmpcf['borrow'] = "on";
1411
					$tmpcf['bandwidth'] = $remainbw * 0.2; /* 20% bandwidth */
1412
					$tmpcf['bandwidthtype'] = "%";
1413
				} else if ($sched == "HFSC") {
1414
					$gamesbw = $remainbw * 0.2; /* 20% bandwidth */
1415
					$tmpcf['linkshare'] = "on";
1416
					$tmpcf['linkshare3'] = "{$gamesbw}%";
1417
					$tmpcf['bandwidth'] = "{$gamesbw}";
1418
					$tmpcf['bandwidthtype'] = "%";
1419
				}
1420
				array_push($tmppath, "qGames");
1421
				$qtmp =& $altq->add_queue($q, $tmpcf, $tmppath, $input_errors);
1422
				array_pop($tmppath);
1423
				//echo "qGames <br />";
1424
				//var_dump($input_errors);
1425
				$qtmp->wconfig();
1426
			}
1427

    
1428
			if ($otherpriority) {
1429
				if ($sched == "PRIQ")
1430
					$q =& new priq_queue();
1431
				else if ($sched == "CBQ")
1432
					$q =& new cbq_queue();
1433
				else if ($sched == "HFSC")
1434
					$q =& new hfsc_queue();
1435
				$tmpcf = array();
1436
				$tmpcf['name'] = "qOthersHigh";
1437
				$tmpcf['priority'] = 4;
1438
				$tmpcf['ecn'] = "on";
1439
				$tmpcf['enabled'] = "on";
1440
				if ($sched == "CBQ") {
1441
					$tmpcf['borrow'] = "on";
1442
					$tmpcf['bandwidth'] = $remainbw * 0.1; /* 10% bandwidth */
1443
					$tmpcf['bandwidthtype'] = "%";
1444
				} else if ($sched == "HFSC") {
1445
					$tmpcf['linkshare'] = "on";
1446
					$otherbw = $remainbw * 0.1; /* 10% bandwidth */
1447
					$tmpcf['linkshare3'] = "{$otherbw}%";
1448
					$tmpcf['bandwidth'] = $otherbw;
1449
					$tmpcf['bandwidthtype'] = "%";
1450
				}
1451
				array_push($tmppath, "qOthersHigh");
1452
				$qtmp =& $altq->add_queue($q, $tmpcf, $tmppath, $input_errors);
1453
				array_pop($tmppath);
1454
				//echo "qHigh <br />";
1455
				//var_dump($input_errors);
1456
				$qtmp->wconfig();
1457

    
1458

    
1459
				if ($sched == "PRIQ")
1460
					$q =& new priq_queue();
1461
				else if ($sched == "CBQ")
1462
					$q =& new cbq_queue();
1463
				else if ($sched == "HFSC")
1464
					$q =& new hfsc_queue();
1465
				$tmpcf = array();
1466
				$tmpcf['name'] = "qOthersLow";
1467
				$tmpcf['priority'] = 3;
1468
				$tmpcf['ecn'] = "on";
1469
				$tmpcf['enabled'] = "on";
1470
				if ($sched == "CBQ") {
1471
					$tmpcf['borrow'] = "on";
1472
					if ($penalty) {
1473
						$tmpcf['bandwidth'] = $penaltybw;
1474
						$tmpcf['bandwidthtype'] = $penaltybwunit;
1475
					} else {
1476
						$tmpcf['bandwidthtype'] = "%";
1477
						$tmpcf['bandwidth'] = $remainbw * 0.05; /* 5% bandwidth */
1478
					}
1479
				} else if ($sched == "HFSC") {
1480
					if ($penalty) {
1481
						$tmpcf['linkshare3'] = "{$penaltybw}{$penaltybwunit}";
1482
						$tmpcf['bandwidth'] = $penaltybw;
1483
						$tmpcf['bandwidthtype'] = $penaltybwunit;
1484
					} else {
1485
						$lsbw = $remainbw * 0.05;
1486
						$tmpcf['linkshare3'] = "{$lsbw}%"; /* 5% bandwidth */
1487
						$tmpcf['bandwidth'] = $lsbw;
1488
						$tmpcf['bandwidthtype'] = "%";
1489
					}
1490
					$tmpcf['linkshare'] = "on";
1491
				}
1492
				array_push($tmppath, "qOthersLow");
1493
				$qtmp =& $altq->add_queue($q, $tmpcf, $tmppath, $input_errors);
1494
				array_pop($tmppath);
1495
				//echo "qLow <br />";
1496
				//var_dump($input_errors);
1497
				$qtmp->wconfig();
1498
			}
1499
			array_pop($tmppath);
1500
	}
1501

    
1502
/* End LAN bandwidth ------------------------------------------------------------------------------------- */
1503

    
1504

    
1505

    
1506
	if (!is_array($config['filter']['rule']))
1507
		$config['filter']['rule'] = array();
1508

    
1509
	$interfacelist = implode(",", $interfacelist);
1510

    
1511
	/* Rules */
1512
	if ($penalty) {
1513
		if( is_ipaddr($config['ezshaper']['step4']['address']) || is_alias($config['ezshaper']['step4']['address'])) {
1514
			$rule = array();
1515
			$rule['type'] = "match";
1516
			$rule['interface'] = $interfacelist;
1517
			$rule['descr'] = gettext("Penalty Box");
1518
			$rule['defaultqueue'] = "qOthersLow";
1519
			$rule['source']['address'] = $config['ezshaper']['step4']['address'];
1520
			$rule['destination']['any'] = TRUE;
1521
			$rule['floating'] = "yes";
1522
			$rule['wizard'] = "yes";
1523
			$rule['enabled'] = "on";
1524
			$rule['created'] = make_config_revision_entry(null, gettext("Traffic Shaper Wizard"));
1525
			$config['filter']['rule'][] = $rule;
1526

    
1527
		}
1528
	}
1529

    
1530
			/* If user specifies an IP, we don't bother with providers */
1531
			if ($voip) {
1532
				if( is_ipaddr($config['ezshaper']['step3']['address']) || is_alias($config['ezshaper']['step3']['address'])) {
1533
					/* create VOIP rules */
1534
					$rule = array();
1535
					$rule['type'] = "match";
1536
					//$rule['interface'] = $interfacelist;
1537
					$rule['descr'] = gettext("Connections From Upstream SIP Server");
1538
					$rule['protocol'] = "udp";
1539
					$rule['defaultqueue'] = "qVoIP";
1540
					$rule['source']['address'] = $config['ezshaper']['step3']['address'];
1541
					$rule['destination']['any'] = TRUE;
1542
					$rule['floating'] = "yes";
1543
					$rule['wizard'] = "yes";
1544
					$rule['enabled'] = "on";
1545
					$rule['created'] = make_config_revision_entry(null, gettext("Traffic Shaper Wizard"));
1546
					$config['filter']['rule'][] = $rule;
1547

    
1548
					$rule = array();
1549
					$rule['type'] = "match";
1550
					//$rule['interface'] = $interfacelist;
1551
					$rule['descr'] = gettext("Connections To Upstream SIP Server");
1552
					$rule['protocol'] = "udp";
1553
					$rule['defaultqueue'] = "qVoIP";
1554
					$rule['source']['any'] = TRUE;
1555
					$rule['destination']['address'] = $config['ezshaper']['step3']['address'];
1556
					$rule['floating'] = "yes";
1557
					$rule['wizard'] = "yes";
1558
					$rule['enabled'] = "on";
1559
					$rule['created'] = make_config_revision_entry(null, gettext("Traffic Shaper Wizard"));
1560
					$config['filter']['rule'][] = $rule;
1561

    
1562
				} elseif( $config['ezshaper']['step3']['provider'] == "Generic" ) {
1563
					/* create VOIP rules */
1564
					$rule = array();
1565
					$rule['type'] = "match";
1566
					$rule['interface'] = $interfacelist;
1567
					$rule['descr'] = "DiffServ/Lowdelay/Upload";
1568
					$rule['protocol'] = "udp";
1569
					$rule['source']['any'] = TRUE;
1570
					$rule['defaultqueue'] = "qVoIP";
1571
					$rule['destination']['any'] = TRUE;
1572
					$rule['iptos'] = "lowdelay";
1573
					$rule['floating'] = "yes";
1574
					$rule['wizard'] = "yes";
1575
					$rule['enabled'] = "on";
1576
					$rule['created'] = make_config_revision_entry(null, gettext("Traffic Shaper Wizard"));
1577
					$config['filter']['rule'][] = $rule;
1578

    
1579
				} else {
1580
					/* loop through voiplist[] */
1581
					foreach ($voiplist[$config['ezshaper']['step3']['provider']] as $voip) {
1582
						$rule = array();
1583
						$rule['type'] = "match";
1584
						$rule['interface'] = $interfacelist;
1585
						$rule['defaultqueue'] = 'qVoIP';
1586
						$rule['source']['any'] = TRUE;
1587
						$rule['destination']['any'] = TRUE;
1588
						$rule['descr'] = "m_voip {$voip[0]} outbound";
1589
						$rule['floating'] = "yes";
1590
						$rule['wizard'] = "yes";
1591
						$rule['enabled'] = "on";
1592
						$rule['destination']['port'] = $voip[2]."-".$voip[3];
1593
						if($voip[1] != '')
1594
							$rule['protocol'] = $voip[1];
1595
						$rule['created'] = make_config_revision_entry(null, gettext("Traffic Shaper Wizard"));
1596
						$config['filter']['rule'][] = $rule;
1597
					}
1598
				}
1599
			}
1600

    
1601
			/* loop through p2plist[] */
1602
			if ($p2p) {
1603
				foreach($config['ezshaper']['step5'] as $key => $val) {
1604
					if (!is_array($p2plist[$key]))
1605
						continue;
1606
					foreach ($p2plist[$key] as $p2pclient) {
1607
						$rule = array();
1608
						$rule['type'] = "match";
1609
						$rule['interface'] = $interfacelist;
1610
						$rule['defaultqueue'] = 'qP2P';
1611
						$rule['source']['any'] = TRUE;
1612
						$rule['destination']['any'] = TRUE;
1613
						$rule['descr'] = "m_P2P {$p2pclient[0]} outbound";
1614
						$rule['floating'] = "yes";
1615
						$rule['wizard'] = "yes";
1616
						$rule['destination']['port'] = $p2pclient[2]."-".$p2pclient[3];
1617
						if($p2pclient[1] != '')
1618
							$rule['protocol'] = $p2pclient[1];
1619
						$rule['created'] = make_config_revision_entry(null, gettext("Traffic Shaper Wizard"));
1620
						$config['filter']['rule'][] = $rule;
1621
					}
1622
				}
1623
			}
1624

    
1625
			/* loop through gamesplist[] */
1626
			if ($games) {
1627
				foreach($config['ezshaper']['step6'] as $key => $val) {
1628
					if (!is_array($gamesplist[$key]))
1629
										continue;
1630
					foreach ($gamesplist[$key] as $Gameclient) {
1631
						$rule = array();
1632
						$rule['type'] = "match";
1633
						$rule['interface'] = $interfacelist;
1634
						$rule['defaultqueue'] = 'qGames';
1635
						if ($Gameclient[1] == "tcp")
1636
							$rule['ackqueue'] = 'qACK';
1637
						$rule['source']['any'] = TRUE;
1638
						$rule['destination']['any'] = TRUE;
1639
						$rule['floating'] = "yes";
1640
						$rule['wizard'] = "yes";
1641
						$rule['enabled'] = "on";
1642
						$rule['descr'] = "m_Game {$Gameclient[0]} outbound";
1643
						$rule['destination']['port'] = $Gameclient[2]."-".$Gameclient[3];
1644
						if($Gameclient[1] != '')
1645
							$rule['protocol'] = $Gameclient[1];
1646
						$rule['created'] = make_config_revision_entry(null, gettext("Traffic Shaper Wizard"));
1647
						$config['filter']['rule'][] = $rule;
1648
					}
1649
				}
1650
			}
1651

    
1652
	/* loop through othersplist[] */
1653
	if ($otherpriority) {
1654
		foreach($config['ezshaper']['step7'] as $key => $val) {
1655
			if (!is_array($othersplist[$key]))
1656
				continue;
1657
			foreach ($othersplist[$key] as $otherclient) {
1658
				$rule = array();
1659
				$rule['type'] = "match";
1660
				$rule['interface'] = $interfacelist;
1661
				switch ($val) {
1662
				case "H":
1663
					$rule['defaultqueue'] = 'qOthersHigh'; /* posted value H or L */
1664
					if ($otherclient[1] == "tcp")
1665
								$rule['ackqueue'] = 'qACK';
1666
					$loop = 0;
1667
					break;
1668
				case "L":
1669
					$rule['defaultqueue'] = 'qOthersLow'; /* posted value H or L */
1670
					if ($otherclient[1] == "tcp")
1671
						$rule['ackqueue'] = 'qACK';
1672
					$loop = 0;
1673
					break;
1674
				case "D":
1675
					if ($p2pcatchall) {
1676
						$loop = 0;
1677
						$rule['defaultqueue'] = 'qOthersDefault';
1678
						if ($otherclient[1] == "tcp")
1679
							$rule['ackqueue'] = 'qACK';
1680
					} else
1681
						$loop = 1; /* It automitaclly goes to default queue */
1682
					break;
1683
				default:
1684
					$loop = 1;
1685
				}
1686
				if (!$loop) {
1687
					$rule['source']['any'] = TRUE;
1688
					$rule['destination']['any'] = TRUE;
1689
					$rule['floating'] = "yes";
1690
					$rule['wizard'] = "yes";
1691
					$rule['enabled'] = "on";
1692
					$rule['descr'] = "m_Other {$otherclient[0]} outbound";
1693

    
1694
					if($otherclient[2] or $otherclient[3]) {
1695
						$rule['destination']['port'] = $otherclient[2]."-".$otherclient[3];
1696
					}
1697
					if($otherclient[1] != '')
1698
						$rule['protocol'] = $otherclient[1];
1699
					$rule['created'] = make_config_revision_entry(null, gettext("Traffic Shaper Wizard"));
1700
					$config['filter']['rule'][] = $rule;
1701
				}
1702
			}
1703
		}
1704
	}
1705
	write_config();
1706
}
1707

    
1708
function wizard_get_bandwidthtype_scale($type = "b") {
1709
	switch ($type) {
1710
	case "Gb":
1711
		$factor = 1024 * 1024 * 1024;
1712
		break;
1713
	case "Mb":
1714
		$factor = 1024 * 1024;
1715
		break;
1716
	case "Kb":
1717
		$factor = 1024;
1718
		break;
1719
	case "b":
1720
	default:
1721
		$factor = 1;
1722
		break;
1723
	}
1724
	return intval($factor);
1725
}
1726

    
1727
?>
(6-6/7)