Project

General

Profile

Download (11.5 KB) Statistics
| Branch: | Tag: | Revision:
1 0ec2fdf0 Ermal Lu?i
<?php
2
/*
3 dd447bde Jim Thompson
        Copyright (C) 2013-2014 Electric Sheep Fencing, LP
4 1d7ba683 ayvis
	Copyright (C) 2009 Ermal Luçi
5 0ec2fdf0 Ermal Lu?i
	Copyright (C) 2004 Scott Ullrich
6
	All rights reserved.
7
8
	Redistribution and use in source and binary forms, with or without
9
	modification, are permitted provided that the following conditions are met:
10
11
	1. Redistributions of source code must retain the above copyright notice,
12
	   this list of conditions and the following disclaimer.
13
14
	2. Redistributions in binary form must reproduce the above copyright
15
	   notice, this list of conditions and the following disclaimer in the
16
	   documentation and/or other materials provided with the distribution.
17
18
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
19
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
22
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
	POSSIBILITY OF SUCH DAMAGE.
28
*/
29 7ac5a4cb Scott Ullrich
/*
30
	pfSense_BUILDER_BINARIES:	/sbin/ifconfig
31
	pfSense_MODULE:	interfaces
32
*/
33 0ec2fdf0 Ermal Lu?i
34
##|+PRIV
35 7997ed44 Renato Botelho
##|*IDENT=page-interfaces-groups-edit
36 0ec2fdf0 Ermal Lu?i
##|*NAME=Interfaces: Groups: Edit page
37 7997ed44 Renato Botelho
##|*DESCR=Allow access to the 'Interfaces: Groups: Edit' page.
38 0ec2fdf0 Ermal Lu?i
##|*MATCH=interfaces_groups_edit.php*
39
##|-PRIV
40
41
42
require("guiconfig.inc");
43 6730eae1 Carlos Eduardo Ramos
require_once("functions.inc");
44
45
$pgtitle = array(gettext("Interfaces"),gettext("Groups"),gettext("Edit"));
46 b32dd0a6 jim-p
$shortcut_section = "interfaces";
47 0ec2fdf0 Ermal Lu?i
48
if (!is_array($config['ifgroups']['ifgroupentry']))
49
	$config['ifgroups']['ifgroupentry'] = array();
50
51
$a_ifgroups = &$config['ifgroups']['ifgroupentry'];
52
53 e41ec584 Renato Botelho
if (is_numericint($_GET['id']))
54 45316b1c Ermal Lu?i
	$id = $_GET['id'];
55 e41ec584 Renato Botelho
if (isset($_POST['id']) && is_numericint($_POST['id']))
56 0ec2fdf0 Ermal Lu?i
	$id = $_POST['id'];
57
58
if (isset($id) && $a_ifgroups[$id]) {
59
	$pconfig['ifname'] = $a_ifgroups[$id]['ifname'];
60
	$pconfig['members'] = $a_ifgroups[$id]['members'];
61
	$pconfig['descr'] = html_entity_decode($a_ifgroups[$id]['descr']);
62
}
63
64 6e73977b Renato Botelho
$iflist = get_configured_interface_with_descr();
65
$iflist_disabled = get_configured_interface_with_descr(false, true);
66
67 0ec2fdf0 Ermal Lu?i
if ($_POST) {
68
69
	unset($input_errors);
70
	$pconfig = $_POST;
71
72 45316b1c Ermal Lu?i
	if (!isset($id)) {
73 42753d25 Ermal Lu?i
		foreach ($a_ifgroups as $groupentry)
74
			if ($groupentry['ifname'] == $_POST['ifname'])
75 6730eae1 Carlos Eduardo Ramos
				$input_errors[] = gettext("Group name already exists!");
76 42753d25 Ermal Lu?i
	}
77
	if (preg_match("/([^a-zA-Z])+/", $_POST['ifname'], $match))
78 a9a7a131 Rafael Lucas
		$input_errors[] = gettext("Only letters A-Z are allowed as the group name.");
79 0ec2fdf0 Ermal Lu?i
80 6e73977b Renato Botelho
	foreach ($iflist as $gif => $gdescr) {
81 4a71c087 Ermal
		if ($gdescr == $_POST['ifname'] || $gif == $_POST['ifname'])
82
			$input_errors[] = "The specified group name is already used by an interface. Please choose another name.";
83
	}
84 0ec2fdf0 Ermal Lu?i
	$members = "";
85
	$isfirst = 0;
86
	/* item is a normal ifgroupentry type */
87
	for($x=0; $x<9999; $x++) {
88
		if($_POST["members{$x}"] <> "") {
89
			if ($isfirst > 0)
90
				$members .= " ";
91
			$members .= $_POST["members{$x}"];
92
			$isfirst++;
93
		}
94
	}
95
96
	if (!$input_errors) {
97 62663b54 Ermal
		$ifgroupentry = array();
98 0ec2fdf0 Ermal Lu?i
		$ifgroupentry['members'] = $members;
99 d865241e jim-p
		$ifgroupentry['descr'] = $_POST['descr'];
100 0ec2fdf0 Ermal Lu?i
101 62663b54 Ermal
		if (isset($id) && $a_ifgroups[$id] && $_POST['ifname'] != $a_ifgroups[$id]['ifname']) {
102 4d3c8697 Ermal
			if (!empty($config['filter']) && is_array($config['filter']['rule'])) {
103
				foreach ($config['filter']['rule'] as $ridx => $rule) {
104
					if (isset($rule['floating'])) {
105
						$rule_ifs = explode(",", $rule['interface']);
106
						$rule_changed = false;
107
						foreach ($rule_ifs as $rule_if_id => $rule_if) {
108
							if ($rule_if == $a_ifgroups[$id]['ifname']) {
109
								$rule_ifs[$rule_if_id] = $_POST['ifname'];
110
								$rule_changed = true;
111
							}
112 22d0d529 Erik Fonnesbeck
						}
113 4d3c8697 Ermal
						if ($rule_changed)
114
							$config['filter']['rule'][$ridx]['interface'] = implode(",", $rule_ifs);
115
					} else {
116
						if ($rule['interface'] == $a_ifgroups[$id]['ifname'])
117
							$config['filter']['rule'][$ridx]['interface'] = $_POST['ifname'];
118 22d0d529 Erik Fonnesbeck
					}
119
				}
120 62663b54 Ermal
			}
121 4d3c8697 Ermal
			if (!empty($config['nat']) && is_array($config['nat']['rule'])) {
122
				foreach ($config['nat']['rule'] as $ridx => $rule) {
123
					if ($rule['interface'] == $a_ifgroups[$id]['ifname'])
124
						$config['nat']['rule'][$ridx]['interface'] = $_POST['ifname'];
125
				}
126 62663b54 Ermal
			}
127
			$omembers = explode(" ", $a_ifgroups[$id]['members']);
128
			if (count($omembers) > 0) {
129
				foreach ($omembers as $ifs) {
130
					$realif = get_real_interface($ifs);
131
					if ($realif)
132
						mwexec("/sbin/ifconfig {$realif} -group " . $a_ifgroups[$id]['ifname']);
133
				}
134
			}
135
			$ifgroupentry['ifname'] = $_POST['ifname'];
136
			$a_ifgroups[$id] = $ifgroupentry;
137
		} else if (isset($id) && $a_ifgroups[$id]) {
138 42753d25 Ermal Lu?i
			$omembers = explode(" ", $a_ifgroups[$id]['members']);
139
			$nmembers = explode(" ", $members);
140
			$delmembers = array_diff($omembers, $nmembers);
141
			if (count($delmembers) > 0) {
142
				foreach ($delmembers as $ifs) {
143
					$realif = get_real_interface($ifs);
144
					if ($realif)
145
						mwexec("/sbin/ifconfig {$realif} -group " . $a_ifgroups[$id]['ifname']);
146
				}
147
			}
148 62663b54 Ermal
			$ifgroupentry['ifname'] = $_POST['ifname'];
149 0ec2fdf0 Ermal Lu?i
			$a_ifgroups[$id] = $ifgroupentry;
150 62663b54 Ermal
		} else {
151
			$ifgroupentry['ifname'] = $_POST['ifname'];
152 0ec2fdf0 Ermal Lu?i
			$a_ifgroups[] = $ifgroupentry;
153 62663b54 Ermal
		}
154 0ec2fdf0 Ermal Lu?i
155
		write_config();
156
157 42753d25 Ermal Lu?i
		interface_group_setup($ifgroupentry);
158
159 0ec2fdf0 Ermal Lu?i
		header("Location: interfaces_groups.php");
160
		exit;
161
	} else {
162 d865241e jim-p
		$pconfig['descr'] = $_POST['descr'];
163 0ec2fdf0 Ermal Lu?i
		$pconfig['members'] = $members;
164
	}
165
}
166
167
include("head.inc");
168
169
?>
170
171
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
172 5e3a7e82 Colin Fleming
<?php include("fbegin.inc"); ?>
173 0ec2fdf0 Ermal Lu?i
174
<script type="text/javascript">
175 5e3a7e82 Colin Fleming
//<![CDATA[
176 0ec2fdf0 Ermal Lu?i
// Global Variables
177
var rowname = new Array(9999);
178
var rowtype = new Array(9999);
179
var newrow  = new Array(9999);
180
var rowsize = new Array(9999);
181
182
for (i = 0; i < 9999; i++) {
183
        rowname[i] = '';
184
        rowtype[i] = 'select';
185
        newrow[i] = '';
186
        rowsize[i] = '30';
187
}
188
189
var field_counter_js = 0;
190
var loaded = 0;
191
var is_streaming_progress_bar = 0;
192
var temp_streaming_text = "";
193
194
var addRowTo = (function() {
195
    return (function (tableId) {
196
        var d, tbody, tr, td, bgc, i, ii, j;
197
        d = document;
198
        tbody = d.getElementById(tableId).getElementsByTagName("tbody").item(0);
199
        tr = d.createElement("tr");
200
        for (i = 0; i < field_counter_js; i++) {
201
                td = d.createElement("td");
202
		<?php
203 5e3a7e82 Colin Fleming
                        $innerHTML="\"<input type='hidden' value='\" + totalrows +\"' name='\" + rowname[i] + \"_row-\" + totalrows + \"' /><select size='1' name='\" + rowname[i] + totalrows + \"'>\" +\"";
204 0ec2fdf0 Ermal Lu?i
205
                        foreach ($iflist as $ifnam => $ifdescr)
206 329bb072 Colin Fleming
                                $innerHTML .= "<option value='{$ifnam}'>{$ifdescr}<\/option>";
207
			$innerHTML .= "<\/select>\";";
208 0ec2fdf0 Ermal Lu?i
                ?>
209
			td.innerHTML=<?=$innerHTML;?>
210
                tr.appendChild(td);
211
        }
212
        td = d.createElement("td");
213
        td.rowSpan = "1";
214
215 329bb072 Colin Fleming
        td.innerHTML = '<a onclick="removeRow(this);return false;" href="#"><img border="0" src="/themes/' + theme + '/images/icons/icon_x.gif" alt="remove" /><\/a>';
216 0ec2fdf0 Ermal Lu?i
        tr.appendChild(td);
217
        tbody.appendChild(tr);
218
        totalrows++;
219
    });
220
})();
221
222
function removeRow(el) {
223
    var cel;
224
    while (el && el.nodeName.toLowerCase() != "tr")
225
            el = el.parentNode;
226
227
    if (el && el.parentNode) {
228
        cel = el.getElementsByTagName("td").item(0);
229
        el.parentNode.removeChild(el);
230
    }
231
}
232
233
	rowname[0] = "members";
234
	rowtype[0] = "textbox";
235
	rowsize[0] = "30";
236
237
	rowname[2] = "detail";
238
	rowtype[2] = "textbox";
239
	rowsize[2] = "50";
240 5e3a7e82 Colin Fleming
//]]>
241 0ec2fdf0 Ermal Lu?i
</script>
242
<input type='hidden' name='members_type' value='textbox' class="formfld unknown" />
243
244
<?php if ($input_errors) print_input_errors($input_errors); ?>
245
<div id="inputerrors"></div>
246
247
<form action="interfaces_groups_edit.php" method="post" name="iform" id="iform">
248 5e3a7e82 Colin Fleming
<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="interfaces groups edit">
249 0ec2fdf0 Ermal Lu?i
  <tr>
250 a9a7a131 Rafael Lucas
	<td colspan="2" valign="top" class="listtopic"><?=gettext("Interface Groups Edit");?></td>
251 0ec2fdf0 Ermal Lu?i
  </tr>
252
  <tr>
253 a9a7a131 Rafael Lucas
    <td valign="top" class="vncellreq"><?=gettext("Group Name");?></td>
254 0ec2fdf0 Ermal Lu?i
    <td class="vtable">
255 6a0f34b8 Renato Botelho
	<input class="formfld unknown" name="ifname" id="ifname" maxlength="15" value="<?=htmlspecialchars($pconfig['ifname']);?>" />
256 42753d25 Ermal Lu?i
	<br />
257 a9a7a131 Rafael Lucas
	<?=gettext("No numbers or spaces are allowed. Only characters in a-zA-Z");?>
258 0ec2fdf0 Ermal Lu?i
    </td>
259
  </tr>
260
  <tr>
261 a9a7a131 Rafael Lucas
    <td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
262 0ec2fdf0 Ermal Lu?i
    <td width="78%" class="vtable">
263 dd5bf424 Scott Ullrich
      <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
264 0ec2fdf0 Ermal Lu?i
      <br />
265
      <span class="vexpl">
266 a9a7a131 Rafael Lucas
        <?=gettext("You may enter a description here for your reference (not parsed).");?>
267 0ec2fdf0 Ermal Lu?i
      </span>
268
    </td>
269
  </tr>
270
  <tr>
