Project

General

Profile

Download (38.8 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
		if (write_config())
187
			filter_configure();
188

    
189
		header("Location: firewall_schedule.php");
190
		exit;
191
		
192
	}
193
	//we received input errors, copy data to prevent retype
194
	else
195
	{
196
		if (!$_POST['schedule0'])
197
			$getSchedule = false;
198
		else
199
			$getSchedule = true;
200
		$pconfig['name'] = $schedule['name'];
201
		$pconfig['descr'] = $schedule['descr'];
202
		$pconfig['timerange'] = $schedule['timerange'];
203
	}	
204

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

    
208
/* put your custom HTML head content here        */
209
/* using some of the $pfSenseHead function calls */
210
$jscriptstr = <<<EOD
211
<script type="text/javascript">
212
//<![CDATA[
213
var daysSelected = "";
214
var month_array = ['January','February','March','April','May','June','July','August','September','October','November','December'];
215
var day_array = ['Mon','Tues','Wed','Thur','Fri','Sat','Sun'];
216
var schCounter = 0;
217

    
218

    
219

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

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

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

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

    
355
function checkForRanges(){
356
	if (daysSelected != "")
357
	{
358
		alert("You have not saved the specified time range. Please click 'Add Time' button to save the time range.");
359
		return false;
360
	}
361
	else
362
	{
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
	{
381
		errors = "Error: Start Hour cannot be greater than Stop Hour.";
382
		passedValidiation = false;
383
		
384
	}
385
	else if (starttimehour == stoptimehour)
386
	{
387
		if (starttimemin > stoptimemin){
388
			errors = "Error: Start Minute cannot be greater than Stop Minute.";
389
			passedValidiation = false;
390
		}
391
	}	
392
		
393
	if (passedValidiation){
394
		addTimeRange();
395
	}
396
	else {
397
		if (errors != "")
398
			alert(errors);
399
	}
400
}
401

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

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

    
644

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

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

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

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

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

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

    
740

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

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

    
761

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

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