Project

General

Profile

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