Projet

Général

Profil

Télécharger (39 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / firewall_schedule_edit.php @ 0fab7eb1

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

    
66
if (!is_array($config['schedules']['schedule']))
67
	$config['schedules']['schedule'] = array();
68

    
69
$a_schedules = &$config['schedules']['schedule'];
70

    
71
if (is_numericint($_GET['id']))
72
	$id = $_GET['id'];
73
if (isset($_POST['id']) && is_numericint($_POST['id']))
74
	$id = $_POST['id'];
75

    
76
if (isset($id) && $a_schedules[$id]) {
77
	$pconfig['name'] = $a_schedules[$id]['name'];
78
	$pconfig['descr'] = html_entity_decode($a_schedules[$id]['descr']);
79
	$pconfig['timerange'] = $a_schedules[$id]['timerange'];
80
	$pconfig['schedlabel'] = $a_schedules[$id]['schedlabel'];
81
	$getSchedule = true;
82
}
83

    
84
if ($_POST) {
85
	
86
	if(strtolower($_POST['name']) == "lan")
87
		$input_errors[] = gettext("Schedule may not be named LAN.");
88
	if(strtolower($_POST['name']) == "wan")
89
		$input_errors[] = gettext("Schedule may not be named WAN.");
90
	if(strtolower($_POST['name']) == "")
91
		$input_errors[] = gettext("Schedule name cannot be blank.");
92

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

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

    
173
		if (isset($id) && $a_schedules[$id]){
174
			$a_schedules[$id] = $schedule;
175
		}
176
		else{
177
			$a_schedules[] = $schedule;
178
		}
179
		schedule_sort();
180
		if (write_config())
181
			filter_configure();
182

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

    
199
}
200
include("head.inc");
201

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

    
212
function rgb2hex(rgb) {
213
	var parts = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
214
	if (parts == null)
215
		return;
216
	function hex(x) {
217
		return ("0" + parseInt(x).toString(16)).slice(-2);
218
	}
219
	return ("#" + hex(parts[1]) + hex(parts[2]) + hex(parts[3])).toUpperCase();
220
}
221

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

    
248
function daytogglerepeating(week,daypos,bExists){
249
	var tempstr, daycell, dayoriginal = "";
250
	for (j=1; j<=53; j++)
251
	{						
252
		tempstr = 'w' + j + 'p' + daypos;
253
		daycell = eval('document.getElementById(tempstr)');
254
		dayoriginalpos =  daysSelected.indexOf(tempstr);
255
		
256
		//if bExists set to true, means cell is already select it
257
		//unselect it and remove original day from daysSelected string		
258
	
259
		if (daycell != null)
260
		{
261
			if (bExists){	
262
				daycell.style.backgroundColor = "#FFFFFF";  // white
263
			}
264
			else
265
			{
266
				daycell.style.backgroundColor = "#F08080";  // lightcoral		
267
			}	
268
	
269
			if (dayoriginalpos != "-1")
270
			{						
271
				dayoriginalend = daysSelected.indexOf(',', dayoriginalpos);
272
				tempstr = daysSelected.substring(dayoriginalpos, dayoriginalend+1);
273
				daysSelected = daysSelected.replace(tempstr, "");
274
				
275
			}				
276
		}			
277
	}	
278
}
279

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

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

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

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

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

    
379

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

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

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

    
646

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

    
665
function clearTime(){
666
	document.getElementById("starttimehour").value = "0";
667
	document.getElementById("starttimemin").value = "00";
668
	document.getElementById("stoptimehour").value = "23";
669
	document.getElementById("stoptimemin").value = "59";
670
}
671

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

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

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

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

    
742

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

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

    
763

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

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