Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
vernesong committed Sep 19, 2024
2 parents dd5e07d + 03b2cc1 commit e96b596
Show file tree
Hide file tree
Showing 109 changed files with 86,976 additions and 113,976 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/compile_dev_core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
name: Compile The New Clash Dev Core

on:
schedule:
- cron: "0 19 * * 1,3,5,6"
#schedule:
# - cron: "0 19 * * 1,3,5,6"
workflow_dispatch:

jobs:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/compile_meta_core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ jobs:
- name: Setup loongarch abi1 Go
run: |
wget -q https://github.com/xishang0128/loongarch64-golang/releases/download/1.21.5/go1.21.5.linux-amd64-abi1.tar.gz
wget -q https://github.com/MetaCubeX/loongarch64-golang/releases/download/1.22.4/go1.22.4.linux-amd64-abi1.tar.gz
sudo tar zxf go1.21.5.linux-amd64-abi1.tar.gz -C /usr/local
echo "/usr/local/go/bin" >> $GITHUB_PATH
Expand All @@ -126,7 +126,7 @@ jobs:
- name: Setup loongarch abi2 Go
run: |
wget -q https://github.com/xishang0128/loongarch64-golang/releases/download/1.21.5/go1.21.5.linux-amd64-abi2.tar.gz
wget -q https://github.com/MetaCubeX/loongarch64-golang/releases/download/1.22.4/go1.22.4.linux-amd64-abi2.tar.gz
sudo tar zxf go1.21.5.linux-amd64-abi2.tar.gz -C /usr/local
- name: Compile Meta loongarch abi2 Clash
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/compile_premium_core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
name: Compile The New Clash Premium Core

on:
schedule:
- cron: "0 21 * * 1,3,5"
#schedule:
# - cron: "0 21 * * 1,3,5"
workflow_dispatch:

jobs:
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019 vernesong
Copyright (c) 2019-2024 vernesong

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
5 changes: 1 addition & 4 deletions luci-app-openclash/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
include $(TOPDIR)/rules.mk

PKG_NAME:=luci-app-openclash
PKG_VERSION:=0.46.014
PKG_VERSION:=0.46.031
PKG_RELEASE:=beta
PKG_MAINTAINER:=vernesong <https://github.com/vernesong/OpenClash>

