update 2025-02-07 16:24:27

This commit is contained in:
kenzok8 2025-02-07 16:24:27 +08:00
parent c4b653ce84
commit aa3dc268a4
14 changed files with 30 additions and 43 deletions

View File

@ -245,7 +245,7 @@ return view.extend({
const stun = this.formvalue(this.section.section);
const l4proto = document.getElementById('_status_nattest_l4proto').value;
return fs.exec_direct('/etc/fchomo/scripts/natcheck.sh', [stun, l4proto, getRandom(32768, 61000)]).then((stdout) => {
return fs.exec_direct('/usr/libexec/fchomo/natcheck.sh', [stun, l4proto, getRandom(32768, 61000)]).then((stdout) => {
this.description = '<details><summary>' + _('Expand/Collapse result') + '</summary>' + stdout + '</details>';
return this.map.reset().then((res) => {

View File

@ -12,6 +12,8 @@ PROG="/usr/bin/mihomo"
HM_DIR="/etc/fchomo"
TEMPS_DIR="$HM_DIR/templates"
EXE_DIR="/usr/libexec/fchomo"
SDL_DIR="/usr/share/fchomo"
RUN_DIR="/var/run/fchomo"
LOG_PATH="$RUN_DIR/fchomo.log"
@ -112,7 +114,7 @@ start_service() {
if [ "$client_enabled" = "1" ]; then
if [ -z "$1" -o "$1" = "mihomo-c" ]; then
# Generate/Validate client config
ucode -S "$HM_DIR/scripts/generate_client.uc" 2>>"$LOG_PATH" | yq -Poy | yq \
ucode -S "$SDL_DIR/generate_client.uc" 2>>"$LOG_PATH" | yq -Poy | yq \
'.sniffer["force-domain"][] style="double"
| .sniffer["skip-domain"][] style="double"
| with(.dns["nameserver-policy"] | keys; .. style="double")
@ -277,7 +279,7 @@ start_service() {
if [ "$server_enabled" = "1" ]; then
if [ -z "$1" -o "$1" = "mihomo-s" ]; then
# Generate/Validate server config
ucode -S "$HM_DIR/scripts/generate_server.uc" 2>>"$LOG_PATH" | yq -Poy > "$RUN_DIR/mihomo-s.yaml"
ucode -S "$SDL_DIR/generate_server.uc" 2>>"$LOG_PATH" | yq -Poy > "$RUN_DIR/mihomo-s.yaml"
if [ ! -e "$RUN_DIR/mihomo-s.yaml" ]; then
log "Error: failed to generate server configuration."
@ -340,15 +342,15 @@ start_service() {
# log-cleaner
procd_open_instance "log-cleaner"
procd_set_param command "$HM_DIR/scripts/clean_log.sh"
procd_set_param command "$EXE_DIR/clean_log.sh"
procd_set_param respawn
procd_close_instance
# Setup firewall
utpl -S "$HM_DIR/scripts/firewall_pre.ut" > "$RUN_DIR/fchomo_pre.nft"
utpl -S "$SDL_DIR/firewall_pre.ut" > "$RUN_DIR/fchomo_pre.nft"
# Setup Nftables rules
if [ "$client_enabled" = "1" ]; then
[ -z "$1" -o "$1" = "mihomo-c" ] && utpl -S "$HM_DIR/scripts/firewall_post.ut" > "$RUN_DIR/fchomo_post.nft"
[ -z "$1" -o "$1" = "mihomo-c" ] && utpl -S "$SDL_DIR/firewall_post.ut" > "$RUN_DIR/fchomo_post.nft"
fi
log "$(mihomo -v | awk 'NR==1{print $1,$3}') started."

View File

@ -4,6 +4,8 @@ import { mkstemp, popen } from 'fs';
/* Global variables START */
export const HM_DIR = '/etc/fchomo';
export const EXE_DIR = '/usr/libexec/fchomo';
export const SDL_DIR = '/usr/share/fchomo';
export const RUN_DIR = '/var/run/fchomo';
export const PRESET_OUTBOUND = [
'DIRECT',

View File

@ -4,7 +4,7 @@
{%-
import { readfile } from 'fs';
import { cursor } from 'uci';
import { isEmpty, yqRead } from '/etc/fchomo/scripts/fchomo.uc';
import { isEmpty, yqRead } from 'fchomo';
const fw4 = require('fw4');

View File

@ -3,8 +3,8 @@
"description": "Grant access to fchomo configuration",
"read": {
"file": {
"/etc/fchomo/scripts/natcheck.sh": [ "exec" ],
"/etc/init.d/fchomo reload *": [ "exec" ],
"/usr/libexec/fchomo/natcheck.sh": [ "exec" ],
"/var/run/fchomo/fchomo.log": [ "read" ],
"/var/run/fchomo/mihomo-c.log": [ "read" ],
"/var/run/fchomo/mihomo-s.log": [ "read" ]

View File

@ -3,11 +3,10 @@
'use strict';
import { access, lsdir, lstat, popen, readfile, writefile } from 'fs';
/* Kanged from ucode/luci */
function shellquote(s) {
return `'${replace(s, "'", "'\\''")}'`;
}
import {
shellQuote, yqRead,
HM_DIR, EXE_DIR, SDL_DIR, RUN_DIR
} from '/usr/share/fchomo/fchomo.uc';
function isBinary(str) {
for (let off = 0, byte = ord(str); off < length(str); byte = ord(str, ++off))
@ -18,19 +17,7 @@ function isBinary(str) {
}
function hasKernelModule(kmod) {
return (system(sprintf('[ -e "/lib/modules/$(uname -r)"/%s ]', shellquote(kmod))) === 0);
}
function yqRead(flags, command, filepath) {
let out = '';
const fd = popen(`yq ${flags} ${shellquote(command)} ${filepath}`);
if (fd) {
out = fd.read('all');
fd.close();
}
return out;
return (system(sprintf('[ -e "/lib/modules/$(uname -r)"/%s ]', shellQuote(kmod))) === 0);
}
function wGET(url, header, filepath) {
@ -48,18 +35,16 @@ function wGET(url, header, filepath) {
ua = v;
v = null;
}
return v ? '--header=' + shellquote(`${k}: ${v}`) : null;
return v ? '--header=' + shellQuote(`${k}: ${v}`) : null;
}), v => v));
} else
header = '';
let exitcode = system(`wget --tries=1 --timeout=10 --user-agent ${shellquote(ua)} ${header} -q ${shellquote(url)} -O ${shellquote(filepath)}`);
let exitcode = system(`wget --tries=1 --timeout=10 --user-agent ${shellQuote(ua)} ${header} -q ${shellQuote(url)} -O ${shellQuote(filepath)}`);
return exitcode;
}
const HM_DIR = '/etc/fchomo';
const RUN_DIR = '/var/run/fchomo';
const RES_TYPE = ['certs', 'provider', 'ruleset', 'resources', 'templates'];
const methods = {
@ -144,9 +129,9 @@ const methods = {
args: { type: 'type', expr: 'expr' },
call: function(req) {
if (req.args?.type == 'resources') {
system(`sed -i "/${replace(HM_DIR, "/", "\\/")}\\/scripts\\/update_resources.sh/d" /etc/crontabs/root`);
system(`sed -i "/${replace(EXE_DIR, "/", "\\/")}\\/update_resources.sh/d" /etc/crontabs/root`);
if (req.args?.expr)
system(`echo -e "` + req.args?.expr + ` ${HM_DIR}/scripts/update_resources.sh ALL" >> /etc/crontabs/root`);
system(`echo -e "` + req.args?.expr + ` ${EXE_DIR}/update_resources.sh ALL" >> /etc/crontabs/root`);
} else
return { result: false, error: 'illegal type' };
@ -188,9 +173,9 @@ const methods = {
args: { type: 'type', repo: 'repo' },
call: function(req) {
if (req.args?.type) {
const type = shellquote(req.args?.type),
repo = shellquote(req.args?.repo);
const exit_code = system(`${HM_DIR}/scripts/update_resources.sh ${type} ${repo}`);
const type = shellQuote(req.args?.type),
repo = shellQuote(req.args?.repo);
const exit_code = system(`${EXE_DIR}/update_resources.sh ${type} ${repo}`);
return { status: exit_code };
} else
return { status: 255, error: 'illegal type' };

View File

@ -131,7 +131,7 @@ o:value("ipv6_only", translate("IPv6 Only"))
o = s:option(Button, "_stop", translate("Delete All Subscribe Node"))
o.inputstyle = "remove"
function o.write(e, e)
luci.sys.call("lua /usr/share/" .. appname .. "/subscribe.lua truncate all-node > /dev/null 2>&1")
luci.sys.call("lua /usr/share/" .. appname .. "/subscribe.lua truncate > /dev/null 2>&1")
m.no_commit = true
end

View File

@ -1318,13 +1318,11 @@ local function truncate_nodes(add_from)
end
end
end)
if add_from then
uci:foreach(appname, "subscribe_list", function(o)
if add_from == "all-node" or add_from == o.remark then
uci:delete(appname, o['.name'], "md5")
end
end)
end
uci:foreach(appname, "subscribe_list", function(o)
if (not add_from) or add_from == o.remark then
uci:delete(appname, o['.name'], "md5")
end
end)
api.uci_save(uci, appname, true)
end