Project

General

Profile

Download (9.2 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
	All rights reserved.
6
7
	originially part of m0n0wall (http://m0n0.ch/wall)
8
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
9
	All rights reserved.
10
11
	Redistribution and use in source and binary forms, with or without
12
	modification, are permitted provided that the following conditions are met:
13
14
	1. Redistributions of source code must retain the above copyright notice,
15
	   this list of conditions and the following disclaimer.
16
17
	2. Redistributions in binary form must reproduce the above copyright
18
	   notice, this list of conditions and the following disclaimer in the
19
	   documentation and/or other materials provided with the distribution.
20
21
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
22
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
23
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
25
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
	POSSIBILITY OF SUCH DAMAGE.
31
*/
32 7ac5a4cb Scott Ullrich
/*
33
	pfSense_MODULE: schedules
34
*/
35 6b07c15a Matthew Grooms
##|+PRIV
36
##|*IDENT=page-firewall-schedules
37
##|*NAME=Firewall: Schedules page
38
##|*DESCR=Allow access to the 'Firewall: Schedules' page.
39
##|*MATCH=firewall_schedule.php*
40
##|-PRIV
41
42 615b27bc Scott Dale
43 fa227734 Rafael Lucas
$dayArray = array (gettext('Mon'),gettext('Tues'),gettext('Wed'),gettext('Thur'),gettext('Fri'),gettext('Sat'),gettext('Sun'));
44
$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'));
45 615b27bc Scott Dale
46
require("guiconfig.inc");
47 1a03cf69 Scott Ullrich
require("filter.inc");
48
require("shaper.inc");
49 615b27bc Scott Dale
50 7102bd3c Carlos Eduardo Ramos
$pgtitle = array(gettext("Firewall"),gettext("Schedules"));
51
52 615b27bc Scott Dale
if (!is_array($config['schedules']['schedule']))
53
	$config['schedules']['schedule'] = array();
54
55
$a_schedules = &$config['schedules']['schedule'];
56
57
58
if ($_GET['act'] == "del") {
59
	if ($a_schedules[$_GET['id']]) {
60
		/* make sure rule is not being referenced by any nat or filter rules */
61
		$is_schedule_referenced = false;
62
		$referenced_by = false;
63
		$schedule_name = $a_schedules[$_GET['id']]['name'];
64
65
		if(is_array($config['filter']['rule'])) {
66
			foreach($config['filter']['rule'] as $rule) {
67
				//check for this later once this is established
68 273c8b1c Scott Dale
				if ($rule['sched'] == $schedule_name){
69 615b27bc Scott Dale
					$referenced_by = $rule['descr'];
70
					$is_schedule_referenced = true;
71 273c8b1c Scott Dale
					break;
72 615b27bc Scott Dale
				}
73
			}
74
		}
75
76
		if($is_schedule_referenced == true) {
77 fa227734 Rafael Lucas
			$savemsg = sprintf(gettext("Cannot delete Schedule.  Currently in use by %s"),$referenced_by);
78 615b27bc Scott Dale
		} else {
79
			unset($a_schedules[$_GET['id']]);
80
			write_config();
81
			header("Location: firewall_schedule.php");
82
			exit;
83
		}
84
	}
85
}
86
87
include("head.inc");
88
?>
89
90
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
91
<?php include("fbegin.inc"); ?>
92
<?php if ($savemsg) print_info_box($savemsg); ?>
93
<form action="firewall_schedule.php" method="post">
94 d2155191 Colin Fleming
	<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="firewall schedule">
95 615b27bc Scott Dale
	<tr>
96 2db2df36 Vinicius Coque
	  <td width="25%" class="listhdrr"><?=gettext("Name");?></td>
97
	  <td width="35%" class="listhdrr"><?=gettext("Time Range(s)");?></td>
98
	  <td width="35%" class="listhdr"><?=gettext("Description");?></td>
99 d415d821 Seth Mos
	  <td width="5%" class="list sort_ignore">
100 d2155191 Colin Fleming
	    <table border="0" cellspacing="0" cellpadding="1" summary="add">
101 d415d821 Seth Mos
	      <tr>
102
		<td width="17"></td>
103 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>
104 d415d821 Seth Mos
	      </tr>
105
	    </table>
106
	  </td>
107 615b27bc Scott Dale
	</tr>
108
	<?php $i = 0; foreach ($a_schedules as $schedule): ?>
109
	<tr>
110
	   <td class="listlr" ondblclick="document.location='firewall_schedule_edit.php?id=<?=$i;?>';">
111 e242f36a Renato Botelho
			<?=htmlspecialchars($schedule['name']);?>
112
					<?php
113 60120e37 Ermal Lu?i
					$schedstatus = filter_get_time_based_rule_status($schedule);
114 774c288f Scott Dale
					 if ($schedstatus) { ?>
115 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" />
116 774c288f Scott Dale
					 <?php } ?>
117 c0948c6c Renato Botelho
118 615b27bc Scott Dale
  		</td>
119
  		<td class="listlr" ondblclick="document.location='firewall_schedule_edit.php?id=<?=$i;?>';">
120 d2155191 Colin Fleming
  			<table width="98%" border="0" cellpadding="0" cellspacing="0" summary="schedule">
121 c0948c6c Renato Botelho
			<?php
122
123 774c288f Scott Dale
				foreach($schedule['timerange'] as $timerange) {
124 273c8b1c Scott Dale
						$tempFriendlyTime = "";
125
						$tempID = "";
126
						$firstprint = false;
127
						if ($timerange){
128
							$dayFriendly = "";
129 c0948c6c Renato Botelho
							$tempFriendlyTime = "";
130
131 273c8b1c Scott Dale
							//get hours
132
							$temptimerange = $timerange['hour'];
133 615b27bc Scott Dale
							$temptimeseparator = strrpos($temptimerange, "-");
134 c0948c6c Renato Botelho
135
							$starttime = substr ($temptimerange, 0, $temptimeseparator);
136
							$stoptime = substr ($temptimerange, $temptimeseparator+1);
137
138 273c8b1c Scott Dale
							if ($timerange['month']){
139
								$tempmontharray = explode(",", $timerange['month']);
140
								$tempdayarray = explode(",",$timerange['day']);
141
								$arraycounter = 0;
142 1a4f3123 Scott Dale
								$firstDayFound = false;
143
								$firstPrint = false;
144 273c8b1c Scott Dale
								foreach ($tempmontharray as $monthtmp){
145
									$month = $tempmontharray[$arraycounter];
146
									$day = $tempdayarray[$arraycounter];
147 c0948c6c Renato Botelho
148 1a4f3123 Scott Dale
									if (!$firstDayFound)
149
									{
150
										$firstDay = $day;
151
										$firstmonth = $month;
152
										$firstDayFound = true;
153
									}
154 c0948c6c Renato Botelho
155 1a4f3123 Scott Dale
									$currentDay = $day;
156
									$nextDay = $tempdayarray[$arraycounter+1];
157
									$currentDay++;
158
									if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])){
159
										if ($firstPrint)
160
											$dayFriendly .= "<br/>";
161
										$currentDay--;
162
										if ($currentDay != $firstDay)
163
											$dayFriendly .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
164
										else
165
											$dayFriendly .=  $monthArray[$month-1] . " " . $day;
166 c0948c6c Renato Botelho
										$firstDayFound = false;
167 1a4f3123 Scott Dale
										$firstPrint = true;
168 c0948c6c Renato Botelho
									}
169
									$arraycounter++;
170 615b27bc Scott Dale
								}
171
							}
172 273c8b1c Scott Dale
							else
173
							{
174 fdb29c8a Scott Dale
								$tempdayFriendly = $timerange['position'];
175 273c8b1c Scott Dale
								$firstDayFound = false;
176 c0948c6c Renato Botelho
								$tempFriendlyDayArray = explode(",", $tempdayFriendly);
177 273c8b1c Scott Dale
								$currentDay = "";
178
								$firstDay = "";
179
								$nextDay = "";
180 c0948c6c Renato Botelho
								$counter = 0;
181 273c8b1c Scott Dale
								foreach ($tempFriendlyDayArray as $day){
182
									if ($day != ""){
183
										if (!$firstDayFound)
184
										{
185
											$firstDay = $tempFriendlyDayArray[$counter];
186
											$firstDayFound = true;
187
										}
188
										$currentDay =$tempFriendlyDayArray[$counter];
189
										//get next day
190
										$nextDay = $tempFriendlyDayArray[$counter+1];
191 c0948c6c Renato Botelho
										$currentDay++;
192 273c8b1c Scott Dale
										if ($currentDay != $nextDay){
193
											if ($firstprint)
194 1a4f3123 Scott Dale
												$dayFriendly .= "<br/>";
195 273c8b1c Scott Dale
											$currentDay--;
196
											if ($currentDay != $firstDay)
197 6a6d2f63 Scott Dale
												$dayFriendly .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
198 273c8b1c Scott Dale
											else
199 6a6d2f63 Scott Dale
												$dayFriendly .= $dayArray[$firstDay-1];
200 c0948c6c Renato Botelho
											$firstDayFound = false;
201
											$firstprint = true;
202 273c8b1c Scott Dale
										}
203
										$counter++;
204 615b27bc Scott Dale
									}
205 1a4f3123 Scott Dale
								}
206 c0948c6c Renato Botelho
							}
207 1a4f3123 Scott Dale
							$timeFriendly = $starttime . "-" . $stoptime;
208 c0948c6c Renato Botelho
							$description = $timerange['rangedescr'];
209
210 d2155191 Colin Fleming
							?><tr><td><?=$dayFriendly;?></td><td><?=$timeFriendly;?></td><td><?=$description;?></td></tr><?php
211 615b27bc Scott Dale
						}
