mirror of
https://github.com/getnamingo/registry.git
synced 2025-07-26 04:18:29 +02:00
Added domain check page
This commit is contained in:
parent
512de0552a
commit
6855dbaccd
9 changed files with 248 additions and 22 deletions
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\Domain;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
@ -11,9 +11,48 @@ class DomainsController extends Controller
|
|||
{
|
||||
public function view(Request $request, Response $response)
|
||||
{
|
||||
$userModel = new User($this->container->get('db'));
|
||||
$users = $userModel->getAllUsers();
|
||||
return view($response,'admin/domains/index.twig', compact('users'));
|
||||
return view($response,'admin/domains/view.twig');
|
||||
}
|
||||
|
||||
public function check(Request $request, Response $response)
|
||||
{
|
||||
if ($request->getMethod() === 'POST') {
|
||||
// Retrieve POST data
|
||||
$data = $request->getParsedBody();
|
||||
$domainName = $data['domain_name'] ?? null;
|
||||
|
||||
if ($domainName) {
|
||||
$domainModel = new Domain($this->container->get('db'));
|
||||
$availability = $domainModel->getDomainByName($domainName);
|
||||
|
||||
// Convert the DB result into a boolean '0' or '1'
|
||||
$availability = $availability ? '0' : '1';
|
||||
|
||||
$invalid_label = validate_label($domainName, $this->container->get('db'));
|
||||
|
||||
// Check if the domain is Invalid
|
||||
if ($invalid_label) {
|
||||
$status = $invalid_label;
|
||||
$isAvailable = 0;
|
||||
} else {
|
||||
$isAvailable = $availability;
|
||||
$status = null;
|
||||
|
||||
// Check if the domain is unavailable
|
||||
if ($availability === '0') {
|
||||
$status = 'In use';
|
||||
}
|
||||
}
|
||||
|
||||
return view($response, 'admin/domains/check.twig', [
|
||||
'isAvailable' => $isAvailable,
|
||||
'domainName' => $domainName,
|
||||
'status' => $status,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// Default view for GET requests or if POST data is not set
|
||||
return view($response,'admin/domains/check.twig');
|
||||
}
|
||||
}
|
|
@ -23,22 +23,17 @@ class Domain
|
|||
return $this->db->select('SELECT * FROM domain WHERE id = ?', [$id])->fetch();
|
||||
}
|
||||
|
||||
public function createDomain($id, $name, $tldid, $registrant, $crdate, $exdate, $update, $clid, $crid, $upid, $trdate, $trstatus, $reid, $redate, $acid, $acdate, $transfer_exdate, $idnlang, $delTime, $resTime, $rgpstatus, $rgppostData, $rgpdelTime, $rgpresTime, $rgpresReason, $rgpstatement1, $rgpstatement2, $rgpother, $addPeriod, $autoRenewPeriod, $renewPeriod, $transferPeriod, $renewedDate)
|
||||
public function getDomainByName($name)
|
||||
{
|
||||
$id = $this->db->quote($id), $name = $this->db->quote($name), $tldid = $this->db->quote($tldid), $registrant = $this->db->quote($registrant), $crdate = $this->db->quote($crdate), $exdate = $this->db->quote($exdate), $update = $this->db->quote($update), $clid = $this->db->quote($clid), $crid = $this->db->quote($crid), $upid = $this->db->quote($upid), $trdate = $this->db->quote($trdate), $trstatus = $this->db->quote($trstatus), $reid = $this->db->quote($reid), $redate = $this->db->quote($redate), $acid = $this->db->quote($acid), $acdate = $this->db->quote($acdate), $transfer_exdate = $this->db->quote($transfer_exdate), $idnlang = $this->db->quote($idnlang), $delTime = $this->db->quote($delTime), $resTime = $this->db->quote($resTime), $rgpstatus = $this->db->quote($rgpstatus), $rgppostData = $this->db->quote($rgppostData), $rgpdelTime = $this->db->quote($rgpdelTime), $rgpresTime = $this->db->quote($rgpresTime), $rgpresReason = $this->db->quote($rgpresReason), $rgpstatement1 = $this->db->quote($rgpstatement1), $rgpstatement2 = $this->db->quote($rgpstatement2), $rgpother = $this->db->quote($rgpother), $addPeriod = $this->db->quote($addPeriod), $autoRenewPeriod = $this->db->quote($autoRenewPeriod), $renewPeriod = $this->db->quote($renewPeriod), $transferPeriod = $this->db->quote($transferPeriod), $renewedDate = $this->db->quote($renewedDate)
|
||||
$result = $this->db->select('SELECT name FROM domain WHERE name = ?', [$name]);
|
||||
|
||||
$this->db->insert('INSERT INTO domain (id, name, tldid, registrant, crdate, exdate, update, clid, crid, upid, trdate, trstatus, reid, redate, acid, acdate, transfer_exdate, idnlang, delTime, resTime, rgpstatus, rgppostData, rgpdelTime, rgpresTime, rgpresReason, rgpstatement1, rgpstatement2, rgpother, addPeriod, autoRenewPeriod, renewPeriod, transferPeriod, renewedDate) VALUES ($id, $name, $tldid, $registrant, $crdate, $exdate, $update, $clid, $crid, $upid, $trdate, $trstatus, $reid, $redate, $acid, $acdate, $transfer_exdate, $idnlang, $delTime, $resTime, $rgpstatus, $rgppostData, $rgpdelTime, $rgpresTime, $rgpresReason, $rgpstatement1, $rgpstatement2, $rgpother, $addPeriod, $autoRenewPeriod, $renewPeriod, $transferPeriod, $renewedDate)');
|
||||
|
||||
return $this->db->lastInsertId();
|
||||
if (is_array($result)) {
|
||||
return $result;
|
||||
} else if (is_object($result) && method_exists($result, 'fetch')) {
|
||||
return $result->fetch();
|
||||
}
|
||||
|
||||
public function updateDomain($id, $id, $name, $tldid, $registrant, $crdate, $exdate, $update, $clid, $crid, $upid, $trdate, $trstatus, $reid, $redate, $acid, $acdate, $transfer_exdate, $idnlang, $delTime, $resTime, $rgpstatus, $rgppostData, $rgpdelTime, $rgpresTime, $rgpresReason, $rgpstatement1, $rgpstatement2, $rgpother, $addPeriod, $autoRenewPeriod, $renewPeriod, $transferPeriod, $renewedDate)
|
||||
{
|
||||
$id = $this->db->quote($id), $name = $this->db->quote($name), $tldid = $this->db->quote($tldid), $registrant = $this->db->quote($registrant), $crdate = $this->db->quote($crdate), $exdate = $this->db->quote($exdate), $update = $this->db->quote($update), $clid = $this->db->quote($clid), $crid = $this->db->quote($crid), $upid = $this->db->quote($upid), $trdate = $this->db->quote($trdate), $trstatus = $this->db->quote($trstatus), $reid = $this->db->quote($reid), $redate = $this->db->quote($redate), $acid = $this->db->quote($acid), $acdate = $this->db->quote($acdate), $transfer_exdate = $this->db->quote($transfer_exdate), $idnlang = $this->db->quote($idnlang), $delTime = $this->db->quote($delTime), $resTime = $this->db->quote($resTime), $rgpstatus = $this->db->quote($rgpstatus), $rgppostData = $this->db->quote($rgppostData), $rgpdelTime = $this->db->quote($rgpdelTime), $rgpresTime = $this->db->quote($rgpresTime), $rgpresReason = $this->db->quote($rgpresReason), $rgpstatement1 = $this->db->quote($rgpstatement1), $rgpstatement2 = $this->db->quote($rgpstatement2), $rgpother = $this->db->quote($rgpother), $addPeriod = $this->db->quote($addPeriod), $autoRenewPeriod = $this->db->quote($autoRenewPeriod), $renewPeriod = $this->db->quote($renewPeriod), $transferPeriod = $this->db->quote($transferPeriod), $renewedDate = $this->db->quote($renewedDate)
|
||||
|
||||
$this->db->update('UPDATE domain SET id = $id, name = $name, tldid = $tldid, registrant = $registrant, crdate = $crdate, exdate = $exdate, update = $update, clid = $clid, crid = $crid, upid = $upid, trdate = $trdate, trstatus = $trstatus, reid = $reid, redate = $redate, acid = $acid, acdate = $acdate, transfer_exdate = $transfer_exdate, idnlang = $idnlang, delTime = $delTime, resTime = $resTime, rgpstatus = $rgpstatus, rgppostData = $rgppostData, rgpdelTime = $rgpdelTime, rgpresTime = $rgpresTime, rgpresReason = $rgpresReason, rgpstatement1 = $rgpstatement1, rgpstatement2 = $rgpstatement2, rgpother = $rgpother, addPeriod = $addPeriod, autoRenewPeriod = $autoRenewPeriod, renewPeriod = $renewPeriod, transferPeriod = $transferPeriod, renewedDate = $renewedDate WHERE id = ?', [$id]);
|
||||
|
||||
return true;
|
||||
return null;
|
||||
}
|
||||
|
||||
public function deleteDomain($id)
|
||||
|
|
|
@ -167,3 +167,101 @@ function assets($location){
|
|||
function toArray($data){
|
||||
return json_decode(json_encode($data), true);
|
||||
}
|
||||
|
||||
function validate_identifier($identifier) {
|
||||
if (!$identifier) {
|
||||
return 'Please provide a contact ID';
|
||||
}
|
||||
|
||||
$length = strlen($identifier);
|
||||
|
||||
if ($length < 3) {
|
||||
return 'Identifier type minLength value=3, maxLength value=16';
|
||||
}
|
||||
|
||||
if ($length > 16) {
|
||||
return 'Identifier type minLength value=3, maxLength value=16';
|
||||
}
|
||||
|
||||
$pattern1 = '/^[A-Z]+\-[0-9]+$/';
|
||||
$pattern2 = '/^[A-Za-z][A-Z0-9a-z]*$/';
|
||||
|
||||
if (!preg_match($pattern1, $identifier) && !preg_match($pattern2, $identifier)) {
|
||||
return 'The ID of the contact must contain letters (A-Z) (ASCII), hyphen (-), and digits (0-9).';
|
||||
}
|
||||
}
|
||||
|
||||
function validate_label($label, $db) {
|
||||
if (!$label) {
|
||||
return 'You must enter a domain name';
|
||||
}
|
||||
if (strlen($label) > 63) {
|
||||
return 'Total lenght of your domain must be less then 63 characters';
|
||||
}
|
||||
if (strlen($label) < 2) {
|
||||
return 'Total lenght of your domain must be greater then 2 characters';
|
||||
}
|
||||
if (strpos($label, 'xn--') === false && preg_match("/(^-|^\.|-\.|\.-|--|\.\.|-$|\.$)/", $label)) {
|
||||
return 'Invalid domain name format, cannot begin or end with a hyphen (-)';
|
||||
}
|
||||
|
||||
// Extract TLD from the domain and prepend a dot
|
||||
$parts = explode('.', $label);
|
||||
$tld = "." . end($parts);
|
||||
|
||||
// Check if the TLD exists in the domain_tld table
|
||||
$tldExists = $db->select('SELECT COUNT(*) FROM domain_tld WHERE tld = ?', [$tld]);
|
||||
|
||||
if ($tldExists[0]["COUNT(*)"] == 0) {
|
||||
return 'Zone is not supported';
|
||||
}
|
||||
|
||||
// Fetch the IDN regex for the given TLD
|
||||
$idnRegex = $db->selectRow('SELECT idn_table FROM domain_tld WHERE tld = ?', [$tld]);
|
||||
|
||||
if (!$idnRegex) {
|
||||
return 'Failed to fetch domain IDN table';
|
||||
}
|
||||
|
||||
// Check for invalid characters using fetched regex
|
||||
if (!preg_match($idnRegex['idn_table'], $label)) {
|
||||
return 'Invalid domain name format, please review registry policy about accepted labels';
|
||||
}
|
||||
}
|
||||
|
||||
function normalize_v4_address($v4) {
|
||||
// Remove leading zeros from the first octet
|
||||
$v4 = preg_replace('/^0+(\d)/', '$1', $v4);
|
||||
|
||||
// Remove leading zeros from successive octets
|
||||
$v4 = preg_replace('/\.0+(\d)/', '.$1', $v4);
|
||||
|
||||
return $v4;
|
||||
}
|
||||
|
||||
function normalize_v6_address($v6) {
|
||||
// Upper case any alphabetics
|
||||
$v6 = strtoupper($v6);
|
||||
|
||||
// Remove leading zeros from the first word
|
||||
$v6 = preg_replace('/^0+([\dA-F])/', '$1', $v6);
|
||||
|
||||
// Remove leading zeros from successive words
|
||||
$v6 = preg_replace('/:0+([\dA-F])/', ':$1', $v6);
|
||||
|
||||
// Introduce a :: if there isn't one already
|
||||
if (strpos($v6, '::') === false) {
|
||||
$v6 = preg_replace('/:0:0:/', '::', $v6);
|
||||
}
|
||||
|
||||
// Remove initial zero word before a ::
|
||||
$v6 = preg_replace('/^0+::/', '::', $v6);
|
||||
|
||||
// Remove other zero words before a ::
|
||||
$v6 = preg_replace('/(:0)+::/', '::', $v6);
|
||||
|
||||
// Remove zero words following a ::
|
||||
$v6 = preg_replace('/:(:0)+/', ':', $v6);
|
||||
|
||||
return $v6;
|
||||
}
|
|
@ -22,6 +22,18 @@ msgstr "List Domains"
|
|||
msgid "Check Domain"
|
||||
msgstr "Check Domain"
|
||||
|
||||
msgid "Enter the domain name you want to check:"
|
||||
msgstr "Enter the domain name you want to check:"
|
||||
|
||||
msgid "Check Availability"
|
||||
msgstr "Check Availability"
|
||||
|
||||
msgid "is available"
|
||||
msgstr "is available"
|
||||
|
||||
msgid "is not available"
|
||||
msgstr "is not available"
|
||||
|
||||
msgid "Create Domain"
|
||||
msgstr "Create Domain"
|
||||
|
||||
|
|
|
@ -22,6 +22,18 @@ msgstr "Список доменів"
|
|||
msgid "Check Domain"
|
||||
msgstr "Перевірте домен"
|
||||
|
||||
msgid "Enter the domain name you want to check:"
|
||||
msgstr "Введіть доменне ім’я, яке потрібно перевірити:"
|
||||
|
||||
msgid "Check Availability"
|
||||
msgstr "Перевірте наявність"
|
||||
|
||||
msgid "is available"
|
||||
msgstr "доступний"
|
||||
|
||||
msgid "is not available"
|
||||
msgstr "недоступний"
|
||||
|
||||
msgid "Create Domain"
|
||||
msgstr "Створити домен"
|
||||
|
||||
|
|
67
cp/resources/views/admin/domains/check.twig
Normal file
67
cp/resources/views/admin/domains/check.twig
Normal file
|
@ -0,0 +1,67 @@
|
|||
{% extends "layouts/app.twig" %}
|
||||
|
||||
{% block title %}{{ __('Check Domain') }}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="page-wrapper">
|
||||
<!-- Page header -->
|
||||
<div class="page-header d-print-none">
|
||||
<div class="container-xl">
|
||||
<div class="row g-2 align-items-center">
|
||||
<div class="col">
|
||||
<!-- Page pre-title -->
|
||||
<div class="page-pretitle">
|
||||
Overview
|
||||
</div>
|
||||
<h2 class="page-title">
|
||||
{{ __('Check Domain') }}
|
||||
</h2>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Page body -->
|
||||
<div class="page-body">
|
||||
<div class="container-xl">
|
||||
<div class="col-12">
|
||||
<div class="card">
|
||||
<div class="card-body border-bottom py-3">
|
||||
<p class="mb-4">{{ __('Enter the domain name you want to check:') }}</p>
|
||||
<form action="/domain/check" method="POST">
|
||||
{{ csrf.field | raw }}
|
||||
<div class="input-group mb-3">
|
||||
<input type="text" class="form-control" placeholder="yourdomain.com" name="domain_name" required="required">
|
||||
<button type="submit" class="btn btn-primary">{{ __('Check Availability') }}</button>
|
||||
</div>
|
||||
</form>
|
||||
{% if isAvailable is defined and domainName is defined %}
|
||||
{% if isAvailable %}
|
||||
<div class="alert alert-success" role="alert">
|
||||
{{ domainName }} {{ __('is available') }}!
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="alert alert-danger" role="alert">
|
||||
{{ domainName }} {{ __('is not available') }}: {{ status }}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<footer class="footer footer-transparent d-print-none">
|
||||
<div class="container-xl">
|
||||
<div class="col-12 col-lg-auto mt-3 mt-lg-0">
|
||||
<ul class="list-inline list-inline-dots mb-0">
|
||||
<li class="list-inline-item">
|
||||
Copyright © 2023
|
||||
<a href="https://namingo.org" target="_blank" class="link-secondary">Namingo</a>.
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -59,14 +59,14 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="table-responsive">
|
||||
<div class="table-responsive mt-3">
|
||||
<div id="domainTable"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<footer class="footer footer-transparent d-print-none">
|
||||
<div class="container-xl">
|
||||
<div class="col-12 col-lg-auto mt-3 mt-lg-0">
|
|
@ -179,7 +179,7 @@
|
|||
<a class="dropdown-item" href="{{route('domains')}}">
|
||||
{{ __('List Domains') }}
|
||||
</a>
|
||||
<a class="dropdown-item" href="#">
|
||||
<a class="dropdown-item" href="{{route('domaincheck')}}">
|
||||
{{ __('Check Domain') }}
|
||||
</a>
|
||||
<a class="dropdown-item" href="#">
|
||||
|
|
|
@ -38,7 +38,10 @@ $app->group('', function ($route) {
|
|||
|
||||
$app->group('', function ($route) {
|
||||
$route->get('/dashboard', HomeController::class .':dashboard')->setName('home');
|
||||
|
||||
$route->get('/domains', DomainsController::class .':view')->setName('domains');
|
||||
$route->map(['GET', 'POST'], '/domain/check', DomainsController::class . ':check')->setName('domaincheck');
|
||||
|
||||
$route->get('/contacts', ContactsController::class .':view')->setName('contacts');
|
||||
$route->get('/hosts', HostsController::class .':view')->setName('hosts');
|
||||
$route->get('/registrars', RegistrarsController::class .':view')->setName('registrars');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue