mirror of
https://github.com/caiwx86/small-packages.git
synced 2026-10-30 07:25:13 +08:00
update 2026-09-24 10:46:53
This commit is contained in:
1 parent
907a158127
commit
b31a5c3878
4914 files changed
-1716179
No files matched your search
@@ -1,343 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
. "$IPKG_INSTROOT/etc/momo/scripts/include.sh"
|
||||
|
||||
enabled=`uci get momo.config.enabled`
|
||||
|
||||
if [ "$enabled" == "0" ]; then
|
||||
uci set momo.config.enabled=1
|
||||
uci commit momo
|
||||
/etc/init.d/momo restart
|
||||
fi
|
||||
|
||||
echo \
|
||||
"
|
||||
# Momo Debug Info
|
||||
## system
|
||||
\`\`\`shell
|
||||
`
|
||||
cat /etc/openwrt_release
|
||||
`
|
||||
\`\`\`
|
||||
## kernel
|
||||
\`\`\`
|
||||
`
|
||||
uname -a
|
||||
`
|
||||
\`\`\`
|
||||
## application
|
||||
\`\`\`
|
||||
`
|
||||
if [ -x "/bin/opkg" ]; then
|
||||
opkg list-installed "momo"
|
||||
opkg list-installed "luci-app-momo"
|
||||
elif [ -x "/usr/bin/apk" ]; then
|
||||
apk list -I "momo"
|
||||
apk list -I "luci-app-momo"
|
||||
fi
|
||||
`
|
||||
\`\`\`
|
||||
## config
|
||||
\`\`\`json
|
||||
`
|
||||
ucode -S -e '
|
||||
import { cursor } from "uci";
|
||||
|
||||
const uci = cursor();
|
||||
|
||||
const config = uci.get_all("momo");
|
||||
const result = {};
|
||||
|
||||
for (let section_id in config) {
|
||||
const section = config[section_id];
|
||||
const section_type = section[".type"];
|
||||
if (result[section_type] == null) {
|
||||
result[section_type] = [];
|
||||
}
|
||||
push(result[section_type], section);
|
||||
}
|
||||
for (let section_type in result) {
|
||||
for (let section in result[section_type]) {
|
||||
delete section[".anonymous"];
|
||||
delete section[".type"];
|
||||
delete section[".name"];
|
||||
delete section[".index"];
|
||||
}
|
||||
}
|
||||
if (exists(result, "subscription")) {
|
||||
for (let x in result["subscription"]) {
|
||||
if (exists(x, "url")) {
|
||||
x["url"] = "*";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (exists(result, "lan_access_control")) {
|
||||
for (let x in result["lan_access_control"]) {
|
||||
if (exists(x, "ip")) {
|
||||
for (let i = 0; i < length(x["ip"]); i++) {
|
||||
x["ip"][i] = "*";
|
||||
}
|
||||
}
|
||||
if (exists(x, "ip6")) {
|
||||
for (let i = 0; i < length(x["ip6"]); i++) {
|
||||
x["ip6"][i] = "*";
|
||||
}
|
||||
}
|
||||
if (exists(x, "mac")) {
|
||||
for (let i = 0; i < length(x["mac"]); i++) {
|
||||
x["mac"][i] = "*";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
delete result["placeholder"];
|
||||
print(result);
|
||||
'
|
||||
`
|
||||
\`\`\`
|
||||
## profile
|
||||
\`\`\`json
|
||||
`
|
||||
ucode -S -e '
|
||||
import { readfile } from "fs";
|
||||
|
||||
function desensitize_inbounds(inbounds) {
|
||||
for (let x in inbounds) {
|
||||
if (exists(x, "password")) {
|
||||
x["password"] = "*";
|
||||
}
|
||||
if (exists(x, "users")) {
|
||||
x["users"] = "*";
|
||||
}
|
||||
if (exists(x, "obfs")) {
|
||||
if (exists(x["obfs"], "password")) {
|
||||
x["obfs"]["password"] = "*";
|
||||
}
|
||||
}
|
||||
if (exists(x, "tls")) {
|
||||
if (exists(x["tls"], "server_name")) {
|
||||
x["tls"]["server_name"] = "*";
|
||||
}
|
||||
if (exists(x["tls"], "certificate")) {
|
||||
x["tls"]["certificate"] = "*";
|
||||
}
|
||||
if (exists(x["tls"], "key")) {
|
||||
x["tls"]["key"] = "*";
|
||||
}
|
||||
if (exists(x["tls"], "acme")) {
|
||||
x["tls"]["acme"] = {};
|
||||
}
|
||||
if (exists(x["tls"], "reality")) {
|
||||
if (exists(x["tls"]["reality"], "private_key")) {
|
||||
x["tls"]["reality"]["private_key"] = "*";
|
||||
}
|
||||
if (exists(x["tls"]["reality"], "short_id")) {
|
||||
x["tls"]["reality"]["short_id"] = "*";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (exists(x, "transport")) {
|
||||
if (exists(x["transport"], "host")) {
|
||||
x["transport"]["host"] = "*";
|
||||
}
|
||||
if (exists(x["transport"], "path")) {
|
||||
x["transport"]["path"] = "*";
|
||||
}
|
||||
if (exists(x["transport"], "server_name")) {
|
||||
x["transport"]["server_name"] = "*";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function desensitize_outbounds(outbounds) {
|
||||
for (let x in outbounds) {
|
||||
if (exists(x, "server")) {
|
||||
x["server"] = "*";
|
||||
}
|
||||
if (exists(x, "server_port")) {
|
||||
x["server_port"] = "*";
|
||||
}
|
||||
if (exists(x, "server_ports")) {
|
||||
x["server_port"] = "*";
|
||||
}
|
||||
if (exists(x, "sni")) {
|
||||
x["sni"] = "*";
|
||||
}
|
||||
if (exists(x, "ports")) {
|
||||
x["ports"] = "*";
|
||||
}
|
||||
if (exists(x, "port-range")) {
|
||||
x["port-range"] = "*";
|
||||
}
|
||||
if (exists(x, "uuid")) {
|
||||
x["uuid"] = "*";
|
||||
}
|
||||
if (exists(x, "private-key")) {
|
||||
x["private-key"] = "*";
|
||||
}
|
||||
if (exists(x, "public-key")) {
|
||||
x["public-key"] = "*";
|
||||
}
|
||||
if (exists(x, "token")) {
|
||||
x["token"] = "*";
|
||||
}
|
||||
if (exists(x, "user")) {
|
||||
x["user"] = "*";
|
||||
}
|
||||
if (exists(x, "username")) {
|
||||
x["username"] = "*";
|
||||
}
|
||||
if (exists(x, "password")) {
|
||||
x["password"] = "*";
|
||||
}
|
||||
if (exists(x, "obfs")) {
|
||||
if (exists(x["obfs"], "password")) {
|
||||
x["obfs"]["password"] = "*";
|
||||
}
|
||||
}
|
||||
if (exists(x, "tls")) {
|
||||
if (exists(x["tls"], "server_name")) {
|
||||
x["tls"]["server_name"] = "*";
|
||||
}
|
||||
if (exists(x["tls"], "certificate")) {
|
||||
x["tls"]["certificate"] = "*";
|
||||
}
|
||||
if (exists(x["tls"], "reality")) {
|
||||
if (exists(x["tls"]["reality"], "public_key")) {
|
||||
x["tls"]["reality"]["public_key"] = "*";
|
||||
}
|
||||
if (exists(x["tls"]["reality"], "short_id")) {
|
||||
x["tls"]["reality"]["short_id"] = "*";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (exists(x, "transport")) {
|
||||
if (exists(x["transport"], "host")) {
|
||||
x["transport"]["host"] = "*";
|
||||
}
|
||||
if (exists(x["transport"], "path")) {
|
||||
x["transport"]["path"] = "*";
|
||||
}
|
||||
if (exists(x["transport"], "server_name")) {
|
||||
x["transport"]["server_name"] = "*";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function desensitize_endpoints(endpoints) {
|
||||
for (let x in endpoints) {
|
||||
if (exists(x, "private_key")) {
|
||||
x["private_key"] = "*";
|
||||
}
|
||||
if (exists(x, "peers")) {
|
||||
for (let y in x["peers"]) {
|
||||
if (exists(y, "address")) {
|
||||
y["address"] = "*";
|
||||
}
|
||||
if (exists(y, "port")) {
|
||||
y["port"] = "*";
|
||||
}
|
||||
if (exists(y, "public_key")) {
|
||||
y["public_key"] = "*";
|
||||
}
|
||||
if (exists(y, "pre_shared_key")) {
|
||||
y["pre_shared_key"] = "*";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (exists(x, "auth_key")) {
|
||||
x["auth_key"] = "*";
|
||||
}
|
||||
if (exists(x, "control_url")) {
|
||||
x["control_url"] = "*";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function desensitize_profile() {
|
||||
const profile = json(readfile("/etc/momo/run/config.json"));
|
||||
if (exists(profile, "experimental") && exists(profile["experimental"], "clash_api") && exists(profile["experimental"]["clash_api"], "secret")) {
|
||||
profile["secret"] = "*";
|
||||
}
|
||||
if (exists(profile, "inbounds")) {
|
||||
desensitize_inbounds(profile["inbounds"]);
|
||||
}
|
||||
if (exists(profile, "outbounds")) {
|
||||
desensitize_outbounds(profile["outbounds"]);
|
||||
}
|
||||
if (exists(profile, "endpoints")) {
|
||||
desensitize_endpoints(profile["endpoints"]);
|
||||
}
|
||||
if (exists(profile, "services")) {
|
||||
profile["services"] = [];
|
||||
}
|
||||
return profile;
|
||||
}
|
||||
|
||||
print(desensitize_profile());
|
||||
'
|
||||
`
|
||||
\`\`\`
|
||||
## ip rule
|
||||
\`\`\`
|
||||
`
|
||||
ip rule list
|
||||
`
|
||||
\`\`\`
|
||||
## ip route
|
||||
\`\`\`
|
||||
TPROXY:
|
||||
`
|
||||
ip route list table "$(uci get momo.routing.tproxy_route_table)"
|
||||
`
|
||||
|
||||
TUN:
|
||||
`
|
||||
ip route list table "$(uci get momo.routing.tun_route_table)"
|
||||
`
|
||||
\`\`\`
|
||||
## ip6 rule
|
||||
\`\`\`
|
||||
`
|
||||
ip -6 rule list
|
||||
`
|
||||
\`\`\`
|
||||
## ip6 route
|
||||
\`\`\`
|
||||
TPROXY:
|
||||
`
|
||||
ip -6 route list table "$(uci get momo.routing.tproxy_route_table)"
|
||||
`
|
||||
|
||||
TUN:
|
||||
`
|
||||
ip -6 route list table "$(uci get momo.routing.tun_route_table)"
|
||||
`
|
||||
\`\`\`
|
||||
## firewall tables
|
||||
\`\`\`
|
||||
`
|
||||
nft list tables
|
||||
`
|
||||
\`\`\`
|
||||
## firewall
|
||||
\`\`\`
|
||||
`
|
||||
nft list table inet momo
|
||||
`
|
||||
\`\`\`
|
||||
## service
|
||||
\`\`\`json
|
||||
`
|
||||
/etc/init.d/momo info
|
||||
`
|
||||
\`\`\`
|
||||
"
|
||||
|
||||
if [ "$enabled" == "0" ]; then
|
||||
uci set momo.config.enabled=0
|
||||
uci commit momo
|
||||
/etc/init.d/momo restart
|
||||
fi
|
||||
@@ -1,23 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
. "$IPKG_INSTROOT/lib/functions.sh"
|
||||
. "$IPKG_INSTROOT/etc/momo/scripts/include.sh"
|
||||
|
||||
config_load momo
|
||||
config_get_bool enabled "config" "enabled" 0
|
||||
config_get_bool core_only "config" "core_only" 0
|
||||
config_get_bool proxy_enabled "proxy" "enabled" 0
|
||||
config_get tcp_mode "proxy" "tcp_mode"
|
||||
config_get udp_mode "proxy" "udp_mode"
|
||||
config_get tun_inbound_tag "core" "tun_inbound_tag"
|
||||
|
||||
if [ "$enabled" = 1 ] && [ "$core_only" = 0 ] && [ "$proxy_enabled" = 1 ]; then
|
||||
if [ "$tcp_mode" = "tun" ] || [ "$udp_mode" = "tun" ]; then
|
||||
tun_device=$(jsonfilter -q -i "$RUN_PROFILE_PATH" -e "@['inbounds'][*]" | jsonfilter -q -a -e "@[@['tag']='$tun_inbound_tag']" | jsonfilter -q -a -e "@[@['type']='tun']" | jsonfilter -q -e "@['interface_name']")
|
||||
nft insert rule inet fw4 input iifname "$tun_device" counter accept comment "momo"
|
||||
nft insert rule inet fw4 forward oifname "$tun_device" counter accept comment "momo"
|
||||
nft insert rule inet fw4 forward iifname "$tun_device" counter accept comment "momo"
|
||||
fi
|
||||
fi
|
||||
|
||||
exit 0
|
||||
@@ -1,128 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
. "$IPKG_INSTROOT/usr/share/libubox/jshn.sh"
|
||||
|
||||
# paths
|
||||
|
||||
## home
|
||||
HOME_DIR="/etc/momo"
|
||||
PROFILES_DIR="$HOME_DIR/profiles"
|
||||
SUBSCRIPTIONS_DIR="$HOME_DIR/subscriptions"
|
||||
|
||||
## run
|
||||
RUN_DIR="$HOME_DIR/run"
|
||||
RUN_PROFILE_PATH="$RUN_DIR/config.json"
|
||||
|
||||
## ucode
|
||||
UCODE_DIR="$HOME_DIR/ucode"
|
||||
INCLUDE_UC="$UCODE_DIR/include.uc"
|
||||
MIXIN_UC="$UCODE_DIR/mixin.uc"
|
||||
HIJACK_UT="$UCODE_DIR/hijack.ut"
|
||||
|
||||
## scripts
|
||||
SH_DIR="$HOME_DIR/scripts"
|
||||
INCLUDE_SH="$SH_DIR/include.sh"
|
||||
FIREWALL_INCLUDE_SH="$SH_DIR/firewall_include.sh"
|
||||
DEBUG_SH="$SH_DIR/debug.sh"
|
||||
|
||||
## firewall
|
||||
FIREWALL_DIR="$HOME_DIR/firewall"
|
||||
GEOIP_CN_NFT="$FIREWALL_DIR/geoip_cn.nft"
|
||||
GEOIP6_CN_NFT="$FIREWALL_DIR/geoip6_cn.nft"
|
||||
|
||||
## log
|
||||
LOG_DIR="/var/log/momo"
|
||||
APP_LOG_PATH="$LOG_DIR/app.log"
|
||||
CORE_LOG_PATH="$LOG_DIR/core.log"
|
||||
DEBUG_LOG_PATH="$LOG_DIR/debug.log"
|
||||
|
||||
## temp
|
||||
TEMP_DIR="/var/run/momo"
|
||||
PID_FILE_PATH="$TEMP_DIR/momo.pid"
|
||||
STARTED_FLAG_PATH="$TEMP_DIR/started.flag"
|
||||
BRIDGE_NF_CALL_IPTABLES_FLAG_PATH="$TEMP_DIR/bridge_nf_call_iptables.flag"
|
||||
BRIDGE_NF_CALL_IP6TABLES_FLAG_PATH="$TEMP_DIR/bridge_nf_call_ip6tables.flag"
|
||||
|
||||
# functions
|
||||
get_paths() {
|
||||
json_init
|
||||
|
||||
json_add_string home_dir "$HOME_DIR"
|
||||
json_add_string profiles_dir "$PROFILES_DIR"
|
||||
json_add_string subscriptions_dir "$SUBSCRIPTIONS_DIR"
|
||||
|
||||
json_add_string run_dir "$RUN_DIR"
|
||||
json_add_string run_profile_path "$RUN_PROFILE_PATH"
|
||||
|
||||
json_add_string ucode_dir "$UCODE_DIR"
|
||||
json_add_string include_uc "$INCLUDE_UC"
|
||||
json_add_string hijack_ut "$HIJACK_UT"
|
||||
|
||||
json_add_string sh_dir "$SH_DIR"
|
||||
json_add_string include_sh "$INCLUDE_SH"
|
||||
json_add_string firewall_include_sh "$FIREWALL_INCLUDE_SH"
|
||||
json_add_string debug_sh "$DEBUG_SH"
|
||||
|
||||
json_add_string firewall_dir "$FIREWALL_DIR"
|
||||
json_add_string geoip_cn_nft "$GEOIP_CN_NFT"
|
||||
json_add_string geoip6_cn_nft "$GEOIP6_CN_NFT"
|
||||
|
||||
json_add_string log_dir "$LOG_DIR"
|
||||
json_add_string app_log_path "$APP_LOG_PATH"
|
||||
json_add_string core_log_path "$CORE_LOG_PATH"
|
||||
json_add_string debug_log_path "$DEBUG_LOG_PATH"
|
||||
|
||||
json_add_string temp_dir "$TEMP_DIR"
|
||||
json_add_string pid_file_path "$PID_FILE_PATH"
|
||||
json_add_string started_flag_path "$STARTED_FLAG_PATH"
|
||||
json_add_string bridge_nf_call_iptables_flag_path "$BRIDGE_NF_CALL_IPTABLES_FLAG_PATH"
|
||||
json_add_string bridge_nf_call_ip6tables_flag_path "$BRIDGE_NF_CALL_IP6TABLES_FLAG_PATH"
|
||||
|
||||
json_dump
|
||||
|
||||
json_cleanup
|
||||
}
|
||||
|
||||
format_filesize() {
|
||||
local b; b=1
|
||||
local kb; kb=$((b * 1024))
|
||||
local mb; mb=$((kb * 1024))
|
||||
local gb; gb=$((mb * 1024))
|
||||
local tb; tb=$((gb * 1024))
|
||||
local pb; pb=$((tb * 1024))
|
||||
local size; size=$1
|
||||
if [ -n "$size" ]; then
|
||||
if [ "$size" -lt "$kb" ]; then
|
||||
echo "$(awk "BEGIN {print $size / $b}") B"
|
||||
elif [ "$size" -lt "$mb" ]; then
|
||||
echo "$(awk "BEGIN {print $size / $kb}") KB"
|
||||
elif [ "$size" -lt "$gb" ]; then
|
||||
echo "$(awk "BEGIN {print $size / $mb}") MB"
|
||||
elif [ "$size" -lt "$tb" ]; then
|
||||
echo "$(awk "BEGIN {print $size / $gb}") GB"
|
||||
elif [ "$size" -lt "$pb" ]; then
|
||||
echo "$(awk "BEGIN {print $size / $tb}") TB"
|
||||
else
|
||||
echo "$(awk "BEGIN {print $size / $pb}") PB"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
prepare_files() {
|
||||
if [ ! -d "$LOG_DIR" ]; then
|
||||
mkdir -p "$LOG_DIR"
|
||||
fi
|
||||
if [ ! -f "$APP_LOG_PATH" ]; then
|
||||
touch "$APP_LOG_PATH"
|
||||
fi
|
||||
if [ ! -f "$CORE_LOG_PATH" ]; then
|
||||
touch "$CORE_LOG_PATH"
|
||||
fi
|
||||
if [ ! -d "$TEMP_DIR" ]; then
|
||||
mkdir -p "$TEMP_DIR"
|
||||
fi
|
||||
}
|
||||
|
||||
log() {
|
||||
echo "[$(date "+%Y-%m-%d %H:%M:%S")] [$1] $2" >> "$APP_LOG_PATH"
|
||||
}
|
||||
Reference in new issue
Block a user