From 0a38af1b66691c614f0e54d613daa2825a9d6d99 Mon Sep 17 00:00:00 2001 From: Face <69168154+face-hh@users.noreply.github.com> Date: Thu, 21 Aug 2025 12:27:44 +0300 Subject: [PATCH 01/17] DNS server (add NS record) --- .gitignore | 3 +- dns/frontend/domain.html | 8 + dns/frontend/domain.lua | 106 +- dns/frontend/index.html | 48 +- dns/frontend/register.html | 5 +- dns/frontend/register.lua | 17 +- dns/migrations/002_remove_ip_requirement.sql | 7 + dns/migrations/003_add_ns_records.sql | 10 + dns/migrations/004_fix_record_types.sql | 8 + dns/src/discord_bot.rs | 173 ++- dns/src/gurt_server.rs | 8 +- dns/src/gurt_server/helpers.rs | 11 - dns/src/gurt_server/models.rs | 21 +- dns/src/gurt_server/routes.rs | 333 ++++- dns/src/main.rs | 1 - dns/src/secret.rs | 26 - docs/docs/dns-system.md | 253 +++- docs/docusaurus.config.ts | 6 +- docs/package-lock.json | 1196 +++++++++++++++++ docs/package.json | 1 + flumi/Scenes/Tags/select.tscn | 2 +- flumi/Scenes/main.tscn | 23 +- flumi/Scripts/GurtProtocol.gd | 283 +++- flumi/Scripts/Tags/p.gd | 2 +- .../gurt-protocol/bin/windows/gurt_godot.dll | Bin 4695552 -> 4697088 bytes .../gurt-protocol/bin/windows/~gurt_godot.dll | Bin 4695552 -> 4697088 bytes protocol/library/src/server.rs | 127 +- 27 files changed, 2313 insertions(+), 365 deletions(-) create mode 100644 dns/migrations/002_remove_ip_requirement.sql create mode 100644 dns/migrations/003_add_ns_records.sql create mode 100644 dns/migrations/004_fix_record_types.sql delete mode 100644 dns/src/secret.rs diff --git a/.gitignore b/.gitignore index 3e2ae94..92a146e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *target* -*.pem \ No newline at end of file +*.pem +*gurty.toml \ No newline at end of file diff --git a/dns/frontend/domain.html b/dns/frontend/domain.html index 5a422c7..1270cc2 100644 --- a/dns/frontend/domain.html +++ b/dns/frontend/domain.html @@ -116,6 +116,7 @@ +
@@ -125,6 +126,13 @@

Value:

+
+ Enter an IPv4 address (e.g., 192.168.1.1) + Enter an IPv6 address (e.g., 2001:db8::1) + Enter a domain name (e.g., example.com) + Enter any text content + Enter a nameserver domain (e.g., ns1.example.com) +

TTL:

diff --git a/dns/frontend/domain.lua b/dns/frontend/domain.lua index 3700a76..19c49ed 100644 --- a/dns/frontend/domain.lua +++ b/dns/frontend/domain.lua @@ -92,10 +92,16 @@ renderRecords = function(appendOnly) if #records == 0 then local emptyMessage = gurt.create('div', { text = 'No DNS records found. Add your first record below!', - style = 'text-center text-[#6b7280] py-8' + style = 'text-center text-[#6b7280] py-8', + id = '404' }) recordsList:append(emptyMessage) return + else + local err = gurt.select('#404') + if err then + gurt.select('#404'):remove() + end end -- Create header only if not appending or if list is empty @@ -222,6 +228,11 @@ 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', @@ -237,30 +248,51 @@ local function addRecord(type, name, value, ttl) }) }) - if response:ok() then - print('DNS record added successfully') + print('Response received: ' .. tostring(response)) + + if response then + print('Response status: ' .. tostring(response.status)) + print('Response ok: ' .. tostring(response:ok())) - -- Clear form - gurt.select('#record-name').value = '' - gurt.select('#record-value').value = '' - gurt.select('#record-ttl').value = '3600' - - -- 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) - -- Render only the new record - renderRecords(true) + 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' + + -- 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 + + 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 - -- Server didn't return record details, reload to get the actual data - loadRecords() + local error = response:text() + showError('record-error', 'Failed to add record: ' .. error) + print('Failed to add DNS record: ' .. error) end else - local error = response:text() - showError('record-error', 'Failed to add record: ' .. error) - print('Failed to add DNS record: ' .. error) + print('No response received from server') + showError('record-error', 'No response from server - connection failed') + print('Failed to add DNS record: No response') end + end local function logout() @@ -273,9 +305,42 @@ local function goBack() --gurt.location.goto("/dashboard.html") end +-- Function to update help text based on record type +local function updateHelpText() + local recordType = gurt.select('#record-type').value + + -- Hide all help texts + local helpTypes = {'A', 'AAAA', 'CNAME', 'TXT', 'NS'} + for _, helpType in ipairs(helpTypes) do + local helpElement = gurt.select('#help-' .. helpType) + if helpElement then + helpElement.classList:add('hidden') + end + end + + -- Show the relevant help text + local currentHelp = gurt.select('#help-' .. recordType) + if currentHelp then + currentHelp.classList:remove('hidden') + end + + -- Update placeholder text based on record type + local valueInput = gurt.select('#record-value') + if recordType == 'A' then + valueInput.placeholder = '192.168.1.1' + elseif recordType == 'AAAA' then + valueInput.placeholder = '2001:db8::1' + elseif recordType == 'CNAME' or recordType == 'NS' then + valueInput.placeholder = 'example.com' + elseif recordType == 'TXT' then + valueInput.placeholder = 'Any text content' + end +end + -- Event handlers gurt.select('#logout-btn'):on('click', logout) gurt.select('#back-btn'):on('click', goBack) +gurt.select('#record-type'):on('change', updateHelpText) gurt.select('#add-record-btn'):on('click', function() local recordType = gurt.select('#record-type').value @@ -297,4 +362,5 @@ end) -- Initialize print('Domain management page initialized') +updateHelpText() -- Set initial help text checkAuth() diff --git a/dns/frontend/index.html b/dns/frontend/index.html index 161e15e..49cf136 100644 --- a/dns/frontend/index.html +++ b/dns/frontend/index.html @@ -7,35 +7,33 @@