feat: added a route to return discord usernames.

Closes #19
This commit is contained in:
silver 2023-08-27 20:33:43 +01:00
parent ce471ad39a
commit 92fad0dc4b
8 changed files with 352 additions and 122 deletions

369
Cargo.lock generated
View file

@ -56,17 +56,6 @@ dependencies = [
"opaque-debug", "opaque-debug",
] ]
[[package]]
name = "ahash"
version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47"
dependencies = [
"getrandom 0.2.9",
"once_cell",
"version_check",
]
[[package]] [[package]]
name = "ahash" name = "ahash"
version = "0.8.3" version = "0.8.3"
@ -74,6 +63,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
"getrandom 0.2.9",
"once_cell", "once_cell",
"version_check", "version_check",
] ]
@ -216,18 +206,6 @@ dependencies = [
"event-listener", "event-listener",
] ]
[[package]]
name = "async-native-tls"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d57d4cec3c647232e1094dc013546c0b33ce785d8aeb251e1f20dfaf8a9a13fe"
dependencies = [
"futures-util",
"native-tls",
"thiserror",
"url",
]
[[package]] [[package]]
name = "async-process" name = "async-process"
version = "1.7.0" version = "1.7.0"
@ -328,9 +306,9 @@ dependencies = [
[[package]] [[package]]
name = "atoi" name = "atoi"
version = "1.0.0" version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7c57d12312ff59c811c0643f4d80830505833c9ffaebd193d819392b265be8e" checksum = "f28d99ec8bfea296261ca1af174f24225171fea9664ba9003cbebee704810528"
dependencies = [ dependencies = [
"num-traits", "num-traits",
] ]
@ -398,6 +376,15 @@ version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bitflags"
version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635"
dependencies = [
"serde",
]
[[package]] [[package]]
name = "blake3" name = "blake3"
version = "0.3.8" version = "0.3.8"
@ -558,7 +545,7 @@ checksum = "03a5d7b21829bc7b4bf4754a978a241ae54ea55a40f92bb20216e54096f4b951"
dependencies = [ dependencies = [
"aes-gcm", "aes-gcm",
"base64 0.13.1", "base64 0.13.1",
"hkdf", "hkdf 0.10.0",
"hmac 0.10.1", "hmac 0.10.1",
"percent-encoding", "percent-encoding",
"rand 0.8.5", "rand 0.8.5",
@ -779,6 +766,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fffa369a668c8af7dbf8b5e56c9f744fbd399949ed171606040001947de40b1c" checksum = "fffa369a668c8af7dbf8b5e56c9f744fbd399949ed171606040001947de40b1c"
dependencies = [ dependencies = [
"const-oid", "const-oid",
"pem-rfc7468",
"zeroize", "zeroize",
] ]
@ -870,6 +858,9 @@ name = "either"
version = "1.8.1" version = "1.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91"
dependencies = [
"serde",
]
[[package]] [[package]]
name = "elliptic-curve" name = "elliptic-curve"
@ -915,6 +906,12 @@ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
] ]
[[package]]
name = "equivalent"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
[[package]] [[package]]
name = "erased-serde" name = "erased-serde"
version = "0.3.25" version = "0.3.25"
@ -945,6 +942,17 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "etcetera"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "136d1b5283a1ab77bd9257427ffd09d8667ced0570b6f938942bc7568ed5b943"
dependencies = [
"cfg-if 1.0.0",
"home",
"windows-sys 0.48.0",
]
[[package]] [[package]]
name = "event-listener" name = "event-listener"
version = "2.5.3" version = "2.5.3"
@ -1089,9 +1097,9 @@ dependencies = [
[[package]] [[package]]
name = "futures-intrusive" name = "futures-intrusive"
version = "0.4.2" version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a604f7a68fbf8103337523b1fadc8ade7361ee3f112f7c680ad179651616aed5" checksum = "1d930c203dd0b6ff06e0201a4a2fe9149b43c684fd4420555b26d21b1a02956f"
dependencies = [ dependencies = [
"futures-core", "futures-core",
"lock_api", "lock_api",
@ -1226,21 +1234,21 @@ dependencies = [
"subtle", "subtle",
] ]
[[package]]
name = "hashbrown"
version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
[[package]] [[package]]
name = "hashbrown" name = "hashbrown"
version = "0.13.2" version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e"
dependencies = [ dependencies = [
"ahash 0.8.3", "ahash",
] ]
[[package]]
name = "hashbrown"
version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a"
[[package]] [[package]]
name = "hashlink" name = "hashlink"
version = "0.8.2" version = "0.8.2"
@ -1281,6 +1289,15 @@ dependencies = [
"hmac 0.10.1", "hmac 0.10.1",
] ]
[[package]]
name = "hkdf"
version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "791a029f6b9fc27657f6f188ec6e5e43f6911f6f878e0dc5501396e09809d437"
dependencies = [
"hmac 0.12.1",
]
[[package]] [[package]]
name = "hmac" name = "hmac"
version = "0.8.1" version = "0.8.1"
@ -1310,6 +1327,15 @@ dependencies = [
"digest 0.10.7", "digest 0.10.7",
] ]
[[package]]
name = "home"
version = "0.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5444c27eef6923071f7ebcc33e3444508466a76f7a2b93da00ed6e19f30c1ddb"
dependencies = [
"windows-sys 0.48.0",
]
[[package]] [[package]]
name = "hostname" name = "hostname"
version = "0.3.1" version = "0.3.1"
@ -1415,12 +1441,12 @@ dependencies = [
[[package]] [[package]]
name = "indexmap" name = "indexmap"
version = "1.9.3" version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d"
dependencies = [ dependencies = [
"autocfg", "equivalent",
"hashbrown 0.12.3", "hashbrown 0.14.0",
] ]
[[package]] [[package]]
@ -1604,9 +1630,9 @@ dependencies = [
[[package]] [[package]]
name = "libsqlite3-sys" name = "libsqlite3-sys"
version = "0.24.2" version = "0.26.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "898745e570c7d0453cc1fbc4a701eb6c662ed54e8fec8b7d14be137ebeeb9d14" checksum = "afc22eff61b133b115c6e8c74e818c628d6d5e7a502afea6f64dee076dd94326"
dependencies = [ dependencies = [
"cc", "cc",
"pkg-config", "pkg-config",
@ -1680,6 +1706,15 @@ dependencies = [
"syn 1.0.109", "syn 1.0.109",
] ]
[[package]]
name = "md-5"
version = "0.10.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6365506850d44bff6e2fbcb5176cf63650e48bd45ef2fe2665ae1570e0f4b9ca"
dependencies = [
"digest 0.10.7",
]
[[package]] [[package]]
name = "memchr" name = "memchr"
version = "2.5.0" version = "2.5.0"
@ -1814,7 +1849,7 @@ version = "0.10.52"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "01b8574602df80f7b85fdfc5392fa884a4e3b3f4f35402c070ab34c3d3f78d56" checksum = "01b8574602df80f7b85fdfc5392fa884a4e3b3f4f35402c070ab34c3d3f78d56"
dependencies = [ dependencies = [
"bitflags", "bitflags 1.3.2",
"cfg-if 1.0.0", "cfg-if 1.0.0",
"foreign-types", "foreign-types",
"libc", "libc",
@ -1884,27 +1919,25 @@ checksum = "14f2252c834a40ed9bb5422029649578e63aa341ac401f74e719dd1afda8394e"
[[package]] [[package]]
name = "parking_lot" name = "parking_lot"
version = "0.11.2" version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f"
dependencies = [ dependencies = [
"instant",
"lock_api", "lock_api",
"parking_lot_core", "parking_lot_core",
] ]
[[package]] [[package]]
name = "parking_lot_core" name = "parking_lot_core"
version = "0.8.6" version = "0.9.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc" checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
"instant",
"libc", "libc",
"redox_syscall 0.2.16", "redox_syscall",
"smallvec", "smallvec",
"winapi", "windows-targets 0.48.0",
] ]
[[package]] [[package]]
@ -2006,7 +2039,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4b2d323e8ca7996b3e23126511a523f7e62924d93ecd5ae73b333815b0eb3dce" checksum = "4b2d323e8ca7996b3e23126511a523f7e62924d93ecd5ae73b333815b0eb3dce"
dependencies = [ dependencies = [
"autocfg", "autocfg",
"bitflags", "bitflags 1.3.2",
"cfg-if 1.0.0", "cfg-if 1.0.0",
"concurrent-queue", "concurrent-queue",
"libc", "libc",
@ -2166,22 +2199,13 @@ dependencies = [
"rand_core 0.5.1", "rand_core 0.5.1",
] ]
[[package]]
name = "redox_syscall"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a"
dependencies = [
"bitflags",
]
[[package]] [[package]]
name = "redox_syscall" name = "redox_syscall"
version = "0.3.5" version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29"
dependencies = [ dependencies = [
"bitflags", "bitflags 1.3.2",
] ]
[[package]] [[package]]
@ -2247,7 +2271,7 @@ version = "0.37.19"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acf8729d8542766f1b2cf77eb034d52f40d375bb8b615d0b147089946e16613d" checksum = "acf8729d8542766f1b2cf77eb034d52f40d375bb8b615d0b147089946e16613d"
dependencies = [ dependencies = [
"bitflags", "bitflags 1.3.2",
"errno", "errno",
"io-lifetimes", "io-lifetimes",
"libc", "libc",
@ -2296,7 +2320,7 @@ version = "2.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fc758eb7bffce5b308734e9b0c1468893cae9ff70ebf13e7090be8dcbcc83a8" checksum = "1fc758eb7bffce5b308734e9b0c1468893cae9ff70ebf13e7090be8dcbcc83a8"
dependencies = [ dependencies = [
"bitflags", "bitflags 1.3.2",
"core-foundation", "core-foundation",
"core-foundation-sys", "core-foundation-sys",
"libc", "libc",
@ -2587,23 +2611,27 @@ dependencies = [
[[package]] [[package]]
name = "sqlx" name = "sqlx"
version = "0.6.3" version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8de3b03a925878ed54a954f621e64bf55a3c1bd29652d0d1a17830405350188" checksum = "8e58421b6bc416714d5115a2ca953718f6c621a51b68e4f4922aea5a4391a721"
dependencies = [ dependencies = [
"sqlx-core", "sqlx-core",
"sqlx-macros", "sqlx-macros",
"sqlx-mysql",
"sqlx-postgres",
"sqlx-sqlite",
] ]
[[package]] [[package]]
name = "sqlx-core" name = "sqlx-core"
version = "0.6.3" version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa8241483a83a3f33aa5fff7e7d9def398ff9990b2752b6c6112b83c6d246029" checksum = "dd4cef4251aabbae751a3710927945901ee1d97ee96d757f6880ebb9a79bfd53"
dependencies = [ dependencies = [
"ahash 0.7.6", "ahash",
"async-io",
"async-std",
"atoi", "atoi",
"bitflags",
"byteorder", "byteorder",
"bytes 1.4.0", "bytes 1.4.0",
"crc", "crc",
@ -2611,62 +2639,171 @@ dependencies = [
"dotenvy", "dotenvy",
"either", "either",
"event-listener", "event-listener",
"futures-channel",
"futures-core",
"futures-intrusive",
"futures-io",
"futures-util",
"hashlink",
"hex",
"indexmap",
"log",
"memchr",
"native-tls",
"once_cell",
"paste",
"percent-encoding",
"serde",
"serde_json",
"sha2 0.10.7",
"smallvec",
"sqlformat",
"thiserror",
"tracing",
"url",
]
[[package]]
name = "sqlx-macros"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "208e3165167afd7f3881b16c1ef3f2af69fa75980897aac8874a0696516d12c2"
dependencies = [
"proc-macro2",
"quote",
"sqlx-core",
"sqlx-macros-core",
"syn 1.0.109",
]
[[package]]
name = "sqlx-macros-core"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a4a8336d278c62231d87f24e8a7a74898156e34c1c18942857be2acb29c7dfc"
dependencies = [
"async-std",
"dotenvy",
"either",
"heck",
"hex",
"once_cell",
"proc-macro2",
"quote",
"serde",
"serde_json",
"sha2 0.10.7",
"sqlx-core",
"sqlx-mysql",
"sqlx-sqlite",
"syn 1.0.109",
"tempfile",
"url",
]
[[package]]
name = "sqlx-mysql"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ca69bf415b93b60b80dc8fda3cb4ef52b2336614d8da2de5456cc942a110482"
dependencies = [
"atoi",
"base64 0.21.2",
"bitflags 2.4.0",
"byteorder",
"bytes 1.4.0",
"crc",
"digest 0.10.7",
"dotenvy",
"either",
"futures-channel",
"futures-core",
"futures-io",
"futures-util",
"generic-array",
"hex",
"hkdf 0.12.3",
"hmac 0.12.1",
"itoa",
"log",
"md-5",
"memchr",
"once_cell",
"percent-encoding",
"rand 0.8.5",
"rsa",
"serde",
"sha1 0.10.5",
"sha2 0.10.7",
"smallvec",
"sqlx-core",
"stringprep",
"thiserror",
"tracing",
"whoami",
]
[[package]]
name = "sqlx-postgres"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a0db2df1b8731c3651e204629dd55e52adbae0462fa1bdcbed56a2302c18181e"
dependencies = [
"atoi",
"base64 0.21.2",
"bitflags 2.4.0",
"byteorder",
"crc",
"dotenvy",
"etcetera",
"futures-channel",
"futures-core",
"futures-io",
"futures-util",
"hex",
"hkdf 0.12.3",
"hmac 0.12.1",
"home",
"itoa",
"log",
"md-5",
"memchr",
"once_cell",
"rand 0.8.5",
"serde",
"serde_json",
"sha1 0.10.5",
"sha2 0.10.7",
"smallvec",
"sqlx-core",
"stringprep",
"thiserror",
"tracing",
"whoami",
]
[[package]]
name = "sqlx-sqlite"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be4c21bf34c7cae5b283efb3ac1bcc7670df7561124dc2f8bdc0b59be40f79a2"
dependencies = [
"atoi",
"flume 0.10.14", "flume 0.10.14",
"futures-channel", "futures-channel",
"futures-core", "futures-core",
"futures-executor", "futures-executor",
"futures-intrusive", "futures-intrusive",
"futures-util", "futures-util",
"hashlink",
"hex",
"indexmap",
"itoa",
"libc",
"libsqlite3-sys", "libsqlite3-sys",
"log", "log",
"memchr",
"once_cell",
"paste",
"percent-encoding", "percent-encoding",
"sha2 0.10.7", "serde",
"smallvec",
"sqlformat",
"sqlx-rt",
"stringprep",
"thiserror",
"url",
]
[[package]]
name = "sqlx-macros"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9966e64ae989e7e575b19d7265cb79d7fc3cbbdf179835cb0d716f294c2049c9"
dependencies = [
"dotenvy",
"either",
"heck",
"once_cell",
"proc-macro2",
"quote",
"sha2 0.10.7",
"sqlx-core", "sqlx-core",
"sqlx-rt", "tracing",
"syn 1.0.109",
"url", "url",
] ]
[[package]]
name = "sqlx-rt"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "804d3f245f894e61b1e6263c84b23ca675d96753b5abfd5cc8597d86806e8024"
dependencies = [
"async-native-tls",
"async-std",
"native-tls",
]
[[package]] [[package]]
name = "ssh-cipher" name = "ssh-cipher"
version = "0.2.0" version = "0.2.0"
@ -2847,7 +2984,7 @@ checksum = "b9fbec84f381d5795b08656e4912bec604d162bff9291d6189a78f4c8ab87998"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
"fastrand", "fastrand",
"redox_syscall 0.3.5", "redox_syscall",
"rustix", "rustix",
"windows-sys 0.45.0", "windows-sys 0.45.0",
] ]
@ -3262,6 +3399,12 @@ dependencies = [
"wasm-bindgen", "wasm-bindgen",
] ]
[[package]]
name = "whoami"
version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22fc3756b8a9133049b26c7f61ab35416c130e8c09b660f5b3958b446f52cc50"
[[package]] [[package]]
name = "winapi" name = "winapi"
version = "0.3.9" version = "0.3.9"

View file

@ -23,7 +23,7 @@ async-std = { version = "1.12.0", features = ["attributes"] }
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
# For sqlite # For sqlite
sqlx = { version = "0.6.3", features = [ "runtime-async-std-native-tls", "sqlite" ] } sqlx = { version = "0.7.1", features = [ "runtime-async-std-native-tls", "sqlite" ] }
# to make the http requests # to make the http requests
surf = "2.3.2" surf = "2.3.2"

View file

@ -114,9 +114,15 @@
enable = mkEnableOption "enable ${package_name}"; enable = mkEnableOption "enable ${package_name}";
# keep really secret stuff in this # keep really secret stuff in this
envFile = mkOption rec { env = {
type = types.str; ldap = mkOption rec {
description = "The env file"; type = types.str;
description = "Auth for the LDAP, has LDAP_ADMIN_PW";
};
discord = mkOption rec {
type = types.str;
description = "Auth for the discord bot, has LDAP_DISCORD_AUTH";
};
}; };
ldap = { ldap = {
@ -222,7 +228,11 @@
Group = "${cfg.user}"; Group = "${cfg.user}";
Restart = "always"; Restart = "always";
ExecStart = "${self.defaultPackage."${system}"}/bin/${package_name}"; ExecStart = "${self.defaultPackage."${system}"}/bin/${package_name}";
EnvironmentFile = "${cfg.envFile}"; # multiple files
EnvironmentFile = [
"${cfg.env.ldap}"
"${cfg.env.discord}"
];
}; };
}; };
} // serviceGenerator scripts; } // serviceGenerator scripts;

View file

@ -189,6 +189,7 @@ pub struct Config {
pub mail_user: String, pub mail_user: String,
pub mail_pass: String, pub mail_pass: String,
pub ssh_root: String, pub ssh_root: String,
pub auth_discord: String,
} }
pub fn get_config() -> Config { pub fn get_config() -> Config {
@ -207,6 +208,7 @@ pub fn get_config() -> Config {
mail_user: "".to_string(), mail_user: "".to_string(),
mail_pass: "".to_string(), mail_pass: "".to_string(),
ssh_root: "skynet_old".to_string(), ssh_root: "skynet_old".to_string(),
auth_discord: "".to_string(),
}; };
if let Ok(x) = env::var("LDAP_HOST") { if let Ok(x) = env::var("LDAP_HOST") {
@ -242,6 +244,9 @@ pub fn get_config() -> Config {
if let Ok(x) = env::var("SSH_ROOT") { if let Ok(x) = env::var("SSH_ROOT") {
config.ssh_root = x.trim().to_string(); config.ssh_root = x.trim().to_string();
} }
if let Ok(x) = env::var("LDAP_DISCORD_AUTH") {
config.auth_discord = x.trim().to_string();
}
config config
} }

View file

@ -1,6 +1,6 @@
use skynet_ldap_backend::{ use skynet_ldap_backend::{
db_init, get_config, db_init, get_config,
methods::{account_new, account_recover, account_update}, methods::{account_new, account_recover, account_update, discord},
State, State,
}; };
@ -34,6 +34,9 @@ async fn main() -> tide::Result<()> {
app.at("/ldap/recover/ssh/request").post(account_recover::ssh::request); app.at("/ldap/recover/ssh/request").post(account_recover::ssh::request);
app.at("/ldap/recover/ssh/verify").post(account_recover::ssh::verify); app.at("/ldap/recover/ssh/verify").post(account_recover::ssh::verify);
// for discord
app.at("/ldap/discord").get(discord::account::get);
app.listen(host_port).await?; app.listen(host_port).await?;
Ok(()) Ok(())
} }

View file

@ -1,4 +1,4 @@
use crate::{methods::account_new::email::get_wolves_mail, update_group, Config, State}; use crate::{methods::account_new::email::get_wolves_mail, update_group, Accounts, Config, State};
use ldap3::{exop::PasswordModify, LdapConn, Mod, Scope, SearchEntry}; use ldap3::{exop::PasswordModify, LdapConn, Mod, Scope, SearchEntry};
use sqlx::{Pool, Sqlite}; use sqlx::{Pool, Sqlite};
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
@ -77,7 +77,7 @@ pub async fn submit(mut req: Request<State>) -> tide::Result {
// if password is not being updated then just update the required field // if password is not being updated then just update the required field
let mods = vec![ let mods = vec![
// the value we are updating // the value we are updating
Mod::Replace(field, HashSet::from([value])), Mod::Replace(field.clone(), HashSet::from([value.clone()])),
]; ];
ldap.modify(&dn, mods)?.success()?; ldap.modify(&dn, mods)?.success()?;
@ -88,7 +88,7 @@ pub async fn submit(mut req: Request<State>) -> tide::Result {
} else { } else {
// password is going to be updated, even if the old value is not starting with "{SSHA512}" // password is going to be updated, even if the old value is not starting with "{SSHA512}"
pw_keep_same = false; pw_keep_same = false;
value value.clone()
}; };
// changing teh password because of an explicit request or upgrading teh security. // changing teh password because of an explicit request or upgrading teh security.
@ -108,6 +108,14 @@ pub async fn submit(mut req: Request<State>) -> tide::Result {
ldap.unbind()?; ldap.unbind()?;
// if its mail or discord update the local db
if &field == "skDiscord" {
update_local_db(db, "discord", &value).await.ok();
}
if &field == "mail" {
update_local_db(db, "mail", &value).await.ok();
}
Ok(json!({"result": "success", "success": result}).into()) Ok(json!({"result": "success", "success": result}).into())
} }
@ -152,3 +160,8 @@ async fn activate_group(db: &Pool<Sqlite>, config: &Config, user: &str, mail: &s
} }
} }
} }
async fn update_local_db(db: &Pool<Sqlite>, field: &str, value: &str) -> Result<Option<Accounts>, sqlx::Error> {
let query = format!("INSERT OR REPLACE INTO accounts ({field}) VALUES (?1)");
sqlx::query_as::<_, Accounts>(&query).bind(value.to_owned()).fetch_optional(db).await
}

