Project

General

Profile

Download (8.63 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
##|+PRIV
30
##|*IDENT=page-interfacess-groups
31
##|*NAME=Interfaces: Groups: Edit page
32
##|*DESCR=Edit Interface groups
33
##|*MATCH=interfaces_groups_edit.php*
34
##|-PRIV
35

    
36

    
37
$pgtitle = array("Interfaces","Groups", "Edit");
38

    
39
require("guiconfig.inc");
40

    
41
if (!is_array($config['ifgroups']['ifgroupentry']))
42
	$config['ifgroups']['ifgroupentry'] = array();
43

    
44
$a_ifgroups = &$config['ifgroups']['ifgroupentry'];
45

    
46
if (isset($_GET['id']))
47
	$id = $_GET['id'];
48
if (isset($_POST['id']))
49
	$id = $_POST['id'];
50

    
51
if (isset($id) && $a_ifgroups[$id]) {
52
	$pconfig['ifname'] = $a_ifgroups[$id]['ifname'];
53
	$pconfig['members'] = $a_ifgroups[$id]['members'];
54
	$pconfig['descr'] = html_entity_decode($a_ifgroups[$id]['descr']);
55

    
56
}
57

    
58
if ($_POST) {
59

    
60
	unset($input_errors);
61
	$pconfig = $_POST;
62

    
63
	if (!isset($id)) {
64
		foreach ($a_ifgroups as $groupentry)
65
			if ($groupentry['ifname'] == $_POST['ifname'])
66
				$input_errors[] = "Group name already exists!";
67
	}
68
	if (preg_match("/([^a-zA-Z])+/", $_POST['ifname'], $match))
69
		$input_errors[] = "Only characters in a-z A-Z are allowed as interface name.";
70

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

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

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

    
104
		write_config();
105

    
106
		interface_group_setup($ifgroupentry);
107

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

    
116
include("head.inc");
117

    
118
?>
119

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

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

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

    
139
var field_counter_js = 0;
140
var loaded = 0;
141
var is_streaming_progress_bar = 0;
142
var temp_streaming_text = "";
143

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

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

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

    
173
function removeRow(el) {
174
    var cel;
175
    while (el && el.nodeName.toLowerCase() != "tr")
176
            el = el.parentNode;
177

    
178
    if (el && el.parentNode) {
179
        cel = el.getElementsByTagName("td").item(0);
180
        el.parentNode.removeChild(el);
181
    }
182
}
183

    
184
	rowname[0] = "members";
185
	rowtype[0] = "textbox";
186
	rowsize[0] = "30";
187

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

    
194
<?php if ($input_errors) print_input_errors($input_errors); ?>
195
<div id="inputerrors"></div>
196

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

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

    
258
		} // end foreach
259
	} // end if
260
?>
261
        </tbody>
262
        <tfoot>
263

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

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

    
291
<?php include("fend.inc"); ?>
292
</body>
293
</html>
(88-88/218)