Ejemplo n.º 1
0
if ($section['strictMode'] == 1) {
    if (!($overlap = verifySubnetNesting($subnetOld['masterSubnetId'], transform2long($subnetOld['subnet']) . "/" . $_POST['newMask'])) && $subnetOld['masterSubnetId'] != 0) {
        # get master details
        $master = getSubnetDetailsById($subnetOld['masterSubnetId']);
        $master = Transform2long($master['subnet']) . "/" . $master['mask'] . " - " . $master['description'];
        $errors[] = _("New subnet not in master subnet") . "!<br>({$master})";
    }
}
/*
 * If subnet has slaves make sure all slaves are still inside!
 */
if ($section['strictMode'] == 1) {
    $slaves = getAllSlaveSubnetsBySubnetId($_POST['subnetId']);
    if (sizeof($slaves) > 0) {
        foreach ($slaves as $slave) {
            if (!isSubnetInsideSubnet(transform2long($slave['subnet']) . "/" . $slave['mask'], transform2long($subnetOld['subnet']) . "/" . $_POST['newMask'])) {
                $errors[] = _("Nested subnet out of new subnet") . "!<br>(" . transform2long($slave['subnet']) . "/{$slave['mask']} - {$slave['description']})";
            }
        }
    }
}
/* if no errors edit! */
if (sizeof($errors) > 0) {
    print "<div class='alert alert-danger'><ul>";
    foreach ($errors as $error) {
        print "<li>{$error}</li>";
    }
    print "</ul></div>";
} else {
    # failed
    if (!modifySubnetMask($_POST['subnetId'], $_POST['newMask'])) {
Ejemplo n.º 2
0
/**
 * Verify that new nested subnet is inside master subnet!
 *
 * $root = root subnet Id
 * $new  = new subnet that we wish to add to root subnet
 */
function verifySubnetNesting($rootId, $new)
{
    //first get details for root subnet
    $rootDetails = getSubnetDetailsById($rootId);
    $rootDetails = Transform2long($rootDetails['subnet']) . "/" . $rootDetails['mask'];
    /* IPv4 or ipv6? */
    $type1 = IdentifyAddress($rootDetails);
    $type2 = IdentifyAddress($new);
    /* both must be IPv4 or IPv6 */
    if ($type1 != $type2) {
        return false;
        die;
    }
    /* we need network and broadcast address and check for both if the exist in any network!*/
    if (isSubnetInsideSubnet($new, $rootDetails)) {
        return true;
    } else {
        return false;
    }
}