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
|
|
34
|
$pgtitle = "Firewall: Schedules";
|
35
|
|
36
|
$dayArray = array ('Mon','Tues','Wed','Thur','Fri','Sat','Sun');
|
37
|
$monthArray = array ('January','February','March','April','May','June','July','August','September','October','November','December');
|
38
|
|
39
|
require("guiconfig.inc");
|
40
|
|
41
|
if (!is_array($config['schedules']['schedule']))
|
42
|
$config['schedules']['schedule'] = array();
|
43
|
|
44
|
schedule_sort();
|
45
|
$a_schedules = &$config['schedules']['schedule'];
|
46
|
|
47
|
|
48
|
if ($_GET['act'] == "del") {
|
49
|
if ($a_schedules[$_GET['id']]) {
|
50
|
/* make sure rule is not being referenced by any nat or filter rules */
|
51
|
$is_schedule_referenced = false;
|
52
|
$referenced_by = false;
|
53
|
$schedule_name = $a_schedules[$_GET['id']]['name'];
|
54
|
|
55
|
if(is_array($config['filter']['rule'])) {
|
56
|
foreach($config['filter']['rule'] as $rule) {
|
57
|
//check for this later once this is established
|
58
|
if ($rule['sched'] == $schedule_name){
|
59
|
$referenced_by = $rule['descr'];
|
60
|
$is_schedule_referenced = true;
|
61
|
break;
|
62
|
}
|
63
|
}
|
64
|
}
|
65
|
|
66
|
if($is_schedule_referenced == true) {
|
67
|
$savemsg = "Cannot delete Schedule. Currently in use by {$referenced_by}";
|
68
|
} else {
|
69
|
unset($a_schedules[$_GET['id']]);
|
70
|
write_config();
|
71
|
header("Location: firewall_schedule.php");
|
72
|
exit;
|
73
|
}
|
74
|
}
|
75
|
}
|
76
|
|
77
|
include("head.inc");
|
78
|
?>
|
79
|
|
80
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
81
|
<?php include("fbegin.inc"); ?>
|
82
|
<p class="pgtitle"><?=$pgtitle?></p>
|
83
|
<?php if ($savemsg) print_info_box($savemsg); ?>
|
84
|
<form action="firewall_schedule.php" method="post">
|
85
|
<table class="sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
|
86
|
<tr>
|
87
|
<td width="25%" class="listhdrr">Name</td>
|
88
|
<td width="35%" class="listhdrr">Time Range(s)</td>
|
89
|
<td width="35%" class="listhdr">Description</td>
|
90
|
<td width="5%" class="list sort_ignore"></td>
|
91
|
</tr>
|
92
|
<?php $i = 0; foreach ($a_schedules as $schedule): ?>
|
93
|
<tr>
|
94
|
<td class="listlr" ondblclick="document.location='firewall_schedule_edit.php?id=<?=$i;?>';">
|
95
|
<?=htmlspecialchars($schedule['name']);
|
96
|
$schedstatus = get_time_based_rule_status($schedule);
|
97
|
if ($schedstatus) { ?>
|
98
|
<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_frmfld_time.png" title="Schedule is currently active" width="17" height="17" border="0">
|
99
|
<?php } ?>
|
100
|
|
101
|
</td>
|
102
|
<td class="listlr" ondblclick="document.location='firewall_schedule_edit.php?id=<?=$i;?>';">
|
103
|
<table width="98%" border="0" cellpadding="0" cellspacing="0">
|
104
|
<?php
|
105
|
|
106
|
foreach($schedule['timerange'] as $timerange) {
|
107
|
$tempFriendlyTime = "";
|
108
|
$tempID = "";
|
109
|
$firstprint = false;
|
110
|
if ($timerange){
|
111
|
$dayFriendly = "";
|
112
|
$tempFriendlyTime = "";
|
113
|
|
114
|
//get hours
|
115
|
$temptimerange = $timerange['hour'];
|
116
|
$temptimeseparator = strrpos($temptimerange, "-");
|
117
|
|
118
|
$starttime = substr ($temptimerange, 0, $temptimeseparator);
|
119
|
$stoptime = substr ($temptimerange, $temptimeseparator+1);
|
120
|
|
121
|
if ($timerange['month']){
|
122
|
$tempmontharray = explode(",", $timerange['month']);
|
123
|
$tempdayarray = explode(",",$timerange['day']);
|
124
|
$arraycounter = 0;
|
125
|
$firstDayFound = false;
|
126
|
$firstPrint = false;
|
127
|
foreach ($tempmontharray as $monthtmp){
|
128
|
$month = $tempmontharray[$arraycounter];
|
129
|
$day = $tempdayarray[$arraycounter];
|
130
|
|
131
|
if (!$firstDayFound)
|
132
|
{
|
133
|
$firstDay = $day;
|
134
|
$firstmonth = $month;
|
135
|
$firstDayFound = true;
|
136
|
}
|
137
|
|
138
|
$currentDay = $day;
|
139
|
$nextDay = $tempdayarray[$arraycounter+1];
|
140
|
$currentDay++;
|
141
|
if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])){
|
142
|
if ($firstPrint)
|
143
|
$dayFriendly .= "<br/>";
|
144
|
$currentDay--;
|
145
|
if ($currentDay != $firstDay)
|
146
|
$dayFriendly .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
|
147
|
else
|
148
|
$dayFriendly .= $monthArray[$month-1] . " " . $day;
|
149
|
$firstDayFound = false;
|
150
|
$firstPrint = true;
|
151
|
}
|
152
|
$arraycounter++;
|
153
|
}
|
154
|
}
|
155
|
else
|
156
|
{
|
157
|
$tempdayFriendly = $timerange['position'];
|
158
|
$firstDayFound = false;
|
159
|
$tempFriendlyDayArray = explode(",", $tempdayFriendly);
|
160
|
$currentDay = "";
|
161
|
$firstDay = "";
|
162
|
$nextDay = "";
|
163
|
$counter = 0;
|
164
|
foreach ($tempFriendlyDayArray as $day){
|
165
|
if ($day != ""){
|
166
|
if (!$firstDayFound)
|
167
|
{
|
168
|
$firstDay = $tempFriendlyDayArray[$counter];
|
169
|
$firstDayFound = true;
|
170
|
}
|
171
|
$currentDay =$tempFriendlyDayArray[$counter];
|
172
|
//get next day
|
173
|
$nextDay = $tempFriendlyDayArray[$counter+1];
|
174
|
$currentDay++;
|
175
|
if ($currentDay != $nextDay){
|
176
|
if ($firstprint)
|
177
|
$dayFriendly .= "<br/>";
|
178
|
$currentDay--;
|
179
|
if ($currentDay != $firstDay)
|
180
|
$dayFriendly .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
|
181
|
else
|
182
|
$dayFriendly .= $dayArray[$firstDay-1];
|
183
|
$firstDayFound = false;
|
184
|
$firstprint = true;
|
185
|
}
|
186
|
$counter++;
|
187
|
}
|
188
|
}
|
189
|
}
|
190
|
$timeFriendly = $starttime . "-" . $stoptime;
|
191
|
$description = $timerange['rangedescr'];
|
192
|
|
193
|
?><tr><td><?echo $dayFriendly;?></td><td><?echo $timeFriendly;?></td><td><?echo $description;?></td><tr/><?php
|
194
|
}
|
195
|
}//end for?></table>
|
196
|
</td>
|
197
|
<td class="listbg" ondblclick="document.location='firewall_schedule_edit.php?id=<?=$i;?>';">
|
198
|
<font color="#FFFFFF">
|
199
|
<?=htmlspecialchars($schedule['descr']);?>
|
200
|
</td>
|
201
|
<td valign="middle" nowrap class="list">
|
202
|
<table border="0" cellspacing="0" cellpadding="1">
|
203
|
<tr>
|
204
|
<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="edit alias"></a></td>
|
205
|
<td><a href="firewall_schedule.php?act=del&id=<?=$i;?>" onclick="return confirm('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="delete alias"></a></td>
|
206
|
</tr>
|
207
|
</table>
|
208
|
</td>
|
209
|
</tr>
|
210
|
<?php $i++; endforeach; ?>
|
211
|
<tr>
|
212
|
<td class="list" colspan="3"></td>
|
213
|
<td class="list">
|
214
|
<table border="0" cellspacing="0" cellpadding="1">
|
215
|
<tr>
|
216
|
<td valign="middle">
|
217
|
<a href="firewall_schedule_edit.php">
|
218
|
<img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" title="<?=gettext("add a new schedule");?>" alt="" />
|
219
|
</a>
|
220
|
</td>
|
221
|
</tr>
|
222
|
</table>
|
223
|
</td>
|
224
|
</tr>
|
225
|
<tr>
|
226
|
<td class="tabcont" colspan="3">
|
227
|
<p><span class="vexpl"><span class="red"><strong>Note:<br></strong></span>Schedules act as placeholders for time ranges to be used in Firewall Rules.</span></p>
|
228
|
</td>
|
229
|
</tr>
|
230
|
</table>
|
231
|
|
232
|
</form>
|
233
|
|
234
|
<?php include("fend.inc"); ?>
|
235
|
</body>
|
236
|
</html>
|