Expand Down Expand Up @@ -64,7 +64,6 @@ define Build/Prepare
cp -f "$(PKG_BUILD_DIR)/root/etc/openclash/custom/openclash_custom_domain_dns.list" "$(PKG_BUILD_DIR)/root/usr/share/openclash/backup/openclash_custom_domain_dns.list" >/dev/null 2>&1
cp -f "$(PKG_BUILD_DIR)/root/etc/openclash/custom/openclash_custom_domain_dns_policy.list" "$(PKG_BUILD_DIR)/root/usr/share/openclash/backup/openclash_custom_domain_dns_policy.list" >/dev/null 2>&1
cp -f "$(PKG_BUILD_DIR)/root/etc/openclash/custom/openclash_custom_fallback_filter.yaml" "$(PKG_BUILD_DIR)/root/usr/share/openclash/backup/openclash_custom_fallback_filter.yaml" >/dev/null 2>&1
cp -f "$(PKG_BUILD_DIR)/root/etc/openclash/custom/openclash_custom_netflix_domains.list" "$(PKG_BUILD_DIR)/root/usr/share/openclash/backup/openclash_custom_netflix_domains.list" >/dev/null 2>&1
cp -f "$(PKG_BUILD_DIR)/root/etc/openclash/custom/openclash_force_sniffing_domain.yaml" "$(PKG_BUILD_DIR)/root/usr/share/openclash/backup/openclash_force_sniffing_domain.yaml" >/dev/null 2>&1
cp -f "$(PKG_BUILD_DIR)/root/etc/openclash/custom/openclash_sniffing_domain_filter.yaml" "$(PKG_BUILD_DIR)/root/usr/share/openclash/backup/openclash_sniffing_domain_filter.yaml" >/dev/null 2>&1
cp -f "$(PKG_BUILD_DIR)/root/etc/openclash/custom/openclash_sniffing_ports_filter.yaml" "$(PKG_BUILD_DIR)/root/usr/share/openclash/backup/openclash_sniffing_ports_filter.yaml" >/dev/null 2>&1
Expand Down Expand Up @@ -132,11 +131,9 @@ define Package/$(PKG_NAME)/postrm
rm -rf ${dnsmasqconfdir}/dnsmasq_openclash_custom_domain.conf >/dev/null 2>&1
rm -rf ${dnsmasqconfdir}/dnsmasq_openclash_chnroute_pass.conf >/dev/null 2>&1
rm -rf ${dnsmasqconfdir}/dnsmasq_openclash_chnroute6_pass.conf >/dev/null 2>&1
rm -rf ${dnsmasqconfdir}/dnsmasq_accelerated-domains.china.conf >/dev/null 2>&1
rm -rf /tmp/dler* >/dev/null 2>&1
rm -rf /tmp/etc/openclash >/dev/null 2>&1
rm -rf /tmp/openclash_edit_file_name >/dev/null 2>&1
rm -rf /tmp/openclash_*_region>/dev/null 2>&1
sed -i '/OpenClash Append/,/OpenClash Append End/d' "/usr/lib/lua/luci/model/network.lua" >/dev/null 2>&1
sed -i '/.*kB maximum content size*/c\HTTP_MAX_CONTENT = 1024*100 -- 100 kB maximum content size' /usr/lib/lua/luci/http.lua >/dev/null 2>&1
sed -i '/.*kB maximum content size*/c\export let HTTP_MAX_CONTENT = 1024*100; // 100 kB maximum content size' /usr/share/ucode/luci/http.uc >/dev/null 2>&1
Expand Down
140 changes: 19 additions & 121 deletions luci-app-openclash/luasrc/controller/openclash.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ function index()
entry({"admin", "services", "openclash", "coreupdate"},call("action_coreupdate"))
entry({"admin", "services", "openclash", "flush_fakeip_cache"}, call("action_flush_fakeip_cache"))
entry({"admin", "services", "openclash", "download_rule"}, call("action_download_rule"))
entry({"admin", "services", "openclash", "download_netflix_domains"}, call("action_download_netflix_domains"))
entry({"admin", "services", "openclash", "download_disney_domains"}, call("action_download_disney_domains"))
entry({"admin", "services", "openclash", "catch_netflix_domains"}, call("action_catch_netflix_domains"))
entry({"admin", "services", "openclash", "write_netflix_domains"}, call("action_write_netflix_domains"))
entry({"admin", "services", "openclash", "restore"}, call("action_restore_config"))
entry({"admin", "services", "openclash", "backup"}, call("action_backup"))
entry({"admin", "services", "openclash", "backup_ex_core"}, call("action_backup_ex_core"))
Expand Down Expand Up @@ -103,18 +99,17 @@ local json = require "luci.jsonc"
local uci = require("luci.model.uci").cursor()
local datatype = require "luci.cbi.datatypes"
local opkg
local device_name = uci:get("system", "@system[0]", "hostname")
local device_arh = luci.sys.exec("uname -m |tr -d '\n'")

if pcall(require, "luci.model.ipkg") then
opkg = require "luci.model.ipkg"
end

local core_path_mode = uci:get("openclash", "config", "small_flash_memory")
if core_path_mode ~= "1" then
dev_core_path="/etc/openclash/core/clash"
tun_core_path="/etc/openclash/core/clash_tun"
meta_core_path="/etc/openclash/core/clash_meta"
else
dev_core_path="/tmp/etc/openclash/core/clash"
tun_core_path="/tmp/etc/openclash/core/clash_tun"
meta_core_path="/tmp/etc/openclash/core/clash_meta"
end

Expand All @@ -126,10 +121,6 @@ local function is_web()
return luci.sys.call("pidof clash >/dev/null") == 0
end

local function restricted_mode()
return uci:get("openclash", "config", "restricted_mode")
end

