Project

General

Profile

Download (8.7 KB) Statistics
| Branch: | Tag: | Revision:
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-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
if (isset($_GET['id']))
50
	$id = $_GET['id'];
51
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
	if (!isset($id)) {
67
		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
		$input_errors[] = "Only characters in a-z A-Z are allowed as interface name.";
73

    
74
	$ifgroupentry = array();
75
	$ifgroupentry['ifname'] = $_POST['ifname'];
76
	$members = "";
77
	$isfirst = 0;
78
	/* item is a normal ifgroupentry type */
79
	for($x=0; $x<9999; $x++) {
80
		if($_POST["members{$x}"] <> "") {
81
			if ($isfirst > 0)
82
				$members .= " ";
83
			$members .= $_POST["members{$x}"];
84
			$isfirst++;
85
		}
86
	}
87

    
88
	if (!$input_errors) {
89
		$ifgroupentry['members'] = $members;
90
		$ifgroupentry['descr'] = mb_convert_encoding($_POST['descr'],"HTML-ENTITIES","auto");
91

    
92
		if (isset($id) && $a_ifgroups[$id]) {
93
			$omembers = explode(" ", $a_ifgroups[$id]['members']);
94
			$nmembers = explode(" ", $members);
95
			$delmembers = array_diff($omembers, $nmembers);
96
			if (count($delmembers) > 0) {
97
				foreach ($delmembers as $ifs) {
98
					$realif = get_real_interface($ifs);
99
					if ($realif)
100
						mwexec("/sbin/ifconfig {$realif} -group " . $a_ifgroups[$id]['ifname']);
101
				}
102
			}
103
			$a_ifgroups[$id] = $ifgroupentry;
104
		} else
105
			$a_ifgroups[] = $ifgroupentry;
106

    
107
		write_config();
108

    
109
		interface_group_setup($ifgroupentry);
110

    
111
		header("Location: interfaces_groups.php");
112
		exit;
113
	} else {
114
		$pconfig['descr'] = mb_convert_encoding($_POST['descr'],"HTML-ENTITIES","auto");
115
		$pconfig['members'] = $members;
116
	}
117
}
118

    
119
include("head.inc");
120

    
121
?>
122

    
123
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
124
<?php
125
	include("fbegin.inc");
126
?>
127

    
128
<script type="text/javascript">
129
// Global Variables
130
var rowname = new Array(9999);
131
var rowtype = new Array(9999);
132
var newrow  = new Array(9999);
133
var rowsize = new Array(9999);
134

    
135
for (i = 0; i < 9999; i++) {
136
        rowname[i] = '';
137
        rowtype[i] = 'select';
138
        newrow[i] = '';
139
        rowsize[i] = '30';
140
}
141

    
142
var field_counter_js = 0;
143
var loaded = 0;
144
var is_streaming_progress_bar = 0;
145
var temp_streaming_text = "";
146

    
147
var addRowTo = (function() {
148
    return (function (tableId) {
149
        var d, tbody, tr, td, bgc, i, ii, j;
150
        d = document;
151
        tbody = d.getElementById(tableId).getElementsByTagName("tbody").item(0);
152
        tr = d.createElement("tr");
153
        for (i = 0; i < field_counter_js; i++) {
154
                td = d.createElement("td");
155
		<?php
156
                        $innerHTML="\"<INPUT type='hidden' value='\" + totalrows +\"' name='\" + rowname[i] + \"_row-\" + totalrows + \"'></input><select size='1' name='\" + rowname[i] + totalrows + \"'>\" +\"";
157

    
158
			$iflist = get_configured_interface_with_descr();
159
                        foreach ($iflist as $ifnam => $ifdescr)
160
                                $innerHTML .= "<option value={$ifnam}>{$ifdescr}</option>";
161
			$innerHTML .= "</select>\";";
162
                ?>
163
			td.innerHTML=<?=$innerHTML;?>
164
                tr.appendChild(td);
165
        }
166
        td = d.createElement("td");
167
        td.rowSpan = "1";
168

    
169
        td.innerHTML = '<input type="image" src="/themes/' + theme + '/images/icons/icon_x.gif" onclick="removeRow(this);return false;" value="Delete">';
170
        tr.appendChild(td);
171
        tbody.appendChild(tr);
172
        totalrows++;
173
    });
174
})();
175

    
176
function removeRow(el) {
177
    var cel;
178
    while (el && el.nodeName.toLowerCase() != "tr")
179
            el = el.parentNode;
180

    
181
    if (el && el.parentNode) {
182
        cel = el.getElementsByTagName("td").item(0);
183
        el.parentNode.removeChild(el);
184
    }
185
}
186

    
187
	rowname[0] = "members";
