Project

General

Profile

Download (14.9 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
<?php
2 b46bfcf5 Bill Marquette
/* $Id$ */
3 5b237745 Scott Ullrich
/*
4 b49448ac Scott Ullrich
    firewall_shaper.php
5
    Copyright (C) 2004, 2005 Scott Ullrich
6
    All rights reserved.
7
8
    Originally part of m0n0wall (http://m0n0.ch/wall)
9
    Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
10
    All rights reserved.
11
12
    Redistribution and use in source and binary forms, with or without
13
    modification, are permitted provided that the following conditions are met:
14
15
    1. Redistributions of source code must retain the above copyright notice,
16
       this list of conditions and the following disclaimer.
17
18
    2. Redistributions in binary form must reproduce the above copyright
19
       notice, this list of conditions and the following disclaimer in the
20
       documentation and/or other materials provided with the distribution.
21
22
    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
23
    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
24
    AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25
    AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26
    OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
    POSSIBILITY OF SUCH DAMAGE.
32 5b237745 Scott Ullrich
*/
33
34
require("guiconfig.inc");
35
36 09eafb8b Scott Ullrich
/* redirect to wizard if shaper isn't already configured */
37
if(isset($config['shaper']['enable'])) {
38
	$pconfig['enable'] = TRUE;
39
} else {
40
	if(!is_array($config['shaper']['queue']))
41
		Header("Location: wizard.php?xml=traffic_shaper_wizard.xml");
42
}
43
44 12bcdc89 Scott Ullrich
if (!is_array($config['shaper']['rule'])) {
45
	$config['shaper']['rule'] = array();
46 5b237745 Scott Ullrich
}
47 09eafb8b Scott Ullrich
48 12bcdc89 Scott Ullrich
if (!is_array($config['shaper']['queue'])) {
49
	$config['shaper']['queue'] = array();
50 5b237745 Scott Ullrich
}
51 09eafb8b Scott Ullrich
52 12bcdc89 Scott Ullrich
$a_shaper = &$config['shaper']['rule'];
53
$a_queue = &$config['shaper']['queue'];
54 5b237745 Scott Ullrich
55 57b89461 Scott Ullrich
function wipe_magic () {
56
  global $config;
57
58
  /* wipe previous */
59
  unset($config['shaper']['queue']);
60
  unset($config['shaper']['rule']);
61
  $config['shaper']['enable'] = FALSE;
62
}
63
64 664c2cb5 Scott Ullrich
if ($_POST['remove'] or $_GET['remove']) {
65 57b89461 Scott Ullrich
  wipe_magic();
66
  $savemsg = '<p><span class="red"><strong>Note: The traffic shaper has been disabled.</strong></span><strong><br>';
67
  touch($d_shaperconfdirty_path);
68
  unset($config['shaper']['enable']);
69
  write_config();
70 73335292 Scott Ullrich
  filter_configure();
71 faec4b2e Scott Ullrich
  Header("Location: index.php");
72 9d9d5dac Scott Ullrich
  exit;
73 57b89461 Scott Ullrich
}
74
75 5b237745 Scott Ullrich
if ($_POST) {
76
77
	if ($_POST['submit']) {
78
		$pconfig = $_POST;
79 12bcdc89 Scott Ullrich
		$config['shaper']['enable'] = $_POST['enable'] ? true : false;
80 5b237745 Scott Ullrich
		write_config();
81
	}
82
83
	if ($_POST['apply'] || $_POST['submit']) {
84 0c13691b Scott Ullrich
		$config['shaper']['enable'] = $_POST['enable'] ? true : false;
85 e8731417 Scott Ullrich
		write_config();		
86 5b237745 Scott Ullrich
		$retval = 0;
87
		$savemsg = get_std_save_message($retval);
88 098e0219 Scott Ullrich
		/* Setup pf rules since the user may have changed the optimization value */
89
		config_lock();
90
		$retval = filter_configure();
91
		config_unlock();
92 b2774343 Scott Ullrich
		if(stristr($retval, "error") <> true)
93 2a71debf Scott Ullrich
		    $savemsg = get_std_save_message($retval);
94
		else
95
		    $savemsg = $retval;
96 0df08a41 Scott Ullrich
97
	        if(file_exists($d_shaperconfdirty_path))
98
	          unlink($d_shaperconfdirty_path);
99 5b237745 Scott Ullrich
	}
100
}
101
102 1f276138 Scott Ullrich
if (isset($_POST['del_x'])) {
103
        /* delete selected rules */
104
        if (is_array($_POST['rule']) && count($_POST['rule'])) {
105
                foreach ($_POST['rule'] as $rulei) {
106
                        unset($a_shaper[$rulei]);
107
                }
108
                write_config();
109
                touch($d_natconfdirty_path);
110
                header("Location: firewall_shaper.php");
111
                exit;
112
        }
113
}
114
115
116
if ($_GET['act'] == "down") {
117 5b237745 Scott Ullrich
	if ($a_shaper[$_GET['id']] && $a_shaper[$_GET['id']+1]) {
118
		$tmp = $a_shaper[$_GET['id']+1];
119
		$a_shaper[$_GET['id']+1] = $a_shaper[$_GET['id']];
120
		$a_shaper[$_GET['id']] = $tmp;
121
		write_config();
122
		touch($d_shaperconfdirty_path);
123
		header("Location: firewall_shaper.php");
124
		exit;
125
	}
126
} else if ($_GET['act'] == "up") {
127
	if (($_GET['id'] > 0) && $a_shaper[$_GET['id']]) {
128
		$tmp = $a_shaper[$_GET['id']-1];
129
		$a_shaper[$_GET['id']-1] = $a_shaper[$_GET['id']];
130
		$a_shaper[$_GET['id']] = $tmp;
131
		write_config();
132
		touch($d_shaperconfdirty_path);
133
		header("Location: firewall_shaper.php");
134
		exit;
135
	}
136
} else if ($_GET['act'] == "toggle") {
137
	if ($a_shaper[$_GET['id']]) {
138
		$a_shaper[$_GET['id']]['disabled'] = !isset($a_shaper[$_GET['id']]['disabled']);
139
		write_config();
140
		touch($d_shaperconfdirty_path);
141
		header("Location: firewall_shaper.php");
142
		exit;
143
	}
144 0ceb8927 Bill Marquette
} else {
145
	/* yuck - IE won't send value attributes for image buttons, while Mozilla does -
146
	   so we use .x/.y to fine move button clicks instead... */
147
	unset($movebtn);
148
	foreach ($_POST as $pn => $pd) {
149
		if (preg_match("/move_(\d+)_x/", $pn, $matches)) {
150
			$movebtn = $matches[1];
151
			break;
152
		}
153
	}
154
	/* move selected rules before this rule */
155
	if (isset($movebtn) && is_array($_POST['rule']) && count($_POST['rule'])) {
156
		$a_shaper_new = array();
157
158
		/* copy all rules < $movebtn and not selected */
159
		for ($i = 0; $i < $movebtn; $i++) {
160
			if (!in_array($i, $_POST['rule']))
161
				$a_shaper_new[] = $a_shaper[$i];
162
		}
163
164
		/* copy all selected rules */
165
		for ($i = 0; $i < count($a_shaper); $i++) {
166
			if ($i == $movebtn)
167
				continue;
168
			if (in_array($i, $_POST['rule']))
169
				$a_shaper_new[] = $a_shaper[$i];
170
		}
171
172
		/* copy $movebtn rule */
173
		if ($movebtn < count($a_shaper))
174
			$a_shaper_new[] = $a_shaper[$movebtn];
175
176
		/* copy all rules > $movebtn and not selected */
177
		for ($i = $movebtn+1; $i < count($a_shaper); $i++) {
178
			if (!in_array($i, $_POST['rule']))
179
				$a_shaper_new[] = $a_shaper[$i];
180
		}
181
182
		$a_shaper = $a_shaper_new;
183
		write_config();
184 89cc63ee Bill Marquette
		touch($d_shaperconfdirty_path);
185 0ceb8927 Bill Marquette
		header("Location: firewall_shaper.php");
186
		exit;
187
	}
188 5b237745 Scott Ullrich
}
189 52380979 Scott Ullrich
190 da7ae7ef Bill Marquette
$pgtitle = "Firewall: Shaper: Rules";
191 52380979 Scott Ullrich
include("head.inc");
192
193 5b237745 Scott Ullrich
?>
194
195
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
196
<?php include("fbegin.inc"); ?>
197 da7ae7ef Bill Marquette
<p class="pgtitle"><?=$pgtitle?></p>
198 0ceb8927 Bill Marquette
<form action="firewall_shaper.php" method="post" name="iform">
199
<script type="text/javascript" language="javascript" src="row_toggle.js">
200
</script>
201 5b237745 Scott Ullrich
<?php if ($savemsg) print_info_box($savemsg); ?>
202
<?php if (file_exists($d_shaperconfdirty_path)): ?><p>
203
<?php print_info_box_np("The traffic shaper configuration has been changed.<br>You must apply the changes in order for them to take effect.");?><br>
204
<?php endif; ?>
205
<table width="100%" border="0" cellpadding="0" cellspacing="0">
206
  <tr><td>
207 52380979 Scott Ullrich
<?php
208
	$tab_array = array();
209
	$tab_array[0] = array("Rules", true, "firewall_shaper.php");
210
	$tab_array[1] = array("Queues", false, "firewall_shaper_queues.php");
211
	$tab_array[2] = array("EZ Shaper wizard", false, "wizard.php?xml=traffic_shaper_wizard.xml");
212
	display_top_tabs($tab_array);
213
?>  
214 5b237745 Scott Ullrich
  </td></tr>
215
  <tr>
216 d732f186 Bill Marquette
    <td>
217
	<div id="mainarea">
218
              <table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
219 5b237745 Scott Ullrich
                <tr>
220
                  <td class="vtable"><p>
221
                      <input name="enable" type="checkbox" id="enable" value="yes" <?php if ($pconfig['enable'] == "yes") echo "checked";?>>
222
                      <strong>Enable traffic shaper<br>
223
                      </strong></p></td>
224
                </tr>
225
                <tr>
226 57b89461 Scott Ullrich
                  <td> 
227
		  <input name="submit" type="submit" class="formbtn" value="Save"> 
228
		  <input name="remove" type="submit" class="formbtn" id="remove" value="Remove Wizard"> 
229 5b237745 Scott Ullrich
                  </td>
230 57b89461 Scott Ullrich
		  
231 5b237745 Scott Ullrich
                </tr>
232
              </table>
233 d732f186 Bill Marquette
              <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
234 0ceb8927 Bill Marquette
                      <tr id="frheader">
235
		        <td width="3%" class="list">&nbsp;</td>
236
                        <td width="3%" class="list">&nbsp;</td>
237 5b237745 Scott Ullrich
                        <td width="5%" class="listhdrrns">If</td>
238
                        <td width="5%" class="listhdrrns">Proto</td>
239
                        <td width="20%" class="listhdrr">Source</td>
240
                        <td width="20%" class="listhdrr">Destination</td>
241
                        <td width="15%" class="listhdrrns">Target</td>
242 6b8cdc08 Scott Ullrich
                        <td width="25%" class="listhdr">Description</td>
243
                        <td width="10%" class="list"></td>
244 5b237745 Scott Ullrich
                      </tr>
245 0ceb8927 Bill Marquette
                      <?php $nrules = $i = 0; foreach ($a_shaper as $shaperent): ?>
246
                      <tr valign="top" id="fr<?=$nrules;?>">
247
                        <td class="listt"><input type="checkbox" id="frc<?=$nrules;?>" name="rule[]" value="<?=$i;?>" onClick="fr_bgcolor('<?=$nrules;?>')" style="margin: 0; padding: 0; width: 15px; height: 15px;"></td>
248
                        <td class="listt" align="center"></td>
249 3939326c Bill Marquette
                        <td class="listlr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_shaper_edit.php?id=<?=$i;?>';">
250 5b237745 Scott Ullrich
                          <?php
251
				  $dis = "";
252
				  if (isset($shaperent['disabled'])) {
253
				  	$dis = "_d";
254
					$textss = "<span class=\"gray\">";
255
					$textse = "</span>";
256
				  } else {
257
				  	$textss = $textse = "";
258
				  }
259
				  $iflabels = array('lan' => 'LAN', 'wan' => 'WAN', 'pptp' => 'PPTP');
260
				  for ($j = 1; isset($config['interfaces']['opt' . $j]); $j++)
261
				  	$iflabels['opt' . $j] = $config['interfaces']['opt' . $j]['descr'];
262 e295675f Scott Ullrich
				  echo $textss . htmlspecialchars($iflabels[$shaperent['in-interface']]) . "->" . htmlspecialchars($iflabels[$shaperent['out-interface']]);
263
264 5b237745 Scott Ullrich
				  echo "<br>";
265
				  echo "<a href=\"?act=toggle&id={$i}\">";
266 f1f924bf Bill Marquette
				  if ($shaperent['direction'] == "in")
267 677c0869 Erik Kristensen
				  	echo "<img src=\"./themes/".$g['theme']."/images/icons/icon_in{$dis}.gif\" width=\"11\" height=\"11\" border=\"0\" style=\"margin-top: 5px\" title=\"click to toggle enabled/disabled status\">";
268 f1f924bf Bill Marquette
				  if ($shaperent['direction'] == "out")
269 677c0869 Erik Kristensen
				  	echo "<img src=\"./themes/".$g['theme']."/images/icons/icon_out{$dis}.gif\" width=\"11\" height=\"11\" border=\"0\" style=\"margin-top: 5px\" title=\"click to toggle enabled/disabled status\">";
270 f1f924bf Bill Marquette
271 5b237745 Scott Ullrich
				  echo "</a>" . $textse;;
272
				  ?>
273
                        </td>
274 3939326c Bill Marquette
                        <td class="listr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_shaper_edit.php?id=<?=$i;?>';">
275 5b237745 Scott Ullrich
                          <?=$textss;?><?php if (isset($shaperent['protocol'])) echo strtoupper($shaperent['protocol']); else echo "*"; ?><?=$textse;?>
276
                        </td>
277 3939326c Bill Marquette
                        <td class="listr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_shaper_edit.php?id=<?=$i;?>';"><?=$textss;?><?php echo htmlspecialchars(pprint_address($shaperent['source'])); ?>
278 5b237745 Scott Ullrich
						<?php if ($shaperent['source']['port']): ?><br>
279
						Port: <?=htmlspecialchars(pprint_port($shaperent['source']['port'])); ?>
280
						<?php endif; ?><?=$textse;?>
281
                        </td>
282 3939326c Bill Marquette
                        <td class="listr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_shaper_edit.php?id=<?=$i;?>';"><?=$textss;?><?php echo htmlspecialchars(pprint_address($shaperent['destination'])); ?>
283 5b237745 Scott Ullrich
						<?php if ($shaperent['destination']['port']): ?><br>
284
						Port: <?=htmlspecialchars(pprint_port($shaperent['destination']['port'])); ?>
285
						<?php endif; ?><?=$textse;?>
286
                        </td>
287 3939326c Bill Marquette
                        <td class="listr" onClick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_shaper_edit.php?id=<?=$i;?>';"><?=$textss;?>
288 5b237745 Scott Ullrich
                          <?php
289 f1f924bf Bill Marquette
							if (isset($shaperent['outqueue']) && isset($shaperent['inqueue'])) {
290
								$desc = htmlspecialchars($shaperent['outqueue']);
291
							    echo "<a href=\"firewall_shaper_queues_edit.php?id={$shaperent['outqueue']}\">{$desc}</a>";
292
								$desc = htmlspecialchars($shaperent['inqueue']);
293
							    echo "/<a href=\"firewall_shaper_queues_edit.php?id={$shaperent['inqueue']}\">{$desc}</a>";
294 5b237745 Scott Ullrich
							}
295
						  ?><?=$textse;?>
296
                        </td>
297 3939326c Bill Marquette
                        <td class="listbg" onClick="fr_toggle(<?=$nrules;?>)" ondblclick="document.location='firewall_shaper_edit.php?id=<?=$i;?>';"><font color="white">
298 5b237745 Scott Ullrich
                          <?=$textss;?><?=htmlspecialchars($shaperent['descr']);?><?=$textse;?>
299
                          &nbsp; </td>
300 677c0869 Erik Kristensen
                        <td valign="middle" nowrap class="list"> <a href="firewall_shaper_edit.php?id=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" title="edit rule" width="17" height="17" border="0"></a>
301 5b237745 Scott Ullrich
                          <?php if ($i > 0): ?>
302 677c0869 Erik Kristensen
                          <a href="firewall_shaper.php?act=up&id=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_up.gif" title="move up" width="17" height="17" border="0"></a>
303 5b237745 Scott Ullrich
                          <?php else: ?>
304 677c0869 Erik Kristensen
                          <img src="./themes/<?= $g['theme']; ?>/images/icons/icon_up_d.gif" width="17" height="17" border="0">
305 0ceb8927 Bill Marquette
                          <?php endif; ?>
306 677c0869 Erik Kristensen
			  <input name="move_<?=$i;?>" type="image" src="./themes/<?= $g['theme']; ?>/images/icons/icon_left.gif" width="17" height="17" title="move selected rules before this rule" onMouseOver="fr_insline(<?=$nrules;?>, true)" onMouseOut="fr_insline(<?=$nrules;?>, false)"><br>
307 c45cff0b Scott Ullrich
			  
308 677c0869 Erik Kristensen
			  <input name="del" type="image" src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" title="delete selected mappings" onclick="return confirm('Do you really want to delete the selected mappings?')">
309 c45cff0b Scott Ullrich
			  
310 5b237745 Scott Ullrich
                          <?php if (isset($a_shaper[$i+1])): ?>
311 677c0869 Erik Kristensen
                          <a href="firewall_shaper.php?act=down&id=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_down.gif" title="move down" width="17" height="17" border="0"></a>
312 5b237745 Scott Ullrich
                          <?php else: ?>
313 677c0869 Erik Kristensen
                          <img src="./themes/<?= $g['theme']; ?>/images/icons/icon_down_d.gif" width="17" height="17" border="0">
314 5b237745 Scott Ullrich
                          <?php endif; ?>
315 677c0869 Erik Kristensen
                          <a href="firewall_shaper_edit.php?dup=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="add a new rule based on this one" width="17" height="17" border="0"></a>
316 5b237745 Scott Ullrich
                        </td>
317
                      </tr>
318 0ceb8927 Bill Marquette
                      <?php $nrules++; $i++; endforeach; ?>
319 5b237745 Scott Ullrich
                      <tr>
320 0ceb8927 Bill Marquette
                        <td class="list" colspan="8"></td>
321 677c0869 Erik Kristensen
                        <td class="list"> <a href="firewall_shaper_edit.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a></td>
322 5b237745 Scott Ullrich
                      </tr>
323 d732f186 Bill Marquette
		      <tr>
324
		    <td colspan="8"><p><span class="red"><strong>Note:</strong></span><strong><br>
325 4eb6b2a3 Scott Ullrich
                    </strong>The first rule that matches a packet will be executed.<br>
326 5b237745 Scott Ullrich
                    The following match patterns are not shown in the list above:
327 c55a8ab9 Holger Bauer
                    IP packet length, TCP flags.<br>
328
                    You can check the results of your queues at <a href="status_queues.php">Status:Queues</a>.</td>
329 d732f186 Bill Marquette
		    </tr>
330
                    </table>
331
		</div>
332
	  </td>
333 5b237745 Scott Ullrich
	</tr>
334
</table>
335
            </form>
336
<?php include("fend.inc"); ?>
337
</body>
338
</html>