Compare commits

...

31 commits

Author SHA1 Message Date
13e1d73029 Merge pull request 'Bump forgejo-release to v2' (#6) from actions-update into main
All checks were successful
Run Tests on Code / run-tests (push) Successful in 13s
Reviewed-on: https://forgejo.neshweb.net///Neshura/domainlink/pulls/6
2024-08-06 12:31:33 +00:00
a6c4e25702 Bump forgejo-release to v2
All checks were successful
Run Tests on Code / run-tests (push) Successful in 48s
Build binary file and bundle packages / test (pull_request) Successful in 2m5s
Build binary file and bundle packages / build (pull_request) Successful in 4m50s
2024-08-06 12:27:57 +00:00
fec128243c
Release 1.0.3
All checks were successful
Run Tests on Code / run-tests (push) Successful in 33s
Build and release binary file and packages / test (push) Successful in 12s
Build and release binary file and packages / build (push) Successful in 46s
Build and release binary file and packages / upload-generic-package (push) Successful in 1s
Build and release binary file and packages / upload-debian-package (push) Successful in 1s
Build and release binary file and packages / create-release (push) Successful in 7s
2024-04-10 23:32:57 +02:00
ed4ca5899a
Bugfix for previous Logging change
All checks were successful
Run Tests on Code / run-tests (push) Successful in 13s
2024-04-10 23:32:43 +02:00
7cb109018d
Release 1.0.2
All checks were successful
Run Tests on Code / run-tests (push) Successful in 36s
Build and release binary file and packages / upload-generic-package (push) Successful in 1s
Build and release binary file and packages / create-release (push) Successful in 7s
Build and release binary file and packages / test (push) Successful in 35s
Build and release binary file and packages / build (push) Successful in 47s
Build and release binary file and packages / upload-debian-package (push) Successful in 1s
2024-04-10 23:29:55 +02:00
c2bf7cc4ae
Only Output "Using domains.toml" when config contains any redirects
All checks were successful
Run Tests on Code / run-tests (push) Successful in 12s
2024-04-10 23:29:43 +02:00
add30dcfdd
Updated Readme
All checks were successful
Run Tests on Code / run-tests (push) Successful in 13s
2024-04-10 23:28:23 +02:00
55748f30fb
Release 1.0.1
All checks were successful
Run Tests on Code / run-tests (push) Successful in 31s
Build and release binary file and packages / test (push) Successful in 11s
Build and release binary file and packages / build (push) Successful in 48s
Build and release binary file and packages / upload-generic-package (push) Successful in 1s
Build and release binary file and packages / upload-debian-package (push) Successful in 1s
Build and release binary file and packages / create-release (push) Successful in 7s
2024-04-10 23:26:16 +02:00
7b7353997d
Removed Debug Logging 2024-04-10 23:26:11 +02:00
76a567d1bf
Add duplicate domain check, closes #5
All checks were successful
Run Tests on Code / run-tests (push) Successful in 13s
2024-04-10 23:22:11 +02:00
a028d4245b
Revert previous
All checks were successful
Run Tests on Code / run-tests (push) Successful in 13s
2024-04-10 23:00:33 +02:00
3850f4eb3e
Add concurrent test ci runs
All checks were successful
Run Tests on Code / run-tests (push) Successful in 19s
2024-04-10 22:56:11 +02:00
f21af696c4
Release 1.0.0
All checks were successful
Run Tests on Code / run-tests (push) Successful in 36s
Build and release binary file and packages / test (push) Successful in 36s
Build and release binary file and packages / build (push) Successful in 48s
Build and release binary file and packages / upload-generic-package (push) Successful in 1s
Build and release binary file and packages / upload-debian-package (push) Successful in 1s
Build and release binary file and packages / create-release (push) Successful in 8s
2024-04-10 22:50:39 +02:00
6d084c671a
Fix ownership issues caused by confy when interacting with other users' config directory. Closes #1
All checks were successful
Run Tests on Code / run-tests (push) Successful in 19s
2024-04-10 22:50:25 +02:00
d0eb4b793c
Release 0.5.0
All checks were successful
Run Tests on Code / run-tests (push) Successful in 37s
Build and release binary file and packages / test (push) Successful in 35s
Build and release binary file and packages / build (push) Successful in 47s
Build and release binary file and packages / upload-generic-package (push) Successful in 1s
Build and release binary file and packages / upload-debian-package (push) Successful in 1s
Build and release binary file and packages / create-release (push) Successful in 13s
2024-04-10 22:22:29 +02:00
bf3c0102a1
Release Candidate 0.5.0-rc.1
All checks were successful
Run Tests on Code / run-tests (push) Successful in 46s
Build and release binary file and packages / test (push) Successful in 38s
Build and release binary file and packages / build (push) Successful in 59s
Build and release binary file and packages / upload-generic-package (push) Successful in 1s
Build and release binary file and packages / upload-debian-package (push) Successful in 1s
Build and release binary file and packages / create-release (push) Successful in 19s
2024-04-10 22:20:10 +02:00
028067b62a
Add hot reloading of redirect config files
All checks were successful
Run Tests on Code / run-tests (push) Successful in 47s
2024-04-10 22:19:50 +02:00
20af5172b4
Refactored User Config loading, closes #3
All checks were successful
Run Tests on Code / run-tests (push) Successful in 11s
2024-04-10 18:55:17 +02:00
e1260877b6
Replaced /dry route with a more general /status route
All checks were successful
Run Tests on Code / run-tests (push) Successful in 19s
2024-04-10 18:54:21 +02:00
7b3115f5cf Update README.md
All checks were successful
Run Tests on Code / run-tests (push) Successful in 12s
2024-04-09 11:32:53 +00:00
5fcdddde03
Updated Readme
All checks were successful
Run Tests on Code / run-tests (push) Successful in 12s
2024-04-08 23:20:42 +02:00
5a46d3722b
Release 0.4.0
All checks were successful
Build and release binary file and packages / upload-debian-package (push) Successful in 1s
Run Tests on Code / run-tests (push) Successful in 34s
Build and release binary file and packages / test (push) Successful in 33s
Build and release binary file and packages / build (push) Successful in 42s
Build and release binary file and packages / upload-generic-package (push) Successful in 1s
Build and release binary file and packages / create-release (push) Successful in 7s
2024-04-08 23:07:14 +02:00
8e077609e9
remove protocol settings
All checks were successful
Run Tests on Code / run-tests (push) Successful in 12s
2024-04-08 23:05:33 +02:00
0b1ada9221
use domain vector instead of single string 2024-04-08 23:05:25 +02:00
c5f2f49c16
Release 0.3.1
All checks were successful
Run Tests on Code / run-tests (push) Successful in 33s
Build and release binary file and packages / test (push) Successful in 34s
Build and release binary file and packages / build (push) Successful in 41s
Build and release binary file and packages / upload-debian-package (push) Successful in 1s
Build and release binary file and packages / upload-generic-package (push) Successful in 1s
Build and release binary file and packages / create-release (push) Successful in 6s
2024-04-08 22:22:54 +02:00
9e7977b4cd
improved address/port listening info log
Some checks failed
Run Tests on Code / run-tests (push) Has been cancelled
2024-04-08 22:22:40 +02:00
38cfbdcfb8
Fix: stop checking config paths after finding a config file 2024-04-08 22:20:00 +02:00
bd7942430c
Release 0.3.0
All checks were successful
Run Tests on Code / run-tests (push) Successful in 33s
Build and release binary file and packages / test (push) Successful in 32s
Build and release binary file and packages / build (push) Successful in 41s
Build and release binary file and packages / upload-generic-package (push) Successful in 1s
Build and release binary file and packages / upload-debian-package (push) Successful in 1s
Build and release binary file and packages / create-release (push) Successful in 7s
2024-04-08 22:15:20 +02:00
9cb4dba537
Release Candidate 0.3.0-rc.1
All checks were successful
Run Tests on Code / run-tests (push) Successful in 33s
Build and release binary file and packages / test (push) Successful in 31s
Build and release binary file and packages / build (push) Successful in 42s
Build and release binary file and packages / upload-generic-package (push) Successful in 1s
Build and release binary file and packages / upload-debian-package (push) Successful in 1s
Build and release binary file and packages / create-release (push) Successful in 7s
2024-04-08 22:13:20 +02:00
abfa4237ed
Added default config to debian package + turned service file back into root run service
Some checks failed
Run Tests on Code / run-tests (push) Has been cancelled
2024-04-08 22:12:54 +02:00
483fe1e649
implemented split user/system config with unified service at the top due to port conflicts 2024-04-08 22:12:22 +02:00
7 changed files with 591 additions and 82 deletions

View file

@ -137,7 +137,7 @@ jobs:
run: rm release_blobs/build.env run: rm release_blobs/build.env
- -
name: Release New Version name: Release New Version
uses: actions/forgejo-release@v1 uses: actions/forgejo-release@v2
with: with:
direction: upload direction: upload
url: https://forgejo.neshweb.net url: https://forgejo.neshweb.net

282
Cargo.lock generated
View file

@ -333,6 +333,18 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "confy"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "45b1f4c00870f07dc34adcac82bb6a72cc5aabca8536ba1797e01df51d2ce9a0"
dependencies = [
"directories",
"serde",
"thiserror",
"toml",
]
[[package]] [[package]]
name = "convert_case" name = "convert_case"
version = "0.4.0" version = "0.4.0"
@ -368,6 +380,21 @@ dependencies = [
"cfg-if", "cfg-if",
] ]
[[package]]
name = "crossbeam-channel"
version = "0.5.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab3db02a9c5b5121e1e42fbdb1aeb65f5e02624cc58c43f2884c6ccac0b82f95"
dependencies = [
"crossbeam-utils",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345"
[[package]] [[package]]
name = "crypto-common" name = "crypto-common"
version = "0.1.6" version = "0.1.6"
@ -410,12 +437,36 @@ dependencies = [
"crypto-common", "crypto-common",
] ]
[[package]]
name = "directories"
version = "5.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a49173b84e034382284f27f1af4dcbbd231ffa358c0fe316541a7337f376a35"
dependencies = [
"dirs-sys",
]
[[package]]
name = "dirs-sys"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c"
dependencies = [
"libc",
"option-ext",
"redox_users",
"windows-sys 0.48.0",
]
[[package]] [[package]]
name = "domainlink" name = "domainlink"
version = "0.2.0-rc.2" version = "1.0.3"
dependencies = [ dependencies = [
"actix-web", "actix-web",
"confy",
"log", "log",
"notify",
"serde",
"systemd-journal-logger", "systemd-journal-logger",
] ]
@ -444,6 +495,18 @@ dependencies = [
"windows-sys 0.52.0", "windows-sys 0.52.0",
] ]
[[package]]
name = "filetime"
version = "0.2.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ee447700ac8aa0b2f2bd7bc4462ad686ba06baa6727ac149a2d6277f0d240fd"
dependencies = [
"cfg-if",
"libc",
"redox_syscall",
"windows-sys 0.52.0",
]
[[package]] [[package]]
name = "flate2" name = "flate2"
version = "1.0.28" version = "1.0.28"
@ -469,6 +532,15 @@ dependencies = [
"percent-encoding", "percent-encoding",
] ]
[[package]]
name = "fsevent-sys"
version = "4.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76ee7a02da4d231650c7cea31349b889be2f45ddb3ef3032d2ec8185f6313fd2"
dependencies = [
"libc",
]
[[package]] [[package]]
name = "futures-core" name = "futures-core"
version = "0.3.30" version = "0.3.30"
@ -594,6 +666,26 @@ dependencies = [
"hashbrown", "hashbrown",
] ]
[[package]]
name = "inotify"
version = "0.9.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8069d3ec154eb856955c1c0fbffefbf5f3c40a104ec912d4797314c1801abff"
dependencies = [
"bitflags 1.3.2",
"inotify-sys",
"libc",
]
[[package]]
name = "inotify-sys"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e05c02b5e89bff3b946cedeca278abc628fe811e604f027c45a8aa3cf793d0eb"
dependencies = [
"libc",
]
[[package]] [[package]]
name = "itoa" name = "itoa"
version = "1.0.11" version = "1.0.11"
@ -609,6 +701,26 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "kqueue"
version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7447f1ca1b7b563588a205fe93dea8df60fd981423a768bc1c0ded35ed147d0c"
dependencies = [
"kqueue-sys",
"libc",
]
[[package]]
name = "kqueue-sys"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed9625ffda8729b85e45cf04090035ac368927b8cebc34898e7c120f52e4838b"
dependencies = [
"bitflags 1.3.2",
"libc",
]
[[package]] [[package]]
name = "language-tags" name = "language-tags"
version = "0.3.2" version = "0.3.2"
@ -621,6 +733,16 @@ version = "0.2.153"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
[[package]]
name = "libredox"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d"
dependencies = [
"bitflags 2.5.0",
"libc",
]
[[package]] [[package]]
name = "linux-raw-sys" name = "linux-raw-sys"
version = "0.4.13" version = "0.4.13"
@ -696,6 +818,25 @@ dependencies = [
"windows-sys 0.48.0", "windows-sys 0.48.0",
] ]
[[package]]
name = "notify"
version = "6.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6205bd8bb1e454ad2e27422015fb5e4f2bcc7e08fa8f27058670d208324a4d2d"
dependencies = [
"bitflags 2.5.0",
"crossbeam-channel",
"filetime",
"fsevent-sys",
"inotify",
"kqueue",
"libc",
"log",
"mio",
"walkdir",
"windows-sys 0.48.0",
]
[[package]] [[package]]
name = "num-conv" name = "num-conv"
version = "0.1.0" version = "0.1.0"
@ -717,6 +858,12 @@ version = "1.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
[[package]]
name = "option-ext"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
[[package]] [[package]]
name = "parking_lot" name = "parking_lot"
version = "0.12.1" version = "0.12.1"
@ -839,6 +986,17 @@ dependencies = [
"bitflags 1.3.2", "bitflags 1.3.2",
] ]
[[package]]
name = "redox_users"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd283d9651eeda4b2a83a43c1c91b266c40fd76ecd39a50a8c630ae69dc72891"
dependencies = [
"getrandom",
"libredox",
"thiserror",
]
[[package]] [[package]]
name = "regex" name = "regex"
version = "1.10.4" version = "1.10.4"
@ -902,6 +1060,15 @@ version = "1.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1"
[[package]]
name = "same-file"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
dependencies = [
"winapi-util",
]
[[package]] [[package]]
name = "scopeguard" name = "scopeguard"
version = "1.2.0" version = "1.2.0"
@ -945,6 +1112,15 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "serde_spanned"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1"
dependencies = [
"serde",
]
[[package]] [[package]]
name = "serde_urlencoded" name = "serde_urlencoded"
version = "0.7.1" version = "0.7.1"
@ -1034,6 +1210,26 @@ dependencies = [
"rustix", "rustix",
] ]
[[package]]
name = "thiserror"
version = "1.0.58"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.58"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.58",
]
[[package]] [[package]]
name = "time" name = "time"
version = "0.3.34" version = "0.3.34"
@ -1111,6 +1307,40 @@ dependencies = [
"tracing", "tracing",
] ]
[[package]]
name = "toml"
version = "0.8.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e9dd1545e8208b4a5af1aa9bbd0b4cf7e9ea08fabc5d0a5c67fcaafa17433aa3"
dependencies = [
"serde",
"serde_spanned",
"toml_datetime",
"toml_edit",
]
[[package]]
name = "toml_datetime"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1"
dependencies = [
"serde",
]
[[package]]
name = "toml_edit"
version = "0.22.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e40bb779c5187258fd7aad0eb68cb8706a0a81fa712fbea808ab43c4b8374c4"
dependencies = [
"indexmap",
"serde",
"serde_spanned",
"toml_datetime",
"winnow",
]
[[package]] [[package]]
name = "tracing" name = "tracing"
version = "0.1.40" version = "0.1.40"
@ -1181,12 +1411,53 @@ version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "walkdir"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b"
dependencies = [
"same-file",
"winapi-util",
]
[[package]] [[package]]
name = "wasi" name = "wasi"
version = "0.11.0+wasi-snapshot-preview1" version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-util"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596"
dependencies = [
"winapi",
]
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]] [[package]]
name = "windows-sys" name = "windows-sys"
version = "0.48.0" version = "0.48.0"
@ -1319,6 +1590,15 @@ version = "0.52.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8"
[[package]]
name = "winnow"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dffa400e67ed5a4dd237983829e66475f0a4a26938c4b04c21baede6262215b8"
dependencies = [
"memchr",
]
[[package]] [[package]]
name = "zerocopy" name = "zerocopy"
version = "0.7.32" version = "0.7.32"

