Project

General

Profile

Download (9.21 KB) Statistics
| Branch: | Tag: | Revision:

univnautes / usr / local / www / firewall_schedule.php @ a1b66bec

1
<?php
2
/*
3
	firewall_schedule.php
4
	Copyright (C) 2004 Scott Ullrich
5
	All rights reserved.
6

    
7
	originally 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
	pfSense_MODULE: schedules
34
*/
35
##|+PRIV
36
##|*IDENT=page-firewall-schedules
37
##|*NAME=Firewall: Schedules page
38
##|*DESCR=Allow access to the 'Firewall: Schedules' page.
39
##|*MATCH=firewall_schedule.php*
40
##|-PRIV
41

    
42

    
43
$dayArray = array (gettext('Mon'),gettext('Tues'),gettext('Wed'),gettext('Thur'),gettext('Fri'),gettext('Sat'),gettext('Sun'));
44
$monthArray = array (gettext('January'),gettext('February'),gettext('March'),gettext('April'),gettext('May'),gettext('June'),gettext('July'),gettext('August'),gettext('September'),gettext('October'),gettext('November'),gettext('December'));
45

    
46
require("guiconfig.inc");
47
require_once("filter.inc");
48
require("shaper.inc");
49

    
50
$pgtitle = array(gettext("Firewall"),gettext("Schedules"));
51

    
52
if (!is_array($config['schedules']['schedule']))
53
	$config['schedules']['schedule'] = array();
54

    
55
$a_schedules = &$config['schedules']['schedule'];
56

    
57

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

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

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

    
87
include("head.inc");
88
?>
89

    
90
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
91
<?php include("fbegin.inc"); ?>
92
<?php if ($savemsg) print_info_box($savemsg); ?>
93
<form action="firewall_schedule.php" method="post">
94
	<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="firewall schedule">
95
	<tr>
96
	  <td width="25%" class="listhdrr"><?=gettext("Name");?></td>
97
	  <td width="35%" class="listhdrr"><?=gettext("Time Range(s)");?></td>
98
	  <td width="35%" class="listhdr"><?=gettext("Description");?></td>
99
	  <td width="5%" class="list sort_ignore">
100
	    <table border="0" cellspacing="0" cellpadding="1" summary="add">
101
	      <tr>
102
		<td width="17"></td>
103
	        <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="add" /></a></td>
104
	      </tr>
105
	    </table>
106
	  </td>
107
	</tr>
108
	<?php $i = 0; foreach ($a_schedules as $schedule): ?>
109
	<tr>
110
	   <td class="listlr" ondblclick="document.location='firewall_schedule_edit.php?id=<?=$i;?>';">
111
			<?=htmlspecialchars($schedule['name']);?>
112
					<?php
113
					$schedstatus = filter_get_time_based_rule_status($schedule);
114
					 if ($schedstatus) { ?>
115
					 	&nbsp;<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_frmfld_time.png" title="<?=gettext("Schedule is currently active");?>" width="17" height="17" border="0" alt="schedule" />
116
					 <?php } ?>
117

    
118
  		</td>
119
  		<td class="listlr" ondblclick="document.location='firewall_schedule_edit.php?id=<?=$i;?>';">
120
  			<table width="98%" border="0" cellpadding="0" cellspacing="0" summary="schedule">
121
			<?php
