Project

General

Profile

Download (38.4 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	firewall_schedule_edit.php
4
	Copyright (C) 2004 Scott Ullrich
5
	All rights reserved.
6

    
7
	originially part of m0n0wall (http://m0n0.ch/wall)
8
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
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
	pfSense_MODULE:	schedules
34
*/
35

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

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

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

    
50
        if (!is_array($config['schedules']['schedule']))
51
                return;
52

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

    
56
require("guiconfig.inc");
57
require_once("functions.inc");
58
require_once("filter.inc");
59
require_once("shaper.inc");
60

    
61
$pgtitle = array(gettext("Firewall"),gettext("Schedules"),gettext("Edit"));
62

    
63
$starttimehr = 00;
64
$starttimemin = 00;
65

    
66
$stoptimehr = 23;
67
$stoptimemin = 59;
68

    
69
$dayArray = array (gettext('Mon'),gettext('Tues'),gettext('Wed'),gettext('Thur'),gettext('Fri'),gettext('Sat'),gettext('Sun'));
70
$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'));
71

    
72
if (!is_array($config['schedules']['schedule']))
73
	$config['schedules']['schedule'] = array();
74

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

    
77

    
78
$id = $_GET['id'];
79
if (isset($_POST['id']))
80
	$id = $_POST['id'];
81

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

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

    
99
	$x = is_validaliasname($_POST['name']);
100
	if (!isset($x)) {
101
		$input_errors[] = gettext("Reserved word used for schedule name.");
102
	} else {
103
		if (is_validaliasname($_POST['name']) == false)
104
			$input_errors[] = gettext("The schedule name may only consist of the characters a-z, A-Z, 0-9");
105
	}
106
	
107
	/* check for name conflicts */
108
	foreach ($a_schedules as $schedule) {
109
		if (isset($id) && ($a_schedules[$id]) && ($a_schedules[$id] === $schedule))
110
			continue;
111

    
112
		if ($schedule['name'] == $_POST['name']) {
113
			$input_errors[] = gettext("A Schedule with this name already exists.");
114
			break;
115
		}
116
	}
117
	$schedule = array();
118
	
119
	$schedule['name'] = $_POST['name'];
120
	$schedule['descr'] = htmlentities($_POST['descr'], ENT_QUOTES, 'UTF-8');	
121
	
122
	$timerangeFound = false;
123
	for ($x=0; $x<99; $x++){
124
		if($_POST['schedule' . $x]) {
125
			$timerangeFound = true;
126
			$timeparts = array();
127
			$firstprint = false;
128
			$timestr = $_POST['schedule' . $x];
129
			$timehourstr = $_POST['starttime' . $x];
130
			$timehourstr .= "-";
131
			$timehourstr .= $_POST['stoptime' . $x];
132
			$timedescrstr = htmlentities($_POST['timedescr' . $x], ENT_QUOTES, 'UTF-8'); 
133
			$dashpos = strpos($timestr, '-');
134
			if ($dashpos === false)
135
			{
136
				$timeparts['position'] = $timestr;
137
			}
138
			else
139
			{
140
				$tempindarray = array();
141
				$monthstr = "";
142
				$daystr = "";
143
				$tempindarray = explode(",", $timestr);
144
				foreach ($tempindarray as $currentselection)
145
				{
146
					if ($currentselection){
147
						if ($firstprint)
148
						{
149
							$monthstr .= ",";
150
							$daystr .= ",";						
151
						}
152
						$tempstr = "";
153
						$monthpos = strpos($currentselection, "m");
154
						$daypos = strpos($currentselection, "d");
155
						$monthstr .= substr($currentselection, $monthpos+1, $daypos-$monthpos-1);
156
						$daystr .=  substr($currentselection, $daypos+1);			
157
						$firstprint = true;
158
					}
159
				}
160
				$timeparts['month'] = $monthstr;
161
				$timeparts['day'] = $daystr;
162
			}			
163
			$timeparts['hour'] = $timehourstr;
164
			$timeparts['rangedescr'] = $timedescrstr;
165
			$schedule['timerange'][$x] = $timeparts;
166
		}
167
	}
168
	
169
	if (!$timerangeFound)
170
		$input_errors[] = gettext("The schedule must have at least one time range configured.");
171
		
172
	if (!$input_errors) {		
173
		
174
		if (!empty($pconfig['schedlabel']))
175
			$schedule['schedlabel'] = $pconfig['schedlabel'];
176
		else
177
			$schedule['schedlabel'] = uniqid();
178

    
179
		if (isset($id) && $a_schedules[$id]){
180
			$a_schedules[$id] = $schedule;
181
		}
182
		else{
183
			$a_schedules[] = $schedule;
184
		}
185
		schedule_sort();
186
		write_config();
187
		
188
		filter_configure();
189
			
190
		header("Location: firewall_schedule.php");
191
		exit;
192
		
193
	}
194
	//we received input errors, copy data to prevent retype
195
	else
196
	{
197
		if (!$_POST['schedule0'])
198
			$getSchedule = false;
199
		else
200
			$getSchedule = true;
201
		$pconfig['name'] = $schedule['name'];
202
		$pconfig['descr'] = $schedule['descr'];
203
		$pconfig['timerange'] = $schedule['timerange'];
204
	}	
205

    
206
}
207
include("head.inc");
208

    
209
/* put your custom HTML head content here        */
210
/* using some of the $pfSenseHead function calls */
211
$jscriptstr = <<<EOD
212
<script type="text/javascript">
213

    
214
var daysSelected = "";
215
var month_array = ['January','February','March','April','May','June','July','August','September','October','November','December'];
216
var day_array = ['Mon','Tues','Wed','Thur','Fri','Sat','Sun'];
217
var schCounter = 0;
218

    
219

    
220

    
221
function repeatExistingDays(){
222
	var tempstr, tempstrdaypos, week, daypos, dayposdone = "";
223
	
224
	var dayarray = daysSelected.split(",");
225
	for (i=0; i<=dayarray.length; i++){
226
		tempstr = dayarray[i];
227
		tempstrdaypos = tempstr.search("p");
228
		week = tempstr.substring(1,tempstrdaypos);
229
		week = parseInt(week);
230
		dashpos = tempstr.search("-");		
231
		daypos = tempstr.substring(tempstrdaypos+1, dashpos);
232
		daypos = parseInt(daypos);
233
		
234
		daydone = dayposdone.search(daypos);
235
		tempstr = 'w' + week + 'p' + daypos;
236
		daycell = eval('document.getElementById(tempstr)');
237
		if (daydone == "-1"){
238
			if (daycell.style.backgroundColor == "lightcoral")
239
				daytogglerepeating(week,daypos,true);
240
			else
241
				daytogglerepeating(week,daypos,false);
242
			dayposdone += daypos + ",";
243
		}
244
	}	
245
}
246

    
247
function daytogglerepeating(week,daypos,bExists){
248
	var tempstr, daycell, dayoriginal = "";
249
	for (j=1; j<=53; j++)
250
	{						
251
		tempstr = 'w' + j + 'p' + daypos;
252
		daycell = eval('document.getElementById(tempstr)');
253
		dayoriginalpos =  daysSelected.indexOf(tempstr);
254
		
255
		//if bExists set to true, means cell is already select it
256
		//unselect it and remove original day from daysSelected string		
257
	
258
		if (daycell != null)
259
		{
260
			if (bExists){	
261
				daycell.style.backgroundColor = "WHITE";
262
			}
263
			else
264
			{
265
				daycell.style.backgroundColor = "lightcoral";		
266
			}	
267
	
268
			if (dayoriginalpos != "-1")
269
			{						
270
				dayoriginalend = daysSelected.indexOf(',', dayoriginalpos);
271
				tempstr = daysSelected.substring(dayoriginalpos, dayoriginalend+1);
272
				daysSelected = daysSelected.replace(tempstr, "");
273
				
274
			}				
275
		}			
276
	}	
277
}
278
	
279
function daytoggle(id) {
280
	var runrepeat, tempstr = "";
281
	var bFoundValid = false;
282
	
283
	iddashpos = id.search("-");
284
	var tempstrdaypos = id.search("p");
285
	var week = id.substring(1,tempstrdaypos);
286
	week = parseInt(week);
287
	
288
	if (iddashpos == "-1")
289
	{
290
		idmod = id;
291
		runrepeat = true;
292
		var daypos = id.substr(tempstrdaypos+1);	
293
	}
294
	else
295
	{		
296
		idmod = id.substring(0,iddashpos);
297
		var daypos = id.substring(tempstrdaypos+1,iddashpos);
298
	}
299
	
300
	daypos = parseInt(daypos);
301
	
302
	while (!bFoundValid){
303
		var daycell = document.getElementById(idmod);		
304
	
305
		if (daycell != null){
306
			if (daycell.style.backgroundColor == "RED"){
307
				daycell.style.backgroundColor = "WHITE";
308
				str = id + ",";
309
				daysSelected = daysSelected.replace(str, "");
310
			}
311
			else if (daycell.style.backgroundColor == "lightcoral")
312
			{
313
				daytogglerepeating(week,daypos,true);
314
			}
315
			else //color is white cell
316
			{
317
				if (!runrepeat)
318
				{
319
					daycell.style.backgroundColor = "RED";
320
				}
321
				else
322
				{
323
					daycell.style.backgroundColor = "lightcoral";
324
					daytogglerepeating(week,daypos,false);								
325
				}
326
				daysSelected += id + ",";
327
			}
328
			bFoundValid = true;
329
		}
330
		else
331
		{
332
			//we found an invalid cell when column was clicked, move up to the next week
333
			week++;
334
			tempstr = "w" + week + "p" + daypos;
335
			idmod = tempstr;			
336
		}
337
	}
338
}
339

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

    
344
	for (i=0; i<=11; i++){
345
		option = document.forms[0].monthsel.options[i].text;
346
		document.popupMonthLayer = eval('document.getElementById (option)');
347
		
348
		if(selected == option) {
349
			document.popupMonthLayer.style.display="block";
350
		}
351
		else
352
			document.popupMonthLayer.style.display="none";
353
	}
354
}
355

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

    
368
function processEntries(){
369
	var tempstr, starttimehour, starttimemin, stoptimehour, stoptimemin, errors = "";
370
	var passedValidiation = true;
371
	
372
	//get time specified
373
	starttimehour = parseInt(document.getElementById("starttimehour").value);
374
	starttimemin = parseInt(document.getElementById("starttimemin").value);
375
	stoptimehour = parseInt(document.getElementById("stoptimehour").value);
376
	stoptimemin = parseInt(document.getElementById("stoptimemin").value);
377

    
378

    
379
	//do time checks	
380
	if (starttimehour > stoptimehour)
381
	{
382
		errors = "Error: Start Hour cannot be greater than Stop Hour.";
383
		passedValidiation = false;
384
		
385
	}
386
	else if (starttimehour == stoptimehour)
387
	{
388
		if (starttimemin > stoptimemin){
389
			errors = "Error: Start Minute cannot be greater than Stop Minute.";
390
			passedValidiation = false;
391
		}
392
	}	
393
		
394
	if (passedValidiation){
395
		addTimeRange();
396
	}
397
	else {
398
		if (errors != "")
399
			alert(errors);
400
	}
401
}
402

    
403
function addTimeRange(){
404
	var tempdayarray = daysSelected.split(",");
405
	var tempstr, tempFriendlyDay, starttimehour, starttimemin, stoptimehour, nrtempFriendlyTime, rtempFriendlyTime, nrtempID, rtempID = "";
406
	var stoptimemin, timeRange, tempstrdaypos, week, daypos, day, month, dashpos, nrtempTime, rtempTime, monthstr, daystr = "";
407
	rtempFriendlyTime = "";
408
	nrtempFriendlyTime = "";
409
	nrtempID = "";
410
	rtempID = "";
411
	nrtempTime = "";
412
	rtempTime = "";
413
	tempdayarray.sort();	
414
	rtempFriendlyDay = "";
415
	monthstr = "";
416
	daystr = "";
417
	
418
	//check for existing entries
419
	var findCurrentCounter;
420
	for (u=0; u<99; u++){
421
		findCurrentCounter = document.getElementById("schedule" + u);
422
		if (!findCurrentCounter)
423
		{
424
			schCounter = u;
425
			break;
426
		}
427
	}
428
		
429
	if (daysSelected != ""){
430
		//get days selected
431
		for (i=0; i<tempdayarray.length; i++)
432
		{
433
			tempstr = tempdayarray[i];
434
			if (tempstr != "")
435
			{			
436
				tempstrdaypos = tempstr.search("p");
437
				week = tempstr.substring(1,tempstrdaypos);
438
				week = parseInt(week);
439
				dashpos = tempstr.search("-");			
440
				
441
				if (dashpos != "-1")
442
				{	
443
					var nonrepeatingfound = true;
444
					daypos = tempstr.substring(tempstrdaypos+1, dashpos);
445
					daypos = parseInt(daypos);	
446
					monthpos = tempstr.search("m");	
447
					tempstrdaypos = tempstr.search("d");
448
					month = tempstr.substring(monthpos+1, tempstrdaypos);
449
					month = parseInt(month);
450
					day = tempstr.substring(tempstrdaypos+1);
451
					day = parseInt(day);
452
					monthstr += month + ",";
453
					daystr += day + ",";
454
					nrtempID += tempstr + ",";
455
				}
456
				else
457
				{	
458
					var repeatingfound = true;
459
					daypos = tempstr.substr(tempstrdaypos+1);
460
					daypos = parseInt(daypos);	
461
					rtempFriendlyDay += daypos + ",";
462
					rtempID += daypos + ",";					
463
				}		
464
			}				
465
		}	
466
		
467
		//code below spits out friendly look format for nonrepeating schedules
468
		var foundEnd = false;
469
		var firstDayFound = false;
470
		var firstprint = false;
471
		var tempFriendlyMonthArray = monthstr.split(",");
472
		var tempFriendlyDayArray = daystr.split(",");
473
		var currentDay, firstDay, nextDay, currentMonth, nextMonth, firstDay, firstMonth = "";
474
		for (k=0; k<tempFriendlyMonthArray.length; k++){
475
			tempstr = tempFriendlyMonthArray[k];
476
			if (tempstr != ""){
477
				if (!firstDayFound)
478
				{
479
					firstDay = tempFriendlyDayArray[k];
480
					firstDay = parseInt(firstDay);
481
					firstMonth = tempFriendlyMonthArray[k];
482
					firstMonth = parseInt(firstMonth);
483
					firstDayFound = true;
484
				}
485
				currentDay = tempFriendlyDayArray[k];
486
				currentDay = parseInt(currentDay);
487
				//get next day
488
				nextDay = tempFriendlyDayArray[k+1];
489
				nextDay = parseInt(nextDay);
490
				//get next month
491
				
492
				currentDay++;						
493
				if ((currentDay != nextDay) || (tempFriendlyMonthArray[k] != tempFriendlyMonthArray[k+1])){
494
					if (firstprint)
495
						nrtempFriendlyTime += ", ";
496
					currentDay--;
497
					if (currentDay != firstDay)
498
						nrtempFriendlyTime += month_array[firstMonth-1] + " " + firstDay + "-" + currentDay;
499
					else
500
						nrtempFriendlyTime += month_array[firstMonth-1] + " " + currentDay; 
501
					firstDayFound = false;	
502
					firstprint = true;			
503
				}
504
			}			
505
		}		
506
		
507
		//code below spits out friendly look format for repeating schedules
508
		foundEnd = false;
509
		firstDayFound = false;
510
		firstprint = false;
511
		tempFriendlyDayArray = rtempFriendlyDay.split(",");
512
		tempFriendlyDayArray.sort();
513
		currentDay, firstDay, nextDay = "";
514
		for (k=0; k<tempFriendlyDayArray.length; k++){
515
			tempstr = tempFriendlyDayArray[k];
516
			if (tempstr != ""){
517
				if (!firstDayFound)
518
				{
519
					firstDay = tempFriendlyDayArray[k];
520
					firstDay = parseInt(firstDay);
521
					firstDayFound = true;
522
				}
523
				currentDay = tempFriendlyDayArray[k];
524
				currentDay = parseInt(currentDay);
525
				//get next day
526
				nextDay = tempFriendlyDayArray[k+1];
527
				nextDay = parseInt(nextDay);
528
				currentDay++;					
529
				if (currentDay != nextDay){
530
					if (firstprint)
531
						rtempFriendlyTime += ", ";
532
					currentDay--;
533
					if (currentDay != firstDay)
534
						rtempFriendlyTime += day_array[firstDay-1] + " - " + day_array[currentDay-1];
535
					else
536
						rtempFriendlyTime += day_array[firstDay-1];
537
					firstDayFound = false;	
538
					firstprint = true;			
539
				}
540
			}
541
		}			
542
		
543
		//sort the tempID
544
		var tempsortArray = rtempID.split(",");
545
		var isFirstdone = false;
546
		tempsortArray.sort();
547
		//clear tempID
548
		rtempID = "";
549
		for (t=0; t<tempsortArray.length; t++)
550
		{
551
			if (tempsortArray[t] != ""){
552
				if (!isFirstdone){
553
					rtempID += tempsortArray[t];
554
					isFirstdone = true;
555
				}
556
				else
557
					rtempID += "," + tempsortArray[t];
558
			}
559
		} 
560
		
561
		 
562
		//get time specified
563
		starttimehour =  document.getElementById("starttimehour").value
564
		starttimemin = document.getElementById("starttimemin").value;
565
		stoptimehour = document.getElementById("stoptimehour").value;
566
		stoptimemin = document.getElementById("stoptimemin").value;
567
		
568
		timeRange = "||" + starttimehour + ":";
569
		timeRange += starttimemin + "-";
570
		timeRange += stoptimehour + ":";	
571
		timeRange += stoptimemin;		
572
				
573
		//get description for time range
574
		var tempdescr = document.getElementById("timerangedescr").value		
575
		
576
		if (nonrepeatingfound){
577
			nrtempTime += nrtempID;
578
			//add time ranges
579
			nrtempTime += timeRange;			
580
			//add description
581
			nrtempTime += "||" + tempdescr;
582
			insertElements(nrtempFriendlyTime, starttimehour, starttimemin, stoptimehour, stoptimemin, tempdescr, nrtempTime, nrtempID);
583
		}
584
		
585
		if (repeatingfound){
586
			rtempTime += rtempID;
587
			//add time ranges
588
			rtempTime += timeRange;
589
			//add description
590
			rtempTime += "||" + tempdescr;
591
			insertElements(rtempFriendlyTime, starttimehour, starttimemin, stoptimehour, stoptimemin, tempdescr, rtempTime, rtempID);
592
		}
593
		
594
	}
595
	else
596
	{
597
		//no days were selected, alert user
598
		alert ("You must select at least 1 day before adding time");
599
	}
600
}
601

    
602
function insertElements(tempFriendlyTime, starttimehour, starttimemin, stoptimehour, stoptimemin, tempdescr, tempTime, tempID){
603
	
604
		//add it to the schedule list
605
		d = document;
606
		tbody = d.getElementById("scheduletable").getElementsByTagName("tbody").item(0);
607
		tr = d.createElement("tr");
608
		td = d.createElement("td");
609
		td.innerHTML= "<span class='vexpl'>" + tempFriendlyTime + "</span>";
610
		tr.appendChild(td);	
611
			
612
		td = d.createElement("td");
613
		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 + "'>";
614
		tr.appendChild(td);
615
		
616
		td = d.createElement("td");
617
		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 + "'>";
618
		tr.appendChild(td);
619
		
620
		td = d.createElement("td");
621
		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 + "'>";
622
		tr.appendChild(td);
623
		
624
		td = d.createElement("td");
625
		td.innerHTML = "<a onclick='editRow(\"" + tempTime + "\",this); return false;' href='#'><img border='0' src='/themes/" + theme + "/images/icons/icon_e.gif' /></a>";
626
		tr.appendChild(td);
627
			
628
		td = d.createElement("td");
629
		td.innerHTML = "<a onclick='removeRow(this); return false;' href='#'><img border='0' src='/themes/" + theme + "/images/icons/icon_x.gif' /></a>";
630
		tr.appendChild(td);
631
		
632
		td = d.createElement("td");		
633
		td.innerHTML="<input type='hidden' id='schedule" + schCounter + "' name='schedule" + schCounter + "' value='" + tempID + "'>";		
634
		tr.appendChild(td);
635
		tbody.appendChild(tr);
636
		
637
		schCounter++;
638
		
639
		//reset calendar and time and descr
640
		clearCalendar();
641
		clearTime();
642
		clearDescr();
643
}
644

    
645

    
646
function clearCalendar(){
647
	var tempstr, daycell = "";
648
	//clear days selected
649
	daysSelected = "";
650
	//loop through all 52 weeks
651
	for (j=1; j<=53; j++)
652
	{
653
		//loop through all 7 days
654
		for (k=1; k<8; k++){
655
			tempstr = 'w' + j + 'p' + k;
656
			daycell = eval('document.getElementById(tempstr)');
657
			if (daycell != null){
658
				daycell.style.backgroundColor = "WHITE";	
659
			}	
660
		}
661
	}	
662
}
663

    
664
function clearTime(){
665
	document.getElementById("starttimehour").value = $starttimehr;
666
	document.getElementById("starttimemin").value = $starttimemin;
667
	document.getElementById("stoptimehour").value = $stoptimehr;
668
	document.getElementById("stoptimemin").value = $stoptimemin;
669
}
670

    
671
function clearDescr(){
672
	document.getElementById("timerangedescr").value = "";
673
}
674

    
675
function editRow(incTime, el) {
676
	var check = checkForRanges();
677
	
678
	if (check){  
679
		
680
		//reset calendar and time
681
		clearCalendar();
682
		clearTime();
683
		
684
		var starttimehour, descr, days, tempstr, starttimemin, hours, stoptimehour, stoptimemin = ""; 
685
		
686
		tempArray = incTime.split ("||");
687
		
688
		days = tempArray[0];
689
		hours = tempArray[1];
690
		descr = tempArray[2];
691
		
692
		var tempdayArray = days.split(",");
693
		var temphourArray = hours.split("-");
694
		tempstr = temphourArray[0];
695
		var temphourArray2 = tempstr.split(":");
696
	
697
		document.getElementById("starttimehour").value = temphourArray2[0];
698
		document.getElementById("starttimemin").value = temphourArray2[1];	
699
		
700
		tempstr = temphourArray[1];
701
		temphourArray2 = tempstr.split(":");
702
		
703
		document.getElementById("stoptimehour").value = temphourArray2[0];
704
		document.getElementById("stoptimemin").value = temphourArray2[1];
705
		
706
		document.getElementById("timerangedescr").value = descr;
707
	
708
		//toggle the appropriate days
709
		for (i=0; i<tempdayArray.length; i++)
710
		{
711
			if (tempdayArray[i]){
712
				var tempweekstr = tempdayArray[i];
713
				dashpos = tempweekstr.search("-");			
714
						
715
				if (dashpos == "-1")
716
				{
717
					tempstr = "w2p" + tempdayArray[i];
718
				}
719
				else
720
				{
721
					tempstr = tempdayArray[i];
722
				}
723
				daytoggle(tempstr);
724
			}
725
		}
726
		removeRownoprompt(el);
727
	}
728
}
729

    
730
function removeRownoprompt(el) {
731
    var cel;
732
    while (el && el.nodeName.toLowerCase() != "tr")
733
	    el = el.parentNode;
734

    
735
    if (el && el.parentNode) {
736
	cel = el.getElementsByTagName("td").item(0);
737
	el.parentNode.removeChild(el);
738
    }
739
}
740

    
741

    
742
function removeRow(el) {
743
	var check = confirm ("Do you really want to delete this time range?");
744
	if (check){
745
	    var cel;
746
	    while (el && el.nodeName.toLowerCase() != "tr")
747
		    el = el.parentNode;
748
	
749
	    if (el && el.parentNode) {
750
		cel = el.getElementsByTagName("td").item(0);
751
		el.parentNode.removeChild(el);
752
	    }
753
	}
754
}
755

    
756
</script>
757
EOD;
758
?>
759

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

    
762

    
763
<?php include("fbegin.inc");	echo $jscriptstr; ?>
764
<?php if ($input_errors) print_input_errors($input_errors); ?>
765
<div id="inputerrors"></div>
766

    
767
<form action="firewall_schedule_edit.php" method="post" name="iform" id="iform">
768
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
769
		<tr>
