$input_errors[] = gettext("The tag range is invalid."); } // Check for duplicates. $index = array_search_ex($_POST['tag'], $config['iscsitarget']['portalgroup'], "tag"); if (FALSE !== $index) { if (!(FALSE !== $cnid && $config['iscsitarget']['portalgroup'][$cnid]['uuid'] === $config['iscsitarget']['portalgroup'][$index]['uuid'])) { $input_errors[] = gettext("This tag already exists."); } } $portals = array(); foreach (explode("\n", $_POST['portals']) as $portal) { $portal = trim($portal, " \t\r\n"); if (!empty($portal)) { if (preg_match("/^\\[([0-9a-fA-F:]+)\\](:([0-9]+))?\$/", $portal, $tmp)) { // IPv6 $addr = normalize_ipv6addr($tmp[1]); $port = isset($tmp[3]) ? $tmp[3] : 3260; if (!is_ipv6addr($addr) || $port < 1 || $port > 65535) { $input_errors[] = sprintf(gettext("The portal '%s' is invalid."), $portal); } $portals[] = sprintf("[%s]:%d", $addr, $port); } else { if (preg_match("/^([0-9\\.]+)(:([0-9]+))?\$/", $portal, $tmp)) { // IPv4 $addr = $tmp[1]; $port = isset($tmp[3]) ? $tmp[3] : 3260; if (!is_ipv4addr($addr) || $port < 1 || $port > 65535) { $input_errors[] = sprintf(gettext("The portal '%s' is invalid."), $portal); } $portals[] = sprintf("%s:%d", $addr, $port); } else {
function get_ipv6network($v6addr, $mask) { if (strlen($v6addr) == 0) { return null; } $v6str = expand_ipv6addr($v6addr); // compute by 16bits $v6a = explode(":", $v6str); foreach ($v6a as &$tmp) { if ($mask >= 16) { $mask -= 16; } else { if ($mask != 0) { $bmask = 0xffff; $bmask <<= 16 - $mask; $tmp = sprintf("%x", intval($tmp, 16) & $bmask); $mask = 0; } else { $tmp = 0; } } } unset($tmp); $v6str = implode(":", $v6a); $v6str = normalize_ipv6addr($v6str); return $v6str; }