local function is_watchdog()
return process_status("openclash_watchdog.sh")
end
Expand Down Expand Up @@ -158,14 +149,6 @@ local function lhie1()
return os.date("%Y-%m-%d %H:%M:%S",fs.mtime("/usr/share/openclash/res/lhie1.yaml"))
end

local function ConnersHua()
return os.date("%Y-%m-%d %H:%M:%S",fs.mtime("/usr/share/openclash/res/ConnersHua.yaml"))
end

local function ConnersHua_return()
return os.date("%Y-%m-%d %H:%M:%S",fs.mtime("/usr/share/openclash/res/ConnersHua_return.yaml"))
end

local function chnroute()
return os.date("%Y-%m-%d %H:%M:%S",fs.mtime("/etc/openclash/china_ip_route.ipset"))
end
Expand Down Expand Up @@ -238,29 +221,13 @@ local function coremodel()
end

local function check_core()
if not nixio.fs.access(dev_core_path) and not nixio.fs.access(tun_core_path) and not nixio.fs.access(meta_core_path) then
if not nixio.fs.access(meta_core_path) then
return "0"
else
return "1"
end
end

local function corecv()
if not nixio.fs.access(dev_core_path) then
return "0"
else
return luci.sys.exec(string.format("%s -v 2>/dev/null |awk -F ' ' '{print $2}'", dev_core_path))
end
end

local function coretuncv()
if not nixio.fs.access(tun_core_path) then
return "0"
else
return luci.sys.exec(string.format("%s -v 2>/dev/null |awk -F ' ' '{print $2}'", tun_core_path))
end
end

local function coremetacv()
if not nixio.fs.access(meta_core_path) then
return "0"
Expand All @@ -271,10 +238,8 @@ end

local function corelv()
luci.sys.call("bash /usr/share/openclash/clash_version.sh")
local core_lv = luci.sys.exec("sed -n 1p /tmp/clash_last_version 2>/dev/null")
local core_tun_lv = luci.sys.exec("sed -n 2p /tmp/clash_last_version 2>/dev/null")
local core_meta_lv = luci.sys.exec("sed -n 3p /tmp/clash_last_version 2>/dev/null")
return core_lv .. "," .. core_tun_lv .. "," .. core_meta_lv
return core_meta_lv
end

local function opcv()
Expand Down Expand Up @@ -354,13 +319,9 @@ function core_download()
local cdn_url = luci.http.formvalue("url")
if cdn_url then
luci.sys.call(string.format("rm -rf /tmp/clash_last_version 2>/dev/null && bash /usr/share/openclash/clash_version.sh '%s' >/dev/null 2>&1", cdn_url))
luci.sys.call(string.format("bash /usr/share/openclash/openclash_core.sh 'Dev' '%s' >/dev/null 2>&1 &", cdn_url))
luci.sys.call(string.format("bash /usr/share/openclash/openclash_core.sh 'TUN' '%s' >/dev/null 2>&1 &", cdn_url))
luci.sys.call(string.format("bash /usr/share/openclash/openclash_core.sh 'Meta' '%s' >/dev/null 2>&1 &", cdn_url))
else
luci.sys.call("rm -rf /tmp/clash_last_version 2>/dev/null && bash /usr/share/openclash/clash_version.sh >/dev/null 2>&1")
luci.sys.call("bash /usr/share/openclash/openclash_core.sh 'Dev' >/dev/null 2>&1 &")
luci.sys.call("bash /usr/share/openclash/openclash_core.sh 'TUN' >/dev/null 2>&1 &")
luci.sys.call("bash /usr/share/openclash/openclash_core.sh 'Meta' >/dev/null 2>&1 &")
end

Expand All @@ -372,16 +333,6 @@ function download_rule()
return state
end

function download_disney_domains()
local state = luci.sys.call(string.format('/usr/share/openclash/openclash_download_rule_list.sh "%s" >/dev/null 2>&1',"disney_domains"))
return state
end

function download_netflix_domains()
local state = luci.sys.call(string.format('/usr/share/openclash/openclash_download_rule_list.sh "%s" >/dev/null 2>&1',"netflix_domains"))
return state
end

