Project

General

Profile

Download (6.35 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
config_init_path('schedules/schedule');
48

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

    
53
include("head.inc");
54

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

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

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

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

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

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

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

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

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

    
130
						$currentDay--;
131

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

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

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

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

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

    
169
							$currentDay--;
170

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

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

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

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

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

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

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

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

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

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

    
227
<?php
228

    
229
include("foot.inc");
(54-54/232)