Project

General

Profile

Download (9.26 KB) Statistics
| Branch: | Tag: | Revision:
1 615b27bc Scott Dale
<?php
2
/*
3 dcef097d Scott Dale
	firewall_schedule.php
4 615b27bc Scott Dale
	Copyright (C) 2004 Scott Ullrich
5 ce77a9c4 Phil Davis
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
6 615b27bc Scott Dale
	All rights reserved.
7
8 51dc66c9 Phil Davis
	originally part of m0n0wall (http://m0n0.ch/wall)
9 615b27bc Scott Dale
	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 7ac5a4cb Scott Ullrich
/*
34
	pfSense_MODULE: schedules
35
*/
36 6b07c15a Matthew Grooms
##|+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 615b27bc Scott Dale
44 fa227734 Rafael Lucas
$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 615b27bc Scott Dale
47
require("guiconfig.inc");
48 f6339216 jim-p
require_once("filter.inc");
49 1a03cf69 Scott Ullrich
require("shaper.inc");
50 615b27bc Scott Dale
51 7102bd3c Carlos Eduardo Ramos
$pgtitle = array(gettext("Firewall"),gettext("Schedules"));
52
53 615b27bc Scott Dale
if (!is_array($config['schedules']['schedule']))
54
	$config['schedules']['schedule'] = array();
55
56
$a_schedules = &$config['schedules']['schedule'];
57
58
59
if ($_GET['act'] == "del") {
60
	if ($a_schedules[$_GET['id']]) {
61
		/* make sure rule is not being referenced by any nat or filter rules */
62
		$is_schedule_referenced = false;
63
		$referenced_by = false;
64
		$schedule_name = $a_schedules[$_GET['id']]['name'];
65
66
		if(is_array($config['filter']['rule'])) {
67
			foreach($config['filter']['rule'] as $rule) {
68
				//check for this later once this is established
69 273c8b1c Scott Dale
				if ($rule['sched'] == $schedule_name){
70 615b27bc Scott Dale
					$referenced_by = $rule['descr'];
71
					$is_schedule_referenced = true;
72 273c8b1c Scott Dale
					break;
73 615b27bc Scott Dale
				}
74
			}
75
		}
76
77
		if($is_schedule_referenced == true) {
78 fa227734 Rafael Lucas
			$savemsg = sprintf(gettext("Cannot delete Schedule.  Currently in use by %s"),$referenced_by);
79 615b27bc Scott Dale
		} else {
80
			unset($a_schedules[$_GET['id']]);
81
			write_config();
82
			header("Location: firewall_schedule.php");
83
			exit;
84
		}
85
	}
86
}
87
88
include("head.inc");
89
?>
90
91
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
92
<?php include("fbegin.inc"); ?>
93
<?php if ($savemsg) print_info_box($savemsg); ?>
94
<form action="firewall_schedule.php" method="post">
95 d2155191 Colin Fleming
	<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="firewall schedule">
96 615b27bc Scott Dale
	<tr>
97 2db2df36 Vinicius Coque
	  <td width="25%" class="listhdrr"><?=gettext("Name");?></td>
98
	  <td width="35%" class="listhdrr"><?=gettext("Time Range(s)");?></td>
99
	  <td width="35%" class="listhdr"><?=gettext("Description");?></td>
100 d415d821 Seth Mos
	  <td width="5%" class="list sort_ignore">
101 d2155191 Colin Fleming
	    <table border="0" cellspacing="0" cellpadding="1" summary="add">
102 d415d821 Seth Mos
	      <tr>
103
		<td width="17"></td>
104 d2155191 Colin Fleming
	        <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>
105 d415d821 Seth Mos
	      </tr>
106
	    </table>
107
	  </td>
108 615b27bc Scott Dale
	</tr>
109
	<?php $i = 0; foreach ($a_schedules as $schedule): ?>
110
	<tr>
111
	   <td class="listlr" ondblclick="document.location='firewall_schedule_edit.php?id=<?=$i;?>';">
112 e242f36a Renato Botelho
			<?=htmlspecialchars($schedule['name']);?>
113
					<?php
114 60120e37 Ermal Lu?i
					$schedstatus = filter_get_time_based_rule_status($schedule);
115 774c288f Scott Dale
					 if ($schedstatus) { ?>
116 d2155191 Colin Fleming
					 	&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" />
117 774c288f Scott Dale
					 <?php } ?>
118 c0948c6c Renato Botelho
119 615b27bc Scott Dale
  		</td>
120
  		<td class="listlr" ondblclick="document.location='firewall_schedule_edit.php?id=<?=$i;?>';">
121 d2155191 Colin Fleming
  			<table width="98%" border="0" cellpadding="0" cellspacing="0" summary="schedule">
122 c0948c6c Renato Botelho
			<?php
