Project

General

Profile

Download (38.7 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	firewall_schedule_edit.php
4
	Copyright (C) 2004 Scott Ullrich
5
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
6
	All rights reserved.
7

    
8
	originally part of m0n0wall (http://m0n0.ch/wall)
9
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
10
	All rights reserved.
11

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

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

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

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

    
37
##|+PRIV
38
##|*IDENT=page-firewall-schedules-edit
39
##|*NAME=Firewall: Schedules: Edit page
40
##|*DESCR=Allow access to the 'Firewall: Schedules: Edit' page.
41
##|*MATCH=firewall_schedule_edit.php*
42
##|-PRIV
43

    
44
function schedulecmp($a, $b) {
45
	return strcmp($a['name'], $b['name']);
46
}
47

    
48
function schedule_sort() {
49
	global $g, $config;
50

    
51
	if (!is_array($config['schedules']['schedule'])) {
52
		return;
53
	}
54

    
55
	usort($config['schedules']['schedule'], "schedulecmp");
56
}
57

    
58
require("guiconfig.inc");
59
require_once("functions.inc");
60
require_once("filter.inc");
61
require_once("shaper.inc");
62

    
63
$pgtitle = array(gettext("Firewall"), gettext("Schedules"), gettext("Edit"));
64

    
65
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/firewall_schedule.php');
66

    
67
$dayArray = array (gettext('Mon'), gettext('Tues'), gettext('Wed'), gettext('Thur'), gettext('Fri'), gettext('Sat'), gettext('Sun'));
68
$monthArray = array (gettext('January'), gettext('February'), gettext('March'), gettext('April'), gettext('May'), gettext('June'), gettext('July'), gettext('August'), gettext('September'), gettext('October'), gettext('November'), gettext('December'));
69

    
70
if (!is_array($config['schedules']['schedule'])) {
71
	$config['schedules']['schedule'] = array();
72
}
73

    
74
$a_schedules = &$config['schedules']['schedule'];
75

    
76
if (is_numericint($_GET['id'])) {
77
	$id = $_GET['id'];
78
}
79
if (isset($_POST['id']) && is_numericint($_POST['id'])) {
80
	$id = $_POST['id'];
81
}
82

    
83
if (isset($id) && $a_schedules[$id]) {
84
	$pconfig['name'] = $a_schedules[$id]['name'];
85
	$pconfig['descr'] = html_entity_decode($a_schedules[$id]['descr']);
86
	$pconfig['timerange'] = $a_schedules[$id]['timerange'];
87
	$pconfig['schedlabel'] = $a_schedules[$id]['schedlabel'];
88
	$getSchedule = true;
89
}
90

    
91
if ($_POST) {
92

    
93
	if (strtolower($_POST['name']) == "lan") {
94
		$input_errors[] = gettext("Schedule may not be named LAN.");
95
	}
96
	if (strtolower($_POST['name']) == "wan") {
97
		$input_errors[] = gettext("Schedule may not be named WAN.");
98
	}
99
	if (strtolower($_POST['name']) == "") {
100
		$input_errors[] = gettext("Schedule name cannot be blank.");
101
	}
102

    
103
	$x = is_validaliasname($_POST['name']);
104
	if (!isset($x)) {
105
		$input_errors[] = gettext("Reserved word used for schedule name.");
106
	} else {
107
		if (is_validaliasname($_POST['name']) == false) {
108
			$input_errors[] = gettext("The schedule name may only consist of the characters a-z, A-Z, 0-9");
109
		}
110
	}
111

    
112
	/* check for name conflicts */
113
	foreach ($a_schedules as $schedule) {
114
		if (isset($id) && ($a_schedules[$id]) && ($a_schedules[$id] === $schedule)) {
115
			continue;
116
		}
117

    
118
		if ($schedule['name'] == $_POST['name']) {
119
			$input_errors[] = gettext("A Schedule with this name already exists.");
120
			break;
121
		}
122
	}
123
	$schedule = array();
124

    
125
	$schedule['name'] = $_POST['name'];
126
	$schedule['descr'] = htmlentities($_POST['descr'], ENT_QUOTES, 'UTF-8');
127

    
128
	$timerangeFound = false;
129
	for ($x = 0; $x < 99; $x++) {
130
		if ($_POST['schedule' . $x]) {
131
			if (!preg_match('/^[0-9]+:[0-9]+$/', $_POST['starttime' . $x])) {
132
				$input_errors[] = sprintf(gettext("Invalid start time - '%s'"), $_POST['starttime' . $x]);
133
				continue;
134
			}
135
			if (!preg_match('/^[0-9]+:[0-9]+$/', $_POST['stoptime' . $x])) {
136
				$input_errors[] = sprintf(gettext("Invalid stop time - '%s'"), $_POST['stoptime' . $x]);
137
				continue;
138
			}
139
			$timerangeFound = true;
140
			$timeparts = array();
141
			$firstprint = false;
142
			$timestr = $_POST['schedule' . $x];
143
			$timehourstr = $_POST['starttime' . $x];
144
			$timehourstr .= "-";
145
			$timehourstr .= $_POST['stoptime' . $x];
146
			$timedescrstr = htmlentities($_POST['timedescr' . $x], ENT_QUOTES, 'UTF-8');
147
			$dashpos = strpos($timestr, '-');
148
			if ($dashpos === false) {
149
				$timeparts['position'] = $timestr;
150
			} else {
151
				$tempindarray = array();
152
				$monthstr = "";
153
				$daystr = "";
154
				$tempindarray = explode(",", $timestr);
155
				foreach ($tempindarray as $currentselection) {
156
					if ($currentselection) {
157
						if ($firstprint) {
158
							$monthstr .= ",";
159
							$daystr .= ",";
160
						}
161
						$tempstr = "";
162
						$monthpos = strpos($currentselection, "m");
163
						$daypos = strpos($currentselection, "d");
164
						$monthstr .= substr($currentselection, $monthpos+1, $daypos-$monthpos-1);
165
						$daystr .= substr($currentselection, $daypos+1);
166
						$firstprint = true;
167
					}
168
				}
169
				$timeparts['month'] = $monthstr;
170
				$timeparts['day'] = $daystr;
171
			}
172
			$timeparts['hour'] = $timehourstr;
173
			$timeparts['rangedescr'] = $timedescrstr;
174
			$schedule['timerange'][$x] = $timeparts;
175
		}
176
	}
177

    
178
	if (!$timerangeFound) {
179
		$input_errors[] = gettext("The schedule must have at least one time range configured.");
180
	}
181

    
182
	if (!$input_errors) {
183

    
184
		if (!empty($pconfig['schedlabel'])) {
185
			$schedule['schedlabel'] = $pconfig['schedlabel'];
186
		} else {
187
			$schedule['schedlabel'] = uniqid();
188
		}
189

    
190
		if (isset($id) && $a_schedules[$id]) {
191
			$a_schedules[$id] = $schedule;
192
		} else {
193
			$a_schedules[] = $schedule;
194
		}
195
		schedule_sort();
196
		if (write_config()) {
197
			filter_configure();
198
		}
199

    
200
		header("Location: firewall_schedule.php");
201
		exit;
202
	} else {
203
		//we received input errors, copy data to prevent retype
204
		if (!$_POST['schedule0']) {
205
			$getSchedule = false;
206
		} else {
207
			$getSchedule = true;
208
		}
209
		$pconfig['name'] = $schedule['name'];
210
		$pconfig['descr'] = $schedule['descr'];
211
		$pconfig['timerange'] = $schedule['timerange'];
212
	}
213

    
214
}
215
include("head.inc");
216

    
217
/* put your custom HTML head content here        */
218
/* using some of the $pfSenseHead function calls */
219
$jscriptstr = <<<EOD
220
<script type="text/javascript">
221
//<![CDATA[
222
var daysSelected = "";
223
var month_array = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
224
var day_array = ['Mon', 'Tues', 'Wed', 'Thur', 'Fri', 'Sat', 'Sun'];
225
var schCounter = 0;
226

    
227
function rgb2hex(rgb) {
228
	var parts = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
229
	if (parts == null) {
230
		return;
231
	}
232
	function hex(x) {
233
		return ("0" + parseInt(x).toString(16)).slice(-2);
234
	}
235
	return ("#" + hex(parts[1]) + hex(parts[2]) + hex(parts[3])).toUpperCase();
236
}
237

    
238
function repeatExistingDays() {
239
	var tempstr, tempstrdaypos, week, daypos, dayposdone = "";
240

    
241
	var dayarray = daysSelected.split(",");
242
	for (i = 0; i <= dayarray.length; i++) {
243
		tempstr = dayarray[i];
244
		tempstrdaypos = tempstr.search("p");
245
		week = tempstr.substring(1, tempstrdaypos);
246
		week = parseInt(week);
247
		dashpos = tempstr.search("-");
248
		daypos = tempstr.substring(tempstrdaypos+1, dashpos);
249
		daypos = parseInt(daypos);
250

    
251
		daydone = dayposdone.search(daypos);
252
		tempstr = 'w' + week + 'p' + daypos;
253
		daycell = eval('document.getElementById(tempstr)');
254
		if (daydone == "-1") {
255
			if (rgb2hex(daycell.style.backgroundColor) == "#F08080") { // lightcoral
256
				daytogglerepeating(week, daypos, true);
257
			} else {
258
				daytogglerepeating(week, daypos, false);
259
			}
260
			dayposdone += daypos + ",";
261
		}
262
	}
263
}
264

    
265
function daytogglerepeating(week, daypos, bExists) {
266
	var tempstr, daycell, dayoriginal = "";
267
	for (j=1; j<=53; j++) {
268
		tempstr = 'w' + j + 'p' + daypos;
269
		daycell = eval('document.getElementById(tempstr)');
270
		dayoriginalpos = daysSelected.indexOf(tempstr);
271

    
272
		//if bExists set to true, means cell is already select it
273
		//unselect it and remove original day from daysSelected string
274

    
275
		if (daycell != null) {
276
			if (bExists) {
277
				daycell.style.backgroundColor = "#FFFFFF";  // white
278
			} else {
279
				daycell.style.backgroundColor = "#F08080";  // lightcoral
280
			}
281

    
282
			if (dayoriginalpos != "-1") {
283
				dayoriginalend = daysSelected.indexOf(',', dayoriginalpos);
284
				tempstr = daysSelected.substring(dayoriginalpos, dayoriginalend+1);
285
				daysSelected = daysSelected.replace(tempstr, "");
286

    
287
			}
288
		}
289
	}
290
}
291

    
292
function daytoggle(id) {
293
	var runrepeat, tempstr = "";
294
	var bFoundValid = false;
295

    
296
	iddashpos = id.search("-");
297
	var tempstrdaypos = id.search("p");
298
	var week = id.substring(1, tempstrdaypos);
299
	week = parseInt(week);
300

    
301
	if (iddashpos == "-1") {
302
		idmod = id;
303
		runrepeat = true;
304
		var daypos = id.substr(tempstrdaypos+1);
305
	} else {
306
		idmod = id.substring(0, iddashpos);
307
		var daypos = id.substring(tempstrdaypos+1, iddashpos);
308
	}
309

    
310
	daypos = parseInt(daypos);
311

    
312
	while (!bFoundValid) {
313
		var daycell = document.getElementById(idmod);
314

    
315
		if (daycell != null) {
316
			if (rgb2hex(daycell.style.backgroundColor) == "#FF0000") { // red
317
				daycell.style.backgroundColor = "#FFFFFF";  // white
318
				str = id + ",";
319
				daysSelected = daysSelected.replace(str, "");
320
			} else if (rgb2hex(daycell.style.backgroundColor) == "#F08080") { // lightcoral
321
				daytogglerepeating(week, daypos, true);
322
			} else {
323
				//color is white cell
324
				if (!runrepeat) {
325
					daycell.style.backgroundColor = "#FF0000";  // red
326
				} else {
327
					daycell.style.backgroundColor = "#F08080";  // lightcoral
328
					daytogglerepeating(week, daypos, false);
329
				}
330
				daysSelected += id + ",";
331
			}
332
			bFoundValid = true;
333
		} else {
334
			//we found an invalid cell when column was clicked, move up to the next week
335
			week++;
336
			tempstr = "w" + week + "p" + daypos;
337
			idmod = tempstr;
338
		}
339
	}
340
}
341

    
342
function update_month() {
343
	var indexNum = document.forms[0].monthsel.selectedIndex;
344
	var selected = document.forms[0].monthsel.options[indexNum].text;
345

    
346
	for (i = 0; i <= 11; i++) {
347
		option = document.forms[0].monthsel.options[i].text;
348
		document.popupMonthLayer = eval('document.getElementById (option)');
349

    
350
		if (selected == option) {
351
			document.popupMonthLayer.style.display="block";
352
		} else {
353
			document.popupMonthLayer.style.display="none";
354
		}
355
	}
356
}
357

    
358
function checkForRanges() {
359
	if (daysSelected != "") {
360
		alert("You have not saved the specified time range. Please click 'Add Time' button to save the time range.");
361
		return false;
362
	} else {
363
		return true;
364
	}
365
}
366

    
367
function processEntries() {
368
	var tempstr, starttimehour, starttimemin, stoptimehour, stoptimemin, errors = "";
369
	var passedValidiation = true;
370

    
371
	//get time specified
372
	starttimehour = parseInt(document.getElementById("starttimehour").value);
373
	starttimemin = parseInt(document.getElementById("starttimemin").value);
374
	stoptimehour = parseInt(document.getElementById("stoptimehour").value);
375
	stoptimemin = parseInt(document.getElementById("stoptimemin").value);
376

    
377

    
378
	//do time checks
379
	if (starttimehour > stoptimehour) {
380
		errors = "Error: Start Hour cannot be greater than Stop Hour.";
381
		passedValidiation = false;
382

    
383
	} else if (starttimehour == stoptimehour) {
384
		if (starttimemin > stoptimemin) {
385
			errors = "Error: Start Minute cannot be greater than Stop Minute.";
386
			passedValidiation = false;
387
		}
388
	}
389

    
390
	if (passedValidiation) {
391
		addTimeRange();
392
	} else {
393
		if (errors != "") {
394
			alert(errors);
395
		}
396
	}
397
}
398

    
399
function addTimeRange() {
400
	var tempdayarray = daysSelected.split(",");
401
	var tempstr, tempFriendlyDay, starttimehour, starttimemin, stoptimehour, nrtempFriendlyTime, rtempFriendlyTime, nrtempID, rtempID = "";
402
	var stoptimemin, timeRange, tempstrdaypos, week, daypos, day, month, dashpos, nrtempTime, rtempTime, monthstr, daystr = "";
403
	rtempFriendlyTime = "";
404
	nrtempFriendlyTime = "";
405
	nrtempID = "";
406
	rtempID = "";
407
	nrtempTime = "";
408
	rtempTime = "";
409
	tempdayarray.sort();
410
	rtempFriendlyDay = "";
411
	monthstr = "";
412
	daystr = "";
413

    
414
	//check for existing entries
415
	var findCurrentCounter;
416
	for (u = 0; u < 99; u++) {
417
		findCurrentCounter = document.getElementById("schedule" + u);
418
		if (!findCurrentCounter) {
419
			schCounter = u;
420
			break;
421
		}
422
	}
423

    
424
	if (daysSelected != "") {
425
		//get days selected
426
		for (i = 0; i < tempdayarray.length; i++) {
427
			tempstr = tempdayarray[i];
428
			if (tempstr != "") {
429
				tempstrdaypos = tempstr.search("p");
430
				week = tempstr.substring(1, tempstrdaypos);
431
				week = parseInt(week);
432
				dashpos = tempstr.search("-");
433

    
434
				if (dashpos != "-1") {
435
					var nonrepeatingfound = true;
436
					daypos = tempstr.substring(tempstrdaypos+1, dashpos);
437
					daypos = parseInt(daypos);
438
					monthpos = tempstr.search("m");
439
					tempstrdaypos = tempstr.search("d");
440
					month = tempstr.substring(monthpos+1, tempstrdaypos);
441
					month = parseInt(month);
442
					day = tempstr.substring(tempstrdaypos+1);
443
					day = parseInt(day);
444
					monthstr += month + ",";
445
					daystr += day + ",";
446
					nrtempID += tempstr + ",";
447
				} else {
448
					var repeatingfound = true;
449
					daypos = tempstr.substr(tempstrdaypos+1);
450
					daypos = parseInt(daypos);
451
					rtempFriendlyDay += daypos + ",";
452
					rtempID += daypos + ",";
453
				}
454
			}
455
		}
456

    
457
		//code below spits out friendly look format for nonrepeating schedules
458
		var foundEnd = false;
459
		var firstDayFound = false;
460
		var firstprint = false;
461
		var tempFriendlyMonthArray = monthstr.split(",");
462
		var tempFriendlyDayArray = daystr.split(",");
463
		var currentDay, firstDay, nextDay, currentMonth, nextMonth, firstDay, firstMonth = "";
464
		for (k = 0; k < tempFriendlyMonthArray.length; k++) {
465
			tempstr = tempFriendlyMonthArray[k];
466
			if (tempstr != "") {
467
				if (!firstDayFound) {
468
					firstDay = tempFriendlyDayArray[k];
469
					firstDay = parseInt(firstDay);
470
					firstMonth = tempFriendlyMonthArray[k];
471
					firstMonth = parseInt(firstMonth);
472
					firstDayFound = true;
473
				}
474
				currentDay = tempFriendlyDayArray[k];
475
				currentDay = parseInt(currentDay);
476
				//get next day
477
				nextDay = tempFriendlyDayArray[k+1];
478
				nextDay = parseInt(nextDay);
479
				//get next month
480

    
481
				currentDay++;
482
				if ((currentDay != nextDay) || (tempFriendlyMonthArray[k] != tempFriendlyMonthArray[k+1])) {
483
					if (firstprint) {
484
						nrtempFriendlyTime += ", ";
485
					}
486
					currentDay--;
487
					if (currentDay != firstDay) {
488
						nrtempFriendlyTime += month_array[firstMonth-1] + " " + firstDay + "-" + currentDay;
489
					} else {
490
						nrtempFriendlyTime += month_array[firstMonth-1] + " " + currentDay;
491
					}
492
					firstDayFound = false;
493
					firstprint = true;
494
				}
495
			}
496
		}
497

    
498
		//code below spits out friendly look format for repeating schedules
499
		foundEnd = false;
500
		firstDayFound = false;
501
		firstprint = false;
502
		tempFriendlyDayArray = rtempFriendlyDay.split(",");
503
		tempFriendlyDayArray.sort();
504
		currentDay, firstDay, nextDay = "";
505
		for (k = 0; k < tempFriendlyDayArray.length; k++) {
506
			tempstr = tempFriendlyDayArray[k];
507
			if (tempstr != "") {
508
				if (!firstDayFound) {
509
					firstDay = tempFriendlyDayArray[k];
510
					firstDay = parseInt(firstDay);
511
					firstDayFound = true;
512
				}
513
				currentDay = tempFriendlyDayArray[k];
514
				currentDay = parseInt(currentDay);
515
				//get next day
516
				nextDay = tempFriendlyDayArray[k+1];
517
				nextDay = parseInt(nextDay);
518
				currentDay++;
519
				if (currentDay != nextDay) {
520
					if (firstprint) {
521
						rtempFriendlyTime += ", ";
522
					}
523
					currentDay--;
524
					if (currentDay != firstDay) {
525
						rtempFriendlyTime += day_array[firstDay-1] + " - " + day_array[currentDay-1];
526
					} else {
527
						rtempFriendlyTime += day_array[firstDay-1];
528
					}
529
					firstDayFound = false;
530
					firstprint = true;
531
				}
532
			}
533
		}
534

    
535
		//sort the tempID
536
		var tempsortArray = rtempID.split(",");
537
		var isFirstdone = false;
538
		tempsortArray.sort();
539
		//clear tempID
540
		rtempID = "";
541
		for (t = 0; t < tempsortArray.length; t++) {
542
			if (tempsortArray[t] != "") {
543
				if (!isFirstdone) {
544
					rtempID += tempsortArray[t];
545
					isFirstdone = true;
546
				} else {
547
					rtempID += "," + tempsortArray[t];
548
				}
549
			}
550
		}
551

    
552

    
553
		//get time specified
554
		starttimehour = document.getElementById("starttimehour").value
555
		starttimemin = document.getElementById("starttimemin").value;
556
		stoptimehour = document.getElementById("stoptimehour").value;
557
		stoptimemin = document.getElementById("stoptimemin").value;
558

    
559
		timeRange = "||" + starttimehour + ":";
560
		timeRange += starttimemin + "-";
561
		timeRange += stoptimehour + ":";
562
		timeRange += stoptimemin;
563

    
564
		//get description for time range
565
		var tempdescr = document.getElementById("timerangedescr").value
566

    
567
		if (nonrepeatingfound) {
568
			nrtempTime += nrtempID;
569
			//add time ranges
570
			nrtempTime += timeRange;
571
			//add description
572
			nrtempTime += "||" + tempdescr;
573
			insertElements(nrtempFriendlyTime, starttimehour, starttimemin, stoptimehour, stoptimemin, tempdescr, nrtempTime, nrtempID);
574
		}
575

    
576
		if (repeatingfound) {
577
			rtempTime += rtempID;
578
			//add time ranges
579
			rtempTime += timeRange;
580
			//add description
581
			rtempTime += "||" + tempdescr;
582
			insertElements(rtempFriendlyTime, starttimehour, starttimemin, stoptimehour, stoptimemin, tempdescr, rtempTime, rtempID);
583
		}
584

    
585
	} else {
586
		//no days were selected, alert user
587
		alert ("You must select at least 1 day before adding time");
588
	}
589
}
590

    
591
function insertElements(tempFriendlyTime, starttimehour, starttimemin, stoptimehour, stoptimemin, tempdescr, tempTime, tempID) {
592

    
593
	//add it to the schedule list
594
	d = document;
595
	tbody = d.getElementById("scheduletable").getElementsByTagName("tbody").item(0);
596
	tr = d.createElement("tr");
597
	td = d.createElement("td");
598
	td.innerHTML= "<span class='vexpl'>" + tempFriendlyTime + "<\/span>";
599
	tr.appendChild(td);
600

    
601
	td = d.createElement("td");
602
	td.innerHTML="<input type='text' readonly class='vexpl' name='starttime" + schCounter + "' id='starttime" + schCounter + "' style=' word-wrap:break-word; width:100%; border:0px solid;' value='" + starttimehour + ":" + starttimemin + "' />";
603
	tr.appendChild(td);
604

    
605
	td = d.createElement("td");
606
	td.innerHTML="<input type='text' readonly class='vexpl' name='stoptime" + schCounter + "' id='stoptime" + schCounter + "' style=' word-wrap:break-word; width:100%; border:0px solid;' value='" + stoptimehour + ":" + stoptimemin + "' />";
607
	tr.appendChild(td);
608

    
609
	td = d.createElement("td");
610
	td.innerHTML="<input type='text' readonly class='vexpl' name='timedescr" + schCounter + "' id='timedescr" + schCounter + "' style=' word-wrap:break-word; width:100%; border:0px solid;' value='" + tempdescr + "' />";
611
	tr.appendChild(td);
612

    
613
	td = d.createElement("td");
614
	td.innerHTML = "<a onclick='editRow(\"" + tempTime + "\",this); return false;' href='#'><img border='0' src='/themes/" + theme + "/images/icons/icon_e.gif' alt='edit' /></\a>";
615
	tr.appendChild(td);
616

    
617
	td = d.createElement("td");
618
	td.innerHTML = "<a onclick='removeRow(this); return false;' href='#'><img border='0' src='/themes/" + theme + "/images/icons/icon_x.gif' alt='remove' /></\a>";
619
	tr.appendChild(td);
620

    
621
	td = d.createElement("td");
622
	td.innerHTML="<input type='hidden' id='schedule" + schCounter + "' name='schedule" + schCounter + "' value='" + tempID + "' />";
623
	tr.appendChild(td);
624
	tbody.appendChild(tr);
625

    
626
	schCounter++;
627

    
628
	//reset calendar and time and descr
629
	clearCalendar();
630
	clearTime();
631
	clearDescr();
632
}
633

    
634

    
635
function clearCalendar() {
636
	var tempstr, daycell = "";
637
	//clear days selected
638
	daysSelected = "";
639
	//loop through all 52 weeks
640
	for (j=1; j<=53; j++) {
641
		//loop through all 7 days
642
		for (k=1; k<8; k++) {
643
			tempstr = 'w' + j + 'p' + k;
644
			daycell = eval('document.getElementById(tempstr)');
645
			if (daycell != null) {
646
				daycell.style.backgroundColor = "#FFFFFF";  // white
647
			}
648
		}
649
	}
650
}
651

    
652
function clearTime() {
653
	document.getElementById("starttimehour").value = "0";
654
	document.getElementById("starttimemin").value = "00";
655
	document.getElementById("stoptimehour").value = "23";
656
	document.getElementById("stoptimemin").value = "59";
657
}
658

    
659
function clearDescr() {
660
	document.getElementById("timerangedescr").value = "";
661
}
662

    
663
function editRow(incTime, el) {
664
	var check = checkForRanges();
665

    
666
	if (check) {
667

    
668
		//reset calendar and time
669
		clearCalendar();
670
		clearTime();
671

    
672
		var starttimehour, descr, days, tempstr, starttimemin, hours, stoptimehour, stoptimemin = "";
673

    
674
		tempArray = incTime.split ("||");
675

    
676
		days = tempArray[0];
677
		hours = tempArray[1];
678
		descr = tempArray[2];
679

    
680
		var tempdayArray = days.split(",");
681
		var temphourArray = hours.split("-");
682
		tempstr = temphourArray[0];
683
		var temphourArray2 = tempstr.split(":");
684

    
685
		document.getElementById("starttimehour").value = temphourArray2[0];
686
		document.getElementById("starttimemin").value = temphourArray2[1];
687

    
688
		tempstr = temphourArray[1];
689
		temphourArray2 = tempstr.split(":");
690

    
691
		document.getElementById("stoptimehour").value = temphourArray2[0];
692
		document.getElementById("stoptimemin").value = temphourArray2[1];
693

    
694
		document.getElementById("timerangedescr").value = descr;
695

    
696
		//toggle the appropriate days
697
		for (i = 0; i < tempdayArray.length; i++) {
698
			if (tempdayArray[i]) {
699
				var tempweekstr = tempdayArray[i];
700
				dashpos = tempweekstr.search("-");
701

    
702
				if (dashpos == "-1") {
703
					tempstr = "w2p" + tempdayArray[i];
704
				} else {
705
					tempstr = tempdayArray[i];
706
				}
707
				daytoggle(tempstr);
708
			}
709
		}
710
		removeRownoprompt(el);
711
	}
712
}
713

    
714
function removeRownoprompt(el) {
715
	var cel;
716
	while (el && el.nodeName.toLowerCase() != "tr") {
717
		el = el.parentNode;
718
	}
719

    
720
	if (el && el.parentNode) {
721
		cel = el.getElementsByTagName("td").item(0);
722
		el.parentNode.removeChild(el);
723
	}
724
}
725

    
726

    
727
function removeRow(el) {
728
	var check = confirm ("Do you really want to delete this time range?");
729
	if (check) {
730
		var cel;
731
		while (el && el.nodeName.toLowerCase() != "tr") {
732
			el = el.parentNode;
733
		}
734

    
735
		if (el && el.parentNode) {
736
			cel = el.getElementsByTagName("td").item(0);
737
			el.parentNode.removeChild(el);
738
		}
739
	}
740
}
741
//]]>
742
</script>
743
EOD;
744
?>
745

    
746
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
747

    
748

    
749
<?php include("fbegin.inc");	echo $jscriptstr; ?>
750
<?php if ($input_errors) print_input_errors($input_errors); ?>
751
<div id="inputerrors"></div>
752

    
753
<form action="firewall_schedule_edit.php" method="post" name="iform" id="iform">
754
	<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="firewall schedule">
755
		<tr>
756
			<td colspan="2" valign="top" class="listtopic"><?=gettext("Schedule information");?></td>
757
		</tr>
758
		<tr>
759
			<td>
760
				<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area">
761
					<tr>
762
						<td width="15%" valign="top" class="vncellreq"><?=gettext("Schedule Name");?></td>
763
						<td width="85%" class="vtable">
764
						<?php if (is_schedule_inuse($pconfig['name']) == true): ?>
765
							<input name="name" type="hidden" id="name" size="40" value="<?=htmlspecialchars($pconfig['name']);?>" />
766
							<?php echo $pconfig['name']; ?>
767
							<p>
768
								<span class="vexpl"><?=gettext("NOTE: This schedule is in use so the name may not be modified!");?></span>
769
							</p>
770
						<?php else: ?>
771
							<input name="name" type="text" id="name" size="40" maxlength="40" class="formfld unknown" value="<?=htmlspecialchars($pconfig['name']);?>" /><br />
772
							<span class="vexpl">
773
								<?=gettext("The name of the alias may only consist of the characters a-z, A-Z and 0-9");?>
774
							</span>
775
						<?php endif; ?>
776
						</td>
777
					</tr>
778
					<tr>
779
						<td width="15%" valign="top" class="vncell"><?=gettext("Description");?></td>
780
						<td width="85%" class="vtable"><input name="descr" type="text" id="descr" size="40" maxlength="40" class="formfld unknown" value="<?=htmlspecialchars($pconfig['descr']);?>" /><br />
781
							<span class="vexpl">
782
								<?=gettext("You may enter a description here for your reference (not parsed).");?>
783
							</span>
784
						</td>
785
					</tr>
786
					<!-- tr>
787
					</tr -->
788
					<tr>
789
						<td width="15%" valign="top" class="vncellreq"><?=gettext("Month");?></td>
790
						<td width="85%" class="vtable">
791
							<select name="monthsel" class="formselect" id="monthsel" onchange="update_month();">
792
							<?php
793
								$monthcounter = date("n");
794
								$monthlimit = $monthcounter + 12;
795
								$yearcounter = date("Y");
796
								for ($k = 0; $k < 12; $k++) {?>
797
									<option value="<?php echo $monthcounter;?>"><?php echo date("F_y", mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter)));?></option>
798
							<?php
799
									if ($monthcounter == 12) {
800
										$monthcounter = 1;
801
										$yearcounter++;
802
									} else {
803
										$monthcounter++;
804
									}
805
								} ?>
