= $tag_min) && ($_POST[$membername] <= $tag_max)) { $valid_members[] = intval($_POST[$membername]); } elseif ($_POST[$membername] != "") { $tag_format_error = true; } // else ignore empty rows // Remember the POSTed values so they can be redisplayed if there were errors. $posted_members .= ($membercounter == 0 ? '':' ') . $_POST[$membername]; $membercounter++; $membername = "member{$membercounter}"; } if ($tag_format_error) { $input_errors[] = sprintf(gettext('Tags can contain only numbers or a range (in format #-#) from %1$s to %2$s.'), $tag_min, $tag_max); } // Just use the unique valid members. There could have been overlap in the ranges or repeat of numbers entered. $members = implode(" ", array_unique($valid_members)); if ($members == "") { $input_errors[] = gettext("At least one tag must be entered."); } if (!$input_errors) { $qinqentry['members'] = $members; $qinqentry['descr'] = $_POST['descr']; $qinqentry['vlanif'] = "{$_POST['if']}_{$_POST['tag']}"; $nmembers = explode(" ", $members); if (isset($id) && $a_qinqs[$id]) { $omembers = explode(" ", $a_qinqs[$id]['members']); $delmembers = array_diff($omembers, $nmembers); $addmembers = array_diff($nmembers, $omembers); if ((count($delmembers) > 0) || (count($addmembers) > 0)) { $fd = fopen("{$g['tmp_path']}/netgraphcmd", "w"); foreach ($delmembers as $tag) { fwrite($fd, "shutdown {$qinqentry['vlanif']}h{$tag}:\n"); fwrite($fd, "msg {$qinqentry['vlanif']}qinq: delfilter \\\"{$qinqentry['vlanif']}{$tag}\\\"\n"); } foreach ($addmembers as $member) { $qinq = array(); $qinq['if'] = $qinqentry['vlanif']; $qinq['tag'] = $member; $macaddr = get_interface_mac($qinqentry['vlanif']); interface_qinq2_configure($qinq, $fd, $macaddr); } fclose($fd); mwexec("/usr/sbin/ngctl -f {$g['tmp_path']}/netgraphcmd"); } $a_qinqs[$id] = $qinqentry; } else { interface_qinq_configure($qinqentry); $a_qinqs[] = $qinqentry; } if ($_POST['autogroup'] == "yes") { if (!is_array($config['ifgroups']['ifgroupentry'])) { $config['ifgroups']['ifgroupentry'] = array(); } foreach ($config['ifgroups']['ifgroupentry'] as $gid => $group) { if ($group['ifname'] == "QinQ") { $found = true; break; } } $additions = ""; foreach ($nmembers as $qtag) { $additions .= "{$qinqentry['vlanif']}_{$qtag} "; } $additions .= "{$qinqentry['vlanif']}"; if ($found == true) { $config['ifgroups']['ifgroupentry'][$gid]['members'] .= " {$additions}"; } else { $gentry = array(); $gentry['ifname'] = "QinQ"; $gentry['members'] = "{$additions}"; $gentry['descr'] = gettext("QinQ VLANs group"); $config['ifgroups']['ifgroupentry'][] = $gentry; } } write_config(); header("Location: interfaces_qinq.php"); exit; } else { $pconfig['descr'] = $_POST['descr']; $pconfig['tag'] = $_POST['tag']; $pconfig['members'] = $posted_members; } } function build_parent_list() { global $portlist; $list = array(); foreach ($portlist as $ifn => $ifinfo) { if (is_jumbo_capable($ifn)) { $list[$ifn] = $ifn . ' (' . $ifinfo['mac'] . ')'; } } return($list); } include("head.inc"); if ($input_errors) { print_input_errors($input_errors); } $form = new Form(); $section = new Form_Section('QinQ Configuration'); $section->addInput(new Form_Select( 'if', '*Parent interface', $pconfig['if'], build_parent_list() ))->setHelp('Only QinQ capable interfaces will be shown.'); $section->addInput(new Form_Input( 'tag', '*First level tag', 'number', $pconfig['tag'], ['max' => '4094', 'min' => '1'] ))->setHelp('This is the first level VLAN tag. On top of this are stacked the member VLANs defined below.'); $section->addInput(new Form_Checkbox( 'autogroup', 'Option(s)', 'Adds interface to QinQ interface groups', $pconfig['autogroup'] ))->setHelp('Allows rules to be written more easily.'); $section->addInput(new Form_Input( 'descr', 'Description', 'text', $pconfig['descr'] ))->setHelp('A description may be entered here for administrative reference (not parsed).'); $section->addInput(new Form_StaticText( 'Member(s)', 'Ranges can be specified in the inputs below. Enter a range (2-3) or individual numbers.' . '
' . 'Click "Add Tag" as many times as needed to add new inputs.' )); if (isset($id) && $a_qinqs[$id]) { $section->addInput(new Form_Input( 'id', null, 'hidden', $id )); } $counter = 0; $members = $pconfig['members']; // List each of the member tags from the space-separated list if ($members != "") { $item = explode(" ", $members); } else { $item = array(''); } foreach ($item as $ww) { $group = new Form_Group($counter == 0 ? 'Tag(s)':''); $group->addClass('repeatable'); $group->add(new Form_Input( 'member' . $counter, null, 'text', $ww ))->setWidth(6); // Width must be <= 8 to make room for the duplication buttons $group->add(new Form_Button( 'deleterow' . $counter, 'Delete', null, 'fa-trash' ))->addClass('btn-warning'); $counter++; $section->add($group); } $form->addGlobal(new Form_Button( 'addrow', 'Add Tag', null, 'fa-plus' ))->addClass('btn-success addbtn'); $form->add($section); print($form); ?>