Project

General

Profile

Download (9.17 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	firewall_schedule.php
4
	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
/*
33
	pfSense_MODULE: schedules
34
*/
35
##|+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
$pgtitle = array(gettext("Firewall"),gettext("Schedules"));
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("filter.inc");
49
require("shaper.inc");
50

    
51
if (!is_array($config['schedules']['schedule']))
52
	$config['schedules']['schedule'] = array();
53

    
54
$a_schedules = &$config['schedules']['schedule'];
55

    
56

    
57
if ($_GET['act'] == "del") {
58
	if ($a_schedules[$_GET['id']]) {
59
		/* make sure rule is not being referenced by any nat or filter rules */
60
		$is_schedule_referenced = false;
61
		$referenced_by = false;
62
		$schedule_name = $a_schedules[$_GET['id']]['name'];
63

    
64
		if(is_array($config['filter']['rule'])) {
65
			foreach($config['filter']['rule'] as $rule) {
66
				//check for this later once this is established
67
				if ($rule['sched'] == $schedule_name){
68
					$referenced_by = $rule['descr'];
69
					$is_schedule_referenced = true;
70
					break;
71
				}
72
			}
73
		}
74

    
75
		if($is_schedule_referenced == true) {
76
			$savemsg = sprintf(gettext("Cannot delete Schedule.  Currently in use by %s"),$referenced_by);
77
		} else {
78
			unset($a_schedules[$_GET['id']]);
79
			write_config();
80
			header("Location: firewall_schedule.php");
81
			exit;
82
		}
83
	}
84
}
85

    
86
include("head.inc");
87
?>
88

    
89
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
90
<?php include("fbegin.inc"); ?>
91
<?php if ($savemsg) print_info_box($savemsg); ?>
92
<form action="firewall_schedule.php" method="post">
93
	<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
94
	<tr>
95
	  <td width="25%" class="listhdrr"><?=gettext("Name");?></td>
96
	  <td width="35%" class="listhdrr"><?=gettext("Time Range(s)");?></td>
97
	  <td width="35%" class="listhdr"><?=gettext("Description");?></td>
98
	  <td width="5%" class="list sort_ignore">
99
	    <table border="0" cellspacing="0" cellpadding="1">
100
	      <tr>
101
		<td width="17"></td>
102
	        <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="" /></a></td>
103
	      </tr>
104
	    </table>
105
	  </td>
106
	</tr>
107
	<?php $i = 0; foreach ($a_schedules as $schedule): ?>
108
	<tr>
109
	   <td class="listlr" ondblclick="document.location='firewall_schedule_edit.php?id=<?=$i;?>';">
110
			<?=htmlspecialchars($schedule['name']); 
111
					$schedstatus = filter_get_time_based_rule_status($schedule);
112
					 if ($schedstatus) { ?>
113
					 	&nbsp;<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_frmfld_time.png" title="<?=gettext("Schedule is currently active");?>" width="17" height="17" border="0">
114
					 <?php } ?>
115
    
116
  		</td>
117
  		<td class="listlr" ondblclick="document.location='firewall_schedule_edit.php?id=<?=$i;?>';">
118
  			<table width="98%" border="0" cellpadding="0" cellspacing="0">
119
			<?php 
120
			
121
				foreach($schedule['timerange'] as $timerange) {
122
						$tempFriendlyTime = "";
123
						$tempID = "";
124
						$firstprint = false;
125
						if ($timerange){
126
							$dayFriendly = "";
127
							$tempFriendlyTime = "";							
128
								
129
							//get hours
130
							$temptimerange = $timerange['hour'];
131
							$temptimeseparator = strrpos($temptimerange, "-");
132
							
133
							$starttime = substr ($temptimerange, 0, $temptimeseparator); 
134
							$stoptime = substr ($temptimerange, $temptimeseparator+1); 
135
								
136
							if ($timerange['month']){
137
								$tempmontharray = explode(",", $timerange['month']);
138
								$tempdayarray = explode(",",$timerange['day']);
139
								$arraycounter = 0;
140
								$firstDayFound = false;
141
								$firstPrint = false;
142
								foreach ($tempmontharray as $monthtmp){
143
									$month = $tempmontharray[$arraycounter];
144
									$day = $tempdayarray[$arraycounter];
145
									
146
									if (!$firstDayFound)
147
									{
148
										$firstDay = $day;
149
										$firstmonth = $month;
150
										$firstDayFound = true;
151
									}
152
										
153
									$currentDay = $day;
154
									$nextDay = $tempdayarray[$arraycounter+1];
155
									$currentDay++;
156
									if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])){
157
										if ($firstPrint)
158
											$dayFriendly .= "<br/>";
159
										$currentDay--;
160
										if ($currentDay != $firstDay)
161
											$dayFriendly .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
162
										else
163
											$dayFriendly .=  $monthArray[$month-1] . " " . $day;
164
										$firstDayFound = false;	
165
										$firstPrint = true;
166
									}													
167
									$arraycounter++;	
168
								}
169
							}