806
							</select>
807
							<br /><br />
808
							<?php
809
								$firstmonth = TRUE;
810
								$monthcounter = date("n");
811
								$yearcounter = date("Y");
812
								for ($k = 0; $k < 12; $k++) {
813
									$firstdayofmonth = date("w", mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter)));
814
									if ($firstdayofmonth == 0) {
815
										$firstdayofmonth = 7;
816
									}
817

    
818
									$daycounter = 1;
819
									//number of day in month
820
									$numberofdays = date("t", mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter)));
821
									$firstdayprinted = FALSE;
822
									$lasttr = FALSE;
823
									$positioncounter = 1;//7 for Sun, 1 for Mon, 2 for Tues, etc
824
							?>
825
							<div id="<?php echo date("F_y", mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter)));?>" style=" position:relative; display:<?php if ($firstmonth)echo "block";else echo "none";?>">
826
							<table border="1" cellspacing="1" cellpadding="1" id="calTable<?=$monthcounter . $yearcounter;?>" class="tabcont" summary="month">
827
								<tr>
828
									<td colspan="7" align="center" class="listbg"><b><?php echo date("F_Y", mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter)));?></b></td>
829
								</tr>
830
								<tr>
831
									<td align="center" class="listhdrr" style="cursor: pointer;" onclick="daytoggle('w1p1');"><u><b><?=gettext("Mon");?></b></u></td>
