Project

General

Profile

Download (39.2 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(year,week,daypos,bExists){
247
	var tempstr, daycell, dayoriginal = "";
248
	for (j=1; j<=53; j++)
249
	{						
250
		tempstr = 'y' + year +'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

    
284
	var tempstryearpos = id.search("y");
285
	var tempstrweekpos = id.search("w");
286
	var tempstrdaypos = id.search("p");
287

    
288
	var year = id.substring(tempstryearpos + 1,tempstrweekpos);
289
	year = parseInt(year);
290

    
291
	var week = id.substring(tempstrweekpos + 1,tempstrdaypos);
292
	week = parseInt(week);
293
	
294
	if (iddashpos == "-1")
295
	{
296
		idmod = id;
297
		runrepeat = true;
298
		var daypos = id.substr(tempstrdaypos+1);	
299
	}
300
	else
301
	{		
302
		idmod = id.substring(0,iddashpos);
303
		var daypos = id.substring(tempstrdaypos+1,iddashpos);
304
	}
305
	
306
	daypos = parseInt(daypos);
307
	
308
	while (!bFoundValid){
309
		var daycell = document.getElementById(idmod);		
310
	
311
		if (daycell != null){
312
			if (daycell.style.backgroundColor == "#FF0000"){  // red
313
				daycell.style.backgroundColor = "#FFFFFF";  // white
314
				str = id + ",";
315
				daysSelected = daysSelected.replace(str, "");
316
			}
317
			else if (daycell.style.backgroundColor == "#F08080")  // lightcoral
318
			{
319
				daytogglerepeating(year,week,daypos,true);
320
			}
321
			else //color is white cell
322
			{
323
				if (!runrepeat)
324
				{
325
					daycell.style.backgroundColor = "#FF0000";  // red
326
				}
327
				else
328
				{
329
					daycell.style.backgroundColor = "#F08080";  // lightcoral
330
					daytogglerepeating(year,week,daypos,false);								
331
				}
332
				daysSelected += id + ",";
333
			}
334
			bFoundValid = true;
335
		}
336
		else
337
		{
338
			//we found an invalid cell when column was clicked, move up to the next week
339
			week++;
340
			tempstr = "y" + year + "w" + week + "p" + daypos;
341
			idmod = tempstr;			
342
		}
343
	}
344
}
345

    
346
function update_month(){
347
	var indexNum = document.forms[0].monthsel.selectedIndex;
348
	var selected = document.forms[0].monthsel.options[indexNum].text;
349

    
350
	for (i=0; i<=11; i++){
351
		option = document.forms[0].monthsel.options[i].text;
352
		document.popupMonthLayer = eval('document.getElementById (option)');
353
		
354
		if(selected == option) {
355
			document.popupMonthLayer.style.display="block";
356
		}
357
		else
358
			document.popupMonthLayer.style.display="none";
359
	}
360
}
361

    
362
function checkForRanges(){
363
	if (daysSelected != "")
364
	{
365
		alert("You have not saved the specified time range. Please click 'Add Time' button to save the time range.");
366
		return false;
367
	}
368
	else
369
	{
370
		return true;
371
	}
372
}
373

    
374
function processEntries(){
375
	var tempstr, starttimehour, starttimemin, stoptimehour, stoptimemin, errors = "";
376
	var passedValidiation = true;
377
	
378
	//get time specified
379
	starttimehour = parseInt(document.getElementById("starttimehour").value);
380
	starttimemin = parseInt(document.getElementById("starttimemin").value);
381
	stoptimehour = parseInt(document.getElementById("stoptimehour").value);
382
	stoptimemin = parseInt(document.getElementById("stoptimemin").value);
383

    
384

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

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

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

    
651

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

    
670
function clearTime(){
671
	document.getElementById("starttimehour").value = $starttimehr;
672
	document.getElementById("starttimemin").value = $starttimemin;
673
	document.getElementById("stoptimehour").value = $stoptimehr;
674
	document.getElementById("stoptimemin").value = $stoptimemin;
675
}
676

    
677
function clearDescr(){
678
	document.getElementById("timerangedescr").value = "";
679
}
680

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

    
736
function removeRownoprompt(el) {
737
    var cel;
738
    while (el && el.nodeName.toLowerCase() != "tr")
739
	    el = el.parentNode;
740

    
741
    if (el && el.parentNode) {
742
	cel = el.getElementsByTagName("td").item(0);
743
	el.parentNode.removeChild(el);
744
    }
745
}
746

    
747

    
748
function removeRow(el) {
749
	var check = confirm ("Do you really want to delete this time range?");
750
	if (check){
751
	    var cel;
752
	    while (el && el.nodeName.toLowerCase() != "tr")
753
		    el = el.parentNode;
754
	
755
	    if (el && el.parentNode) {
756
		cel = el.getElementsByTagName("td").item(0);
757
		el.parentNode.removeChild(el);
758
	    }
759
	}
760
}
761
//]]>
762
</script>
763
EOD;
764
?>
765

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

    
768

    
769
<?php include("fbegin.inc");	echo $jscriptstr; ?>
770
<?php if ($input_errors) print_input_errors($input_errors); ?>
771
<div id="inputerrors"></div>
772

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