mirror of
https://github.com/itflow-org/itflow
synced 2026-05-31 15:18:20 +00:00
API: Add some missing end points
This commit is contained in:
28
api/v1/domains/create.php
Normal file
28
api/v1/domains/create.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
require_once '../validate_api_key.php';
|
||||
|
||||
require_once '../require_post_method.php';
|
||||
|
||||
// Parse Info
|
||||
$domain_row = false; // Creation, not an update
|
||||
require_once 'domain_model.php';
|
||||
|
||||
// Default
|
||||
$insert_id = false;
|
||||
|
||||
if (!empty($name)) {
|
||||
|
||||
$insert_sql = mysqli_query($mysqli, "INSERT INTO domains SET domain_name = '$name', domain_description = '$description', domain_registrar = '$registrar', domain_expire = '$expire', domain_notes = '$notes', domain_vendor_id = $vendor_id, domain_client_id = $client_id");
|
||||
|
||||
if ($insert_sql) {
|
||||
$insert_id = mysqli_insert_id($mysqli);
|
||||
|
||||
// Logging
|
||||
logAction("Domain", "Create", "Created domain $name via API ($api_key_name)", $client_id, $insert_id);
|
||||
logAction("API", "Success", "Created domain $name via API ($api_key_name)", $client_id);
|
||||
}
|
||||
}
|
||||
|
||||
// Output
|
||||
require_once '../create_output.php';
|
||||
28
api/v1/domains/delete.php
Normal file
28
api/v1/domains/delete.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
require_once '../validate_api_key.php';
|
||||
|
||||
require_once '../require_post_method.php';
|
||||
|
||||
// Parse ID
|
||||
$domain_id = intval($_POST['domain_id']);
|
||||
|
||||
// Default
|
||||
$delete_count = false;
|
||||
|
||||
if (!empty($domain_id)) {
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT * FROM domains WHERE domain_id = $domain_id AND domain_client_id = $client_id LIMIT 1"));
|
||||
$domain_name = $row['domain_name'];
|
||||
|
||||
$delete_sql = mysqli_query($mysqli, "DELETE FROM domains WHERE domain_id = $domain_id AND domain_client_id = $client_id LIMIT 1");
|
||||
|
||||
if ($delete_sql && !empty($domain_name)) {
|
||||
$delete_count = mysqli_affected_rows($mysqli);
|
||||
|
||||
// Logging
|
||||
logAction("Domain", "Delete", "$domain_name via API ($api_key_name)", $client_id);
|
||||
}
|
||||
}
|
||||
|
||||
// Output
|
||||
require_once '../delete_output.php';
|
||||
51
api/v1/domains/domain_model.php
Normal file
51
api/v1/domains/domain_model.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
// Variable assignment from POST (or: blank/from DB is updating)
|
||||
|
||||
if (isset($_POST['domain_name'])) {
|
||||
$name = sanitizeInput($_POST['domain_name']);
|
||||
} elseif ($domain_row) {
|
||||
$name = mysqli_real_escape_string($mysqli, $domain_row['domain_name']);
|
||||
} else {
|
||||
$name = '';
|
||||
}
|
||||
|
||||
if (isset($_POST['domain_description'])) {
|
||||
$description = sanitizeInput($_POST['domain_description']);
|
||||
} elseif ($domain_row) {
|
||||
$description = mysqli_real_escape_string($mysqli, $domain_row['domain_description']);
|
||||
} else {
|
||||
$description = '';
|
||||
}
|
||||
|
||||
if (isset($_POST['domain_registrar'])) {
|
||||
$registrar = sanitizeInput($_POST['domain_registrar']);
|
||||
} elseif ($domain_row) {
|
||||
$registrar = mysqli_real_escape_string($mysqli, $domain_row['domain_registrar']);
|
||||
} else {
|
||||
$registrar = '';
|
||||
}
|
||||
|
||||
if (isset($_POST['domain_expire'])) {
|
||||
$expire = sanitizeInput($_POST['domain_expire']);
|
||||
} elseif ($domain_row) {
|
||||
$expire = $domain_row['domain_expire'];
|
||||
} else {
|
||||
$expire = 'NULL';
|
||||
}
|
||||
|
||||
if (isset($_POST['domain_notes'])) {
|
||||
$notes = sanitizeInput($_POST['domain_notes']);
|
||||
} elseif ($domain_row) {
|
||||
$notes = mysqli_real_escape_string($mysqli, $domain_row['domain_notes']);
|
||||
} else {
|
||||
$notes = '';
|
||||
}
|
||||
|
||||
if (isset($_POST['domain_vendor_id'])) {
|
||||
$vendor_id = intval($_POST['domain_vendor_id']);
|
||||
} elseif ($domain_row) {
|
||||
$vendor_id = $domain_row['domain_vendor_id'];
|
||||
} else {
|
||||
$vendor_id = 0;
|
||||
}
|
||||
31
api/v1/domains/update.php
Normal file
31
api/v1/domains/update.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
require_once '../validate_api_key.php';
|
||||
|
||||
require_once '../require_post_method.php';
|
||||
|
||||
// Parse ID
|
||||
$domain_id = intval($_POST['domain_id']);
|
||||
|
||||
// Default
|
||||
$update_count = false;
|
||||
|
||||
if (!empty($domain_id)) {
|
||||
|
||||
$domain_row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT * FROM domains WHERE domain_id = '$domain_id' AND domain_client_id = $client_id LIMIT 1"));
|
||||
|
||||
require_once 'domain_model.php';
|
||||
|
||||
$update_sql = mysqli_query($mysqli, "UPDATE domains SET domain_name = '$name', domain_description = '$description', domain_registrar = '$registrar', domain_expire = '$expire', domain_notes = '$notes', domain_vendor_id = $vendor_id WHERE domain_id = $domain_id AND domain_client_id = $client_id LIMIT 1");
|
||||
|
||||
if ($update_sql) {
|
||||
$update_count = mysqli_affected_rows($mysqli);
|
||||
|
||||
// Logging
|
||||
logAction("Domain", "Edit", "$name via API ($api_key_name)", $client_id);
|
||||
logAction("API", "Success", "Edited domain $name via API ($api_key_name)", $client_id);
|
||||
}
|
||||
}
|
||||
|
||||
// Output
|
||||
require_once '../update_output.php';
|
||||
Reference in New Issue
Block a user