Project

General

Profile

Download (8.76 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
schedule_sort();
53
$a_schedules = &$config['schedules']['schedule'];
54

    
55

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

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

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

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

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

    
242
</form>
243

    
244
<?php include("fend.inc"); ?>
245
</body>
246
</html>
(53-53/206)