Project

General

Profile

Download (7.38 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

    
34
$pgtitle = "Firewall: Schedules";
35

    
36
$dayArray = array ('Mon','Tues','Wed','Thur','Fri','Sat','Sun');
37
$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
				if ($rule['sched'] == $schedule_name){
59
					$referenced_by = $rule['descr'];
60
					$is_schedule_referenced = true;
61
					break;
62
				}
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
	<table class="sortable" width="98%" border="0" cellpadding="0" cellspacing="0">
86
	<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
	  <td width="5%" class="list sort_ignore"></td>
91
	</tr>
92
	<?php $i = 0; foreach ($a_schedules as $schedule): ?>
93
	<tr>
94
	   <td class="listlr" ondblclick="document.location='firewall_schedule_edit.php?id=<?=$i;?>';">
95
    <?=htmlspecialchars($schedule['name']);?>
96
  		</td>
97
  		<td class="listlr" ondblclick="document.location='firewall_schedule_edit.php?id=<?=$i;?>';">
98
			<?php 					
99

    
100
					foreach($schedule['timerange'] as $timerange) {
101
						$tempFriendlyTime = "";
102
						$tempID = "";
103
						$firstprint = false;
104
						if ($timerange){
105
							$dayFriendly = "";
106
							$tempFriendlyTime = "";							
107
							$daytimeseparator = strrpos($timerange, ",");
108
								
109
							//get hours
110
							$temptimerange = $timerange['hour'];
111
							$temptimeseparator = strrpos($temptimerange, "-");
112
							
113
							$starttime = substr ($temptimerange, 0, $temptimeseparator); 
114
							$stoptime = substr ($temptimerange, $temptimeseparator+1); 
115
								
116
							if ($timerange['month']){
117
								$tempmontharray = explode(",", $timerange['month']);
118
								$tempdayarray = explode(",",$timerange['day']);
119
								$arraycounter = 0;
120
								foreach ($tempmontharray as $monthtmp){
121
									if ($firstprint)
122
									{
123
										$dayFriendly .= ", ";										
124
									}	
125
									$month = $tempmontharray[$arraycounter];
126
									$day = $tempdayarray[$arraycounter];
127
									$monthstr = $monthArray[$month-1];
128
									$dayFriendly .= $monthstr . " " . $day;
129
									$arraycounter++;
130
									$firstprint = true;
131
				
132
								}
133
							}
134
							else
135
							{
136
								$tempdayFriendly = $timerange['position'];
137
								$firstDayFound = false;
138
								$tempFriendlyDayArray = explode(",", $tempdayFriendly);								
139
								$currentDay = "";
140
								$firstDay = "";
141
								$nextDay = "";
142
								$counter = 0;													
143
								foreach ($tempFriendlyDayArray as $day){
144
									if ($day != ""){
145
										if (!$firstDayFound)
146
										{
147
											$firstDay = $tempFriendlyDayArray[$counter];
148
											$firstDayFound = true;
149
										}
150
										$currentDay =$tempFriendlyDayArray[$counter];
151
										//get next day
152
										$nextDay = $tempFriendlyDayArray[$counter+1];
153
										$currentDay++;					
154
										if ($currentDay != $nextDay){
155
											if ($firstprint)
156
												$dayFriendly .= ", ";
157
											$currentDay--;
158
											if ($currentDay != $firstDay)
159
												$dayFriendly .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
160
											else
161
												$dayFriendly .= $dayArray[$firstDay-1];
162
											$firstDayFound = false;	
163
											$firstprint = true;			
164
										}
165
										$counter++;
166
									}
167
								}	
168
							}		
169
		
170
						
171
							$dayFriendly .= " : " . $starttime . "-" . $stoptime . " : " . $timerange['rangedescr'];											
172
							echo $dayFriendly;	
173
							echo "<br/>";
174
						}
175
					}//end for?>
176
	  </td>
177
	 <td class="listbg" ondblclick="document.location='firewall_schedule_edit.php?id=<?=$i;?>';">
178
    	<font color="#FFFFFF">
179
    		<?=htmlspecialchars($schedule['descr']);?>&nbsp;
180
  		</td>
181
  		  <td valign="middle" nowrap class="list">
182
    <table border="0" cellspacing="0" cellpadding="1">
183
      <tr>
184
        <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>
185
        <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>
186
      </tr>
187
    </table>
188
  </td>
189
</tr>
190
<?php $i++; endforeach; ?>
191
<tr>
192
  <td class="list" colspan="3"></td>
193
  <td class="list">
194
    <table border="0" cellspacing="0" cellpadding="1">
195
      <tr>
196
	        <td valign="middle">
197
	          <a href="firewall_schedule_edit.php">
198
	            <img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" title="<?=gettext("add a new schedule");?>" alt="" />
199
	          </a>
200
	         </td>
201
	      </tr>
202
	    </table>
203
	  </td>
204
	</tr>
205
	<tr>
206
	  <td class="tabcont" colspan="3">
207
	   <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>
208
	  </td>
209
	</tr>
210
	</table>
211

    
212
</form>
213

    
214
<?php include("fend.inc"); ?>
215
</body>
216
</html>
(50-50/169)