diff --git a/.gitignore b/.gitignore index 3e2ae94..bb782b7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ *target* -*.pem \ No newline at end of file +*.pem +gurty.toml +certs \ No newline at end of file diff --git a/dns/Cargo.lock b/dns/Cargo.lock index 2685d98..82947c7 100644 --- a/dns/Cargo.lock +++ b/dns/Cargo.lock @@ -797,6 +797,21 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + [[package]] name = "form_urlencoded" version = "1.2.1" @@ -1545,12 +1560,50 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +[[package]] +name = "openssl" +version = "0.10.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8505734d46c8ab1e19a1dce3aef597ad87dcb4c37e7188231769bd6bd51cebf8" +dependencies = [ + "bitflags 2.9.2", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.104", +] + [[package]] name = "openssl-probe" version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d05e27ee213611ffe7d6348b942e8f942b37114c00cc03cec254295a4a17852e" +[[package]] +name = "openssl-sys" +version = "0.9.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90096e2e47630d78b7d1c20952dc621f957103f8bc2c8359ec81290d75238571" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "parking_lot" version = "0.12.3" @@ -3082,6 +3135,9 @@ name = "uuid" version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a183cf7feeba97b4dd1c0d46788634f6221d87fa961b305bed08c851829efcc0" +dependencies = [ + "getrandom", +] [[package]] name = "uwl" @@ -3250,6 +3306,7 @@ name = "webx_dns" version = "0.0.1" dependencies = [ "anyhow", + "base64 0.22.1", "bcrypt", "chrono", "clap", @@ -3260,6 +3317,7 @@ dependencies = [ "jsonwebtoken", "log", "macros-rs", + "openssl", "pretty_env_logger", "prettytable", "rand", @@ -3267,9 +3325,11 @@ dependencies = [ "serde", "serde_json", "serenity", + "sha2", "sqlx", "tokio", "toml", + "uuid", ] [[package]] diff --git a/dns/Cargo.toml b/dns/Cargo.toml index ddd75d3..17c96dc 100644 --- a/dns/Cargo.toml +++ b/dns/Cargo.toml @@ -26,3 +26,7 @@ clap = { version = "4.5.4", features = ["derive"] } rand = { version = "0.8.5", features = ["small_rng"] } serde = { version = "1.0.203", features = ["derive"] } serde_json = "1.0" +sha2 = "0.10" +base64 = "0.22" +uuid = { version = "1.0", features = ["v4"] } +openssl = "0.10" diff --git a/dns/frontend/domain.html b/dns/frontend/domain.html index 5a422c7..967d21f 100644 --- a/dns/frontend/domain.html +++ b/dns/frontend/domain.html @@ -120,7 +120,7 @@

Name:

- +

Value:

diff --git a/dns/frontend/domain.lua b/dns/frontend/domain.lua index 3700a76..986cc9a 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 @@ -125,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', { @@ -221,11 +227,10 @@ end local function addRecord(type, name, value, ttl) hideError('record-error') - print('Adding DNS record: ' .. type .. ' ' .. name .. ' ' .. value) - + local response = fetch('gurt://localhost:8877/domain/' .. domainName .. '/records', { method = 'POST', - headers = { + headers = { ['Content-Type'] = 'application/json', Authorization = 'Bearer ' .. authToken }, @@ -237,30 +242,36 @@ local function addRecord(type, name, value, ttl) }) }) - 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) - -- Render only the new record - renderRecords(true) + if response then + if response:ok() then + gurt.select('#record-name').value = '' + gurt.select('#record-value').value = '' + gurt.select('#record-ttl').value = '' + + local newRecord = response:json() + if newRecord and newRecord.id then + table.insert(records, newRecord) + + local wasEmpty = (#records == 1) + + if wasEmpty then + renderRecords(false) + else + renderRecords(true) + end + else + 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) + showError('record-error', 'No response from server - connection failed') + print('Failed to add DNS record: No response') end + end local function logout() @@ -273,15 +284,48 @@ 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'} + 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' 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 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') @@ -297,4 +341,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..d97961d 100644 --- a/dns/frontend/index.html +++ b/dns/frontend/index.html @@ -7,35 +7,33 @@