getnamingo-registry/cp/resources/views/admin/domains/create.twig
2023-09-04 19:22:04 +03:00

319 lines
No EOL
16 KiB
Twig

{% extends "layouts/app.twig" %}
{% block title %}{{ __('Create 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">
{{ __('Create Domain') }}
</h2>
</div>
</div>
</div>
</div>
<!-- Page body -->
<div class="page-body">
<div class="container-xl">
<div class="col-12">
{% if domainName is defined and crdate is defined %}
<div class="alert alert-important alert-success alert-dismissible" role="alert">
<div class="d-flex">
<div>
<svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M5 12l5 5l10 -10" /></svg>
</div>
<div>
&nbsp;{{ __('Domain') }} <strong>{{ domainName }}</strong> {{ __('has been created successfully on') }} <strong>{{ crdate|date("Y-m-d H:i:s") }}!</strong>
</div>
</div>
<a class="btn-close" data-bs-dismiss="alert" aria-label="close"></a>
</div>
{% elseif error is defined %}
<div class="alert alert-important alert-danger alert-dismissible" role="alert">
<div class="d-flex">
<div>
<svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M3 12a9 9 0 1 0 18 0a9 9 0 0 0 -18 0" /><path d="M12 8v4" /><path d="M12 16h.01" /></svg>
</div>
<div>
&nbsp;{{ __('Domain') }} <strong>{{ domainName }}</strong> {{ __('can not be created') }}: <strong>{{ error }}</strong>
</div>
</div>
<a class="btn-close" data-bs-dismiss="alert" aria-label="close"></a>
</div>
{% endif %}
<div class="card">
<div class="card-body">
<form id="domainCreateForm" action="/domain/create" method="post">
{{ csrf.field | raw }}
<div class="mb-3">
<label for="domainName" class="form-label required">Your Domain Name</label>
<input type="text" class="form-control mb-2" placeholder="example.com" name="domainName" id="domainName" required="required">
</div>
{% if registrars %}
<div class="form-group mb-3">
<label for="registrarDropdown" class="form-label required">{{ __('Select Registrar') }}:</label>
<select id="registrarDropdown" name="registrar" class="form-control">
{% for registrar in registrars %}
<option value="{{ registrar.id }}">{{ registrar.name }}</option>
{% endfor %}
</select>
</div>
{% endif %}
<!-- Slider for years -->
<div class="mb-3">
<label for="registrationYears" class="form-label">Registration Years</label>
<input type="range" class="form-range" min="1" max="10" step="1" id="registrationYears" name="registrationYears" value="1">
<span id="yearValue">1 Year</span>
</div>
<!-- Placeholder for displaying domain price -->
<div class="mb-3" id="domainPriceDisplay" style="display:none;">
<strong>Estimated Price: </strong><span id="domainPrice">$0.00</span>
</div>
<!-- Fields for 4 contacts with roles -->
<div class="mb-3">
<label for="contactRegistrant" class="form-label required">Contacts</label>
<input type="text" class="form-control mb-2" placeholder="Registrant Contact" name="contactRegistrant" id="contactRegistrant" required="required">
<input type="text" class="form-control mb-2" placeholder="Admin Contact" name="contactAdmin">
<input type="text" class="form-control mb-2" placeholder="Tech Contact" name="contactTech">
<input type="text" class="form-control mb-2" placeholder="Billing Contact" name="contactBilling">
</div>
<!-- Fields for nameservers -->
<div id="nameserverFields">
<label class="form-label">Nameservers</label>
<div class="nameserver-group mb-1 row">
<div class="col-md-4">
<input type="text" class="form-control mb-1" placeholder="Nameserver 1" name="nameserver[]" required>
</div>
<div class="col-md-4">
<input type="text" class="form-control mb-1" placeholder="Nameserver 1 - IPv4" name="nameserver_ipv4[]">
</div>
<div class="col-md-4">
<input type="text" class="form-control mb-1" placeholder="Nameserver 1 - IPv6" name="nameserver_ipv6[]">
</div>
</div>
<div class="nameserver-group mb-1 row">
<div class="col-md-4">
<input type="text" class="form-control mb-1" placeholder="Nameserver 2" name="nameserver[]" required>
</div>
<div class="col-md-4">
<input type="text" class="form-control mb-1" placeholder="Nameserver 2 - IPv4" name="nameserver_ipv4[]">
</div>
<div class="col-md-4">
<input type="text" class="form-control mb-1" placeholder="Nameserver 2 - IPv6" name="nameserver_ipv6[]">
</div>
</div>
</div>
<button type="button" id="addNameserver" class="btn btn-success btn-sm mb-2">+</button>
<button type="button" id="removeNameserver" class="btn btn-danger btn-sm mb-2">-</button>
<!-- DNSSEC Data with checkbox -->
<div class="mb-3 form-check">
<input type="checkbox" class="form-check-input" id="addDnssec" name="addDnssec">
<label class="form-check-label" for="addDnssec">Add DNSSEC Data</label>
</div>
<div id="dnssecData" style="display: none;">
<div class="mb-3">
<label for="dsKeyTag" class="form-label">DS Record</label>
<input type="text" class="form-control mb-2" placeholder="Key Tag" name="dsKeyTag" id="dsKeyTag">
<select class="form-control mb-2" name="dsAlg">
<option value="" disabled selected>Select Algorithm</option>
<option value="1">RSA/MD5 (deprecated)</option>
<option value="3">DSA/SHA1</option>
<option value="5">RSA/SHA-1</option>
<!-- Add other algorithms as required -->
</select>
<select class="form-control mb-2" name="dsDigestType">
<option value="" disabled selected>Select Digest Type</option>
<option value="1">SHA-1</option>
<option value="2">SHA-256</option>
<!-- Add other digest types as required -->
</select>
<input type="text" class="form-control mb-2" placeholder="Digest" name="dsDigest">
</div>
<div class="mb-3">
<label for="dnskeyFlags" class="form-label">DNSKEY Record</label>
<input type="number" class="form-control mb-2" placeholder="Flags" name="dnskeyFlags" id="dnskeyFlags">
<input type="number" class="form-control mb-2" placeholder="Protocol" name="dnskeyProtocol" value="3" readonly> <!-- Protocol is typically set to 3 -->
<select class="form-control mb-2" name="dnskeyAlg">
<option value="" disabled selected>Select Algorithm</option>
<option value="1">RSA/MD5 (deprecated)</option>
<option value="3">DSA/SHA1</option>
<option value="5">RSA/SHA-1</option>
<!-- Add other algorithms as required -->
</select>
<input type="text" class="form-control mb-2" placeholder="Public Key" name="dnskeyPubKey">
</div>
</div>
<!-- AuthInfo -->
<div class="mb-3">
<label for="authInfo" class="form-label">Auth Info</label>
<input type="text" class="form-control" id="authInfo" name="authInfo" readonly>
</div>
</div>
<div class="card-footer">
<div class="row align-items-center">
<div class="col-auto">
<button type="submit" class="btn btn-primary">Create Domain</button>
</div>
</div>
</div>
</form>
</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 &copy; 2023
<a href="https://namingo.org" target="_blank" class="link-secondary">Namingo</a>.
</li>
</ul>
</div>
</div>
</div>
</footer>
</div>
<script>
document.addEventListener("DOMContentLoaded", function() {
const yearSlider = document.getElementById('registrationYears');
const yearValueDisplay = document.getElementById('yearValue');
const addNameserverBtn = document.getElementById('addNameserver');
const removeNameserverBtn = document.getElementById('removeNameserver');
const nameserverFields = document.getElementById('nameserverFields');
const authInfoField = document.getElementById('authInfo');
// Display year value from slider
yearSlider.addEventListener('input', function() {
yearValueDisplay.textContent = `${yearSlider.value} Year${yearSlider.value > 1 ? 's' : ''}`;
});
function createNameserverGroup(count) {
const group = document.createElement('div');
group.className = 'nameserver-group mb-1 row';
const nameserverCol = document.createElement('div');
nameserverCol.className = 'col-md-4';
const nameserverField = document.createElement('input');
nameserverField.type = 'text';
nameserverField.className = 'form-control mb-1';
nameserverField.placeholder = `Nameserver ${count}`;
nameserverField.name = `nameserver[]`;
nameserverCol.appendChild(nameserverField);
const ipv4Col = document.createElement('div');
ipv4Col.className = 'col-md-4';
const ipv4Field = document.createElement('input');
ipv4Field.type = 'text';
ipv4Field.className = 'form-control mb-1';
ipv4Field.placeholder = `Nameserver ${count} - IPv4`;
ipv4Field.name = `nameserver_ipv4[]`;
ipv4Col.appendChild(ipv4Field);
const ipv6Col = document.createElement('div');
ipv6Col.className = 'col-md-4';
const ipv6Field = document.createElement('input');
ipv6Field.type = 'text';
ipv6Field.className = 'form-control mb-1';
ipv6Field.placeholder = `Nameserver ${count} - IPv6`;
ipv6Field.name = `nameserver_ipv6[]`;
ipv6Col.appendChild(ipv6Field);
group.appendChild(nameserverCol);
group.appendChild(ipv4Col);
group.appendChild(ipv6Col);
return group;
}
// Add nameserver fields
let nameserverCount = 2;
addNameserverBtn.addEventListener('click', function() {
if (nameserverCount < 13) {
nameserverCount++;
const nameserverGroup = createNameserverGroup(nameserverCount);
nameserverFields.appendChild(nameserverGroup);
}
});
// Remove nameserver group
removeNameserverBtn.addEventListener('click', function() {
if (nameserverCount > 2) {
const lastGroup = nameserverFields.querySelector('.nameserver-group:last-child');
if (lastGroup) {
nameserverFields.removeChild(lastGroup);
nameserverCount--;
}
}
});
// Generate random AuthInfo and set it to the field
function generateAuthInfo() {
const charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
let result = "";
for (let i = 0; i < 16; i++) {
result += charset.charAt(Math.floor(Math.random() * charset.length));
}
return result;
}
authInfoField.value = generateAuthInfo();
// Display DNSSEC data when the checkbox is ticked
document.getElementById('addDnssec').addEventListener('change', function() {
const dnssecData = document.getElementById('dnssecData');
if (this.checked) {
dnssecData.style.display = 'block';
} else {
dnssecData.style.display = 'none';
}
});
const domainInput = document.getElementById('domainName');
const yearInput = document.getElementById('registrationYears');
const priceDisplay = document.getElementById('domainPriceDisplay');
const priceValue = document.getElementById('domainPrice');
// Simulate an API request
function getDomainPrice(domain, years) {
// For now, we'll just return a dummy price. In a real scenario, you'd call your API here.
return new Promise(resolve => {
setTimeout(() => {
resolve(10.00 * years); // Example: Price is $10/year
}, 500); // Simulating API delay
});
}
function updatePrice() {
if (domainInput.value) {
getDomainPrice(domainInput.value, yearInput.value).then(price => {
priceValue.innerText = `$${price.toFixed(2)}`;
priceDisplay.style.display = 'block';
});
} else {
priceDisplay.style.display = 'none';
}
}
domainInput.addEventListener('input', updatePrice);
yearInput.addEventListener('input', updatePrice);
});
</script>
{% endblock %}