Project

General

Profile

Download (6.38 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * firewall_schedule.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8
 * Copyright (c) 2014-2024 Rubicon Communications, LLC (Netgate)
9
 * All rights reserved.
10
 *
11
 * originally based on m0n0wall (http://m0n0.ch/wall)
12
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
13
 * All rights reserved.
14
 *
15
 * Licensed under the Apache License, Version 2.0 (the "License");
16
 * you may not use this file except in compliance with the License.
17
 * You may obtain a copy of the License at
18
 *
19
 * http://www.apache.org/licenses/LICENSE-2.0
20
 *
21
 * Unless required by applicable law or agreed to in writing, software
22
 * distributed under the License is distributed on an "AS IS" BASIS,
23
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
 * See the License for the specific language governing permissions and
25
 * limitations under the License.
26
 */
27

    
28
##|+PRIV
29
##|*IDENT=page-firewall-schedules
30
##|*NAME=Firewall: Schedules
31
##|*DESCR=Allow access to the 'Firewall: Schedules' page.
32
##|*MATCH=firewall_schedule.php*
33
##|-PRIV
34

    
35
define('CLOCK', '<i class="fa-regular fa-clock icon-black"></i>');
36

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

    
40
require_once("guiconfig.inc");
41
require_once("filter.inc");
42
require_once("shaper.inc");
43
require_once("firewall_schedule.inc");
44

    
45
$pgtitle = array(gettext("Firewall"), gettext("Schedules"));
46

    
47
init_config_arr(array('schedules', 'schedule'));
48
$a_schedules = &$config['schedules']['schedule'];
49

    
50
if ($_POST['act'] == "del") {
51
	$errmsg = deleteSchedule($_POST);
52
}
53

    
54
include("head.inc");
55

    
56
if ($errmsg) {
57
	print_info_box($errmsg, 'danger');
58
}
59
?>
60

    
61
<div class="panel panel-default">
62
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('Schedules')?></h2></div>
63
	<div class="panel-body table-responsive">
64
		<table class="table table-striped table-hover table-condensed table-rowdblclickedit">
65
			<thead>
66
				<tr>
67
					<th><!--"Active" indicator--></th>
68
					<th><?=gettext("Name")?></th>
69
					<th><?=gettext("Range: Date / Times / Name")?></th>
70
					<th><?=gettext("Description")?></th>
71
					<th><?=gettext("Actions")?></th>
72
				</tr>
73
			</thead>
74
			<tbody>
75
<?php
76
$i = 0;
77
foreach ($a_schedules as $schedule):
78
	$schedstatus = filter_get_time_based_rule_status($schedule);
79
?>
80
				<tr>
81
					<td>
82
						<?=($schedstatus) ? '<a title="' . gettext("Schedule is currently active") . '">' . CLOCK . '</a>':''?>
83
					</td>
84
					<td>
85
						 <?=htmlspecialchars($schedule['name'])?>
86
					</td>
87
					<td>
88
<?php
89
	$first = true;
90
	foreach ($schedule['timerange'] as $timerange) {
91
		$tempFriendlyTime = "";
92
		$tempID = "";
93
		$firstprint = false;
94

    
95
		if ($timerange) {
96
			$dayFriendly = "";
97
			$tempFriendlyTime = "";
98

    
99
			//get hours
100
			$temptimerange = $timerange['hour'];
101
			$temptimeseparator = strrpos($temptimerange, "-");
102

    
103
			$starttime = substr ($temptimerange, 0, $temptimeseparator);
104
			$stoptime = substr ($temptimerange, $temptimeseparator+1);
105

    
106
			if ($timerange['month']) {
107
				$tempmontharray = explode(",", $timerange['month']);
108
				$tempdayarray = explode(",", $timerange['day']);
109
				$arraycounter = 0;
110
				$firstDayFound = false;
111
				$firstPrint = false;
112
				foreach ($tempmontharray as $monthtmp) {
113
					$month = $tempmontharray[$arraycounter];
114
					$day = $tempdayarray[$arraycounter];
115

    
116
					if (!$firstDayFound) {
117
						$firstDay = $day;
118
						$firstmonth = $month;
119
						$firstDayFound = true;
120
					}
121

    
122
					$currentDay = $day;
123
					$nextDay = $tempdayarray[$arraycounter+1];
124
					$currentDay++;
125

    
126
					if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])) {
127
						if ($firstPrint) {
128
							$dayFriendly .= "<br />";
129
						}
130

    
131
						$currentDay--;
132

    
133
						if ($currentDay != $firstDay) {
134
							$dayFriendly .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
135
						} else {
136
							$dayFriendly .=	 $monthArray[$month-1] . " " . $day;
137
						}
138

    
139
						$firstDayFound = false;
140
						$firstPrint = true;
141
					}
142
					$arraycounter++;
143
				}
144
			} else {
145
				$tempdayFriendly = $timerange['position'];
146
				$firstDayFound = false;
147
				$tempFriendlyDayArray = explode(",", $tempdayFriendly);
148
				$currentDay = "";
149
				$firstDay = "";
150
				$nextDay = "";
151
				$counter = 0;
152

    
153
				foreach ($tempFriendlyDayArray as $day) {
154
					if ($day != "") {
155
						if (!$firstDayFound) {
156
							$firstDay = $tempFriendlyDayArray[$counter];
157
							$firstDayFound = true;
158
						}
159

    
160
						$currentDay =$tempFriendlyDayArray[$counter];
161
						//get next day
162
						$nextDay = $tempFriendlyDayArray[$counter+1];
163
						$currentDay++;
164

    
165
						if ($currentDay != $nextDay) {
166
							if ($firstprint) {
167
								$dayFriendly .= "<br />";
168
							}
169

    
170
							$currentDay--;
171

    
172
							if ($currentDay != $firstDay) {
173
								$dayFriendly .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
174
							} else {
175
								$dayFriendly .= $dayArray[$firstDay-1];
176
							}
177

    
178
							$firstDayFound = false;
179
							$firstprint = true;
180
						}
181
						$counter++;
182
					}
183
				}
184
			}
185

    
186
			$timeFriendly = $starttime . "-" . $stoptime;
187
			$description = htmlspecialchars($timerange['rangedescr']);
188

    
189
			print(($first ? '':'<br />') . $dayFriendly . ' / ' . $timeFriendly . ' / ' . $description);
190
		}
