Project

General

Profile

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