Project

General

Profile

Download (11.5 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
        Copyright (C) 2013-2014 Electric Sheep Fencing, LP
4
	Copyright (C) 2009 Ermal Luçi
5
	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
/*
30
	pfSense_BUILDER_BINARIES:	/sbin/ifconfig
31
	pfSense_MODULE:	interfaces
32
*/
33

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

    
41

    
42
require("guiconfig.inc");
43
require_once("functions.inc");
44

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

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

    
51
$a_ifgroups = &$config['ifgroups']['ifgroupentry'];
52

    
53
if (is_numericint($_GET['id']))
54
	$id = $_GET['id'];
55
if (isset($_POST['id']) && is_numericint($_POST['id']))
56
	$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
$iflist = get_configured_interface_with_descr();
65
$iflist_disabled = get_configured_interface_with_descr(false, true);
66

    
67
if ($_POST) {
68

    
69
	unset($input_errors);
70
	$pconfig = $_POST;
71

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

    
80
	foreach ($iflist as $gif => $gdescr) {
81
		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
	$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
		$ifgroupentry = array();
98
		$ifgroupentry['members'] = $members;
99
		$ifgroupentry['descr'] = $_POST['descr'];
100

    
101
		if (isset($id) && $a_ifgroups[$id] && $_POST['ifname'] != $a_ifgroups[$id]['ifname']) {
102
			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
						}
113
						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
					}
119
				}
120
			}
121
			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
			}
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
			$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
			$ifgroupentry['ifname'] = $_POST['ifname'];
149
			$a_ifgroups[$id] = $ifgroupentry;
150
		} else {
151
			$ifgroupentry['ifname'] = $_POST['ifname'];
152
			$a_ifgroups[] = $ifgroupentry;
153
		}
154

    
155
		write_config();
156

    
157
		interface_group_setup($ifgroupentry);
158

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

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

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

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

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

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

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