191
	$first = false;
192
	}
193
?>
194
					</td>
195

    
196
					<td>
197
						<?=htmlspecialchars($schedule['descr'])?>&nbsp;
198
					</td>
199

    
200
					<td>
201
						<a class="fa-solid fa-pencil" title="<?=gettext("Edit schedule"); ?>" href="firewall_schedule_edit.php?id=<?=$i?>"></a>
202
						<a class="fa-solid fa-trash-can" title="<?=gettext("Delete schedule")?>" href="firewall_schedule.php?act=del&amp;id=<?=$i?>" usepost></a>
203

    
204
					</td>
205
				</tr>
206
<?php
207
	$i++;
208
endforeach;
209
?>
210
			</tbody>
211
		</table>
212
	</div>
213
</div>
214

    
215
<?=($i > 0) ? CLOCK . gettext(' Indicates that the schedule is currently active.'):''?>
216

    
217
<nav class="action-buttons">
218
	<a href="firewall_schedule_edit.php" class="btn btn-sm btn-success">
219
		<i class="fa-solid fa-plus icon-embed-btn"></i>
220
		<?=gettext("Add")?>
221
	</a>
222
</nav>
223

    
224
<div class="infoblock">
225
	<?php print_info_box(gettext('Schedules act as placeholders for time ranges to be used in firewall rules.'), 'info', false); ?>
226
</div>
227

    
228
<?php
229

    
230
include("foot.inc");
(54-54/230)