}
 if ($_POST['gateway'] && !is_ipaddr($_POST['gateway'])) {
     $input_errors[] = gettext("A valid gateway IP address must be specified.");
 }
 if ($_POST['gateway'] && $_POST['network']) {
     if (is_ipv4addr($_POST['gateway']) && !is_ipv4addr($_POST['network'])) {
         $input_errors[] = gettext("You must enter the same IP type for network and gateway.");
     } else {
         if (is_ipv6addr($_POST['gateway']) && !is_ipv6addr($_POST['network'])) {
             $input_errors[] = gettext("IP type mismatch for network and gateway.");
         }
     }
 }
 // Check for overlaps
 // gen_subnet work for IPv4 only... This function permit to fix user input error for network number.
 if (is_ipv4addr($_POST['network'])) {
     $osn = gen_subnet($_POST['network'], $_POST['network_subnet']) . "/" . $_POST['network_subnet'];
 } else {
     $osn = $_POST['network'] . "/" . $_POST['network_subnet'];
 }
 $index = array_search_ex($osn, $a_routes, "network");
 if (FALSE !== $index) {
     if (!(FALSE !== $cnid && $a_routes[$cnid]['uuid'] === $a_routes[$index]['uuid'])) {
         $input_errors[] = gettext("A route to this destination network already exists.");
     }
 }
 if (!$input_errors) {
     $route = array();
     $route['uuid'] = $_POST['uuid'];
     $route['interface'] = $_POST['interface'];
     $route['network'] = $osn;
Example #2
0
 $pconfig = $_POST;
 // Input validation.
 if (isset($_POST['enable']) && $_POST['enable']) {
     /* description unique? */
     for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
         if ($i != $index) {
             if ($config['interfaces']['opt' . $i]['descr'] == $_POST['descr']) {
                 $input_errors[] = gettext("An interface with the specified description already exists.");
             }
         }
     }
     if ($_POST['type'] === "Static") {
         $reqdfields = explode(" ", "descr ipaddr subnet");
         $reqdfieldsn = array(gettext("Description"), gettext("IP address"), gettext("Subnet bit count"));
         do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
         if ($_POST['ipaddr'] && !is_ipv4addr($_POST['ipaddr'])) {
             $input_errors[] = gettext("A valid IP address must be specified.");
         }
         if ($_POST['subnet'] && !filter_var($_POST['subnet'], FILTER_VALIDATE_INT, array('options' => array('min_range' => 1, 'max_range' => 32)))) {
             $input_errors[] = gettext("A valid network bit count (1-32) must be specified.");
         }
     }
     if (isset($_POST['ipv6_enable']) && $_POST['ipv6_enable'] && $_POST['ipv6type'] === "Static") {
         $reqdfields = explode(" ", "ipv6addr ipv6subnet");
         $reqdfieldsn = array(gettext("IPv6 address"), gettext("Prefix"));
         do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
         if ($_POST['ipv6addr'] && !is_ipv6addr($_POST['ipv6addr'])) {
             $input_errors[] = gettext("A valid IPv6 address must be specified.");
         }
         if ($_POST['ipv6subnet'] && !filter_var($_POST['ipv6subnet'], FILTER_VALIDATE_INT, array('options' => array('min_range' => 1, 'max_range' => 128)))) {
             $input_errors[] = gettext("A valid prefix (1-128) must be specified.");
     $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 {
                 $input_errors[] = sprintf(gettext("The portal '%s' is invalid."), $portal);
             }
         }
     }
 }
 if (count($portals) == 0) {
     $input_errors[] = sprintf(gettext("The attribute '%s' is required."), gettext("Portals"));
 }
 if (empty($input_errors)) {
     $iscsitarget_pg = array();
     $iscsitarget_pg['uuid'] = $_POST['uuid'];
Example #4
0
 if (!empty($_POST['webguiport'])) {
     $reqdfields = array_merge($reqdfields, array("webguiport"));
     $reqdfieldsn = array_merge($reqdfieldsn, array(gettext("Port")));
     $reqdfieldst = array_merge($reqdfieldst, array("port"));
 }
 do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
 do_input_validation_type($_POST, $reqdfields, $reqdfieldsn, $reqdfieldst, $input_errors);
 if (!empty($_POST['webguihostsallow'])) {
     foreach (explode(' ', $_POST['webguihostsallow']) as $a) {
         list($hp, $np) = explode('/', $a);
         if (!is_ipaddr($hp) || !empty($np) && !is_subnet($a)) {
             $input_errors[] = gettext("A valid IP address or CIDR notation must be specified for the hosts allow.");
         }
     }
 }
 if ($_POST['dns1'] && !is_ipv4addr($_POST['dns1']) || $_POST['dns2'] && !is_ipv4addr($_POST['dns2'])) {
     $input_errors[] = gettext("A valid IPv4 address must be specified for the primary/secondary DNS server.");
 }
 if ($_POST['ipv6dns1'] && !is_ipv6addr($_POST['ipv6dns1']) || $_POST['ipv6dns2'] && !is_ipv6addr($_POST['ipv6dns2'])) {
     $input_errors[] = gettext("A valid IPv6 address must be specified for the primary/secondary DNS server.");
 }
 if (isset($_POST['ntp_enable'])) {
     $t = (int) $_POST['ntp_updateinterval'];
     if ($t < 0 || $t > 0 && $t < 6 || $t > 1440) {
         $input_errors[] = gettext("The time update interval must be either between 6 and 1440.");
     }
     foreach (explode(' ', $_POST['ntp_timeservers']) as $ts) {
         if (!is_domain($ts)) {
             $input_errors[] = gettext("A NTP time server name may only contain the characters a-z, 0-9, '-' and '.'.");
         }
     }
     $netmask = trim($netmask, " \t\r\n");
     if (!empty($netmask)) {
         if (preg_match("/^\\[([0-9a-fA-F:]+)\\](\\/([0-9]+))?\$/", $netmask, $tmp)) {
             // IPv6
             $addr = normalize_ipv6addr($tmp[1]);
             $mask = isset($tmp[3]) ? $tmp[3] : 128;
             if (!is_ipv6addr($addr) || $mask < 0 || $mask > 128) {
                 $input_errors[] = sprintf(gettext("The network '%s' is invalid."), $netmask);
             }
             $netmasks[] = sprintf("[%s]/%d", $addr, $mask);
         } else {
             if (preg_match("/^([0-9\\.]+)(\\/([0-9]+))?\$/", $netmask, $tmp)) {
                 // IPv4
                 $addr = $tmp[1];
                 $mask = isset($tmp[3]) ? $tmp[3] : 32;
                 if (!is_ipv4addr($addr) || $mask < 0 || $mask > 32) {
                     $input_errors[] = sprintf(gettext("The network '%s' is invalid."), $netmask);
                 }
                 $netmasks[] = sprintf("%s/%d", $addr, $mask);
             } else {
                 if (strcasecmp("ALL", $netmask) == 0) {
                     $netmasks[] = sprintf("%s", $netmask);
                 } else {
                     $input_errors[] = sprintf(gettext("The network '%s' is invalid."), $netmask);
                 }
             }
         }
     }
 }
 if (count($netmasks) == 0) {
     $input_errors[] = sprintf(gettext("The attribute '%s' is required."), gettext("Authorised network"));
    $pconfig['extraoptions'] = "";
    $pconfig['desc'] = "";
    $pconfig['advbase'] = "1";
}
if ($_POST) {
    unset($input_errors);
    $pconfig = $_POST;
    if (isset($_POST['Cancel']) && $_POST['Cancel']) {
        header("Location: interfaces_carp.php");
        exit;
    }
    // Input validation.
    $reqdfields = explode(" ", "vipaddr vsubnet");
    $reqdfieldsn = array(gettext("Virtual IP address"), gettext("Subnet bit count"));
    do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
    if (!empty($_POST['vipaddr']) && !is_ipv4addr($_POST['vipaddr'])) {
        $input_errors[] = gettext("A valid IPv4 address must be specified.");
    }
    if (!empty($_POST['vsubnet']) && !filter_var($_POST['vsubnet'], FILTER_VALIDATE_INT, array('options' => array('min_range' => 1, 'max_range' => 32)))) {
        $input_errors[] = gettext("A valid network bit count (1-32) must be specified.");
    }
    $reqdfields = explode(" ", "vhid advskew password advbase");
    $reqdfieldsn = array(gettext("Virtual Host ID"), gettext("Advertisement skew"), gettext("Password"), gettext("Advertisement base"));
    $reqdfieldst = explode(" ", "numericint numericint string numericint");
    do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
    do_input_validation_type($_POST, $reqdfields, $reqdfieldsn, $reqdfieldst, $input_errors);
    if (!empty($_POST['password']) && preg_match("/\\'|\"/", $_POST['password'])) {
        $input_errors[] = sprintf(gettext("The attribute '%s' contains invalid characters."), gettext("Password"));
    }
    if (empty($input_errors)) {
        $carp = array();