832
									<td align="center" class="listhdrr" style="cursor: pointer;" onclick="daytoggle('w1p2');"><u><b><?=gettext("Tue");?></b></u></td>
833
									<td align="center" class="listhdrr" style="cursor: pointer;" onclick="daytoggle('w1p3');"><u><b><?=gettext("Wed");?></b></u></td>
834
									<td align="center" class="listhdrr" style="cursor: pointer;" onclick="daytoggle('w1p4');"><u><b><?=gettext("Thu");?></b></u></td>
835
									<td align="center" class="listhdrr" style="cursor: pointer;" onclick="daytoggle('w1p5');"><u><b><?=gettext("Fri");?></b></u></td>
836
									<td align="center" class="listhdrr" style="cursor: pointer;" onclick="daytoggle('w1p6');"><u><b><?=gettext("Sat");?></b></u></td>
837
									<td align="center" class="listhdrr" style="cursor: pointer;" onclick="daytoggle('w1p7');"><u><b><?=gettext("Sun");?></b></u></td>
838
								</tr>
839
								<?php
840
									$firstmonth = FALSE;
841
									while ($daycounter<=$numberofdays) {
842
										$weekcounter = date("W", mktime(0, 0, 0, date($monthcounter), date($daycounter), date($yearcounter)));
843
										$weekcounter = ltrim($weekcounter, "0");
844
										if ($positioncounter == 1) {
845
											echo "<tr>";
846
										}
847
										if ($firstdayofmonth == $positioncounter) {
848
								?>
849
										<td align="center" style="cursor: pointer;" class="listr" id="w<?=$weekcounter;?>p<?=$positioncounter;?>" onclick="daytoggle('w<?=$weekcounter;?>p<?=$positioncounter;?>-m<?=$monthcounter;?>d<?=$daycounter;?>');">
850
								<?php
851
											echo $daycounter;
852
											$daycounter++;
853
											$firstdayprinted = TRUE;
854
											echo "</td>";
855
										} elseif ($firstdayprinted == TRUE && $daycounter <= $numberofdays) {
856
								?>
857
										<td align="center" style="cursor: pointer;" class="listr" id="w<?=$weekcounter;?>p<?=$positioncounter;?>" onclick="daytoggle('w<?=$weekcounter;?>p<?=$positioncounter;?>-m<?=$monthcounter;?>d<?=$daycounter;?>');">
858
								<?php
859
											echo $daycounter;
860
											$daycounter++;
861
											echo "</td>";
862
										} else {
863
											echo "<td align=\"center\" class=\"listr\"></td>";
864
										}
865

    
866
										if ($positioncounter == 7 || $daycounter > $numberofdays) {
867
											$positioncounter = 1;
868
											echo "</tr>";
869
										} else {
870
											$positioncounter++;
871
										}
872

    
873
									} //end while loop