View file

@ -1,7 +1,7 @@
[package] [package]
authors = ["Neshura"] authors = ["Neshura"]
name = "domainlink" name = "domainlink"
version = "0.2.0-rc.2" version = "1.0.3"
edition = "2021" edition = "2021"
description = "Lightweight tool for handling (sub-)domain to URL redirects instead of having to deal with copy and pasting proxy rules" description = "Lightweight tool for handling (sub-)domain to URL redirects instead of having to deal with copy and pasting proxy rules"
license = "GPL-3.0-or-later" license = "GPL-3.0-or-later"
@ -16,6 +16,11 @@ assets = [
"target/release/domainlink", "target/release/domainlink",
"/usr/local/bin/domainlink", "/usr/local/bin/domainlink",
"755", "755",
],
[
"debian/app_config.toml",
"/usr/local/share/domainlink/config.toml",
"755",
] ]
] ]
systemd-units = { enable = false } systemd-units = { enable = false }
@ -24,5 +29,8 @@ systemd-units = { enable = false }
[dependencies] [dependencies]
actix-web = "4" actix-web = "4"
confy = "0.6"
log = "0.4" log = "0.4"
systemd-journal-logger = "2" notify = "6"
systemd-journal-logger = "2"
serde = { version = "1.0.197", features = ["derive"] }