function action_flush_fakeip_cache()
local state = 0
if is_running() then
Expand Down Expand Up @@ -751,7 +702,7 @@ function action_rule_mode()
local daip = daip()
local dase = dase() or ""
local cn_port = cn_port()
core_type = uci:get("openclash", "config", "core_type") or "Dev"
core_type = uci:get("openclash", "config", "core_type") or "Meta"
if not daip or not cn_port then return end
info = json.parse(luci.sys.exec(string.format('curl -sL -m 3 -H "Content-Type: application/json" -H "Authorization: Bearer %s" -XGET http://"%s":"%s"/configs', dase, daip, cn_port)))
if info then
Expand All @@ -773,9 +724,7 @@ function action_switch_rule_mode()
local daip = daip()
local dase = dase() or ""
local cn_port = cn_port()
local core_type = uci:get("openclash", "config", "core_type") or "Dev"
mode = luci.http.formvalue("rule_mode")
if mode == script and core_type ~= "TUN" then luci.http.status(500, "Switch Faild") return end
if not daip or not cn_port then luci.http.status(500, "Switch Faild") return end
info = luci.sys.exec(string.format('curl -sL -m 3 -H "Content-Type: application/json" -H "Authorization: Bearer %s" -XPATCH http://"%s":"%s"/configs -d \'{\"mode\": \"%s\"}\'', dase, daip, cn_port, mode))
if info ~= "" then
Expand Down Expand Up @@ -1081,17 +1030,14 @@ function action_status()
db_forward_ssl = db_foward_ssl(),
web = is_web(),
cn_port = cn_port(),
restricted_mode = restricted_mode(),
core_type = uci:get("openclash", "config", "core_type") or "Dev";
core_type = uci:get("openclash", "config", "core_type") or "Meta";
})
end

function action_state()
luci.http.prepare_content("application/json")
luci.http.write_json({
lhie1 = lhie1(),
ConnersHua = ConnersHua(),
ConnersHua_return = ConnersHua_return(),
ipdb = ipdb(),
geosite = geosite(),
historychecktime = historychecktime(),
Expand All @@ -1117,8 +1063,6 @@ end
function action_update()
luci.http.prepare_content("application/json")
luci.http.write_json({
corecv = corecv(),
coretuncv = coretuncv(),
coremetacv = coremetacv(),
coremodel = coremodel(),
opcv = opcv(),
Expand Down Expand Up @@ -1198,20 +1142,6 @@ function action_download_rule()
})
end

function action_download_netflix_domains()
luci.http.prepare_content("application/json")
luci.http.write_json({
rule_download_status = download_netflix_domains();
})
end

function action_download_disney_domains()
luci.http.prepare_content("application/json")
luci.http.write_json({
rule_download_status = download_disney_domains();
})
end

function action_refresh_log()
luci.http.prepare_content("application/json")
local logfile="/tmp/openclash.log"
Expand Down Expand Up @@ -1326,38 +1256,6 @@ function split(str,delimiter)
return arr
end

function action_write_netflix_domains()
local domains = luci.http.formvalue("domains")
local dustom_file = "/etc/openclash/custom/openclash_custom_netflix_domains.list"
local file = io.open(dustom_file, "a+")
file:seek("set")
local domain = file:read("*a")
for v, k in pairs(split(domains,"\n")) do
if not string.find(domain,k,1,true) then
file:write(k.."\n")
end
end
file:close()
return
end

function action_catch_netflix_domains()
local cmd = "/usr/share/openclash/openclash_debug_getcon.lua 'netflix-nflxvideo'"
luci.http.prepare_content("text/plain")
local util = io.popen(cmd)
if util and util ~= "" then
while true do
local ln = util:read("*l")
if not ln then break end
luci.http.write(ln)
luci.http.write(",")
end
util:close()
return
end
luci.http.status(500, "Bad address")
end

function action_diag_connection()
local addr = luci.http.formvalue("addr")
if addr and (datatype.hostname(addr) or datatype.ipaddr(addr)) then
Expand Down Expand Up @@ -1425,8 +1323,8 @@ function action_backup()
local reader = ltn12_popen("tar -C '/etc/openclash/' -cz . 2>/dev/null")

luci.http.header(
'Content-Disposition', 'attachment; filename="Backup-OpenClash-%s.tar.gz"' %{
os.date("%Y-%m-%d-%H-%M-%S")
'Content-Disposition', 'attachment; filename="Backup-OpenClash-%s-%s-%s.tar.gz"' %{
device_name, device_arh, os.date("%Y-%m-%d-%H-%M-%S")
})

luci.http.prepare_content("application/x-targz")
Expand All @@ -1439,8 +1337,8 @@ function action_backup_ex_core()
local reader = ltn12_popen("echo 'core' > /tmp/oc_exclude.txt && tar -C '/etc/openclash/' -X '/tmp/oc_exclude.txt' -cz . 2>/dev/null")

luci.http.header(
'Content-Disposition', 'attachment; filename="Backup-OpenClash-Exclude-Cores-%s.tar.gz"' %{
os.date("%Y-%m-%d-%H-%M-%S")
'Content-Disposition', 'attachment; filename="Backup-OpenClash-Exclude-Cores-%s-%s-%s.tar.gz"' %{
device_name, device_arh, os.date("%Y-%m-%d-%H-%M-%S")
})

luci.http.prepare_content("application/x-targz")
Expand All @@ -1452,8 +1350,8 @@ function action_backup_only_config()
local reader = ltn12_popen("tar -C '/etc/openclash' -cz './config' 2>/dev/null")

luci.http.header(
'Content-Disposition', 'attachment; filename="Backup-OpenClash-Config-%s.tar.gz"' %{
os.date("%Y-%m-%d-%H-%M-%S")
'Content-Disposition', 'attachment; filename="Backup-OpenClash-Config-%s-%s-%s.tar.gz"' %{
device_name, device_arh, os.date("%Y-%m-%d-%H-%M-%S")
})

luci.http.prepare_content("application/x-targz")
Expand All @@ -1464,8 +1362,8 @@ function action_backup_only_core()
local reader = ltn12_popen("tar -C '/etc/openclash' -cz './core' 2>/dev/null")

luci.http.header(
'Content-Disposition', 'attachment; filename="Backup-OpenClash-Cores-%s.tar.gz"' %{
os.date("%Y-%m-%d-%H-%M-%S")
'Content-Disposition', 'attachment; filename="Backup-OpenClash-Cores-%s-%s-%s.tar.gz"' %{
device_name, device_arh, os.date("%Y-%m-%d-%H-%M-%S")
})

luci.http.prepare_content("application/x-targz")
Expand All @@ -1476,8 +1374,8 @@ function action_backup_only_rule()
local reader = ltn12_popen("tar -C '/etc/openclash' -cz './rule_provider' 2>/dev/null")

luci.http.header(
'Content-Disposition', 'attachment; filename="Backup-OpenClash-Only-Rule-Provider-%s.tar.gz"' %{
os.date("%Y-%m-%d-%H-%M-%S")
'Content-Disposition', 'attachment; filename="Backup-OpenClash-Only-Rule-Provider-%s-%s-%s.tar.gz"' %{
device_name, device_arh, os.date("%Y-%m-%d-%H-%M-%S")
})

luci.http.prepare_content("application/x-targz")
Expand All @@ -1488,8 +1386,8 @@ function action_backup_only_proxy()
local reader = ltn12_popen("tar -C '/etc/openclash' -cz './proxy_provider' 2>/dev/null")

luci.http.header(
'Content-Disposition', 'attachment; filename="Backup-OpenClash-Proxy-Provider-%s.tar.gz"' %{
os.date("%Y-%m-%d-%H-%M-%S")
'Content-Disposition', 'attachment; filename="Backup-OpenClash-Proxy-Provider-%s-%s-%s.tar.gz"' %{
device_name, device_arh, os.date("%Y-%m-%d-%H-%M-%S")
})

luci.http.prepare_content("application/x-targz")
Expand Down
Loading

0 comments on commit e96b596

Please sign in to comment.