874
								?>
875
							</table>
876
							</div>
877
					<?php
878
						if ($monthcounter == 12) {
879
							$monthcounter = 1;
880
							$yearcounter++;
881
						} else {
882
							$monthcounter++;
883
						}
884
					} //end for loop
885
					?>
886
							<br />
887
							<?=gettext("Click individual date to select that date only. Click the appropriate weekday Header to select all occurrences of that weekday.");?>
888
						</td>
889
					</tr>
890
					<tr>
891
						<td width="15%" valign="top" class="vncellreq"><?=gettext("Time");?></td>
892
						<td width="85%" class="vtable">
893
							<table cellspacing="2" class="tabcont" summary="time">
894
								<tr>
895
									<td class="listhdrr" align="center"><?=gettext("Start Time");?></td><td></td><td class="listhdrr" align="center"><?=gettext("Stop Time");?></td>
896
								</tr>
897
								<tr>
898
									<td>
899
										<select name="starttimehour" class="formselect" id="starttimehour">
900
										<?php
901
											for ($i = 0; $i < 24; $i++) {
902
												echo "<option value=\"$i\">";
903
												echo $i;
904
												echo "</option>";
905
											}
906
										?>
907
										</select>&nbsp;<?=gettext("Hr"); ?>&nbsp;&nbsp;
