Project

General

Profile

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