Big improvement in CP flows

This commit is contained in:
Pinga 2024-01-09 11:47:18 +02:00
parent 7c2e6d4388
commit f3fa1f1855
15 changed files with 244 additions and 961 deletions

View file

@ -148,13 +148,8 @@ class DomainsController extends Controller
$invalid_domain = validate_label($domainName, $db);
if ($invalid_domain) {
return view($response, 'admin/domains/createDomain.twig', [
'domainName' => $domainName,
'error' => 'Invalid domain name',
'registrars' => $registrars,
'registrar' => $registrar,
'launch_phases' => $launch_phases
]);
$this->container->get('flash')->addMessage('error', 'Error creating domain: Invalid domain name');
return $response->withHeader('Location', '/domain/create')->withStatus(302);
}
$valid_tld = false;
@ -169,13 +164,8 @@ class DomainsController extends Controller
}
if (!$valid_tld) {
return view($response, 'admin/domains/createDomain.twig', [
'domainName' => $domainName,
'error' => 'Invalid domain extension',
'registrars' => $registrars,
'registrar' => $registrar,
'launch_phases' => $launch_phases
]);
$this->container->get('flash')->addMessage('error', 'Error creating domain: Invalid domain extension');
return $response->withHeader('Location', '/domain/create')->withStatus(302);
}
$domain_already_exist = $db->selectValue(
@ -184,13 +174,8 @@ class DomainsController extends Controller
);
if ($domain_already_exist) {
return view($response, 'admin/domains/createDomain.twig', [
'domainName' => $domainName,
'error' => 'Domain name already exists',
'registrars' => $registrars,
'registrar' => $registrar,
'launch_phases' => $launch_phases
]);
$this->container->get('flash')->addMessage('error', 'Error creating domain: Domain name already exists');
return $response->withHeader('Location', '/domain/create')->withStatus(302);
}
$currentDateTime = new \DateTime();
@ -210,40 +195,20 @@ class DomainsController extends Controller
if ($phase_details !== 'First-Come-First-Serve') {
if ($phaseType !== 'none') {
if ($phaseType == null && $phaseType == '') {
return view($response, 'admin/domains/createDomain.twig', [
'domainName' => $domainName,
'error' => 'The launch phase ' . $phaseType . ' is improperly configured. Please check the settings or contact support.',
'registrars' => $registrars,
'registrar' => $registrar,
'launch_phases' => $launch_phases
]);
$this->container->get('flash')->addMessage('error', 'Error creating domain: The launch phase ' . $phaseType . ' is improperly configured. Please check the settings or contact support.');
return $response->withHeader('Location', '/domain/create')->withStatus(302);
} else if ($phase_details == null) {
return view($response, 'admin/domains/createDomain.twig', [
'domainName' => $domainName,
'error' => 'The launch phase ' . $phaseType . ' is currently not active.',
'registrars' => $registrars,
'registrar' => $registrar,
'launch_phases' => $launch_phases
]);
$this->container->get('flash')->addMessage('error', 'Error creating domain: The launch phase ' . $phaseType . ' is currently not active.');
return $response->withHeader('Location', '/domain/create')->withStatus(302);
}
}
} else if ($phaseType !== 'none') {
if ($phaseType == null && $phaseType == '') {
return view($response, 'admin/domains/createDomain.twig', [
'domainName' => $domainName,
'error' => 'The launch phase ' . $phaseType . ' is improperly configured. Please check the settings or contact support.',
'registrars' => $registrars,
'registrar' => $registrar,
'launch_phases' => $launch_phases
]);
$this->container->get('flash')->addMessage('error', 'Error creating domain: The launch phase ' . $phaseType . ' is improperly configured. Please check the settings or contact support.');
return $response->withHeader('Location', '/domain/create')->withStatus(302);
} else if ($phase_details == null) {
return view($response, 'admin/domains/createDomain.twig', [
'domainName' => $domainName,
'error' => 'The launch phase ' . $phaseType . ' is currently not active.',
'registrars' => $registrars,
'registrar' => $registrar,
'launch_phases' => $launch_phases
]);
$this->container->get('flash')->addMessage('error', 'Error creating domain: The launch phase ' . $phaseType . ' is currently not active.');
return $response->withHeader('Location', '/domain/create')->withStatus(302);
}
}
@ -251,14 +216,8 @@ class DomainsController extends Controller
if (!isset($data['noticeid']) || $data['noticeid'] === '' ||
!isset($data['notafter']) || $data['notafter'] === '' ||
!isset($data['accepted']) || $data['accepted'] === '') {
// Trigger an error
return view($response, 'admin/domains/createDomain.twig', [
'domainName' => $domainName,
'error' => "Error: 'noticeid', 'notafter', or 'accepted' cannot be empty when phaseType is 'claims'",
'registrars' => $registrars,
'registrar' => $registrar,
'launch_phases' => $launch_phases
]);
$this->container->get('flash')->addMessage('error', "Error creating domain: 'noticeid', 'notafter', or 'accepted' cannot be empty when phaseType is 'claims'");
return $response->withHeader('Location', '/domain/create')->withStatus(302);
}
$noticeid = $data['noticeid'];
@ -302,26 +261,15 @@ class DomainsController extends Controller
}
if (!in_array($label, $labels)) {
return view($response, 'admin/domains/createDomain.twig', [
'domainName' => $domainName,
'error' => "SMD file is not valid for the domain name being registered.",
'registrars' => $registrars,
'registrar' => $registrar,
'launch_phases' => $launch_phases
]);
$this->container->get('flash')->addMessage('error', 'Error creating domain: SMD file is not valid for the domain name being registered.');
return $response->withHeader('Location', '/domain/create')->withStatus(302);
}
// Check if current date and time is between notBefore and notAfter
$now = new \DateTime();
if (!($now >= $notBefore && $now <= $notAfter)) {
// Current time is outside the valid range, return an error view
return view($response, 'admin/domains/createDomain.twig', [
'domainName' => $domainName,
'error' => "Current time is outside the valid range.",
'registrars' => $registrars,
'registrar' => $registrar,
'launch_phases' => $launch_phases
]);
$this->container->get('flash')->addMessage('error', 'Error creating domain: Current time is outside the valid range in the SMD.');
return $response->withHeader('Location', '/domain/create')->withStatus(302);
}
// Verify the signature
@ -332,22 +280,12 @@ class DomainsController extends Controller
$isValid = $xmlSignatureVerifier->verifyXml($xmlContent);
if (!$isValid) {
return view($response, 'admin/domains/createDomain.twig', [
'domainName' => $domainName,
'error' => "The XML signature of the SMD file is not valid.",
'registrars' => $registrars,
'registrar' => $registrar,
'launch_phases' => $launch_phases
]);
$this->container->get('flash')->addMessage('error', 'Error creating domain: The XML signature of the SMD file is not valid.');
return $response->withHeader('Location', '/domain/create')->withStatus(302);
}
} else {
return view($response, 'admin/domains/createDomain.twig', [
'domainName' => $domainName,
'error' => "SMD upload is required in the 'sunrise' phase.",
'registrars' => $registrars,
'registrar' => $registrar,
'launch_phases' => $launch_phases
]);
$this->container->get('flash')->addMessage('error', "Error creating domain: SMD upload is required in the 'sunrise' phase.");
return $response->withHeader('Location', '/domain/create')->withStatus(302);
}
}
@ -364,25 +302,15 @@ class DomainsController extends Controller
$this->container->get('flash')->addMessage('error', 'Domain ' . $domainName . ' is not available: Allocation Token mismatch');
return $response->withHeader('Location', '/domain/create')->withStatus(302);
}
} else {
return view($response, 'admin/domains/createDomain.twig', [
'domainName' => $domainName,
'error' => 'Domain name is reserved or restricted',
'registrars' => $registrars,
'registrar' => $registrar,
'launch_phases' => $launch_phases
]);
} else {
$this->container->get('flash')->addMessage('error', 'Error creating domain: Domain name is reserved or restricted');
return $response->withHeader('Location', '/domain/create')->withStatus(302);
}
}
if ($registrationYears && (($registrationYears < 1) || ($registrationYears > 10))) {
return view($response, 'admin/domains/createDomain.twig', [
'domainName' => $domainName,
'error' => 'Domain period must be from 1 to 10',
'registrars' => $registrars,
'registrar' => $registrar,
'launch_phases' => $launch_phases
]);
$this->container->get('flash')->addMessage('error', 'Error creating domain: Domain period must be from 1 to 10');
return $response->withHeader('Location', '/domain/create')->withStatus(302);
} elseif (!$registrationYears) {
$registrationYears = 1;
}
@ -407,23 +335,13 @@ class DomainsController extends Controller
$price = $returnValue['price'];
if (!$price) {
return view($response, 'admin/domains/createDomain.twig', [
'domainName' => $domainName,
'error' => 'The price, period and currency for such TLD are not declared',
'registrars' => $registrars,
'registrar' => $registrar,
'launch_phases' => $launch_phases
]);
$this->container->get('flash')->addMessage('error', 'Error creating domain: The price, period and currency for such TLD are not declared');
return $response->withHeader('Location', '/domain/create')->withStatus(302);
}
if (($registrar_balance + $creditLimit) < $price) {
return view($response, 'admin/domains/createDomain.twig', [
'domainName' => $domainName,
'error' => 'Low credit: minimum threshold reached',
'registrars' => $registrars,
'registrar' => $registrar,
'launch_phases' => $launch_phases
]);
$this->container->get('flash')->addMessage('error', 'Error creating domain: Low credit: minimum threshold reached');
return $response->withHeader('Location', '/domain/create')->withStatus(302);
}
$nameservers = array_filter($data['nameserver'] ?? [], function($value) {
@ -438,34 +356,19 @@ class DomainsController extends Controller
if (!empty($nameservers)) {
if (count($nameservers) !== count(array_unique($nameservers))) {
return view($response, 'admin/domains/createDomain.twig', [
'domainName' => $domainName,
'error' => 'Duplicate nameservers detected. Please provide unique nameservers.',
'registrars' => $registrars,
'registrar' => $registrar,
'launch_phases' => $launch_phases
]);
$this->container->get('flash')->addMessage('error', 'Error creating domain: Duplicate nameservers detected. Please provide unique nameservers.');
return $response->withHeader('Location', '/domain/create')->withStatus(302);
}
foreach ($nameservers as $index => $nameserver) {
if (preg_match("/^-|^\.-|-\.$|^\.$/", $nameserver)) {
return view($response, 'admin/domains/createDomain.twig', [
'domainName' => $domainName,
'error' => 'Invalid hostName',
'registrars' => $registrars,
'registrar' => $registrar,
'launch_phases' => $launch_phases
]);
$this->container->get('flash')->addMessage('error', 'Error creating domain: Invalid hostName');
return $response->withHeader('Location', '/domain/create')->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) {
return view($response, 'admin/domains/createDomain.twig', [
'domainName' => $domainName,
'error' => 'Invalid hostName',
'registrars' => $registrars,
'registrar' => $registrar,
'launch_phases' => $launch_phases
]);
$this->container->get('flash')->addMessage('error', 'Error creating domain: Invalid hostName');
return $response->withHeader('Location', '/domain/create')->withStatus(302);
}
}
}
@ -475,23 +378,13 @@ class DomainsController extends Controller
$row = $db->selectRow('SELECT id, clid FROM contact WHERE identifier = ?', [$contactRegistrant]);
if (!$row) {
return view($response, 'admin/domains/createDomain.twig', [
'domainName' => $domainName,
'error' => 'Registrant does not exist',
'registrars' => $registrars,
'registrar' => $registrar,
'launch_phases' => $launch_phases
]);
$this->container->get('flash')->addMessage('error', 'Error creating domain: Registrant does not exist');
return $response->withHeader('Location', '/domain/create')->withStatus(302);
}
if ($clid != $row['clid']) {
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,
'registrar' => $registrar,
'launch_phases' => $launch_phases
]);
$this->container->get('flash')->addMessage('error', 'Error creating domain: The contact requested in the command does NOT belong to the current registrar');
return $response->withHeader('Location', '/domain/create')->withStatus(302);
}
}
@ -500,23 +393,13 @@ class DomainsController extends Controller
$row = $db->selectRow('SELECT id, clid FROM contact WHERE identifier = ?', [$contactAdmin]);
if (!$row) {
return view($response, 'admin/domains/createDomain.twig', [
'domainName' => $domainName,
'error' => 'Admin contact does not exist',
'registrars' => $registrars,
'registrar' => $registrar,
'launch_phases' => $launch_phases
]);
$this->container->get('flash')->addMessage('error', 'Error creating domain: Admin contact does not exist');
return $response->withHeader('Location', '/domain/create')->withStatus(302);
}
if ($clid != $row['clid']) {
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,
'registrar' => $registrar,
'launch_phases' => $launch_phases
]);
$this->container->get('flash')->addMessage('error', 'Error creating domain: The contact requested in the command does NOT belong to the current registrar');
return $response->withHeader('Location', '/domain/create')->withStatus(302);
}
}
@ -525,23 +408,13 @@ class DomainsController extends Controller
$row = $db->selectRow('SELECT id, clid FROM contact WHERE identifier = ?', [$contactTech]);
if (!$row) {
return view($response, 'admin/domains/createDomain.twig', [
'domainName' => $domainName,
'error' => 'Tech contact does not exist',
'registrars' => $registrars,
'registrar' => $registrar,
'launch_phases' => $launch_phases
]);
$this->container->get('flash')->addMessage('error', 'Error creating domain: Tech contact does not exist');
return $response->withHeader('Location', '/domain/create')->withStatus(302);
}
if ($clid != $row['clid']) {
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,
'registrar' => $registrar,
'launch_phases' => $launch_phases
]);
$this->container->get('flash')->addMessage('error', 'Error creating domain: The contact requested in the command does NOT belong to the current registrar');
return $response->withHeader('Location', '/domain/create')->withStatus(302);
}
}
@ -550,54 +423,29 @@ class DomainsController extends Controller
$row = $db->selectRow('SELECT id, clid FROM contact WHERE identifier = ?', [$contactBilling]);
if (!$row) {
return view($response, 'admin/domains/createDomain.twig', [
'domainName' => $domainName,
'error' => 'Billing contact does not exist',
'registrars' => $registrars,
'registrar' => $registrar,
'launch_phases' => $launch_phases
]);
$this->container->get('flash')->addMessage('error', 'Error creating domain: Billing contact does not exist');
return $response->withHeader('Location', '/domain/create')->withStatus(302);
}
if ($clid != $row['clid']) {
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,
'registrar' => $registrar,
'launch_phases' => $launch_phases
]);
$this->container->get('flash')->addMessage('error', 'Error creating domain: The contact requested in the command does NOT belong to the current registrar');
return $response->withHeader('Location', '/domain/create')->withStatus(302);
}
}
if (!$authInfo) {
return view($response, 'admin/domains/createDomain.twig', [
'domainName' => $domainName,
'error' => 'Missing domain authinfo',
'registrars' => $registrars,
'registrar' => $registrar,
'launch_phases' => $launch_phases
]);
$this->container->get('flash')->addMessage('error', 'Error creating domain: Missing domain authinfo');
return $response->withHeader('Location', '/domain/create')->withStatus(302);
}
if (strlen($authInfo) < 6 || strlen($authInfo) > 16) {
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,
'registrar' => $registrar,
'launch_phases' => $launch_phases
]);
$this->container->get('flash')->addMessage('error', 'Error creating domain: Password needs to be at least 6 and up to 16 characters long');
return $response->withHeader('Location', '/domain/create')->withStatus(302);
}
if (!preg_match('/[A-Z]/', $authInfo)) {
return view($response, 'admin/domains/createDomain.twig', [
'domainName' => $domainName,
'error' => 'Password should have both upper and lower case characters',
'registrars' => $registrars,
'registrar' => $registrar,
'launch_phases' => $launch_phases
]);
$this->container->get('flash')->addMessage('error', 'Error creating domain: Password should have both upper and lower case characters');
return $response->withHeader('Location', '/domain/create')->withStatus(302);
}
$registrant_id = $db->selectValue(
@ -701,47 +549,27 @@ class DomainsController extends Controller
// Validate keyTag
if (!empty($dsKeyTag)) {
if (!is_int($dsKeyTag)) {
return view($response, 'admin/domains/createDomain.twig', [
'domainName' => $domainName,
'error' => 'Incomplete key tag provided',
'registrars' => $registrars,
'registrar' => $registrar,
'launch_phases' => $launch_phases
]);
$this->container->get('flash')->addMessage('error', 'Error creating domain: Incomplete key tag provided');
return $response->withHeader('Location', '/domain/create')->withStatus(302);
}
if ($dsKeyTag < 0 || $dsKeyTag > 65535) {
return view($response, 'admin/domains/createDomain.twig', [
'domainName' => $domainName,
'error' => 'Incomplete key tag provided',
'registrars' => $registrars,
'registrar' => $registrar,
'launch_phases' => $launch_phases
]);
$this->container->get('flash')->addMessage('error', 'Error creating domain: Incomplete key tag provided');
return $response->withHeader('Location', '/domain/create')->withStatus(302);
}
}
// Validate alg
$validAlgorithms = [8, 13, 14, 15, 16];
if (!empty($dsAlg) && !in_array($dsAlg, $validAlgorithms)) {
return view($response, 'admin/domains/createDomain.twig', [
'domainName' => $domainName,
'error' => 'Incomplete algorithm provided',
'registrars' => $registrars,
'registrar' => $registrar,
'launch_phases' => $launch_phases
]);
$this->container->get('flash')->addMessage('error', 'Error creating domain: Incomplete algorithm provided');
return $response->withHeader('Location', '/domain/create')->withStatus(302);
}
// Validate digestType and digest
if (!empty($dsDigestType) && !is_int($dsDigestType)) {
return view($response, 'admin/domains/createDomain.twig', [
'domainName' => $domainName,
'error' => 'Incomplete digest type provided',
'registrars' => $registrars,
'registrar' => $registrar,
'launch_phases' => $launch_phases
]);
$this->container->get('flash')->addMessage('error', 'Error creating domain: Incomplete digest type provided');
return $response->withHeader('Location', '/domain/create')->withStatus(302);
}
$validDigests = [
2 => 64, // SHA-256
@ -749,13 +577,8 @@ class DomainsController extends Controller
];
if (!empty($dsDigest)) {
if (strlen($dsDigest) != $validDigests[$dsDigestType] || !ctype_xdigit($dsDigest)) {
return view($response, 'admin/domains/createDomain.twig', [
'domainName' => $domainName,
'error' => 'Invalid digest length or format',
'registrars' => $registrars,
'registrar' => $registrar,
'launch_phases' => $launch_phases
]);
$this->container->get('flash')->addMessage('error', 'Error creating domain: Invalid digest length or format');
return $response->withHeader('Location', '/domain/create')->withStatus(302);
}
}
@ -763,46 +586,26 @@ class DomainsController extends Controller
// Validate flags
$validFlags = [256, 257];
if (!empty($dnskeyFlags) && !in_array($dnskeyFlags, $validFlags)) {
return view($response, 'admin/domains/createDomain.twig', [
'domainName' => $domainName,
'error' => 'Invalid flags provided',
'registrars' => $registrars,
'registrar' => $registrar,
'launch_phases' => $launch_phases
]);
$this->container->get('flash')->addMessage('error', 'Error creating domain: Invalid flags provided');
return $response->withHeader('Location', '/domain/create')->withStatus(302);
}
// Validate protocol
if (!empty($dnskeyProtocol) && $dnskeyProtocol != 3) {
return view($response, 'admin/domains/createDomain.twig', [
'domainName' => $domainName,
'error' => 'Invalid protocol provided',
'registrars' => $registrars,
'registrar' => $registrar,
'launch_phases' => $launch_phases
]);
$this->container->get('flash')->addMessage('error', 'Error creating domain: Invalid protocol provided');
return $response->withHeader('Location', '/domain/create')->withStatus(302);
}
// Validate algKeyData
if (!empty($dnskeyAlg)) {
return view($response, 'admin/domains/createDomain.twig', [
'domainName' => $domainName,
'error' => 'Invalid algorithm encoding',
'registrars' => $registrars,
'registrar' => $registrar,
'launch_phases' => $launch_phases
]);
$this->container->get('flash')->addMessage('error', 'Error creating domain: Invalid algorithm encoding');
return $response->withHeader('Location', '/domain/create')->withStatus(302);
}
// Validate pubKey
if (!empty($dnskeyPubKey) && base64_encode(base64_decode($dnskeyPubKey, true)) !== $dnskeyPubKey) {
return view($response, 'admin/domains/createDomain.twig', [
'domainName' => $domainName,
'error' => 'Invalid public key encoding',
'registrars' => $registrars,
'registrar' => $registrar,
'launch_phases' => $launch_phases
]);
$this->container->get('flash')->addMessage('error', 'Error creating domain: Invalid public key encoding');
return $response->withHeader('Location', '/domain/create')->withStatus(302);
}
if (!empty($dsKeyTag)) {
@ -958,13 +761,8 @@ class DomainsController extends Controller
if ($internal_host) {
if (empty($nameserver_ipv4[$index]) && empty($nameserver_ipv6[$index])) {
return view($response, 'admin/domains/createDomain.twig', [
'domainName' => $domainName,
'error' => 'Error: No IPv4 or IPv6 addresses provided for internal host',
'registrars' => $registrars,
'registrar' => $registrar,
'launch_phases' => $launch_phases
]);
$this->container->get('flash')->addMessage('error', 'Error creating domain: No IPv4 or IPv6 addresses provided for internal host');
return $response->withHeader('Location', '/domain/create')->withStatus(302);
}
if (isset($nameserver_ipv4[$index]) && !empty($nameserver_ipv4[$index])) {
@ -1049,22 +847,12 @@ class DomainsController extends Controller
$db->commit();
} catch (Exception $e) {
$db->rollBack();
return view($response, 'admin/domains/createDomain.twig', [
'domainName' => $domainName,
'error' => 'Database failure: ' . $e->getMessage(),
'registrars' => $registrars,
'registrar' => $registrar,
'launch_phases' => $launch_phases
]);
$this->container->get('flash')->addMessage('error', 'Database failure: ' . $e->getMessage());
return $response->withHeader('Location', '/domain/create')->withStatus(302);
} catch (\Pinga\Db\Throwable\IntegrityConstraintViolationException $e) {
$db->rollBack();
return view($response, 'admin/domains/createDomain.twig', [
'domainName' => $domainName,
'error' => 'Database failure: ' . $e->getMessage(),
'registrars' => $registrars,
'registrar' => $registrar,
'launch_phases' => $launch_phases
]);
$this->container->get('flash')->addMessage('error', 'Database failure: ' . $e->getMessage());
return $response->withHeader('Location', '/domain/create')->withStatus(302);
}
$crdate = $db->selectValue(