908
										<select name="starttimemin" class="formselect" id="starttimemin">
909
											<option value="00">00</option>
910
											<option value="15">15</option>
911
											<option value="30">30</option>
912
											<option value="45">45</option>
913
											<option value="59">59</option>
914
										</select>&nbsp;<?=gettext("Min"); ?>
915
									</td>
916
									<td></td>
917
									<td>
918
										<select name="stoptimehour" class="formselect" id="stoptimehour">
919
										<?php
920
											for ($i = 0; $i < 24; $i++) {
921
												if ($i == 23) {
922
													$selected = "selected=\"selected\"";
923
												} else {
924
													$selected = "";
925
												}
926

    
927
												echo "<option value=\"$i\" $selected>";
928
												echo $i;
929
												echo "</option>";
930
											}
931
										?>
932
										</select>&nbsp;<?=gettext("Hr");?>&nbsp;&nbsp;
933
										<select name="stoptimemin" class="formselect" id="stoptimemin">
934
											<option value="00">00</option>
935
											<option value="15">15</option>
936
											<option value="30">30</option>
937
											<option value="45">45</option>
938
											<option value="59" selected="selected">59</option>
939
										</select>&nbsp;<?=gettext("Min");?>
940
									</td>
941
								</tr>
942
							</table>
943
							<br />
