Project

General

Profile

Download (8.74 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
##|+PRIV
34
##|*IDENT=page-firewall-schedules
35
##|*NAME=Firewall: Schedules page
36
##|*DESCR=Allow access to the 'Firewall: Schedules' page.
37
##|*MATCH=firewall_schedule.php*
38
##|-PRIV
39

    
40

    
41

    
42
$pgtitle = array("Firewall","Schedules");
43

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

    
47
require("guiconfig.inc");
48

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

    
52
$a_schedules = &$config['schedules']['schedule'];
53

    
54

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

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

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

    
84
include("head.inc");
85
?>
86

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

    
241
</form>
242

    
243
<?php include("fend.inc"); ?>
244
</body>
245
</html>
(59-59/217)