Project

General

Profile

Download (8.63 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
34
$pgtitle = "Firewall: Schedules";
35
36 6a6d2f63 Scott Dale
$dayArray = array ('Mon','Tues','Wed','Thur','Fri','Sat','Sun');
37 615b27bc Scott Dale
$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 273c8b1c Scott Dale
				if ($rule['sched'] == $schedule_name){
59 615b27bc Scott Dale
					$referenced_by = $rule['descr'];
60
					$is_schedule_referenced = true;
61 273c8b1c Scott Dale
					break;
62 615b27bc Scott Dale
				}
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 1a4f3123 Scott Dale
	<table class="sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
86 615b27bc Scott Dale
	<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 d415d821 Seth Mos
	  <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 615b27bc Scott Dale
	</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 774c288f Scott Dale
			<?=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 615b27bc Scott Dale
  		</td>
109
  		<td class="listlr" ondblclick="document.location='firewall_schedule_edit.php?id=<?=$i;?>';">
110 1a4f3123 Scott Dale
  			<table width="98%" border="0" cellpadding="0" cellspacing="0">
111 774c288f Scott Dale
			<?php 
112
			
113
				foreach($schedule['timerange'] as $timerange) {
114 273c8b1c Scott Dale
						$tempFriendlyTime = "";
115
						$tempID = "";
116
						$firstprint = false;
117
						if ($timerange){
118
							$dayFriendly = "";
119
							$tempFriendlyTime = "";							
120
								
121
							//get hours
122
							$temptimerange = $timerange['hour'];
123 615b27bc Scott Dale
							$temptimeseparator = strrpos($temptimerange, "-");
124 273c8b1c Scott Dale
							
125 615b27bc Scott Dale
							$starttime = substr ($temptimerange, 0, $temptimeseparator); 
126
							$stoptime = substr ($temptimerange, $temptimeseparator+1); 
127 273c8b1c Scott Dale
								
128
							if ($timerange['month']){
129
								$tempmontharray = explode(",", $timerange['month']);
130
								$tempdayarray = explode(",",$timerange['day']);
131
								$arraycounter = 0;
132 1a4f3123 Scott Dale
								$firstDayFound = false;
133
								$firstPrint = false;
134 273c8b1c Scott Dale
								foreach ($tempmontharray as $monthtmp){
135
									$month = $tempmontharray[$arraycounter];
136
									$day = $tempdayarray[$arraycounter];
137 1a4f3123 Scott Dale
									
138
									if (!$firstDayFound)
139
									{
140
										$firstDay = $day;
141
										$firstmonth = $month;
142
										$firstDayFound = true;
143
									}
144
										
145
									$currentDay = $day;
146
									$nextDay = $tempdayarray[$arraycounter+1];
147
									$currentDay++;
148
									if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])){
149
										if ($firstPrint)
150
											$dayFriendly .= "<br/>";
151
										$currentDay--;
152
										if ($currentDay != $firstDay)
153
											$dayFriendly .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
154
										else
155
											$dayFriendly .=  $monthArray[$month-1] . " " . $day;
156
										$firstDayFound = false;	
157
										$firstPrint = true;
158
									}													
159
									$arraycounter++;	
160 615b27bc Scott Dale
								}
161
							}
162 273c8b1c Scott Dale
							else
163
							{
164 fdb29c8a Scott Dale
								$tempdayFriendly = $timerange['position'];
165 273c8b1c Scott Dale
								$firstDayFound = false;
166
								$tempFriendlyDayArray = explode(",", $tempdayFriendly);								
167
								$currentDay = "";
168
								$firstDay = "";
169
								$nextDay = "";
170
								$counter = 0;													
171
								foreach ($tempFriendlyDayArray as $day){
172
									if ($day != ""){
173
										if (!$firstDayFound)
174
										{
175
											$firstDay = $tempFriendlyDayArray[$counter];
176
											$firstDayFound = true;
177
										}
178
										$currentDay =$tempFriendlyDayArray[$counter];
179
										//get next day
180
										$nextDay = $tempFriendlyDayArray[$counter+1];
181
										$currentDay++;					
182
										if ($currentDay != $nextDay){
183
											if ($firstprint)
184 1a4f3123 Scott Dale
												$dayFriendly .= "<br/>";
185 273c8b1c Scott Dale
											$currentDay--;
186
											if ($currentDay != $firstDay)
187 6a6d2f63 Scott Dale
												$dayFriendly .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
188 273c8b1c Scott Dale
											else
189 6a6d2f63 Scott Dale
												$dayFriendly .= $dayArray[$firstDay-1];
190 273c8b1c Scott Dale
											$firstDayFound = false;	
191
											$firstprint = true;			
192
										}
193
										$counter++;
194 615b27bc Scott Dale
									}
195 1a4f3123 Scott Dale
								}
196 273c8b1c Scott Dale
							}		
197 1a4f3123 Scott Dale
							$timeFriendly = $starttime . "-" . $stoptime;
198
							$description = $timerange['rangedescr'];	
199
							
200 02dee88e Scott Ullrich
							?><tr><td><?echo $dayFriendly;?></td><td><?echo $timeFriendly;?></td><td><?echo $description;?></td><tr/><?php
201 615b27bc Scott Dale
						}
202 1a4f3123 Scott Dale
					}//end for?></table>
203 615b27bc Scott Dale
	  </td>
204
	 <td class="listbg" ondblclick="document.location='firewall_schedule_edit.php?id=<?=$i;?>';">
205
    	<font color="#FFFFFF">
206
    		<?=htmlspecialchars($schedule['descr']);?>&nbsp;
207
  		</td>
208
  		  <td valign="middle" nowrap class="list">
209
    <table border="0" cellspacing="0" cellpadding="1">
210
      <tr>
211
        <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>
212
        <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>
213
      </tr>
214
    </table>
215
  </td>
216
</tr>
217
<?php $i++; endforeach; ?>
218
<tr>
219
  <td class="list" colspan="3"></td>
220
  <td class="list">
221
    <table border="0" cellspacing="0" cellpadding="1">
222
      <tr>
223 d415d821 Seth Mos
	<td width="17"></td>
224
        <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>
225
      </tr>
226
    </table>
227
  </td>
228
</tr>
229
<tr>
230
  <td class="tabcont" colspan="3">
231
   <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>
232
  </td>
233
</tr>
234
</table>
235 615b27bc Scott Dale
236
</form>
237
238
<?php include("fend.inc"); ?>
239
</body>
240
</html>