123
124 774c288f Scott Dale
				foreach($schedule['timerange'] as $timerange) {
125 273c8b1c Scott Dale
						$tempFriendlyTime = "";
126
						$tempID = "";
127
						$firstprint = false;
128
						if ($timerange){
129
							$dayFriendly = "";
130 c0948c6c Renato Botelho
							$tempFriendlyTime = "";
131
132 273c8b1c Scott Dale
							//get hours
133
							$temptimerange = $timerange['hour'];
134 615b27bc Scott Dale
							$temptimeseparator = strrpos($temptimerange, "-");
135 c0948c6c Renato Botelho
136
							$starttime = substr ($temptimerange, 0, $temptimeseparator);
137
							$stoptime = substr ($temptimerange, $temptimeseparator+1);
138
139 273c8b1c Scott Dale
							if ($timerange['month']){
140
								$tempmontharray = explode(",", $timerange['month']);
141
								$tempdayarray = explode(",",$timerange['day']);
142
								$arraycounter = 0;
143 1a4f3123 Scott Dale
								$firstDayFound = false;
144
								$firstPrint = false;
145 273c8b1c Scott Dale
								foreach ($tempmontharray as $monthtmp){
146
									$month = $tempmontharray[$arraycounter];
147
									$day = $tempdayarray[$arraycounter];
148 c0948c6c Renato Botelho
149 1a4f3123 Scott Dale
									if (!$firstDayFound)
150
									{
151
										$firstDay = $day;
152
										$firstmonth = $month;
153
										$firstDayFound = true;
154
									}
155 c0948c6c Renato Botelho
156 1a4f3123 Scott Dale
									$currentDay = $day;
157
									$nextDay = $tempdayarray[$arraycounter+1];
158
									$currentDay++;
159
									if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])){
160
										if ($firstPrint)
161 8cd558b6 ayvis
											$dayFriendly .= "<br />";
162 1a4f3123 Scott Dale
										$currentDay--;
163
										if ($currentDay != $firstDay)
164
											$dayFriendly .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
165
										else
166
											$dayFriendly .=  $monthArray[$month-1] . " " . $day;
167 c0948c6c Renato Botelho
										$firstDayFound = false;
168 1a4f3123 Scott Dale
										$firstPrint = true;
169 c0948c6c Renato Botelho
									}
170
									$arraycounter++;
171 615b27bc Scott Dale
								}
172
							}
173 273c8b1c Scott Dale
							else
174
							{
175 fdb29c8a Scott Dale
								$tempdayFriendly = $timerange['position'];
176 273c8b1c Scott Dale
								$firstDayFound = false;
177 c0948c6c Renato Botelho
								$tempFriendlyDayArray = explode(",", $tempdayFriendly);
178 273c8b1c Scott Dale
								$currentDay = "";
179
								$firstDay = "";
180
								$nextDay = "";
181 c0948c6c Renato Botelho
								$counter = 0;
182 273c8b1c Scott Dale
								foreach ($tempFriendlyDayArray as $day){
183
									if ($day != ""){
184
										if (!$firstDayFound)
185
										{
186
											$firstDay = $tempFriendlyDayArray[$counter];
187
											$firstDayFound = true;
188
										}
189
										$currentDay =$tempFriendlyDayArray[$counter];
190
										//get next day
191
										$nextDay = $tempFriendlyDayArray[$counter+1];
192 c0948c6c Renato Botelho
										$currentDay++;
193 273c8b1c Scott Dale
										if ($currentDay != $nextDay){
194
											if ($firstprint)
195 8cd558b6 ayvis
												$dayFriendly .= "<br />";
196 273c8b1c Scott Dale
											$currentDay--;
197
											if ($currentDay != $firstDay)
198 6a6d2f63 Scott Dale
												$dayFriendly .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
199 273c8b1c Scott Dale
											else
200 6a6d2f63 Scott Dale
												$dayFriendly .= $dayArray[$firstDay-1];
201 c0948c6c Renato Botelho
											$firstDayFound = false;
202
											$firstprint = true;
203 273c8b1c Scott Dale
										}
204
										$counter++;
205 615b27bc Scott Dale
									}
206 1a4f3123 Scott Dale
								}
207 c0948c6c Renato Botelho
							}
208 1a4f3123 Scott Dale
							$timeFriendly = $starttime . "-" . $stoptime;
209 c0948c6c Renato Botelho
							$description = $timerange['rangedescr'];
210
211 d2155191 Colin Fleming
							?><tr><td><?=$dayFriendly;?></td><td><?=$timeFriendly;?></td><td><?=$description;?></td></tr><?php
212 615b27bc Scott Dale
						}
213 1a4f3123 Scott Dale
					}//end for?></table>
214 615b27bc Scott Dale
	  </td>
215
	 <td class="listbg" ondblclick="document.location='firewall_schedule_edit.php?id=<?=$i;?>';">
216
    		<?=htmlspecialchars($schedule['descr']);?>&nbsp;
217
  		</td>
218 d2155191 Colin Fleming
  		  <td valign="middle" class="list nowrap">
219
    <table border="0" cellspacing="0" cellpadding="1" summary="buttons">
220 615b27bc Scott Dale
      <tr>
221 d2155191 Colin Fleming
        <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>
222
        <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>
223 615b27bc Scott Dale
      </tr>
224
    </table>
225
  </td>
226
</tr>
227
<?php $i++; endforeach; ?>
228
<tr>
229
  <td class="list" colspan="3"></td>
230
  <td class="list">
231 d2155191 Colin Fleming
    <table border="0" cellspacing="0" cellpadding="1" summary="add">
232 615b27bc Scott Dale
      <tr>
233 d415d821 Seth Mos
	<td width="17"></td>
234 d2155191 Colin Fleming
        <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>
235 d415d821 Seth Mos
      </tr>
236
    </table>
237
  </td>
238
</tr>
239
<tr>
240
  <td class="tabcont" colspan="3">
241 8cd558b6 ayvis
   <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>
242 d415d821 Seth Mos
  </td>
243
</tr>
244
</table>
245 615b27bc Scott Dale
</form>
246
<?php include("fend.inc"); ?>
247
</body>
248
</html>