Project

General

Profile

Download (9.2 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	firewall_schedule.php
4
	Copyright (C) 2004 Scott Ullrich
5
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
6
	All rights reserved.
7

    
8
	originally part of m0n0wall (http://m0n0.ch/wall)
9
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
10
	All rights reserved.
11

    
12
	Redistribution and use in source and binary forms, with or without
13
	modification, are permitted provided that the following conditions are met:
14

    
15
	1. Redistributions of source code must retain the above copyright notice,
16
	   this list of conditions and the following disclaimer.
17

    
18
	2. Redistributions in binary form must reproduce the above copyright
19
	   notice, this list of conditions and the following disclaimer in the
20
	   documentation and/or other materials provided with the distribution.
21

    
22
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
23
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
24
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
	POSSIBILITY OF SUCH DAMAGE.
32
*/
33
/*
34
	pfSense_MODULE: schedules
35
*/
36
##|+PRIV
37
##|*IDENT=page-firewall-schedules
38
##|*NAME=Firewall: Schedules page
39
##|*DESCR=Allow access to the 'Firewall: Schedules' page.
40
##|*MATCH=firewall_schedule.php*
41
##|-PRIV
42

    
43

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

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

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

    
53
if (!is_array($config['schedules']['schedule'])) {
54
	$config['schedules']['schedule'] = array();
55
}
56

    
57
$a_schedules = &$config['schedules']['schedule'];
58

    
59

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

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

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

    
89
include("head.inc");
90
?>
91

    
92
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
93
<?php include("fbegin.inc"); ?>
94
<?php if ($savemsg) print_info_box($savemsg); ?>
95
<form action="firewall_schedule.php" method="post">
96
	<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="firewall schedule">
97
	<tr>
98
		<td width="25%" class="listhdrr"><?=gettext("Name");?></td>
99
		<td width="35%" class="listhdrr"><?=gettext("Time Range(s)");?></td>
100
		<td width="35%" class="listhdr"><?=gettext("Description");?></td>
101
		<td width="5%" class="list sort_ignore">
102
			<table border="0" cellspacing="0" cellpadding="1" summary="add">
103
				<tr>
104
					<td width="17"></td>
105
					<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="add" /></a></td>
106
				</tr>
107
			</table>
108
		</td>
109
	</tr>
110
	<?php $i = 0; foreach ($a_schedules as $schedule): ?>
111
	<tr>
112
		<td class="listlr" ondblclick="document.location='firewall_schedule_edit.php?id=<?=$i;?>';">
113
			<?=htmlspecialchars($schedule['name']);?>
114
			<?php
115
				$schedstatus = filter_get_time_based_rule_status($schedule);
116
				if ($schedstatus) { ?>
117
					&nbsp;<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_frmfld_time.png" title="<?=gettext("Schedule is currently active");?>" width="17" height="17" border="0" alt="schedule" />
118
			<?php } ?>
119
		</td>
120
		<td class="listlr" ondblclick="document.location='firewall_schedule_edit.php?id=<?=$i;?>';">
121
			<table width="98%" border="0" cellpadding="0" cellspacing="0" summary="schedule">
122
			<?php
123
				foreach ($schedule['timerange'] as $timerange) {
124
					$tempFriendlyTime = "";
125
					$tempID = "";
126
					$firstprint = false;
127
					if ($timerange) {
128
						$dayFriendly = "";
129
						$tempFriendlyTime = "";
130

    
131
						//get hours
132
						$temptimerange = $timerange['hour'];
133
						$temptimeseparator = strrpos($temptimerange, "-");
134

    
135
						$starttime = substr ($temptimerange, 0, $temptimeseparator);
136
						$stoptime = substr ($temptimerange, $temptimeseparator+1);
137

    
138
						if ($timerange['month']) {
139
							$tempmontharray = explode(",", $timerange['month']);
140
							$tempdayarray = explode(",",$timerange['day']);
141
							$arraycounter = 0;
142
							$firstDayFound = false;
143
							$firstPrint = false;
144
							foreach ($tempmontharray as $monthtmp) {
145
								$month = $tempmontharray[$arraycounter];
146
								$day = $tempdayarray[$arraycounter];
147

    
148
								if (!$firstDayFound) {
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
									}
161
									$currentDay--;
162
									if ($currentDay != $firstDay) {
163
										$dayFriendly .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
164
									} else {
165
										$dayFriendly .=  $monthArray[$month-1] . " " . $day;
166
									}
167
									$firstDayFound = false;
168
									$firstPrint = true;
169
								}
170
								$arraycounter++;
171
							}
172
						} else {
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
										$firstDay = $tempFriendlyDayArray[$counter];
184
										$firstDayFound = true;
185
									}
186
									$currentDay =$tempFriendlyDayArray[$counter];
187
									//get next day
188
									$nextDay = $tempFriendlyDayArray[$counter+1];
189
									$currentDay++;
190
									if ($currentDay != $nextDay) {
191
										if ($firstprint) {
192
											$dayFriendly .= "<br />";
193
										}
194
										$currentDay--;
195
										if ($currentDay != $firstDay) {
196
											$dayFriendly .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
197
										} else {
198
											$dayFriendly .= $dayArray[$firstDay-1];
199
										}
200
										$firstDayFound = false;
201
										$firstprint = true;
202
									}
203
									$counter++;
204
								}
205
							}
206
						}
207
						$timeFriendly = $starttime . "-" . $stoptime;
208
						$description = $timerange['rangedescr'];
209

    
210
			?>
211
				<tr>
212
					<td><?=$dayFriendly;?></td>
213
					<td><?=$timeFriendly;?></td>
214
					<td><?=$description;?></td>
215
				</tr>
216
			<?php
217
					}
218
				}//end for
219
			?>
220
			</table>
221
		</td>
222
		<td class="listbg" ondblclick="document.location='firewall_schedule_edit.php?id=<?=$i;?>';">
223
			<?=htmlspecialchars($schedule['descr']);?>&nbsp;
224
		</td>
225
		<td valign="middle" class="list nowrap">
226
			<table border="0" cellspacing="0" cellpadding="1" summary="buttons">
227
				<tr>
228
					<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");?>" alt="edit" /></a></td>
229
					<td><a href="firewall_schedule.php?act=del&amp;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");?>" alt="delete" /></a></td>
230
				</tr>
231
			</table>
232
		</td>
233
	</tr>
234
<?php $i++; endforeach; ?>
235
	<tr>
236
		<td class="list" colspan="3"></td>
237
		<td class="list">
238
			<table border="0" cellspacing="0" cellpadding="1" summary="add">
239
				<tr>
240
					<td width="17"></td>
241
					<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="add" /></a></td>
242
				</tr>
243
			</table>
244
		</td>
245
	</tr>
246
	<tr>
247
		<td class="tabcont" colspan="3">
248
			<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>
249
		</td>
250
	</tr>
251
</table>
252
</form>
253
<?php include("fend.inc"); ?>
254
</body>
255
</html>
(73-73/256)