diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..794bbbd --- /dev/null +++ b/.prettierrc @@ -0,0 +1,18 @@ +{ + "arrowParens": "always", + "bracketSameLine": false, + "bracketSpacing": true, + "endOfLine": "lf", + "htmlWhitespaceSensitivity": "css", + "jsxBracketSameLine": false, + "jsxSingleQuote": true, + "printWidth": 120, + "proseWrap": "preserve", + "quoteProps": "consistent", + "semi": true, + "singleAttributePerLine": true, + "singleQuote": false, + "tabWidth": 2, + "trailingComma": "all", + "useTabs": false +} \ No newline at end of file diff --git a/client/bun.lockb b/client/bun.lockb index 34556df..3ce0a0f 100755 Binary files a/client/bun.lockb and b/client/bun.lockb differ diff --git a/client/package.json b/client/package.json index f8b6e70..7382f51 100644 --- a/client/package.json +++ b/client/package.json @@ -18,6 +18,7 @@ "@mui/lab": "^6.0.0-beta.14", "@mui/material": "^6.1.6", "@tauri-apps/api": "^2.1.0", + "@tauri-apps/plugin-http": "~2", "@types/pg": "^8.11.10", "dotenv": "^16.4.5", "jotai": "^2.10.1", diff --git a/client/src-tauri/Cargo.lock b/client/src-tauri/Cargo.lock index d1af67a..3841b44 100644 --- a/client/src-tauri/Cargo.lock +++ b/client/src-tauri/Cargo.lock @@ -99,6 +99,7 @@ dependencies = [ "serde_json", "tauri", "tauri-build", + "tauri-plugin-http", "tauri-plugin-log", ] @@ -131,6 +132,12 @@ dependencies = [ "system-deps", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.4.0" @@ -463,7 +470,7 @@ dependencies = [ "bitflags 2.6.0", "block", "cocoa-foundation", - "core-foundation", + "core-foundation 0.10.0", "core-graphics", "foreign-types", "libc", @@ -478,7 +485,7 @@ checksum = "e14045fb83be07b5acf1c0884b2180461635b433455fa35d1cd6f17f1450679d" dependencies = [ "bitflags 2.6.0", "block", - "core-foundation", + "core-foundation 0.10.0", "core-graphics-types", "libc", "objc", @@ -506,10 +513,39 @@ version = "0.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ddef33a339a91ea89fb53151bd0a4689cfce27055c291dfa69945475d22c747" dependencies = [ + "percent-encoding", "time", "version_check", ] +[[package]] +name = "cookie_store" +version = "0.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2eac901828f88a5241ee0600950ab981148a18f2f756900ffba1b125ca6a3ef9" +dependencies = [ + "cookie", + "document-features", + "idna 1.0.3", + "log", + "publicsuffix", + "serde", + "serde_derive", + "serde_json", + "time", + "url", +] + +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "core-foundation" version = "0.10.0" @@ -533,7 +569,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa95a34622365fa5bbf40b20b75dba8dfa8c94c734aea8ac9a5ca38af14316f1" dependencies = [ "bitflags 2.6.0", - "core-foundation", + "core-foundation 0.10.0", "core-graphics-types", "foreign-types", "libc", @@ -546,7 +582,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d44a101f213f6c4cdc1853d4b78aef6db6bdfa3468798cc1d9912f4735013eb" dependencies = [ "bitflags 2.6.0", - "core-foundation", + "core-foundation 0.10.0", "libc", ] @@ -665,6 +701,12 @@ dependencies = [ "syn 2.0.87", ] +[[package]] +name = "data-url" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c297a1c74b71ae29df00c3e22dd9534821d60eb9af5a0192823fa2acea70c2a" + [[package]] name = "deranged" version = "0.3.11" @@ -759,6 +801,15 @@ dependencies = [ "syn 2.0.87", ] +[[package]] +name = "document-features" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb6969eaabd2421f8a2775cfd2471a2b634372b4a25d41e3bd647b79912850a0" +dependencies = [ + "litrs", +] + [[package]] name = "dpi" version = "0.1.1" @@ -815,6 +866,15 @@ version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ef6b89e5b37196644d8796de5268852ff179b44e96276cf4290264843743bb7" +[[package]] +name = "encoding_rs" +version = "0.8.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3" +dependencies = [ + "cfg-if", +] + [[package]] name = "env_filter" version = "0.1.2" @@ -1303,6 +1363,25 @@ dependencies = [ "syn 2.0.87", ] +[[package]] +name = "h2" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap 2.6.0", + "slab", + "tokio", + "tokio-util", + "tracing", +] + [[package]] name = "hashbrown" version = "0.12.3" @@ -1405,6 +1484,7 @@ dependencies = [ "bytes", "futures-channel", "futures-util", + "h2", "http", "http-body", "httparse", @@ -1415,6 +1495,24 @@ dependencies = [ "want", ] +[[package]] +name = "hyper-rustls" +version = "0.27.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" +dependencies = [ + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", + "webpki-roots", +] + [[package]] name = "hyper-util" version = "0.1.10" @@ -1591,6 +1689,16 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" +[[package]] +name = "idna" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e14ddfc70884202db2244c223200c204c2bda1bc6e0998d11b5e024d657209e6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + [[package]] name = "idna" version = "1.0.3" @@ -1832,6 +1940,12 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "643cb0b8d4fcc284004d5fd0d67ccf61dfffadb7f75e1e71bc420f4688a3a704" +[[package]] +name = "litrs" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4ce301924b7887e9d637144fdade93f9dfff9b60981d4ac161db09720d39aa5" + [[package]] name = "lock_api" version = "0.4.12" @@ -2596,6 +2710,12 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "psl-types" +version = "2.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33cb294fe86a74cbcf50d4445b37da762029549ebeea341421c7c70370f86cac" + [[package]] name = "ptr_meta" version = "0.1.4" @@ -2616,6 +2736,16 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "publicsuffix" +version = "2.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96a8c1bda5ae1af7f99a2962e49df150414a43d62404644d98dd5c3a93d07457" +dependencies = [ + "idna 0.3.0", + "psl-types", +] + [[package]] name = "quick-xml" version = "0.32.0" @@ -2625,6 +2755,55 @@ dependencies = [ "memchr", ] +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror 1.0.69", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand 0.8.5", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror 1.0.69", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d5a626c6807713b15cac82a6acaccd6043c9a5408c24baae07611fec3f243da" +dependencies = [ + "cfg_aliases 0.2.1", + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.59.0", +] + [[package]] name = "quote" version = "1.0.37" @@ -2793,12 +2972,17 @@ checksum = "a77c62af46e79de0a562e1a9849205ffcb7fc1238876e9bd743357570e04046f" dependencies = [ "base64 0.22.1", "bytes", + "cookie", + "cookie_store", + "encoding_rs", "futures-core", "futures-util", + "h2", "http", "http-body", "http-body-util", "hyper", + "hyper-rustls", "hyper-util", "ipnet", "js-sys", @@ -2807,11 +2991,17 @@ dependencies = [ "once_cell", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", + "rustls-pemfile", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", "sync_wrapper", + "system-configuration", "tokio", + "tokio-rustls", "tokio-util", "tower-service", "url", @@ -2819,9 +3009,25 @@ dependencies = [ "wasm-bindgen-futures", "wasm-streams", "web-sys", + "webpki-roots", "windows-registry", ] +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom 0.2.15", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + [[package]] name = "rkyv" version = "0.7.45" @@ -2873,6 +3079,12 @@ version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +[[package]] +name = "rustc-hash" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" + [[package]] name = "rustc_version" version = "0.4.1" @@ -2882,6 +3094,46 @@ dependencies = [ "semver", ] +[[package]] +name = "rustls" +version = "0.23.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eee87ff5d9b36712a58574e12e9f0ea80f915a5b0ac518d322b24a465617925e" +dependencies = [ + "once_cell", + "ring", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16f1201b3c9a7ee8039bcadc17b7e605e2945b27eee7631788c1bd2b0643674b" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + [[package]] name = "ryu" version = "1.0.18" @@ -3221,6 +3473,12 @@ dependencies = [ "system-deps", ] +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + [[package]] name = "stable_deref_trait" version = "1.2.0" @@ -3259,6 +3517,12 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + [[package]] name = "swift-rs" version = "1.0.7" @@ -3324,6 +3588,27 @@ dependencies = [ "syn 2.0.87", ] +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags 2.6.0", + "core-foundation 0.9.4", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "system-deps" version = "6.2.2" @@ -3345,7 +3630,7 @@ checksum = "833b4d43383d76d5078d72f3acd977f47eb5b6751eb40baa665d13828e7b79df" dependencies = [ "bitflags 2.6.0", "cocoa", - "core-foundation", + "core-foundation 0.10.0", "core-graphics", "crossbeam-channel", "dispatch", @@ -3529,6 +3814,49 @@ dependencies = [ "walkdir", ] +[[package]] +name = "tauri-plugin-fs" +version = "2.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96ba7d46e86db8c830d143ef90ab5a453328365b0cc834c24edea4267b16aba0" +dependencies = [ + "anyhow", + "dunce", + "glob", + "percent-encoding", + "schemars", + "serde", + "serde_json", + "serde_repr", + "tauri", + "tauri-plugin", + "thiserror 1.0.69", + "url", + "uuid", +] + +[[package]] +name = "tauri-plugin-http" +version = "2.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c752aee1b00ec3c4d4f440095995d9bd2c640b478f2067d1fba388900b82eb96" +dependencies = [ + "data-url", + "http", + "regex", + "reqwest", + "schemars", + "serde", + "serde_json", + "tauri", + "tauri-plugin", + "tauri-plugin-fs", + "thiserror 1.0.69", + "tokio", + "url", + "urlpattern", +] + [[package]] name = "tauri-plugin-log" version = "2.0.2" @@ -3770,9 +4098,32 @@ dependencies = [ "mio", "pin-project-lite", "socket2", + "tokio-macros", "windows-sys 0.52.0", ] +[[package]] +name = "tokio-macros" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + [[package]] name = "tokio-util" version = "0.7.12" @@ -3950,18 +4301,39 @@ dependencies = [ "unic-common", ] +[[package]] +name = "unicode-bidi" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" + [[package]] name = "unicode-ident" version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" +[[package]] +name = "unicode-normalization" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" +dependencies = [ + "tinyvec", +] + [[package]] name = "unicode-segmentation" version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + [[package]] name = "url" version = "2.5.3" @@ -3969,7 +4341,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8d157f1b96d14500ffdc1f10ba712e780825526c03d9a49b4d0324b0d9113ada" dependencies = [ "form_urlencoded", - "idna", + "idna 1.0.3", "percent-encoding", "serde", ] @@ -4223,6 +4595,15 @@ dependencies = [ "system-deps", ] +[[package]] +name = "webpki-roots" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "webview2-com" version = "0.33.0" @@ -4781,6 +5162,12 @@ dependencies = [ "synstructure", ] +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" + [[package]] name = "zerovec" version = "0.10.4" diff --git a/client/src-tauri/Cargo.toml b/client/src-tauri/Cargo.toml index ece8146..e329e87 100644 --- a/client/src-tauri/Cargo.toml +++ b/client/src-tauri/Cargo.toml @@ -23,3 +23,4 @@ serde = { version = "1.0", features = ["derive"] } log = "0.4" tauri = { version = "2.1.0", features = [] } tauri-plugin-log = "2.0.0-rc" +tauri-plugin-http = "2" diff --git a/client/src-tauri/build.rs b/client/src-tauri/build.rs index 795b9b7..d860e1e 100644 --- a/client/src-tauri/build.rs +++ b/client/src-tauri/build.rs @@ -1,3 +1,3 @@ fn main() { - tauri_build::build() + tauri_build::build() } diff --git a/client/src-tauri/capabilities/default.json b/client/src-tauri/capabilities/default.json index c135d7f..678b627 100644 --- a/client/src-tauri/capabilities/default.json +++ b/client/src-tauri/capabilities/default.json @@ -6,6 +6,27 @@ "main" ], "permissions": [ - "core:default" + { + "identifier": "core:window:default", + "permissions": [ + "core:window:default", + "core:window:allow-start-dragging", + "core:window:allow-is-fullscreen", + "core:window:allow-minimize", + "core:window:allow-toggle-maximize", + "core:window:allow-close" + ], + "windows": [ + "main" + ] + }, + { + "identifier": "http:default", + "allow": [ + { + "url": "https://ip.vomitblood.com" + } + ] + } ] -} +} \ No newline at end of file diff --git a/client/src-tauri/src/lib.rs b/client/src-tauri/src/lib.rs index 9c3118c..9c98c64 100644 --- a/client/src-tauri/src/lib.rs +++ b/client/src-tauri/src/lib.rs @@ -1,16 +1,17 @@ #[cfg_attr(mobile, tauri::mobile_entry_point)] pub fn run() { - tauri::Builder::default() - .setup(|app| { - if cfg!(debug_assertions) { - app.handle().plugin( - tauri_plugin_log::Builder::default() - .level(log::LevelFilter::Info) - .build(), - )?; - } - Ok(()) - }) - .run(tauri::generate_context!()) - .expect("error while running tauri application"); + tauri::Builder::default() + .plugin(tauri_plugin_http::init()) + .setup(|app| { + if cfg!(debug_assertions) { + app.handle().plugin( + tauri_plugin_log::Builder::default() + .level(log::LevelFilter::Info) + .build(), + )?; + } + Ok(()) + }) + .run(tauri::generate_context!()) + .expect("error while running tauri application"); } diff --git a/client/src-tauri/src/main.rs b/client/src-tauri/src/main.rs index ad5fe83..69c3a72 100644 --- a/client/src-tauri/src/main.rs +++ b/client/src-tauri/src/main.rs @@ -2,5 +2,5 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] fn main() { - app_lib::run(); + app_lib::run(); } diff --git a/client/src-tauri/tauri.conf.json b/client/src-tauri/tauri.conf.json index f2c0aec..1682a90 100644 --- a/client/src-tauri/tauri.conf.json +++ b/client/src-tauri/tauri.conf.json @@ -2,22 +2,6 @@ "$schema": "../node_modules/@tauri-apps/cli/config.schema.json", "app": { "security": { - "capabilities": [ - { - "identifier": "my-identifier", - "permissions": [ - "core:window:default", - "core:window:allow-start-dragging", - "core:window:allow-is-fullscreen", - "core:window:allow-minimize", - "core:window:allow-toggle-maximize", - "core:window:allow-close" - ], - "windows": [ - "main" - ] - } - ], "csp": null }, "windows": [ diff --git a/client/src/components/Generic/Layout.tsx b/client/src/components/Generic/Layout.tsx deleted file mode 100644 index 9cad2af..0000000 --- a/client/src/components/Generic/Layout.tsx +++ /dev/null @@ -1,118 +0,0 @@ -import { - Box, - Button, - Container, - Grid2, - Switch, - TextField, - Typography, - useTheme, -} from "@mui/material"; - -import { HeaderBar } from "../HeaderBar/HeaderBar"; -import { AttackItem } from "../Home/AttackItem"; - -export const Layout = () => { - // contexts - const theme = useTheme(); - - return ( - - - - {/* main content goes here buddy */} - - - - CSPJ Application Attacks - - - Secured version - - - - - {/* - TODO: implmenent simple ping server to check if the user entered a valid backend url - debounce when typing - update textfield color based on the response - */} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ); -}; diff --git a/client/src/components/HeaderBar/HeaderBar.tsx b/client/src/components/HeaderBar/HeaderBar.tsx index 200abff..f779ce6 100644 --- a/client/src/components/HeaderBar/HeaderBar.tsx +++ b/client/src/components/HeaderBar/HeaderBar.tsx @@ -3,6 +3,7 @@ import { WindowButtons } from "./WindowButtons"; import { NavigationButtons } from "./NavigationButtons"; import { RouteDisplay } from "./RouteDisplay"; import { Testing } from "../Testing/Testing"; +import { ServerStatus } from "./ServerStatus"; export const HeaderBar = () => { return ( @@ -71,6 +72,7 @@ export const HeaderBar = () => { flexDirection: "row", }} > + diff --git a/client/src/components/HeaderBar/ServerStatus.tsx b/client/src/components/HeaderBar/ServerStatus.tsx new file mode 100644 index 0000000..6660f52 --- /dev/null +++ b/client/src/components/HeaderBar/ServerStatus.tsx @@ -0,0 +1,115 @@ +import { Box, Button, Chip, CircularProgress, Popover, Stack, useTheme } from "@mui/material"; +import { fetch } from "@tauri-apps/plugin-http"; +import { useAtom } from "jotai"; +import { MouseEvent, useState } from "react"; +import { serverConnectionAtom, serverUrlAtom } from "../../lib/jotai"; +import { defaultSettings } from "../../lib/settings"; +import { ServerUrlInput } from "../Home/ServerUrlInput"; + +export const ServerStatus = () => { + // contexts + const theme = useTheme(); + + // atoms + const [serverConnection, setServerConnection] = useAtom(serverConnectionAtom); + const [serverUrl, setServerUrl] = useAtom(serverUrlAtom); + + // use states + const [anchorEl, setAnchorEl] = useState(null); + + const clickEvent = (event: MouseEvent) => { + setAnchorEl(event.currentTarget); + }; + + const dialogCloseEvent = () => { + setAnchorEl(null); + }; + + // function to check server health + const checkServerConnection = async () => { + fetch(serverUrl + "/health") + .then((response) => { + if (response.ok) { + setServerConnection("connected"); + } else { + setServerConnection("disconnected"); + } + }) + .catch(() => { + setServerConnection("disconnected"); + }); + + // if the server is connected then continue to ping every 5 seconds + if (serverConnection === "connected") { + setTimeout(checkServerConnection, 5000); + } + }; + + return ( + + {serverConnection === "connecting" && ( + + )} + + + +
{ + checkServerConnection(); + }} + > + + + +
+
+
+ ); +}; diff --git a/client/src/components/Home/Layout.tsx b/client/src/components/Home/Layout.tsx new file mode 100644 index 0000000..d65032e --- /dev/null +++ b/client/src/components/Home/Layout.tsx @@ -0,0 +1,89 @@ +import { Box, Button, Container, Grid2, Switch, TextField, Typography, useTheme } from "@mui/material"; + +import { HeaderBar } from "../HeaderBar/HeaderBar"; +import { AttackItem } from "./AttackItem"; +import { ServerUrlInput } from "./ServerUrlInput"; + +export const Layout = () => { + // contexts + const theme = useTheme(); + + return ( + + + + {/* main content goes here buddy */} + + + + CSPJ Application Attack Simulator + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ); +}; diff --git a/client/src/components/Home/ServerUrlInput.tsx b/client/src/components/Home/ServerUrlInput.tsx new file mode 100644 index 0000000..3586fba --- /dev/null +++ b/client/src/components/Home/ServerUrlInput.tsx @@ -0,0 +1,18 @@ +import { TextField } from "@mui/material"; +import { useAtom } from "jotai"; +import { serverConnectionAtom, serverUrlAtom } from "../../lib/jotai"; + +export const ServerUrlInput = () => { + // atoms + const [serverUrl, setServerUrl] = useAtom(serverUrlAtom); + + return ( + setServerUrl(event.target.value)} + size='small' + value={serverUrl} + /> + ); +}; diff --git a/client/src/components/Testing/Testing.tsx b/client/src/components/Testing/Testing.tsx index 0c36372..63edbde 100644 --- a/client/src/components/Testing/Testing.tsx +++ b/client/src/components/Testing/Testing.tsx @@ -1,8 +1,9 @@ +import { BugReportOutlined } from "@mui/icons-material"; import { Box, Button, IconButton, useTheme } from "@mui/material"; +import { fetch } from "@tauri-apps/plugin-http"; import { useState } from "react"; import { defaultSettings } from "../../lib/settings"; import { FloatingDialog } from "../Generic/FloatingDialog"; -import { BugReportOutlined } from "@mui/icons-material"; export const Testing = () => { // contexts @@ -15,6 +16,12 @@ export const Testing = () => { // functions const close = () => setOpenState(false); + const testing = () => { + fetch("https://ip.vomitblood.com/ping").then((response) => { + console.log(response); + }); + }; + return ( { p: 0, }} > - + + + } close={close} maximisedState={maximisedState} openButton={ - setOpenState(true)} size="small"> + setOpenState(true)} + size='small' + > } openState={openState} setMaximisedState={setMaximisedState} - title="Testing" + title='Testing' /> ); }; diff --git a/client/src/lib/jotai.ts b/client/src/lib/jotai.ts index c7ae5d2..9e348c6 100644 --- a/client/src/lib/jotai.ts +++ b/client/src/lib/jotai.ts @@ -1,3 +1,14 @@ +import { Server } from "http"; import { atom } from "jotai"; +// store which page the user is currently on +// no actual routing is done here, +// full page components are used render the different pages export const routeAtom = atom("index"); + +// store the status of connection to backend +type ServerConnection = "connected" | "connecting" | "disconnected"; +export const serverConnectionAtom = atom("disconnected"); + +// store the url of the backend server +export const serverUrlAtom = atom(""); diff --git a/client/src/pages/index.tsx b/client/src/pages/index.tsx index 779323e..140e3b3 100644 --- a/client/src/pages/index.tsx +++ b/client/src/pages/index.tsx @@ -1,4 +1,4 @@ -import { Layout } from "../components/Generic/Layout"; +import { Layout } from "../components/Home/Layout"; export default function Home() { return ; diff --git a/server/internal/http_server/http_server.go b/server/internal/http_server/http_server.go index 06bc217..415e518 100644 --- a/server/internal/http_server/http_server.go +++ b/server/internal/http_server/http_server.go @@ -8,16 +8,23 @@ import ( "github.com/Vomitblood/cspj-application/server/internal/sql_injection" ) +func healthCheck(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + w.Write([]byte(`{"status": "ok"}`)) +} + // setup the http server func ServeApi() { + http.HandleFunc("/health", healthCheck) http.HandleFunc("/setup-demo-db", db.SetupDemoDb) http.HandleFunc("/nuke-db", db.NukeDb) http.HandleFunc("/fetch-all-users", db.FetchAllUsers) http.HandleFunc("/execute-sql", sql_injection.ExecuteSql) http.HandleFunc("/secure-execute-sql", sql_injection.SecureExecuteSql) http.HandleFunc("/secure-get-user", sql_injection.SecureGetUser) - log.Println("Server is running on http://localhost:3001") - if err := http.ListenAndServe(":3001", nil); err != nil { + log.Println("Server is running on http://localhost:5000") + if err := http.ListenAndServe(":5000", nil); err != nil { log.Fatalf("Failed to start server: %v", err) } }