Project

General

Profile

Download (7.49 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	firewall_shaper_queues.php
5
	Copyright (C) 2004, 2005 Scott Ullrich
6
	Copyright (C) 2008 Ermal Lu?i
7
	All rights reserved.
8

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

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

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

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

    
31
require("guiconfig.inc");
32

    
33
if($_GET['reset'] <> "") {
34
	mwexec("killall -9 pfctl php");
35
	exit;
36
}
37

    
38
read_altq_config();
39
$qlist =& get_unique_queue_list();
40

    
41
if (!is_array($qlist)) 
42
	$qlist = array();
43

    
44
$tree = "<ul class=\"tree\" >";
45
foreach ($qlist as $queue => $qkey) {
46
	$tree .= "<li><a href=\"firewall_shaper_queues.php?queue={$queue}&action=show\" >{$queue}</a></li>";
47
}
48
$tree .= "</ul>";
49

    
50
if ($_GET) {
51
	if ($_GET['queue'])
52
        	$qname = trim($_GET['queue']);
53
        if ($_GET['interface'])
54
                $interface = trim($_GET['interface']);
55
        if ($_GET['action'])
56
                $action = $_GET['action'];
57

    
58
	switch ($action) {
59
	case "delete":
60
			$altq =& $altq_list_queues[$interface];
61
			$qtmp =& $altq->find_queue("", $qname);
62
			if ($qtmp) {
63
				$qtmp->delete_queue(); 
64
				write_config();
65
				touch($d_shaperconfdirty_path);
66
			}
67
			header("Location: firewall_shaper_queues.php");
68
			exit;
69
		break;
70
	case "add":
71
			/* 
72
			 * XXX: WARNING: This returns the first it finds.
73
			 * Maybe the user expects something else?!
74
			 */
75
                        foreach ($altq_list_queues as $altq) {
76
                                $qtmp =& $altq->find_queue("", $qname);
77
                                if ($qtmp) {
78
                                        $copycfg = array();
79
                                        $qtmp->copy_queue($interface, &$copycfg);
80
                                        $aq =& $altq_list_queues[$interface];
81
					if ($qname == $qtmp->GetInterface()) {
82
                                                $config['shaper']['queue'][] = $copycfg;
83
                                        } else if ($aq) {
84
                                                $tmp1 =& $qtmp->find_parentqueue($interface, $qname);
85
                                                if ($tmp1) 
86
                                                        $tmp =& $aq->find_queue($interface, $tmp1->GetQname());
87

    
88
                                                if ($tmp)
89
                                                        $link =& get_reference_to_me_in_config($tmp->GetLink());
90
                                                else
91
                                                        $link =& get_reference_to_me_in_config($aq->GetLink());
92
                                                $link['queue'][] = $copycfg;
93
                                        } else {
94
                                                $newroot = array();
95
                                                $newroot['name'] = $interface;
96
                                                $newroot['interface'] = $interface;
97
                                                $newroot['scheduler'] = $altq->GetScheduler();
98
                                                $newroot['queue'] = array();
99
                                                $newroot['queue'][] = $copycfg;
100
                                                $config['shaper']['queue'][] = $newroot;
101
                                        }
102
                                        write_config();
103
                                        touch($d_shaperconfdirty_path);
104
                                        break;
105
                                }
106
                        }
107

    
108
			header("Location: firewall_shaper_queues.php?queue=".$qname."&action=show");
109
			exit;
110
		break;
111
	case "show":
112
			$iflist = get_interface_list();
113
			foreach ($iflist as $if) {
114
				$altq = $altq_list_queues[$if['friendly']];
115
				if ($altq) {
116
					$qtmp =& $altq->find_queue("", $qname);
117
					if ($qtmp) 
118
						$output .= $qtmp->build_shortform();
119
					else
120
						$output .= build_iface_without_this_queue($if['friendly'], $qname);
121
				} else 
122
					$output .= build_iface_without_this_queue($if['friendly'], $qname);
123
			}	
124
		break;
125
	}
126
}
127

    
128
if ($_POST['apply']) {
129
          write_config();
130

    
131
          $retval = 0;
132
         $savemsg = get_std_save_message($retval);
133
        /* Setup pf rules since the user may have changed the optimization value */
134

    
135
                        config_lock();
136
                        $retval = filter_configure();
137
                        config_unlock();
138
                        if (stristr($retval, "error") <> true)
139
                                $savemsg = get_std_save_message($retval);
140
                        else
141
                                $savemsg = $retval;
142

    
143
 		/* reset rrd queues */
144
                system("rm -f /var/db/rrd/*queuedrops.rrd");
145
                system("rm -f /var/db/rrd/*queues.rrd");
146
			enable_rrd_graphing();
147

    
148
            unlink($d_shaperconfdirty_path);
149
}
150

    
151
$pgtitle = "Firewall: Shaper: By Queues View";
152

    
153
include("head.inc");
154
?>
155
<link rel="stylesheet" type="text/css" media="all" href="./tree/tree.css" />
156
<script type="text/javascript" src="./tree/tree.js"></script>
157

    
158
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
159
<?php include("fbegin.inc"); ?>
160
<div id="inputerrors"></div>
161
<?php if ($input_errors) print_input_errors($input_errors); ?>
162
<form action="firewall_shaper_queues.php" method="post" name="iform" id="iform">
163
<?php if ($savemsg) print_info_box($savemsg); ?>
164
<?php if (file_exists($d_shaperconfdirty_path)): ?><p>
165
<?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>
166
<?php endif; ?>
167
<table width="100%" border="0" cellpadding="0" cellspacing="0">
168
  <tr><td>
169
<?php
170
	$tab_array = array();
171
	$tab_array[0] = array("By Interface", false, "firewall_shaper.php");
172
	$tab_array[1] = array("By Queue", true, "firewall_shaper_queues.php");
173
	$tab_array[2] = array("Wizards", false, "firewall_shaper_wizards.php");
174
	display_top_tabs($tab_array);
175
?>
176
  </td></tr>
177
  <tr> 
178
    <td valign="top">
179
	<div id="mainarea">
180
		<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
181
		<tr>
182
		<td width="30%" valign="top" algin="left">
183
                <?      echo $tree; ?>
184
		</td>
185
		<td width="70%" valign="top" align="center">
186
			<? 
187
				if ($qname)
188
        				echo "<pr class=\"pgtitle\">" . $qname . "</pr><br />";
189
				echo "<table align=\"center\" class=\"tabcont\" width=\"80%\" border=\"0\" cellpadding=\"4\" cellspacing=\"0\">";
190
				echo $output;
191
				echo "</table>";
192
			?>	
193
			</td></tr>
194
			</table>
195

    
196
		      </td></tr>
197
		</div>
198
	  </td>
199
	</tr>
200
</table>
201
            </form>
202
<?php include("fend.inc"); 
203
?>
204
</body>
205
</html>
(56-56/193)