View file

@ -1,3 +1,20 @@
# DomainLink # DomainLink
Lightweight tool for handling (sub-)domain to URL redirects instead of having to deal with copy and pasting proxy rules. Lightweight tool for handling (sub-)domain to URL redirects instead of having to deal with copy and pasting proxy rules.
#### System Configuration
The package provides a default configuration in `/usr/share/local/domainlink/config.toml`.
Modifying this is not recommended as updates may override any changes, instead make a copy at `/etc/domainlink/config.toml`.
Any changes there will persist updates and supersede the default config. The System Config only contains the settings for listen addresses and ports.
#### User Configuration
DomainLink currently expects redirect files to be placed in any home directory, specifically `/home/{user}/.config/domainlink/domains.toml` or `/root/.config/domainlink/domains.toml`.
Redirects are configured in an array, below is an example config.
```toml
[[domain_configs]]
domains = ["sub.domain.tld", "sub2.domain.tld"]
target = "https://sub.domain.tld/query"
```
By default, DomainLink does not create any redirect rules, you will have to create these yourself.

2
debian/app_config.toml vendored Normal file
View file

@ -0,0 +1,2 @@
ports = [80]
addresses = ["::"]

View file

@ -5,7 +5,6 @@ After=network-online.target
[Service] [Service]
Type=simple Type=simple
User=%i
ExecStart=/usr/local/bin/domainlink ExecStart=/usr/local/bin/domainlink
Restart=always Restart=always
RestartSec=3 RestartSec=3

