Project

General

Profile

Download (9.17 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	firewall_schedule.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
##|+PRIV
36
##|*IDENT=page-firewall-schedules
37
##|*NAME=Firewall: Schedules page
38
##|*DESCR=Allow access to the 'Firewall: Schedules' page.
39
##|*MATCH=firewall_schedule.php*
40
##|-PRIV
41

    
42

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

    
46
require("guiconfig.inc");
47
require("filter.inc");
48
require("shaper.inc");
49

    
50
$pgtitle = array(gettext("Firewall"),gettext("Schedules"));
51

    
52
if (!is_array($config['schedules']['schedule']))
53
	$config['schedules']['schedule'] = array();
54

    
55
$a_schedules = &$config['schedules']['schedule'];
56

    
57

    
58
if ($_GET['act'] == "del") {
59
	if ($a_schedules[$_GET['id']]) {
60
		/* make sure rule is not being referenced by any nat or filter rules */
61
		$is_schedule_referenced = false;
62
		$referenced_by = false;
63
		$schedule_name = $a_schedules[$_GET['id']]['name'];
64

    
65
		if(is_array($config['filter']['rule'])) {
66
			foreach($config['filter']['rule'] as $rule) {
67
				//check for this later once this is established
68
				if ($rule['sched'] == $schedule_name){
69
					$referenced_by = $rule['descr'];
70
					$is_schedule_referenced = true;
71
					break;
72
				}
73
			}
74
		}
75

    
76
		if($is_schedule_referenced == true) {
77
			$savemsg = sprintf(gettext("Cannot delete Schedule.  Currently in use by %s"),$referenced_by);
78
		} else {
79
			unset($a_schedules[$_GET['id']]);
80
			write_config();
81
			header("Location: firewall_schedule.php");
82
			exit;
83
		}
84
	}
85
}
86

    
87
include("head.inc");
88
?>
89

    
90
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
91
<?php include("fbegin.inc"); ?>
92
<?php if ($savemsg) print_info_box($savemsg); ?>
93
<form action="firewall_schedule.php" method="post">
94
	<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
95
	<tr>
96
	  <td width="25%" class="listhdrr"><?=gettext("Name");?></td>
97
	  <td width="35%" class="listhdrr"><?=gettext("Time Range(s)");?></td>
98
	  <td width="35%" class="listhdr"><?=gettext("Description");?></td>
99
	  <td width="5%" class="list sort_ignore">
100
	    <table border="0" cellspacing="0" cellpadding="1">
101
	      <tr>
102
		<td width="17"></td>
103
	        <td valign="middle"><a href="firewall_schedule_edit.php"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" title="<?=gettext("add a new schedule");?>" alt="" /></a></td>
104
	      </tr>
105
	    </table>
106
	  </td>
107
	</tr>
108
	<?php $i = 0; foreach ($a_schedules as $schedule): ?>
109
	<tr>
110
	   <td class="listlr" ondblclick="document.location='firewall_schedule_edit.php?id=<?=$i;?>';">
111
			<?=htmlspecialchars($schedule['name']); 
112
					$schedstatus = filter_get_time_based_rule_status($schedule);
113
					 if ($schedstatus) { ?>
114
					 	&nbsp;<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_frmfld_time.png" title="<?=gettext("Schedule is currently active");?>" width="17" height="17" border="0">
115
					 <?php } ?>
116
    
117
  		</td>
118
  		<td class="listlr" ondblclick="document.location='firewall_schedule_edit.php?id=<?=$i;?>';">
119
  			<table width="98%" border="0" cellpadding="0" cellspacing="0">
120
			<?php 
121
			
122
				foreach($schedule['timerange'] as $timerange) {
123
						$tempFriendlyTime = "";
124
						$tempID = "";
125
						$firstprint = false;
126
						if ($timerange){
127
							$dayFriendly = "";
128
							$tempFriendlyTime = "";							
129
								
130
							//get hours
131
							$temptimerange = $timerange['hour'];
132
							$temptimeseparator = strrpos($temptimerange, "-");
133
							
134
							$starttime = substr ($temptimerange, 0, $temptimeseparator); 
135
							$stoptime = substr ($temptimerange, $temptimeseparator+1); 
136
								
137
							if ($timerange['month']){
138
								$tempmontharray = explode(",", $timerange['month']);
139
								$tempdayarray = explode(",",$timerange['day']);
140
								$arraycounter = 0;
141
								$firstDayFound = false;
142
								$firstPrint = false;
143
								foreach ($tempmontharray as $monthtmp){
144
									$month = $tempmontharray[$arraycounter];
145
									$day = $tempdayarray[$arraycounter];
146
									
147
									if (!$firstDayFound)
148
									{
149
										$firstDay = $day;
150
										$firstmonth = $month;
151
										$firstDayFound = true;
152
									}
153
										
154
									$currentDay = $day;
155
									$nextDay = $tempdayarray[$arraycounter+1];
156
									$currentDay++;
157
									if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])){
158
										if ($firstPrint)
159
											$dayFriendly .= "<br/>";
160
										$currentDay--;
161
										if ($currentDay != $firstDay)
162
											$dayFriendly .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
163
										else
164
											$dayFriendly .=  $monthArray[$month-1] . " " . $day;
165
										$firstDayFound = false;	
166
										$firstPrint = true;
167
									}													
168
									$arraycounter++;	
169
								}
170
							}
