Project

General

Profile

Download (11.8 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php
3
/*
4
	firewall_shaper.php
5
	part of m0n0wall (http://m0n0.ch/wall)
6

    
7
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
8
	All rights reserved.
9

    
10
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12

    
13
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15

    
16
	2. Redistributions in binary form must reproduce the above copyright
17
	   notice, this list of conditions and the following disclaimer in the
18
	   documentation and/or other materials provided with the distribution.
19

    
20
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30
*/
31

    
32
require("guiconfig.inc");
33

    
34
if (!is_array($config['pfqueueing']['rule'])) {
35
	$config['pfqueueing']['rule'] = array();
36
}
37
if (!is_array($config['pfqueueing']['pipe'])) {
38
	$config['pfqueueing']['pipe'] = array();
39
}
40
if (!is_array($config['pfqueueing']['queue'])) {
41
	$config['pfqueueing']['queue'] = array();
42
}
43
$a_shaper = &$config['pfqueueing']['rule'];
44
$a_pipe = &$config['pfqueueing']['pipe'];
45
$a_queue = &$config['pfqueueing']['queue'];
46

    
47
$pconfig['enable'] = isset($config['pfqueueing']['enable']);
48

    
49
if ($_POST) {
50

    
51
	if ($_POST['submit']) {
52
		$pconfig = $_POST;
53
		$config['pfqueueing']['enable'] = $_POST['enable'] ? true : false;
54
		write_config();
55
	}
56

    
57
	if ($_POST['apply'] || $_POST['submit']) {
58
		$retval = 0;
59
		if (!file_exists($d_sysrebootreqd_path)) {
60
			config_lock();
61
			$retval = shaper_configure();
62
			config_unlock();
63
		}
64
		$savemsg = get_std_save_message($retval);
65
		if ($retval == 0) {
66
			if (file_exists($d_shaperconfdirty_path))
67
				unlink($d_shaperconfdirty_path);
68
		}
69
	}
70
}
71

    
72
if ($_GET['act'] == "del") {
73
	if ($a_shaper[$_GET['id']]) {
74
		unset($a_shaper[$_GET['id']]);
75
		write_config();
76
		touch($d_shaperconfdirty_path);
77
		header("Location: firewall_shaper.php");
78
		exit;
79
	}
80
} else if ($_GET['act'] == "down") {
81
	if ($a_shaper[$_GET['id']] && $a_shaper[$_GET['id']+1]) {
82
		$tmp = $a_shaper[$_GET['id']+1];
83
		$a_shaper[$_GET['id']+1] = $a_shaper[$_GET['id']];
84
		$a_shaper[$_GET['id']] = $tmp;
85
		write_config();
86
		touch($d_shaperconfdirty_path);
87
		header("Location: firewall_shaper.php");
88
		exit;
89
	}
90
} else if ($_GET['act'] == "up") {
91
	if (($_GET['id'] > 0) && $a_shaper[$_GET['id']]) {
92
		$tmp = $a_shaper[$_GET['id']-1];
93
		$a_shaper[$_GET['id']-1] = $a_shaper[$_GET['id']];
94
		$a_shaper[$_GET['id']] = $tmp;
95
		write_config();
96
		touch($d_shaperconfdirty_path);
97
		header("Location: firewall_shaper.php");
98
		exit;
99
	}
100
} else if ($_GET['act'] == "toggle") {
101
	if ($a_shaper[$_GET['id']]) {
102
		$a_shaper[$_GET['id']]['disabled'] = !isset($a_shaper[$_GET['id']]['disabled']);
103
		write_config();
104
		touch($d_shaperconfdirty_path);
105
		header("Location: firewall_shaper.php");
106
		exit;
107
	}
108
}
109
?>
110
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
111
<html>
112
<head>
113
<title><?=gentitle("Firewall: Traffic shaper");?></title>
114
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
115
<link href="gui.css" rel="stylesheet" type="text/css">
116
</head>
117

    
118
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
119
<?php include("fbegin.inc"); ?>
120
<p class="pgtitle">Firewall: Traffic shaper</p>
121
<form action="firewall_shaper.php" method="post">
122
<?php if ($savemsg) print_info_box($savemsg); ?>
123
<?php if (file_exists($d_shaperconfdirty_path)): ?><p>
124
<?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>
125
<input name="apply" type="submit" class="formbtn" id="apply" value="Apply changes"></p>
126
<?php endif; ?>
127
<table width="100%" border="0" cellpadding="0" cellspacing="0">
128
  <tr><td>
129
  <ul id="tabnav">
130
    <li class="tabact">Rules</li>
131
    <li class="tabinact"><a href="firewall_shaper_pipes.php">Pipes</a></li>
132
    <li class="tabinact"><a href="firewall_shaper_queues.php">Queues</a></li>
133
    <li class="tabinact"><a href="firewall_shaper_magic.php">Magic shaper wizard</a></li>
134
  </ul>
135
  </td></tr>
136
  <tr>
137
    <td class="tabcont">
138
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
139
                <tr>
140
                  <td class="vtable"><p>
141
                      <input name="enable" type="checkbox" id="enable" value="yes" <?php if ($pconfig['enable'] == "yes") echo "checked";?>>
142
                      <strong>Enable traffic shaper<br>
143
                      </strong></p></td>
144
                </tr>
145
                <tr>
146
                  <td> <input name="submit" type="submit" class="formbtn" value="Save">
147
                  </td>
148
                </tr>
149
              </table>
150
              &nbsp;<br>
151
              <table width="100%" border="0" cellpadding="0" cellspacing="0">
152
                      <tr>
153
                        <td width="5%" class="listhdrrns">If</td>
154
                        <td width="5%" class="listhdrrns">Proto</td>
155
                        <td width="20%" class="listhdrr">Source</td>
156
                        <td width="20%" class="listhdrr">Destination</td>
157
                        <td width="15%" class="listhdrrns">Target</td>
158
                        <td width="25%" class="listhdr">Description</td>
159
                        <td width="10%" class="list"></td>
160
                      </tr>
161
                      <?php $i = 0; foreach ($a_shaper as $shaperent): ?>
162
                      <tr valign="top">
163
                        <td class="listlr">
164
                          <?php
165
				  $dis = "";
166
				  if (isset($shaperent['disabled'])) {
167
				  	$dis = "_d";
168
					$textss = "<span class=\"gray\">";
169
					$textse = "</span>";
170
				  } else {
171
				  	$textss = $textse = "";
172
				  }
173
				  $iflabels = array('lan' => 'LAN', 'wan' => 'WAN', 'pptp' => 'PPTP');
174
				  for ($j = 1; isset($config['interfaces']['opt' . $j]); $j++)
175
				  	$iflabels['opt' . $j] = $config['interfaces']['opt' . $j]['descr'];
176
				  echo $textss . htmlspecialchars($iflabels[$shaperent['interface']]);
177
				  echo "<br>";
178
				  echo "<a href=\"?act=toggle&id={$i}\">";
179
				  if ($shaperent['direction'] != "in")
180
				  	echo "<img src=\"out{$dis}.gif\" width=\"11\" height=\"11\" border=\"0\" style=\"margin-top: 5px\" title=\"click to toggle enabled/disabled status\">";
181
				  if ($shaperent['direction'] != "out")
182
				  	echo "<img src=\"in{$dis}.gif\" width=\"11\" height=\"11\" border=\"0\" style=\"margin-top: 5px\" title=\"click to toggle enabled/disabled status\">";
183
				  echo "</a>" . $textse;;
184
				  ?>
185
                        </td>
186
                        <td class="listr">
187
                          <?=$textss;?><?php if (isset($shaperent['protocol'])) echo strtoupper($shaperent['protocol']); else echo "*"; ?><?=$textse;?>
188
                        </td>
189
                        <td class="listr"><?=$textss;?><?php echo htmlspecialchars(pprint_address($shaperent['source'])); ?>
190
						<?php if ($shaperent['source']['port']): ?><br>
191
						Port: <?=htmlspecialchars(pprint_port($shaperent['source']['port'])); ?>
192
						<?php endif; ?><?=$textse;?>
193
                        </td>
194
                        <td class="listr"><?=$textss;?><?php echo htmlspecialchars(pprint_address($shaperent['destination'])); ?>
195
						<?php if ($shaperent['destination']['port']): ?><br>
196
						Port: <?=htmlspecialchars(pprint_port($shaperent['destination']['port'])); ?>
197
						<?php endif; ?><?=$textse;?>
198
                        </td>
199
                        <td class="listr"><?=$textss;?>
200
                          <?php
201
							if (isset($shaperent['targetpipe'])) {
202
								if ($a_pipe[$shaperent['targetpipe']]['descr'])
203
									$desc = htmlspecialchars($a_pipe[$shaperent['targetpipe']]['descr']);
204
								else
205
									$desc = "Pipe " . ($shaperent['targetpipe']+1);
206
								echo "<a href=\"firewall_shaper_pipes_edit.php?id={$shaperent['targetpipe']}\">{$desc}</a>";
207
							} else if (isset($shaperent['targetqueue'])) {
208
								if ($a_queue[$shaperent['targetqueue']]['descr'])
209
									$desc = htmlspecialchars($a_queue[$shaperent['targetqueue']]['descr']);
210
								else
211
									$desc = "Queue " . ($shaperent['targetqueue']+1);
212
								echo "<a href=\"firewall_shaper_queues_edit.php?id={$shaperent['targetqueue']}\">{$desc}</a>";
213
							}
214
						  ?><?=$textse;?>
215
                        </td>
216
                        <td class="listbg">
217
                          <?=$textss;?><?=htmlspecialchars($shaperent['descr']);?><?=$textse;?>
218
                          &nbsp; </td>
219
                        <td valign="middle" nowrap class="list"> <a href="firewall_shaper_edit.php?id=<?=$i;?>"><img src="e.gif" title="edit rule" width="17" height="17" border="0"></a>
220
                          <?php if ($i > 0): ?>
221
                          <a href="firewall_shaper.php?act=up&id=<?=$i;?>"><img src="up.gif" title="move up" width="17" height="17" border="0"></a>
222
                          <?php else: ?>
223
                          <img src="up_d.gif" width="17" height="17" border="0">
224
                          <?php endif; ?><br>
225
						  <a href="firewall_shaper.php?act=del&id=<?=$i;?>" onclick="return confirm('Do you really want to delete this rule?')"><img src="x.gif" title="delete rule" width="17" height="17" border="0"></a>
226
                          <?php if (isset($a_shaper[$i+1])): ?>
227
                          <a href="firewall_shaper.php?act=down&id=<?=$i;?>"><img src="down.gif" title="move down" width="17" height="17" border="0"></a>
228
                          <?php else: ?>
229
                          <img src="down_d.gif" width="17" height="17" border="0">
230
                          <?php endif; ?>
231
                          <a href="firewall_shaper_edit.php?dup=<?=$i;?>"><img src="plus.gif" title="add a new rule based on this one" width="17" height="17" border="0"></a>
232
                        </td>
233
                      </tr>
234
                      <?php $i++; endforeach; ?>
235
                      <tr>
236
                        <td class="list" colspan="6"></td>
237
                        <td class="list"> <a href="firewall_shaper_edit.php"><img src="plus.gif" width="17" height="17" border="0"></a></td>
238
                      </tr>
239
                    </table>
240

    
241
                    <table border="0" cellspacing="0" cellpadding="0">
242
                      <tr>
243
                        <td width="16"><img src="in.gif" width="11" height="11"></td>
244
                        <td>incoming (as seen by firewall)</td>
245
                        <td width="14"></td>
246
                        <td width="16"><img src="out.gif" width="11" height="11"></td>
247
                        <td>outgoing (as seen by firewall)</td>
248
                      </tr>
249
                      <tr>
250
                        <td colspan="5" height="4"></td>
251
                      </tr>
252
                      <tr>
253
                        <td><img src="in_d.gif" width="11" height="11"></td>
254
                        <td>incoming (disabled)</td>
255
                        <td width="14"></td>
256
                        <td><img src="out_d.gif" width="11" height="11"></td>
257
                        <td>outgoing (disabled)</td>
258
                      </tr>
259
                    </table>
260
			        <p><span class="red"><strong>Note:</strong></span><strong><br>
261
                    </strong>the first rule that matches a packet will be executed.<br>
262
                    The following match patterns are not shown in the list above:
263
                    IP packet length, TCP flags.</td>
264
	</tr>
265
</table>
266
            </form>
267
<?php include("fend.inc"); ?>
268
</body>
269
</html>
(30-30/86)