/** * Modify API details */ function modifyAPI($api) { global $database; # set query based on action if ($api['action'] == "add") { $query = "insert into `api` (`app_id`,`app_code`,`app_permissions`, `app_comment`) values ('{$api['app_id']}','{$api['app_code']}','{$api['app_permissions']}', '{$api['app_comment']}');"; } elseif ($api['action'] == "edit") { $query = "update `api` set `app_id`='{$api['app_id']}',`app_code`='{$api['app_code']}',`app_permissions`='{$api['app_permissions']}', `app_comment`='{$api['app_comment']}' where `id`={$api['id']} ; "; } elseif ($api['action'] == "delete") { $query = "delete from `api` where `id` = {$api['id']};"; } else { return false; } $log = prepareLogFromArray($api); # prepare log /* execute */ try { $database->executeQuery($query); } catch (Exception $e) { $error = $e->getMessage(); updateLogTable('API update failed - ' . $error, $log, 2); # write error log return false; } # success updateLogTable('API updated ok', $log, 1); # write success log return true; }
/** * Insert new IP request */ function addNewRequest($request) { global $database; # replace special chars for description $request['description'] = mysqli_real_escape_string($database, $request['description']); /* set query */ $query = 'insert into requests ' . "\n"; $query .= '(`subnetId`, `ip_addr`,`description`,`dns_name`,`owner`,`requester`,`comment`,`processed`) ' . "\n"; $query .= 'values ' . "\n"; $query .= '("' . $request['subnetId'] . '", "' . $request['ip_addr'] . '", "' . $request['description'] . '", ' . "\n"; $query .= ' "' . $request['dns_name'] . '", "' . $request['owner'] . '", "' . $request['requester'] . '", "' . $request['comment'] . '", "0");'; /* set log file */ $log = prepareLogFromArray($request); /* execute */ try { $database->executeQuery($query); } catch (Exception $e) { $error = $e->getMessage(); print "<div class='alert alert-danger'>" . _('Error') . ": {$error}</div>"; updateLogTable('Failed to add new IP request', $log . "\n" . $error, 2); return false; } /* return success */ updateLogTable('New IP request added', $log, 1); return true; }
$ip['action'] = "edit"; } else { $ip['action'] = "add"; } } //if it fails set error log if (!modifyIpAddress($ip)) { $errors[] = _('Cannot') . ' ' . $ip['action'] . ' ' . _('IP address') . ' ' . transform2long($m); } /* next IP */ $m = gmp_strval(gmp_add($m, 1)); } /* print errors if they exist */ if (isset($errors)) { print '<div class="alert alert-danger">'; $log = prepareLogFromArray($errors); print $log; print '</div>'; updateLogTable('Error ' . $ip['action'] . ' range ' . $ip['start'] . ' - ' . $ip['stop'], $log, 2); } else { print '<div class="alert alert-success">' . _('Range') . ' ' . $ip['start'] . ' - ' . $ip['stop'] . ' ' . _('updated successfully') . '!</div>'; updateLogTable('Range ' . $ip['start'] . ' - ' . $ip['stop'] . ' ' . $ip['action'] . ' successfull!', 'Range ' . $ip['start'] . ' - ' . $ip['stop'] . ' ' . $ip['action'] . ' ' . _('successfull') . '!', 0); } } else { /* unique */ if (isset($_POST['unique'])) { if ($_POST['unique'] == "1" && strlen($_POST['dns_name']) > 0) { # check if unique if (!isHostUnique($_POST['dns_name'])) { die('<div class="alert alert-danger">' . _('Hostname is not unique') . '!</div>'); }