944
							<?=gettext("Select the time range for the day(s) selected on the Month(s) above. A full day is 0:00-23:59.")?>
945
						</td>
946
					</tr>
947
					<tr>
948
						<td width="15%" valign="top" class="vncell"><?=gettext("Time Range Description")?></td>
949
						<td width="85%" class="vtable"><input name="timerangedescr" type="text" class="formfld unknown" id="timerangedescr" size="40" maxlength="40" /><br />
950
							<span class="vexpl">
951
								<?=gettext("You may enter a description here for your reference (not parsed).")?>
952
							</span>
953
						</td>
954
					</tr>
955
					<tr>
956
						<td width="22%" valign="top">&nbsp;</td>
957
						<td width="78%">
958
							<input type="button" value="<?=gettext("Add Time");?>" class="formbtn" onclick="javascript:processEntries();" />&nbsp;&nbsp;&nbsp;
959
							<input type="button" value="<?=gettext("Clear Selection");?>" class="formbtn" onclick="javascript:clearCalendar(); clearTime(); clearDescr();" />
960
						</td>
961
					</tr>
962
					<tr>
963
						<td width="15%" valign="top" class="vtable"></td>
964
						<td width="85%" class="vtable"></td>
965
					</tr>
966
					<tr>
967
						<td colspan="2" valign="top" class="listtopic"><?=gettext("Schedule repeat");?></td>
