Project

General

Profile

Download (9.26 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	firewall_schedule.php
4
	Copyright (C) 2004 Scott Ullrich
5
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
6
	All rights reserved.
7

    
8
	originally part of m0n0wall (http://m0n0.ch/wall)
9
	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
/*
34
	pfSense_MODULE: schedules
35
*/
36
##|+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

    
44
$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

    
47
require("guiconfig.inc");
48
require_once("filter.inc");
49
require("shaper.inc");
50

    
51
$pgtitle = array(gettext("Firewall"),gettext("Schedules"));
52

    
53
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
				if ($rule['sched'] == $schedule_name){
70
					$referenced_by = $rule['descr'];
71
					$is_schedule_referenced = true;
72
					break;
73
				}
74
			}
75
		}
76

    
77
		if($is_schedule_referenced == true) {
78
			$savemsg = sprintf(gettext("Cannot delete Schedule.  Currently in use by %s"),$referenced_by);
79
		} 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
	<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="firewall schedule">
96
	<tr>
97
	  <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
	  <td width="5%" class="list sort_ignore">
101
	    <table border="0" cellspacing="0" cellpadding="1" summary="add">
102
	      <tr>
103
		<td width="17"></td>
104
	        <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
	      </tr>
106
	    </table>
107
	  </td>
108
	</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
			<?=htmlspecialchars($schedule['name']);?>
113
					<?php
114
					$schedstatus = filter_get_time_based_rule_status($schedule);
115
					 if ($schedstatus) { ?>
116
					 	&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
					 <?php } ?>
118

    
119
  		</td>
120
  		<td class="listlr" ondblclick="document.location='firewall_schedule_edit.php?id=<?=$i;?>';">
121
  			<table width="98%" border="0" cellpadding="0" cellspacing="0" summary="schedule">
122
			<?php
123

    
124
				foreach($schedule['timerange'] as $timerange) {
125
						$tempFriendlyTime = "";
126
						$tempID = "";
127
						$firstprint = false;
128
						if ($timerange){
129
							$dayFriendly = "";
130
							$tempFriendlyTime = "";
131

    
132
							//get hours
133
							$temptimerange = $timerange['hour'];
134
							$temptimeseparator = strrpos($temptimerange, "-");
135

    
136
							$starttime = substr ($temptimerange, 0, $temptimeseparator);
137
							$stoptime = substr ($temptimerange, $temptimeseparator+1);
138

    
139
							if ($timerange['month']){
140
								$tempmontharray = explode(",", $timerange['month']);
141
								$tempdayarray = explode(",",$timerange['day']);
142
								$arraycounter = 0;
143
								$firstDayFound = false;
144
								$firstPrint = false;
145
								foreach ($tempmontharray as $monthtmp){
146
									$month = $tempmontharray[$arraycounter];
147
									$day = $tempdayarray[$arraycounter];
148

    
149
									if (!$firstDayFound)
150
									{
151
										$firstDay = $day;
152
										$firstmonth = $month;
153
										$firstDayFound = true;
154
									}
155

    
156
									$currentDay = $day;
157
									$nextDay = $tempdayarray[$arraycounter+1];
158
									$currentDay++;
159
									if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])){
160
										if ($firstPrint)
161
											$dayFriendly .= "<br />";
162
										$currentDay--;
163
										if ($currentDay != $firstDay)
164
											$dayFriendly .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
165
										else
166
											$dayFriendly .=  $monthArray[$month-1] . " " . $day;
167
										$firstDayFound = false;
168
										$firstPrint = true;
169
									}
170
									$arraycounter++;
171
								}
172
							}
173
							else
174
							{
175
								$tempdayFriendly = $timerange['position'];
176
								$firstDayFound = false;
177
								$tempFriendlyDayArray = explode(",", $tempdayFriendly);
178
								$currentDay = "";
179
								$firstDay = "";
180
								$nextDay = "";
181
								$counter = 0;
182
								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
										$currentDay++;
193
										if ($currentDay != $nextDay){
194
											if ($firstprint)
195
												$dayFriendly .= "<br />";
196
											$currentDay--;
197
											if ($currentDay != $firstDay)
198
												$dayFriendly .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
199
											else
200
												$dayFriendly .= $dayArray[$firstDay-1];
201
											$firstDayFound = false;
202
											$firstprint = true;
203
										}
204
										$counter++;
205
									}
206
								}
207
							}
208
							$timeFriendly = $starttime . "-" . $stoptime;
209
							$description = $timerange['rangedescr'];
210

    
211
							?><tr><td><?=$dayFriendly;?></td><td><?=$timeFriendly;?></td><td><?=$description;?></td></tr><?php
212
						}
213
					}//end for?></table>
214
	  </td>
215
	 <td class="listbg" ondblclick="document.location='firewall_schedule_edit.php?id=<?=$i;?>';">
216
    		<?=htmlspecialchars($schedule['descr']);?>&nbsp;
217
  		</td>
218
  		  <td valign="middle" class="list nowrap">
219
    <table border="0" cellspacing="0" cellpadding="1" summary="buttons">
220
      <tr>
221
        <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
      </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
    <table border="0" cellspacing="0" cellpadding="1" summary="add">
232
      <tr>
233
	<td width="17"></td>
234
        <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
      </tr>
236
    </table>
237
  </td>
238
</tr>
239
<tr>
240
  <td class="tabcont" colspan="3">
241
   <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
  </td>
243
</tr>
244
</table>
245
</form>
246
<?php include("fend.inc"); ?>
247
</body>
248
</html>
(73-73/256)