From a7aa791fb553de9d1b98977b3cc0a76312835797 Mon Sep 17 00:00:00 2001 From: Pinga <121483313+getpinga@users.noreply.github.com> Date: Mon, 4 Dec 2023 14:25:37 +0200 Subject: [PATCH] DomainUpdate CP almost ready --- cp/app/Controllers/DomainsController.php | 565 ++++++++++++++++-- cp/resources/views/admin/dashboard/index.twig | 6 +- .../domains/{check.twig => checkDomain.twig} | 0 .../{create.twig => createDomain.twig} | 0 .../views/admin/domains/editDomain.twig | 291 +++++++++ .../domains/{view.twig => listDomains.twig} | 6 +- .../{transfers.twig => listTransfers.twig} | 0 .../views/admin/domains/updateDomain.twig | 267 +++++++++ cp/resources/views/layouts/app.twig | 15 +- cp/resources/views/layouts/auth.twig | 12 +- cp/resources/views/partials/flash.twig | 6 +- cp/resources/views/partials/js-domains.twig | 61 +- cp/routes/web.php | 16 +- 13 files changed, 1130 insertions(+), 115 deletions(-) rename cp/resources/views/admin/domains/{check.twig => checkDomain.twig} (100%) rename cp/resources/views/admin/domains/{create.twig => createDomain.twig} (100%) create mode 100644 cp/resources/views/admin/domains/editDomain.twig rename cp/resources/views/admin/domains/{view.twig => listDomains.twig} (96%) rename cp/resources/views/admin/domains/{transfers.twig => listTransfers.twig} (100%) create mode 100644 cp/resources/views/admin/domains/updateDomain.twig diff --git a/cp/app/Controllers/DomainsController.php b/cp/app/Controllers/DomainsController.php index fb79413..eb181f9 100644 --- a/cp/app/Controllers/DomainsController.php +++ b/cp/app/Controllers/DomainsController.php @@ -9,12 +9,12 @@ use Psr\Container\ContainerInterface; class DomainsController extends Controller { - public function view(Request $request, Response $response) + public function listDomains(Request $request, Response $response) { - return view($response,'admin/domains/view.twig'); + return view($response,'admin/domains/listDomains.twig'); } - public function check(Request $request, Response $response) + public function checkDomain(Request $request, Response $response) { if ($request->getMethod() === 'POST') { // Retrieve POST data @@ -59,7 +59,7 @@ class DomainsController extends Controller } } - return view($response, 'admin/domains/check.twig', [ + return view($response, 'admin/domains/checkDomain.twig', [ 'isAvailable' => $isAvailable, 'domainName' => $domainName, 'status' => $status, @@ -68,10 +68,10 @@ class DomainsController extends Controller } // Default view for GET requests or if POST data is not set - return view($response,'admin/domains/check.twig'); + return view($response,'admin/domains/checkDomain.twig'); } - public function create(Request $request, Response $response) + public function createDomain(Request $request, Response $response) { if ($request->getMethod() === 'POST') { // Retrieve POST data @@ -111,7 +111,7 @@ class DomainsController extends Controller $invalid_domain = validate_label($domainName, $db); if ($invalid_domain) { - return view($response, 'admin/domains/create.twig', [ + return view($response, 'admin/domains/createDomain.twig', [ 'domainName' => $domainName, 'error' => 'Invalid domain name', 'registrars' => $registrars, @@ -131,7 +131,7 @@ class DomainsController extends Controller } if (!$valid_tld) { - return view($response, 'admin/domains/create.twig', [ + return view($response, 'admin/domains/createDomain.twig', [ 'domainName' => $domainName, 'error' => 'Invalid domain extension', 'registrars' => $registrars, @@ -145,7 +145,7 @@ class DomainsController extends Controller ); if ($domain_already_exist) { - return view($response, 'admin/domains/create.twig', [ + return view($response, 'admin/domains/createDomain.twig', [ 'domainName' => $domainName, 'error' => 'Domain name already exists', 'registrars' => $registrars, @@ -159,7 +159,7 @@ class DomainsController extends Controller ); if ($domain_already_reserved) { - return view($response, 'admin/domains/create.twig', [ + return view($response, 'admin/domains/createDomain.twig', [ 'domainName' => $domainName, 'error' => 'Domain name is reserved or restricted', 'registrars' => $registrars, @@ -168,7 +168,7 @@ class DomainsController extends Controller } if ($registrationYears && (($registrationYears < 1) || ($registrationYears > 10))) { - return view($response, 'admin/domains/create.twig', [ + return view($response, 'admin/domains/createDomain.twig', [ 'domainName' => $domainName, 'error' => 'Domain period must be from 1 to 10', 'registrars' => $registrars, @@ -201,7 +201,7 @@ class DomainsController extends Controller ); if (!$price) { - return view($response, 'admin/domains/create.twig', [ + return view($response, 'admin/domains/createDomain.twig', [ 'domainName' => $domainName, 'error' => 'The price, period and currency for such TLD are not declared', 'registrars' => $registrars, @@ -210,7 +210,7 @@ class DomainsController extends Controller } if (($registrar_balance + $creditLimit) < $price) { - return view($response, 'admin/domains/create.twig', [ + return view($response, 'admin/domains/createDomain.twig', [ 'domainName' => $domainName, 'error' => 'Low credit: minimum threshold reached', 'registrars' => $registrars, @@ -219,7 +219,7 @@ class DomainsController extends Controller } if (count($nameservers) !== count(array_unique($nameservers))) { - return view($response, 'admin/domains/create.twig', [ + return view($response, 'admin/domains/createDomain.twig', [ 'domainName' => $domainName, 'error' => 'Duplicate nameservers detected. Please provide unique nameservers.', 'registrars' => $registrars, @@ -229,7 +229,7 @@ class DomainsController extends Controller foreach ($nameservers as $index => $nameserver) { if (preg_match("/^-|^\.-|-\.$|^\.$/", $nameserver)) { - return view($response, 'admin/domains/create.twig', [ + return view($response, 'admin/domains/createDomain.twig', [ 'domainName' => $domainName, 'error' => 'Invalid hostName', 'registrars' => $registrars, @@ -238,7 +238,7 @@ class DomainsController extends Controller } if (!preg_match('/^([A-Z0-9]([A-Z0-9-]{0,61}[A-Z0-9]){0,1}\.){1,125}[A-Z0-9]([A-Z0-9-]{0,61}[A-Z0-9])$/i', $nameserver) && strlen($nameserver) < 254) { - return view($response, 'admin/domains/create.twig', [ + return view($response, 'admin/domains/createDomain.twig', [ 'domainName' => $domainName, 'error' => 'Invalid hostName', 'registrars' => $registrars, @@ -252,7 +252,7 @@ class DomainsController extends Controller $row = $db->selectRow('SELECT id, clid FROM contact WHERE identifier = ?', [$contactRegistrant]); if (!$row) { - return view($response, 'admin/domains/create.twig', [ + return view($response, 'admin/domains/createDomain.twig', [ 'domainName' => $domainName, 'error' => 'Registrant does not exist', 'registrars' => $registrars, @@ -261,7 +261,7 @@ class DomainsController extends Controller } if ($clid != $row['clid']) { - return view($response, 'admin/domains/create.twig', [ + return view($response, 'admin/domains/createDomain.twig', [ 'domainName' => $domainName, 'error' => 'The contact requested in the command does NOT belong to the current registrar', 'registrars' => $registrars, @@ -275,7 +275,7 @@ class DomainsController extends Controller $row = $db->selectRow('SELECT id, clid FROM contact WHERE identifier = ?', [$contactAdmin]); if (!$row) { - return view($response, 'admin/domains/create.twig', [ + return view($response, 'admin/domains/createDomain.twig', [ 'domainName' => $domainName, 'error' => 'Admin contact does not exist', 'registrars' => $registrars, @@ -284,7 +284,7 @@ class DomainsController extends Controller } if ($clid != $row['clid']) { - return view($response, 'admin/domains/create.twig', [ + return view($response, 'admin/domains/createDomain.twig', [ 'domainName' => $domainName, 'error' => 'The contact requested in the command does NOT belong to the current registrar', 'registrars' => $registrars, @@ -298,7 +298,7 @@ class DomainsController extends Controller $row = $db->selectRow('SELECT id, clid FROM contact WHERE identifier = ?', [$contactTech]); if (!$row) { - return view($response, 'admin/domains/create.twig', [ + return view($response, 'admin/domains/createDomain.twig', [ 'domainName' => $domainName, 'error' => 'Tech contact does not exist', 'registrars' => $registrars, @@ -307,7 +307,7 @@ class DomainsController extends Controller } if ($clid != $row['clid']) { - return view($response, 'admin/domains/create.twig', [ + return view($response, 'admin/domains/createDomain.twig', [ 'domainName' => $domainName, 'error' => 'The contact requested in the command does NOT belong to the current registrar', 'registrars' => $registrars, @@ -321,7 +321,7 @@ class DomainsController extends Controller $row = $db->selectRow('SELECT id, clid FROM contact WHERE identifier = ?', [$contactBilling]); if (!$row) { - return view($response, 'admin/domains/create.twig', [ + return view($response, 'admin/domains/createDomain.twig', [ 'domainName' => $domainName, 'error' => 'Billing contact does not exist', 'registrars' => $registrars, @@ -330,7 +330,7 @@ class DomainsController extends Controller } if ($clid != $row['clid']) { - return view($response, 'admin/domains/create.twig', [ + return view($response, 'admin/domains/createDomain.twig', [ 'domainName' => $domainName, 'error' => 'The contact requested in the command does NOT belong to the current registrar', 'registrars' => $registrars, @@ -340,7 +340,7 @@ class DomainsController extends Controller } if (!$authInfo) { - return view($response, 'admin/domains/create.twig', [ + return view($response, 'admin/domains/createDomain.twig', [ 'domainName' => $domainName, 'error' => 'Missing domain authinfo', 'registrars' => $registrars, @@ -349,7 +349,7 @@ class DomainsController extends Controller } if (strlen($authInfo) < 6 || strlen($authInfo) > 16) { - return view($response, 'admin/domains/create.twig', [ + return view($response, 'admin/domains/createDomain.twig', [ 'domainName' => $domainName, 'error' => 'Password needs to be at least 6 and up to 16 characters long', 'registrars' => $registrars, @@ -358,7 +358,7 @@ class DomainsController extends Controller } if (!preg_match('/[A-Z]/', $authInfo)) { - return view($response, 'admin/domains/create.twig', [ + return view($response, 'admin/domains/createDomain.twig', [ 'domainName' => $domainName, 'error' => 'Password should have both upper and lower case characters', 'registrars' => $registrars, @@ -415,7 +415,7 @@ class DomainsController extends Controller // Validate keyTag if (!empty($dsKeyTag)) { if (!is_int($dsKeyTag)) { - return view($response, 'admin/domains/create.twig', [ + return view($response, 'admin/domains/createDomain.twig', [ 'domainName' => $domainName, 'error' => 'Incomplete key tag provided', 'registrars' => $registrars, @@ -424,7 +424,7 @@ class DomainsController extends Controller } if ($dsKeyTag < 0 || $dsKeyTag > 65535) { - return view($response, 'admin/domains/create.twig', [ + return view($response, 'admin/domains/createDomain.twig', [ 'domainName' => $domainName, 'error' => 'Incomplete key tag provided', 'registrars' => $registrars, @@ -436,7 +436,7 @@ class DomainsController extends Controller // Validate alg $validAlgorithms = [2, 3, 5, 6, 7, 8, 10, 13, 14, 15, 16]; if (!empty($dsAlg) && !in_array($dsAlg, $validAlgorithms)) { - return view($response, 'admin/domains/create.twig', [ + return view($response, 'admin/domains/createDomain.twig', [ 'domainName' => $domainName, 'error' => 'Incomplete algorithm provided', 'registrars' => $registrars, @@ -446,7 +446,7 @@ class DomainsController extends Controller // Validate digestType and digest if (!empty($dsDigestType) && !is_int($dsDigestType)) { - return view($response, 'admin/domains/create.twig', [ + return view($response, 'admin/domains/createDomain.twig', [ 'domainName' => $domainName, 'error' => 'Incomplete digest type provided', 'registrars' => $registrars, @@ -459,7 +459,7 @@ class DomainsController extends Controller 4 => 96 // SHA-384 ]; if (!empty($validDigests[$dsDigestType])) { - return view($response, 'admin/domains/create.twig', [ + return view($response, 'admin/domains/createDomain.twig', [ 'domainName' => $domainName, 'error' => 'Unsupported digest type', 'registrars' => $registrars, @@ -468,7 +468,7 @@ class DomainsController extends Controller } if (!empty($dsDigest)) { if (strlen($dsDigest) != $validDigests[$dsDigestType] || !ctype_xdigit($dsDigest)) { - return view($response, 'admin/domains/create.twig', [ + return view($response, 'admin/domains/createDomain.twig', [ 'domainName' => $domainName, 'error' => 'Invalid digest length or format', 'registrars' => $registrars, @@ -481,7 +481,7 @@ class DomainsController extends Controller // Validate flags $validFlags = [256, 257]; if (!empty($dnskeyFlags) && !in_array($dnskeyFlags, $validFlags)) { - return view($response, 'admin/domains/create.twig', [ + return view($response, 'admin/domains/createDomain.twig', [ 'domainName' => $domainName, 'error' => 'Invalid flags provided', 'registrars' => $registrars, @@ -491,7 +491,7 @@ class DomainsController extends Controller // Validate protocol if (!empty($dnskeyProtocol) && $dnskeyProtocol != 3) { - return view($response, 'admin/domains/create.twig', [ + return view($response, 'admin/domains/createDomain.twig', [ 'domainName' => $domainName, 'error' => 'Invalid protocol provided', 'registrars' => $registrars, @@ -501,7 +501,7 @@ class DomainsController extends Controller // Validate algKeyData if (!empty($dnskeyAlg)) { - return view($response, 'admin/domains/create.twig', [ + return view($response, 'admin/domains/createDomain.twig', [ 'domainName' => $domainName, 'error' => 'Invalid algorithm encoding', 'registrars' => $registrars, @@ -511,7 +511,7 @@ class DomainsController extends Controller // Validate pubKey if (!empty($dnskeyPubKey) && base64_encode(base64_decode($dnskeyPubKey, true)) !== $dnskeyPubKey) { - return view($response, 'admin/domains/create.twig', [ + return view($response, 'admin/domains/createDomain.twig', [ 'domainName' => $domainName, 'error' => 'Invalid public key encoding', 'registrars' => $registrars, @@ -702,7 +702,7 @@ class DomainsController extends Controller $db->commit(); } catch (Exception $e) { $db->rollBack(); - return view($response, 'admin/domains/create.twig', [ + return view($response, 'admin/domains/createDomain.twig', [ 'domainName' => $domainName, 'error' => 'Database failure: ' . $e->getMessage(), 'registrars' => $registrars, @@ -715,7 +715,7 @@ class DomainsController extends Controller [$domain_id] ); - return view($response, 'admin/domains/create.twig', [ + return view($response, 'admin/domains/createDomain.twig', [ 'domainName' => $domainName, 'crdate' => $crdate, 'registrars' => $registrars, @@ -744,7 +744,7 @@ class DomainsController extends Controller $position = (strpos($pattern, '¤') < strpos($pattern, '#')) ? 'before' : 'after'; // Default view for GET requests or if POST data is not set - return view($response,'admin/domains/create.twig', [ + return view($response,'admin/domains/createDomain.twig', [ 'registrars' => $registrars, 'currencySymbol' => $symbol, 'currencyPosition' => $position, @@ -752,11 +752,6 @@ class DomainsController extends Controller ]); } - public function transfers(Request $request, Response $response) - { - return view($response,'admin/domains/transfers.twig'); - } - public function viewDomain(Request $request, Response $response, $args) { $db = $this->container->get('db'); @@ -818,7 +813,7 @@ class DomainsController extends Controller 'currentUri' => $uri ]); } else { - // Contact does not exist, redirect to the domains view + // Domain does not exist, redirect to the domains view return $response->withHeader('Location', '/domains')->withStatus(302); } @@ -828,5 +823,483 @@ class DomainsController extends Controller } } + + public function updateDomain(Request $request, Response $response, $args) + { + $db = $this->container->get('db'); + $registrars = $db->select("SELECT id, clid, name FROM registrar"); + if ($_SESSION["auth_roles"] != 0) { + $registrar = true; + } else { + $registrar = null; + } + + $uri = $request->getUri()->getPath(); + + if ($args) { + $domain = $db->selectRow('SELECT id, name, registrant, crdate, exdate, `update`, clid, idnlang, rgpstatus FROM domain WHERE name = ?', + [ $args ]); + + if ($domain) { + $registrars = $db->selectRow('SELECT id, clid, name FROM registrar WHERE id = ?', [$domain['clid']]); + + // 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 domains view if the user is not authorized for this contact + return $response->withHeader('Location', '/domains')->withStatus(302); + } + } + + $domainRegistrant = $db->selectRow('SELECT identifier FROM contact WHERE id = ?', + [ $domain['registrant'] ]); + $domainStatus = $db->select('SELECT status FROM domain_status WHERE domain_id = ?', + [ $domain['id'] ]); + $domainAuth = $db->selectRow('SELECT authinfo FROM domain_authInfo WHERE domain_id = ?', + [ $domain['id'] ]); + $domainSecdns = $db->select('SELECT * FROM secdns WHERE domain_id = ?', + [ $domain['id'] ]); + $domainHostsQuery = ' + SELECT dhm.id, dhm.domain_id, dhm.host_id, h.name + FROM domain_host_map dhm + JOIN host h ON dhm.host_id = h.id + WHERE dhm.domain_id = ?'; + + $domainHosts = $db->select($domainHostsQuery, [$domain['id']]); + $domainContactsQuery = ' + SELECT dcm.id, dcm.domain_id, dcm.contact_id, dcm.type, c.identifier + FROM domain_contact_map dcm + JOIN contact c ON dcm.contact_id = c.id + WHERE dcm.domain_id = ?'; + $domainContacts = $db->select($domainContactsQuery, [$domain['id']]); + + return view($response,'admin/domains/updateDomain.twig', [ + 'domain' => $domain, + 'domainStatus' => $domainStatus, + 'domainAuth' => $domainAuth, + 'domainRegistrant' => $domainRegistrant, + 'domainSecdns' => $domainSecdns, + 'domainHosts' => $domainHosts, + 'domainContacts' => $domainContacts, + 'registrar' => $registrars, + 'currentUri' => $uri + ]); + } else { + // Domain does not exist, redirect to the domains view + return $response->withHeader('Location', '/domains')->withStatus(302); + } + + } else { + // Redirect to the domains view + return $response->withHeader('Location', '/domains')->withStatus(302); + } + } + + public function updateDomainProcess(Request $request, Response $response) + { + if ($request->getMethod() === 'POST') { + // Retrieve POST data + $data = $request->getParsedBody(); + $db = $this->container->get('db'); + $domainName = $data['domainName'] ?? 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 domain WHERE name = ?', [$domainName]); + } + + $contactRegistrant = $data['contactRegistrant'] ?? null; + $contactAdmin = $data['contactAdmin'] ?? null; + $contactTech = $data['contactTech'] ?? null; + $contactBilling = $data['contactBilling'] ?? null; + + $nameservers = $data['nameserver'] ?? []; + + $dsKeyTag = $data['dsKeyTag'] ?? null; + $dsAlg = $data['dsAlg'] ?? null; + $dsDigestType = $data['dsDigestType'] ?? null; + $dsDigest = $data['dsDigest'] ?? null; + + $dnskeyFlags = $data['dnskeyFlags'] ?? null; + $dnskeyProtocol = $data['dnskeyProtocol'] ?? null; + $dnskeyAlg = $data['dnskeyAlg'] ?? null; + $dnskeyPubKey = $data['dnskeyPubKey'] ?? null; + + $authInfo = $data['authInfo'] ?? null; + + foreach ($nameservers as $index => $nameserver) { + if (preg_match("/^-|^\.-|-\.$|^\.$/", $nameserver)) { + $this->container->get('flash')->addMessage('error', 'Invalid hostName'); + return $response->withHeader('Location', '/domain/update/'.$domainName)->withStatus(302); + } + + if (!preg_match('/^([A-Z0-9]([A-Z0-9-]{0,61}[A-Z0-9]){0,1}\.){1,125}[A-Z0-9]([A-Z0-9-]{0,61}[A-Z0-9])$/i', $nameserver) && strlen($nameserver) < 254) { + $this->container->get('flash')->addMessage('error', 'Invalid hostName'); + return $response->withHeader('Location', '/domain/update/'.$domainName)->withStatus(302); + } + } + + if ($contactRegistrant) { + $validRegistrant = validate_identifier($contactRegistrant); + $row = $db->selectRow('SELECT id, clid FROM contact WHERE identifier = ?', [$contactRegistrant]); + + if (!$row) { + $this->container->get('flash')->addMessage('error', 'Registrant does not exist'); + return $response->withHeader('Location', '/domain/update/'.$domainName)->withStatus(302); + } + + if ($clid != $row['clid']) { + $this->container->get('flash')->addMessage('error', 'The contact requested in the command does NOT belong to the current registrar'); + return $response->withHeader('Location', '/domain/update/'.$domainName)->withStatus(302); + } + } + + if ($contactAdmin) { + $validAdmin = validate_identifier($contactAdmin); + $row = $db->selectRow('SELECT id, clid FROM contact WHERE identifier = ?', [$contactAdmin]); + + if (!$row) { + $this->container->get('flash')->addMessage('error', 'Admin contact does not exist'); + return $response->withHeader('Location', '/domain/update/'.$domainName)->withStatus(302); + } + + if ($clid != $row['clid']) { + $this->container->get('flash')->addMessage('error', 'The contact requested in the command does NOT belong to the current registrar'); + return $response->withHeader('Location', '/domain/update/'.$domainName)->withStatus(302); + } + } + + if ($contactTech) { + $validTech = validate_identifier($contactTech); + $row = $db->selectRow('SELECT id, clid FROM contact WHERE identifier = ?', [$contactTech]); + + if (!$row) { + $this->container->get('flash')->addMessage('error', 'Tech contact does not exist'); + return $response->withHeader('Location', '/domain/update/'.$domainName)->withStatus(302); + } + + if ($clid != $row['clid']) { + $this->container->get('flash')->addMessage('error', 'The contact requested in the command does NOT belong to the current registrar'); + return $response->withHeader('Location', '/domain/update/'.$domainName)->withStatus(302); + } + } + + if ($contactBilling) { + $validBilling = validate_identifier($contactBilling); + $row = $db->selectRow('SELECT id, clid FROM contact WHERE identifier = ?', [$contactBilling]); + + if (!$row) { + $this->container->get('flash')->addMessage('error', 'Billing contact does not exist'); + return $response->withHeader('Location', '/domain/update/'.$domainName)->withStatus(302); + } + + if ($clid != $row['clid']) { + $this->container->get('flash')->addMessage('error', 'The contact requested in the command does NOT belong to the current registrar'); + return $response->withHeader('Location', '/domain/update/'.$domainName)->withStatus(302); + } + } + + if (!$authInfo) { + $this->container->get('flash')->addMessage('error', 'Domain ' . $domainName . ' can not be updated: Missing domain authinfo'); + return $response->withHeader('Location', '/domain/update/'.$domainName)->withStatus(302); + } + + if (strlen($authInfo) < 6 || strlen($authInfo) > 16) { + $this->container->get('flash')->addMessage('error', 'Password needs to be at least 6 and up to 16 characters long'); + return $response->withHeader('Location', '/domain/update/'.$domainName)->withStatus(302); + } + + if (!preg_match('/[A-Z]/', $authInfo)) { + $this->container->get('flash')->addMessage('error', 'Password should have both upper and lower case characters'); + return $response->withHeader('Location', '/domain/update/'.$domainName)->withStatus(302); + } + + $registrant_id = $db->selectValue( + 'SELECT id FROM contact WHERE identifier = ? LIMIT 1', + [$contactRegistrant] + ); + + try { + $db->beginTransaction(); + + $currentDateTime = new \DateTime(); + $update = $currentDateTime->format('Y-m-d H:i:s.v'); // Current timestamp + + $db->update('domain', [ + 'registrant' => $registrant_id, + 'update' => $update, + 'upid' => $clid + ], + [ + 'name' => $domainName + ] + ); + $domain_id = $db->selectValue( + 'SELECT id FROM domain WHERE name = ?', + [$domainName] + ); + + $db->update( + 'domain_authInfo', + [ + 'authinfo' => $authInfo + ], + [ + 'id' => $domain_id, + 'authtype' => 'pw' + ] + ); + + // Data sanity checks + // Validate keyTag + if (!empty($dsKeyTag)) { + if (!is_int($dsKeyTag)) { + $this->container->get('flash')->addMessage('error', 'Incomplete key tag provided'); + return $response->withHeader('Location', '/domain/update/'.$domainName)->withStatus(302); + } + + if ($dsKeyTag < 0 || $dsKeyTag > 65535) { + $this->container->get('flash')->addMessage('error', 'Incomplete key tag provided'); + return $response->withHeader('Location', '/domain/update/'.$domainName)->withStatus(302); + } + } + + // Validate alg + $validAlgorithms = [2, 3, 5, 6, 7, 8, 10, 13, 14, 15, 16]; + if (!empty($dsAlg) && !in_array($dsAlg, $validAlgorithms)) { + $this->container->get('flash')->addMessage('error', 'Incomplete algorithm provided'); + return $response->withHeader('Location', '/domain/update/'.$domainName)->withStatus(302); + } + + // Validate digestType and digest + if (!empty($dsDigestType) && !is_int($dsDigestType)) { + $this->container->get('flash')->addMessage('error', 'Incomplete digest type provided'); + return $response->withHeader('Location', '/domain/update/'.$domainName)->withStatus(302); + } + $validDigests = [ + 1 => 40, // SHA-1 + 2 => 64, // SHA-256 + 4 => 96 // SHA-384 + ]; + if (!empty($validDigests[$dsDigestType])) { + $this->container->get('flash')->addMessage('error', 'Unsupported digest type'); + return $response->withHeader('Location', '/domain/update/'.$domainName)->withStatus(302); + } + if (!empty($dsDigest)) { + if (strlen($dsDigest) != $validDigests[$dsDigestType] || !ctype_xdigit($dsDigest)) { + $this->container->get('flash')->addMessage('error', 'Invalid digest length or format'); + return $response->withHeader('Location', '/domain/update/'.$domainName)->withStatus(302); + } + } + + // Data sanity checks for keyData + // Validate flags + $validFlags = [256, 257]; + if (!empty($dnskeyFlags) && !in_array($dnskeyFlags, $validFlags)) { + $this->container->get('flash')->addMessage('error', 'Invalid flags provided'); + return $response->withHeader('Location', '/domain/update/'.$domainName)->withStatus(302); + } + + // Validate protocol + if (!empty($dnskeyProtocol) && $dnskeyProtocol != 3) { + $this->container->get('flash')->addMessage('error', 'Invalid protocol provided'); + return $response->withHeader('Location', '/domain/update/'.$domainName)->withStatus(302); + } + + // Validate algKeyData + if (!empty($dnskeyAlg)) { + $this->container->get('flash')->addMessage('error', 'Invalid algorithm encoding'); + return $response->withHeader('Location', '/domain/update/'.$domainName)->withStatus(302); + } + + // Validate pubKey + if (!empty($dnskeyPubKey) && base64_encode(base64_decode($dnskeyPubKey, true)) !== $dnskeyPubKey) { + $this->container->get('flash')->addMessage('error', 'Invalid public key encoding'); + return $response->withHeader('Location', '/domain/update/'.$domainName)->withStatus(302); + } + + if (!empty($dsKeyTag) || !empty($dnskeyFlags)) { + $db->insert('secdns', [ + 'domain_id' => $domain_id, + 'maxsiglife' => $maxSigLife, + 'interface' => 'dsData', + 'keytag' => $dsKeyTag, + 'alg' => $dsAlg, + 'digesttype' => $dsDigestType, + 'digest' => $dsDigest, + 'flags' => $dnskeyFlags ?? null, + 'protocol' => $dnskeyProtocol ?? null, + 'keydata_alg' => $dnskeyAlg ?? null, + 'pubkey' => $dnskeyPubKey ?? null + ]); + } + + foreach ($nameservers as $index => $nameserver) { + $hostName_already_exist = $db->selectValue( + 'SELECT id FROM host WHERE name = ? LIMIT 1', + [$nameserver] + ); + + if ($hostName_already_exist) { + $domain_host_map_id = $db->selectValue( + 'SELECT domain_id FROM domain_host_map WHERE domain_id = ? AND host_id = ? LIMIT 1', + [$domain_id, $hostName_already_exist] + ); + + if (!$domain_host_map_id) { + $db->insert( + 'domain_host_map', + [ + 'domain_id' => $domain_id, + 'host_id' => $hostName_already_exist + ] + ); + } else { + $currentDateTime = new \DateTime(); + $logdate = $currentDateTime->format('Y-m-d H:i:s.v'); + $db->insert( + 'error_log', + [ + 'registrar_id' => $clid, + 'log' => "Domain : $domainName ; hostName : $nameserver - is duplicated", + 'date' => $logdate + ] + ); + } + } else { + $currentDateTime = new \DateTime(); + $host_date = $currentDateTime->format('Y-m-d H:i:s.v'); + $host_id = $db->insert( + 'host', + [ + 'name' => $nameserver, + 'domain_id' => $domain_id, + 'clid' => $clid, + 'crid' => $clid, + 'crdate' => $host_date + ] + ); + + $db->insert( + 'domain_host_map', + [ + 'domain_id' => $domain_id, + 'host_id' => $host_id + ] + ); + + if (isset($nameserver_ipv4[$index]) && !empty($nameserver_ipv4[$index])) { + $ipv4 = normalize_v4_address($nameserver_ipv4[$index]); + + $db->insert( + 'host_addr', + [ + 'host_id' => $host_id, + 'addr' => $ipv4, + 'ip' => 'v4' + ] + ); + } + + if (isset($nameserver_ipv6[$index]) && !empty($nameserver_ipv6[$index])) { + $ipv6 = normalize_v6_address($nameserver_ipv6[$index]); + + $db->insert( + 'host_addr', + [ + 'host_id' => $host_id, + 'addr' => $ipv6, + 'ip' => 'v6' + ] + ); + } + + } + } + + $contacts = [ + 'admin' => $data['contactAdmin'] ?? null, + 'tech' => $data['contactTech'] ?? null, + 'billing' => $data['contactBilling'] ?? null + ]; + + foreach ($contacts as $type => $contact) { + if ($contact !== null) { + $contact_id = $db->selectValue( + 'SELECT id FROM contact WHERE identifier = ? LIMIT 1', + [$contact] + ); + + // Check if $contact_id is not null before update + if ($contact_id !== null) { + $db->update( + 'domain_contact_map', + [ + 'contact_id' => $contact_id, + ], + [ + 'domain_id' => $domain_id, + 'type' => $type + ] + ); + } + } + } + + $db->commit(); + } catch (Exception $e) { + $db->rollBack(); + $this->container->get('flash')->addMessage('error', 'Database failure during update: ' . $e->getMessage()); + return $response->withHeader('Location', '/domain/update/'.$domainName)->withStatus(302); + } + + $this->container->get('flash')->addMessage('success', 'Domain ' . $domainName . ' has been updated successfully on ' . $update); + return $response->withHeader('Location', '/domain/update/'.$domainName)->withStatus(302); + } + } + + public function renewDomain(Request $request, Response $response) + { + return view($response,'admin/domains/renewDomain.twig'); + } + + public function deleteDomain(Request $request, Response $response) + { + return view($response,'admin/domains/deleteDomain.twig'); + } + + public function listTransfers(Request $request, Response $response) + { + return view($response,'admin/domains/listTransfers.twig'); + } + + public function requestTransfer(Request $request, Response $response) + { + return view($response,'admin/domains/requestTransfer.twig'); + } + + public function approveTransfer(Request $request, Response $response) + { + return view($response,'admin/domains/approveTransfer.twig'); + } + + public function rejectTransfer(Request $request, Response $response) + { + return view($response,'admin/domains/rejectTransfer.twig'); + } + + public function cancelTransfer(Request $request, Response $response) + { + return view($response,'admin/domains/cancelTransfer.twig'); + } } \ No newline at end of file diff --git a/cp/resources/views/admin/dashboard/index.twig b/cp/resources/views/admin/dashboard/index.twig index 51cf27a..8f2ae3f 100644 --- a/cp/resources/views/admin/dashboard/index.twig +++ b/cp/resources/views/admin/dashboard/index.twig @@ -25,11 +25,11 @@ {{ __('View Reports') }} - + {{ __('Create new domain') }} - + @@ -45,7 +45,7 @@