1) { if (preg_match("/([^0-9])+/", $member[0], $match) || preg_match("/([^0-9])+/", $member[1], $match)) { $input_errors[] = gettext("Tags can contain only numbers or a range in format #-#."); } for ($i = $member[0]; $i <= $member[1]; $i++) { $members .= ($isfirst == 0 ? '':' ') . $i; $isfirst++; } } else { // Just a single number if (preg_match("/([^0-9])+/", $memb, $match)) { $input_errors[] = gettext("Tags can contain only numbers or a range in format #-#."); } else { $members .= ($isfirst == 0 ? '':' ') . $memb; $isfirst++; } } } 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'] = $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 "Duplicate" 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) { $member = $item[$counter]; $group = new Form_Group($counter == 0 ? 'Tag(s)':''); $group->addClass('repeatable'); $group->add(new Form_Input( 'members[]', 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); include("foot.inc");