Compare commits

..

14 commits
0.5.0 ... main

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 47s
Build binary file and bundle packages / build (pull_request) Successful in 51s
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
5 changed files with 75 additions and 11 deletions

View file

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

2
Cargo.lock generated
View file

@ -460,7 +460,7 @@ dependencies = [
[[package]]
name = "domainlink"
version = "0.5.0"
version = "1.0.3"
dependencies = [
"actix-web",
"confy",

View file

@ -1,7 +1,7 @@
[package]
authors = ["Neshura"]
name = "domainlink"
version = "0.5.0"
version = "1.0.3"
edition = "2021"
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"

View file

@ -10,7 +10,7 @@ Any changes there will persist updates and supersede the default config. The Sys
#### User Configuration
DomainLink currently expects redirect files to be placed in any home directory, specifically `/home/{user}/.config/domainlink/config.toml`.
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]]
@ -18,4 +18,3 @@ 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.
Support for `/root/.config/domainlink/redirects` may come in the future.

View file

@ -1,6 +1,8 @@
use std::error::Error;
use std::fs;
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};
@ -144,6 +146,7 @@ impl Config {
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,
@ -158,10 +161,20 @@ impl Config {
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(config_path.clone() + "/domains.toml") {
match confy::load_path::<UserConfig>(config_path.clone() + "/domains.toml") {
Ok(data) => {
let msg = format!("Using {config_path}/domains.toml");
info!(msg);
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) => {
@ -185,6 +198,58 @@ impl Config {
}
}
}
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]