This commit is contained in:
eric
2026-05-28 15:59:03 -05:00
parent 1d89aa29e0
commit 08155500fc
47 changed files with 1126 additions and 122 deletions

View File

@@ -3,6 +3,8 @@ set -euo pipefail
SERVICE_ID="${1:-}"
ACTION="${2:-status}"
ACTION_ARG1="${3:-}"
ACTION_ARG2="${4:-}"
ROOT_DIR="$(cd "$(dirname "$0")/../.." && pwd)"
CONFIG_DIR="$ROOT_DIR/config"
@@ -254,6 +256,10 @@ docker_container_status() {
}
resolve_neko_image() {
if [ -n "${NEKO_IMAGE:-}" ]; then
printf '%s' "$NEKO_IMAGE"
return 0
fi
case "$(uname -m)" in
x86_64|amd64)
printf '%s' "$NEKO_IMAGE_X86"
@@ -766,7 +772,7 @@ service_shellcrash_status() {
return 0
fi
running=0
detail="$(filtered_pgrep 'CrashCore|shellcrash' | tr '\n' ';' || true)"
detail="$(filtered_pgrep '(^|[ /])CrashCore([ ]|$)' | tr '\n' ';' || true)"
if unit_active shellcrash.service || [ -n "$detail" ]; then
running=1
fi
@@ -781,10 +787,10 @@ service_shellcrash_status() {
}
service_shellcrash_start() {
if unit_exists shellcrash.service; then
systemctl enable --now shellcrash.service
elif [ -x "$SHELLCRASH_DIR/start.sh" ]; then
if [ -x "$SHELLCRASH_DIR/start.sh" ]; then
"$SHELLCRASH_DIR/start.sh" start
elif unit_exists shellcrash.service; then
systemctl enable --now shellcrash.service
else
kv message "ShellCrash is not installed"
exit 1
@@ -792,6 +798,18 @@ service_shellcrash_start() {
kv message "ShellCrash started"
}
service_shellcrash_restart() {
if [ -x "$SHELLCRASH_DIR/start.sh" ]; then
"$SHELLCRASH_DIR/start.sh" restart
elif unit_exists shellcrash.service; then
systemctl restart shellcrash.service
else
kv message "ShellCrash is not installed"
exit 1
fi
kv message "ShellCrash restarted"
}
service_shellcrash_stop() {
if unit_exists shellcrash.service; then
systemctl stop shellcrash.service
@@ -801,6 +819,149 @@ service_shellcrash_stop() {
kv message "ShellCrash stopped"
}
service_shellcrash_apply_profile() {
local src="${ACTION_ARG1:-$SHELLCRASH_DIR/yamls/LsRzcR3pHoA9.yaml}"
local target_node="${ACTION_ARG2:-5d723acc-singbox_tuic3}"
local src_real stage_root shell_yaml_root profile_name cfg unit_path selected
if [ -z "$target_node" ] || printf '%s' "$target_node" | grep -q '[[:cntrl:]]'; then
kv message "Invalid ShellCrash target node"
exit 1
fi
if ! have realpath; then
kv message "realpath is required to apply ShellCrash profile"
exit 1
fi
src_real="$(realpath -m "$src")"
stage_root="$(realpath -m "$ROOT_DIR/.process_runner")"
shell_yaml_root="$(realpath -m "$SHELLCRASH_DIR/yamls")"
case "$src_real" in
"$stage_root"/*|"$shell_yaml_root"/*) ;;
*)
kv message "ShellCrash profile path must be staged under $stage_root or $shell_yaml_root"
exit 1
;;
esac
if [ ! -s "$src_real" ]; then
kv message "ShellCrash profile is missing or empty: $src_real"
exit 1
fi
mkdir -p "$SHELLCRASH_DIR/yamls" "$SHELLCRASH_DIR/configs" /tmp/ShellCrash
profile_name="$(basename "$src_real")"
case "$profile_name" in
*.yaml|*.yml) ;;
*) profile_name="LsRzcR3pHoA9.yaml" ;;
esac
install -m 0644 "$src_real" "$SHELLCRASH_DIR/yamls/$profile_name"
install -m 0644 "$src_real" "$SHELLCRASH_DIR/yamls/config.yaml"
rm -f "$SHELLCRASH_DIR/configs/web_save" "$SHELLCRASH_DIR/.start_error"
cfg="$SHELLCRASH_DIR/configs/ShellCrash.cfg"
[ -f "$cfg" ] || printf '%s\n' "#ShellCrash配置文件不明勿动" >"$cfg"
set_shellcrash_cfg() {
local key="$1" value="$2"
sed -i "/^${key}=.*/d" "$cfg"
printf '%s=%s\n' "$key" "$value" >>"$cfg"
}
set_shellcrash_cfg crashcore meta
set_shellcrash_cfg cpucore arm64
set_shellcrash_cfg redir_mod "Redir模式"
set_shellcrash_cfg firewall_area 3
set_shellcrash_cfg dns_mod redir_host
set_shellcrash_cfg mix_port 7890
set_shellcrash_cfg redir_port 7892
set_shellcrash_cfg tproxy_port 7893
set_shellcrash_cfg db_port 9999
set_shellcrash_cfg dns_port 1053
set_shellcrash_cfg proxies_bypass ON
set_shellcrash_cfg sniffer ON
set_shellcrash_cfg skip_cert ON
set_shellcrash_cfg common_ports ON
set_shellcrash_cfg multiport "22,53,80,123,443,8080,8443"
set_shellcrash_cfg network_check OFF
cat >"$SHELLCRASH_DIR/configs/command.env" <<EOF
TMPDIR=/tmp/ShellCrash
BINDIR=$SHELLCRASH_DIR
COMMAND="\$TMPDIR/CrashCore -d \$BINDIR -f \$TMPDIR/config.yaml"
EOF
if unit_exists shellcrash.service; then
unit_path="$(systemctl show -p FragmentPath shellcrash.service | sed 's/^FragmentPath=//')"
if [ -n "$unit_path" ] && [ -f "$unit_path" ]; then
sed -i "s#^ExecStart=.*#ExecStart=/tmp/ShellCrash/CrashCore -d $SHELLCRASH_DIR -f /tmp/ShellCrash/config.yaml#" "$unit_path"
systemctl daemon-reload
fi
systemctl reset-failed shellcrash.service >/dev/null 2>&1 || true
systemctl restart shellcrash.service
elif [ -x "$SHELLCRASH_DIR/start.sh" ]; then
"$SHELLCRASH_DIR/start.sh" restart
else
kv message "ShellCrash is not installed"
exit 1
fi
selected=""
if have python3; then
selected="$(python3 - "$target_node" "$SHELLCRASH_DIR/configs/ShellCrash.cfg" <<'PY' || true
import json
import sys
import time
import urllib.parse
import urllib.request
target = sys.argv[1]
cfg_path = sys.argv[2]
base = "http://127.0.0.1:9999"
secret = ""
try:
with open(cfg_path, encoding="utf-8", errors="replace") as fh:
for line in fh:
if line.startswith("secret="):
secret = line.split("=", 1)[1].strip()
break
except OSError:
pass
headers = {"Content-Type": "application/json"}
if secret:
headers["Authorization"] = f"Bearer {secret}"
def request(path, *, data=None, method="GET"):
req = urllib.request.Request(base + path, data=data, headers=headers, method=method)
return urllib.request.urlopen(req, timeout=3).read()
last = None
for _ in range(30):
try:
payload = json.loads(request("/proxies").decode("utf-8"))
break
except Exception as exc: # noqa: BLE001
last = exc
time.sleep(1)
else:
raise SystemExit(f"api unavailable: {last}")
changed = []
for name, item in payload.get("proxies", {}).items():
all_nodes = item.get("all") or []
if target in all_nodes and item.get("type") in ("Selector", "URLTest", "Fallback", "LoadBalance"):
body = json.dumps({"name": target}).encode("utf-8")
request("/proxies/" + urllib.parse.quote(name, safe=""), data=body, method="PUT")
changed.append(name)
print("|".join(changed))
PY
)"
fi
kv message "ShellCrash profile applied"
kv profile "$SHELLCRASH_DIR/yamls/config.yaml"
kv target_node "$target_node"
kv selected "$selected"
}
service_srs_status() {
if ! have docker || [ ! -f "$SRS_COMPOSE" ]; then
kv available 0