false]) as $intf => $intfdata) { if (substr($intfdata['if'], 0, 3) != 'gre' && substr($intfdata['if'], 0, 2) != 'lo') { $ifacelist[$intf] = $intfdata['descr']; } } if ($_SERVER['REQUEST_METHOD'] === 'GET') { // read form data if (!empty($a_bridges[$_GET['id']])) { $id = $_GET['id']; } // copy fields 1-on-1 $copy_fields = ['descr', 'bridgeif', 'maxaddr', 'timeout', 'maxage','fwdelay', 'hellotime', 'priority', 'proto', 'holdcnt', 'span']; foreach ($copy_fields as $fieldname) { if (isset($a_bridges[$id][$fieldname])) { $pconfig[$fieldname] = $a_bridges[$id][$fieldname]; } else { $pconfig[$fieldname] = null; } } // bool fields $pconfig['enablestp'] = !empty($a_bridges[$id]['enablestp']); $pconfig['linklocal'] = !empty($a_bridges[$id]['linklocal']); // simple array fields $array_fields = ['members', 'stp', 'edge', 'autoedge', 'ptp', 'autoptp', 'static', 'private']; foreach ($array_fields as $fieldname) { if (!empty($a_bridges[$id][$fieldname])) { $pconfig[$fieldname] = explode(',', $a_bridges[$id][$fieldname]); } else { $pconfig[$fieldname] = []; } } // array key/value sets if (!empty($a_bridges[$id]['ifpriority'])) { foreach (explode(",", $a_bridges[$id]['ifpriority']) as $cfg) { list ($key, $value) = explode(":", $cfg); $pconfig['ifpriority_'.$key] = $value; } } if (!empty($a_bridges[$id]['ifpathcost'])) { foreach (explode(",", $a_bridges[$id]['ifpathcost']) as $cfg) { list ($key, $value) = explode(":", $cfg); $pconfig['ifpathcost_'.$key] = $value; } } } elseif ($_SERVER['REQUEST_METHOD'] === 'POST') { // save / validate formdata if (!empty($a_bridges[$_POST['id']])) { $id = $_POST['id']; } $input_errors = []; $pconfig = $_POST; $not_between_int = function($val, $min, $max) { return !is_numeric($val) || $val < $min || $val > $max; }; if (!empty($pconfig['maxage']) && $not_between_int($pconfig['maxage'], 6, 40)) { $input_errors[] = gettext("Maxage needs to be an integer between 6 and 40."); } if ($pconfig['maxaddr'] != "" && $not_between_int($pconfig['maxaddr'], 0, PHP_INT_MAX)) { $input_errors[] = gettext("Maxaddr needs to be an integer."); } if ($pconfig['timeout'] != "" && $not_between_int($pconfig['timeout'], 0, PHP_INT_MAX)) { $input_errors[] = gettext("Timeout needs to be an integer."); } if (!empty($pconfig['fwdelay']) && $not_between_int($pconfig['fwdelay'], 4, 30)) { $input_errors[] = gettext("Forward Delay needs to be an integer between 4 and 30."); } if (!empty($pconfig['hellotime']) && $not_between_int($pconfig['hellotime'], 1, 2)) { $input_errors[] = gettext("Hello time for STP needs to be an integer between 1 and 2."); } if ($pconfig['priority'] != "" && $not_between_int($pconfig['priority'], 0, 61440)) { $input_errors[] = gettext("Priority for STP needs to be an integer between 0 and 61440."); } if (!empty($pconfig['holdcnt']) && $not_between_int($pconfig['holdcnt'], 1, 10)) { $input_errors[] = gettext("Transmit Hold Count for STP needs to be an integer between 1 and 10."); } foreach ($ifacelist as $ifn => $ifdescr) { if ($pconfig['ifpriority_'.$ifn] != "" && $not_between_int($pconfig['ifpriority_'.$ifn], 0, 240)) { $input_errors[] = sprintf(gettext("%s interface priority for STP needs to be an integer between 0 and 240."), $ifdescr); } if (!empty($pconfig['ifpathcost_'.$ifn]) && $not_between_int($pconfig['ifpathcost_'.$ifn], 1, 200000000)) { $input_errors[] = sprintf(gettext("%s interface path cost for STP needs to be an integer between 1 and 200000000."), $ifdescr); } } $members = !empty($pconfig['members']) ? $pconfig['members'] : []; if (!empty($members)) { foreach($members as $ifmembers) { if (empty($config['interfaces'][$ifmembers])) { $input_errors[] = gettext("A member interface passed does not exist in configuration"); } if (!empty($config['interfaces'][$ifmembers]['wireless']['mode']) && $config['interfaces'][$ifmembers]['wireless']['mode'] != "hostap") { $input_errors[] = gettext("Bridging a wireless interface is only possible in hostap mode."); } if ($pconfig['span'] != "none" && $pconfig['span'] == $ifmembers) { $input_errors[] = gettext("Span interface cannot be part of the bridge. Remove the span interface from bridge members to continue."); } } } foreach (['stp', 'edge', 'autoedge', 'ptp', 'autoptp', 'static', 'private'] as $section) { if (!empty($pconfig[$section])) { foreach ($pconfig[$section] as $if) { if (!in_array($if, $members)) { $ifname = !empty($ifacelist[$if]) ? $ifacelist[$if] : $if; $input_errors[] = gettext(sprintf("Option %s contains non bridge member interface %s", $section, $ifname)); } } } } if (count($input_errors) == 0) { $bridge = []; // booleans foreach (['enablestp', 'linklocal'] as $fieldname) { if (!empty($pconfig[$fieldname])) { $bridge[$fieldname] = true; } } // 1 on 1 copy $copy_fields = ['descr', 'maxaddr', 'timeout', 'bridgeif', 'maxage','fwdelay', 'hellotime', 'priority', 'proto', 'holdcnt']; foreach ($copy_fields as $fieldname) { if (isset($pconfig[$fieldname]) && $pconfig[$fieldname] != '') { $bridge[$fieldname] = $pconfig[$fieldname]; } else { $bridge[$fieldname] = null; } } if ($pconfig['span'] != 'none') { $bridge['span'] = $pconfig['span']; } // simple array fields $array_fields = ['members', 'stp', 'edge', 'autoedge', 'ptp', 'autoptp', 'static', 'private']; foreach ($array_fields as $fieldname) { if(!empty($pconfig[$fieldname])) { $bridge[$fieldname] = implode(',', $pconfig[$fieldname]); } } // array key/value sets $bridge['ifpriority'] = ''; $bridge['ifpathcost'] = ''; foreach ($ifacelist as $ifn => $ifdescr) { if (isset($pconfig['ifpriority_'.$ifn]) && $pconfig['ifpriority_' . $ifn] != '') { if (!empty($bridge['ifpriority'])) { $bridge['ifpriority'] .= ','; } $bridge['ifpriority'] .= $ifn . ':' . $pconfig['ifpriority_' . $ifn]; } if (isset($pconfig['ifpathcost_' . $ifn]) && $pconfig['ifpathcost_' . $ifn] != '') { if (!empty($bridge['ifpathcost'])) { $bridge['ifpathcost'] .= ','; } $bridge['ifpathcost'] .= $ifn . ':' . $pconfig['ifpathcost_' . $ifn]; } } if (empty($bridge['bridgeif'])) { $bridge['bridgeif'] = legacy_interface_create('bridge'); /* XXX find another strategy */ } if (empty($bridge['bridgeif']) || strpos($bridge['bridgeif'], 'bridge') !== 0) { $input_errors[] = gettext("Error occurred creating interface, please retry."); } else { if (isset($id)) { $a_bridges[$id] = $bridge; } else { $a_bridges[] = $bridge; } write_config(); interfaces_bridge_configure($bridge['bridgeif']); ifgroup_setup(); interfaces_restart_by_device(false, [$bridge['bridgeif']]); header(url_safe('Location: /interfaces_bridge.php')); exit; } } } legacy_html_escape_form_data($pconfig); include("head.inc"); ?>