968
					</tr>
969
					<tr>
970
						<td width="15%" valign="top" class="vncellreq"><?=gettext("Configured Ranges");?></td>
971
						<td width="85%">
972
							<table id="scheduletable" summary="range">
973
								<tbody>
974
									<tr>
975
										<td align="center" class="listbg" width="35%"><?=gettext("Day(s)");?></td>
976
										<td align="center" class="listbg" width="12%"><?=gettext("Start Time");?></td>
977
										<td align="center" class="listbg" width="11%"><?=gettext("Stop Time");?></td>
978
										<td align="center" class="listbg" width="42%"><?=gettext("Description");?></td>
979
									</tr>
980
									<?php
981
									if ($getSchedule) {
982
										$counter = 0;
983

    
984
										foreach ($pconfig['timerange'] as $timerange) {
985
											$tempFriendlyTime = "";
986
											$tempID = "";
987
											if ($timerange) {
988
												$dayFriendly = "";
989
												$tempFriendlyTime = "";
990
												$timedescr = $timerange['rangedescr'];
991

    
992
												//get hours
993
												$temptimerange = $timerange['hour'];
994
												$temptimeseparator = strrpos($temptimerange, "-");
995

    
996
												$starttime = substr ($temptimerange, 0, $temptimeseparator);
997
												$stoptime = substr ($temptimerange, $temptimeseparator+1);
998
												$currentDay = "";
999
												$firstDay = "";
1000
												$nextDay = "";
1001
												$foundEnd = false;
1002
												$firstDayFound = false;
1003
												$firstPrint = false;
1004
												$firstprint2 = false;
1005

    
1006
												if ($timerange['month']) {
1007
													$tempmontharray = explode(",", $timerange['month']);
1008
													$tempdayarray = explode(",", $timerange['day']);
1009
													$arraycounter = 0;
1010
													foreach ($tempmontharray as $monthtmp) {
1011
														$month = $tempmontharray[$arraycounter];
1012
														$day = $tempdayarray[$arraycounter];
1013
														$daypos = date("w", mktime(0, 0, 0, date($month), date($day), date("Y")));
1014
														//if sunday, set position to 7 to get correct week number. This is due to php limitations on ISO-8601. When we move to php5.1 we can change this.
1015
														if ($daypos == 0) {
1016
															$daypos = 7;
1017
														}
1018
														$weeknumber = date("W", mktime(0, 0, 0, date($month), date($day), date("Y")));
1019
														$weeknumber = ltrim($weeknumber, "0");
1020

    
1021
														if ($firstPrint) {
1022
															$tempID .= ",";
1023
														}
1024
														$tempID .= "w" . $weeknumber . "p" . $daypos . "-m" . $month . "d" . $day;
1025
														$firstPrint = true;
1026

    
1027
														if (!$firstDayFound) {
1028
															$firstDay = $day;
1029
															$firstmonth = $month;
1030
															$firstDayFound = true;
1031
														}
1032

    
1033
														$currentDay = $day;
1034
														$nextDay = $tempdayarray[$arraycounter+1];
1035
														$currentDay++;
1036
														if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])) {
1037
															if ($firstprint2) {
1038
																$tempFriendlyTime .= ", ";
1039
															}
1040
															$currentDay--;
1041
															if ($currentDay != $firstDay) {
1042
																$tempFriendlyTime .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
1043
															} else {
1044
																$tempFriendlyTime .= $monthArray[$month-1] . " " . $day;
1045
															}
1046
															$firstDayFound = false;
1047
															$firstprint2 = true;
1048
														}
1049
														$arraycounter++;
1050
													}
1051
												} else {
1052
													$dayFriendly = $timerange['position'];
1053
													$tempID = $dayFriendly;
1054
												}
