Project

General

Profile

Download (8.75 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
33 6b07c15a Matthew Grooms
##|+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 615b27bc Scott Dale
42 d88c6a9f Scott Ullrich
$pgtitle = array("Firewall","Schedules");
43 615b27bc Scott Dale
44 6a6d2f63 Scott Dale
$dayArray = array ('Mon','Tues','Wed','Thur','Fri','Sat','Sun');
45 615b27bc Scott Dale
$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 273c8b1c Scott Dale
				if ($rule['sched'] == $schedule_name){
67 615b27bc Scott Dale
					$referenced_by = $rule['descr'];
68
					$is_schedule_referenced = true;
69 273c8b1c Scott Dale
					break;
70 615b27bc Scott Dale
				}
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 1a4f3123 Scott Dale
	<table class="sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
93 615b27bc Scott Dale
	<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 d415d821 Seth Mos
	  <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 615b27bc Scott Dale
	</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 774c288f Scott Dale
			<?=htmlspecialchars($schedule['name']); 
110
			  	 $schedstatus = 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 615b27bc Scott Dale
  		</td>
116
  		<td class="listlr" ondblclick="document.location='firewall_schedule_edit.php?id=<?=$i;?>';">
117 1a4f3123 Scott Dale
  			<table width="98%" border="0" cellpadding="0" cellspacing="0">
118 774c288f Scott Dale
			<?php 
119
			
120
				foreach($schedule['timerange'] as $timerange) {
121 273c8b1c Scott Dale
						$tempFriendlyTime = "";
122
						$tempID = "";
123
						$firstprint = false;
124
						if ($timerange){
125
							$dayFriendly = "";
126
							$tempFriendlyTime = "";							
127
								
128
							//get hours
129
							$temptimerange = $timerange['hour'];
130 615b27bc Scott Dale
							$temptimeseparator = strrpos($temptimerange, "-");
131 273c8b1c Scott Dale
							
132 615b27bc Scott Dale
							$starttime = substr ($temptimerange, 0, $temptimeseparator); 
133
							$stoptime = substr ($temptimerange, $temptimeseparator+1); 
134 273c8b1c Scott Dale
								
135
							if ($timerange['month']){
136
								$tempmontharray = explode(",", $timerange['month']);
137
								$tempdayarray = explode(",",$timerange['day']);
138
								$arraycounter = 0;
139 1a4f3123 Scott Dale
								$firstDayFound = false;
140
								$firstPrint = false;
141 273c8b1c Scott Dale
								foreach ($tempmontharray as $monthtmp){
142
									$month = $tempmontharray[$arraycounter];
143
									$day = $tempdayarray[$arraycounter];
144 1a4f3123 Scott Dale
									
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 615b27bc Scott Dale
								}
168
							}
169 273c8b1c Scott Dale
							else
170
							{
171 fdb29c8a Scott Dale
								$tempdayFriendly = $timerange['position'];
172 273c8b1c Scott Dale
								$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 1a4f3123 Scott Dale
												$dayFriendly .= "<br/>";
192 273c8b1c Scott Dale
											$currentDay--;
193
											if ($currentDay != $firstDay)
194 6a6d2f63 Scott Dale
												$dayFriendly .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
195 273c8b1c Scott Dale
											else
196 6a6d2f63 Scott Dale
												$dayFriendly .= $dayArray[$firstDay-1];
197 273c8b1c Scott Dale
											$firstDayFound = false;	
198
											$firstprint = true;			
199
										}
200
										$counter++;
201 615b27bc Scott Dale
									}
202 1a4f3123 Scott Dale
								}
203 273c8b1c Scott Dale
							}		
204 1a4f3123 Scott Dale
							$timeFriendly = $starttime . "-" . $stoptime;
205
							$description = $timerange['rangedescr'];	
206
							
207 02dee88e Scott Ullrich
							?><tr><td><?echo $dayFriendly;?></td><td><?echo $timeFriendly;?></td><td><?echo $description;?></td><tr/><?php
208 615b27bc Scott Dale
						}
209 1a4f3123 Scott Dale
					}//end for?></table>
210 615b27bc Scott Dale
	  </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 d415d821 Seth Mos
	<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 615b27bc Scott Dale
242
</form>
243
244
<?php include("fend.inc"); ?>
245
</body>
246
</html>