🎨 Sync 2026-04-10 15:34:26

This commit is contained in:
github-actions[bot] committed 2026-04-10 15:34:26 +08:00
1 parent 9b1a57d792
commit 42174fc0b0
66 files changed
+6841 -2210

No files matched your search

+19 -8
View File
@@ -4,17 +4,10 @@ config config 'config'
option 'profile' 'file:example.json'
option 'start_delay' '0'
option 'scheduled_restart' '0'
option 'cron_expression' '0 3 * * *'
option 'scheduled_restart_cron' '0 3 * * *'
option 'test_profile' '1'
option 'core_only' '0'
config log 'log'
option 'log_cleanup_enabled' '0'
option 'log_cleanup_cron_expression' '0 4 * * *'
option 'log_cleanup_size_enabled' '0'
option 'log_cleanup_size_check_cron_expression' '*/30 * * * *'
option 'log_cleanup_size_mb' '50'
config procd 'procd'
option 'fast_reload' '0'
@@ -25,6 +18,18 @@ config core 'core'
option 'dns_inbound_tag' 'dns-in'
option 'fake_ip_dns_server_tag' 'fake-ip-dns-server'
config mixin 'mixin'
option 'log_disabled' '0'
option 'log_level' 'info'
option 'log_timestamp' '1'
option 'dns_independent_cache' '1'
option 'dns_reverse_mapping' '1'
option 'cache_enabled' '1'
option 'cache_store_fakeip' '1'
option 'cache_store_rdrc' '1'
option 'external_control_ui_path' 'ui'
option 'external_control_ui_download_url' 'https://github.com/Zephyruso/zashboard/releases/latest/download/dist-cdn-fonts.zip'
config proxy 'proxy'
option 'enabled' '1'
option 'ipv4_dns_hijack' '1'
@@ -115,4 +120,10 @@ config routing 'routing'
option 'cgroup_name' 'momo'
option 'dummy_device' 'momo-dummy'
config log 'log'
option 'scheduled_clear' '1'
option 'scheduled_clear_cron' '*/5 * * * *'
option 'scheduled_clear_size_limit' '1'
option 'scheduled_clear_size_limit_unit' 'MB'
config placeholder 'placeholder'
+50 -59
View File
@@ -9,8 +9,7 @@ PROG="/usr/bin/sing-box"
. "$IPKG_INSTROOT/etc/momo/scripts/include.sh"
extra_command 'update_subscription' 'Update subscription by section id'
extra_command 'cleanup_logs' 'Cleanup logs immediately'
extra_command 'check_log_cleanup' 'Cleanup logs if size threshold is reached'
extra_command 'clear_logs' 'Clear logs if size exceeds the limit'
boot_func() {
# prepare files
@@ -30,7 +29,7 @@ boot_func() {
}
boot() {
boot_func &
boot_func < /dev/null > /dev/null 2>&1 &
}
start_service() {
@@ -64,11 +63,6 @@ start_service() {
config_get profile "config" "profile"
config_get_bool test_profile "config" "test_profile" 0
config_get_bool core_only "config" "core_only" 0
config_get_bool log_cleanup_enabled "log" "log_cleanup_enabled" 0
config_get log_cleanup_cron_expression "log" "log_cleanup_cron_expression"
config_get_bool log_cleanup_size_enabled "log" "log_cleanup_size_enabled" 0
config_get log_cleanup_size_check_cron_expression "log" "log_cleanup_size_check_cron_expression"
config_get log_cleanup_size_mb "log" "log_cleanup_size_mb" 0
## procd config
### general
local fast_reload
@@ -97,6 +91,10 @@ start_service() {
config_get_bool ipv6_dns_hijack "proxy" "ipv6_dns_hijack" 0
config_get tcp_mode "proxy" "tcp_mode"
config_get udp_mode "proxy" "udp_mode"
## log config
local log_scheduled_clear log_scheduled_clear_cron
config_get_bool log_scheduled_clear "log" "scheduled_clear" 0
config_get log_scheduled_clear_cron "log" "scheduled_clear_cron"
# get profile
local profile_type; profile_type=$(echo "$profile" | cut -d ':' -f 1)
local profile_id; profile_id=$(echo "$profile" | cut -d ':' -f 2)
@@ -131,6 +129,11 @@ start_service() {
log "App" "Exit."
return
fi
# mixin
if [ "$core_only" = 0 ]; then
log "Mixin" "Mixin config."
ucode -S "$MIXIN_UC"
fi
# check profile
if [ "$core_only" = 0 ] && [ "$proxy_enabled" = 1 ]; then
log "Profile" "Checking..."
@@ -202,23 +205,18 @@ start_service() {
procd_close_instance
# cron
local cron_reload; cron_reload=0
if [ "$scheduled_restart" = 1 ] && [ -n "$cron_expression" ]; then
local reload_cron; reload_cron=0
if [ "$scheduled_restart" = 1 ] && [ -n "$scheduled_restart_cron" ]; then
log "App" "Set scheduled restart."
echo "$cron_expression /etc/init.d/momo restart #momo_scheduled_restart" >> "/etc/crontabs/root"
cron_reload=1
echo "$scheduled_restart_cron /etc/init.d/momo restart #momo scheduled restart" >> "/etc/crontabs/root"
reload_cron=1
fi
if [ "$log_cleanup_enabled" = 1 ] && [ -n "$log_cleanup_cron_expression" ]; then
log "Log" "Set scheduled log cleanup."
echo "$log_cleanup_cron_expression /etc/init.d/momo cleanup_logs > /dev/null 2>&1 #momo_log_cleanup_time" >> "/etc/crontabs/root"
cron_reload=1
if [ "$log_scheduled_clear" = 1 ] && [ -n "$log_scheduled_clear_cron" ]; then
log "App" "Set log scheduled clear."
echo "$log_scheduled_clear_cron /etc/init.d/momo clear_logs #momo log scheduled clear" >> "/etc/crontabs/root"
reload_cron=1
fi
if [ "$log_cleanup_size_enabled" = 1 ] && [ -n "$log_cleanup_size_check_cron_expression" ] && [ "${log_cleanup_size_mb:-0}" -gt 0 ]; then
log "Log" "Set size-based log cleanup check."
echo "$log_cleanup_size_check_cron_expression /etc/init.d/momo check_log_cleanup > /dev/null 2>&1 #momo_log_cleanup_size" >> "/etc/crontabs/root"
cron_reload=1
fi
if [ "$cron_reload" = 1 ]; then
if [ "$reload_cron" = 1 ]; then
/etc/init.d/cron restart
fi
# set started flag
@@ -379,8 +377,6 @@ service_triggers() {
}
cleanup() {
# clear log
clear_log
# load config
config_load momo
# get config
@@ -427,44 +423,39 @@ cleanup() {
/etc/init.d/cron restart
}
cleanup_logs() {
prepare_files
run_log_cleanup "scheduled trigger"
}
check_log_cleanup() {
prepare_files
clear_logs() {
# load config
config_load momo
local log_cleanup_size_enabled log_cleanup_size_mb total_size_bytes threshold_size_bytes
config_get_bool log_cleanup_size_enabled "log" "log_cleanup_size_enabled" 0
config_get log_cleanup_size_mb "log" "log_cleanup_size_mb" 0
if [ "$log_cleanup_size_enabled" != 1 ] || [ "${log_cleanup_size_mb:-0}" -le 0 ]; then
return
# get config
## log config
local log_scheduled_clear_size_limit log_scheduled_clear_size_limit_unit
config_get log_scheduled_clear_size_limit "log" "scheduled_clear_size_limit" 1
config_get log_scheduled_clear_size_limit_unit "log" "scheduled_clear_size_limit_unit" "MB"
# prepare config
local log_scheduled_clear_size_limit_in_bytes; log_scheduled_clear_size_limit_in_bytes=0
case "$log_scheduled_clear_size_limit_unit" in
B)
log_scheduled_clear_size_limit_in_bytes=$((log_scheduled_clear_size_limit))
;;
KB)
log_scheduled_clear_size_limit_in_bytes=$((log_scheduled_clear_size_limit * 1024))
;;
MB)
log_scheduled_clear_size_limit_in_bytes=$((log_scheduled_clear_size_limit * 1024 * 1024))
;;
GB)
log_scheduled_clear_size_limit_in_bytes=$((log_scheduled_clear_size_limit * 1024 * 1024 * 1024))
;;
esac
# clear logs
if [ -f "$APP_LOG_PATH" ] && [ "$(wc -c < "$APP_LOG_PATH")" -ge "$log_scheduled_clear_size_limit_in_bytes" ]; then
echo -n > "$APP_LOG_PATH"
log "Log" "App log is cleared due to scheduled clear and exceeding size limits."
fi
total_size_bytes=$(get_total_log_size)
threshold_size_bytes=$((log_cleanup_size_mb * 1024 * 1024))
if [ "$total_size_bytes" -lt "$threshold_size_bytes" ]; then
return
if [ -f "$CORE_LOG_PATH" ] && [ "$(wc -c < "$CORE_LOG_PATH")" -ge "$log_scheduled_clear_size_limit_in_bytes" ]; then
echo -n > "$CORE_LOG_PATH"
log "Log" "Core log is cleared due to scheduled clear and exceeding size limits."
fi
run_log_cleanup "size threshold ${log_cleanup_size_mb} MB reached" "$total_size_bytes"
}
run_log_cleanup() {
local reason previous_size
reason="$1"
previous_size="$2"
if [ -z "$previous_size" ]; then
previous_size=$(get_total_log_size)
fi
clear_log
log "Log" "Cleanup executed: ${reason}. Previous total size: $(format_filesize "$previous_size")."
}
update_subscription() {
-28
View File
@@ -118,39 +118,11 @@ prepare_files() {
if [ ! -f "$CORE_LOG_PATH" ]; then
touch "$CORE_LOG_PATH"
fi
if [ ! -f "$DEBUG_LOG_PATH" ]; then
touch "$DEBUG_LOG_PATH"
fi
if [ ! -d "$TEMP_DIR" ]; then
mkdir -p "$TEMP_DIR"
fi
}
clear_log() {
echo -n > "$APP_LOG_PATH"
echo -n > "$CORE_LOG_PATH"
echo -n > "$DEBUG_LOG_PATH"
}
get_filesize() {
local path; path="$1"
if [ ! -f "$path" ]; then
echo 0
return
fi
wc -c < "$path" | tr -d '[:space:]'
}
get_total_log_size() {
local total_size path path_size
total_size=0
for path in "$APP_LOG_PATH" "$CORE_LOG_PATH" "$DEBUG_LOG_PATH"; do
path_size=$(get_filesize "$path")
total_size=$((total_size + path_size))
done
echo "$total_size"
}
log() {
echo "[$(date "+%Y-%m-%d %H:%M:%S")] [$1] $2" >> "$APP_LOG_PATH"
}
+21
View File
@@ -0,0 +1,21 @@
#!/bin/sh
. "$IPKG_INSTROOT/etc/momo/scripts/include.sh"
# check momo.config.init
init=$(uci -q get momo.config.init); [ -z "$init" ] && return
# generate random string for api secret and authentication password
random=$(awk 'BEGIN{srand(); printf "%06d", int(rand() * 1000000)}')
# set momo.mixin.api_secret
uci set momo.mixin.external_control_api_secret="$random"
# remove momo.config.init
uci del momo.config.init
# commit
uci commit momo
# exit with 0
exit 0
+19 -32
View File
@@ -27,42 +27,29 @@ dummy_device=$(uci -q get momo.routing.dummy_device); [ -z "$dummy_device" ] &&
# since v1.1.2
section_log=$(uci -q get momo.log); [ -z "$section_log" ] && uci set momo.log=log
config_scheduled_restart_cron=$(uci -q get momo.config.scheduled_restart_cron); [ -z "$config_scheduled_restart_cron" ] && uci rename momo.config.cron_expression="scheduled_restart_cron"
log_cleanup_enabled=$(uci -q get momo.log.log_cleanup_enabled)
[ -z "$log_cleanup_enabled" ] && {
log_cleanup_enabled=$(uci -q get momo.config.log_cleanup_enabled)
[ -n "$log_cleanup_enabled" ] && uci set momo.log.log_cleanup_enabled=$log_cleanup_enabled || uci set momo.log.log_cleanup_enabled=0
section_log=$(uci -q get momo.log); [ -z "$section_log" ] && {
uci set momo.log=log
uci set momo.log.scheduled_clear=1
uci set momo.log.scheduled_clear_cron="*/5 * * * *"
uci set momo.log.scheduled_clear_size_limit=1
uci set momo.log.scheduled_clear_size_limit_unit=MB
}
uci -q del momo.config.log_cleanup_enabled
log_cleanup_cron_expression=$(uci -q get momo.log.log_cleanup_cron_expression)
[ -z "$log_cleanup_cron_expression" ] && {
log_cleanup_cron_expression=$(uci -q get momo.config.log_cleanup_cron_expression)
[ -n "$log_cleanup_cron_expression" ] && uci set momo.log.log_cleanup_cron_expression="$log_cleanup_cron_expression" || uci set momo.log.log_cleanup_cron_expression='0 4 * * *'
section_mixin=$(uci -q get momo.mixin); [ -z "$section_mixin" ] && {
uci set momo.mixin=mixin
uci set momo.mixin.log_disabled='0'
uci set momo.mixin.log_level='info'
uci set momo.mixin.log_timestamp='1'
uci set momo.mixin.dns_independent_cache='1'
uci set momo.mixin.dns_reverse_mapping='1'
uci set momo.mixin.cache_enabled='1'
uci set momo.mixin.cache_store_fakeip='1'
uci set momo.mixin.cache_store_rdrc='1'
uci set momo.mixin.external_control_ui_path='ui'
uci set momo.mixin.external_control_ui_download_url='https://github.com/Zephyruso/zashboard/releases/latest/download/dist-cdn-fonts.zip'
}
uci -q del momo.config.log_cleanup_cron_expression
log_cleanup_size_enabled=$(uci -q get momo.log.log_cleanup_size_enabled)
[ -z "$log_cleanup_size_enabled" ] && {
log_cleanup_size_enabled=$(uci -q get momo.config.log_cleanup_size_enabled)
[ -n "$log_cleanup_size_enabled" ] && uci set momo.log.log_cleanup_size_enabled=$log_cleanup_size_enabled || uci set momo.log.log_cleanup_size_enabled=0
}
uci -q del momo.config.log_cleanup_size_enabled
log_cleanup_size_check_cron_expression=$(uci -q get momo.log.log_cleanup_size_check_cron_expression)
[ -z "$log_cleanup_size_check_cron_expression" ] && {
log_cleanup_size_check_cron_expression=$(uci -q get momo.config.log_cleanup_size_check_cron_expression)
[ -n "$log_cleanup_size_check_cron_expression" ] && uci set momo.log.log_cleanup_size_check_cron_expression="$log_cleanup_size_check_cron_expression" || uci set momo.log.log_cleanup_size_check_cron_expression='*/30 * * * *'
}
uci -q del momo.config.log_cleanup_size_check_cron_expression
log_cleanup_size_mb=$(uci -q get momo.log.log_cleanup_size_mb)
[ -z "$log_cleanup_size_mb" ] && {
log_cleanup_size_mb=$(uci -q get momo.config.log_cleanup_size_mb)
[ -n "$log_cleanup_size_mb" ] && uci set momo.log.log_cleanup_size_mb=$log_cleanup_size_mb || uci set momo.log.log_cleanup_size_mb=50
}
uci -q del momo.config.log_cleanup_size_mb
# commit
uci commit momo
+11 -1
View File
@@ -1,4 +1,4 @@
import { readfile, popen } from 'fs';
import { readfile, writefile, popen } from 'fs';
export function get_paths() {
let result = {};
@@ -120,4 +120,14 @@ export function get_cgroups() {
}
}
return result;
};
export function load_profile() {
const paths = get_paths();
return json(readfile(paths.run_profile_path));
};
export function save_profile(obj) {
const paths = get_paths();
return writefile(paths.run_profile_path, obj);
};
+48
View File
@@ -0,0 +1,48 @@
#!/usr/bin/ucode
'use strict';
import { cursor } from 'uci';
import { uci_bool, uci_int, uci_array, merge, trim_all, load_profile, save_profile } from '/etc/momo/ucode/include.uc';
const uci = cursor();
const config = {};
config['log'] = {};
config['log']['disabled'] = uci_bool(uci.get('momo', 'mixin', 'log_disabled'));
config['log']['level'] = uci.get('momo', 'mixin', 'log_level');
config['log']['timestamp'] = uci_bool(uci.get('momo', 'mixin', 'log_timestamp'));
config['log']['output'] = uci.get('momo', 'mixin', 'log_output');
config['dns'] = {};
config['dns']['strategy'] = uci.get('momo', 'mixin', 'dns_strategy');
config['dns']['disable_cache'] = uci_bool(uci.get('momo', 'mixin', 'dns_disable_cache'));
config['dns']['disable_expire'] = uci_bool(uci.get('momo', 'mixin', 'dns_disable_expire'));
config['dns']['independent_cache'] = uci_bool(uci.get('momo', 'mixin', 'dns_independent_cache'));
config['dns']['cache_capacity'] = uci_int(uci.get('momo', 'mixin', 'dns_cache_capacity'));
config['dns']['reverse_mapping'] = uci_bool(uci.get('momo', 'mixin', 'dns_reverse_mapping'));
config['ntp'] = {};
config['ntp']['enabled'] = uci_bool(uci.get('momo', 'mixin', 'ntp_enabled'));
config['ntp']['server'] = uci.get('momo', 'mixin', 'ntp_server');
config['ntp']['server_port'] = uci_int(uci.get('momo', 'mixin', 'ntp_server_port'));
config['ntp']['interval'] = uci.get('momo', 'mixin', 'ntp_interval');
config['experimental'] = {};
config['experimental']['cache_file'] = {};
config['experimental']['cache_file']['enabled'] = uci_bool(uci.get('momo', 'mixin', 'cache_enabled'));
config['experimental']['cache_file']['path'] = uci.get('momo', 'mixin', 'cache_path');
config['experimental']['cache_file']['store_fakeip'] = uci_bool(uci.get('momo', 'mixin', 'cache_store_fakeip'));
config['experimental']['cache_file']['store_rdrc'] = uci_bool(uci.get('momo', 'mixin', 'cache_store_rdrc'));
config['experimental']['clash_api'] = {};
config['experimental']['clash_api']['external_ui'] = uci.get('momo', 'mixin', 'external_control_ui_path');
config['experimental']['clash_api']['external_ui_download_url'] = uci.get('momo', 'mixin', 'external_control_ui_download_url');
config['experimental']['clash_api']['external_controller'] = uci.get('momo', 'mixin', 'external_control_api_listen');
config['experimental']['clash_api']['secret'] = uci.get('momo', 'mixin', 'external_control_api_secret');
const profile = load_profile();
save_profile(merge(profile, trim_all(config)));