Project

General

Profile

Download (8.69 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

    
34
$pgtitle = "Firewall: Schedules";
35

    
36
$dayArray = array ('Mon','Tues','Wed','Thur','Fri','Sat','Sun');
37
$monthArray = array ('January','February','March','April','May','June','July','August','September','October','November','December');
38

    
39
require("guiconfig.inc");
40

    
41
if (!is_array($config['schedules']['schedule']))
42
	$config['schedules']['schedule'] = array();
43

    
44
schedule_sort();
45
$a_schedules = &$config['schedules']['schedule'];
46

    
47

    
48
if ($_GET['act'] == "del") {
49
	if ($a_schedules[$_GET['id']]) {
50
		/* make sure rule is not being referenced by any nat or filter rules */
51
		$is_schedule_referenced = false;
52
		$referenced_by = false;
53
		$schedule_name = $a_schedules[$_GET['id']]['name'];
54

    
55
		if(is_array($config['filter']['rule'])) {
56
			foreach($config['filter']['rule'] as $rule) {
57
				//check for this later once this is established
58
				if ($rule['sched'] == $schedule_name){
59
					$referenced_by = $rule['descr'];
60
					$is_schedule_referenced = true;
61
					break;
62
				}
63
			}
64
		}
65

    
66
		if($is_schedule_referenced == true) {
67
			$savemsg = "Cannot delete Schedule.  Currently in use by {$referenced_by}";
68
		} else {
69
			unset($a_schedules[$_GET['id']]);
70
			write_config();
71
			header("Location: firewall_schedule.php");
72
			exit;
73
		}
74
	}
75
}
76

    
77
include("head.inc");
78
?>
79

    
80
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
81
<?php include("fbegin.inc"); ?>
82
<p class="pgtitle"><?=$pgtitle?></p>
83
<?php if ($savemsg) print_info_box($savemsg); ?>
84
<form action="firewall_schedule.php" method="post">
85
	<table class="sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
86
	<tr>
87
	  <td width="25%" class="listhdrr">Name</td>
88
	  <td width="35%" class="listhdrr">Time Range(s)</td>
89
	  <td width="35%" class="listhdr">Description</td>
90
	  <td width="5%" class="list sort_ignore">
91
	    <table border="0" cellspacing="0" cellpadding="1">
92
	      <tr>
93
		<td width="17"></td>
94
	        <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>
95
	      </tr>
96
	    </table>
97
	  </td>
98
	</tr>
99
	<?php $i = 0; foreach ($a_schedules as $schedule): ?>
100
	<tr>
101
	   <td class="listlr" ondblclick="document.location='firewall_schedule_edit.php?id=<?=$i;?>';">
102
			<?=htmlspecialchars($schedule['name']); 
103
			  	 $schedstatus = get_time_based_rule_status($schedule);
104
					 if ($schedstatus) { ?>
105
					 	&nbsp;<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_frmfld_time.png" title="Schedule is currently active" width="17" height="17" border="0">
106
					 <?php } ?>
107
    
108
  		</td>
109
  		<td class="listlr" ondblclick="document.location='firewall_schedule_edit.php?id=<?=$i;?>';">
110
  			<table width="98%" border="0" cellpadding="0" cellspacing="0">
111
			<?php 					
112

    
113
					foreach($schedule['timerange'] as $timerange) {
114
						$tempFriendlyTime = "";
115
						$tempID = "";
116
						$firstprint = false;
117
						if ($timerange){
118
							$dayFriendly = "";
119
							$tempFriendlyTime = "";							
120
							$daytimeseparator = strrpos($timerange, ",");
121
								
122
							//get hours
123
							$temptimerange = $timerange['hour'];
124
							$temptimeseparator = strrpos($temptimerange, "-");
125
							
126
							$starttime = substr ($temptimerange, 0, $temptimeseparator); 
127
							$stoptime = substr ($temptimerange, $temptimeseparator+1); 
128
								
129
							if ($timerange['month']){
130
								$tempmontharray = explode(",", $timerange['month']);
131
								$tempdayarray = explode(",",$timerange['day']);
132
								$arraycounter = 0;
133
								$firstDayFound = false;
134
								$firstPrint = false;
135
								foreach ($tempmontharray as $monthtmp){
136
									$month = $tempmontharray[$arraycounter];
137
									$day = $tempdayarray[$arraycounter];
138
									
139
									if (!$firstDayFound)
140
									{
141
										$firstDay = $day;
142
										$firstmonth = $month;
143
										$firstDayFound = true;
144
									}
145
										
146
									$currentDay = $day;
147
									$nextDay = $tempdayarray[$arraycounter+1];
148
									$currentDay++;
149
									if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])){
150
										if ($firstPrint)
151
											$dayFriendly .= "<br/>";
152
										$currentDay--;
153
										if ($currentDay != $firstDay)
154
											$dayFriendly .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
155
										else
156
											$dayFriendly .=  $monthArray[$month-1] . " " . $day;
157
										$firstDayFound = false;	
158
										$firstPrint = true;
159
									}													
160
									$arraycounter++;	
161
								}
162
							}