171
							else
172
							{
173
								$tempdayFriendly = $timerange['position'];
174
								$firstDayFound = false;
175
								$tempFriendlyDayArray = explode(",", $tempdayFriendly);								
176
								$currentDay = "";
177
								$firstDay = "";
178
								$nextDay = "";
179
								$counter = 0;													
180
								foreach ($tempFriendlyDayArray as $day){
181
									if ($day != ""){
182
										if (!$firstDayFound)
183
										{
184
											$firstDay = $tempFriendlyDayArray[$counter];
185
											$firstDayFound = true;
186
										}
187
										$currentDay =$tempFriendlyDayArray[$counter];
188
										//get next day
189
										$nextDay = $tempFriendlyDayArray[$counter+1];
190
										$currentDay++;					
191
										if ($currentDay != $nextDay){
192
											if ($firstprint)
193
												$dayFriendly .= "<br/>";
194
											$currentDay--;
195
											if ($currentDay != $firstDay)
196
												$dayFriendly .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
197
											else
198
												$dayFriendly .= $dayArray[$firstDay-1];
199
											$firstDayFound = false;	
200
											$firstprint = true;			
201
										}
202
										$counter++;
203
									}
204
								}
205
							}		
206
							$timeFriendly = $starttime . "-" . $stoptime;
207
							$description = $timerange['rangedescr'];	
208
							
209
							?><tr><td><?echo $dayFriendly;?></td><td><?echo $timeFriendly;?></td><td><?echo $description;?></td><tr/><?php
210
						}
211
					}//end for?></table>
212
	  </td>
213
	 <td class="listbg" ondblclick="document.location='firewall_schedule_edit.php?id=<?=$i;?>';">
214
    		<?=htmlspecialchars($schedule['descr']);?>&nbsp;
215
  		</td>
216
  		  <td valign="middle" nowrap class="list">
217
    <table border="0" cellspacing="0" cellpadding="1">
218
      <tr>
219
        <td valign="middle"><a href="firewall_schedule_edit.php?id=<?=$i;?>"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0" title="<?=gettext("edit alias");?>"></a></td>
220
        <td><a href="firewall_schedule.php?act=del&id=<?=$i;?>" onclick="return confirm('<?=gettext('Do you really want to delete this schedule?');?>')"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0" title="<?=gettext("delete alias");?>"></a></td>
221
      </tr>
222
    </table>
223
  </td>
224
</tr>
225
<?php $i++; endforeach; ?>
226
<tr>
227
  <td class="list" colspan="3"></td>
228
  <td class="list">
229
    <table border="0" cellspacing="0" cellpadding="1">
230
      <tr>
231
	<td width="17"></td>
232
        <td valign="middle"><a href="firewall_schedule_edit.php"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" title="<?=gettext("add a new schedule");?>" alt="" /></a></td>
233
      </tr>
234
    </table>
235
  </td>
236
</tr>
237
<tr>
238
  <td class="tabcont" colspan="3">
239
   <p><span class="vexpl"><span class="red"><strong><?=gettext("Note");?>:<br></strong></span><?=gettext("Schedules act as placeholders for time ranges to be used in Firewall Rules.");?></span></p>
240
  </td>
241
</tr>
242
</table>
243

    
244
</form>
245

    
246
<?php include("fend.inc"); ?>
247
</body>
248
</html>
(59-59/222)