122

    
123
				foreach($schedule['timerange'] as $timerange) {
124
						$tempFriendlyTime = "";
125
						$tempID = "";
126
						$firstprint = false;
127
						if ($timerange){
128
							$dayFriendly = "";
129
							$tempFriendlyTime = "";
130

    
131
							//get hours
132
							$temptimerange = $timerange['hour'];
133
							$temptimeseparator = strrpos($temptimerange, "-");
134

    
135
							$starttime = substr ($temptimerange, 0, $temptimeseparator);
136
							$stoptime = substr ($temptimerange, $temptimeseparator+1);
137

    
138
							if ($timerange['month']){
139
								$tempmontharray = explode(",", $timerange['month']);
140
								$tempdayarray = explode(",",$timerange['day']);
141
								$arraycounter = 0;
142
								$firstDayFound = false;
143
								$firstPrint = false;
144
								foreach ($tempmontharray as $monthtmp){
145
									$month = $tempmontharray[$arraycounter];
146
									$day = $tempdayarray[$arraycounter];
147

    
148
									if (!$firstDayFound)
149
									{
150
										$firstDay = $day;
151
										$firstmonth = $month;
152
										$firstDayFound = true;
153
									}
154

    
155
									$currentDay = $day;
156
									$nextDay = $tempdayarray[$arraycounter+1];
157
									$currentDay++;
158
									if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])){
159
										if ($firstPrint)
160
											$dayFriendly .= "<br />";
161
										$currentDay--;
162
										if ($currentDay != $firstDay)
163
											$dayFriendly .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
164
										else
165
											$dayFriendly .=  $monthArray[$month-1] . " " . $day;
166
										$firstDayFound = false;
167
										$firstPrint = true;
168
									}
169
									$arraycounter++;
170
								}
171
							}
172
							else
173
							{
174
								$tempdayFriendly = $timerange['position'];
175
								$firstDayFound = false;
176
								$tempFriendlyDayArray = explode(",", $tempdayFriendly);
177
								$currentDay = "";
178
								$firstDay = "";
179
								$nextDay = "";
180
								$counter = 0;
181
								foreach ($tempFriendlyDayArray as $day){
182
									if ($day != ""){
183
										if (!$firstDayFound)
184
										{
185
											$firstDay = $tempFriendlyDayArray[$counter];
186
											$firstDayFound = true;
187
										}
188
										$currentDay =$tempFriendlyDayArray[$counter];
189
										//get next day
190
										$nextDay = $tempFriendlyDayArray[$counter+1];
191
										$currentDay++;
192
										if ($currentDay != $nextDay){
193
											if ($firstprint)
194
												$dayFriendly .= "<br />";
195
											$currentDay--;
196
											if ($currentDay != $firstDay)
197
												$dayFriendly .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
198
											else
199
												$dayFriendly .= $dayArray[$firstDay-1];
200
											$firstDayFound = false;
201
											$firstprint = true;
202
										}
203
										$counter++;
204
									}
205
								}
206
							}
207
							$timeFriendly = $starttime . "-" . $stoptime;
208
							$description = $timerange['rangedescr'];
209

    
210
							?><tr><td><?=$dayFriendly;?></td><td><?=$timeFriendly;?></td><td><?=$description;?></td></tr><?php
211
						}
212
					}//end for?></table>
213
	  </td>
214
	 <td class="listbg" ondblclick="document.location='firewall_schedule_edit.php?id=<?=$i;?>';">
215
    		<?=htmlspecialchars($schedule['descr']);?>&nbsp;
216
  		</td>
217
  		  <td valign="middle" class="list nowrap">
218
    <table border="0" cellspacing="0" cellpadding="1" summary="buttons">
219
      <tr>
220
        <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="<?=gettext("edit alias");?>" alt="edit" /></a></td>
221
        <td><a href="firewall_schedule.php?act=del&amp;id=<?=$i;?>" onclick="return confirm('<?=gettext('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="<?=gettext("delete alias");?>" alt="delete" /></a></td>
222
      </tr>
223
    </table>
224
  </td>
225
</tr>
226
<?php $i++; endforeach; ?>
227
<tr>
228
  <td class="list" colspan="3"></td>
229
  <td class="list">
230
    <table border="0" cellspacing="0" cellpadding="1" summary="add">
231
      <tr>
232
	<td width="17"></td>
233
        <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="add" /></a></td>
234
      </tr>
235
    </table>
236
  </td>
237
</tr>
238
<tr>
239
  <td class="tabcont" colspan="3">
240
   <p><span class="vexpl"><span class="red"><strong><?=gettext("Note:");?><br /></strong></span><?=gettext("Schedules act as placeholders for time ranges to be used in Firewall Rules.");?></span></p>
241
  </td>
242
</tr>
243
</table>
244
</form>
245
<?php include("fend.inc"); ?>
246
</body>
247
</html>
(73-73/256)