View file

@ -1,8 +1,16 @@
use std::fmt::{Display, Formatter}; use std::error::Error;
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; use std::{fs, io};
use std::net::{IpAddr, Ipv6Addr};
use std::os::unix;
use std::os::unix::fs::MetadataExt;
use std::path::{Path, PathBuf};
use std::sync::RwLock;
use actix_web::{web, App, HttpResponse, HttpServer, get, Responder, HttpRequest}; use actix_web::{web, App, HttpResponse, HttpServer, get, Responder, HttpRequest};
use log::{LevelFilter}; use log::{LevelFilter};
use notify::{Event, EventKind, RecursiveMode, Watcher};
use notify::event::{AccessKind, AccessMode};
use systemd_journal_logger::{connected_to_journal, JournalLog}; use systemd_journal_logger::{connected_to_journal, JournalLog};
use serde::{Deserialize, Serialize};
macro_rules! info { macro_rules! info {
@ -32,93 +40,287 @@ macro_rules! error {
}; };
} }
#[derive(Clone)] #[derive(Clone, Serialize, Deserialize)]
enum Protocol {
Http,
Https
}
impl Display for Protocol {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Protocol::Http => write!(f, "http://"),
Protocol::Https => write!(f, "https://")
}
}
}
#[derive(Clone)]
struct DomainLinkConfig { struct DomainLinkConfig {
domain: String, domains: Vec<String>,
protocol: Protocol,
target: String, target: String,
} }
#[derive(Clone)] #[derive(Clone, Serialize, Deserialize, Default)]
struct Config { struct UserConfig {
redirects: Vec<DomainLinkConfig>, domain_configs: Vec<DomainLinkConfig>
}
#[derive(Clone, Serialize, Deserialize)]
struct SystemConfig {
ports: Vec<u16>, ports: Vec<u16>,
addresses: Vec<IpAddr>, addresses: Vec<IpAddr>,
} }
impl Default for SystemConfig {
fn default() -> Self {
Self {
ports: vec![8000],
addresses: vec![IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0))],
}
}
}
#[derive(Clone)]
struct Config {
user: UserConfig,
system: SystemConfig,
}
impl Config {
pub fn load() -> Result<(Self, Vec<PathBuf>), Box<dyn Error>> {
// get list of home directories
// query every home directory for a config file (just attempt a load, an empty config is perfectly fine)
// merge all configs into one
let mut directories: Vec<PathBuf> = vec![];
let mut user_config = UserConfig::default();
let root_contents = match fs::read_dir("/") {
Ok(contents) => { contents }
Err(e) => {
error!(e);
return Err(Box::new(e));
}
};
root_contents.for_each(|directory| {
let path = directory.expect("Unexpected Error while Unwrapping the listed Dir Entry").path();
if path.is_dir() {
match path.display().to_string().as_str() {
"/root" => {
let (mut root_configs, root_path) = Self::load_user_config_directory(path);
if let Some(root_directory) = root_path {
directories.push(Path::new(root_directory.as_str()).to_path_buf());
}
user_config.domain_configs.append(&mut root_configs.domain_configs);
},
"/home" => {
match fs::read_dir(path) {
Ok(home_contents) => {
home_contents.for_each(|home_folder| {
let home_folder_path = home_folder.expect("Unexpected Error while Unwrapping the listed Home Dir Entry").path();
if home_folder_path.is_dir() {
let (mut user_folder_configs, user_folder_path) = Self::load_user_config_directory(home_folder_path);
if let Some(user_folder_directory) = user_folder_path {
directories.push(Path::new(user_folder_directory.as_str()).to_path_buf());
}
user_config.domain_configs.append(&mut user_folder_configs.domain_configs);
}
})
},
Err(e) => {
error!(e);
}
}
},
_ => {}
}
}
});
let etc_path = format!("/etc/{}", env!("CARGO_PKG_NAME"));
let usr_path = format!("/usr/local/share/{}", env!("CARGO_PKG_NAME"));
let system_config_paths = vec![
Path::new(&etc_path),
Path::new(&usr_path),
];
let mut system_path= system_config_paths[1];
for path in system_config_paths {
let cfg_path = path.join("config.toml");
if cfg_path.exists() {
system_path = path;
break;
}
};
let path = format!("{}/config.toml", system_path.display());
match confy::load_path(path.clone()) {
Ok(data) => {
let msg = format!("Using {}", path);
directories.push(system_path.to_path_buf());
info!(msg);
Self::check_for_duplicate_domains(&user_config.domain_configs);
Ok((Config {
user: user_config,
system: data,
}, directories))
},
Err(e) => {
error!(e);
Err(Box::new(e))
}
}
}
fn load_user_config_directory(path: PathBuf) -> (UserConfig, Option<String>) {
let config_path = format!("{}/.config/{}", path.display(), env!("CARGO_PKG_NAME"));
match confy::load_path::<UserConfig>(config_path.clone() + "/domains.toml") {
Ok(data) => {
if data.domain_configs.is_empty() {
match Self::fix_path_ownership(path, vec![".config", env!("CARGO_PKG_NAME"), "domains.toml"]) {
Ok(_) => (),
Err(e) => {
error!(e);
}
};
}
else {
let msg = format!("Using {config_path}/domains.toml");
info!(msg);
}
(data, Some(config_path))
},
Err(e) => {
match &e {
confy::ConfyError::GeneralLoadError(os_error) => {
if os_error.raw_os_error() == Some(13) {
let msg = format!("Missing read permissions for {}, skipping", path.display().to_string().as_str());
warn!(msg);
(UserConfig::default(), None)
}
else {
error!(e);
(UserConfig::default(), None)
}
},
_ => {
error!(e);
(UserConfig::default(), None)
}
}
}
}
}
fn fix_path_ownership(root: PathBuf, paths: Vec<&str>) -> io::Result<()> {
let root_metadata = fs::metadata(&root)?;
let uid = root_metadata.uid();
let gid = root_metadata.gid();
match paths.len() {
1 => {
let new_root = root.join(paths[0]);
unix::fs::chown(new_root, Some(uid), Some(gid))
},
_ => {
let new_root = root.join(paths[0]);
let ret = unix::fs::chown(&new_root, Some(uid), Some(gid));
let mut new_paths = paths.clone();
new_paths.remove(0);
match Self::fix_path_ownership(new_root, new_paths) {
Ok(_) => ret,
Err(e) => {
error!(e);
Err(e)
}
}
}
}
}
fn check_for_duplicate_domains(domain_configs: &[DomainLinkConfig]) {
let mut checked_domains: Vec<String> = vec![];
for (cfg_idx, config) in domain_configs.iter().enumerate() {
for (idx, domain) in config.domains.iter().enumerate() {
if !checked_domains.contains(domain) {
if config.domains[idx+1..].contains(domain) {
// Error
let msg = format!("Duplicate Domain use detected for '{domain}");
warn!(msg);
checked_domains.push(domain.clone());
}
else {
for d in domain_configs[cfg_idx+1..].iter() {
if d.domains.contains(domain) {
let msg = format!("Duplicate Domain use detected for '{domain}");
warn!(msg);
checked_domains.push(domain.clone());
break;
}
}
}
}
}
}
}
}
#[actix_web::main] #[actix_web::main]
async fn main() -> std::io::Result<()> { async fn main() -> notify::Result<()> {
JournalLog::new().expect("Systemd-Logger crate error").install().expect("Systemd-Logger crate error"); JournalLog::new().expect("Systemd-Logger crate error").install().expect("Systemd-Logger crate error");
log::set_max_level(LevelFilter::Info); log::set_max_level(LevelFilter::Info);
let config = Config { let (config, directories) = Config::load().expect("Error while loading or generating the config");
redirects: vec![
DomainLinkConfig {
domain: "neshura.me".to_owned(),
protocol: Protocol::Https,
target: "neshweb.net".to_owned(),
},
DomainLinkConfig {
domain: "lemmy.neshura.me".to_owned(),
protocol: Protocol::Https,
target: "bookwormstory.social/u/neshura".to_owned()
},
DomainLinkConfig {
domain: "test2.neshura.me".to_owned(),
protocol: Protocol::Https,
target: "neshweb.net".to_owned()
}
],
ports: vec![8080, 8090],
addresses: vec![
IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)),
IpAddr::V4(Ipv4Addr::new(192, 168, 178, 11))
],
};
let msg = "This Build is not intended for production use!"; let loaded_redirects_msg = format!("Loaded {} redirects from user config", config.user.domain_configs.len());
info!("Test Info"); info!(loaded_redirects_msg);
warn!(msg);
error!(msg); let app_data = web::Data::new(RwLock::new(config));
let app_data_clone = web::Data::clone(&app_data);
let mut server = HttpServer::new(move || { let mut server = HttpServer::new(move || {
App::new() App::new()
.app_data(web::Data::new(config.redirects.clone())) .app_data(web::Data::clone(&app_data_clone))
.service(handle) .service(status)
.service(dry_handle) .service(do_redirect)
}); });
for address in config.addresses.iter() { for address in app_data.read().expect("Read Lock Failed").system.addresses.iter() {
for port in config.ports.iter() { let ports = app_data.read().expect("Read Lock Failed").system.ports.clone();
for port in ports.iter() {
let msg = if address.is_ipv6() {
format!("Listening on [{address}]:{port}")
}
else {
format!("Listening on {address}:{port}")
};
info!(msg);
server = server.bind((*address, *port))? server = server.bind((*address, *port))?
} }
} }
server.run().await
let mut watcher = notify::recommended_watcher(move |res: Result<Event, notify::Error>| {
match res {
Ok(event) => {
if event.kind == EventKind::Access(AccessKind::Close(AccessMode::Write)) {
let (config, _) = Config::load().expect("Error while loading or generating the config");
let mut tmp_app_data = app_data.write().expect("Write Lock Failed");
tmp_app_data.system = config.system;
tmp_app_data.user = config.user;
info!("Reloading Configuration");
}
},
Err(e) => {
let msg = format!("Error watching files: {e}");
error!(msg);
}
}
})?;
for directory in directories.iter() {
watcher.watch(directory, RecursiveMode::NonRecursive)?;
}
let _ = server.run().await;
Ok(())
} }
#[get("/")] #[get("/")]
async fn handle(redirects: web::Data<Vec<DomainLinkConfig>>, request: HttpRequest) -> impl Responder { async fn do_redirect(data: web::Data<RwLock<Config>>, request: HttpRequest) -> impl Responder {
let redirects = &data.read().expect("Read Lock Failed").user.domain_configs;
if let Some(host_raw) = request.headers().get("host") { if let Some(host_raw) = request.headers().get("host") {
let host = host_raw.to_str().expect("host conversion to string should never fail"); let host = host_raw.to_str().expect("host conversion to string should never fail");
println!("{host}");
for redirect in redirects.iter() { for redirect in redirects.iter() {
if redirect.domain == host { if redirect.domains.contains(&host.to_owned()) {
return HttpResponse::PermanentRedirect().insert_header(("location", format!("{}{}", redirect.protocol, redirect.target).as_str())).finish(); return HttpResponse::PermanentRedirect().insert_header(("location", redirect.target.to_string().as_str())).finish();
} }
} }
let fail_msg = format!("No Redirect for {host} found"); let fail_msg = format!("No Redirect for {host} found");
@ -127,19 +329,20 @@ async fn handle(redirects: web::Data<Vec<DomainLinkConfig>>, request: HttpReques
HttpResponse::NotFound().body("Host not specified") HttpResponse::NotFound().body("Host not specified")
} }
#[get("/dry")] #[get("/status")]
async fn dry_handle(redirects: web::Data<Vec<DomainLinkConfig>>, request: HttpRequest) -> impl Responder { async fn status(data: web::Data<RwLock<Config>>) -> impl Responder {
if let Some(host_raw) = request.headers().get("host") { let redirects = &data.read().expect("Read Lock Failed").user.domain_configs;
let host = host_raw.to_str().expect("host conversion to string should never fail"); let mut body_msg = format!("Redirects Loaded: {}", redirects.len());
println!("{host}"); for redirect in redirects.iter() {
for redirect in redirects.iter() { body_msg += "\n[";
if redirect.domain == host { for (idx, domain) in redirect.domains.iter().enumerate() {
let body = format!("Redirecting: {} -> {}{}", host, redirect.protocol, redirect.target); body_msg += domain;
return HttpResponse::Ok().body(body); if idx != (redirect.domains.len() - 1) {
body_msg += ", ";
} }
} }
let fail_msg = format!("No Redirect for {host} found"); body_msg += format!("] => '{}'", redirect.target).as_str();
return HttpResponse::NotFound().body(fail_msg)
} }
HttpResponse::NotFound().body("Host not specified")
} HttpResponse::Ok().body(body_msg)
}