163
							else
164
							{
165
								$tempdayFriendly = $timerange['position'];
166
								$firstDayFound = false;
167
								$tempFriendlyDayArray = explode(",", $tempdayFriendly);								
168
								$currentDay = "";
169
								$firstDay = "";
170
								$nextDay = "";
171
								$counter = 0;													
172
								foreach ($tempFriendlyDayArray as $day){
173
									if ($day != ""){
174
										if (!$firstDayFound)
175
										{
176
											$firstDay = $tempFriendlyDayArray[$counter];
177
											$firstDayFound = true;
178
										}
179
										$currentDay =$tempFriendlyDayArray[$counter];
180
										//get next day
181
										$nextDay = $tempFriendlyDayArray[$counter+1];
182
										$currentDay++;					
183
										if ($currentDay != $nextDay){
184
											if ($firstprint)
185
												$dayFriendly .= "<br/>";
186
											$currentDay--;
187
											if ($currentDay != $firstDay)
188
												$dayFriendly .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
189
											else
190
												$dayFriendly .= $dayArray[$firstDay-1];
191
											$firstDayFound = false;	
192
											$firstprint = true;			
193
										}
194
										$counter++;
195
									}
196
								}
197
							}		
198
							$timeFriendly = $starttime . "-" . $stoptime;
199
							$description = $timerange['rangedescr'];	
200
							
201
							?><tr><td><?echo $dayFriendly;?></td><td><?echo $timeFriendly;?></td><td><?echo $description;?></td><tr/><?php
202
						}
203
					}//end for?></table>
204
	  </td>
205
	 <td class="listbg" ondblclick="document.location='firewall_schedule_edit.php?id=<?=$i;?>';">
206
    	<font color="#FFFFFF">
207
    		<?=htmlspecialchars($schedule['descr']);?>&nbsp;
208
  		</td>
209
  		  <td valign="middle" nowrap class="list">
210
    <table border="0" cellspacing="0" cellpadding="1">
211
      <tr>
212
        <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="edit alias"></a></td>
213
        <td><a href="firewall_schedule.php?act=del&id=<?=$i;?>" onclick="return confirm('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="delete alias"></a></td>
214
      </tr>
215
    </table>
216
  </td>
217
</tr>
218
<?php $i++; endforeach; ?>
219
<tr>
220
  <td class="list" colspan="3"></td>
221
  <td class="list">
222
    <table border="0" cellspacing="0" cellpadding="1">
223
      <tr>
224
	<td width="17"></td>
225
        <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>
226
      </tr>
227
    </table>
228
  </td>
229
</tr>
230
<tr>
231
  <td class="tabcont" colspan="3">
232
   <p><span class="vexpl"><span class="red"><strong>Note:<br></strong></span>Schedules act as placeholders for time ranges to be used in Firewall Rules.</span></p>
233
  </td>
234
</tr>
235
</table>
236

    
237
</form>
238

    
239
<?php include("fend.inc"); ?>
240
</body>
241
</html>
(55-55/176)