/* Set permissions for add! */
if ($_POST['action'] == "add") {
    # root
    if ($_POST['masterSubnetId'] == 0) {
        $_POST['permissions'] = $section['permissions'];
    } else {
        # get parent
        $parent = getSubnetDetailsById($_POST['masterSubnetId']);
        $_POST['permissions'] = $parent['permissions'];
    }
}
/* If no errors are present execute request */
if (sizeof($errors) != 0) {
    print '<div class="alert alert-danger"><strong>' . _('Please fix following problems') . '</strong>:';
    foreach ($errors as $error) {
        print "<br>" . $error;
    }
    print '</div>';
    die;
} else {
    # failed
    if (!modifySubnetDetails($_POST)) {
        print '<div class="alert alert-danger">' . _('Error adding new subnet') . '!</div>';
    } else {
        if ($_POST['action'] == "delete") {
            print '<div class="alert alert-success">' . _('Subnet, IP addresses and all belonging subnets deleted successfully') . '!</div>';
        } else {
            print '<div class="alert alert-success">' . _("Subnet {$_POST['action']} successfull") . '!</div>';
        }
    }
}
    print "<div class='alert alert-danger'>" . _('Wrong IP addresses (subnet or broadcast)') . "<ul>";
    foreach ($errors as $error) {
        print "<li>{$error}</li>";
    }
    print "</ul></div>";
    die;
}
# create new subnets and change subnetId for recalculated hosts
$m = 0;
foreach ($newsubnets as $subnet) {
    # set action and subnet - must be in long format
    $subnet['action'] = "add";
    $subnet['description'] = $subnet['description'] . "/{$m}";
    $subnet['subnet'] = transform2long($subnet['subnet']) . "/" . $subnet['mask'];
    # create subnet and save last id
    $lastId = modifySubnetDetails($subnet, true);
    # true returns last id
    # save all to array
    $lastIdArray[] = $lastId;
    # replace ID in IP addresses
    foreach ($ipaddresses as $ip) {
        if ($ip['subnetId'] == $m) {
            $ip['ip_addr'] = transform2long($ip['ip_addr']);
            if (!moveIPAddress($ip['id'], $lastId)) {
                $errors[] = $ip['ip_addr'];
            }
        }
    }
    # next
    $m++;
}
Esempio n. 3
0
            $errors[] = verifySubnetOverlapping($subnetDetails['sectionId'], $subnetDetails['subnet'], "000");
        } else {
            if (verifyNestedSubnetOverlapping($subnetDetails['sectionId'], $subnetDetails['subnet'], "000")) {
                $errors[] = verifyNestedSubnetOverlapping($subnetDetails['sectionId'], $subnetDetails['subnet'], "000");
            } else {
                $subnetInsert[] = $subnetDetails;
            }
        }
    }
}
/* print errors if they exist or success */
if (!isset($errors)) {
    $errors2 = 0;
    //insert if all other is ok!
    foreach ($subnetInsert as $subnetDetails) {
        if (!modifySubnetDetails($subnetDetails)) {
            print '<div class="alert alert-danger alert-absolute">' . _('Failed to import subnet') . ' ' . $subnetDetails['subnet'] . '</div>';
            $errors2++;
        }
    }
    //check if all is ok and print it!
    if ($errors2 == 0) {
        print '<div class="alert alert-success alert-absolute">' . _('Import successfull') . '!</div>';
    }
} else {
    print '<div class="alert alert-danger alert-absolute">' . _('Please fix the following errors before inserting') . ':<hr>' . "\n";
    foreach ($errors as $line) {
        print $line . '<br>';
    }
    print '</div>';
}