Project

General

Profile

Download (8.6 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
$id = $_GET['id'];
47
if (isset($_POST['id']))
48
	$id = $_POST['id'];
49

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

    
55
}
56

    
57
if ($_POST) {
58

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

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

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

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

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

    
103
		write_config();
104

    
105
		interface_group_setup($ifgroupentry);
106

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

    
115
include("head.inc");
116

    
117
?>
118

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
290
<?php include("fend.inc"); ?>
291
</body>
292
</html>
(81-81/203)