212 1a4f3123 Scott Dale
					}//end for?></table>
213 615b27bc Scott Dale
	  </td>
214
	 <td class="listbg" ondblclick="document.location='firewall_schedule_edit.php?id=<?=$i;?>';">
215
    		<?=htmlspecialchars($schedule['descr']);?>&nbsp;
216
  		</td>
217 d2155191 Colin Fleming
  		  <td valign="middle" class="list nowrap">
218
    <table border="0" cellspacing="0" cellpadding="1" summary="buttons">
219 615b27bc Scott Dale
      <tr>
220 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>
221
        <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>
222 615b27bc Scott Dale
      </tr>
223
    </table>
224
  </td>
225
</tr>
226
<?php $i++; endforeach; ?>
227
<tr>
228
  <td class="list" colspan="3"></td>
229
  <td class="list">
230 d2155191 Colin Fleming
    <table border="0" cellspacing="0" cellpadding="1" summary="add">
231 615b27bc Scott Dale
      <tr>
232 d415d821 Seth Mos
	<td width="17"></td>
233 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>
234 d415d821 Seth Mos
      </tr>
235
    </table>
236
  </td>
237
</tr>
238
<tr>
239
  <td class="tabcont" colspan="3">
240 d2155191 Colin Fleming
   <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>
241 d415d821 Seth Mos
  </td>
242
</tr>
243
</table>
244 615b27bc Scott Dale
</form>
245
<?php include("fend.inc"); ?>
246
</body>
247
</html>