From 3428a637ce420baef9aa9f9803e71bd587867005 Mon Sep 17 00:00:00 2001 From: FxQnLr Date: Wed, 10 Apr 2024 00:16:55 +0200 Subject: Closes #24. Changed postgres to json directory storage --- .github/workflows/pull_request.yml | 1 - .github/workflows/push.yml | 1 - .gitignore | 1 + ...f32262fd643b452aacca373ee527c978e816115de6.json | 49 -- ...ce1174021ce0fb896a818a6deee291a1eb85ae2a8a.json | 15 - ...ce2248cb3a734074014a493a7aad6fa03bb1286dc8.json | 49 -- ...c09e37b14c828c4ee44b696d83f87f739022be6948.json | 20 - ...f6b4f7ee6dae2130c2109fb6f1e47e0990ec395744.json | 46 -- ...1cbd787a2f2a30efc581ea075b7e86ae75458c9014.json | 46 -- ...b8cf06394a302d288e91f5eedde65db6630021f737.json | 17 - ...248493f4458a532eee554d57438ef7849758238185.json | 15 - ...86cffd2b4739d88b3061931562e07c3e8dd24e6359.json | 49 -- ...1b2849b2530be7bcdcbe14362077b3fd47cd711c89.json | 17 - Cargo.lock | 731 +-------------------- Cargo.toml | 3 +- Dockerfile | 2 +- build.rs | 5 - docker-compose.yml | 13 - migrations/20231009123228_devices.sql | 9 - src/config.rs | 4 +- src/db.rs | 37 -- src/error.rs | 8 +- src/main.rs | 33 +- src/routes/device.rs | 118 +--- src/routes/start.rs | 92 +-- src/routes/status.rs | 24 +- src/services/ping.rs | 45 +- src/storage.rs | 65 ++ src/wol.rs | 20 - 29 files changed, 156 insertions(+), 1379 deletions(-) delete mode 100644 .sqlx/query-1dc5f44967ffdee882f4cef32262fd643b452aacca373ee527c978e816115de6.json delete mode 100644 .sqlx/query-25ab5caa92ff80ef3f85ddce1174021ce0fb896a818a6deee291a1eb85ae2a8a.json delete mode 100644 .sqlx/query-566c84386614590144dfebce2248cb3a734074014a493a7aad6fa03bb1286dc8.json delete mode 100644 .sqlx/query-5ac2b9a76338dd1342938cc09e37b14c828c4ee44b696d83f87f739022be6948.json delete mode 100644 .sqlx/query-62c84231c7e9c85dc91d71f6b4f7ee6dae2130c2109fb6f1e47e0990ec395744.json delete mode 100644 .sqlx/query-a1114f47abaa2ace231ef61cbd787a2f2a30efc581ea075b7e86ae75458c9014.json delete mode 100644 .sqlx/query-adead45e1a6b02d5eabd68b8cf06394a302d288e91f5eedde65db6630021f737.json delete mode 100644 .sqlx/query-df462bb016e2d258de146e248493f4458a532eee554d57438ef7849758238185.json delete mode 100644 .sqlx/query-e452c5ed8bdaec2011d78386cffd2b4739d88b3061931562e07c3e8dd24e6359.json delete mode 100644 .sqlx/query-edc4ecf39512caec1076be1b2849b2530be7bcdcbe14362077b3fd47cd711c89.json delete mode 100644 build.rs delete mode 100644 docker-compose.yml delete mode 100644 migrations/20231009123228_devices.sql delete mode 100644 src/db.rs create mode 100644 src/storage.rs diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 7196d4e..663f437 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -5,7 +5,6 @@ on: [ pull_request, workflow_dispatch ] env: SCCACHE_GHA_ENABLED: "true" RUSTC_WRAPPER: "sccache" - SQLX_OFFLINE: "true" CARGO_TERM_COLOR: always jobs: diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index d41941b..c04a19a 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -8,7 +8,6 @@ on: env: SCCACHE_GHA_ENABLED: "true" RUSTC_WRAPPER: "sccache" - SQLX_OFFLINE: "true" CARGO_TERM_COLOR: always jobs: diff --git a/.gitignore b/.gitignore index cbba613..9458d8b 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,5 @@ config.* .lapce logs/ +devices/ *.log diff --git a/.sqlx/query-1dc5f44967ffdee882f4cef32262fd643b452aacca373ee527c978e816115de6.json b/.sqlx/query-1dc5f44967ffdee882f4cef32262fd643b452aacca373ee527c978e816115de6.json deleted file mode 100644 index dd85eaa..0000000 --- a/.sqlx/query-1dc5f44967ffdee882f4cef32262fd643b452aacca373ee527c978e816115de6.json +++ /dev/null @@ -1,49 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n UPDATE devices\n SET mac = $1, broadcast_addr = $2, ip = $3 WHERE id = $4\n RETURNING id, mac, broadcast_addr, ip, times;\n ", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "id", - "type_info": "Varchar" - }, - { - "ordinal": 1, - "name": "mac", - "type_info": "Macaddr" - }, - { - "ordinal": 2, - "name": "broadcast_addr", - "type_info": "Varchar" - }, - { - "ordinal": 3, - "name": "ip", - "type_info": "Inet" - }, - { - "ordinal": 4, - "name": "times", - "type_info": "Int8Array" - } - ], - "parameters": { - "Left": [ - "Macaddr", - "Varchar", - "Inet", - "Text" - ] - }, - "nullable": [ - false, - false, - false, - false, - true - ] - }, - "hash": "1dc5f44967ffdee882f4cef32262fd643b452aacca373ee527c978e816115de6" -} diff --git a/.sqlx/query-25ab5caa92ff80ef3f85ddce1174021ce0fb896a818a6deee291a1eb85ae2a8a.json b/.sqlx/query-25ab5caa92ff80ef3f85ddce1174021ce0fb896a818a6deee291a1eb85ae2a8a.json deleted file mode 100644 index 71438e3..0000000 --- a/.sqlx/query-25ab5caa92ff80ef3f85ddce1174021ce0fb896a818a6deee291a1eb85ae2a8a.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n UPDATE devices\n SET times = array_append(times, $1)\n WHERE id = $2;\n ", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Int8", - "Text" - ] - }, - "nullable": [] - }, - "hash": "25ab5caa92ff80ef3f85ddce1174021ce0fb896a818a6deee291a1eb85ae2a8a" -} diff --git a/.sqlx/query-566c84386614590144dfebce2248cb3a734074014a493a7aad6fa03bb1286dc8.json b/.sqlx/query-566c84386614590144dfebce2248cb3a734074014a493a7aad6fa03bb1286dc8.json deleted file mode 100644 index 735c3bb..0000000 --- a/.sqlx/query-566c84386614590144dfebce2248cb3a734074014a493a7aad6fa03bb1286dc8.json +++ /dev/null @@ -1,49 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n INSERT INTO devices (id, mac, broadcast_addr, ip)\n VALUES ($1, $2, $3, $4)\n RETURNING id, mac, broadcast_addr, ip, times;\n ", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "id", - "type_info": "Varchar" - }, - { - "ordinal": 1, - "name": "mac", - "type_info": "Macaddr" - }, - { - "ordinal": 2, - "name": "broadcast_addr", - "type_info": "Varchar" - }, - { - "ordinal": 3, - "name": "ip", - "type_info": "Inet" - }, - { - "ordinal": 4, - "name": "times", - "type_info": "Int8Array" - } - ], - "parameters": { - "Left": [ - "Varchar", - "Macaddr", - "Varchar", - "Inet" - ] - }, - "nullable": [ - false, - false, - false, - false, - true - ] - }, - "hash": "566c84386614590144dfebce2248cb3a734074014a493a7aad6fa03bb1286dc8" -} diff --git a/.sqlx/query-5ac2b9a76338dd1342938cc09e37b14c828c4ee44b696d83f87f739022be6948.json b/.sqlx/query-5ac2b9a76338dd1342938cc09e37b14c828c4ee44b696d83f87f739022be6948.json deleted file mode 100644 index c385101..0000000 --- a/.sqlx/query-5ac2b9a76338dd1342938cc09e37b14c828c4ee44b696d83f87f739022be6948.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "SELECT times FROM devices;", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "times", - "type_info": "Int8Array" - } - ], - "parameters": { - "Left": [] - }, - "nullable": [ - true - ] - }, - "hash": "5ac2b9a76338dd1342938cc09e37b14c828c4ee44b696d83f87f739022be6948" -} diff --git a/.sqlx/query-62c84231c7e9c85dc91d71f6b4f7ee6dae2130c2109fb6f1e47e0990ec395744.json b/.sqlx/query-62c84231c7e9c85dc91d71f6b4f7ee6dae2130c2109fb6f1e47e0990ec395744.json deleted file mode 100644 index 905bb51..0000000 --- a/.sqlx/query-62c84231c7e9c85dc91d71f6b4f7ee6dae2130c2109fb6f1e47e0990ec395744.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n SELECT id, mac, broadcast_addr, ip, times\n FROM devices\n WHERE id = $1;\n ", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "id", - "type_info": "Varchar" - }, - { - "ordinal": 1, - "name": "mac", - "type_info": "Macaddr" - }, - { - "ordinal": 2, - "name": "broadcast_addr", - "type_info": "Varchar" - }, - { - "ordinal": 3, - "name": "ip", - "type_info": "Inet" - }, - { - "ordinal": 4, - "name": "times", - "type_info": "Int8Array" - } - ], - "parameters": { - "Left": [ - "Text" - ] - }, - "nullable": [ - false, - false, - false, - false, - true - ] - }, - "hash": "62c84231c7e9c85dc91d71f6b4f7ee6dae2130c2109fb6f1e47e0990ec395744" -} diff --git a/.sqlx/query-a1114f47abaa2ace231ef61cbd787a2f2a30efc581ea075b7e86ae75458c9014.json b/.sqlx/query-a1114f47abaa2ace231ef61cbd787a2f2a30efc581ea075b7e86ae75458c9014.json deleted file mode 100644 index 53608ed..0000000 --- a/.sqlx/query-a1114f47abaa2ace231ef61cbd787a2f2a30efc581ea075b7e86ae75458c9014.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n SELECT id, mac, broadcast_addr, ip, times\n FROM devices\n WHERE id = $1;\n ", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "id", - "type_info": "Varchar" - }, - { - "ordinal": 1, - "name": "mac", - "type_info": "Macaddr" - }, - { - "ordinal": 2, - "name": "broadcast_addr", - "type_info": "Varchar" - }, - { - "ordinal": 3, - "name": "ip", - "type_info": "Inet" - }, - { - "ordinal": 4, - "name": "times", - "type_info": "Int8Array" - } - ], - "parameters": { - "Left": [ - "Text" - ] - }, - "nullable": [ - false, - false, - false, - false, - true - ] - }, - "hash": "a1114f47abaa2ace231ef61cbd787a2f2a30efc581ea075b7e86ae75458c9014" -} diff --git a/.sqlx/query-adead45e1a6b02d5eabd68b8cf06394a302d288e91f5eedde65db6630021f737.json b/.sqlx/query-adead45e1a6b02d5eabd68b8cf06394a302d288e91f5eedde65db6630021f737.json deleted file mode 100644 index d25b12e..0000000 --- a/.sqlx/query-adead45e1a6b02d5eabd68b8cf06394a302d288e91f5eedde65db6630021f737.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n INSERT INTO devices (id, mac, broadcast_addr, ip)\n VALUES ($1, $2, $3, $4);\n ", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Varchar", - "Macaddr", - "Varchar", - "Inet" - ] - }, - "nullable": [] - }, - "hash": "adead45e1a6b02d5eabd68b8cf06394a302d288e91f5eedde65db6630021f737" -} diff --git a/.sqlx/query-df462bb016e2d258de146e248493f4458a532eee554d57438ef7849758238185.json b/.sqlx/query-df462bb016e2d258de146e248493f4458a532eee554d57438ef7849758238185.json deleted file mode 100644 index e448b24..0000000 --- a/.sqlx/query-df462bb016e2d258de146e248493f4458a532eee554d57438ef7849758238185.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n UPDATE devices\n SET times = array_append(times, $1)\n WHERE id = $2;\n ", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Int8", - "Text" - ] - }, - "nullable": [] - }, - "hash": "df462bb016e2d258de146e248493f4458a532eee554d57438ef7849758238185" -} diff --git a/.sqlx/query-e452c5ed8bdaec2011d78386cffd2b4739d88b3061931562e07c3e8dd24e6359.json b/.sqlx/query-e452c5ed8bdaec2011d78386cffd2b4739d88b3061931562e07c3e8dd24e6359.json deleted file mode 100644 index 75ec121..0000000 --- a/.sqlx/query-e452c5ed8bdaec2011d78386cffd2b4739d88b3061931562e07c3e8dd24e6359.json +++ /dev/null @@ -1,49 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n UPDATE devices\n SET mac = $1, broadcast_addr = $2, ip = $3 WHERE id = $4\n RETURNING id, mac, broadcast_addr, ip, times;\n ", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "id", - "type_info": "Varchar" - }, - { - "ordinal": 1, - "name": "mac", - "type_info": "Macaddr" - }, - { - "ordinal": 2, - "name": "broadcast_addr", - "type_info": "Varchar" - }, - { - "ordinal": 3, - "name": "ip", - "type_info": "Inet" - }, - { - "ordinal": 4, - "name": "times", - "type_info": "Int8Array" - } - ], - "parameters": { - "Left": [ - "Macaddr", - "Varchar", - "Inet", - "Text" - ] - }, - "nullable": [ - false, - false, - false, - false, - true - ] - }, - "hash": "e452c5ed8bdaec2011d78386cffd2b4739d88b3061931562e07c3e8dd24e6359" -} diff --git a/.sqlx/query-edc4ecf39512caec1076be1b2849b2530be7bcdcbe14362077b3fd47cd711c89.json b/.sqlx/query-edc4ecf39512caec1076be1b2849b2530be7bcdcbe14362077b3fd47cd711c89.json deleted file mode 100644 index 2b17c9b..0000000 --- a/.sqlx/query-edc4ecf39512caec1076be1b2849b2530be7bcdcbe14362077b3fd47cd711c89.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n INSERT INTO devices (id, mac, broadcast_addr, ip)\n VALUES ($1, $2, $3, $4);\n ", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Varchar", - "Macaddr", - "Varchar", - "Inet" - ] - }, - "nullable": [] - }, - "hash": "edc4ecf39512caec1076be1b2849b2530be7bcdcbe14362077b3fd47cd711c89" -} diff --git a/Cargo.lock b/Cargo.lock index 0296951..5261edf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,19 +17,6 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" -[[package]] -name = "ahash" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" -dependencies = [ - "cfg-if", - "getrandom", - "once_cell", - "version_check", - "zerocopy", -] - [[package]] name = "aho-corasick" version = "1.1.3" @@ -39,12 +26,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "allocator-api2" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" - [[package]] name = "async-trait" version = "0.1.79" @@ -56,15 +37,6 @@ dependencies = [ "syn 2.0.58", ] -[[package]] -name = "atoi" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f28d99ec8bfea296261ca1af174f24225171fea9664ba9003cbebee704810528" -dependencies = [ - "num-traits", -] - [[package]] name = "autocfg" version = "1.2.0" @@ -162,12 +134,6 @@ version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - [[package]] name = "bitflags" version = "1.3.2" @@ -263,12 +229,6 @@ dependencies = [ "yaml-rust", ] -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - [[package]] name = "const-random" version = "0.1.18" @@ -307,21 +267,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crc" -version = "3.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69e6e4d7b33a94f0991c26729976b10ebde1d34c3ee82408fb536164fa10d636" -dependencies = [ - "crc-catalog", -] - -[[package]] -name = "crc-catalog" -version = "2.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" - [[package]] name = "crc32fast" version = "1.4.0" @@ -340,15 +285,6 @@ dependencies = [ "crossbeam-utils", ] -[[package]] -name = "crossbeam-queue" -version = "0.3.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df0346b5d5e76ac2fe4e327c5fd1118d6be7c51dfb18f9b7922923f287471e35" -dependencies = [ - "crossbeam-utils", -] - [[package]] name = "crossbeam-utils" version = "0.8.19" @@ -390,17 +326,6 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7e962a19be5cfc3f3bf6dd8f61eb50107f356ad6270fbb3ed41476571db78be5" -[[package]] -name = "der" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" -dependencies = [ - "const-oid", - "pem-rfc7468", - "zeroize", -] - [[package]] name = "deranged" version = "0.3.11" @@ -417,9 +342,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", - "const-oid", "crypto-common", - "subtle", ] [[package]] @@ -431,54 +354,12 @@ dependencies = [ "const-random", ] -[[package]] -name = "dotenvy" -version = "0.15.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" - -[[package]] -name = "either" -version = "1.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" -dependencies = [ - "serde", -] - [[package]] name = "equivalent" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" -[[package]] -name = "errno" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "etcetera" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "136d1b5283a1ab77bd9257427ffd09d8667ced0570b6f938942bc7568ed5b943" -dependencies = [ - "cfg-if", - "home", - "windows-sys 0.48.0", -] - -[[package]] -name = "event-listener" -version = "2.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" - [[package]] name = "eyre" version = "0.6.12" @@ -489,18 +370,6 @@ dependencies = [ "once_cell", ] -[[package]] -name = "fastrand" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "658bd65b1cf4c852a3cc96f18a8ce7b5640f6b703f905c7d74532294c2a63984" - -[[package]] -name = "finl_unicode" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fcfdc7a0362c9f4444381a9e697c79d435fe65b52a37466fc2c1184cee9edc6" - [[package]] name = "flate2" version = "1.0.28" @@ -511,17 +380,6 @@ dependencies = [ "miniz_oxide", ] -[[package]] -name = "flume" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55ac459de2512911e4b674ce33cf20befaba382d05b62b008afc1c8b57cbf181" -dependencies = [ - "futures-core", - "futures-sink", - "spin 0.9.8", -] - [[package]] name = "fnv" version = "1.0.7" @@ -544,7 +402,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" dependencies = [ "futures-core", - "futures-sink", ] [[package]] @@ -553,34 +410,6 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" -[[package]] -name = "futures-executor" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-intrusive" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d930c203dd0b6ff06e0201a4a2fe9149b43c684fd4420555b26d21b1a02956f" -dependencies = [ - "futures-core", - "lock_api", - "parking_lot", -] - -[[package]] -name = "futures-io" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" - [[package]] name = "futures-sink" version = "0.3.30" @@ -600,10 +429,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" dependencies = [ "futures-core", - "futures-io", "futures-sink", "futures-task", - "memchr", "pin-project-lite", "pin-utils", "slab", @@ -653,28 +480,12 @@ name = "hashbrown" version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" -dependencies = [ - "ahash", - "allocator-api2", -] - -[[package]] -name = "hashlink" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8094feaf31ff591f651a2664fb9cfd92bba7a60ce3197265e9482ebe753c8f7" -dependencies = [ - "hashbrown 0.14.3", -] [[package]] name = "heck" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" -dependencies = [ - "unicode-segmentation", -] [[package]] name = "hermit-abi" @@ -688,33 +499,6 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" -[[package]] -name = "hkdf" -version = "0.12.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7" -dependencies = [ - "hmac", -] - -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - -[[package]] -name = "home" -version = "0.5.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" -dependencies = [ - "windows-sys 0.52.0", -] - [[package]] name = "http" version = "1.1.0" @@ -832,15 +616,6 @@ dependencies = [ "serde", ] -[[package]] -name = "itertools" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" -dependencies = [ - "either", -] - [[package]] name = "itoa" version = "1.0.11" @@ -863,9 +638,6 @@ name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -dependencies = [ - "spin 0.5.2", -] [[package]] name = "libc" @@ -873,35 +645,12 @@ version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" -[[package]] -name = "libm" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" - -[[package]] -name = "libsqlite3-sys" -version = "0.27.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4e226dcd58b4be396f7bd3c20da8fdee2911400705297ba7d2d7cc2c30f716" -dependencies = [ - "cc", - "pkg-config", - "vcpkg", -] - [[package]] name = "linked-hash-map" version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" -[[package]] -name = "linux-raw-sys" -version = "0.4.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" - [[package]] name = "lock_api" version = "0.4.11" @@ -944,16 +693,6 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" -[[package]] -name = "md-5" -version = "0.10.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf" -dependencies = [ - "cfg-if", - "digest", -] - [[package]] name = "memchr" version = "2.7.2" @@ -1050,59 +789,12 @@ dependencies = [ "winapi", ] -[[package]] -name = "num-bigint-dig" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc84195820f291c7697304f3cbdadd1cb7199c0efc917ff5eafd71225c136151" -dependencies = [ - "byteorder", - "lazy_static", - "libm", - "num-integer", - "num-iter", - "num-traits", - "rand", - "smallvec", - "zeroize", -] - [[package]] name = "num-conv" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" -[[package]] -name = "num-integer" -version = "0.1.46" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" -dependencies = [ - "num-traits", -] - -[[package]] -name = "num-iter" -version = "0.1.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d869c01cc0c455284163fd0092f1f93835385ccab5a98a0dcc497b2f8bf055a9" -dependencies = [ - "autocfg", - "num-integer", - "num-traits", -] - -[[package]] -name = "num-traits" -version = "0.2.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" -dependencies = [ - "autocfg", - "libm", -] - [[package]] name = "num_cpus" version = "1.16.0" @@ -1182,27 +874,12 @@ dependencies = [ "windows-targets 0.48.5", ] -[[package]] -name = "paste" -version = "1.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" - [[package]] name = "pathdiff" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd" -[[package]] -name = "pem-rfc7468" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" -dependencies = [ - "base64ct", -] - [[package]] name = "percent-encoding" version = "2.3.1" @@ -1286,33 +963,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkcs1" -version = "0.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8ffb9f10fa047879315e6625af03c164b16962a5368d724ed16323b68ace47f" -dependencies = [ - "der", - "pkcs8", - "spki", -] - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - -[[package]] -name = "pkg-config" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" - [[package]] name = "pnet_base" version = "0.34.0" @@ -1504,26 +1154,6 @@ dependencies = [ "serde_derive", ] -[[package]] -name = "rsa" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d0e5124fcb30e76a7e79bfee683a2746db83784b86289f6251b54b7950a0dfc" -dependencies = [ - "const-oid", - "digest", - "num-bigint-dig", - "num-integer", - "num-traits", - "pkcs1", - "pkcs8", - "rand_core", - "signature", - "spki", - "subtle", - "zeroize", -] - [[package]] name = "rust-embed" version = "8.3.0" @@ -1574,19 +1204,6 @@ version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" -[[package]] -name = "rustix" -version = "0.38.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65e04861e65f21776e67888bfbea442b3642beaa0138fdb1dd7a84a52dffdb89" -dependencies = [ - "bitflags 2.5.0", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", -] - [[package]] name = "rustversion" version = "1.0.15" @@ -1707,16 +1324,6 @@ dependencies = [ "lazy_static", ] -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "digest", - "rand_core", -] - [[package]] name = "slab" version = "0.4.9" @@ -1742,257 +1349,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "spin" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" - -[[package]] -name = "spin" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" -dependencies = [ - "lock_api", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", -] - -[[package]] -name = "sqlformat" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce81b7bd7c4493975347ef60d8c7e8b742d4694f4c49f93e0a12ea263938176c" -dependencies = [ - "itertools", - "nom", - "unicode_categories", -] - -[[package]] -name = "sqlx" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9a2ccff1a000a5a59cd33da541d9f2fdcd9e6e8229cc200565942bff36d0aaa" -dependencies = [ - "sqlx-core", - "sqlx-macros", - "sqlx-mysql", - "sqlx-postgres", - "sqlx-sqlite", -] - -[[package]] -name = "sqlx-core" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24ba59a9342a3d9bab6c56c118be528b27c9b60e490080e9711a04dccac83ef6" -dependencies = [ - "ahash", - "atoi", - "byteorder", - "bytes", - "crc", - "crossbeam-queue", - "either", - "event-listener", - "futures-channel", - "futures-core", - "futures-intrusive", - "futures-io", - "futures-util", - "hashlink", - "hex", - "indexmap", - "ipnetwork", - "log", - "mac_address", - "memchr", - "once_cell", - "paste", - "percent-encoding", - "serde", - "serde_json", - "sha2", - "smallvec", - "sqlformat", - "thiserror", - "tokio", - "tokio-stream", - "tracing", - "url", -] - -[[package]] -name = "sqlx-macros" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ea40e2345eb2faa9e1e5e326db8c34711317d2b5e08d0d5741619048a803127" -dependencies = [ - "proc-macro2", - "quote", - "sqlx-core", - "sqlx-macros-core", - "syn 1.0.109", -] - -[[package]] -name = "sqlx-macros-core" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5833ef53aaa16d860e92123292f1f6a3d53c34ba8b1969f152ef1a7bb803f3c8" -dependencies = [ - "dotenvy", - "either", - "heck", - "hex", - "once_cell", - "proc-macro2", - "quote", - "serde", - "serde_json", - "sha2", - "sqlx-core", - "sqlx-mysql", - "sqlx-postgres", - "sqlx-sqlite", - "syn 1.0.109", - "tempfile", - "tokio", - "url", -] - -[[package]] -name = "sqlx-mysql" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ed31390216d20e538e447a7a9b959e06ed9fc51c37b514b46eb758016ecd418" -dependencies = [ - "atoi", - "base64", - "bitflags 2.5.0", - "byteorder", - "bytes", - "crc", - "digest", - "dotenvy", - "either", - "futures-channel", - "futures-core", - "futures-io", - "futures-util", - "generic-array", - "hex", - "hkdf", - "hmac", - "itoa", - "log", - "md-5", - "memchr", - "once_cell", - "percent-encoding", - "rand", - "rsa", - "serde", - "sha1", - "sha2", - "smallvec", - "sqlx-core", - "stringprep", - "thiserror", - "tracing", - "whoami", -] - -[[package]] -name = "sqlx-postgres" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c824eb80b894f926f89a0b9da0c7f435d27cdd35b8c655b114e58223918577e" -dependencies = [ - "atoi", - "base64", - "bitflags 2.5.0", - "byteorder", - "crc", - "dotenvy", - "etcetera", - "futures-channel", - "futures-core", - "futures-io", - "futures-util", - "hex", - "hkdf", - "hmac", - "home", - "ipnetwork", - "itoa", - "log", - "mac_address", - "md-5", - "memchr", - "once_cell", - "rand", - "serde", - "serde_json", - "sha2", - "smallvec", - "sqlx-core", - "stringprep", - "thiserror", - "tracing", - "whoami", -] - -[[package]] -name = "sqlx-sqlite" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b244ef0a8414da0bed4bb1910426e890b19e5e9bccc27ada6b797d05c55ae0aa" -dependencies = [ - "atoi", - "flume", - "futures-channel", - "futures-core", - "futures-executor", - "futures-intrusive", - "futures-util", - "libsqlite3-sys", - "log", - "percent-encoding", - "serde", - "sqlx-core", - "tracing", - "url", - "urlencoding", -] - -[[package]] -name = "stringprep" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb41d74e231a107a1b4ee36bd1214b11285b77768d2e3824aedafa988fd36ee6" -dependencies = [ - "finl_unicode", - "unicode-bidi", - "unicode-normalization", -] - -[[package]] -name = "subtle" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" - [[package]] name = "surge-ping" version = "0.8.1" @@ -2016,7 +1372,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" dependencies = [ "proc-macro2", - "quote", "unicode-ident", ] @@ -2043,18 +1398,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" -[[package]] -name = "tempfile" -version = "3.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" -dependencies = [ - "cfg-if", - "fastrand", - "rustix", - "windows-sys 0.52.0", -] - [[package]] name = "thiserror" version = "1.0.58" @@ -2170,17 +1513,6 @@ dependencies = [ "syn 2.0.58", ] -[[package]] -name = "tokio-stream" -version = "0.1.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" -dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", -] - [[package]] name = "tokio-tungstenite" version = "0.21.0" @@ -2407,12 +1739,6 @@ version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" -[[package]] -name = "unicode_categories" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e" - [[package]] name = "url" version = "2.5.0" @@ -2424,12 +1750,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "urlencoding" -version = "2.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" - [[package]] name = "utf-8" version = "0.7.6" @@ -2493,12 +1813,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version_check" version = "0.9.4" @@ -2521,15 +1835,9 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" -[[package]] -name = "wasite" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b" - [[package]] name = "webol" -version = "0.3.4" +version = "0.4.0" dependencies = [ "axum", "axum-macros", @@ -2540,7 +1848,6 @@ dependencies = [ "mac_address", "serde", "serde_json", - "sqlx", "surge-ping", "thiserror", "time", @@ -2553,16 +1860,6 @@ dependencies = [ "uuid", ] -[[package]] -name = "whoami" -version = "1.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44ab49fad634e88f55bf8f9bb3abd2f27d7204172a112c7c9987e01c1c94ea9" -dependencies = [ - "redox_syscall", - "wasite", -] - [[package]] name = "winapi" version = "0.3.9" @@ -2744,32 +2041,6 @@ dependencies = [ "linked-hash-map", ] -[[package]] -name = "zerocopy" -version = "0.7.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" -dependencies = [ - "zerocopy-derive", -] - -[[package]] -name = "zerocopy-derive" -version = "0.7.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.58", -] - -[[package]] -name = "zeroize" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" - [[package]] name = "zip" version = "0.6.6" diff --git a/Cargo.toml b/Cargo.toml index d15bcd1..1b7db8e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "webol" -version = "0.3.4" +version = "0.4.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -14,7 +14,6 @@ time = { version = "0.3", features = ["macros"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" config = "0.14" -sqlx = { version = "0.7", features = ["postgres", "runtime-tokio", "ipnetwork", "mac_address"]} surge-ping = "0.8" axum-macros = "0.4" uuid = { version = "1.8", features = ["v4", "fast-rng"] } diff --git a/Dockerfile b/Dockerfile index 3336fe2..e5057e9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,7 @@ RUN cd /tmp && \ mkdir /dpkg && \ for deb in *.deb; do dpkg --extract $deb /dpkg || exit 10; done -FROM rust:1.76 as builder +FROM rust:1.77 as builder WORKDIR /app COPY . . RUN cargo install --path . diff --git a/build.rs b/build.rs deleted file mode 100644 index 7609593..0000000 --- a/build.rs +++ /dev/null @@ -1,5 +0,0 @@ -// generated by `sqlx migrate build-script` -fn main() { - // trigger recompilation when a new migration is added - println!("cargo:rerun-if-changed=migrations"); -} \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index abac64e..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,13 +0,0 @@ -version: '3.1' - -services: - db: - image: postgres - container_name: webol_dev_postgres - restart: no - environment: - - POSTGRES_PASSWORD=postgres - - POSTGRES_DB=webol - - ports: - - "5432:5432" diff --git a/migrations/20231009123228_devices.sql b/migrations/20231009123228_devices.sql deleted file mode 100644 index 6983ada..0000000 --- a/migrations/20231009123228_devices.sql +++ /dev/null @@ -1,9 +0,0 @@ --- Add migration script here -CREATE TABLE IF NOT EXISTS "devices" -( - "id" VARCHAR(255) PRIMARY KEY NOT NULL, - "mac" MACADDR NOT NULL, - "broadcast_addr" VARCHAR(39) NOT NULL, - "ip" INET NOT NULL, - "times" BIGINT[] -) diff --git a/src/config.rs b/src/config.rs index 9636af4..124893b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -5,7 +5,6 @@ use crate::auth; #[derive(Debug, Clone, Deserialize)] pub struct Config { - pub database_url: String, pub serveraddr: String, pub pingtimeout: i64, pub pingthreshold: i64, @@ -26,9 +25,10 @@ impl Config { .set_default("pingtimeout", 10)? .set_default("pingthreshold", 1)? .set_default("timeoffset", 0)? + .set_default("auth.secret", "")? .add_source(File::with_name("config.toml").required(false)) .add_source(File::with_name("config.dev.toml").required(false)) - .add_source(config::Environment::with_prefix("WEBOL").prefix_separator("_")) + .add_source(config::Environment::with_prefix("WEBOL").separator("_")) .build()?; config.try_deserialize() diff --git a/src/db.rs b/src/db.rs deleted file mode 100644 index a2b2009..0000000 --- a/src/db.rs +++ /dev/null @@ -1,37 +0,0 @@ -use serde::Serialize; -use sqlx::{PgPool, postgres::PgPoolOptions, types::{ipnetwork::IpNetwork, mac_address::MacAddress}}; -use tracing::{debug, info}; -use utoipa::ToSchema; - -#[derive(Serialize, Debug)] -pub struct Device { - pub id: String, - pub mac: MacAddress, - pub broadcast_addr: String, - pub ip: IpNetwork, - pub times: Option> -} - -#[derive(ToSchema)] -#[schema(as = Device)] -pub struct DeviceSchema { - pub id: String, - pub mac: String, - pub broadcast_addr: String, - pub ip: String, - pub times: Option> -} - -pub async fn init_db_pool(db_url: &str) -> PgPool { - debug!("attempt to connect dbPool to '{}'", db_url); - - let pool = PgPoolOptions::new() - .max_connections(5) - .connect(db_url) - .await - .unwrap(); - - info!("dbPool successfully connected to '{}'", db_url); - - pool -} diff --git a/src/error.rs b/src/error.rs index 006fcdb..8a011bf 100644 --- a/src/error.rs +++ b/src/error.rs @@ -11,10 +11,10 @@ use tracing::error; #[derive(Debug, thiserror::Error, ToSchema)] pub enum Error { - #[error("db: {source}")] - Db { + #[error("json: {source}")] + Json { #[from] - source: sqlx::Error, + source: serde_json::Error, }, #[error("buffer parse: {source}")] @@ -52,7 +52,7 @@ impl IntoResponse for Error { fn into_response(self) -> Response { error!("{}", self.to_string()); let (status, error_message) = match self { - Self::Db { source } => { + Self::Json { source } => { error!("{source}"); (StatusCode::INTERNAL_SERVER_ERROR, "Server Error") } diff --git a/src/main.rs b/src/main.rs index 70c67cf..cf0d39b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,5 @@ use crate::{ - config::Config, - db::init_db_pool, - routes::{device, start, status}, - services::ping::{BroadcastCommand, StatusMap}, + config::Config, routes::{device, start, status}, services::ping::{BroadcastCommand, StatusMap}, storage::Device }; use axum::{ middleware::from_fn_with_state, @@ -10,7 +7,6 @@ use axum::{ Router, }; use dashmap::DashMap; -use sqlx::PgPool; use std::{env, sync::Arc}; use time::UtcOffset; use tokio::sync::broadcast::{channel, Sender}; @@ -26,10 +22,10 @@ use utoipa::{ }; use utoipa_swagger_ui::SwaggerUi; +mod auth; mod config; -mod db; +mod storage; mod error; -mod auth; mod routes; mod services; mod wol; @@ -39,20 +35,16 @@ mod wol; paths( start::post, start::get, - start::start_payload, device::get, - device::get_payload, device::post, device::put, ), components( schemas( - start::PayloadOld, start::Payload, start::Response, - device::DevicePayload, - device::GetDevicePayload, - db::DeviceSchema, + device::Payload, + storage::DeviceSchema, ) ), modifiers(&SecurityAddon), @@ -99,34 +91,26 @@ async fn main() -> color_eyre::eyre::Result<()> { ) .init(); - let version = env!("CARGO_PKG_VERSION"); + Device::setup()?; + let version = env!("CARGO_PKG_VERSION"); info!("start webol v{}", version); - let db = init_db_pool(&config.database_url).await; - sqlx::migrate!().run(&db).await.unwrap(); - let (tx, _) = channel(32); let ping_map: StatusMap = DashMap::new(); let shared_state = AppState { - db, config: config.clone(), ping_send: tx, ping_map, }; let app = Router::new() - .route("/start", post(start::start_payload)) .route("/start/:id", post(start::post).get(start::get)) - .route( - "/device", - post(device::post).get(device::get_payload).put(device::put), - ) + .route("/device", post(device::post).put(device::put)) .route("/device/:id", get(device::get)) .route("/status", get(status::status)) - // TODO: Don't load on `None` Auth .route_layer(from_fn_with_state(shared_state.clone(), auth::auth)) .merge(SwaggerUi::new("/swagger-ui").url("/api-docs/openapi.json", ApiDoc::openapi())) .with_state(Arc::new(shared_state)); @@ -141,7 +125,6 @@ async fn main() -> color_eyre::eyre::Result<()> { #[derive(Clone)] pub struct AppState { - db: PgPool, config: Config, ping_send: Sender, ping_map: StatusMap, diff --git a/src/routes/device.rs b/src/routes/device.rs index 40b5cd8..b6bd9d0 100644 --- a/src/routes/device.rs +++ b/src/routes/device.rs @@ -1,47 +1,15 @@ -use crate::db::Device; use crate::error::Error; -use axum::extract::{Path, State}; +use crate::storage::Device; +use axum::extract::Path; use axum::Json; +use ipnetwork::IpNetwork; use mac_address::MacAddress; use serde::Deserialize; use serde_json::{json, Value}; -use sqlx::types::ipnetwork::IpNetwork; -use std::{str::FromStr, sync::Arc}; +use std::str::FromStr; use tracing::{debug, info}; use utoipa::ToSchema; -#[utoipa::path( - get, - path = "/device", - request_body = GetDevicePayload, - responses( - (status = 200, description = "Get `Device` information", body = [Device]) - ), - security(("api_key" = [])) -)] -#[deprecated] -pub async fn get_payload( - State(state): State>, - Json(payload): Json, -) -> Result, Error> { - info!("get device {}", payload.id); - let device = sqlx::query_as!( - Device, - r#" - SELECT id, mac, broadcast_addr, ip, times - FROM devices - WHERE id = $1; - "#, - payload.id - ) - .fetch_one(&state.db) - .await?; - - debug!("got device {:?}", device); - - Ok(Json(json!(device))) -} - #[utoipa::path( get, path = "/device/{id}", @@ -53,22 +21,10 @@ pub async fn get_payload( ), security((), ("api_key" = [])) )] -pub async fn get( - State(state): State>, - Path(path): Path, -) -> Result, Error> { - info!("get device from path {}", path); - let device = sqlx::query_as!( - Device, - r#" - SELECT id, mac, broadcast_addr, ip, times - FROM devices - WHERE id = $1; - "#, - path - ) - .fetch_one(&state.db) - .await?; +pub async fn get(Path(id): Path) -> Result, Error> { + info!("get device from path {}", id); + + let device = Device::read(&id)?; debug!("got device {:?}", device); @@ -76,13 +32,7 @@ pub async fn get( } #[derive(Deserialize, ToSchema)] -#[deprecated] -pub struct GetDevicePayload { - id: String, -} - -#[derive(Deserialize, ToSchema)] -pub struct DevicePayload { +pub struct Payload { id: String, mac: String, broadcast_addr: String, @@ -92,15 +42,14 @@ pub struct DevicePayload { #[utoipa::path( put, path = "/device", - request_body = DevicePayload, + request_body = Payload, responses( (status = 200, description = "add device to storage", body = [DeviceSchema]) ), security((), ("api_key" = [])) )] pub async fn put( - State(state): State>, - Json(payload): Json, + Json(payload): Json, ) -> Result, Error> { info!( "add device {} ({}, {}, {})", @@ -109,20 +58,14 @@ pub async fn put( let ip = IpNetwork::from_str(&payload.ip)?; let mac = MacAddress::from_str(&payload.mac)?; - let device = sqlx::query_as!( - Device, - r#" - INSERT INTO devices (id, mac, broadcast_addr, ip) - VALUES ($1, $2, $3, $4) - RETURNING id, mac, broadcast_addr, ip, times; - "#, - payload.id, + let device = Device { + id: payload.id, mac, - payload.broadcast_addr, - ip - ) - .fetch_one(&state.db) - .await?; + broadcast_addr: payload.broadcast_addr, + ip, + times: None, + }; + device.write()?; Ok(Json(json!(device))) } @@ -130,15 +73,14 @@ pub async fn put( #[utoipa::path( post, path = "/device", - request_body = DevicePayload, + request_body = Payload, responses( (status = 200, description = "update device in storage", body = [DeviceSchema]) ), security((), ("api_key" = [])) )] pub async fn post( - State(state): State>, - Json(payload): Json, + Json(payload): Json, ) -> Result, Error> { info!( "edit device {} ({}, {}, {})", @@ -146,20 +88,16 @@ pub async fn post( ); let ip = IpNetwork::from_str(&payload.ip)?; let mac = MacAddress::from_str(&payload.mac)?; - let device = sqlx::query_as!( - Device, - r#" - UPDATE devices - SET mac = $1, broadcast_addr = $2, ip = $3 WHERE id = $4 - RETURNING id, mac, broadcast_addr, ip, times; - "#, + let times = Device::read(&payload.id)?.times; + + let device = Device { + id: payload.id, mac, - payload.broadcast_addr, + broadcast_addr: payload.broadcast_addr, ip, - payload.id - ) - .fetch_one(&state.db) - .await?; + times, + }; + device.write()?; Ok(Json(json!(device))) } diff --git a/src/routes/start.rs b/src/routes/start.rs index ff3d1be..6907193 100644 --- a/src/routes/start.rs +++ b/src/routes/start.rs @@ -1,7 +1,7 @@ -use crate::db::Device; +use crate::storage::Device; use crate::error::Error; use crate::services::ping::Value as PingValue; -use crate::wol::{create_buffer, send_packet}; +use crate::wol::send_packet; use axum::extract::{Path, State}; use axum::Json; use serde::{Deserialize, Serialize}; @@ -11,55 +11,6 @@ use tracing::{debug, info}; use utoipa::ToSchema; use uuid::Uuid; -#[utoipa::path( - post, - path = "/start", - request_body = PayloadOld, - responses( - (status = 200, description = "DEP", body = [Response]) - ), - security((), ("api_key" = [])) -)] -#[deprecated] -pub async fn start_payload( - State(state): State>, - Json(payload): Json, -) -> Result, Error> { - info!("POST request"); - let device = sqlx::query_as!( - Device, - r#" - SELECT id, mac, broadcast_addr, ip, times - FROM devices - WHERE id = $1; - "#, - payload.id - ) - .fetch_one(&state.db) - .await?; - - info!("starting {}", device.id); - - let bind_addr = "0.0.0.0:0"; - - let _ = send_packet( - bind_addr, - &device.broadcast_addr, - &create_buffer(&device.mac.to_string())?, - )?; - let dev_id = device.id.clone(); - let uuid = if payload.ping.is_some_and(|ping| ping) { - Some(setup_ping(state, device)) - } else { - None - }; - Ok(Json(json!(Response { - id: dev_id, - boot: true, - uuid - }))) -} - #[utoipa::path( post, path = "/start/{id}", @@ -77,7 +28,7 @@ pub async fn post( Path(id): Path, payload: Option>, ) -> Result, Error> { - send_wol(state, &id, payload).await + send_wol(state, &id, payload) } #[utoipa::path( @@ -95,26 +46,16 @@ pub async fn get( State(state): State>, Path(id): Path, ) -> Result, Error> { - send_wol(state, &id, None).await + send_wol(state, &id, None) } -async fn send_wol( +fn send_wol( state: Arc, id: &str, payload: Option>, ) -> Result, Error> { - info!("Start request for {id}"); - let device = sqlx::query_as!( - Device, - r#" - SELECT id, mac, broadcast_addr, ip, times - FROM devices - WHERE id = $1; - "#, - id - ) - .fetch_one(&state.db) - .await?; + info!("start request for {id}"); + let device = Device::read(id)?; info!("starting {}", device.id); @@ -122,8 +63,8 @@ async fn send_wol( let _ = send_packet( bind_addr, - &device.broadcast_addr, - &create_buffer(&device.mac.to_string())?, + &device.broadcast_addr.to_string(), + &device.mac.bytes() )?; let dev_id = device.id.clone(); let uuid = if let Some(pl) = payload { @@ -163,6 +104,7 @@ fn setup_ping(state: Arc, device: Device) -> String { uuid_gen.clone(), PingValue { ip: device.ip, + eta: get_eta(device.clone().times), online: false, }, ); @@ -174,7 +116,6 @@ fn setup_ping(state: Arc, device: Device) -> String { device, uuid_gen, &state.ping_map, - &state.db, ) .await; }); @@ -182,11 +123,14 @@ fn setup_ping(state: Arc, device: Device) -> String { uuid_ret } -#[derive(Deserialize, ToSchema)] -#[deprecated] -pub struct PayloadOld { - id: String, - ping: Option, +fn get_eta(times: Option>) -> i64 { + let times = if let Some(times) = times { + times + } else { + vec![0] + }; + + times.iter().sum::() / i64::try_from(times.len()).unwrap() } #[derive(Deserialize, ToSchema)] diff --git a/src/routes/status.rs b/src/routes/status.rs index 0e25f7d..b38202b 100644 --- a/src/routes/status.rs +++ b/src/routes/status.rs @@ -3,7 +3,6 @@ use crate::AppState; use axum::extract::ws::{Message, WebSocket}; use axum::extract::{State, WebSocketUpgrade}; use axum::response::Response; -use sqlx::PgPool; use std::sync::Arc; use tracing::{debug, trace}; @@ -18,13 +17,13 @@ pub async fn websocket(mut socket: WebSocket, state: Arc) { trace!("Search for uuid: {}", uuid); - let eta = get_eta(&state.db).await; - let _ = socket - .send(Message::Text(format!("eta_{eta}_{uuid}"))) - .await; let device_exists = state.ping_map.contains_key(&uuid); if device_exists { + let eta = state.ping_map.get(&uuid).unwrap().eta; + let _ = socket + .send(Message::Text(format!("eta_{eta}_{uuid}"))) + .await; let _ = socket .send(receive_ping_broadcast(state.clone(), uuid).await) .await; @@ -62,18 +61,3 @@ async fn receive_ping_broadcast(state: Arc, uuid: String) -> Message { } } } - -async fn get_eta(db: &PgPool) -> i64 { - let query = sqlx::query!(r#"SELECT times FROM devices;"#) - .fetch_one(db) - .await - .unwrap(); - - let times = if let Some(times) = query.times { - times - } else { - vec![0] - }; - - times.iter().sum::() / i64::try_from(times.len()).unwrap() -} diff --git a/src/services/ping.rs b/src/services/ping.rs index 8cf6072..1bf022d 100644 --- a/src/services/ping.rs +++ b/src/services/ping.rs @@ -1,8 +1,7 @@ use crate::config::Config; -use crate::db::Device; +use crate::storage::Device; use dashmap::DashMap; use ipnetwork::IpNetwork; -use sqlx::PgPool; use std::fmt::Display; use time::{Duration, Instant}; use tokio::sync::broadcast::Sender; @@ -13,6 +12,7 @@ pub type StatusMap = DashMap; #[derive(Debug, Clone)] pub struct Value { pub ip: IpNetwork, + pub eta: i64, pub online: bool, } @@ -22,7 +22,6 @@ pub async fn spawn( device: Device, uuid: String, ping_map: &StatusMap, - db: &PgPool, ) { let timer = Instant::now(); let payload = [0; 8]; @@ -56,27 +55,29 @@ pub async fn spawn( let _ = tx.send(msg.clone()); if msg.command == BroadcastCommands::Success { if timer.elapsed().whole_seconds() > config.pingthreshold { - sqlx::query!( - r#" - UPDATE devices - SET times = array_append(times, $1) - WHERE id = $2; - "#, - timer.elapsed().whole_seconds(), - device.id - ) - .execute(db) - .await - .unwrap(); + let newtimes = if let Some(mut oldtimes) = device.times { + oldtimes.push(timer.elapsed().whole_seconds()); + oldtimes + } else { + vec![timer.elapsed().whole_seconds()] + }; + + let updatedev = Device { + id: device.id, + mac: device.mac, + broadcast_addr: device.broadcast_addr, + ip: device.ip, + times: Some(newtimes), + }; + updatedev.write().unwrap(); } - ping_map.insert( - uuid.clone(), - Value { - ip: device.ip, - online: true, - }, - ); + ping_map.alter(&uuid, |_, v| Value { + ip: v.ip, + eta: v.eta, + online: true, + }); + tokio::time::sleep(tokio::time::Duration::from_secs(60)).await; } trace!("remove {} from ping_map", uuid); diff --git a/src/storage.rs b/src/storage.rs new file mode 100644 index 0000000..6ba5ee1 --- /dev/null +++ b/src/storage.rs @@ -0,0 +1,65 @@ +use std::{ + fs::{create_dir_all, File}, + io::{Read, Write}, + path::Path, +}; + +use ipnetwork::IpNetwork; +use mac_address::MacAddress; +use serde::{Deserialize, Serialize}; +use serde_json::json; +use tracing::{debug, warn}; +use utoipa::ToSchema; + +use crate::error::Error; + +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct Device { + pub id: String, + pub mac: MacAddress, + pub broadcast_addr: String, + pub ip: IpNetwork, + pub times: Option>, +} + +impl Device { + const STORAGE_PATH: &'static str = "devices"; + + pub fn setup() -> Result { + let sp = Path::new(Self::STORAGE_PATH); + if !sp.exists() { + warn!("device storage path doesn't exist, creating it"); + create_dir_all(Self::STORAGE_PATH)?; + }; + + debug!("device storage at '{}'", Self::STORAGE_PATH); + + Ok(Self::STORAGE_PATH.to_string()) + } + + pub fn read(id: &str) -> Result { + let mut file = File::open(format!("{}/{id}.json", Self::STORAGE_PATH))?; + let mut buf = String::new(); + file.read_to_string(&mut buf)?; + + let dev = serde_json::from_str(&buf)?; + Ok(dev) + } + + pub fn write(&self) -> Result<(), Error> { + let mut file = File::create(format!("{}/{}.json", Self::STORAGE_PATH, self.id))?; + file.write_all(json!(self).to_string().as_bytes())?; + + Ok(()) + } +} + +#[derive(ToSchema)] +#[schema(as = Device)] +pub struct DeviceSchema { + pub id: String, + pub mac: String, + pub broadcast_addr: String, + pub ip: String, + pub times: Option>, +} diff --git a/src/wol.rs b/src/wol.rs index 31cf350..6392366 100644 --- a/src/wol.rs +++ b/src/wol.rs @@ -2,26 +2,6 @@ use std::net::{ToSocketAddrs, UdpSocket}; use crate::error::Error; -/// Creates the magic packet from a mac address -/// -/// # Panics -/// -/// Panics if `mac_addr` is an invalid mac -pub fn create_buffer(mac_addr: &str) -> Result, Error> { - let mut mac = Vec::new(); - let sp = mac_addr.split(':'); - for f in sp { - mac.push(u8::from_str_radix(f, 16)?); - } - let mut buf = vec![255; 6]; - for _ in 0..16 { - for i in &mac { - buf.push(*i); - } - } - Ok(buf) -} - /// Sends a buffer on UDP broadcast pub fn send_packet( bind_addr: A, -- cgit v1.2.3