Compare commits
No commits in common. "main" and "0.5.0" have entirely different histories.
5 changed files with 11 additions and 75 deletions
|
@ -137,7 +137,7 @@ jobs:
|
|||
run: rm release_blobs/build.env
|
||||
-
|
||||
name: Release New Version
|
||||
uses: actions/forgejo-release@v2
|
||||
uses: actions/forgejo-release@v1
|
||||
with:
|
||||
direction: upload
|
||||
url: https://forgejo.neshweb.net
|
||||
|
|
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -460,7 +460,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "domainlink"
|
||||
version = "1.0.3"
|
||||
version = "0.5.0"
|
||||
dependencies = [
|
||||
"actix-web",
|
||||
"confy",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
authors = ["Neshura"]
|
||||
name = "domainlink"
|
||||
version = "1.0.3"
|
||||
version = "0.5.0"
|
||||
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"
|
||||
|
|
|
@ -10,11 +10,12 @@ 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/domains.toml` or `/root/.config/domainlink/domains.toml`.
|
||||
DomainLink currently expects redirect files to be placed in any home directory, specifically `/home/{user}/.config/domainlink/config.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.
|
||||
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.
|
75
src/main.rs
75
src/main.rs
|
@ -1,8 +1,6 @@
|
|||
use std::error::Error;
|
||||
use std::{fs, io};
|
||||
use std::fs;
|
||||
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};
|
||||
|
@ -146,7 +144,6 @@ 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,
|
||||
|
@ -161,20 +158,10 @@ 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::<UserConfig>(config_path.clone() + "/domains.toml") {
|
||||
match confy::load_path(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);
|
||||
}
|
||||
let msg = format!("Using {config_path}/domains.toml");
|
||||
info!(msg);
|
||||
(data, Some(config_path))
|
||||
},
|
||||
Err(e) => {
|
||||
|
@ -198,58 +185,6 @@ 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]
|
||||
|
@ -303,7 +238,7 @@ async fn main() -> notify::Result<()> {
|
|||
}
|
||||
}
|
||||
})?;
|
||||
|
||||
|
||||
for directory in directories.iter() {
|
||||
watcher.watch(directory, RecursiveMode::NonRecursive)?;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue