Project

General

Profile

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