Project

General

Profile

Download (6.31 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-2025 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"></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
if ($_POST['act'] == "del") {
48
	$errmsg = deleteSchedule($_POST);
49
}
50

    
51
include("head.inc");
52

    
53
if ($errmsg) {
54
	print_info_box($errmsg, 'danger');
55
}
56
?>
57

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

    
92
		if ($timerange) {
93
			$dayFriendly = "";
94
			$tempFriendlyTime = "";
95

    
96
			//get hours
97
			$temptimerange = $timerange['hour'];
98
			$temptimeseparator = strrpos($temptimerange, "-");
99

    
100
			$starttime = substr ($temptimerange, 0, $temptimeseparator);
101
			$stoptime = substr ($temptimerange, $temptimeseparator+1);
102

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

    
113
					if (!$firstDayFound) {
114
						$firstDay = $day;
115
						$firstmonth = $month;
116
						$firstDayFound = true;
117
					}
118

    
119
					$currentDay = $day;
120
					$nextDay = $tempdayarray[$arraycounter+1];
121
					$currentDay++;
122

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

    
128
						$currentDay--;
129

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

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

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

    
157
						$currentDay =$tempFriendlyDayArray[$counter];
158
						//get next day
159
						$nextDay = $tempFriendlyDayArray[$counter+1];
160
						$currentDay++;
161

    
162
						if ($currentDay != $nextDay) {
163
							if ($firstprint) {
164
								$dayFriendly .= "<br />";
165
							}
166

    
167
							$currentDay--;
168

    
169
							if ($currentDay != $firstDay) {
170
								$dayFriendly .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
171
							} else {
172
								$dayFriendly .= $dayArray[$firstDay-1];
173
							}
174

    
175
							$firstDayFound = false;
176
							$firstprint = true;
177
						}
178
						$counter++;
179
					}
180
				}
181
			}
182

    
183
			$timeFriendly = $starttime . "-" . $stoptime;
184
			$description = htmlspecialchars($timerange['rangedescr']);
185

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

    
193
					<td>
194
						<?=htmlspecialchars($schedule['descr'])?>&nbsp;
195
					</td>
196

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

    
201
					</td>
202
				</tr>
203
<?php
204
	$i++;
205
endforeach;
206
?>
207
			</tbody>
208
		</table>
209
	</div>
210
</div>
211

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

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

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

    
225
<?php
226

    
227
include("foot.inc");
(54-54/233)