1055

    
1056
												$tempTime = $tempID . "||" . $starttime . "-" . $stoptime . "||" . $timedescr;
1057

    
1058
												//following code makes the days friendly appearing, IE instead of Mon, Tues, Wed it will show Mon - Wed
1059
												$foundEnd = false;
1060
												$firstDayFound = false;
1061
												$firstprint = false;
1062
												$tempFriendlyDayArray = explode(",", $dayFriendly);
1063
												$currentDay = "";
1064
												$firstDay = "";
1065
												$nextDay = "";
1066
												$i = 0;
1067
												if (!$timerange['month']) {
1068
													foreach ($tempFriendlyDayArray as $day) {
1069
														if ($day != "") {
1070
															if (!$firstDayFound) {
1071
																$firstDay = $tempFriendlyDayArray[$i];
1072
																$firstDayFound = true;
1073
															}
1074
															$currentDay =$tempFriendlyDayArray[$i];
1075
															//get next day
1076
															$nextDay = $tempFriendlyDayArray[$i+1];
1077
															$currentDay++;
1078
															if ($currentDay != $nextDay) {
1079
																if ($firstprint) {
1080
																	$tempFriendlyTime .= ", ";
1081
																}
1082
																$currentDay--;
1083
																if ($currentDay != $firstDay) {
1084
																	$tempFriendlyTime .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
1085
																} else {
1086
																	$tempFriendlyTime .= $dayArray[$firstDay-1];
1087
																}
1088
																$firstDayFound = false;
1089
																$firstprint = true;
1090
															}
1091
															$i++;
1092
														}
1093
													}
1094
												}
1095
									?>
1096
									<tr>
1097
										<td>
1098
											<span class="vexpl"><?php echo $tempFriendlyTime; ?></span>
1099
										</td>
1100
										<td>
1101
											<input type='text' readonly='readonly' class='vexpl' name='starttime<?php echo $counter; ?>' id='starttime<?php echo $counter; ?>' style=' word-wrap:break-word; width:100%; border:0px solid;' value='<?php echo $starttime; ?>' />
1102
										</td>
1103
										<td>
1104
											<input type='text' readonly='readonly' class='vexpl' name='stoptime<?php echo $counter; ?>' id='stoptime<?php echo $counter; ?>' style=' word-wrap:break-word; width:100%; border:0px solid;' value='<?php echo $stoptime; ?>' />
1105
										</td>
1106
										<td>
1107
											<input type='text' readonly='readonly' class='vexpl' name='timedescr<?php echo $counter; ?>' id='timedescr<?php echo $counter; ?>' style=' word-wrap:break-word; width:100%; border:0px solid;' value='<?php echo $timedescr; ?>' />
1108
										</td>
1109
										<td>
1110
											<a onclick='editRow("<?php echo $tempTime; ?>",this); return false;' href='#'><img border='0' src='/themes/<?php echo $g['theme']; ?>/images/icons/icon_e.gif' alt='edit' /></a>
1111
										</td>
1112
										<td>
1113
											<a onclick='removeRow(this); return false;' href='#'><img border='0' src='/themes/<?php echo $g['theme']; ?>/images/icons/icon_x.gif' alt='remove' /></a>
1114
										</td>
1115
										<td>
1116
											<input type='hidden' id='schedule<?php echo $counter; ?>' name='schedule<?php echo $counter; ?>' value='<?php echo $tempID; ?>' />
1117
										</td>
1118
									</tr>
1119
									<?php
1120
												$counter++;
1121
											}//end if
1122
										} // end foreach
1123
									}//end if
1124
									?>
1125
								</tbody>
1126
							</table>
1127
						</td>
1128
					</tr>
1129
					<tr>
1130
						<td width="15%" valign="top">&nbsp;</td>
1131
						<td width="85%">
1132
							<input id="submit" name="submit" type="submit" onclick="return checkForRanges();" class="formbtn" value="<?=gettext("Save"); ?>" />
1133
							<input type="button" class="formbtn" value="<?=gettext("Cancel");?>" onclick="window.location.href='<?=$referer;?>'" />
1134
							<?php if (isset($id) && $a_schedules[$id]): ?>
1135
							<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
1136
							<?php endif; ?>
1137
						</td>
1138
					</tr>
1139
				</table>
1140
			</td>
1141
		</tr>
1142
	</table>
1143
</form>
1144
<?php include("fend.inc"); ?>
1145
</body>
1146
</html>
(74-74/252)