From dda44f7df667ff97e8e387e76cd348368e7f7265 Mon Sep 17 00:00:00 2001 From: Revertron Date: Thu, 18 Mar 2021 18:53:14 +0100 Subject: [PATCH] Implemented immidiate check of DNS records, reverted Edge usage. --- Cargo.toml | 2 +- src/web_ui.rs | 10 ++++++++++ src/webview/scripts.js | 25 ++++++++++++++++++++----- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3fc7616..22c096d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ rust-crypto = "^0.2" blakeout = "0.1.0" num_cpus = "1.13.0" byteorder = "1.3.2" -web-view = { version = "0.7.3", features = ["edge"] } +web-view = { version = "0.7.3", features = [] } tinyfiledialogs = "3.3.10" serde = { version = "1.0.123", features = ["derive"] } serde_json = "1.0.42" diff --git a/src/web_ui.rs b/src/web_ui.rs index 3633d73..b638cb7 100644 --- a/src/web_ui.rs +++ b/src/web_ui.rs @@ -46,6 +46,7 @@ pub fn run_interface(context: Arc>, miner: Arc>) { LoadKey => { action_load_key(&context, web_view); } CreateKey => { keys::create_key(Arc::clone(&context)); } SaveKey => { action_save_key(&context); } + CheckRecord { data } => { action_check_record(web_view, data); } CheckDomain { name } => { action_check_domain(&context, web_view, name); } MineDomain { name, records, .. } => { action_create_domain(Arc::clone(&context), Arc::clone(&miner), web_view, name, &records); @@ -105,6 +106,13 @@ fn action_check_zone(context: &Arc>, web_view: &mut WebView<()>, } } +fn action_check_record(web_view: &mut WebView<()>, data: String) { + match serde_json::from_str::(&data) { + Ok(_) => { web_view.eval("recordOkay(true)").expect("Error evaluating!"); } + Err(e) => { web_view.eval("recordOkay(false)").expect("Error evaluating!"); dbg!(e); } + } +} + fn action_check_domain(context: &Arc>, web_view: &mut WebView<()>, name: String) { let name = name.to_lowercase(); let c = context.lock().unwrap(); @@ -230,6 +238,7 @@ fn action_create_domain(context: Arc>, miner: Arc>, let data = DomainData::new(zone.clone(), records); let data = serde_json::to_string(&data).unwrap(); create_domain(c, miner, &name, &data, difficulty, &context.keystore); + let _ = web_view.eval("domainMiningStarted()"); } } MineResult::WrongName => { show_warning(web_view, "You can't mine this domain!"); } @@ -304,6 +313,7 @@ pub enum Cmd { SaveKey, CheckZone { name: String }, MineZone { name: String, data: String }, + CheckRecord { data: String }, CheckDomain { name: String }, MineDomain { name: String, records: String, tags: String }, TransferDomain { name: String, owner: String }, diff --git a/src/webview/scripts.js b/src/webview/scripts.js index 0638f6f..cd2d2df 100644 --- a/src/webview/scripts.js +++ b/src/webview/scripts.js @@ -48,9 +48,7 @@ function refresh_records_list() { function showNewRecordDialog() { button_positive = document.getElementById("new_record_positive_button"); button_positive.onclick = function() { - addRecord(get_record_from_dialog()); // It will refresh list - dialog = document.getElementById("new_record_dialog"); - dialog.className = "modal"; + checkRecord(get_record_from_dialog()); }; button_negative = document.getElementById("new_record_negative_button"); @@ -65,7 +63,7 @@ function showNewRecordDialog() { } function get_record_from_dialog() { - record_name = document.getElementById("record_name").value; + record_name = document.getElementById("record_name").value.toLowerCase(); record_type = document.getElementById("record_type").value; record_ttl = parseInt(document.getElementById("record_ttl").value); record_data = document.getElementById("record_data").value; @@ -123,11 +121,28 @@ function saveKey() { external.invoke(JSON.stringify({cmd: 'saveKey'})); } +function checkRecord(data) { + external.invoke(JSON.stringify({cmd: 'checkRecord', data: JSON.stringify(data)})); +} + +function recordOkay(okay) { + if (okay) { + addRecord(get_record_from_dialog()); // It will refresh list + dialog = document.getElementById("new_record_dialog"); + dialog.className = "modal"; + } else { + showWarning('Record is not valid!'); + } +} + function createDomain() { - new_domain = document.getElementById("new_domain").value; + new_domain = document.getElementById("new_domain").value.toLowerCase(); new_dom_records = JSON.stringify(recordsBuffer); new_dom_tags = document.getElementById("new_domain_tags").value; external.invoke(JSON.stringify({cmd: 'mineDomain', name: new_domain, records: new_dom_records, tags: new_dom_tags})); +} + +function domainMiningStarted() { recordsBuffer = []; }