770
			<td colspan="2" valign="top" class="listtopic"><?=gettext("Schedule information");?></td>
771
		</tr>	
772
        <tr>
773
          <td>
774
			  <table width="100%" border="0" cellpadding="6" cellspacing="0">
775
               	<tr>
776
				  <td width="15%" valign="top" class="vncellreq"><?=gettext("Schedule Name");?></td>
777
				  <td width="85%" class="vtable">
778
				  <?php if(is_schedule_inuse($pconfig['name']) == true): ?>
779
				  			<input name="name" type="hidden" id="name" size="40"  value="<?=htmlspecialchars($pconfig['name']);?>" />
780
						  <?php echo $pconfig['name']; ?>
781
						      <p>
782
						        <span class="vexpl"><?=gettext("NOTE: This schedule is in use so the name may not be modified!");?></span>
783
						      </p>
784
				<?php else: ?>
785
				  <input name="name" type="text" id="name" size="40" maxlength="40" class="formfld unknown" value="<?=htmlspecialchars($pconfig['name']);?>"><br>
786
				      	<span class="vexpl">
787
     					   <?=gettext("The name of the alias may only consist of the characters a-z, A-Z and 0-9");?>
788
      					</span>
789
      			<?php endif; ?>   					
790
				  </td>
791
				</tr>
792
				<tr>
793
					<td width="15%" valign="top" class="vncell"><?=gettext("Description");?></td>
794
					<td width="85%" class="vtable"><input name="descr" type="text" id="descr" size="40" maxlength="40" class="formfld unknown" value="<?=htmlspecialchars($pconfig['descr']);?>"><br>
795
 						<span class="vexpl">
796
				        	<?=gettext("You may enter a description here for your reference (not parsed).");?>
797
				      	</span>
798
				  
799
					</td>
800
				</tr>
801
				<tr>
802
				</tr>
803
			    <tr>
804
				  <td width="15%" valign="top" class="vncellreq"><?=gettext("Month");?></td>
805
				  <td width="85%" class="vtable">
806
                    <select name="monthsel" class="formselect" id="monthsel" onchange="update_month();">
807
                    	<?php 
808
                    	$monthcounter = date("n");
809
                    	$monthlimit = $monthcounter + 12;
810
                    	$yearcounter = date("Y");
811
                    	for ($k=0; $k<12; $k++){?>	             
812
                    		<option value="<?php echo $monthcounter;?>"><?php echo date("F y", mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter)));?></option>
813
                          <?php        	
814
                          if ($monthcounter == 12)
815
							{
816
								$monthcounter = 1;
817
								$yearcounter++;
818
							}
819
							else
820
							{
821
								$monthcounter++;
822
							}	
823
						} ?>      	
824
                    </select><br><br>
825
            		<?php
826
            		$firstmonth = TRUE;
827
            		$monthcounter = date("n");
828
            		$yearcounter = date("Y");
829
            		for ($k=0; $k<12; $k++){
830
						$firstdayofmonth = date("w", mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter)));
831
						if ($firstdayofmonth == 0)
832
							$firstdayofmonth = 7;
833
							
834
						$daycounter = 1;
835
						//number of day in month
836
						$numberofdays = date("t", mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter)));
837
						$firstdayprinted = FALSE;
838
						$lasttr = FALSE;
839
						$positioncounter = 1;//7 for Sun, 1 for Mon, 2 for Tues, etc						
840
						?>	
841
	                        <div id="<?php echo date("F y",mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter)));?>" z-index:-1000; style="position:relative; display:<?php if($firstmonth)echo "block";else echo "none";?>">    	
842
		                   	<TABLE BORDER=1 CELLSPACING=1 CELLPADDING=1 id="calTable" class="tabcont">
843
								<TR><TD COLSPAN="7" ALIGN=center class="listbg"><B><?php echo date("F Y", mktime(0, 0, 0, date($monthcounter), 1, date($yearcounter)));?></B></TD>
844
								</TR>							
845
								<TR>																
846
									<TD ALIGN=center class="listhdrr" style="cursor: pointer;" onClick="daytoggle('w1p1');"><u><b><?=gettext("Mon");?></b></u></TD>
847
									<TD ALIGN=center class="listhdrr" style="cursor: pointer;" onClick="daytoggle('w1p2');"><u><b><?=gettext("Tue");?></b></u></TD>
848
									<TD ALIGN=center class="listhdrr" style="cursor: pointer;" onClick="daytoggle('w1p3');"><u><b><?=gettext("Wed");?></b></u></TD>
849
									<TD ALIGN=center class="listhdrr" style="cursor: pointer;" onClick="daytoggle('w1p4');"><u><b><?=gettext("Thu");?></b></u></TD>
850
									<TD ALIGN=center class="listhdrr" style="cursor: pointer;" onClick="daytoggle('w1p5');"><u><b><?=gettext("Fri");?></b></u></TD>
851
									<TD ALIGN=center class="listhdrr" style="cursor: pointer;" onClick="daytoggle('w1p6');"><u><b><?=gettext("Sat");?></b></u></TD>
852
									<TD ALIGN=center class="listhdrr" style="cursor: pointer;" onClick="daytoggle('w1p7');"><u><b><?=gettext("Sun");?></b></u></TD>