55
src/methods/discord.rs Normal file
View file

@ -0,0 +1,55 @@
use crate::{Accounts, State};
use sqlx::{Pool, Sqlite};
use tide::{
prelude::{json, Deserialize},
Request,
};
pub mod account {
use super::*;
#[derive(Debug, Deserialize)]
struct Auth {
auth: String,
}
pub async fn get(req: Request<State>) -> tide::Result {
let config = &req.state().config;
if let Ok(auth) = req.query::<Auth>() {
if auth.auth != config.auth_discord {
return Ok(json!([]).into());
}
} else {
return Ok(json!([]).into());
};
let db = &req.state().db;
let result = get_wolves_mail(db).await;
Ok(json!(result).into())
}
pub async fn get_wolves_mail(db: &Pool<Sqlite>) -> Vec<String> {
let results = sqlx::query_as::<_, Accounts>(
r#"
SELECT *
FROM accounts
WHERE discord IS NOT NULL AND enabled = 1
"#,
)
.fetch_all(db)
.await
.unwrap_or(vec![]);
let mut result = vec![];
for item in results {
if let Some(discord) = item.discord {
result.push(discord);
}
}
result
}
}

View file

@ -1,3 +1,4 @@
pub mod account_new; pub mod account_new;
pub mod account_recover; pub mod account_recover;
pub mod account_update; pub mod account_update;
pub mod discord;