コード例 #1
0
/**
 * Add new subnet
 */
function modifySubnetDetails($subnetDetails, $lastId = false)
{
    global $db;
    # get variables from config file
    $database = new database($db['host'], $db['user'], $db['pass'], $db['name']);
    # open db connection
    # replace special chars
    $subnetDetails['permissions'] = mysqli_real_escape_string($database, $subnetDetails['permissions']);
    $subnetDetails['description'] = mysqli_real_escape_string($database, $subnetDetails['description']);
    # set modify subnet details query
    $query = setModifySubnetDetailsQuery($subnetDetails, $sectionChange);
    $log = prepareLogFromArray($subnetDetails);
    # prepare log
    # execute query
    try {
        $updateId = $database->executeMultipleQuerries($query, $lastId);
    } catch (Exception $e) {
        $error = $e->getMessage();
        updateLogTable('Subnet (' . $subnetDetails['description'] . ') ' . $subnetDetails['action'] . ' failed', $log, 2);
        # write error log
        print "<div class='alert alert-error'>{$error}</div>";
        return false;
    }
    # success
    updateLogTable('Subnet (' . $subnetDetails['description'] . ') ' . $subnetDetails['action'] . ' ok', $log, 1);
    # write success log
    if (!$lastId) {
        return true;
    } else {
        return $updateId;
    }
}
コード例 #2
0
/**
 * Add new subnet
 */
function modifySubnetDetails($subnetDetails, $lastId = false, $api = false)
{
    global $database;
    /* escape vars to prevent SQL injection */
    $subnetDetails = filter_user_input($subnetDetails, true, true);
    /* trim user input */
    $subnetDetails = trim_user_input($subnetDetails);
    # set modify subnet details query
    $query = setModifySubnetDetailsQuery($subnetDetails, $api);
    $log = prepareLogFromArray($subnetDetails);
    # prepare log
    /* save old if delete */
    if ($subnetDetails['action'] == "delete") {
        $dold = getSubnetDetailsById($subnetDetails['subnetId']);
    } elseif ($subnetDetails['action'] == "edit") {
        $old = getSubnetDetailsById($subnetDetails['subnetId']);
    }
    # execute query
    try {
        $updateId = $database->executeMultipleQuerries($query, true);
    } catch (Exception $e) {
        $error = $e->getMessage();
        updateLogTable('Subnet (' . $subnetDetails['description'] . ') ' . $subnetDetails['action'] . ' failed', $log, 2);
        # write error log
        print "<div class='alert alert-danger'>{$error}</div>";
        //save changelog
        writeChangelog('subnet', $ip['action'], 'error', $old, $new);
        return false;
    }
    /* for changelog */
    if ($subnetDetails['action'] == "add") {
        $subnetDetails['subnetId'] = $updateId;
        writeChangelog('subnet', $subnetDetails['action'], 'success', array(), $subnetDetails);
    } elseif ($subnetDetails['action'] == "delete") {
        $dold['subnetId'] = $dold['id'];
        writeChangelog('subnet', $subnetDetails['action'], 'success', $dold, array());
    } else {
        writeChangelog('subnet', $subnetDetails['action'], 'success', $old, $subnetDetails);
    }
    // success
    if ($_POST['isFolder'] == false) {
        updateLogTable('Subnet ' . $subnetDetails['subnet'] . ' (' . $subnetDetails['description'] . ') ' . $subnetDetails['action'] . ' ok', $log, 1);
        # write success log
    } else {
        updateLogTable('Folder ' . $subnetDetails['subnet'] . ' (' . $subnetDetails['description'] . ') ' . $subnetDetails['action'] . ' ok', $log, 1);
        # write success log
    }
    // result
    if (!$lastId) {
        return true;
    } else {
        return $updateId;
    }
}
コード例 #3
0
/**
 * Add new subnet
 */
function modifySubnetDetails($subnetDetails, $lastId = false)
{
    global $db;
    # get variables from config file
    $database = new database($db['host'], $db['user'], $db['pass'], $db['name']);
    # open db connection
    # replace special chars
    $subnetDetails['permissions'] = mysqli_real_escape_string($database, $subnetDetails['permissions']);
    $subnetDetails['description'] = mysqli_real_escape_string($database, $subnetDetails['description']);
    # set modify subnet details query
    $query = setModifySubnetDetailsQuery($subnetDetails, $sectionChange);
    $log = prepareLogFromArray($subnetDetails);
    # prepare log
    /* save old if delete */
    if ($subnetDetails['action'] == "delete") {
        $dold = getSubnetDetailsById($subnetDetails['subnetId']);
    } elseif ($subnetDetails['action'] == "edit") {
        $old = getSubnetDetailsById($subnetDetails['subnetId']);
    }
    # execute query
    try {
        $updateId = $database->executeMultipleQuerries($query, true);
    } catch (Exception $e) {
        $error = $e->getMessage();
        updateLogTable('Subnet (' . $subnetDetails['description'] . ') ' . $subnetDetails['action'] . ' failed', $log, 2);
        # write error log
        print "<div class='alert alert-danger'>{$error}</div>";
        //save changelog
        writeChangelog('subnet', $ip['action'], 'error', $old, $new);
        return false;
    }
    /* for changelog */
    if ($subnetDetails['action'] == "add") {
        $subnetDetails['subnetId'] = $updateId;
        writeChangelog('subnet', $subnetDetails['action'], 'success', array(), $subnetDetails);
    } elseif ($subnetDetails['action'] == "delete") {
        $dold['subnetId'] = $dold['id'];
        writeChangelog('subnet', $subnetDetails['action'], 'success', $dold, array());
    } else {
        writeChangelog('subnet', $subnetDetails['action'], 'success', $old, $subnetDetails);
    }
    // success
    if ($_POST['isFolder'] == false) {
        updateLogTable('Subnet ' . $subnetDetails['subnet'] . ' (' . $subnetDetails['description'] . ') ' . $subnetDetails['action'] . ' ok', $log, 1);
        # write success log
    } else {
        updateLogTable('Folder ' . $subnetDetails['subnet'] . ' (' . $subnetDetails['description'] . ') ' . $subnetDetails['action'] . ' ok', $log, 1);
        # write success log
    }
    // result
    if (!$lastId) {
        return true;
    } else {
        return $updateId;
    }
}