CA
This commit is contained in:
@@ -116,7 +116,6 @@
|
||||
<option value="AAAA">AAAA</option>
|
||||
<option value="CNAME">CNAME</option>
|
||||
<option value="TXT">TXT</option>
|
||||
<option value="NS">NS</option>
|
||||
</select>
|
||||
</div>
|
||||
<div style="form-group">
|
||||
@@ -131,7 +130,6 @@
|
||||
<span id="help-AAAA" style="hidden">Enter an IPv6 address (e.g., 2001:db8::1)</span>
|
||||
<span id="help-CNAME" style="hidden">Enter a domain name (e.g., example.com)</span>
|
||||
<span id="help-TXT" style="hidden">Enter any text content</span>
|
||||
<span id="help-NS" style="hidden">Enter a nameserver domain (e.g., ns1.example.com)</span>
|
||||
</div>
|
||||
</div>
|
||||
<div style="form-group">
|
||||
|
||||
@@ -131,7 +131,7 @@ renderRecords = function(appendOnly)
|
||||
local typeCell = gurt.create('div', { text = record.type, style = 'font-bold' })
|
||||
local nameCell = gurt.create('div', { text = record.name or '@' })
|
||||
local valueCell = gurt.create('div', { text = record.value, style = 'font-mono text-sm break-all' })
|
||||
local ttlCell = gurt.create('div', { text = record.ttl or '3600' })
|
||||
local ttlCell = gurt.create('div', { text = record.ttl or 'none' })
|
||||
|
||||
local actionsCell = gurt.create('div')
|
||||
local deleteBtn = gurt.create('button', {
|
||||
@@ -227,16 +227,10 @@ end
|
||||
|
||||
local function addRecord(type, name, value, ttl)
|
||||
hideError('record-error')
|
||||
print('Adding DNS record: ' .. type .. ' ' .. name .. ' ' .. value)
|
||||
print('Network request details:')
|
||||
print(' URL: gurt://localhost:8877/domain/' .. domainName .. '/records')
|
||||
print(' Method: POST')
|
||||
print(' Auth token: ' .. (authToken and 'present' or 'missing'))
|
||||
print(' Domain name: ' .. (domainName or 'nil'))
|
||||
|
||||
|
||||
local response = fetch('gurt://localhost:8877/domain/' .. domainName .. '/records', {
|
||||
method = 'POST',
|
||||
headers = {
|
||||
headers = {
|
||||
['Content-Type'] = 'application/json',
|
||||
Authorization = 'Bearer ' .. authToken
|
||||
},
|
||||
@@ -248,38 +242,24 @@ local function addRecord(type, name, value, ttl)
|
||||
})
|
||||
})
|
||||
|
||||
print('Response received: ' .. tostring(response))
|
||||
|
||||
if response then
|
||||
print('Response status: ' .. tostring(response.status))
|
||||
print('Response ok: ' .. tostring(response:ok()))
|
||||
|
||||
if response:ok() then
|
||||
print('DNS record added successfully')
|
||||
|
||||
-- Clear form
|
||||
gurt.select('#record-name').value = ''
|
||||
gurt.select('#record-value').value = ''
|
||||
gurt.select('#record-ttl').value = '3600'
|
||||
gurt.select('#record-ttl').value = ''
|
||||
|
||||
-- Add the new record to existing records array
|
||||
local newRecord = response:json()
|
||||
if newRecord and newRecord.id then
|
||||
-- Server returned the created record, add it to our local array
|
||||
table.insert(records, newRecord)
|
||||
|
||||
-- Check if we had no records before (showing empty message)
|
||||
local wasEmpty = (#records == 1) -- If this is the first record
|
||||
local wasEmpty = (#records == 1)
|
||||
|
||||
if wasEmpty then
|
||||
-- Full re-render to replace empty message with proper table
|
||||
renderRecords(false)
|
||||
else
|
||||
-- Just append the new record to existing table
|
||||
renderRecords(true)
|
||||
end
|
||||
else
|
||||
-- Server didn't return record details, reload to get the actual data
|
||||
loadRecords()
|
||||
end
|
||||
else
|
||||
@@ -288,7 +268,6 @@ local function addRecord(type, name, value, ttl)
|
||||
print('Failed to add DNS record: ' .. error)
|
||||
end
|
||||
else
|
||||
print('No response received from server')
|
||||
showError('record-error', 'No response from server - connection failed')
|
||||
print('Failed to add DNS record: No response')
|
||||
end
|
||||
@@ -310,7 +289,7 @@ local function updateHelpText()
|
||||
local recordType = gurt.select('#record-type').value
|
||||
|
||||
-- Hide all help texts
|
||||
local helpTypes = {'A', 'AAAA', 'CNAME', 'TXT', 'NS'}
|
||||
local helpTypes = {'A', 'AAAA', 'CNAME', 'TXT'}
|
||||
for _, helpType in ipairs(helpTypes) do
|
||||
local helpElement = gurt.select('#help-' .. helpType)
|
||||
if helpElement then
|
||||
@@ -330,7 +309,7 @@ local function updateHelpText()
|
||||
valueInput.placeholder = '192.168.1.1'
|
||||
elseif recordType == 'AAAA' then
|
||||
valueInput.placeholder = '2001:db8::1'
|
||||
elseif recordType == 'CNAME' or recordType == 'NS' then
|
||||
elseif recordType == 'CNAME' then
|
||||
valueInput.placeholder = 'example.com'
|
||||
elseif recordType == 'TXT' then
|
||||
valueInput.placeholder = 'Any text content'
|
||||
@@ -346,7 +325,7 @@ gurt.select('#add-record-btn'):on('click', function()
|
||||
local recordType = gurt.select('#record-type').value
|
||||
local recordName = gurt.select('#record-name').value
|
||||
local recordValue = gurt.select('#record-value').value
|
||||
local recordTTL = tonumber(gurt.select('#record-ttl').value) or 3600
|
||||
local recordTTL = tonumber(gurt.select('#record-ttl').value) or ''
|
||||
|
||||
if not recordValue or recordValue == '' then
|
||||
showError('record-error', 'Record value is required')
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
<input id="password" type="password" placeholder="Password" required="true" />
|
||||
<button type="submit" id="submit">Log In</button>
|
||||
</form>
|
||||
<p style="text-center mt-4 text-[#999999] text-base">Don't have an account? <a href="#">Register here</a></p>
|
||||
<p style="text-center mt-4 text-[#999999] text-base">Don't have an account? <a href="/signup.html">Register here</a></p>
|
||||
|
||||
<p id="log-output" style="min-h-24"></p>
|
||||
</div>
|
||||
|
||||
68
dns/frontend/signup.html
Normal file
68
dns/frontend/signup.html
Normal file
@@ -0,0 +1,68 @@
|
||||
<head></head>
|
||||
<title>Sign Up</title>
|
||||
<icon src="https://cdn-icons-png.flaticon.com/512/295/295128.png">
|
||||
<meta name="theme-color" content="#1b1b1b">
|
||||
<meta name="description" content="Create a new account">
|
||||
|
||||
<font name="roboto" src="https://fonts.gstatic.com/s/roboto/v48/KFO7CnqEu92Fr1ME7kSn66aGLdTylUAMa3KUBGEe.woff2" />
|
||||
|
||||
<style>
|
||||
body {
|
||||
bg-[#171616] font-sans text-white
|
||||
}
|
||||
|
||||
.signup-card {
|
||||
bg-[#262626] p-8 rounded-lg shadow-lg max-w-md mx-auto my-auto h-full
|
||||
}
|
||||
|
||||
h1 {
|
||||
text-3xl font-bold text-center mb-6
|
||||
}
|
||||
|
||||
input {
|
||||
w-full p-3 border border-gray-600 rounded-md bg-[#374151] text-white mb-4 placeholder:text-[#999999] outline-none active:border-red-500
|
||||
}
|
||||
|
||||
button {
|
||||
bg-[#dc2626] text-white font-medium p-3 rounded-lg w-full cursor-pointer transition-colors hover:bg-[#b91c1c] active:bg-[#991b1b]
|
||||
}
|
||||
|
||||
a {
|
||||
text-[#ef4444] hover:text-[#dc2626] cursor-pointer
|
||||
}
|
||||
|
||||
#log-output {
|
||||
text-[#fca5a5] p-4 rounded-md mt-4 font-mono max-h-40
|
||||
}
|
||||
|
||||
.info-box {
|
||||
bg-[#1f2937] p-4 rounded-md mb-4 border border-[#374151]
|
||||
}
|
||||
|
||||
.info-text {
|
||||
text-[#d1d5db] text-sm
|
||||
}
|
||||
</style>
|
||||
|
||||
<script src="signup.lua" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div style="signup-card">
|
||||
<h1>Sign Up</h1>
|
||||
|
||||
<div style="info-box">
|
||||
<p style="info-text">New users get 3 free domain registrations to get started!</p>
|
||||
</div>
|
||||
|
||||
<form id="signup-form" style="mx-auto">
|
||||
<input id="username" type="text" placeholder="Username" required="true" />
|
||||
<input id="password" type="password" placeholder="Password" required="true" />
|
||||
<input id="confirm-password" type="password" placeholder="Confirm Password" required="true" />
|
||||
<button type="submit" id="submit">Create Account</button>
|
||||
</form>
|
||||
<p style="text-center mt-4 text-[#999999] text-base">Already have an account? <a href="index.html">Login here</a></p>
|
||||
|
||||
<p id="log-output" style="min-h-24"></p>
|
||||
</div>
|
||||
</body>
|
||||
96
dns/frontend/signup.lua
Normal file
96
dns/frontend/signup.lua
Normal file
@@ -0,0 +1,96 @@
|
||||
if gurt.crumbs.get("auth_token") then
|
||||
gurt.location.goto("/dashboard.html")
|
||||
end
|
||||
|
||||
local submitBtn = gurt.select('#submit')
|
||||
local username_input = gurt.select('#username')
|
||||
local password_input = gurt.select('#password')
|
||||
local confirm_password_input = gurt.select('#confirm-password')
|
||||
local log_output = gurt.select('#log-output')
|
||||
|
||||
function addLog(message)
|
||||
gurt.log(message)
|
||||
log_output.text = log_output.text .. message .. '\n'
|
||||
end
|
||||
|
||||
function clearLog()
|
||||
log_output.text = ''
|
||||
end
|
||||
|
||||
function validateForm(username, password, confirmPassword)
|
||||
if not username or username == '' then
|
||||
addLog('Error: Username is required')
|
||||
return false
|
||||
end
|
||||
|
||||
if not password or password == '' then
|
||||
addLog('Error: Password is required')
|
||||
return false
|
||||
end
|
||||
|
||||
if password ~= confirmPassword then
|
||||
addLog('Error: Passwords do not match')
|
||||
return false
|
||||
end
|
||||
|
||||
if string.len(password) < 6 then
|
||||
addLog('Error: Password must be at least 6 characters long')
|
||||
return false
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
submitBtn:on('submit', function(event)
|
||||
local username = event.data.username
|
||||
local password = event.data.password
|
||||
local confirmPassword = event.data['confirm-password']
|
||||
|
||||
clearLog()
|
||||
|
||||
if not validateForm(username, password, confirmPassword) then
|
||||
return
|
||||
end
|
||||
|
||||
local request_body = JSON.stringify({
|
||||
username = username,
|
||||
password = password
|
||||
})
|
||||
|
||||
local url = 'gurt://127.0.0.1:8877/auth/register'
|
||||
local headers = {
|
||||
['Content-Type'] = 'application/json'
|
||||
}
|
||||
|
||||
addLog('Creating account for username: ' .. username)
|
||||
|
||||
local response = fetch(url, {
|
||||
method = 'POST',
|
||||
headers = headers,
|
||||
body = request_body
|
||||
})
|
||||
|
||||
addLog('Response Status: ' .. response.status .. ' ' .. response.statusText)
|
||||
|
||||
if response:ok() then
|
||||
addLog('Account created successfully!')
|
||||
local jsonData = response:json()
|
||||
if jsonData then
|
||||
addLog('Welcome, ' .. jsonData.user.username .. '!')
|
||||
addLog('You have ' .. jsonData.user.registrations_remaining .. ' domain registrations available')
|
||||
|
||||
gurt.crumbs.set({
|
||||
name = "auth_token",
|
||||
value = jsonData.token,
|
||||
lifespan = 604800
|
||||
})
|
||||
|
||||
addLog('Redirecting to dashboard...')
|
||||
gurt.location.goto("/dashboard.html")
|
||||
end
|
||||
else
|
||||
addLog('Registration failed with status: ' .. response.status)
|
||||
local error_data = response:text()
|
||||
addLog('Error: ' .. error_data)
|
||||
end
|
||||
end)
|
||||
Reference in New Issue
Block a user