Start to make dynamic interfaces work

This commit is contained in:
Michael Mikovsky
2025-12-21 00:35:28 -07:00
parent 1ea26641d6
commit c7d66c5560
26 changed files with 720 additions and 296 deletions
+7
View File
@@ -11,3 +11,10 @@ dist/
# These are backup files generated by rustfmt
**/*.rs.bk
# Added by cargo
#
# already existing elements were commented out
#/target
+353 -29
View File
@@ -34,6 +34,17 @@ version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
[[package]]
name = "aes"
version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0"
dependencies = [
"cfg-if",
"cipher",
"cpufeatures",
]
[[package]]
name = "ahash"
version = "0.8.12"
@@ -48,6 +59,15 @@ dependencies = [
"zerocopy",
]
[[package]]
name = "aho-corasick"
version = "1.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301"
dependencies = [
"memchr",
]
[[package]]
name = "android-activity"
version = "0.6.0"
@@ -164,6 +184,33 @@ dependencies = [
"serde_core",
]
[[package]]
name = "block-buffer"
version = "0.10.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
dependencies = [
"generic-array",
]
[[package]]
name = "block-padding"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8894febbff9f758034a5b8e12d87918f56dfc64a8e1fe757d65e29041538d93"
dependencies = [
"generic-array",
]
[[package]]
name = "block-padding"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "710f1dd022ef4e93f8a438b4ba958de7f64308434fa6a87104481645cc30068b"
dependencies = [
"hybrid-array",
]
[[package]]
name = "block2"
version = "0.5.1"
@@ -196,7 +243,7 @@ checksum = "f9abbd1bc6865053c427f7198e6af43bfdedc55ab791faed4fbd361d789575ff"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.111",
]
[[package]]
@@ -262,6 +309,15 @@ dependencies = [
"wayland-client",
]
[[package]]
name = "cbc"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26b52a9543ae338f279b96b0b9fed9c8093744685043739079ce85cd58f289a6"
dependencies = [
"cipher",
]
[[package]]
name = "cc"
version = "1.2.47"
@@ -286,6 +342,12 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
[[package]]
name = "cfg_aliases"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e"
[[package]]
name = "cfg_aliases"
version = "0.2.1"
@@ -314,6 +376,16 @@ dependencies = [
"windows-link",
]
[[package]]
name = "cipher"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad"
dependencies = [
"crypto-common",
"inout",
]
[[package]]
name = "clipboard-win"
version = "5.4.1"
@@ -401,6 +473,15 @@ dependencies = [
"libc",
]
[[package]]
name = "cpufeatures"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280"
dependencies = [
"libc",
]
[[package]]
name = "crc32fast"
version = "1.5.0"
@@ -422,12 +503,32 @@ version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5"
[[package]]
name = "crypto-common"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a"
dependencies = [
"generic-array",
"typenum",
]
[[package]]
name = "cursor-icon"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f27ae1dd37df86211c42e150270f82743308803d90a6f6e6651cd730d5e1732f"
[[package]]
name = "digest"
version = "0.10.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
dependencies = [
"block-buffer",
"crypto-common",
]
[[package]]
name = "dispatch"
version = "0.2.0"
@@ -452,7 +553,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.111",
]
[[package]]
@@ -673,7 +774,7 @@ checksum = "f282cfdfe92516eb26c2af8589c274c7c17681f5ecc03c18255fe741c6aa64eb"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.111",
]
[[package]]
@@ -684,7 +785,7 @@ checksum = "2f9ed6b3789237c8a0c1c505af1c7eb2c560df6186f01b098c3a1064ea532f38"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.111",
]
[[package]]
@@ -751,7 +852,7 @@ checksum = "a0aca10fb742cb43f9e7bb8467c91aa9bcb8e3ffbc6a6f7389bb93ffc920577d"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.111",
]
[[package]]
@@ -803,7 +904,7 @@ checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.111",
]
[[package]]
@@ -821,6 +922,16 @@ dependencies = [
"percent-encoding",
]
[[package]]
name = "generic-array"
version = "0.14.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
dependencies = [
"typenum",
"version_check",
]
[[package]]
name = "gethostname"
version = "1.1.0"
@@ -873,7 +984,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12124de845cacfebedff80e877bb37b5b75c34c5a4c89e47e1cdd67fb6041325"
dependencies = [
"bitflags 2.10.0",
"cfg_aliases",
"cfg_aliases 0.2.1",
"cgl",
"dispatch2",
"glutin_egl_sys",
@@ -897,7 +1008,7 @@ version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85edca7075f8fc728f28cb8fbb111a96c3b89e930574369e3e9c27eb75d3788f"
dependencies = [
"cfg_aliases",
"cfg_aliases 0.2.1",
"glutin",
"raw-window-handle",
"winit",
@@ -959,6 +1070,18 @@ version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c"
[[package]]
name = "hex"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
[[package]]
name = "hex-literal"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e712f64ec3850b98572bffac52e2c6f282b29fe6c5fa6d42334b30be438d95c1"
[[package]]
name = "hexf-parse"
version = "0.2.1"
@@ -974,6 +1097,15 @@ dependencies = [
"windows-sys 0.61.2",
]
[[package]]
name = "hybrid-array"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f471e0a81b2f90ffc0cb2f951ae04da57de8baa46fa99112b062a5173a5088d0"
dependencies = [
"typenum",
]
[[package]]
name = "iana-time-zone"
version = "0.1.64"
@@ -1124,6 +1256,16 @@ dependencies = [
"hashbrown",
]
[[package]]
name = "inout"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01"
dependencies = [
"block-padding 0.3.3",
"generic-array",
]
[[package]]
name = "itertools"
version = "0.14.0"
@@ -1331,7 +1473,7 @@ dependencies = [
"bit-set",
"bitflags 2.10.0",
"cfg-if",
"cfg_aliases",
"cfg_aliases 0.2.1",
"codespan-reporting",
"half",
"hashbrown",
@@ -1411,7 +1553,7 @@ dependencies = [
"proc-macro-crate",
"proc-macro2",
"quote",
"syn",
"syn 2.0.111",
]
[[package]]
@@ -1755,7 +1897,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c80231409c20246a13fddb31776fb942c38553c51e871f8cbd687a4cfb5843d"
dependencies = [
"phf_shared",
"rand",
"rand 0.8.5",
]
[[package]]
@@ -1768,7 +1910,7 @@ dependencies = [
"phf_shared",
"proc-macro2",
"quote",
"syn",
"syn 2.0.111",
"unicase",
]
@@ -1799,7 +1941,7 @@ checksum = "6e918e4ff8c4549eb882f14b3a4bc8c8bc93de829416eacf579f1207a8fbf861"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.111",
]
[[package]]
@@ -1865,6 +2007,15 @@ dependencies = [
"zerovec",
]
[[package]]
name = "ppv-lite86"
version = "0.2.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9"
dependencies = [
"zerocopy",
]
[[package]]
name = "proc-macro-crate"
version = "3.4.0"
@@ -1934,7 +2085,27 @@ version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"rand_core",
"rand_core 0.6.4",
]
[[package]]
name = "rand"
version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1"
dependencies = [
"rand_chacha",
"rand_core 0.9.3",
]
[[package]]
name = "rand_chacha"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb"
dependencies = [
"ppv-lite86",
"rand_core 0.9.3",
]
[[package]]
@@ -1943,6 +2114,15 @@ version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
[[package]]
name = "rand_core"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38"
dependencies = [
"getrandom",
]
[[package]]
name = "raw-window-handle"
version = "0.6.2"
@@ -1967,6 +2147,35 @@ dependencies = [
"bitflags 2.10.0",
]
[[package]]
name = "regex"
version = "1.12.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "843bc0191f75f3e22651ae5f1e72939ab2f72a4bc30fa80a066bd66edefc24d4"
dependencies = [
"aho-corasick",
"memchr",
"regex-automata",
"regex-syntax",
]
[[package]]
name = "regex-automata"
version = "0.4.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5276caf25ac86c8d810222b3dbb938e512c55c6831a10f3e6ed1c93b84041f1c"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
]
[[package]]
name = "regex-syntax"
version = "0.8.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58"
[[package]]
name = "renderdoc-sys"
version = "1.1.0"
@@ -2084,7 +2293,7 @@ checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.111",
]
[[package]]
@@ -2100,6 +2309,17 @@ dependencies = [
"serde_core",
]
[[package]]
name = "sha2"
version = "0.10.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283"
dependencies = [
"cfg-if",
"cpufeatures",
"digest",
]
[[package]]
name = "shlex"
version = "1.3.0"
@@ -2223,6 +2443,45 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]]
name = "static_init"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8bae1df58c5fea7502e8e352ec26b5579f6178e1fdb311e088580c980dee25ed"
dependencies = [
"bitflags 1.3.2",
"cfg_aliases 0.2.1",
"libc",
"parking_lot",
"parking_lot_core",
"static_init_macro",
"winapi",
]
[[package]]
name = "static_init_macro"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1389c88ddd739ec6d3f8f83343764a0e944cd23cfbf126a9796a714b0b6edd6f"
dependencies = [
"cfg_aliases 0.1.1",
"memchr",
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]]
name = "syn"
version = "1.0.109"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "syn"
version = "2.0.111"
@@ -2242,7 +2501,7 @@ checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.111",
]
[[package]]
@@ -2271,7 +2530,7 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.111",
]
[[package]]
@@ -2282,7 +2541,7 @@ checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.111",
]
[[package]]
@@ -2371,6 +2630,12 @@ dependencies = [
"rustc-hash 2.1.1",
]
[[package]]
name = "typenum"
version = "1.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb"
[[package]]
name = "unicase"
version = "2.8.1"
@@ -2395,6 +2660,20 @@ version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254"
[[package]]
name = "unshell-crypt"
version = "0.1.0"
dependencies = [
"aes",
"block-padding 0.4.2",
"cbc",
"getrandom",
"hex",
"hex-literal",
"regex",
"sha2",
]
[[package]]
name = "unshell-gui"
version = "0.1.0"
@@ -2407,11 +2686,34 @@ dependencies = [
"log",
"serde",
"serde_json",
"unshell-lib",
"wasm-bindgen",
"wasm-bindgen-futures",
"web-sys",
]
[[package]]
name = "unshell-lib"
version = "0.0.0"
dependencies = [
"chrono",
"serde",
"serde_json",
"unshell-obfuscate",
]
[[package]]
name = "unshell-obfuscate"
version = "0.0.0"
dependencies = [
"proc-macro2",
"quote",
"rand 0.9.2",
"static_init",
"syn 2.0.111",
"unshell-crypt",
]
[[package]]
name = "url"
version = "2.5.7"
@@ -2500,7 +2802,7 @@ dependencies = [
"bumpalo",
"proc-macro2",
"quote",
"syn",
"syn 2.0.111",
"wasm-bindgen-shared",
]
@@ -2699,7 +3001,7 @@ dependencies = [
"arrayvec",
"bitflags 2.10.0",
"cfg-if",
"cfg_aliases",
"cfg_aliases 0.2.1",
"document-features",
"hashbrown",
"log",
@@ -2724,7 +3026,7 @@ dependencies = [
"bit-vec",
"bitflags 2.10.0",
"bytemuck",
"cfg_aliases",
"cfg_aliases 0.2.1",
"document-features",
"hashbrown",
"indexmap",
@@ -2760,7 +3062,7 @@ checksum = "5b21cb61c57ee198bc4aff71aeadff4cbb80b927beb912506af9c780d64313ce"
dependencies = [
"bitflags 2.10.0",
"cfg-if",
"cfg_aliases",
"cfg_aliases 0.2.1",
"libloading",
"log",
"naga",
@@ -2786,6 +3088,22 @@ dependencies = [
"web-sys",
]
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-util"
version = "0.1.11"
@@ -2795,6 +3113,12 @@ dependencies = [
"windows-sys 0.61.2",
]
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows-core"
version = "0.62.2"
@@ -2816,7 +3140,7 @@ checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.111",
]
[[package]]
@@ -2827,7 +3151,7 @@ checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.111",
]
[[package]]
@@ -3098,7 +3422,7 @@ dependencies = [
"block2",
"bytemuck",
"calloop 0.13.0",
"cfg_aliases",
"cfg_aliases 0.2.1",
"concurrent-queue",
"core-foundation 0.9.4",
"core-graphics",
@@ -3239,7 +3563,7 @@ checksum = "b659052874eb698efe5b9e8cf382204678a0086ebf46982b79d6ca3182927e5d"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.111",
"synstructure",
]
@@ -3260,7 +3584,7 @@ checksum = "cf955aa904d6040f70dc8e9384444cb1030aed272ba3cb09bbc4ab9e7c1f34f5"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.111",
]
[[package]]
@@ -3280,7 +3604,7 @@ checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.111",
"synstructure",
]
@@ -3314,7 +3638,7 @@ checksum = "eadce39539ca5cb3985590102671f2567e659fca9666581ad3411d59207951f3"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.111",
]
[[package]]
+1 -1
View File
@@ -12,7 +12,7 @@ all-features = true
targets = ["x86_64-unknown-linux-gnu", "wasm32-unknown-unknown"]
[dependencies]
# unshell-lib = {path="../unshell-lib"}
unshell-lib = {path="../unshell-lib"}
egui = "0.33.0"
eframe = { version = "0.33.0", default-features = false, features = [
+38 -5
View File
@@ -1,9 +1,11 @@
use egui::{Align2, Area, Color32, Frame, Order, Sense, UiKind, Vec2, mutex::Mutex};
use serde::de::DeserializeOwned;
use serde::{Serialize, de::DeserializeOwned};
use serde_json::json;
use std::sync::Arc;
use wasm_bindgen::prelude::Closure;
use unshell_lib::Result;
#[derive(serde::Deserialize, serde::Serialize)]
pub struct Auth {
// Auth Stuff
@@ -150,10 +152,10 @@ impl Auth {
// });
}
pub fn get<T, F>(&self, path: &str, ret: F)
pub fn get<R, F>(&self, path: &str, ret: F) -> Result<()>
where
F: FnOnce(T) + 'static,
T: DeserializeOwned,
F: FnOnce(R) + 'static,
R: DeserializeOwned,
{
if let Some(ref token) = self.token {
let state = self.auth_state.clone();
@@ -162,7 +164,7 @@ impl Auth {
format!("Bearer {}", token.token),
Closure::once_into_js(move |ok: bool, response: String| {
if ok {
if let Ok(value) = serde_json::from_str::<T>(&response) {
if let Ok(value) = serde_json::from_str::<R>(&response) {
ret(value)
} else {
*(state.lock()) = AuthState::Error("Malformed Response".into());
@@ -173,6 +175,37 @@ impl Auth {
}),
);
}
Ok(())
}
pub fn post<R, T, F>(&self, path: &str, data: &T, ret: F) -> Result<()>
where
R: DeserializeOwned,
T: Serialize,
F: FnOnce(R) + 'static,
{
if let Some(ref token) = self.token {
let state = self.auth_state.clone();
crate::httpPostAuth(
path,
format!("Bearer {}", token.token),
&serde_json::to_string(data)?,
Closure::once_into_js(move |ok: bool, response: String| {
if ok {
if let Ok(value) = serde_json::from_str::<R>(&response) {
ret(value)
} else {
*(state.lock()) = AuthState::Error("Malformed Response".into());
}
} else {
*(state.lock()) = AuthState::Error(response);
}
}),
);
}
Ok(())
}
}
+13 -9
View File
@@ -1,11 +1,14 @@
mod config;
mod render_interface;
use std::{
path::PathBuf,
sync::{Arc, Mutex},
};
use crate::{auth::Auth, interface::config::Tree2Repr};
use unshell_lib::Result;
use unshell_lib::config::TreeMessage;
use crate::auth::Auth;
#[derive(serde::Deserialize, serde::Serialize)]
pub struct InterfaceWindow {
@@ -18,7 +21,7 @@ pub struct InterfaceWindow {
pub struct InterfaceWindowState {
is_request: bool,
is_error: bool,
branch: Option<Tree2Repr>,
branch: Option<TreeMessage>,
}
impl InterfaceWindow {
@@ -63,7 +66,7 @@ impl InterfaceWindow {
let state_clone = self.state.clone();
auth.get(
&format!("/api/interface{}", self.path.display()),
move |response: Result<Tree2Repr, String>| {
move |response: Result<TreeMessage>| {
let mut state_lock = state_clone.lock().unwrap();
match response {
@@ -79,20 +82,21 @@ impl InterfaceWindow {
drop(state_lock);
},
);
)
.unwrap();
} else {
let state_clone = self.state.clone();
let mut state_lock = state_clone.lock().unwrap();
let branch = (state_lock.branch).as_ref().unwrap();
let mut branch = (state_lock.branch).as_mut().unwrap();
let clear = match branch {
Tree2Repr::File(file) => {
ui.label(&format!("File {}", file));
TreeMessage::InterfaceAndValue(interface_struct, interface_data) => {
render_interface::render(ui, interface_struct, interface_data);
false
}
Tree2Repr::Folder(items) => {
TreeMessage::Folder(items) => {
let mut clear = false;
for item in items {
if ui.button(&format!("Item {}", item)).clicked() {
@@ -0,0 +1,64 @@
use egui::{Color32, TextEdit};
use unshell_lib::config::{InterfaceData, InterfaceStruct, config_struct};
pub fn render(
ui: &mut egui::Ui,
interface_struct: &InterfaceStruct,
interface_data: &mut InterfaceData,
) {
match (interface_struct, interface_data) {
(InterfaceStruct::ConfigStruct(interface), InterfaceData::ConfigStruct(data)) => {
render_config_struct(ui, interface, data);
}
}
}
fn render_config_struct(
ui: &mut egui::Ui,
interface: &config_struct::ConfigStructKeys,
data: &mut config_struct::ConfigStructValues,
) {
for (interface, data) in interface.iter().zip(data) {
match (interface, data) {
(config_struct::ConfigStructField::Header(text), serde_json::Value::Null) => {
ui.heading(text);
}
(config_struct::ConfigStructField::Text(text), serde_json::Value::Null) => {
ui.label(text);
}
(
config_struct::ConfigStructField::String {
default: _,
max_length,
protected,
},
serde_json::Value::String(value),
) => {
let mut widget = TextEdit::singleline(value);
if let Some(limit) = &max_length {
widget = widget.char_limit(*limit);
}
if let Some(protected) = &protected {
widget = widget.password(*protected);
}
ui.add(widget);
}
(
config_struct::ConfigStructField::Integer { default, min, max },
serde_json::Value::Number(number),
) => todo!(),
(interface, data) => {
ui.colored_label(
Color32::RED,
&format!("Incorrect type and value! {interface:?} and {data:?}"),
);
}
}
}
}
+2 -1
View File
@@ -192,7 +192,8 @@ impl LogViewer {
state_lock.requested_data = true;
// crate::log(&format!("{e:?}"));
});
})
.unwrap();
}
}
+18 -69
View File
@@ -37,26 +37,6 @@ version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
[[package]]
name = "bincode"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "36eaf5d7b090263e8150820482d5d93cd964a81e4019913c972f4edcc6edb740"
dependencies = [
"bincode_derive",
"serde",
"unty",
]
[[package]]
name = "bincode_derive"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf95709a440f45e986983918d0e8a1f30a9b1df04918fc828670606804ac3c09"
dependencies = [
"virtue",
]
[[package]]
name = "bitflags"
version = "1.3.2"
@@ -98,9 +78,9 @@ dependencies = [
[[package]]
name = "bumpalo"
version = "3.19.0"
version = "3.19.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43"
checksum = "5dd9dc738b7a8311c7ade152424974d8115f2cdad61e8dab8dac9f2362298510"
[[package]]
name = "cbc"
@@ -113,9 +93,9 @@ dependencies = [
[[package]]
name = "cc"
version = "1.2.45"
version = "1.2.50"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "35900b6c8d709fb1d854671ae27aeaa9eec2f8b01b364e1619a40da3e6fe2afe"
checksum = "9f50d563227a1c37cc0a263f64eca3334388c01c5e4c4861a9def205c614383c"
dependencies = [
"find-msvc-tools",
"shlex",
@@ -177,21 +157,6 @@ dependencies = [
"libc",
]
[[package]]
name = "crossbeam-channel"
version = "0.5.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "82b8f8f868b36967f9606790d1903570de9ceaf870a7bf9fbbd3016d636a2cb2"
dependencies = [
"crossbeam-utils",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28"
[[package]]
name = "crypto-common"
version = "0.1.6"
@@ -214,9 +179,9 @@ dependencies = [
[[package]]
name = "find-msvc-tools"
version = "0.1.4"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "52051878f80a721bb68ebfbc930e07b65ba72f2da88968ea5c06fd6ca3d3a127"
checksum = "3a3076410a55c90011c298b04d0cfa770b00fa04e1e3c97d3f6c9de105a03844"
[[package]]
name = "generic-array"
@@ -303,9 +268,9 @@ checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
[[package]]
name = "js-sys"
version = "0.3.82"
version = "0.3.83"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b011eec8cc36da2aab2d5cff675ec18454fad408585853910a202391cf9f8e65"
checksum = "464a3709c7f55f1f721e5389aa6ea4e3bc6aba669353300af094b29ffbdde1d8"
dependencies = [
"once_cell",
"wasm-bindgen",
@@ -328,9 +293,9 @@ dependencies = [
[[package]]
name = "log"
version = "0.4.28"
version = "0.4.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432"
checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897"
[[package]]
name = "memchr"
@@ -640,11 +605,7 @@ dependencies = [
name = "unshell-lib"
version = "0.0.0"
dependencies = [
"bincode",
"chrono",
"crossbeam-channel",
"libc",
"rand",
"serde",
"serde_json",
"unshell-obfuscate",
@@ -662,24 +623,12 @@ dependencies = [
"unshell-crypt",
]
[[package]]
name = "unty"
version = "0.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d49784317cd0d1ee7ec5c716dd598ec5b4483ea832a2dced265471cc0f690ae"
[[package]]
name = "version_check"
version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
[[package]]
name = "virtue"
version = "0.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "051eb1abcf10076295e815102942cc58f9d5e3b4560e46e53c21e8ff6f3af7b1"
[[package]]
name = "wasip2"
version = "1.0.1+wasi-0.2.4"
@@ -691,9 +640,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen"
version = "0.2.105"
version = "0.2.106"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da95793dfc411fbbd93f5be7715b0578ec61fe87cb1a42b12eb625caa5c5ea60"
checksum = "0d759f433fa64a2d763d1340820e46e111a7a5ab75f993d1852d70b03dbb80fd"
dependencies = [
"cfg-if",
"once_cell",
@@ -704,9 +653,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.105"
version = "0.2.106"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04264334509e04a7bf8690f2384ef5265f05143a4bff3889ab7a3269adab59c2"
checksum = "48cb0d2638f8baedbc542ed444afc0644a29166f1595371af4fecf8ce1e7eeb3"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
@@ -714,9 +663,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.105"
version = "0.2.106"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "420bc339d9f322e562942d52e115d57e950d12d88983a14c79b86859ee6c7ebc"
checksum = "cefb59d5cd5f92d9dcf80e4683949f15ca4b511f4ac0a6e14d4e1ac60c6ecd40"
dependencies = [
"bumpalo",
"proc-macro2",
@@ -727,9 +676,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.105"
version = "0.2.106"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76f218a38c84bcb33c25ec7059b07847d465ce0e0a76b995e134a45adcb6af76"
checksum = "cbc538057e648b67f72a982e708d485b2efa771e1ac05fec311f9f63e5800db4"
dependencies = [
"unicode-ident",
]
+4 -4
View File
@@ -17,13 +17,13 @@ obfuscate = ["unshell-obfuscate/obfuscate"]
[dependencies]
# Base dependencies
# libloading = {version = "0.8.9"}
bincode = "2.0.1"
# bincode = "2.0.1"
unshell-obfuscate = {path = "../unshell-obfuscate"}
chrono = "0.4.42"
serde = { version = "1.0.228", features = ["derive"] }
serde_json = "1.0.145"
libc = "0.2.177"
rand = "0.9.2"
crossbeam-channel = "0.5.15"
# libc = "0.2.177"
# rand = "0.9.2"
# crossbeam-channel = "0.5.15"
+15 -15
View File
@@ -1,7 +1,7 @@
use bincode::{Decode, Encode};
// use bincode::{Decode, Encode};
/// Mostly temporary server message type
#[derive(Clone, Debug, Encode, Decode)]
// #[derive(Clone, Debug, Encode, Decode)]
pub enum Announcement {
TestAnnouncement(String),
// GetRuntimes,
@@ -11,18 +11,18 @@ pub enum Announcement {
// StartRuntimeAck(bool),
}
const BINCODE_CONFIG: bincode::config::Configuration = bincode::config::standard();
// const BINCODE_CONFIG: bincode::config::Configuration = bincode::config::standard();
impl Announcement {
pub fn encode(&self) -> Vec<u8> {
bincode::encode_to_vec(self, BINCODE_CONFIG).unwrap()
}
// impl Announcement {
// pub fn encode(&self) -> Vec<u8> {
// bincode::encode_to_vec(self, BINCODE_CONFIG).unwrap()
// }
pub fn decode(bytes: &[u8]) -> Option<Self> {
if let Ok((decoded, _)) = bincode::decode_from_slice(&bytes[..], BINCODE_CONFIG) {
Some(decoded)
} else {
None
}
}
}
// pub fn decode(bytes: &[u8]) -> Option<Self> {
// if let Ok((decoded, _)) = bincode::decode_from_slice(&bytes[..], BINCODE_CONFIG) {
// Some(decoded)
// } else {
// None
// }
// }
// }
@@ -1,20 +1,15 @@
use std::collections::HashMap;
use serde::{Deserialize, Serialize};
use serde_json::Value;
#[derive(Clone, serde::Deserialize, serde::Serialize)]
pub enum Tree2Repr {
File(String),
Folder(Vec<String>),
pub type ConfigStructKeys = Vec<ConfigStructField>;
pub type ConfigStructValues = Vec<Value>;
pub struct Config {
keys: ConfigStructKeys,
values: ConfigStructValues,
}
// #[derive(Clone, serde::Deserialize, serde::Serialize)]
// pub struct InterfaceWrapper {
// pub name: String,
// pub interface: Interface,
// }
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
#[derive(Debug, Clone, Deserialize, Serialize)]
pub enum ConfigStructField {
Header(String),
Text(String),
+5
View File
@@ -1,3 +1,8 @@
pub mod config_struct;
mod tree;
pub use tree::{InterfaceData, InterfaceStruct, Tree, TreeMessage};
use std::collections::HashMap;
#[derive(Debug, Clone)]
+73
View File
@@ -0,0 +1,73 @@
use serde::{Deserialize, Serialize};
use serde_json::Value;
use crate::{ModuleError, Result, config::config_struct};
pub trait Tree {
fn is_folder() -> bool {
false
}
fn get_children_string(&self) -> Vec<String> {
unimplemented!();
}
fn select_child(&self, child: &str, _message: TreeMessage) -> Result<TreeMessage>;
fn get_value(&self, _message: TreeMessage) -> TreeMessage {
unimplemented!()
}
fn get_path(&self, elements: &mut Vec<&str>, message: TreeMessage) -> Result<TreeMessage> {
if elements.is_empty() {
return if Self::is_folder() {
Ok(TreeMessage::Folder(self.get_children_string()))
} else {
Ok(self.get_value(message))
};
}
let child = elements.remove(0);
if Self::is_folder() {
self.select_child(child, message)
} else {
Err(ModuleError::TreeMessageError(
"This is a folder, not a file".into(),
))
}
}
fn get(&self, path: &str, message: TreeMessage) -> Result<TreeMessage> {
let mut path = if path.is_empty() {
Vec::new()
} else {
path.split("/").collect::<Vec<&str>>()
};
self.get_path(&mut path, message)
}
}
#[derive(Clone, Serialize, Deserialize)]
pub enum TreeMessage {
RequestState,
RequestStruct,
RequestStructAndValue,
State(Value),
Interface(InterfaceStruct),
InterfaceAndValue(InterfaceStruct, InterfaceData),
Folder(Vec<String>),
}
#[derive(Clone, Serialize, Deserialize)]
pub enum InterfaceStruct {
ConfigStruct(config_struct::ConfigStructKeys),
}
#[derive(Clone, Serialize, Deserialize)]
pub enum InterfaceData {
ConfigStruct(config_struct::ConfigStructValues),
}
+32
View File
@@ -0,0 +1,32 @@
///Generic error type for module-related operations.
#[derive(Debug, serde::Serialize, serde::Deserialize)]
pub enum ModuleError {
LibLoadingError(String),
// LogError(log::SetLoggerError),
LinkError(String),
CryptError(String),
DatabaseError(String),
SerdeJsonError(String),
TreeMessageError(String),
Error(String),
}
impl From<&str> for ModuleError {
fn from(value: &str) -> Self {
Self::Error(value.into())
}
}
impl From<serde_json::Error> for ModuleError {
fn from(value: serde_json::Error) -> Self {
Self::SerdeJsonError(value.to_string())
}
}
impl From<Box<dyn std::error::Error>> for ModuleError {
fn from(value: Box<dyn std::error::Error>) -> Self {
ModuleError::Error(value.to_string())
}
}
+3 -10
View File
@@ -1,25 +1,18 @@
#![no_main]
pub mod config;
mod error;
pub mod logger;
mod announcement;
use std::fmt::{self, Debug};
pub use error::ModuleError;
pub use announcement::Announcement;
pub type Result<T> = std::result::Result<T, ModuleError>;
///Generic error type for module-related operations.
#[derive(Debug)]
pub enum ModuleError {
LibLoadingError(String),
// LogError(log::SetLoggerError),
LinkError(String),
CryptError(String),
Error(String),
}
impl std::error::Error for ModuleError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
None
-19
View File
@@ -177,21 +177,6 @@ dependencies = [
"libc",
]
[[package]]
name = "crossbeam-channel"
version = "0.5.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "82b8f8f868b36967f9606790d1903570de9ceaf870a7bf9fbbd3016d636a2cb2"
dependencies = [
"crossbeam-utils",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28"
[[package]]
name = "crypto-common"
version = "0.1.7"
@@ -650,11 +635,7 @@ dependencies = [
name = "unshell-lib"
version = "0.0.0"
dependencies = [
"bincode",
"chrono",
"crossbeam-channel",
"libc",
"rand",
"serde",
"serde_json",
"unshell-obfuscate",
+2 -2
View File
@@ -1,7 +1,7 @@
mod manager;
mod module;
mod module_interface;
pub mod network;
// pub mod network;
mod proc_load;
pub mod interface;
@@ -11,7 +11,7 @@ use std::sync::{Arc, Mutex};
pub use manager::Manager;
pub use module::Module;
pub use interface::{InterfaceWrapper, NamedComponent};
pub use interface::{InterfaceWrapper, NamedComponent, PayloadConfig};
extern crate unshell_lib;
use unshell_lib::Result;
+7 -7
View File
@@ -1,6 +1,6 @@
use unshell_lib::{Announcement, Result};
use crate::network::Stream;
// use crate::network::Stream;
use crate::Manager;
@@ -27,10 +27,10 @@ impl Manager {
}
}
pub fn broadcast(&mut self, announcement: Announcement) -> Result<()> {
for connection in &mut self.connections {
connection.write(announcement.clone())?;
}
Ok(())
}
// pub fn broadcast(&mut self, announcement: Announcement) -> Result<()> {
// for connection in &mut self.connections {
// connection.write(announcement.clone())?;
// }
// Ok(())
// }
}
+8 -10
View File
@@ -1,5 +1,5 @@
mod announcement;
mod connection;
// mod connection;
use std::{
collections::HashMap,
@@ -15,7 +15,7 @@ use crate::{
ModuleRuntime,
interface::{NamedComponent, PayloadConfig},
module::Module,
network::Stream,
// network::Stream,
};
// #[derive(Debug)]
@@ -28,8 +28,7 @@ pub struct Manager {
components: HashMap<String, NamedComponent>,
active_runtimes: Vec<Box<dyn ModuleRuntime>>,
pub connections: Vec<Box<dyn Stream<Announcement>>>,
// pub connections: Vec<Box<dyn Stream<Announcement>>>,
}
// static mut MANAGER_RUNTIME: Option<Arc<Mutex<Manager>>> = None;
@@ -46,8 +45,7 @@ impl Manager {
.map(|c| (c.name.to_string(), c))
.collect(),
active_runtimes: Vec::new(),
connections: Vec::new(),
// connections: Vec::new(),
}
}
@@ -130,11 +128,11 @@ impl Manager {
}
});
// Read announcements
this_lock.recv_connection_announcements();
// // Read announcements
// this_lock.recv_connection_announcements();
// Prune dead connections
this_lock.prune_connections();
// // Prune dead connections
// this_lock.prune_connections();
drop(this_lock)
}
+15 -16
View File
@@ -437,15 +437,6 @@ dependencies = [
"cfg-if",
]
[[package]]
name = "crossbeam-channel"
version = "0.5.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "82b8f8f868b36967f9606790d1903570de9ceaf870a7bf9fbbd3016d636a2cb2"
dependencies = [
"crossbeam-utils",
]
[[package]]
name = "crossbeam-epoch"
version = "0.9.18"
@@ -851,9 +842,9 @@ dependencies = [
[[package]]
name = "libc"
version = "0.2.177"
version = "0.2.178"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976"
checksum = "37c93d8daa9d8a012fd8ab92f088405fb202ea0b6ab73ee2482ae66af4f42091"
[[package]]
name = "libloading"
@@ -1602,14 +1593,21 @@ dependencies = [
name = "unshell-lib"
version = "0.0.0"
dependencies = [
"bincode",
"chrono",
"crossbeam-channel",
"serde",
"serde_json",
"unshell-obfuscate",
]
[[package]]
name = "unshell-manager"
version = "0.0.0"
dependencies = [
"bincode",
"libc",
"libloading",
"rand",
"serde",
"serde_json",
"unshell-lib",
"unshell-obfuscate",
]
@@ -1627,7 +1625,7 @@ dependencies = [
[[package]]
name = "unshell-server"
version = "0.1.0"
version = "0.0.0"
dependencies = [
"axum",
"axum-extra",
@@ -1642,6 +1640,7 @@ dependencies = [
"tokio",
"toml",
"unshell-lib",
"unshell-manager",
"unshell-obfuscate",
]
+6 -5
View File
@@ -1,15 +1,16 @@
[package]
name = "unshell-server"
version = "0.1.0"
# version = "0.1.0"
edition = "2024"
[features]
log_debug = ["unshell-lib/log_debug"]
default=["log_debug"]
log_debug = ["unshell-lib/log_debug", "unshell-manager/log_debug"]
[dependencies]
unshell-lib = {path = "../unshell-lib"}
unshell-obfuscate = {path = "../unshell-obfuscate"}
unshell-lib = {path = "../unshell-lib", default-featues = false}
unshell-obfuscate = {path = "../unshell-obfuscate", default-featues = false}
unshell-manager = {path = "../unshell-manager", default-featues = false}
axum = "0.8.7"
axum-extra = {version="0.12.2", features = ["typed-header"]}
+8 -5
View File
@@ -7,7 +7,7 @@ use std::{
path::{Path, PathBuf},
};
use unshell_lib::{debug, info};
use unshell_lib::{ModuleError, Result, debug, info};
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
struct ComponentMetadata {
@@ -66,15 +66,18 @@ pub struct ComponentState {
path: PathBuf,
}
pub fn load_config(path: &PathBuf) -> Result<Vec<ComponentState>, Box<dyn Error>> {
let path_absolute = fs::canonicalize(path.clone())?;
pub fn load_config(path: &PathBuf) -> Result<Vec<ComponentState>> {
let path_absolute =
fs::canonicalize(path.clone()).map_err(|e| ModuleError::Error(e.to_string()))?;
debug!("Loading data from path: `{:?}`", path_absolute);
// Read string as path
let config_str = fs::read_to_string(path.clone())?;
let config_str =
fs::read_to_string(path.clone()).map_err(|e| ModuleError::Error(e.to_string()))?;
// Load config from String
let config = toml::from_str::<ComponentMetadata>(&config_str)?;
let config = toml::from_str::<ComponentMetadata>(&config_str)
.map_err(|e| ModuleError::Error(e.to_string()))?;
info!("Loaded component `{}`", config.name);
+1 -2
View File
@@ -2,7 +2,6 @@ mod api;
mod auth;
mod config;
pub mod logger;
mod modules;
mod server;
pub use server::Server;
@@ -18,7 +17,7 @@ pub static DEFAULT_HOST: String = "localhost".to_string();
pub static DATABASE_NAME: String = "database".to_string();
#[static_init::dynamic]
pub static SERVER_CONFIG: unshell_lib::config::PayloadConfig = unshell_lib::config::PayloadConfig {
pub static SERVER_CONFIG: unshell_manager::PayloadConfig = unshell_manager::PayloadConfig {
id: "Server",
components: Vec::new(),
runtime_config: Vec::new(),
View File
+21 -11
View File
@@ -1,12 +1,16 @@
use std::{
error::Error,
collections::HashMap,
path::PathBuf,
sync::{Arc, Mutex},
};
use unshell_lib::module::Manager;
use crate::server::tree2::{Tree, Tree2Repr};
use serde_json::Value;
use unshell_lib::{
ModuleError,
config::{InterfaceData, Tree, TreeMessage, config_struct::ConfigStructField},
};
use unshell_lib::{Result, config::InterfaceStruct};
use unshell_manager::Manager;
mod blobs;
mod database;
@@ -22,7 +26,7 @@ pub struct Server {
}
impl Server {
pub fn new(config_paths: Vec<PathBuf>, database: String) -> Result<Self, Box<dyn Error>> {
pub fn new(config_paths: Vec<PathBuf>, database: String) -> Result<Self> {
let mut component_configs: Vec<crate::config::ComponentState> = Vec::new();
for config in &config_paths {
@@ -32,7 +36,7 @@ impl Server {
Ok(Self {
component_configs,
manager: Manager::start(&crate::SERVER_CONFIG, Vec::new()),
db: sled::open(database)?,
db: sled::open(database).map_err(|e| ModuleError::DatabaseError(e.to_string()))?,
// tree: Tree2::default(),
// interface: get_test_interface(),
})
@@ -48,12 +52,18 @@ impl Tree for Server {
vec!["connection_count".into()]
}
fn select_child(&self, child: &str) -> Result<Tree2Repr, String> {
fn select_child(&self, child: &str, _message: TreeMessage) -> Result<TreeMessage> {
match child {
"connection_count" => Ok(Tree2Repr::File(format!(
"Connection count: {}",
self.manager.lock().unwrap().connections.len()
))),
"connection_count" => {
let interface = vec![ConfigStructField::Header(format!("Test Heading!"))];
let value = vec![Value::Null];
Ok(TreeMessage::InterfaceAndValue(
InterfaceStruct::ConfigStruct(interface),
InterfaceData::ConfigStruct(value),
))
}
_ => Err("No such child".into()),
}
}
+16 -63
View File
@@ -2,63 +2,24 @@ use axum::{
Extension, Json,
extract::{Path, State},
};
use serde::{Deserialize, Serialize};
use serde_json::Value;
use unshell_lib::debug;
use unshell_lib::{
ModuleError,
config::{Tree, TreeMessage},
debug,
};
use crate::{Server, auth::structs::CurrentUser};
pub trait Tree {
fn is_folder() -> bool {
false
}
fn get_children_string(&self) -> Vec<String> {
Vec::new()
}
fn select_child(&self, child: &str) -> Result<Tree2Repr, String>;
fn get_value(&self) -> String {
"DEFAULT".into()
}
fn get_path(&self, elements: &mut Vec<&str>) -> Result<Tree2Repr, String> {
if elements.is_empty() {
return if Self::is_folder() {
Ok(Tree2Repr::Folder(self.get_children_string()))
} else {
Ok(Tree2Repr::File(self.get_value()))
};
}
let child = elements.remove(0);
if Self::is_folder() {
self.select_child(child)
} else {
Err("This is a folder, not a file".into())
}
}
fn get(&self, path: &str) -> Result<Tree2Repr, String> {
let mut path = if path.is_empty() {
Vec::new()
} else {
path.split("/").collect::<Vec<&str>>()
};
self.get_path(&mut path)
}
}
#[derive(Clone, Serialize, Deserialize)]
pub enum Tree2Repr {
File(String),
Folder(Vec<String>),
}
impl Server {
pub async fn get_tree2_root(
State(server): State<Server>,
Extension(extension): Extension<CurrentUser>,
) -> Json<Value> {
Self::get_tree2(State(server), Path("".into()), Extension(extension)).await
}
pub async fn get_tree2(
State(server): State<Server>,
Path(path): Path<String>,
@@ -66,18 +27,10 @@ impl Server {
) -> Json<Value> {
debug!("GET /api/interface/{}", path);
let result = (|| -> Result<_, String> {
let interface = server.get(&path)?;
Ok(interface)
})();
let result = server
.get(&path, TreeMessage::RequestStructAndValue)
.map_err(|e| ModuleError::CryptError(e.to_string()));
Json(serde_json::to_value(result).unwrap())
}
pub async fn get_tree2_root(
State(server): State<Server>,
Extension(extension): Extension<CurrentUser>,
) -> Json<Value> {
Self::get_tree2(State(server), Path("".into()), Extension(extension)).await
}
}