mirror of
https://github.com/getnamingo/registry.git
synced 2025-06-28 07:03:28 +02:00
More work on the panel
This commit is contained in:
parent
ee02066073
commit
ae0c1ee158
5 changed files with 619 additions and 37 deletions
|
@ -10,12 +10,12 @@ use League\ISO3166\ISO3166;
|
|||
|
||||
class ContactsController extends Controller
|
||||
{
|
||||
public function view(Request $request, Response $response)
|
||||
public function listContacts(Request $request, Response $response)
|
||||
{
|
||||
return view($response,'admin/contacts/view.twig');
|
||||
return view($response,'admin/contacts/listContacts.twig');
|
||||
}
|
||||
|
||||
public function create(Request $request, Response $response)
|
||||
public function createContact(Request $request, Response $response)
|
||||
{
|
||||
if ($request->getMethod() === 'POST') {
|
||||
// Retrieve POST data
|
||||
|
@ -58,7 +58,7 @@ class ContactsController extends Controller
|
|||
$authInfo_pw = $data['authInfo'] ?? null;
|
||||
|
||||
if (!$contactID) {
|
||||
return view($response, 'admin/contacts/create.twig', [
|
||||
return view($response, 'admin/contacts/createContact.twig', [
|
||||
'contactID' => $contactID,
|
||||
'error' => 'Please provide a contact ID',
|
||||
'registrars' => $registrars,
|
||||
|
@ -70,7 +70,7 @@ class ContactsController extends Controller
|
|||
// Validation for contact ID
|
||||
$invalid_identifier = validate_identifier($contactID);
|
||||
if ($invalid_identifier) {
|
||||
return view($response, 'admin/contacts/create.twig', [
|
||||
return view($response, 'admin/contacts/createContact.twig', [
|
||||
'contactID' => $contactID,
|
||||
'error' => 'Invalid contact ID',
|
||||
'registrars' => $registrars,
|
||||
|
@ -81,7 +81,7 @@ class ContactsController extends Controller
|
|||
|
||||
$contact = $db->select('SELECT * FROM contact WHERE identifier = ?', [$contactID]);
|
||||
if ($contact) {
|
||||
return view($response, 'admin/contacts/create.twig', [
|
||||
return view($response, 'admin/contacts/createContact.twig', [
|
||||
'contactID' => $contactID,
|
||||
'error' => 'Contact ID already exists',
|
||||
'registrars' => $registrars,
|
||||
|
@ -100,7 +100,7 @@ class ContactsController extends Controller
|
|||
|
||||
if ($postalInfoIntName) {
|
||||
if (!$postalInfoIntName) {
|
||||
return view($response, 'admin/contacts/create.twig', [
|
||||
return view($response, 'admin/contacts/createContact.twig', [
|
||||
'contactID' => $contactID,
|
||||
'error' => 'Missing contact name',
|
||||
'registrars' => $registrars,
|
||||
|
@ -110,7 +110,7 @@ class ContactsController extends Controller
|
|||
}
|
||||
|
||||
if (preg_match('/(^\-)|(^\,)|(^\.)|(\-\-)|(\,\,)|(\.\.)|(\-$)/', $postalInfoIntName) || !preg_match('/^[a-zA-Z0-9\-\&\,\.\/\s]{5,}$/', $postalInfoIntName)) {
|
||||
return view($response, 'admin/contacts/create.twig', [
|
||||
return view($response, 'admin/contacts/createContact.twig', [
|
||||
'contactID' => $contactID,
|
||||
'error' => 'Invalid contact name',
|
||||
'registrars' => $registrars,
|
||||
|
@ -121,7 +121,7 @@ class ContactsController extends Controller
|
|||
|
||||
if ($postalInfoIntOrg) {
|
||||
if (preg_match('/(^\-)|(^\,)|(^\.)|(\-\-)|(\,\,)|(\.\.)|(\-$)/', $postalInfoIntOrg) || !preg_match('/^[a-zA-Z0-9\-\&\,\.\/\s]{5,}$/', $postalInfoIntOrg)) {
|
||||
return view($response, 'admin/contacts/create.twig', [
|
||||
return view($response, 'admin/contacts/createContact.twig', [
|
||||
'contactID' => $contactID,
|
||||
'error' => 'Invalid contact org',
|
||||
'registrars' => $registrars,
|
||||
|
@ -133,7 +133,7 @@ class ContactsController extends Controller
|
|||
|
||||
if ($postalInfoIntStreet1) {
|
||||
if (preg_match('/(^\-)|(^\,)|(^\.)|(\-\-)|(\,\,)|(\.\.)|(\-$)/', $postalInfoIntStreet1) || !preg_match('/^[a-zA-Z0-9\-\&\,\.\/\s]{5,}$/', $postalInfoIntStreet1)) {
|
||||
return view($response, 'admin/contacts/create.twig', [
|
||||
return view($response, 'admin/contacts/createContact.twig', [
|
||||
'contactID' => $contactID,
|
||||
'error' => 'Invalid contact street',
|
||||
'registrars' => $registrars,
|
||||
|
@ -145,7 +145,7 @@ class ContactsController extends Controller
|
|||
|
||||
if ($postalInfoIntStreet2) {
|
||||
if (preg_match('/(^\-)|(^\,)|(^\.)|(\-\-)|(\,\,)|(\.\.)|(\-$)/', $postalInfoIntStreet2) || !preg_match('/^[a-zA-Z0-9\-\&\,\.\/\s]{5,}$/', $postalInfoIntStreet2)) {
|
||||
return view($response, 'admin/contacts/create.twig', [
|
||||
return view($response, 'admin/contacts/createContact.twig', [
|
||||
'contactID' => $contactID,
|
||||
'error' => 'Invalid contact street',
|
||||
'registrars' => $registrars,
|
||||
|
@ -157,7 +157,7 @@ class ContactsController extends Controller
|
|||
|
||||
if ($postalInfoIntStreet3) {
|
||||
if (preg_match('/(^\-)|(^\,)|(^\.)|(\-\-)|(\,\,)|(\.\.)|(\-$)/', $postalInfoIntStreet3) || !preg_match('/^[a-zA-Z0-9\-\&\,\.\/\s]{5,}$/', $postalInfoIntStreet3)) {
|
||||
return view($response, 'admin/contacts/create.twig', [
|
||||
return view($response, 'admin/contacts/createContact.twig', [
|
||||
'contactID' => $contactID,
|
||||
'error' => 'Invalid contact street',
|
||||
'registrars' => $registrars,
|
||||
|
@ -168,7 +168,7 @@ class ContactsController extends Controller
|
|||
}
|
||||
|
||||
if (preg_match('/(^\-)|(^\.)|(\-\-)|(\.\.)|(\.\-)|(\-\.)|(\-$)|(\.$)/', $postalInfoIntCity) || !preg_match('/^[a-z][a-z\-\.\s]{3,}$/i', $postalInfoIntCity)) {
|
||||
return view($response, 'admin/contacts/create.twig', [
|
||||
return view($response, 'admin/contacts/createContact.twig', [
|
||||
'contactID' => $contactID,
|
||||
'error' => 'Invalid contact city',
|
||||
'registrars' => $registrars,
|
||||
|
@ -179,7 +179,7 @@ class ContactsController extends Controller
|
|||
|
||||
if ($postalInfoIntSp) {
|
||||
if (preg_match('/(^\-)|(^\.)|(\-\-)|(\.\.)|(\.\-)|(\-\.)|(\-$)|(\.$)/', $postalInfoIntSp) || !preg_match('/^[A-Z][a-zA-Z\-\.\s]{1,}$/', $postalInfoIntSp)) {
|
||||
return view($response, 'admin/contacts/create.twig', [
|
||||
return view($response, 'admin/contacts/createContact.twig', [
|
||||
'contactID' => $contactID,
|
||||
'error' => 'Invalid contact state/province',
|
||||
'registrars' => $registrars,
|
||||
|
@ -191,7 +191,7 @@ class ContactsController extends Controller
|
|||
|
||||
if ($postalInfoIntPc) {
|
||||
if (preg_match('/(^\-)|(\-\-)|(\-$)/', $postalInfoIntPc) || !preg_match('/^[A-Z0-9\-\s]{3,}$/', $postalInfoIntPc)) {
|
||||
return view($response, 'admin/contacts/create.twig', [
|
||||
return view($response, 'admin/contacts/createContact.twig', [
|
||||
'contactID' => $contactID,
|
||||
'error' => 'Invalid contact postal code',
|
||||
'registrars' => $registrars,
|
||||
|
@ -205,7 +205,7 @@ class ContactsController extends Controller
|
|||
|
||||
if ($postalInfoLocName) {
|
||||
if (!$postalInfoLocName) {
|
||||
return view($response, 'admin/contacts/create.twig', [
|
||||
return view($response, 'admin/contacts/createContact.twig', [
|
||||
'contactID' => $contactID,
|
||||
'error' => 'Missing loc contact name',
|
||||
'registrars' => $registrars,
|
||||
|
@ -215,7 +215,7 @@ class ContactsController extends Controller
|
|||
}
|
||||
|
||||
if (preg_match('/(^\-)|(^\,)|(^\.)|(\-\-)|(\,\,)|(\.\.)|(\-$)/', $postalInfoLocName) || !preg_match('/^[a-zA-Z0-9\-\&\,\.\/\s]{5,}$/', $postalInfoLocName)) {
|
||||
return view($response, 'admin/contacts/create.twig', [
|
||||
return view($response, 'admin/contacts/createContact.twig', [
|
||||
'contactID' => $contactID,
|
||||
'error' => 'Invalid loc contact name',
|
||||
'registrars' => $registrars,
|
||||
|
@ -226,7 +226,7 @@ class ContactsController extends Controller
|
|||
|
||||
if ($postalInfoLocOrg) {
|
||||
if (preg_match('/(^\-)|(^\,)|(^\.)|(\-\-)|(\,\,)|(\.\.)|(\-$)/', $postalInfoLocOrg) || !preg_match('/^[a-zA-Z0-9\-\&\,\.\/\s]{5,}$/', $postalInfoLocOrg)) {
|
||||
return view($response, 'admin/contacts/create.twig', [
|
||||
return view($response, 'admin/contacts/createContact.twig', [
|
||||
'contactID' => $contactID,
|
||||
'error' => 'Invalid loc contact org',
|
||||
'registrars' => $registrars,
|
||||
|
@ -238,7 +238,7 @@ class ContactsController extends Controller
|
|||
|
||||
if ($postalInfoLocStreet1) {
|
||||
if (preg_match('/(^\-)|(^\,)|(^\.)|(\-\-)|(\,\,)|(\.\.)|(\-$)/', $postalInfoLocStreet1) || !preg_match('/^[a-zA-Z0-9\-\&\,\.\/\s]{5,}$/', $postalInfoLocStreet1)) {
|
||||
return view($response, 'admin/contacts/create.twig', [
|
||||
return view($response, 'admin/contacts/createContact.twig', [
|
||||
'contactID' => $contactID,
|
||||
'error' => 'Invalid loc contact street',
|
||||
'registrars' => $registrars,
|
||||
|
@ -250,7 +250,7 @@ class ContactsController extends Controller
|
|||
|
||||
if ($postalInfoLocStreet2) {
|
||||
if (preg_match('/(^\-)|(^\,)|(^\.)|(\-\-)|(\,\,)|(\.\.)|(\-$)/', $postalInfoLocStreet2) || !preg_match('/^[a-zA-Z0-9\-\&\,\.\/\s]{5,}$/', $postalInfoLocStreet2)) {
|
||||
return view($response, 'admin/contacts/create.twig', [
|
||||
return view($response, 'admin/contacts/createContact.twig', [
|
||||
'contactID' => $contactID,
|
||||
'error' => 'Invalid loc contact street',
|
||||
'registrars' => $registrars,
|
||||
|
@ -262,7 +262,7 @@ class ContactsController extends Controller
|
|||
|
||||
if ($postalInfoLocStreet3) {
|
||||
if (preg_match('/(^\-)|(^\,)|(^\.)|(\-\-)|(\,\,)|(\.\.)|(\-$)/', $postalInfoLocStreet3) || !preg_match('/^[a-zA-Z0-9\-\&\,\.\/\s]{5,}$/', $postalInfoLocStreet3)) {
|
||||
return view($response, 'admin/contacts/create.twig', [
|
||||
return view($response, 'admin/contacts/createContact.twig', [
|
||||
'contactID' => $contactID,
|
||||
'error' => 'Invalid loc contact street',
|
||||
'registrars' => $registrars,
|
||||
|
@ -273,7 +273,7 @@ class ContactsController extends Controller
|
|||
}
|
||||
|
||||
if (preg_match('/(^\-)|(^\.)|(\-\-)|(\.\.)|(\.\-)|(\-\.)|(\-$)|(\.$)/', $postalInfoLocCity) || !preg_match('/^[a-z][a-z\-\.\s]{3,}$/i', $postalInfoLocCity)) {
|
||||
return view($response, 'admin/contacts/create.twig', [
|
||||
return view($response, 'admin/contacts/createContact.twig', [
|
||||
'contactID' => $contactID,
|
||||
'error' => 'Invalid loc contact city',
|
||||
'registrars' => $registrars,
|
||||
|
@ -284,7 +284,7 @@ class ContactsController extends Controller
|
|||
|
||||
if ($postalInfoLocSp) {
|
||||
if (preg_match('/(^\-)|(^\.)|(\-\-)|(\.\.)|(\.\-)|(\-\.)|(\-$)|(\.$)/', $postalInfoLocSp) || !preg_match('/^[A-Z][a-zA-Z\-\.\s]{1,}$/', $postalInfoLocSp)) {
|
||||
return view($response, 'admin/contacts/create.twig', [
|
||||
return view($response, 'admin/contacts/createContact.twig', [
|
||||
'contactID' => $contactID,
|
||||
'error' => 'Invalid loc contact state/province',
|
||||
'registrars' => $registrars,
|
||||
|
@ -296,7 +296,7 @@ class ContactsController extends Controller
|
|||
|
||||
if ($postalInfoLocPc) {
|
||||
if (preg_match('/(^\-)|(\-\-)|(\-$)/', $postalInfoLocPc) || !preg_match('/^[A-Z0-9\-\s]{3,}$/', $postalInfoLocPc)) {
|
||||
return view($response, 'admin/contacts/create.twig', [
|
||||
return view($response, 'admin/contacts/createContact.twig', [
|
||||
'contactID' => $contactID,
|
||||
'error' => 'Invalid loc contact postal code',
|
||||
'registrars' => $registrars,
|
||||
|
@ -309,7 +309,7 @@ class ContactsController extends Controller
|
|||
}
|
||||
|
||||
if ($voice && (!preg_match('/^\+\d{1,3}\.\d{1,14}$/', $voice) || strlen($voice) > 17)) {
|
||||
return view($response, 'admin/contacts/create.twig', [
|
||||
return view($response, 'admin/contacts/createContact.twig', [
|
||||
'contactID' => $contactID,
|
||||
'error' => 'Voice must be (\+[0-9]{1,3}\.[0-9]{1,14})',
|
||||
'registrars' => $registrars,
|
||||
|
@ -319,7 +319,7 @@ class ContactsController extends Controller
|
|||
}
|
||||
|
||||
if ($fax && (!preg_match('/^\+\d{1,3}\.\d{1,14}$/', $fax) || strlen($fax) > 17)) {
|
||||
return view($response, 'admin/contacts/create.twig', [
|
||||
return view($response, 'admin/contacts/createContact.twig', [
|
||||
'contactID' => $contactID,
|
||||
'error' => 'Fax must be (\+[0-9]{1,3}\.[0-9]{1,14})',
|
||||
'registrars' => $registrars,
|
||||
|
@ -329,7 +329,7 @@ class ContactsController extends Controller
|
|||
}
|
||||
|
||||
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
return view($response, 'admin/contacts/create.twig', [
|
||||
return view($response, 'admin/contacts/createContact.twig', [
|
||||
'contactID' => $contactID,
|
||||
'error' => 'Email address failed check',
|
||||
'registrars' => $registrars,
|
||||
|
@ -339,7 +339,7 @@ class ContactsController extends Controller
|
|||
}
|
||||
|
||||
if (!$authInfo_pw) {
|
||||
return view($response, 'admin/contacts/create.twig', [
|
||||
return view($response, 'admin/contacts/createContact.twig', [
|
||||
'contactID' => $contactID,
|
||||
'error' => 'Email contact authinfo',
|
||||
'registrars' => $registrars,
|
||||
|
@ -349,7 +349,7 @@ class ContactsController extends Controller
|
|||
}
|
||||
|
||||
if ((strlen($authInfo_pw) < 6) || (strlen($authInfo_pw) > 16)) {
|
||||
return view($response, 'admin/contacts/create.twig', [
|
||||
return view($response, 'admin/contacts/createContact.twig', [
|
||||
'contactID' => $contactID,
|
||||
'error' => 'Password needs to be at least 6 and up to 16 characters long',
|
||||
'registrars' => $registrars,
|
||||
|
@ -359,7 +359,7 @@ class ContactsController extends Controller
|
|||
}
|
||||
|
||||
if (!preg_match('/[A-Z]/', $authInfo_pw)) {
|
||||
return view($response, 'admin/contacts/create.twig', [
|
||||
return view($response, 'admin/contacts/createContact.twig', [
|
||||
'contactID' => $contactID,
|
||||
'error' => 'Password should have both upper and lower case characters',
|
||||
'registrars' => $registrars,
|
||||
|
@ -383,7 +383,7 @@ class ContactsController extends Controller
|
|||
$nin_type = (isset($data['isBusiness']) && $data['isBusiness'] === 1) ? 'business' : 'personal';
|
||||
|
||||
if (!preg_match('/\d/', $nin)) {
|
||||
return view($response, 'admin/contacts/create.twig', [
|
||||
return view($response, 'admin/contacts/createContact.twig', [
|
||||
'contactID' => $contactID,
|
||||
'error' => 'NIN should contain one or more numbers',
|
||||
'registrars' => $registrars,
|
||||
|
@ -481,7 +481,7 @@ class ContactsController extends Controller
|
|||
$db->commit();
|
||||
} catch (Exception $e) {
|
||||
$db->rollBack();
|
||||
return view($response, 'admin/contacts/create.twig', [
|
||||
return view($response, 'admin/contacts/createContact.twig', [
|
||||
'contactID' => $contactID,
|
||||
'error' => $e->getMessage(),
|
||||
'registrars' => $registrars,
|
||||
|
@ -495,7 +495,7 @@ class ContactsController extends Controller
|
|||
[$contact_id]
|
||||
);
|
||||
|
||||
return view($response, 'admin/contacts/create.twig', [
|
||||
return view($response, 'admin/contacts/createContact.twig', [
|
||||
'contactID' => $contactID,
|
||||
'crdate' => $crdate,
|
||||
'registrars' => $registrars,
|
||||
|
@ -515,7 +515,7 @@ class ContactsController extends Controller
|
|||
}
|
||||
|
||||
// Default view for GET requests or if POST data is not set
|
||||
return view($response,'admin/contacts/create.twig', [
|
||||
return view($response,'admin/contacts/createContact.twig', [
|
||||
'registrars' => $registrars,
|
||||
'countries' => $countries,
|
||||
'registrar' => $registrar,
|
||||
|
@ -578,4 +578,274 @@ class ContactsController extends Controller
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
public function updateContact(Request $request, Response $response, $args)
|
||||
{
|
||||
$db = $this->container->get('db');
|
||||
// Get the current URI
|
||||
$uri = $request->getUri()->getPath();
|
||||
|
||||
if ($args) {
|
||||
$contact = $db->selectRow('SELECT id, identifier, voice, fax, email, nin, nin_type, crdate, clid, disclose_voice, disclose_fax, disclose_email FROM contact WHERE identifier = ?',
|
||||
[ $args ]);
|
||||
|
||||
if ($contact) {
|
||||
$registrars = $db->selectRow('SELECT id, clid, name FROM registrar WHERE id = ?', [$contact['clid']]);
|
||||
$iso3166 = new ISO3166();
|
||||
$countries = $iso3166->all();
|
||||
|
||||
// Check if the user is not an admin (assuming role 0 is admin)
|
||||
if ($_SESSION["auth_roles"] != 0) {
|
||||
$userRegistrars = $db->select('SELECT registrar_id FROM registrar_users WHERE user_id = ?', [$_SESSION['auth_user_id']]);
|
||||
|
||||
// Assuming $userRegistrars returns an array of arrays, each containing 'registrar_id'
|
||||
$userRegistrarIds = array_column($userRegistrars, 'registrar_id');
|
||||
|
||||
// Check if the registrar's ID is in the user's list of registrar IDs
|
||||
if (!in_array($registrars['id'], $userRegistrarIds)) {
|
||||
// Redirect to the contacts view if the user is not authorized for this contact
|
||||
return $response->withHeader('Location', '/contacts')->withStatus(302);
|
||||
}
|
||||
}
|
||||
|
||||
$contactStatus = $db->selectRow('SELECT status FROM contact_status WHERE contact_id = ?',
|
||||
[ $contact['id'] ]);
|
||||
$contactAuth = $db->selectRow('SELECT authinfo FROM contact_authInfo WHERE contact_id = ?',
|
||||
[ $contact['id'] ]);
|
||||
$contactPostal = $db->select('SELECT * FROM contact_postalInfo WHERE contact_id = ?',
|
||||
[ $contact['id'] ]);
|
||||
|
||||
return view($response,'admin/contacts/updateContact.twig', [
|
||||
'contact' => $contact,
|
||||
'contactStatus' => $contactStatus,
|
||||
'contactAuth' => $contactAuth,
|
||||
'contactPostal' => $contactPostal,
|
||||
'registrars' => $registrars,
|
||||
'countries' => $countries
|
||||
]);
|
||||
} else {
|
||||
// Contact does not exist, redirect to the contacts view
|
||||
return $response->withHeader('Location', '/contacts')->withStatus(302);
|
||||
}
|
||||
|
||||
} else {
|
||||
// Redirect to the contacts view
|
||||
return $response->withHeader('Location', '/contacts')->withStatus(302);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function updateContactProcess(Request $request, Response $response)
|
||||
{
|
||||
if ($request->getMethod() === 'POST') {
|
||||
// Retrieve POST data
|
||||
$data = $request->getParsedBody();
|
||||
var_dump ($data);die();
|
||||
$db = $this->container->get('db');
|
||||
$identifier = $data['identifier'] ?? null;
|
||||
|
||||
$result = $db->selectRow('SELECT registrar_id FROM registrar_users WHERE user_id = ?', [$_SESSION['auth_user_id']]);
|
||||
|
||||
if ($_SESSION["auth_roles"] != 0) {
|
||||
$clid = $result['registrar_id'];
|
||||
} else {
|
||||
$clid = $db->selectValue('SELECT clid FROM host WHERE name = ?', [$hostName]);
|
||||
}
|
||||
|
||||
$ipv4 = $data['ipv4'] ?? null;
|
||||
$ipv6 = $data['ipv6'] ?? null;
|
||||
|
||||
try {
|
||||
$db->beginTransaction();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$host_id = $db->selectValue(
|
||||
'SELECT id FROM host WHERE name = ?',
|
||||
[$hostName]
|
||||
);
|
||||
|
||||
if (isset($ipv4) && !empty($ipv4)) {
|
||||
$ipv4 = normalize_v4_address($ipv4);
|
||||
|
||||
$does_it_exist = $db->selectValue("SELECT id FROM host_addr WHERE host_id = ? AND ip = 'v4'", [$host_id]);
|
||||
|
||||
if ($does_it_exist) {
|
||||
$db->update(
|
||||
'host_addr',
|
||||
[
|
||||
'addr' => $ipv4
|
||||
],
|
||||
[
|
||||
'host_id' => $host_id,
|
||||
'ip' => 'v4'
|
||||
]
|
||||
);
|
||||
} else {
|
||||
$db->insert(
|
||||
'host_addr',
|
||||
[
|
||||
'addr' => $ipv4,
|
||||
'host_id' => $host_id,
|
||||
'ip' => 'v4'
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (isset($ipv6) && !empty($ipv6)) {
|
||||
$ipv6 = normalize_v6_address($ipv6);
|
||||
|
||||
$does_it_exist = $db->selectValue("SELECT id FROM host_addr WHERE host_id = ? AND ip = 'v6'", [$host_id]);
|
||||
|
||||
if ($does_it_exist) {
|
||||
$db->update(
|
||||
'host_addr',
|
||||
[
|
||||
'addr' => $ipv6
|
||||
],
|
||||
[
|
||||
'host_id' => $host_id,
|
||||
'ip' => 'v6'
|
||||
]
|
||||
);
|
||||
} else {
|
||||
$db->insert(
|
||||
'host_addr',
|
||||
[
|
||||
'addr' => $ipv6,
|
||||
'host_id' => $host_id,
|
||||
'ip' => 'v6'
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$currentDateTime = new \DateTime();
|
||||
$update = $currentDateTime->format('Y-m-d H:i:s.v'); // Current timestamp
|
||||
|
||||
$db->update('host', [
|
||||
'update' => $update,
|
||||
'upid' => $clid
|
||||
],
|
||||
[
|
||||
'name' => $hostName
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$db->commit();
|
||||
} catch (Exception $e) {
|
||||
$db->rollBack();
|
||||
$this->container->get('flash')->addMessage('error', 'Database failure during update: ' . $e->getMessage());
|
||||
return $response->withHeader('Location', '/host/update/'.$hostName)->withStatus(302);
|
||||
}
|
||||
|
||||
$this->container->get('flash')->addMessage('success', 'Host ' . $hostName . ' has been updated successfully on ' . $update);
|
||||
return $response->withHeader('Location', '/host/update/'.$hostName)->withStatus(302);
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteContact(Request $request, Response $response, $args)
|
||||
{
|
||||
// if ($request->getMethod() === 'POST') {
|
||||
$db = $this->container->get('db');
|
||||
// Get the current URI
|
||||
$uri = $request->getUri()->getPath();
|
||||
|
||||
if ($args) {
|
||||
$contact_id = $db->selectValue('SELECT id FROM contact WHERE identifier = ?',
|
||||
[ $args ]);
|
||||
|
||||
$is_linked_registrant = $db->selectRow('SELECT id FROM domain WHERE registrant = ?',
|
||||
[ $contact_id ]);
|
||||
|
||||
if ($is_linked_registrant) {
|
||||
$this->container->get('flash')->addMessage('error', 'This contact is associated with a domain as a registrant');
|
||||
return $response->withHeader('Location', '/hosts')->withStatus(302);
|
||||
}
|
||||
|
||||
$is_linked_other = $db->selectRow('SELECT contact_id FROM domain_contact_map WHERE contact_id = ?',
|
||||
[ $contact_id ]);
|
||||
|
||||
if ($is_linked_other) {
|
||||
$this->container->get('flash')->addMessage('error', 'This contact is associated with a domain');
|
||||
return $response->withHeader('Location', '/contacts')->withStatus(302);
|
||||
}
|
||||
|
||||
$statuses = $db->select('SELECT status FROM contact_status WHERE contact_id = ?', [$contact_id]);
|
||||
|
||||
foreach ($statuses as $status) {
|
||||
if (preg_match('/.*(UpdateProhibited|DeleteProhibited)$/', $status['status']) || preg_match('/^pending/', $status['status'])) {
|
||||
$this->container->get('flash')->addMessage('error', 'It has a status that does not allow deletion');
|
||||
return $response->withHeader('Location', '/contacts')->withStatus(302);
|
||||
}
|
||||
}
|
||||
|
||||
$db->delete(
|
||||
'contact_postalInfo',
|
||||
[
|
||||
'contact_id' => $contact_id
|
||||
]
|
||||
);
|
||||
|
||||
$db->delete(
|
||||
'contact_authInfo',
|
||||
[
|
||||
'contact_id' => $contact_id
|
||||
]
|
||||
);
|
||||
|
||||
$db->delete(
|
||||
'contact_status',
|
||||
[
|
||||
'contact_id' => $contact_id
|
||||
]
|
||||
);
|
||||
|
||||
$db->delete(
|
||||
'contact',
|
||||
[
|
||||
'id' => $contact_id
|
||||
]
|
||||
);
|
||||
|
||||
$this->container->get('flash')->addMessage('success', 'Contact ' . $args . ' deleted successfully');
|
||||
return $response->withHeader('Location', '/contacts')->withStatus(302);
|
||||
} else {
|
||||
// Redirect to the hosts view
|
||||
return $response->withHeader('Location', '/contacts')->withStatus(302);
|
||||
}
|
||||
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue