Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 41 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,59 @@ jobs:
#build tomoon start
- uses: actions/checkout@v4

- name: Install Tools
run: |
sudo apt-get update
sudo apt-get install -y wget unzip upx

- name: Download Clash and Yacd and Subconverter
run: |
mkdir tmp && cd tmp
mkdir core && cd core
# Mihomo (Clash Meta)
wget -O clash.gz https://github.com/MetaCubeX/mihomo/releases/download/v1.19.1/mihomo-linux-amd64-v1.19.1.gz
LATEST_URL=$(curl -s https://api.github.com/repos/MetaCubeX/mihomo/releases/latest | grep "browser_download_url.*linux-amd64-v.*gz\"" | cut -d '"' -f 4)
wget -O clash.gz $LATEST_URL
gzip -d clash.gz

# upx
chmod +x clash
upx clash

# country.mmdb & geosite.dat
wget https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/country.mmdb
wget https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geosite.dat
wget -O asn.mmdb https://github.com/P3TERX/GeoLite.mmdb/raw/download/GeoLite2-ASN.mmdb

# dashboard
mkdir web
# yacd
wget -O yacd.zip https://github.com/MetaCubeX/yacd/archive/gh-pages.zip
wget -O yacd.zip https://github.com/haishanh/yacd/archive/refs/heads/gh-pages.zip
unzip yacd.zip
mv Yacd-meta-gh-pages web
mv yacd-gh-pages web/yacd
# yacd-meta
wget -O yacd-meta.zip https://github.com/MetaCubeX/yacd/archive/gh-pages.zip
unzip yacd-meta.zip
mv Yacd-meta-gh-pages web/yacd-meta
# metacubexd
wget -O metacubexd.zip https://github.com/MetaCubeX/metacubexd/archive/refs/heads/gh-pages.zip
unzip metacubexd.zip
mv metacubexd-gh-pages web/metacubexd
# zashboard
wget -O zashboard.zip https://github.com/Zephyruso/zashboard/releases/latest/download/dist.zip
unzip zashboard.zip
mv dist web/zashboard

echo "clean zips"
rm -f *.zip

cd $GITHUB_WORKSPACE
wget -O subconverter_linux64.tar.gz https://github.com/MetaCubeX/subconverter/releases/download/Alpha/subconverter_linux64.tar.gz
tar xvf subconverter_linux64.tar.gz

# upx
chmod +x subconverter/subconverter
upx subconverter/subconverter

# build front-end start
- uses: actions/setup-node@v4
with:
Expand All @@ -62,6 +96,10 @@ jobs:
args: --target x86_64-unknown-linux-gnu --release
use-cross: false

- name: upx tomoon
run: |
upx ./backend/target/x86_64-unknown-linux-gnu/release/tomoon

- name: Collect Files
run: |
mkdir -p ./release/tomoon/bin/core/web
Expand Down
73 changes: 62 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ help: ## Display list of tasks with descriptions

vendor: ## Install project dependencies
@echo "+ $@"
@cp -r usdpl src/
@pnpm i
@cd tomoon-web && pnpm i

env: ## Create default .env file
@echo "+ $@"
Expand All @@ -38,10 +40,12 @@ download:
@echo "+ $@"
@$(MAKE) clean_tmp
@$(MAKE) download_core
@$(MAKE) upx_core
@$(MAKE) download_mmdb
@$(MAKE) download_yacd
@$(MAKE) download_dashboard
@$(MAKE) download_rules
@$(MAKE) download_subconverter
@$(MAKE) upx_subconverter

clean_tmp:
@echo "+ $@"
Expand All @@ -51,9 +55,17 @@ download_core:
@echo "+ $@"
@mkdir -p ./tmp
@mkdir -p ./tmp/core
@wget -O clash.gz https://github.com/MetaCubeX/mihomo/releases/download/v1.19.1/mihomo-linux-amd64-v1.19.1.gz
@gzip -d clash.gz -c > ./tmp/core/clash
@rm -f clash.gz
@echo "Fetching latest release info from GitHub..."
@LATEST_URL=$$(curl -s https://api.github.com/repos/MetaCubeX/mihomo/releases/latest | grep "browser_download_url.*linux-amd64-v.*gz\"" | cut -d '"' -f 4) && \
echo "Downloading from: $$LATEST_URL" && \
wget -O clash.gz $$LATEST_URL && \
gzip -d clash.gz -c > ./tmp/core/clash && \
rm -f clash.gz

upx_core: ## Compress core/clash with UPX
@echo "+ $@"
@chmod +x ./tmp/core/clash
@upx ./tmp/core/clash

download_mmdb:
@echo "+ $@"
Expand All @@ -63,17 +75,50 @@ download_mmdb:
@wget -O ./tmp/core/geosite.dat https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geosite.dat
@wget -O ./tmp/core/asn.mmdb https://github.com/P3TERX/GeoLite.mmdb/raw/download/GeoLite2-ASN.mmdb

download_yacd:
download_dashboard:
@echo "+ $@"
@mkdir -p ./tmp
@mkdir -p ./tmp/core
@wget -O ./tmp/yacd.zip https://github.com/MetaCubeX/yacd/archive/gh-pages.zip
@unzip ./tmp/yacd.zip -d ./tmp
@mv ./tmp/Yacd-meta-gh-pages ./tmp/core/web
@rm -f ./tmp/yacd.zip
@mkdir -p ./tmp/core/web
@rm -rf ./tmp/core/web/*

$(MAKE) download_yacd
$(MAKE) download_yacd_meta
$(MAKE) download_metacubexd
$(MAKE) download_zashboard

@echo "clean tmp"
@rm -f ./tmp/*.zip

download_yacd:
@echo "+ $@"
@wget -O ./tmp/yacd.zip https://github.com/haishanh/yacd/archive/refs/heads/gh-pages.zip
@unzip -o ./tmp/yacd.zip -d ./tmp
@mv ./tmp/yacd-gh-pages ./tmp/core/web/yacd

download_yacd_meta:
@echo "+ $@"
@wget -O ./tmp/yacd-meta.zip https://github.com/MetaCubeX/yacd/archive/gh-pages.zip
@unzip -o ./tmp/yacd-meta.zip -d ./tmp
@mv ./tmp/Yacd-meta-gh-pages ./tmp/core/web/yacd-meta

download_metacubexd:
@echo "+ $@"
@wget -O ./tmp/metacubexd.zip https://github.com/MetaCubeX/metacubexd/archive/refs/heads/gh-pages.zip
@unzip -o ./tmp/metacubexd.zip -d ./tmp
@mv ./tmp/metacubexd-gh-pages ./tmp/core/web/metacubexd

download_zashboard:
@echo "+ $@"
@wget -O ./tmp/zashboard.zip https://github.com/Zephyruso/zashboard/releases/latest/download/dist.zip
@unzip -o ./tmp/zashboard.zip -d ./tmp
@mv ./tmp/dist ./tmp/core/web/zashboard


download_rules:
@echo "+ $@"
@mkdir -p ./assets/subconverter_rules
@rm -rf ./assets/subconverter_rules/*.list*
@bash ./assets/subconverter_rules/dl_rules.sh ./assets/subconverter_rules

download_subconverter:
Expand All @@ -84,6 +129,11 @@ download_subconverter:
@tar xvf subconverter_linux64.tar.gz -C ./tmp/subconverter_tmp/
@cp ./tmp/subconverter_tmp/subconverter/subconverter ./tmp/subconverter/
@rm -r ./tmp/subconverter_tmp

upx_subconverter: ## Compress subconverter with UPX
@echo "+ $@"
@chmod +x ./tmp/subconverter/subconverter
@upx ./tmp/subconverter/subconverter

build-front: ## Build frontend
@echo "+ $@"
Expand All @@ -101,7 +151,9 @@ build-front-sub:

copy-file:
@echo "+ $@"
@cp -r ./tmp/core ./bin/
@mkdir -p ./bin
@rm -rf ./bin/core
@cp -rv ./tmp/core ./bin/
@cp ./tmp/subconverter/subconverter ./bin/subconverter

build-back: ## Build backend
Expand All @@ -127,7 +179,6 @@ deploy-steamdeck: ## Deploy plugin build to steamdeck
--exclude='node_modules/' \
--exclude='.pnpm-store/' \
--exclude='src/' \
--exclude='yacd' . \
--exclude='tomoon-web/' \
--exclude='backend/' \
--exclude='tmp/' \
Expand Down
2 changes: 1 addition & 1 deletion backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ env_logger = "0.10.0"
local-ip-address = "0.5.1"
actix-cors = "0.6.4"
tokio = { version = "1.24.1", features = ["macros", "process"]}
urlencoding = "2.1.3"
urlencoding = "2.1.3"
4 changes: 2 additions & 2 deletions backend/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
all:
@echo "+ $@"
@rustup default stable
# @cross build --release --target x86_64-unknown-linux-gnu
@cargo build --release --target x86_64-unknown-linux-gnu
@cross build --release --target x86_64-unknown-linux-gnu
# @cargo build --release --target x86_64-unknown-linux-gnu
@mkdir -p ../bin
@cp ./target/x86_64-unknown-linux-gnu/release/tomoon ../bin/tomoon

Expand Down
77 changes: 47 additions & 30 deletions backend/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,14 @@ pub fn set_clash_status(runtime: &ControlRuntime) -> impl Fn(Vec<Primitive>) ->
}
}
if *enabled {
match clash.run(&settings.current_sub, settings.skip_proxy, settings.override_dns, settings.enhanced_mode) {
match clash.run(
&settings.current_sub,
settings.skip_proxy,
settings.override_dns,
settings.allow_remote_access,
settings.enhanced_mode,
settings.dashboard.clone(),
) {
Ok(_) => (),
Err(e) => {
log::error!("Run clash error: {}", e);
Expand Down Expand Up @@ -190,7 +197,9 @@ pub fn download_sub(runtime: &ControlRuntime) -> impl Fn(Vec<Primitive>) -> Vec<
}
};
if !helper::check_yaml(&file_content) {
log::error!("The downloaded subscription is not a legal profile.");
log::error!(
"The downloaded subscription is not a legal profile."
);
update_status(DownloadStatus::Error);
return;
}
Expand Down Expand Up @@ -249,14 +258,19 @@ pub fn download_sub(runtime: &ControlRuntime) -> impl Fn(Vec<Primitive>) -> Vec<
// 是一个链接
} else {
match minreq::get(url.clone())
.with_header("User-Agent", format!("ToMoonClash/{}",env!("CARGO_PKG_VERSION")))
.with_header(
"User-Agent",
format!("ToMoonClash/{}", env!("CARGO_PKG_VERSION")),
)
.with_timeout(15)
.send()
{
Ok(x) => {
let response = x.as_str().unwrap();
if !helper::check_yaml(&String::from(response)) {
log::error!("The downloaded subscription is not a legal profile.");
log::error!(
"The downloaded subscription is not a legal profile."
);
update_status(DownloadStatus::Error);
return;
}
Expand Down Expand Up @@ -446,7 +460,7 @@ pub fn delete_sub(runtime: &ControlRuntime) -> impl Fn(Vec<Primitive>) -> Vec<Pr
}

pub fn set_sub(runtime: &ControlRuntime) -> impl Fn(Vec<Primitive>) -> Vec<Primitive> {
//let runtime_clash = runtime.clash_state_clone();
let runtime_clash = runtime.clash_state_clone();
let runtime_state = runtime.state_clone();
let runtime_setting = runtime.settings_clone();
move |params: Vec<Primitive>| {
Expand All @@ -471,16 +485,16 @@ pub fn set_sub(runtime: &ControlRuntime) -> impl Fn(Vec<Primitive>) -> Vec<Primi
return vec![];
}
};
// //更新到当前内存中
// match runtime_clash.write() {
// Ok(mut x) => {
// x.update_config_path(path);
// log::info!("set profile path to {}", path);
// }
// Err(e) => {
// log::error!("set_sub() failed to acquire clash write lock: {}", e);
// }
// }
//更新到当前内存中
match runtime_clash.write() {
Ok(mut x) => {
x.update_config_path(path);
log::info!("set profile path to {}", path);
}
Err(e) => {
log::error!("set_sub() failed to acquire clash write lock: {}", e);
}
}
}
return vec![];
}
Expand All @@ -505,9 +519,16 @@ pub fn update_subs(runtime: &ControlRuntime) -> impl Fn(Vec<Primitive>) -> Vec<P
}
thread::spawn(move || {
match minreq::get(i.url.clone())
.with_header("User-Agent", format!("ToMoon/{} mihomo/1.18.3 Clash/v1.18.0",env!("CARGO_PKG_VERSION")))
.with_timeout(15)
.send() {
.with_header(
"User-Agent",
format!(
"ToMoon/{} mihomo/1.18.3 Clash/v1.18.0",
env!("CARGO_PKG_VERSION")
),
)
.with_timeout(15)
.send()
{
Ok(response) => {
let response = match response.as_str() {
Ok(x) => x,
Expand All @@ -517,7 +538,9 @@ pub fn update_subs(runtime: &ControlRuntime) -> impl Fn(Vec<Primitive>) -> Vec<P
}
};
if !helper::check_yaml(&response.to_string()) {
log::error!("The downloaded subscription is not a legal profile.");
log::error!(
"The downloaded subscription is not a legal profile."
);
return;
}
match fs::write(i.path.clone(), response) {
Expand All @@ -532,7 +555,7 @@ pub fn update_subs(runtime: &ControlRuntime) -> impl Fn(Vec<Primitive>) -> Vec<P
return;
}
}
},
}
Err(e) => {
log::error!("Error occurred while download sub {}", i.url);
log::error!("Error Message : {}", e);
Expand Down Expand Up @@ -575,14 +598,11 @@ pub fn create_debug_log(runtime: &ControlRuntime) -> impl Fn(Vec<Primitive>) ->
//let update_status = runtime.update_status_clone();
let home = match runtime.state_clone().read() {
Ok(state) => state.home.clone(),
Err(_) => State::default().home
Err(_) => State::default().home,
};
move |_| {
let running_status = format!(
"Clash status : {}\n",
helper::is_clash_running()
);
let tomoon_config =match fs::read_to_string(home.join(".config/tomoon/tomoon.json")) {
let running_status = format!("Clash status : {}\n", helper::is_clash_running());
let tomoon_config = match fs::read_to_string(home.join(".config/tomoon/tomoon.json")) {
Ok(x) => x,
Err(e) => {
format!("can not get Tomoon config, error message: {} \n", e)
Expand Down Expand Up @@ -611,10 +631,7 @@ pub fn create_debug_log(runtime: &ControlRuntime) -> impl Fn(Vec<Primitive>) ->
Clash log:\n
{}\n
",
running_status,
tomoon_config,
tomoon_log,
clash_log,
running_status, tomoon_config, tomoon_log, clash_log,
);
fs::write("/tmp/tomoon.debug.log", log).unwrap();
return vec![true.into()];
Expand Down
Loading