853
								</TR>
854
								<?php			
855
								$firstmonth = FALSE;				
856
								while ($daycounter<=$numberofdays){
857
									$weekcounter =  date("W", mktime(0, 0, 0, date($monthcounter), date($daycounter), date($yearcounter)));
858
									$weekcounter = ltrim($weekcounter, "0");
859
									if ($positioncounter == 1)
860
									{
861
										echo "<tr>";
862
									}											
863
									if ($firstdayofmonth == $positioncounter){?>
864
										<TD ALIGN=center style="cursor: pointer;" class="listr" id="w<?=$weekcounter;?>p<?=$positioncounter;?>" onClick="daytoggle('w<?=$weekcounter;?>p<?=$positioncounter;?>-m<?=$monthcounter;?>d<?=$daycounter;?>');">
865
										<?php echo $daycounter;
866
										$daycounter++;
867
										$firstdayprinted = TRUE;
868
										echo "</td>";
869
									}
870
									elseif ($firstdayprinted == TRUE && $daycounter <= $numberofdays){?>
871
										<TD ALIGN=center style="cursor: pointer;" class="listr" id="w<?=$weekcounter;?>p<?=$positioncounter;?>" onClick="daytoggle('w<?=$weekcounter;?>p<?=$positioncounter;?>-m<?=$monthcounter;?>d<?=$daycounter;?>');">
872
										<?php echo $daycounter;
873
										$daycounter++;
874
										echo "</td>";
875
									}
876
									else
877
									{
878
										echo "<td align=center class=\"listr\"></td>";
879
									}
880
									
881
									if ($positioncounter ==7){
882
										$positioncounter = 1;
883
										echo "</tr>";
884
									}
885
									else{
886
										$positioncounter++;
887
									}
888
								
889
								}//end while loop?>	
890
							</TABLE>
891
							</div>
892
					<?php 
893
						
894
						if ($monthcounter == 12)
895
						{
896
							$monthcounter = 1;
897
							$yearcounter++;
898
						}
899
						else
900
						{
901
							$monthcounter++;
902
						}					
903
					} //end for loop
904
					?>
905
							<br/>
906
					<?=gettext("Click individual date to select that date only. Click the appropriate weekday Header to select all occurences of that weekday.");?>
907
	                 </td>
908
				</tr>
909
				<tr>
910
				  <td width="15%" valign="top" class="vncellreq"><?=gettext("Time");?></td>
911
				  <td width="85%" class="vtable">
912
				  	<table cellspacing=2 class="tabcont">
913
				  		<tr>
914
				  			<td class="listhdrr" align="center"><?=gettext("Start Time");?></td><td></td><td class="listhdrr" align="center"><?=gettext("Stop Time");?></td>
915
				  		</tr>
916
				  		<tr>
917
				  			<td>
918
				  				<select name="starttimehour" class="formselect" id="starttimehour">
919
				  					<?php 
920
				  						for ($i=0; $i<24; $i++)
921
				  						{				  							
922
				  							echo "<option value=\"$i\">";
923
				  							echo $i;
924
				  							echo "</option>";
925
				  						}
926
				  					?>
927
				  				</select>&nbsp;<?=gettext("Hr"); ?>&nbsp;&nbsp;
928
				  				<select name="starttimemin" class="formselect" id="starttimemin">
929
				  					<option value="00">00</option>
930
				  					<option value="15">15</option>
931
				  					<option value="30">30</option>
932
				  					<option value="45">45</option>
933
				  					<option value="59">59</option>
934
				  				</select>&nbsp;<?=gettext("Min"); ?>
935
				  			</td>
936
				  			<td></td>
937
				  			<td>
938
				  				<select name="stoptimehour" class="formselect" id="stoptimehour">
939
				  				<?php 
940
				  						for ($i=0; $i<24; $i++)
941
				  						{
942
				  							if ($i==23)
943
				  								$selected = "SELECTED";
944
				  							else
945
				  								$selected = "";
946
				  								
947
				  							echo "<option value=\"$i\" $selected>";
948
				  							echo $i;
949
				  							echo "</option>";
950
				  						}
951
				  					?>
952
				  				</select>&nbsp;<?=gettext("Hr");?>&nbsp;&nbsp;
953
				  				<select name="stoptimemin" class="formselect" id="stoptimemin">
954
				  					<option value="00">00</option>
955
				  					<option value="15">15</option>
956
				  					<option value="30">30</option>
957
				  					<option value="45">45</option>
958
				  					<option value="59" SELECTED>59</option>
959
				  				</select>&nbsp;<?=gettext("Min");?>
960
				  			</td>
961
				  		</tr>
962
				  	</table><br>
963
                   <?=gettext("Select the time range for the day(s) selected on the Month(s) above. A full day is 0:00-23:59.")?>
964
					</td>
965
				</tr>
966
				<tr>
967
					<td width="15%" valign="top" class="vncell"><?=gettext("Time Range Description")?></td>
968
					<td width="85%" class="vtable"><input name="timerangedescr" type="text" class="formfld unknown" id="timerangedescr" size="40" maxlength="40"><br>
969
 						<span class="vexpl">
970
				        	<?=gettext("You may enter a description here for your reference (not parsed).")?>
971
				      	</span>     
972
				      </td>					
973
				</tr>
974
				<tr>
975
				  <td width="22%" valign="top">&nbsp;</td>
976
				  <td width="78%">
977
				  	<input type="button" value="<?=gettext("Add Time");?>"  class="formbtn"  onclick="javascript:processEntries();">&nbsp;&nbsp;&nbsp;
978
				  	<input type="button" value="<?=gettext("Clear Selection");?>" class="formbtn" onclick="javascript:clearCalendar(); clearTime(); clearDescr();">
979
                    </td>
980
				</tr>
981
				<tr>
982
				  <td width="15%" valign="top" class="vtable"></td>
983
				  <td width="85%" class="vtable">
984
                    </td>
985
				</tr>
986
				<tr>
987
					<td colspan="2" valign="top" class="listtopic"><?=gettext("Schedule repeat");?></td>
988
				</tr>	
989
				<tr>
990
					<td width="15%" valign="top" class="vncellreq"><?=gettext("Configured Ranges");?></td>
991
					<td width="85%">
992
						<table id="scheduletable">
993
							<tbody>
994
								<tr>
995
									<TD ALIGN="center" class="listbg" width="35%"><?=gettext("Day(s)");?></td>
996
									<TD ALIGN="center" class="listbg" width="12%"><?=gettext("Start Time");?></td>
997
									<TD ALIGN="center" class="listbg" width="11%"><?=gettext("Stop Time");?></td>
998
									<TD ALIGN="center" class="listbg" width="42%"><?=gettext("Description");?></td>
999
								</tr>
1000
								<?php
1001
								if ($getSchedule){
1002
									$counter = 0;
1003
																		
1004
									foreach($pconfig['timerange'] as $timerange) {
1005
										$tempFriendlyTime = "";
1006
										$tempID = "";
1007
										if ($timerange){
1008
											$dayFriendly = "";
1009
											$tempFriendlyTime = "";
1010
											$timedescr = $timerange['rangedescr'];			
1011
												
1012
											//get hours
1013
											$temptimerange = $timerange['hour'];
1014
											$temptimeseparator = strrpos($temptimerange, "-");
1015
											
1016
											$starttime = substr ($temptimerange, 0, $temptimeseparator); 
1017
											$stoptime = substr ($temptimerange, $temptimeseparator+1); 
1018
											$currentDay = "";
1019
											$firstDay = "";
1020
											$nextDay = "";
1021
											$foundEnd = false;
1022
											$firstDayFound = false;
1023
											$firstPrint = false;	
1024
											$firstprint2 = false;
1025
											
1026
											if ($timerange['month']){
1027
												$tempmontharray = explode(",", $timerange['month']);
1028
												$tempdayarray = explode(",",$timerange['day']);
1029
												$arraycounter = 0;
1030
												foreach ($tempmontharray as $monthtmp){
1031
													$month = $tempmontharray[$arraycounter];
1032
													$day = $tempdayarray[$arraycounter];
1033
													$daypos = date("w", mktime(0, 0, 0, date($month), date($day), date("Y")));
1034
													//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.
1035
													if ($daypos == 0){
1036
														$daypos = 7;
1037
													}									
1038
													$weeknumber = date("W", mktime(0, 0, 0, date($month), date($day), date("Y")));
1039
													$weeknumber = ltrim($weeknumber, "0");		
1040
																										
1041
													if ($firstPrint)
1042
													{
1043
														$tempID .= ",";
1044
													}
1045
													$tempID .= "w" . $weeknumber . "p" . $daypos . "-m" .  $month . "d" . $day;
1046
													$firstPrint = true;
1047
													
1048
													if (!$firstDayFound)
1049
													{
1050
														$firstDay = $day;
1051
														$firstmonth = $month;
1052
														$firstDayFound = true;
1053
													}
1054
														
1055
													$currentDay = $day;
1056
													$nextDay = $tempdayarray[$arraycounter+1];
1057
													$currentDay++;
1058
													if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])){
1059
														if ($firstprint2)
1060
															$tempFriendlyTime .= ", ";
1061
														$currentDay--;
1062
														if ($currentDay != $firstDay)
1063
															$tempFriendlyTime .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
1064
														else
1065
															$tempFriendlyTime .=  $monthArray[$month-1] . " " . $day;
1066
														$firstDayFound = false;	
1067
														$firstprint2 = true;
1068
													}													
1069
													$arraycounter++;			
1070
												}																						
1071
												
1072
											}
1073
											else
1074
											{
1075
												$dayFriendly = $timerange['position'];
1076
												$tempID = $dayFriendly;
1077
											}											
1078
											
1079
											$tempTime = $tempID . "||" . $starttime . "-" . $stoptime . "||" . $timedescr;
1080
									
1081
											//following code makes the days friendly appearing, IE instead of Mon, Tues, Wed it will show Mon - Wed
1082
											$foundEnd = false;
1083
											$firstDayFound = false;
1084
											$firstprint = false;
1085
											$tempFriendlyDayArray = explode(",", $dayFriendly);
1086
											$currentDay = "";
1087
											$firstDay = "";
1088
											$nextDay = "";
1089
											$i = 0;
1090
											if (!$timerange['month']){										
1091
												foreach ($tempFriendlyDayArray as $day){
1092
													if ($day != ""){
1093
														if (!$firstDayFound)
1094
														{
1095
															$firstDay = $tempFriendlyDayArray[$i];
1096
															$firstDayFound = true;
1097
														}
1098
														$currentDay =$tempFriendlyDayArray[$i];
1099
														//get next day
1100
														$nextDay = $tempFriendlyDayArray[$i+1];
1101
														$currentDay++;					
1102
														if ($currentDay != $nextDay){
1103
															if ($firstprint)
1104
																$tempFriendlyTime .= ", ";
1105
															$currentDay--;
1106
															if ($currentDay != $firstDay)
1107
																$tempFriendlyTime .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
1108
															else
1109
																$tempFriendlyTime .= $dayArray[$firstDay-1];
1110
															$firstDayFound = false;	
1111
															$firstprint = true;			
1112
														}
1113
														$i++;
1114
													}
1115
												}		
1116
											}	
1117
												
1118
																																													
1119
									?>
1120
						          <tr>
1121
						          	<td>
1122
						          		<span class="vexpl"><?php echo $tempFriendlyTime; ?><span>
1123
						          	</td>
1124
									<td>
1125
						              <input type='text' 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; ?>'>
1126
							        </td>
1127
						            <td>
1128
						              <input type='text' 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; ?>'> 
1129
							        </td>
1130
							        <td>
1131
							        	<input type='text' 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; ?>'>
1132
							        </td>
1133
							        <td>
1134
							        	<a onclick='editRow("<?php echo $tempTime; ?>",this); return false;' href='#'><img border='0' src='/themes/<?php echo $g['theme']; ?>/images/icons/icon_e.gif' /></a>
1135
							        </td>
1136
							        <td>
1137
							        	<a onclick='removeRow(this); return false;' href='#'><img border='0' src='/themes/<?php echo $g['theme']; ?>/images/icons/icon_x.gif' /></a>
1138
							        </td>
1139
							        <td>
1140
							        	<input type='hidden' id='schedule<?php echo $counter; ?>' name='schedule<?php echo $counter; ?>' value='<?php echo $tempID; ?>'>
1141
							        </td>
1142
						          </tr>
1143
									<?php
1144
						        $counter++;
1145
									}//end if						
1146
						        } // end foreach	
1147
								}//end if							
1148
								?>
1149
							</tdody>	
1150
						</table>				
1151
					</td>
1152
				</tr>
1153
			 	<tr>
1154
				    <td width="15%" valign="top">&nbsp;</td>
1155
				    <td width="85%">
1156
				      <input id="submit" name="submit" type="submit" onclick="return checkForRanges();" class="formbtn" value="<?=gettext("Save"); ?>" />
1157
				      <input id="cancelbutton" name="cancelbutton" type="button" class="formbtn" value="<?=gettext("Cancel"); ?>" onclick="history.back()" />
1158
				      <?php if (isset($id) && $a_schedules[$id]): ?>
1159
				      <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
1160
				      <?php endif; ?>
1161
				    </td>
1162
			  	</tr>
1163
			 </table>
1164
		
1165
</td></tr></table></form>
1166
<?php include("fend.inc"); ?>
1167
</body>
1168
</html>
(70-70/245)