Project

General

Profile

Download (11.4 KB) Statistics
| Branch: | Tag: | Revision:

univnautes / usr / local / www / interfaces_groups_edit.php @ a1b66bec

1
<?php
2
/*
3
	Copyright (C) 2009 Ermal Luçi
4
	Copyright (C) 2004 Scott Ullrich
5
	All rights reserved.
6

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

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

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

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

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

    
40

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

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

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

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

    
52
if (is_numericint($_GET['id']))
53
	$id = $_GET['id'];
54
if (isset($_POST['id']) && is_numericint($_POST['id']))
55
	$id = $_POST['id'];
56

    
57
if (isset($id) && $a_ifgroups[$id]) {
58
	$pconfig['ifname'] = $a_ifgroups[$id]['ifname'];
59
	$pconfig['members'] = $a_ifgroups[$id]['members'];
60
	$pconfig['descr'] = html_entity_decode($a_ifgroups[$id]['descr']);
61
}
62

    
63
$iflist = get_configured_interface_with_descr();
64
$iflist_disabled = get_configured_interface_with_descr(false, true);
65

    
66
if ($_POST) {
67

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

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

    
79
	foreach ($iflist as $gif => $gdescr) {
80
		if ($gdescr == $_POST['ifname'] || $gif == $_POST['ifname'])
81
			$input_errors[] = "The specified group name is already used by an interface. Please choose another name.";
82
	}
83
	$members = "";
84
	$isfirst = 0;
85
	/* item is a normal ifgroupentry type */
86
	for($x=0; $x<9999; $x++) {
87
		if($_POST["members{$x}"] <> "") {
88
			if ($isfirst > 0)
89
				$members .= " ";
90
			$members .= $_POST["members{$x}"];
91
			$isfirst++;
92
		}
93
	}
94

    
95
	if (!$input_errors) {
96
		$ifgroupentry = array();
97
		$ifgroupentry['members'] = $members;
98
		$ifgroupentry['descr'] = $_POST['descr'];
99

    
100
		if (isset($id) && $a_ifgroups[$id] && $_POST['ifname'] != $a_ifgroups[$id]['ifname']) {
101
			if (!empty($config['filter']) && is_array($config['filter']['rule'])) {
102
				foreach ($config['filter']['rule'] as $ridx => $rule) {
103
					if (isset($rule['floating'])) {
104
						$rule_ifs = explode(",", $rule['interface']);
105
						$rule_changed = false;
106
						foreach ($rule_ifs as $rule_if_id => $rule_if) {
107
							if ($rule_if == $a_ifgroups[$id]['ifname']) {
108
								$rule_ifs[$rule_if_id] = $_POST['ifname'];
109
								$rule_changed = true;
110
							}
111
						}
112
						if ($rule_changed)
113
							$config['filter']['rule'][$ridx]['interface'] = implode(",", $rule_ifs);
114
					} else {
115
						if ($rule['interface'] == $a_ifgroups[$id]['ifname'])
116
							$config['filter']['rule'][$ridx]['interface'] = $_POST['ifname'];
117
					}
118
				}
119
			}
120
			if (!empty($config['nat']) && is_array($config['nat']['rule'])) {
121
				foreach ($config['nat']['rule'] as $ridx => $rule) {
122
					if ($rule['interface'] == $a_ifgroups[$id]['ifname'])
123
						$config['nat']['rule'][$ridx]['interface'] = $_POST['ifname'];
124
				}
125
			}
126
			$omembers = explode(" ", $a_ifgroups[$id]['members']);
127
			if (count($omembers) > 0) {
128
				foreach ($omembers as $ifs) {
129
					$realif = get_real_interface($ifs);
130
					if ($realif)
131
						mwexec("/sbin/ifconfig {$realif} -group " . $a_ifgroups[$id]['ifname']);
132
				}
133
			}
134
			$ifgroupentry['ifname'] = $_POST['ifname'];
135
			$a_ifgroups[$id] = $ifgroupentry;
136
		} else if (isset($id) && $a_ifgroups[$id]) {
137
			$omembers = explode(" ", $a_ifgroups[$id]['members']);
138
			$nmembers = explode(" ", $members);
139
			$delmembers = array_diff($omembers, $nmembers);
140
			if (count($delmembers) > 0) {
141
				foreach ($delmembers as $ifs) {
142
					$realif = get_real_interface($ifs);
143
					if ($realif)
144
						mwexec("/sbin/ifconfig {$realif} -group " . $a_ifgroups[$id]['ifname']);
145
				}
146
			}
147
			$ifgroupentry['ifname'] = $_POST['ifname'];
148
			$a_ifgroups[$id] = $ifgroupentry;
149
		} else {
150
			$ifgroupentry['ifname'] = $_POST['ifname'];
151
			$a_ifgroups[] = $ifgroupentry;
152
		}
153

    
154
		write_config();
155

    
156
		interface_group_setup($ifgroupentry);
157

    
158
		header("Location: interfaces_groups.php");
159
		exit;
160
	} else {
161
		$pconfig['descr'] = $_POST['descr'];
162
		$pconfig['members'] = $members;
163
	}
164
}
165

    
166
include("head.inc");
167

    
168
?>
169

    
170
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
171
<?php include("fbegin.inc"); ?>
172

    
173
<script type="text/javascript">
174
//<![CDATA[
175
// Global Variables
176
var rowname = new Array(9999);
177
var rowtype = new Array(9999);
178
var newrow  = new Array(9999);
179
var rowsize = new Array(9999);
180

    
181
for (i = 0; i < 9999; i++) {
182
        rowname[i] = '';
183
        rowtype[i] = 'select';
184
        newrow[i] = '';
185
        rowsize[i] = '30';
186
}
187

    
188
var field_counter_js = 0;
189
var loaded = 0;
190
var is_streaming_progress_bar = 0;
191
var temp_streaming_text = "";
192

    
193
var addRowTo = (function() {
194
    return (function (tableId) {
195
        var d, tbody, tr, td, bgc, i, ii, j;
196
        d = document;
197
        tbody = d.getElementById(tableId).getElementsByTagName("tbody").item(0);
198
        tr = d.createElement("tr");
199
        for (i = 0; i < field_counter_js; i++) {
200
                td = d.createElement("td");
201
		<?php
202
                        $innerHTML="\"<input type='hidden' value='\" + totalrows +\"' name='\" + rowname[i] + \"_row-\" + totalrows + \"' /><select size='1' name='\" + rowname[i] + totalrows + \"'>\" +\"";
203

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

    
214
        td.innerHTML = '<a onclick="removeRow(this);return false;" href="#"><img border="0" src="/themes/' + theme + '/images/icons/icon_x.gif" alt="remove" /><\/a>';
215
        tr.appendChild(td);
216
        tbody.appendChild(tr);
217
        totalrows++;
218
    });
219
})();
220

    
221
function removeRow(el) {
222
    var cel;
223
    while (el && el.nodeName.toLowerCase() != "tr")
224
            el = el.parentNode;
225

    
226
    if (el && el.parentNode) {
227
        cel = el.getElementsByTagName("td").item(0);
228
        el.parentNode.removeChild(el);
229
    }
230
}
231

    
232
	rowname[0] = "members";
233
	rowtype[0] = "textbox";
234
	rowsize[0] = "30";
235

    
236
	rowname[2] = "detail";
237
	rowtype[2] = "textbox";
238
	rowsize[2] = "50";
239
//]]>
240
</script>
241
<input type='hidden' name='members_type' value='textbox' class="formfld unknown" />
242

    
243
<?php if ($input_errors) print_input_errors($input_errors); ?>
244
<div id="inputerrors"></div>
245

    
246
<form action="interfaces_groups_edit.php" method="post" name="iform" id="iform">
247
<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="interfaces groups edit">
248
  <tr>
249
	<td colspan="2" valign="top" class="listtopic"><?=gettext("Interface Groups Edit");?></td>
250
  </tr>
251
  <tr>
252
    <td valign="top" class="vncellreq"><?=gettext("Group Name");?></td>
253
    <td class="vtable">
254
	<input class="formfld unknown" name="ifname" id="ifname" maxlength="15" value="<?=htmlspecialchars($pconfig['ifname']);?>" />
255
	<br />
256
	<?=gettext("No numbers or spaces are allowed. Only characters in a-zA-Z");?>
257
    </td>
258
  </tr>
259
  <tr>
260
    <td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
261
    <td width="78%" class="vtable">
262
      <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
263
      <br />
264
      <span class="vexpl">
265
        <?=gettext("You may enter a description here for your reference (not parsed).");?>
266
      </span>
267
    </td>
268
  </tr>
269
  <tr>
270
    <td width="22%" valign="top" class="vncellreq"><div id="membersnetworkport"><?=gettext("Member (s)");?></div></td>
271
    <td width="78%" class="vtable">
272
      <table id="maintable" summary="main table">
273
        <tbody>
274
          <tr>
275
            <td><div id="onecolumn"><?=gettext("Interface");?></div></td>
276
          </tr>
277

    
278
	<?php
279
	$counter = 0;
280
	$members = $pconfig['members'];
281
	if ($members <> "") {
282
		$item = explode(" ", $members);
283
		foreach($item as $ww) {
284
			$members = $item[$counter];
285
			$tracker = $counter;
286
	?>
287
        <tr>
288
	<td class="vtable">
289
	        <select name="members<?php echo $tracker; ?>" class="formselect" id="members<?php echo $tracker; ?>">
290
			<?php
291
				$found = false;
292
				foreach ($iflist as $ifnam => $ifdescr) {
293
					echo "<option value=\"{$ifnam}\"";
294
					if ($ifnam == $members) {
295
						$found = true;
296
						echo " selected=\"selected\"";
297
					}
298
					echo ">{$ifdescr}</option>";
299
				}
300

    
301
				if ($found === false)
302
					foreach ($iflist_disabled as $ifnam => $ifdescr)
303
						if ($ifnam == $members)
304
							echo "<option value=\"{$ifnam}\" selected=\"selected\">{$ifdescr}</option>";
305
			?>
306
                        </select>
307
	</td>
308
        <td>
309
	<a onclick="removeRow(this); return false;" href="#"><img border="0" src="/themes/<?echo $g['theme'];?>/images/icons/icon_x.gif" alt="remove" /></a>
310
	      </td>
311
          </tr>
312
<?php
313
		$counter++;
314

    
315
		} // end foreach
316
	} // end if
317
?>
318
        </tbody>
319
		  </table>
320
			<a onclick="javascript:addRowTo('maintable'); return false;" href="#">
321
        <img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" title="<?=gettext("add another entry");?>" />
322
      </a>
323
		<br /><br />
324
		<strong><?PHP echo gettext("NOTE:");?></strong>
325
		<?PHP echo gettext("Rules for WAN type interfaces in groups do not contain the reply-to mechanism upon which Multi-WAN typically relies.");?>
326
		<a href="https://doc.pfsense.org/index.php/Interface_Groups"><?PHP echo gettext("More Information");?></a>
327
		</td>
328
  </tr>
329
  <tr>
330
    <td width="22%" valign="top">&nbsp;</td>
331
    <td width="78%">
332
      <input id="submit" name="submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
333
      <a href="interfaces_groups.php"><input id="cancelbutton" name="cancelbutton" type="button" class="formbtn" value="<?=gettext("Cancel");?>" /></a>
334
      <?php if (isset($id) && $a_ifgroups[$id]): ?>
335
      <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
336
      <?php endif; ?>
337
    </td>
338
  </tr>
339
</table>
340
</form>
341

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

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