Projet

Général

Profil

Télécharger (10,8 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / interfaces_groups_edit.php @ 0fab7eb1

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-interfaces-groups-edit
35
##|*NAME=Interfaces: Groups: Edit page
36
##|*DESCR=Allow access to the 'Interfaces: Groups: Edit' page.
37
##|*MATCH=interfaces_groups_edit.php*
38
##|-PRIV
39

    
40

    
41
require("guiconfig.inc");
42
require_once("functions.inc");
43

    
44
$pgtitle = array(gettext("Interfaces"),gettext("Groups"),gettext("Edit"));
45
$shortcut_section = "interfaces";
46

    
47
if (!is_array($config['ifgroups']['ifgroupentry']))
48
	$config['ifgroups']['ifgroupentry'] = array();
49

    
50
$a_ifgroups = &$config['ifgroups']['ifgroupentry'];
51

    
52
if (is_numericint($_GET['id']))
53
	$id = $_GET['id'];
54
if (isset($_POST['id']) && is_numericint($_POST['id']))
55
	$id = $_POST['id'];
56

    
57
if (isset($id) && $a_ifgroups[$id]) {
58
	$pconfig['ifname'] = $a_ifgroups[$id]['ifname'];
59
	$pconfig['members'] = $a_ifgroups[$id]['members'];
60
	$pconfig['descr'] = html_entity_decode($a_ifgroups[$id]['descr']);
61

    
62
}
63

    
64
if ($_POST) {
65

    
66
	unset($input_errors);
67
	$pconfig = $_POST;
68

    
69
	if (!isset($id)) {
70
		foreach ($a_ifgroups as $groupentry)
71
			if ($groupentry['ifname'] == $_POST['ifname'])
72
				$input_errors[] = gettext("Group name already exists!");
73
	}
74
	if (preg_match("/([^a-zA-Z])+/", $_POST['ifname'], $match))
75
		$input_errors[] = gettext("Only letters A-Z are allowed as the group name.");
76

    
77
	$ifaces = get_configured_interface_with_descr();
78
	foreach ($ifaces as $gif => $gdescr) {
79
		if ($gdescr == $_POST['ifname'] || $gif == $_POST['ifname'])
80
			$input_errors[] = "The specified group name is already used by an interface. Please choose another name.";
81
	}
82
	$members = "";
83
	$isfirst = 0;
84
	/* item is a normal ifgroupentry type */
85
	for($x=0; $x<9999; $x++) {
86
		if($_POST["members{$x}"] <> "") {
87
			if ($isfirst > 0)
88
				$members .= " ";
89
			$members .= $_POST["members{$x}"];
90
			$isfirst++;
91
		}
92
	}
93

    
94
	if (!$input_errors) {
95
		$ifgroupentry = array();
96
		$ifgroupentry['members'] = $members;
97
		$ifgroupentry['descr'] = $_POST['descr'];
98

    
99
		if (isset($id) && $a_ifgroups[$id] && $_POST['ifname'] != $a_ifgroups[$id]['ifname']) {
100
			if (!empty($config['filter']) && is_array($config['filter']['rule'])) {
101
				foreach ($config['filter']['rule'] as $ridx => $rule) {
102
					if (isset($rule['floating'])) {
103
						$rule_ifs = explode(",", $rule['interface']);
104
						$rule_changed = false;
105
						foreach ($rule_ifs as $rule_if_id => $rule_if) {
106
							if ($rule_if == $a_ifgroups[$id]['ifname']) {
107
								$rule_ifs[$rule_if_id] = $_POST['ifname'];
108
								$rule_changed = true;
109
							}
110
						}
111
						if ($rule_changed)
112
							$config['filter']['rule'][$ridx]['interface'] = implode(",", $rule_ifs);
113
					} else {
114
						if ($rule['interface'] == $a_ifgroups[$id]['ifname'])
115
							$config['filter']['rule'][$ridx]['interface'] = $_POST['ifname'];
116
					}
117
				}
118
			}
119
			if (!empty($config['nat']) && is_array($config['nat']['rule'])) {
120
				foreach ($config['nat']['rule'] as $ridx => $rule) {
121
					if ($rule['interface'] == $a_ifgroups[$id]['ifname'])
122
						$config['nat']['rule'][$ridx]['interface'] = $_POST['ifname'];
123
				}
124
			}
125
			$omembers = explode(" ", $a_ifgroups[$id]['members']);
126
			if (count($omembers) > 0) {
127
				foreach ($omembers as $ifs) {
128
					$realif = get_real_interface($ifs);
129
					if ($realif)
130
						mwexec("/sbin/ifconfig {$realif} -group " . $a_ifgroups[$id]['ifname']);
131
				}
132
			}
133
			$ifgroupentry['ifname'] = $_POST['ifname'];
134
			$a_ifgroups[$id] = $ifgroupentry;
135
		} else if (isset($id) && $a_ifgroups[$id]) {
136
			$omembers = explode(" ", $a_ifgroups[$id]['members']);
137
			$nmembers = explode(" ", $members);
138
			$delmembers = array_diff($omembers, $nmembers);
139
			if (count($delmembers) > 0) {
140
				foreach ($delmembers as $ifs) {
141
					$realif = get_real_interface($ifs);
142
					if ($realif)
143
						mwexec("/sbin/ifconfig {$realif} -group " . $a_ifgroups[$id]['ifname']);
144
				}
145
			}
146
			$ifgroupentry['ifname'] = $_POST['ifname'];
147
			$a_ifgroups[$id] = $ifgroupentry;
148
		} else {
149
			$ifgroupentry['ifname'] = $_POST['ifname'];
150
			$a_ifgroups[] = $ifgroupentry;
151
		}
152

    
153
		write_config();
154

    
155
		interface_group_setup($ifgroupentry);
156

    
157
		header("Location: interfaces_groups.php");
158
		exit;
159
	} else {
160
		$pconfig['descr'] = $_POST['descr'];
161
		$pconfig['members'] = $members;
162
	}
163
}
164

    
165
include("head.inc");
166

    
167
?>
168

    
169
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
170
<?php include("fbegin.inc"); ?>
171

    
172
<script type="text/javascript">
173
//<![CDATA[
174
// Global Variables
175
var rowname = new Array(9999);
176
var rowtype = new Array(9999);
177
var newrow  = new Array(9999);
178
var rowsize = new Array(9999);
179

    
180
for (i = 0; i < 9999; i++) {
181
        rowname[i] = '';
182
        rowtype[i] = 'select';
183
        newrow[i] = '';
184
        rowsize[i] = '30';
185
}
186

    
187
var field_counter_js = 0;
188
var loaded = 0;
189
var is_streaming_progress_bar = 0;
190
var temp_streaming_text = "";
191

    
192
var addRowTo = (function() {
193
    return (function (tableId) {
194
        var d, tbody, tr, td, bgc, i, ii, j;
195
        d = document;
196
        tbody = d.getElementById(tableId).getElementsByTagName("tbody").item(0);
197
        tr = d.createElement("tr");
198
        for (i = 0; i < field_counter_js; i++) {
199
                td = d.createElement("td");
200
		<?php
201
                        $innerHTML="\"<input type='hidden' value='\" + totalrows +\"' name='\" + rowname[i] + \"_row-\" + totalrows + \"' /><select size='1' name='\" + rowname[i] + totalrows + \"'>\" +\"";
202

    
203
			$iflist = get_configured_interface_with_descr();
204
                        foreach ($iflist as $ifnam => $ifdescr)
205
                                $innerHTML .= "<option value='{$ifnam}'>{$ifdescr}<\/option>";
206
			$innerHTML .= "<\/select>\";";
207
                ?>
208
			td.innerHTML=<?=$innerHTML;?>
209
                tr.appendChild(td);
210
        }
211
        td = d.createElement("td");
212
        td.rowSpan = "1";
213

    
214
        td.innerHTML = '<a onclick="removeRow(this);return false;" href="#"><img border="0" src="/themes/' + theme + '/images/icons/icon_x.gif" alt="remove" /><\/a>';
215
        tr.appendChild(td);
216
        tbody.appendChild(tr);
217
        totalrows++;
218
    });
219
})();
220

    
221
function removeRow(el) {
222
    var cel;
223
    while (el && el.nodeName.toLowerCase() != "tr")
224
            el = el.parentNode;
225

    
226
    if (el && el.parentNode) {
227
        cel = el.getElementsByTagName("td").item(0);
228
        el.parentNode.removeChild(el);
229
    }
230
}
231

    
232
	rowname[0] = "members";
233
	rowtype[0] = "textbox";
234
	rowsize[0] = "30";
235

    
236
	rowname[2] = "detail";
237
	rowtype[2] = "textbox";
238
	rowsize[2] = "50";
239
//]]>
240
</script>
241
<input type='hidden' name='members_type' value='textbox' class="formfld unknown" />
242

    
243
<?php if ($input_errors) print_input_errors($input_errors); ?>
244
<div id="inputerrors"></div>
245

    
246
<form action="interfaces_groups_edit.php" method="post" name="iform" id="iform">
247
<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="interfaces groups edit">
248
  <tr>
249
	<td colspan="2" valign="top" class="listtopic"><?=gettext("Interface Groups Edit");?></td>
250
  </tr>
251
  <tr>
252
    <td valign="top" class="vncellreq"><?=gettext("Group Name");?></td>
253
    <td class="vtable">
254
	<input class="formfld unknown" name="ifname" id="ifname" value="<?=htmlspecialchars($pconfig['ifname']);?>" />
255
	<br />
256
	<?=gettext("No numbers or spaces are allowed. Only characters in a-zA-Z");?>
257
    </td>
258
  </tr>
259
  <tr>
260
    <td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
261
    <td width="78%" class="vtable">
262
      <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
263
      <br />
264
      <span class="vexpl">
265
        <?=gettext("You may enter a description here for your reference (not parsed).");?>
266
      </span>
267
    </td>
268
  </tr>
269
  <tr>
270
    <td width="22%" valign="top" class="vncellreq"><div id="membersnetworkport"><?=gettext("Member (s)");?></div></td>
271
    <td width="78%" class="vtable">
272
      <table id="maintable" summary="main table">
273
        <tbody>
274
          <tr>
275
            <td><div id="onecolumn"><?=gettext("Interface");?></div></td>
276
          </tr>
277

    
278
	<?php
279
	$counter = 0;
280
	$members = $pconfig['members'];
281
	if ($members <> "") {
282
		$item = explode(" ", $members);
283
		foreach($item as $ww) {
284
			$members = $item[$counter];
285
			$tracker = $counter;
286
	?>
287
        <tr>
288
	<td class="vtable">
289
	        <select name="members<?php echo $tracker; ?>" class="formselect" id="members<?php echo $tracker; ?>">
290
			<?php
291
				foreach ($iflist as $ifnam => $ifdescr) {
292
					echo "<option value=\"{$ifnam}\"";
293
					if ($ifnam == $members)
294
						echo " selected=\"selected\"";
295
					echo ">{$ifdescr}</option>";
296
				}
297
			?>
298
                        </select>
299
	</td>
300
        <td>
301
	<a onclick="removeRow(this); return false;" href="#"><img border="0" src="/themes/<?echo $g['theme'];?>/images/icons/icon_x.gif" alt="remove" /></a>
302
	      </td>
303
          </tr>
304
<?php
305
		$counter++;
306

    
307
		} // end foreach
308
	} // end if
309
?>
310
        </tbody>
311
		  </table>
312
			<a onclick="javascript:addRowTo('maintable'); return false;" href="#">
313
        <img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" title="<?=gettext("add another entry");?>" />
314
      </a>
315
		</td>
316
  </tr>
317
  <tr>
318
    <td width="22%" valign="top">&nbsp;</td>
319
    <td width="78%">
320
      <input id="submit" name="submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
321
      <a href="interfaces_groups.php"><input id="cancelbutton" name="cancelbutton" type="button" class="formbtn" value="<?=gettext("Cancel");?>" /></a>
322
      <?php if (isset($id) && $a_ifgroups[$id]): ?>
323
      <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
324
      <?php endif; ?>
325
    </td>
326
  </tr>
327
</table>
328
</form>
329

    
330
<script type="text/javascript">
331
//<![CDATA[
332
	field_counter_js = 1;
333
	rows = 1;
334
	totalrows = <?php echo $counter; ?>;
335
	loaded = <?php echo $counter; ?>;
336
//]]>
337
</script>
338

    
339
<?php include("fend.inc"); ?>
340
</body>
341
</html>
(102-102/254)