From b5dc8b440ca44e32f21b0e628da8ee28478ad840 Mon Sep 17 00:00:00 2001 From: mahesh bhatiya Date: Tue, 26 Aug 2025 21:48:36 +0530 Subject: [PATCH] Add CLI commands to list and remove eBPF programs - Implemented `list` command to display all eBPF programs in the database with clean, aligned table output showing ID, Title, Version, Status, and Path. - Added `remove` command to delete an eBPF program by ID: - Removes the program record from the database. - Deletes the corresponding binary file from the filesystem. - Provides warnings if file does not exist. - Supports --id flag for specifying program ID. --- Cargo.lock | 126 +++++-- bin/xdp_pass_kern.o | Bin 0 -> 720 bytes ebpf-demo/Cargo.lock | 332 ++---------------- ebpf-demo/Cargo.toml | 10 +- ebpf-demo/build-ebpf.sh | 39 -- ebpf-demo/ebpf/Cargo.toml | 11 - ebpf-demo/ebpf/src/lib.rs | 33 -- ebpf-demo/user/Cargo.toml | 4 +- ebpf-demo/user/src/main.rs | 36 +- ebpf-demo/{ => xdp_drop}/.cargo/config.toml | 2 +- ebpf-demo/xdp_drop/Cargo.toml | 12 + ebpf-demo/xdp_drop/src/lib.rs | 15 + ebpf-demo/xdp_drop/src/main.rs | 26 ++ ebpf-demo/xdp_pass_kern.c | 12 + ebpf-demo/xdp_pass_kern.o | Bin 0 -> 720 bytes eclipta-cli/Cargo.toml | 3 +- .../src/commands/{ => config}/config.rs | 0 .../src/commands/{ => config}/daemon.rs | 0 eclipta-cli/src/commands/config/mod.rs | 2 + .../src/commands/{ => ebpf}/inspect.rs | 0 eclipta-cli/src/commands/ebpf/list.rs | 35 ++ eclipta-cli/src/commands/{ => ebpf}/load.rs | 0 eclipta-cli/src/commands/ebpf/mod.rs | 6 + eclipta-cli/src/commands/ebpf/remove.rs | 28 ++ eclipta-cli/src/commands/{ => ebpf}/unload.rs | 0 eclipta-cli/src/commands/{ => ebpf}/upload.rs | 30 +- eclipta-cli/src/commands/mod.rs | 21 +- .../src/commands/{ => network}/alerts.rs | 0 eclipta-cli/src/commands/network/mod.rs | 2 + .../src/commands/{ => network}/ping_all.rs | 0 .../src/commands/{ => store}/check_db.rs | 0 eclipta-cli/src/commands/store/mod.rs | 1 + eclipta-cli/src/commands/{ => system}/logs.rs | 0 eclipta-cli/src/commands/system/mod.rs | 4 + .../src/commands/{ => system}/monitor.rs | 0 .../src/commands/{ => system}/status.rs | 0 .../src/commands/{ => system}/watch_cpu.rs | 0 eclipta-cli/src/db/programs.rs | 40 ++- eclipta-cli/src/main.rs | 97 +++-- eclipta-cli/src/utils/db.rs | 3 +- 40 files changed, 411 insertions(+), 519 deletions(-) create mode 100644 bin/xdp_pass_kern.o delete mode 100644 ebpf-demo/build-ebpf.sh delete mode 100644 ebpf-demo/ebpf/Cargo.toml delete mode 100644 ebpf-demo/ebpf/src/lib.rs rename ebpf-demo/{ => xdp_drop}/.cargo/config.toml (72%) create mode 100644 ebpf-demo/xdp_drop/Cargo.toml create mode 100644 ebpf-demo/xdp_drop/src/lib.rs create mode 100644 ebpf-demo/xdp_drop/src/main.rs create mode 100644 ebpf-demo/xdp_pass_kern.c create mode 100644 ebpf-demo/xdp_pass_kern.o rename eclipta-cli/src/commands/{ => config}/config.rs (100%) rename eclipta-cli/src/commands/{ => config}/daemon.rs (100%) create mode 100644 eclipta-cli/src/commands/config/mod.rs rename eclipta-cli/src/commands/{ => ebpf}/inspect.rs (100%) create mode 100644 eclipta-cli/src/commands/ebpf/list.rs rename eclipta-cli/src/commands/{ => ebpf}/load.rs (100%) create mode 100644 eclipta-cli/src/commands/ebpf/mod.rs create mode 100644 eclipta-cli/src/commands/ebpf/remove.rs rename eclipta-cli/src/commands/{ => ebpf}/unload.rs (100%) rename eclipta-cli/src/commands/{ => ebpf}/upload.rs (77%) rename eclipta-cli/src/commands/{ => network}/alerts.rs (100%) create mode 100644 eclipta-cli/src/commands/network/mod.rs rename eclipta-cli/src/commands/{ => network}/ping_all.rs (100%) rename eclipta-cli/src/commands/{ => store}/check_db.rs (100%) create mode 100644 eclipta-cli/src/commands/store/mod.rs rename eclipta-cli/src/commands/{ => system}/logs.rs (100%) create mode 100644 eclipta-cli/src/commands/system/mod.rs rename eclipta-cli/src/commands/{ => system}/monitor.rs (100%) rename eclipta-cli/src/commands/{ => system}/status.rs (100%) rename eclipta-cli/src/commands/{ => system}/watch_cpu.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 39b0782..d278911 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -128,22 +128,6 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" -[[package]] -name = "aya" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "758d57288601ecc9d149e3413a5f23d6b72c0373febc97044d4f4aa149033b5e" -dependencies = [ - "bitflags 1.3.2", - "bytes", - "lazy_static", - "libc", - "log", - "object 0.28.4", - "parking_lot", - "thiserror", -] - [[package]] name = "aya" version = "0.13.1" @@ -155,7 +139,7 @@ dependencies = [ "bytes", "libc", "log", - "object 0.36.7", + "object", "once_cell", "thiserror", ] @@ -169,7 +153,7 @@ dependencies = [ "core-error", "hashbrown 0.15.4", "log", - "object 0.36.7", + "object", "thiserror", ] @@ -183,7 +167,7 @@ dependencies = [ "cfg-if", "libc", "miniz_oxide", - "object 0.36.7", + "object", "rustc-demangle", "windows-targets 0.52.6", ] @@ -519,6 +503,27 @@ dependencies = [ "typenum", ] +[[package]] +name = "csv" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acdc4883a9c96732e4733212c01447ebd805833b7275a73ca3ee080fd77afdaf" +dependencies = [ + "csv-core", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "csv-core" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d02f3b0da4c6504f86e9cd789d8dbafab48c2321be74e9987593de5a894d93d" +dependencies = [ + "memchr", +] + [[package]] name = "der" version = "0.7.10" @@ -551,6 +556,16 @@ dependencies = [ "dirs-sys", ] +[[package]] +name = "dirs-next" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1" +dependencies = [ + "cfg-if", + "dirs-sys-next", +] + [[package]] name = "dirs-sys" version = "0.4.1" @@ -563,6 +578,17 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "dirs-sys-next" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + [[package]] name = "displaydoc" version = "0.2.5" @@ -585,7 +611,7 @@ name = "eclipta-cli" version = "1.0.0" dependencies = [ "anyhow", - "aya 0.13.1", + "aya", "byteorder", "bytes", "chrono", @@ -601,6 +627,7 @@ dependencies = [ "humantime", "log", "nix", + "prettytable", "serde", "serde_json", "sqlx", @@ -863,6 +890,12 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" +[[package]] +name = "hermit-abi" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c" + [[package]] name = "hex" version = "0.4.3" @@ -1060,6 +1093,17 @@ dependencies = [ "hashbrown 0.15.4", ] +[[package]] +name = "is-terminal" +version = "0.4.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e04d7f318608d35d4b61ddd75cbdaee86b023ebe2bd5a66ee0915f0bf93095a9" +dependencies = [ + "hermit-abi", + "libc", + "windows-sys 0.59.0", +] + [[package]] name = "is_terminal_polyfill" version = "1.70.1" @@ -1295,15 +1339,6 @@ dependencies = [ "libm", ] -[[package]] -name = "object" -version = "0.28.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e42c982f2d955fac81dd7e1d0e1426a7d702acd9c98d19ab01083a6a0328c424" -dependencies = [ - "memchr", -] - [[package]] name = "object" version = "0.36.7" @@ -1447,6 +1482,20 @@ dependencies = [ "zerocopy", ] +[[package]] +name = "prettytable" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46480520d1b77c9a3482d39939fcf96831537a250ec62d4fd8fbdf8e0302e781" +dependencies = [ + "csv", + "encode_unicode", + "is-terminal", + "lazy_static", + "term", + "unicode-width 0.1.14", +] + [[package]] name = "proc-macro2" version = "1.0.95" @@ -1835,6 +1884,7 @@ dependencies = [ "atoi", "byteorder", "bytes", + "chrono", "crc", "crossbeam-queue", "either", @@ -1917,6 +1967,7 @@ dependencies = [ "bitflags 2.9.1", "byteorder", "bytes", + "chrono", "crc", "digest", "dotenvy", @@ -1958,6 +2009,7 @@ dependencies = [ "base64", "bitflags 2.9.1", "byteorder", + "chrono", "crc", "dotenvy", "etcetera", @@ -1993,6 +2045,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b244ef0a8414da0bed4bb1910426e890b19e5e9bccc27ada6b797d05c55ae0aa" dependencies = [ "atoi", + "chrono", "flume", "futures-channel", "futures-core", @@ -2099,6 +2152,17 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "term" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c59df8ac95d96ff9bede18eb7300b0fda5e5d8d90960e76f8e14ae765eedbf1f" +dependencies = [ + "dirs-next", + "rustversion", + "winapi", +] + [[package]] name = "thiserror" version = "1.0.69" @@ -2356,10 +2420,6 @@ checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" [[package]] name = "user" version = "0.1.0" -dependencies = [ - "anyhow", - "aya 0.11.0", -] [[package]] name = "utf8_iter" diff --git a/bin/xdp_pass_kern.o b/bin/xdp_pass_kern.o new file mode 100644 index 0000000000000000000000000000000000000000..0a95580acb7b3e3af7bcc1725ba3aac160e682d8 GIT binary patch literal 720 zcmb<-^>JfjWMqH=MuzVU2p&w7fk6OC&;cy$z`zbvxgE%60^+G)F$MOxFvb=z_AW#Pkz*tPo40a2!UBh!3yVt#Msc(IiT@jTv&L(_@HpZrymxsF!dZT29#EU>PPoO08}2` zK6Lks0M#-3{Lcqc4Nxs$Y6p}9N-H1$^B=l?C!icm4Ok(Rh=9@wP#UBUqz>kO38**# Dw?8VZ literal 0 HcmV?d00001 diff --git a/ebpf-demo/Cargo.lock b/ebpf-demo/Cargo.lock index 786def3..227823c 100644 --- a/ebpf-demo/Cargo.lock +++ b/ebpf-demo/Cargo.lock @@ -2,38 +2,11 @@ # It is not intended for manual editing. version = 4 -[[package]] -name = "anyhow" -version = "1.0.98" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487" - -[[package]] -name = "autocfg" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" - -[[package]] -name = "aya" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "758d57288601ecc9d149e3413a5f23d6b72c0373febc97044d4f4aa149033b5e" -dependencies = [ - "bitflags 1.3.2", - "bytes", - "lazy_static", - "libc", - "log", - "object", - "parking_lot", - "thiserror", -] - [[package]] name = "aya-ebpf" version = "0.1.1" -source = "git+https://github.com/aya-rs/aya#fff92f8529e05f7e644f1df87fdab4d8e86de18a" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8dbaf5409a1a0982e5c9bdc0f499a55fe5ead39fe9c846012053faf0d404f73" dependencies = [ "aya-ebpf-bindings", "aya-ebpf-cty", @@ -44,7 +17,8 @@ dependencies = [ [[package]] name = "aya-ebpf-bindings" version = "0.1.1" -source = "git+https://github.com/aya-rs/aya#fff92f8529e05f7e644f1df87fdab4d8e86de18a" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "783dc1a82a3d71d83286165381dcc1b1d41643f4b110733d135547527c000a9a" dependencies = [ "aya-ebpf-cty", ] @@ -52,197 +26,53 @@ dependencies = [ [[package]] name = "aya-ebpf-cty" version = "0.2.2" -source = "git+https://github.com/aya-rs/aya#fff92f8529e05f7e644f1df87fdab4d8e86de18a" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2cce099aaf3abb89f9a1f8594ffe07fa53738ebc2882fac624d10d9ba31a1b10" [[package]] name = "aya-ebpf-macros" version = "0.1.1" -source = "git+https://github.com/aya-rs/aya#fff92f8529e05f7e644f1df87fdab4d8e86de18a" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72f47f7b4a75eb5f1d7ba0fb5628d247b1cf20388658899177875dabdda66865" dependencies = [ + "proc-macro-error", "proc-macro2", - "proc-macro2-diagnostics", "quote", "syn", ] [[package]] -name = "aya-log-common" -version = "0.1.15" -source = "git+https://github.com/aya-rs/aya#fff92f8529e05f7e644f1df87fdab4d8e86de18a" -dependencies = [ - "num_enum", -] - -[[package]] -name = "aya-log-ebpf" -version = "0.1.1" -source = "git+https://github.com/aya-rs/aya#fff92f8529e05f7e644f1df87fdab4d8e86de18a" -dependencies = [ - "aya-ebpf", - "aya-log-common", - "aya-log-ebpf-macros", -] - -[[package]] -name = "aya-log-ebpf-macros" -version = "0.1.0" -source = "git+https://github.com/aya-rs/aya#fff92f8529e05f7e644f1df87fdab4d8e86de18a" +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" dependencies = [ - "aya-log-common", - "aya-log-parser", + "proc-macro-error-attr", "proc-macro2", "quote", - "syn", -] - -[[package]] -name = "aya-log-parser" -version = "0.1.13" -source = "git+https://github.com/aya-rs/aya#fff92f8529e05f7e644f1df87fdab4d8e86de18a" -dependencies = [ - "aya-log-common", -] - -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "bitflags" -version = "2.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967" - -[[package]] -name = "bytes" -version = "1.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" - -[[package]] -name = "cfg-if" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268" - -[[package]] -name = "ebpf" -version = "0.1.0" -dependencies = [ - "aya-ebpf", - "aya-log-ebpf", -] - -[[package]] -name = "lazy_static" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" - -[[package]] -name = "libc" -version = "0.2.174" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" - -[[package]] -name = "lock_api" -version = "0.4.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96936507f153605bddfcda068dd804796c84324ed2510809e5b2a624c81da765" -dependencies = [ - "autocfg", - "scopeguard", -] - -[[package]] -name = "log" -version = "0.4.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" - -[[package]] -name = "memchr" -version = "2.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0" - -[[package]] -name = "num_enum" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a973b4e44ce6cad84ce69d797acf9a044532e4184c4f267913d1b546a0727b7a" -dependencies = [ - "num_enum_derive", - "rustversion", + "version_check", ] [[package]] -name = "num_enum_derive" -version = "0.7.4" +name = "proc-macro-error-attr" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" dependencies = [ "proc-macro2", "quote", - "syn", -] - -[[package]] -name = "object" -version = "0.28.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e42c982f2d955fac81dd7e1d0e1426a7d702acd9c98d19ab01083a6a0328c424" -dependencies = [ - "memchr", -] - -[[package]] -name = "parking_lot" -version = "0.12.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70d58bf43669b5795d1576d0641cfb6fbb2057bf629506267a92807158584a13" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc838d2a56b5b1a6c25f55575dfc605fabb63bb2365f6c2353ef9159aa69e4a5" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets", + "version_check", ] [[package]] name = "proc-macro2" -version = "1.0.95" +version = "1.0.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" +checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de" dependencies = [ "unicode-ident", ] -[[package]] -name = "proc-macro2-diagnostics" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af066a9c399a26e020ada66a034357a868728e72cd426f3adcd35f80d88d88c8" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "version_check", -] - [[package]] name = "quote" version = "1.0.40" @@ -252,15 +82,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "redox_syscall" -version = "0.5.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5407465600fb0548f1442edf71dd20683c6ed326200ace4b1ef0763521bb3b77" -dependencies = [ - "bitflags 2.9.1", -] - [[package]] name = "rustversion" version = "1.0.22" @@ -268,46 +89,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" [[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "smallvec" -version = "1.15.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" - -[[package]] -name = "syn" -version = "2.0.104" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17b6f705963418cdb9927482fa304bc562ece2fdd4f616084c50b7023b435a40" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "thiserror" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" +name = "simple-ebpf" +version = "0.1.0" dependencies = [ - "thiserror-impl", + "aya-ebpf", ] [[package]] -name = "thiserror-impl" -version = "1.0.69" +name = "syn" +version = "2.0.106" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" +checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6" dependencies = [ "proc-macro2", "quote", - "syn", + "unicode-ident", ] [[package]] @@ -316,80 +112,8 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" -[[package]] -name = "user" -version = "0.1.0" -dependencies = [ - "anyhow", - "aya", -] - [[package]] name = "version_check" version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" - -[[package]] -name = "windows-targets" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" -dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" diff --git a/ebpf-demo/Cargo.toml b/ebpf-demo/Cargo.toml index a9f680b..82e0bfb 100644 --- a/ebpf-demo/Cargo.toml +++ b/ebpf-demo/Cargo.toml @@ -1,9 +1,5 @@ [workspace] -members = ["ebpf", "user"] +members = ["user", + "xdp_drop" +] resolver = "2" - -[profile.release] -strip = true -opt-level = "z" -lto = true -codegen-units = 1 diff --git a/ebpf-demo/build-ebpf.sh b/ebpf-demo/build-ebpf.sh deleted file mode 100644 index cf99a7c..0000000 --- a/ebpf-demo/build-ebpf.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -ROOT_DIR="/eclipta" -BIN_DIR="$ROOT_DIR/bin" -PROJ_DIR="$ROOT_DIR/ebpf-demo" - -cd "$PROJ_DIR" - -rustup toolchain install nightly --profile minimal || true -rustup target add bpfel-unknown-none --toolchain nightly || true - -if ! command -v bpf-linker >/dev/null 2>&1; then - cargo +nightly install bpf-linker --locked -fi - -cargo +nightly build -Z build-std=core --target bpfel-unknown-none -p ebpf --release - -OUT_DIR="$PROJ_DIR/target/bpfel-unknown-none/release" -OBJ="" - -if [[ -f "$OUT_DIR/libebpf.so" ]]; then - OBJ="$OUT_DIR/libebpf.so" -else - # Fallback to the newest non-bitcode .o in release (exclude deps/*.o which are bitcode) - CANDIDATE=$(find "$OUT_DIR" -maxdepth 1 -type f -name "*.o" -printf "%T@ %p\n" | sort -nr | head -n1 | awk '{print $2}') - if [[ -n "${CANDIDATE:-}" ]] && file "$CANDIDATE" | grep -q "ELF"; then - OBJ="$CANDIDATE" - fi -fi - -if [[ -z "${OBJ:-}" ]]; then - echo "No ELF eBPF object found under $OUT_DIR" >&2 - exit 1 -fi - -mkdir -p "$BIN_DIR" -cp -f "$OBJ" "$BIN_DIR/ebpf.so" -echo "Built and moved: $BIN_DIR/ebpf.so" \ No newline at end of file diff --git a/ebpf-demo/ebpf/Cargo.toml b/ebpf-demo/ebpf/Cargo.toml deleted file mode 100644 index 97cc9ca..0000000 --- a/ebpf-demo/ebpf/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "ebpf" -version = "0.1.0" -edition = "2021" - -[lib] -crate-type = ["cdylib"] - -[dependencies] -aya-ebpf = { git = "https://github.com/aya-rs/aya", package = "aya-ebpf" } -aya-log-ebpf = { git = "https://github.com/aya-rs/aya", package = "aya-log-ebpf" } diff --git a/ebpf-demo/ebpf/src/lib.rs b/ebpf-demo/ebpf/src/lib.rs deleted file mode 100644 index 16b4111..0000000 --- a/ebpf-demo/ebpf/src/lib.rs +++ /dev/null @@ -1,33 +0,0 @@ -#![no_std] -#![no_main] - -use aya_ebpf::{ - helpers::bpf_get_smp_processor_id, - macros::{map, tracepoint}, - maps::HashMap, - programs::TracePointContext, -}; - -#[map(name = "CPU_STATS")] -static mut CPU_STATS: HashMap = HashMap::::with_max_entries(256, 0); - -#[tracepoint(name = "cpu_usage", category = "sched")] -pub fn cpu_usage(_ctx: TracePointContext) -> u32 { - let cpu_id = unsafe { bpf_get_smp_processor_id() } as u32; - - unsafe { - let current = match CPU_STATS.get(&cpu_id) { - Some(v) => *v, - None => 0, - }; - let new_val = current.wrapping_add(1); - let _ = CPU_STATS.insert(&cpu_id, &new_val, 0); - } - - 0 -} - -#[panic_handler] -fn panic(_info: &core::panic::PanicInfo) -> ! { - loop {} -} diff --git a/ebpf-demo/user/Cargo.toml b/ebpf-demo/user/Cargo.toml index 8ae0ce6..68f345f 100644 --- a/ebpf-demo/user/Cargo.toml +++ b/ebpf-demo/user/Cargo.toml @@ -1,8 +1,6 @@ [package] name = "user" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] -aya = "0.11" -anyhow = "1" diff --git a/ebpf-demo/user/src/main.rs b/ebpf-demo/user/src/main.rs index b767cb5..e7a11a9 100644 --- a/ebpf-demo/user/src/main.rs +++ b/ebpf-demo/user/src/main.rs @@ -1,35 +1,3 @@ -use aya::{Bpf, programs::TracePoint}; -use aya::maps::HashMap; -use std::time::Duration; -use tokio::time; - -#[tokio::main] -async fn main() -> Result<(), anyhow::Error> { - // Load the compiled eBPF object - let mut bpf = Bpf::load_file( - "target/bpfel-unknown-none/release/deps/ebpf.o" - )?; - - // Attach to the sched:sched_switch tracepoint - let program: &mut TracePoint = bpf.program_mut("cpu_usage") - .unwrap() - .try_into()?; - program.load()?; - program.attach("sched", "sched_switch")?; - - // Get the eBPF map for CPU stats - let mut cpu_stats: HashMap<_, u32, u64> = HashMap::try_from( - bpf.map_mut("CPU_STATS")? - )?; - - println!("Tracking per-CPU usage in real time (Ctrl+C to exit)"); - loop { - println!("---------------------------"); - for cpu_id in 0..num_cpus::get() as u32 { - if let Ok(val) = cpu_stats.get(&cpu_id, 0) { - println!("CPU {}: {} ns active", cpu_id, val); - } - } - time::sleep(Duration::from_secs(1)).await; - } +fn main() { + println!("Hello, world!"); } diff --git a/ebpf-demo/.cargo/config.toml b/ebpf-demo/xdp_drop/.cargo/config.toml similarity index 72% rename from ebpf-demo/.cargo/config.toml rename to ebpf-demo/xdp_drop/.cargo/config.toml index cc9374d..c3ccdee 100644 --- a/ebpf-demo/.cargo/config.toml +++ b/ebpf-demo/xdp_drop/.cargo/config.toml @@ -2,4 +2,4 @@ target-dir = "target" [target.bpfel-unknown-none] -linker = "bpf-linker" \ No newline at end of file +linker = "bpf-linker" \ No newline at end of file diff --git a/ebpf-demo/xdp_drop/Cargo.toml b/ebpf-demo/xdp_drop/Cargo.toml new file mode 100644 index 0000000..45e47da --- /dev/null +++ b/ebpf-demo/xdp_drop/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "simple-ebpf" +version = "0.1.0" +edition = "2021" + +[dependencies] +aya-ebpf = "0.1" + +[lib] +name = "simple_ebpf" +path = "src/lib.rs" +crate-type = ["cdylib"] diff --git a/ebpf-demo/xdp_drop/src/lib.rs b/ebpf-demo/xdp_drop/src/lib.rs new file mode 100644 index 0000000..f91c453 --- /dev/null +++ b/ebpf-demo/xdp_drop/src/lib.rs @@ -0,0 +1,15 @@ +#![no_std] +#![no_main] + +use aya_ebpf::{macros::xdp, programs::XdpContext}; +use aya_ebpf::bindings::xdp_action; + +#[xdp(name = "xdp_drop")] +pub fn xdp_drop(_ctx: XdpContext) -> u32 { + xdp_action::XDP_DROP +} + +#[panic_handler] +fn panic(_info: &core::panic::PanicInfo) -> ! { + loop {} +} diff --git a/ebpf-demo/xdp_drop/src/main.rs b/ebpf-demo/xdp_drop/src/main.rs new file mode 100644 index 0000000..fb47aa8 --- /dev/null +++ b/ebpf-demo/xdp_drop/src/main.rs @@ -0,0 +1,26 @@ +#![no_std] +#![no_main] + +use aya_ebpf::{ + bindings::xdp_action, + macros::xdp, + programs::XdpContext, +}; + +#[xdp] +pub fn simple_ebpf_program(ctx: XdpContext) -> u32 { + match try_simple_ebpf_program(ctx) { + Ok(ret) => ret, + Err(_) => xdp_action::XDP_ABORTED, + } +} + +fn try_simple_ebpf_program(_ctx: XdpContext) -> Result { + // Simple success - no logging to avoid macro issues + Ok(xdp_action::XDP_PASS) // Return 2 (XDP_PASS - allows packet through) +} + +#[panic_handler] +fn panic(_info: &core::panic::PanicInfo) -> ! { + unsafe { core::hint::unreachable_unchecked() } +} \ No newline at end of file diff --git a/ebpf-demo/xdp_pass_kern.c b/ebpf-demo/xdp_pass_kern.c new file mode 100644 index 0000000..6446b16 --- /dev/null +++ b/ebpf-demo/xdp_pass_kern.c @@ -0,0 +1,12 @@ +// xdp_pass_kern.c +#include +#include + +// XDP program: just passes all packets without dropping +SEC("xdp") +int xdp_pass(struct xdp_md *ctx) { + return XDP_PASS; // let packets continue +} + +// Required license declaration +char LICENSE[] SEC("license") = "GPL"; diff --git a/ebpf-demo/xdp_pass_kern.o b/ebpf-demo/xdp_pass_kern.o new file mode 100644 index 0000000000000000000000000000000000000000..0a95580acb7b3e3af7bcc1725ba3aac160e682d8 GIT binary patch literal 720 zcmb<-^>JfjWMqH=MuzVU2p&w7fk6OC&;cy$z`zbvxgE%60^+G)F$MOxFvb=z_AW#Pkz*tPo40a2!UBh!3yVt#Msc(IiT@jTv&L(_@HpZrymxsF!dZT29#EU>PPoO08}2` zK6Lks0M#-3{Lcqc4Nxs$Y6p}9N-H1$^B=l?C!icm4Ok(Rh=9@wP#UBUqz>kO38**# Dw?8VZ literal 0 HcmV?d00001 diff --git a/eclipta-cli/Cargo.toml b/eclipta-cli/Cargo.toml index ee16ebe..7e8ed11 100644 --- a/eclipta-cli/Cargo.toml +++ b/eclipta-cli/Cargo.toml @@ -26,7 +26,8 @@ hostname = "0.4.1" humantime = "2.1" dirs = "5.0" # sqlx = { version = "0.8", features = ["postgres", "runtime-tokio-rustls", "macros"] } -sqlx = { version = "0.7.4", features = ["postgres", "runtime-tokio-rustls"] } +sqlx = { version = "0.7.4", features = ["postgres", "runtime-tokio-rustls", "chrono"] } dotenvy = "0.15" uuid = { version = "1.8", features = ["v4"] } colored = "2.1" +prettytable = "0.10.0" \ No newline at end of file diff --git a/eclipta-cli/src/commands/config.rs b/eclipta-cli/src/commands/config/config.rs similarity index 100% rename from eclipta-cli/src/commands/config.rs rename to eclipta-cli/src/commands/config/config.rs diff --git a/eclipta-cli/src/commands/daemon.rs b/eclipta-cli/src/commands/config/daemon.rs similarity index 100% rename from eclipta-cli/src/commands/daemon.rs rename to eclipta-cli/src/commands/config/daemon.rs diff --git a/eclipta-cli/src/commands/config/mod.rs b/eclipta-cli/src/commands/config/mod.rs new file mode 100644 index 0000000..1220fbb --- /dev/null +++ b/eclipta-cli/src/commands/config/mod.rs @@ -0,0 +1,2 @@ +pub mod config; +pub mod daemon; diff --git a/eclipta-cli/src/commands/inspect.rs b/eclipta-cli/src/commands/ebpf/inspect.rs similarity index 100% rename from eclipta-cli/src/commands/inspect.rs rename to eclipta-cli/src/commands/ebpf/inspect.rs diff --git a/eclipta-cli/src/commands/ebpf/list.rs b/eclipta-cli/src/commands/ebpf/list.rs new file mode 100644 index 0000000..b3e9bbb --- /dev/null +++ b/eclipta-cli/src/commands/ebpf/list.rs @@ -0,0 +1,35 @@ +use prettytable::{Table, Row, Cell, format}; +use crate::utils::db::init_db; +use crate::utils::logger::info; +use crate::db::programs::list_programs; +use prettytable::row; + + +pub async fn handle_list() -> Result<(), Box> { + let pool = init_db().await?; + let programs = list_programs(&pool).await?; + + if programs.is_empty() { + info("No programs found in database."); + return Ok(()); + } + + let mut table = Table::new(); + table.set_format(*format::consts::FORMAT_NO_LINESEP_WITH_TITLE); + + // Header + table.set_titles(row!["ID", "Title", "Version", "Status", "Path"]); + + for p in programs { + table.add_row(Row::new(vec![ + Cell::new(&p.id.to_string()), + Cell::new(&p.title), + Cell::new(&p.version), + Cell::new(&p.status), + Cell::new(&p.path), + ])); + } + + table.printstd(); + Ok(()) +} diff --git a/eclipta-cli/src/commands/load.rs b/eclipta-cli/src/commands/ebpf/load.rs similarity index 100% rename from eclipta-cli/src/commands/load.rs rename to eclipta-cli/src/commands/ebpf/load.rs diff --git a/eclipta-cli/src/commands/ebpf/mod.rs b/eclipta-cli/src/commands/ebpf/mod.rs new file mode 100644 index 0000000..e0baafa --- /dev/null +++ b/eclipta-cli/src/commands/ebpf/mod.rs @@ -0,0 +1,6 @@ +pub mod list; +pub mod load; +pub mod unload; +pub mod upload; +pub mod inspect; +pub mod remove; \ No newline at end of file diff --git a/eclipta-cli/src/commands/ebpf/remove.rs b/eclipta-cli/src/commands/ebpf/remove.rs new file mode 100644 index 0000000..67ca210 --- /dev/null +++ b/eclipta-cli/src/commands/ebpf/remove.rs @@ -0,0 +1,28 @@ +use crate::utils::db::init_db; +use crate::db::programs::delete_program; +use std::fs; +use clap::Parser; + +#[derive(Parser)] +pub struct RemoveOptions { + pub id: i32, +} + +pub async fn handle_remove(opts: RemoveOptions) -> Result<(), Box> { + let pool = init_db().await?; + let program = sqlx::query!( + "SELECT path, title FROM ebpf_programs WHERE id = $1", + opts.id + ) + .fetch_one(&pool) + .await?; + if fs::remove_file(&program.path).is_ok() { + println!("[OK] Deleted file: {}", &program.path); + } else { + println!("[WARN] File not found or cannot delete: {}", &program.path); + } + delete_program(&pool, opts.id).await?; + println!("[OK] Removed program '{}' (ID: {}) from database.", program.title, opts.id); + + Ok(()) +} diff --git a/eclipta-cli/src/commands/unload.rs b/eclipta-cli/src/commands/ebpf/unload.rs similarity index 100% rename from eclipta-cli/src/commands/unload.rs rename to eclipta-cli/src/commands/ebpf/unload.rs diff --git a/eclipta-cli/src/commands/upload.rs b/eclipta-cli/src/commands/ebpf/upload.rs similarity index 77% rename from eclipta-cli/src/commands/upload.rs rename to eclipta-cli/src/commands/ebpf/upload.rs index 1bc6bb5..418bda1 100644 --- a/eclipta-cli/src/commands/upload.rs +++ b/eclipta-cli/src/commands/ebpf/upload.rs @@ -80,17 +80,27 @@ pub async fn handle_upload(opts: UploadOptions) -> Result<(), Box success("Upload complete! Metadata stored in database."), - Err(e) => error(&format!("Database insert failed: {}", e)), + &pool, + &opts.title, + &opts.description, + &opts.version, + &dest_path.to_string_lossy(), +).await { + Ok(_) => success("Upload complete! Metadata stored in database."), + Err(sqlx::Error::Database(db_err)) => { + if db_err.constraint() == Some("unique_title_version") { + error("A program with this title and version already exists."); + return Ok(()); // or Err if you want non-zero exit + } else { + error(&format!("Database insert failed: {}", db_err)); + return Ok(()); + } } + Err(e) => { + error(&format!("Database insert failed: {}", e)); + return Ok(()); + } +} Ok(()) } diff --git a/eclipta-cli/src/commands/mod.rs b/eclipta-cli/src/commands/mod.rs index ff4d73e..483c21a 100644 --- a/eclipta-cli/src/commands/mod.rs +++ b/eclipta-cli/src/commands/mod.rs @@ -1,16 +1,9 @@ -pub mod welcome; -pub mod status; -pub mod load; -pub mod logs; -pub mod unload; -pub mod inspect; -pub mod daemon; -pub mod monitor; -pub mod ping_all; -pub mod watch_cpu; +pub mod system; +pub mod ebpf; +pub mod network; pub mod config; -pub mod alerts; -pub mod version; + pub mod run; -pub mod check_db; -pub mod upload; +pub mod version; +pub mod welcome; +pub mod store; diff --git a/eclipta-cli/src/commands/alerts.rs b/eclipta-cli/src/commands/network/alerts.rs similarity index 100% rename from eclipta-cli/src/commands/alerts.rs rename to eclipta-cli/src/commands/network/alerts.rs diff --git a/eclipta-cli/src/commands/network/mod.rs b/eclipta-cli/src/commands/network/mod.rs new file mode 100644 index 0000000..caf412b --- /dev/null +++ b/eclipta-cli/src/commands/network/mod.rs @@ -0,0 +1,2 @@ +pub mod ping_all; +pub mod alerts; diff --git a/eclipta-cli/src/commands/ping_all.rs b/eclipta-cli/src/commands/network/ping_all.rs similarity index 100% rename from eclipta-cli/src/commands/ping_all.rs rename to eclipta-cli/src/commands/network/ping_all.rs diff --git a/eclipta-cli/src/commands/check_db.rs b/eclipta-cli/src/commands/store/check_db.rs similarity index 100% rename from eclipta-cli/src/commands/check_db.rs rename to eclipta-cli/src/commands/store/check_db.rs diff --git a/eclipta-cli/src/commands/store/mod.rs b/eclipta-cli/src/commands/store/mod.rs new file mode 100644 index 0000000..96885e3 --- /dev/null +++ b/eclipta-cli/src/commands/store/mod.rs @@ -0,0 +1 @@ +pub mod check_db; diff --git a/eclipta-cli/src/commands/logs.rs b/eclipta-cli/src/commands/system/logs.rs similarity index 100% rename from eclipta-cli/src/commands/logs.rs rename to eclipta-cli/src/commands/system/logs.rs diff --git a/eclipta-cli/src/commands/system/mod.rs b/eclipta-cli/src/commands/system/mod.rs new file mode 100644 index 0000000..242a48b --- /dev/null +++ b/eclipta-cli/src/commands/system/mod.rs @@ -0,0 +1,4 @@ +pub mod monitor; +pub mod status; +pub mod watch_cpu; +pub mod logs; \ No newline at end of file diff --git a/eclipta-cli/src/commands/monitor.rs b/eclipta-cli/src/commands/system/monitor.rs similarity index 100% rename from eclipta-cli/src/commands/monitor.rs rename to eclipta-cli/src/commands/system/monitor.rs diff --git a/eclipta-cli/src/commands/status.rs b/eclipta-cli/src/commands/system/status.rs similarity index 100% rename from eclipta-cli/src/commands/status.rs rename to eclipta-cli/src/commands/system/status.rs diff --git a/eclipta-cli/src/commands/watch_cpu.rs b/eclipta-cli/src/commands/system/watch_cpu.rs similarity index 100% rename from eclipta-cli/src/commands/watch_cpu.rs rename to eclipta-cli/src/commands/system/watch_cpu.rs diff --git a/eclipta-cli/src/db/programs.rs b/eclipta-cli/src/db/programs.rs index be3b04e..5c09c42 100644 --- a/eclipta-cli/src/db/programs.rs +++ b/eclipta-cli/src/db/programs.rs @@ -1,6 +1,13 @@ - use sqlx::{Pool, Postgres}; +#[derive(Debug)] +pub struct Program { + pub id: i32, + pub title: String, + pub version: String, + pub status: String, + pub path: String, +} pub async fn insert_program( pool: &Pool, @@ -22,5 +29,36 @@ pub async fn insert_program( .execute(pool) .await?; + Ok(()) +} + +pub async fn list_programs(pool: &Pool) -> Result, sqlx::Error> { + let rows = sqlx::query_as!( + Program, + r#" + SELECT + id, + title, + version, + status, + path + FROM ebpf_programs + ORDER BY created_at DESC + "# + ) + .fetch_all(pool) + .await?; + + Ok(rows) +} + +pub async fn delete_program(pool: &Pool, program_id: i32) -> Result<(), sqlx::Error> { + sqlx::query!( + "DELETE FROM ebpf_programs WHERE id = $1", + program_id + ) + .execute(pool) + .await?; + Ok(()) } \ No newline at end of file diff --git a/eclipta-cli/src/main.rs b/eclipta-cli/src/main.rs index 1d69f59..2039829 100644 --- a/eclipta-cli/src/main.rs +++ b/eclipta-cli/src/main.rs @@ -2,29 +2,51 @@ mod commands; mod utils; mod db; -use crate::commands::logs::LogOptions; use clap::{Parser, Subcommand}; -use commands::alerts::handle_alerts; -use commands::check_db::{handle_check_db, CheckDbOptions}; -use commands::config::{handle_config, ConfigOptions}; -use commands::daemon::handle_daemon; -use commands::inspect::{handle_inspect, InspectOptions}; -use commands::monitor::handle_monitor; -use commands::ping_all; -use commands::upload::{handle_upload, UploadOptions}; -use commands::version::{handle_version, VersionOptions}; -use commands::watch_cpu::{handle_watch_cpu, WatchCpuOptions}; -use commands::{ - load::handle_load, - logs::handle_logs, + +// SYSTEM COMMANDS +use crate::commands::system::{ + logs::{handle_logs, LogOptions}, + monitor::handle_monitor, status::run_status, + watch_cpu::{handle_watch_cpu, WatchCpuOptions}, +}; + +// EBPf PROGRAM COMMANDS +use crate::commands::ebpf::{ + inspect::{handle_inspect, InspectOptions}, + load::handle_load, unload::{handle_unload, UnloadOptions}, + upload::{handle_upload, UploadOptions}, + list::handle_list, + remove::{handle_remove, RemoveOptions}, +}; + +// NETWORK COMMANDS +use crate::commands::network::{ + alerts::handle_alerts, + ping_all::handle_ping_all, +}; + +// CONFIG COMMANDS +use crate::commands::config::{ + config::{handle_config, ConfigOptions}, + daemon::handle_daemon, +}; + +// STORE / DB COMMANDS +use crate::commands::store::check_db::{handle_check_db, CheckDbOptions}; + +// OTHER GLOBAL COMMANDS +use crate::commands::{ + run::{handle_run, RunOptions}, + version::{handle_version, VersionOptions}, welcome::run_welcome, }; #[derive(Parser)] #[command(name = "eclipta")] -#[command(about = "eclipta CLI - self-hosted observability platform")] +#[command(about = "Eclipta CLI - self-hosted observability platform")] struct Cli { #[command(subcommand)] command: Commands, @@ -34,7 +56,7 @@ struct Cli { enum Commands { Welcome, Status, - Load(commands::load::LoadOptions), + Load(commands::ebpf::load::LoadOptions), Logs(LogOptions), Unload(UnloadOptions), Inspect(InspectOptions), @@ -45,16 +67,24 @@ enum Commands { Config(ConfigOptions), Alerts, Version(VersionOptions), - Run(commands::run::RunOptions), + Run(RunOptions), CheckDb(CheckDbOptions), Upload(UploadOptions), + List, + Remove(RemoveOptions), } #[tokio::main] async fn main() { let cli = Cli::parse(); + if let Err(e) = handle_command(cli.command).await { + eprintln!("[ERROR] {}", e); + std::process::exit(1); + } +} - match cli.command { +async fn handle_command(cmd: Commands) -> Result<(), Box> { + match cmd { Commands::Welcome => run_welcome(), Commands::Status => run_status(), Commands::Load(opts) => handle_load(opts), @@ -62,18 +92,31 @@ async fn main() { Commands::Inspect(opts) => handle_inspect(opts), Commands::Logs(opts) => handle_logs(opts).await, Commands::Daemon => handle_daemon().await, - Commands::Monitor => handle_monitor().await.unwrap(), - Commands::PingAll => ping_all::handle_ping_all().await, - Commands::WatchCpu(opts) => handle_watch_cpu(opts).await.unwrap(), - Commands::Config(opts) => handle_config(opts).await.unwrap(), - Commands::Alerts => handle_alerts().await.unwrap(), - Commands::Version(opts) => handle_version(opts).await.unwrap(), - Commands::Run(opts) => commands::run::handle_run(opts).await, - Commands::CheckDb(opts) => handle_check_db(opts).await.unwrap(), + Commands::Monitor => handle_monitor().await?, + Commands::PingAll => handle_ping_all().await, + Commands::WatchCpu(opts) => handle_watch_cpu(opts).await?, + Commands::Config(opts) => handle_config(opts).await?, + Commands::Alerts => handle_alerts().await?, + Commands::Version(opts) => handle_version(opts).await?, + Commands::Run(opts) => handle_run(opts).await, + Commands::CheckDb(opts) => handle_check_db(opts).await?, Commands::Upload(opts) => { if let Err(e) = handle_upload(opts).await { - eprintln!("Upload failed: {}", e); + eprintln!("[UPLOAD ERROR] {}", e); + } + } + Commands::List => { + if let Err(e) = handle_list().await { + eprintln!("[LIST ERROR] {}", e); } } + Commands::Remove(opts) => { + if let Err(e) = handle_remove(opts).await { + eprintln!("[REMOVE ERROR] {}", e); } } + + } + + Ok(()) +} diff --git a/eclipta-cli/src/utils/db.rs b/eclipta-cli/src/utils/db.rs index eed1f03..34cbdac 100644 --- a/eclipta-cli/src/utils/db.rs +++ b/eclipta-cli/src/utils/db.rs @@ -27,7 +27,8 @@ async fn run_migrations(pool: &Pool) -> Result<(), sqlx::Error> { version TEXT NOT NULL, status TEXT NOT NULL DEFAULT 'deactive', path TEXT NOT NULL, - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + CONSTRAINT unique_title_version UNIQUE (title, version) ) "# )