188
	rowtype[0] = "textbox";
189
	rowsize[0] = "30";
190

    
191
	rowname[2] = "detail";
192
	rowtype[2] = "textbox";
193
	rowsize[2] = "50";
194
</script>
195
<input type='hidden' name='members_type' value='textbox' class="formfld unknown" />
196

    
197
<?php if ($input_errors) print_input_errors($input_errors); ?>
198
<div id="inputerrors"></div>
199

    
200
<form action="interfaces_groups_edit.php" method="post" name="iform" id="iform">
201
<table width="100%" border="0" cellpadding="6" cellspacing="0">
202
  <tr>
203
	<td colspan="2" valign="top" class="listtopic">Interface Groups Edit</td>
204
  </tr>
205
  <tr>
206
    <td valign="top" class="vncellreq">Interface</td>
207
    <td class="vtable">
208
	<input class="formfld unknown" name="ifname" id="ifname" value="<?=$pconfig['ifname'];?>" />
209
	<br />
210
	No numbers or spaces are allowed. Only characters in a-zA-Z
211
    </td>
212
  </tr>
213
  <tr>
214
    <td width="22%" valign="top" class="vncell">Description</td>
215
    <td width="78%" class="vtable">
216
      <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=$pconfig['descr'];?>" />
217
      <br />
218
      <span class="vexpl">
219
        You may enter a description here for your reference (not parsed).
220
      </span>
221
    </td>
222
  </tr>
223
  <tr>
224
    <td width="22%" valign="top" class="vncellreq"><div id="membersnetworkport">Member (s)</div></td>
225
    <td width="78%" class="vtable">
226
      <table id="maintable">
227
        <tbody>
228
          <tr>
229
            <td><div id="onecolumn">Interface</div></td>
230
          </tr>
231

    
232
	<?php
233
	$counter = 0;
234
	$members = $pconfig['members'];
235
	if ($members <> "") {
236
		$item = explode(" ", $members);
237
		foreach($item as $ww) {
238
			$members = $item[$counter];
239
			$tracker = $counter;
240
	?>
241
        <tr>
242
	<td class="vtable">
243
	        <select name="members<?php echo $tracker; ?>" class="formselect" id="members<?php echo $tracker; ?>">
244
			<?php
245
				foreach ($iflist as $ifnam => $ifdescr) {
246
					echo "<option value={$ifnam}";
247
					if ($ifnam == $members)
248
						echo " selected";
249
					echo ">{$ifdescr}</option>";
250
				}
251
			?>
252
                        </select>
253
	</td>
254
        <td>
255
	<input type="image" src="/themes/<?echo $g['theme'];?>/images/icons/icon_x.gif" onclick="removeRow(this); return false;" value="Delete" />
256
	      </td>
257
          </tr>
258
<?php
259
		$counter++;
260

    
261
		} // end foreach
262
	} // end if
263
?>
264
        </tbody>
265
        <tfoot>
266

    
267
        </tfoot>
268
		  </table>
269
			<a onclick="javascript:addRowTo('maintable'); return false;" href="#">
270
        <img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" title="add another entry" />
271
      </a>
272
		</td>
273
  </tr>
274
  <tr>
275
    <td width="22%" valign="top">&nbsp;</td>
276
    <td width="78%">
277
      <input id="submit" name="submit" type="submit" class="formbtn" value="Save" />
278
      <a href="interfaces_groups.php"><input id="cancelbutton" name="cancelbutton" type="button" class="formbtn" value="Cancel" /></a>
279
      <?php if (isset($id) && $a_ifgroups[$id]): ?>
280
      <input name="id" type="hidden" value="<?=$id;?>" />
281
      <?php endif; ?>
282
    </td>
283
  </tr>
284
</table>
285
</form>
286

    
287
<script type="text/javascript">
288
	field_counter_js = 1;
289
	rows = 1;
290
	totalrows = <?php echo $counter; ?>;
291
	loaded = <?php echo $counter; ?>;
292
</script>
293

    
294
<?php include("fend.inc"); ?>
295
</body>
296
</html>
(88-88/215)