170
							else
171
							{
172
								$tempdayFriendly = $timerange['position'];
173
								$firstDayFound = false;
174
								$tempFriendlyDayArray = explode(",", $tempdayFriendly);								
175
								$currentDay = "";
176
								$firstDay = "";
177
								$nextDay = "";
178
								$counter = 0;													
179
								foreach ($tempFriendlyDayArray as $day){
180
									if ($day != ""){
181
										if (!$firstDayFound)
182
										{
183
											$firstDay = $tempFriendlyDayArray[$counter];
184
											$firstDayFound = true;
185
										}
186
										$currentDay =$tempFriendlyDayArray[$counter];
187
										//get next day
188
										$nextDay = $tempFriendlyDayArray[$counter+1];
189
										$currentDay++;					
190
										if ($currentDay != $nextDay){
191
											if ($firstprint)
192
												$dayFriendly .= "<br/>";
193
											$currentDay--;
194
											if ($currentDay != $firstDay)
195
												$dayFriendly .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
196
											else
197
												$dayFriendly .= $dayArray[$firstDay-1];
198
											$firstDayFound = false;	
199
											$firstprint = true;			
200
										}
201
										$counter++;
202
									}
203
								}
204
							}		
205
							$timeFriendly = $starttime . "-" . $stoptime;
206
							$description = $timerange['rangedescr'];	
207
							
208
							?><tr><td><?echo $dayFriendly;?></td><td><?echo $timeFriendly;?></td><td><?echo $description;?></td><tr/><?php
209
						}
210
					}//end for?></table>
211
	  </td>
212
	 <td class="listbg" ondblclick="document.location='firewall_schedule_edit.php?id=<?=$i;?>';">
213
    		<?=htmlspecialchars($schedule['descr']);?>&nbsp;
214
  		</td>
215
  		  <td valign="middle" nowrap class="list">
216
    <table border="0" cellspacing="0" cellpadding="1">
217
      <tr>
218
        <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");?>"></a></td>
219
        <td><a href="firewall_schedule.php?act=del&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");?>"></a></td>
220
      </tr>
221
    </table>
222
  </td>
223
</tr>
224
<?php $i++; endforeach; ?>
225
<tr>
226
  <td class="list" colspan="3"></td>
227
  <td class="list">
228
    <table border="0" cellspacing="0" cellpadding="1">
229
      <tr>
230
	<td width="17"></td>
231
        <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="" /></a></td>
232
      </tr>
233
    </table>
234
  </td>
235
</tr>
236
<tr>
237
  <td class="tabcont" colspan="3">
238
   <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>
239
  </td>
240
</tr>
241
</table>
242

    
243
</form>
244

    
245
<?php include("fend.inc"); ?>
246
</body>
247
</html>
(58-58/221)