Project

General

Profile

Download (11.5 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	interfaces_groups_edit.php
4

    
5
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
6
	Copyright (C) 2009 Ermal Luçi
7
	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
/*
32
	pfSense_BUILDER_BINARIES:	/sbin/ifconfig
33
	pfSense_MODULE:	interfaces
34
*/
35

    
36
##|+PRIV
37
##|*IDENT=page-interfaces-groups-edit
38
##|*NAME=Interfaces: Groups: Edit page
39
##|*DESCR=Allow access to the 'Interfaces: Groups: Edit' page.
40
##|*MATCH=interfaces_groups_edit.php*
41
##|-PRIV
42

    
43

    
44
require("guiconfig.inc");
45
require_once("functions.inc");
46

    
47
$pgtitle = array(gettext("Interfaces"),gettext("Groups"),gettext("Edit"));
48
$shortcut_section = "interfaces";
49

    
50
if (!is_array($config['ifgroups']['ifgroupentry']))
51
	$config['ifgroups']['ifgroupentry'] = array();
52

    
53
$a_ifgroups = &$config['ifgroups']['ifgroupentry'];
54

    
55
if (is_numericint($_GET['id']))
56
	$id = $_GET['id'];
57
if (isset($_POST['id']) && is_numericint($_POST['id']))
58
	$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
$iflist = get_configured_interface_with_descr();
67
$iflist_disabled = get_configured_interface_with_descr(false, true);
68

    
69
if ($_POST) {
70

    
71
	unset($input_errors);
72
	$pconfig = $_POST;
73

    
74
	if (!isset($id)) {
75
		foreach ($a_ifgroups as $groupentry)
76
			if ($groupentry['ifname'] == $_POST['ifname'])
77
				$input_errors[] = gettext("Group name already exists!");
78
	}
79
	if (preg_match("/([^a-zA-Z])+/", $_POST['ifname'], $match))
80
		$input_errors[] = gettext("Only letters A-Z are allowed as the group name.");
81

    
82
	foreach ($iflist as $gif => $gdescr) {
83
		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
	$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
		$ifgroupentry = array();
100
		$ifgroupentry['members'] = $members;
101
		$ifgroupentry['descr'] = $_POST['descr'];
102

    
103
		if (isset($id) && $a_ifgroups[$id] && $_POST['ifname'] != $a_ifgroups[$id]['ifname']) {
104
			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
						}
115
						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
					}
121
				}
122
			}
123
			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
			}
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
			$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
			$ifgroupentry['ifname'] = $_POST['ifname'];
151
			$a_ifgroups[$id] = $ifgroupentry;
152
		} else {
153
			$ifgroupentry['ifname'] = $_POST['ifname'];
154
			$a_ifgroups[] = $ifgroupentry;
155
		}
156

    
157
		write_config();
158

    
159
		interface_group_setup($ifgroupentry);
160

    
161
		header("Location: interfaces_groups.php");
162
		exit;
163
	} else {
164
		$pconfig['descr'] = $_POST['descr'];
165
		$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
<?php include("fbegin.inc"); ?>
175

    
176
<script type="text/javascript">
177
//<![CDATA[
178
// 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
                        $innerHTML="\"<input type='hidden' value='\" + totalrows +\"' name='\" + rowname[i] + \"_row-\" + totalrows + \"' /><select size='1' name='\" + rowname[i] + totalrows + \"'>\" +\"";
206

    
207
                        foreach ($iflist as $ifnam => $ifdescr)
208
                                $innerHTML .= "<option value='{$ifnam}'>{$ifdescr}<\/option>";
209
			$innerHTML .= "<\/select>\";";
210
                ?>
211
			td.innerHTML=<?=$innerHTML;?>
212
                tr.appendChild(td);
213
        }
214
        td = d.createElement("td");
215
        td.rowSpan = "1";
216

    
217
        td.innerHTML = '<a onclick="removeRow(this);return false;" href="#"><img border="0" src="/themes/' + theme + '/images/icons/icon_x.gif" alt="remove" /><\/a>';
218
        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
//]]>
243
</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
<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="interfaces groups edit">
251
  <tr>
252
	<td colspan="2" valign="top" class="listtopic"><?=gettext("Interface Groups Edit");?></td>
253
  </tr>
254
  <tr>
255
    <td valign="top" class="vncellreq"><?=gettext("Group Name");?></td>
256
    <td class="vtable">
257
	<input class="formfld unknown" name="ifname" id="ifname" maxlength="15" value="<?=htmlspecialchars($pconfig['ifname']);?>" />
258
	<br />
259
	<?=gettext("No numbers or spaces are allowed. Only characters in a-zA-Z");?>
260
    </td>
261
  </tr>
262
  <tr>
263
    <td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
264
    <td width="78%" class="vtable">
265
      <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
266
      <br />
267
      <span class="vexpl">
268
        <?=gettext("You may enter a description here for your reference (not parsed).");?>
269
      </span>
270
    </td>
271
  </tr>
272
  <tr>
273
    <td width="22%" valign="top" class="vncellreq"><div id="membersnetworkport"><?=gettext("Member (s)");?></div></td>
274
    <td width="78%" class="vtable">
275
      <table id="maintable" summary="main table">
276
        <tbody>
277
          <tr>
278
            <td><div id="onecolumn"><?=gettext("Interface");?></div></td>
279
          </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
				$found = false;
295
				foreach ($iflist as $ifnam => $ifdescr) {
296
					echo "<option value=\"{$ifnam}\"";
297
					if ($ifnam == $members) {
298
						$found = true;
299
						echo " selected=\"selected\"";
300
					}
301
					echo ">{$ifdescr}</option>";
302
				}
303

    
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
			?>
309
                        </select>
310
	</td>
311
        <td>
312
	<a onclick="removeRow(this); return false;" href="#"><img border="0" src="/themes/<?echo $g['theme'];?>/images/icons/icon_x.gif" alt="remove" /></a>
313
	      </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
        <img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" title="<?=gettext("add another entry");?>" />
325
      </a>
326
		<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
		</td>
331
  </tr>
332
  <tr>
333
    <td width="22%" valign="top">&nbsp;</td>
334
    <td width="78%">
335
      <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
      <?php if (isset($id) && $a_ifgroups[$id]): ?>
338
      <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
339
      <?php endif; ?>
340
    </td>
341
  </tr>
342
</table>
343
</form>
344

    
345
<script type="text/javascript">
346
//<![CDATA[
347
	field_counter_js = 1;
348
	rows = 1;
349
	totalrows = <?php echo $counter; ?>;
350
	loaded = <?php echo $counter; ?>;
351
//]]>
352
</script>
353

    
354
<?php
355
	unset($iflist);
356
	unset($iflist_disabled);
357
	include("fend.inc");
358
?>
359
</body>
360
</html>
(104-104/256)