271 a9a7a131 Rafael Lucas
    <td width="22%" valign="top" class="vncellreq"><div id="membersnetworkport"><?=gettext("Member (s)");?></div></td>
272 0ec2fdf0 Ermal Lu?i
    <td width="78%" class="vtable">
273 5e3a7e82 Colin Fleming
      <table id="maintable" summary="main table">
274 0ec2fdf0 Ermal Lu?i
        <tbody>
275
          <tr>
276 a9a7a131 Rafael Lucas
            <td><div id="onecolumn"><?=gettext("Interface");?></div></td>
277 0ec2fdf0 Ermal Lu?i
          </tr>
278
279
	<?php
280
	$counter = 0;
281
	$members = $pconfig['members'];
282
	if ($members <> "") {
283
		$item = explode(" ", $members);
284
		foreach($item as $ww) {
285
			$members = $item[$counter];
286
			$tracker = $counter;
287
	?>
288
        <tr>
289
	<td class="vtable">
290
	        <select name="members<?php echo $tracker; ?>" class="formselect" id="members<?php echo $tracker; ?>">
291
			<?php
292 6e73977b Renato Botelho
				$found = false;
293 0ec2fdf0 Ermal Lu?i
				foreach ($iflist as $ifnam => $ifdescr) {
294 5e3a7e82 Colin Fleming
					echo "<option value=\"{$ifnam}\"";
295 6e73977b Renato Botelho
					if ($ifnam == $members) {
296
						$found = true;
297 5e3a7e82 Colin Fleming
						echo " selected=\"selected\"";
298 6e73977b Renato Botelho
					}
299 0ec2fdf0 Ermal Lu?i
					echo ">{$ifdescr}</option>";
300
				}
301 6e73977b Renato Botelho
302
				if ($found === false)
303
					foreach ($iflist_disabled as $ifnam => $ifdescr)
304
						if ($ifnam == $members)
305
							echo "<option value=\"{$ifnam}\" selected=\"selected\">{$ifdescr}</option>";
306 0ec2fdf0 Ermal Lu?i
			?>
307
                        </select>
308
	</td>
309
        <td>
310 5e3a7e82 Colin Fleming
	<a onclick="removeRow(this); return false;" href="#"><img border="0" src="/themes/<?echo $g['theme'];?>/images/icons/icon_x.gif" alt="remove" /></a>
311 0ec2fdf0 Ermal Lu?i
	      </td>
312
          </tr>
313
<?php
314
		$counter++;
315
316
		} // end foreach
317
	} // end if
318
?>
319
        </tbody>
320
		  </table>
321
			<a onclick="javascript:addRowTo('maintable'); return false;" href="#">
322 a9a7a131 Rafael Lucas
        <img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" title="<?=gettext("add another entry");?>" />
323 0ec2fdf0 Ermal Lu?i
      </a>
324 5d14b13e jim-p
		<br /><br />
325
		<strong><?PHP echo gettext("NOTE:");?></strong>
326
		<?PHP echo gettext("Rules for WAN type interfaces in groups do not contain the reply-to mechanism upon which Multi-WAN typically relies.");?>
327
		<a href="https://doc.pfsense.org/index.php/Interface_Groups"><?PHP echo gettext("More Information");?></a>
328 0ec2fdf0 Ermal Lu?i
		</td>
329
  </tr>
330
  <tr>
331
    <td width="22%" valign="top">&nbsp;</td>
332
    <td width="78%">
333 a9a7a131 Rafael Lucas
      <input id="submit" name="submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
334
      <a href="interfaces_groups.php"><input id="cancelbutton" name="cancelbutton" type="button" class="formbtn" value="<?=gettext("Cancel");?>" /></a>
335 0ec2fdf0 Ermal Lu?i
      <?php if (isset($id) && $a_ifgroups[$id]): ?>
336 225a2f0b Scott Ullrich
      <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
337 0ec2fdf0 Ermal Lu?i
      <?php endif; ?>
338
    </td>
339
  </tr>
340
</table>
341
</form>
342
343
<script type="text/javascript">
344 5e3a7e82 Colin Fleming
//<![CDATA[
345 0ec2fdf0 Ermal Lu?i
	field_counter_js = 1;
346
	rows = 1;
347
	totalrows = <?php echo $counter; ?>;
348
	loaded = <?php echo $counter; ?>;
349 5e3a7e82 Colin Fleming
//]]>
350 0ec2fdf0 Ermal Lu?i
</script>
351
352 36b9bb28 Renato Botelho
<?php
353
	unset($iflist);
354
	unset($iflist_disabled);
355
	include("fend.inc");
356
?>
357 0ec2fdf0 Ermal Lu?i
</body>
358
</html>