update 2024-11-16 00:27:08
This commit is contained in:
parent
b90ede25b8
commit
fdfbb8e005
|
@ -16,7 +16,7 @@ define Package/$(PKG_NAME)
|
|||
SUBMENU:=3. Applications
|
||||
TITLE:=LuCI support for mihomo
|
||||
PKGARCH:=all
|
||||
DEPENDS:=+kmod-tun +bash +curl +jq +php8 +php8-cgi +php8-mod-curl +php8-mod-zip +php8-cli
|
||||
DEPENDS:=+kmod-tun +bash +curl +jq +php8 +php8-cgi +php8-mod-curl +php8-mod-zip
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)/description
|
||||
|
|
|
@ -223,24 +223,54 @@ function writeToLog($message) {
|
|||
}
|
||||
|
||||
function createCronScript() {
|
||||
$log_rotate_script = '/nekobox/rotate_logs.php';
|
||||
$cron_schedule = "0 1 * * * /usr/bin/php8-cli $log_rotate_script";
|
||||
$cronScriptPath = '/etc/neko/core/set_cron.sh';
|
||||
$log_file = '/var/log/singbox_log.txt';
|
||||
$max_size = 1048576;
|
||||
$max_old_logs = 5;
|
||||
$cron_schedule = "0 1 * * * /bin/bash /etc/neko/core/set_cron.sh";
|
||||
|
||||
$cronScriptContent = <<<EOL
|
||||
#!/bin/bash
|
||||
|
||||
LOG_ROTATE_SCRIPT="$log_rotate_script"
|
||||
LOG_FILE="$log_file"
|
||||
MAX_SIZE=$max_size
|
||||
MAX_OLD_LOGS=$max_old_logs
|
||||
|
||||
CRON_SCHEDULE="0 1 * * * /usr/bin/php8-cli \$LOG_ROTATE_SCRIPT"
|
||||
crontab -l | grep -q "\$LOG_ROTATE_SCRIPT"
|
||||
if [ \$? -ne 0 ]; then
|
||||
CRON_SCHEDULE="0 1 * * * /bin/bash /etc/neko/core/set_cron.sh"
|
||||
|
||||
crontab -l | grep -q "/etc/neko/core/set_cron.sh"
|
||||
if [ $? -ne 0 ]; then
|
||||
(crontab -l 2>/dev/null; echo "\$CRON_SCHEDULE") | crontab -
|
||||
echo "Cron job added to run log rotation daily at 1 AM."
|
||||
else
|
||||
echo "Cron job already exists."
|
||||
fi
|
||||
|
||||
if [ -f "\$LOG_FILE" ] && [ \$(stat -c %s "\$LOG_FILE") -gt \$MAX_SIZE ]; then
|
||||
echo "Log file size exceeds \$MAX_SIZE bytes. Rotating logs..."
|
||||
mv "\$LOG_FILE" "\$LOG_FILE.old"
|
||||
gzip "\$LOG_FILE.old"
|
||||
touch "\$LOG_FILE"
|
||||
chmod 644 "\$LOG_FILE"
|
||||
|
||||
echo "Log file rotated and compressed."
|
||||
else
|
||||
echo "Log file is within the size limit, no rotation needed."
|
||||
fi
|
||||
|
||||
OLD_LOGS=\$(ls -t /var/log/singbox_log*.gz)
|
||||
COUNT=0
|
||||
for LOG in \$OLD_LOGS; do
|
||||
if [ \$COUNT -ge \$MAX_OLD_LOGS ]; then
|
||||
echo "Deleting old log: \$LOG"
|
||||
rm "\$LOG"
|
||||
fi
|
||||
COUNT=\$((COUNT + 1))
|
||||
done
|
||||
|
||||
echo "Log rotation completed."
|
||||
EOL;
|
||||
|
||||
$cronScriptPath = '/etc/neko/core/set_cron.sh';
|
||||
file_put_contents($cronScriptPath, $cronScriptContent);
|
||||
chmod($cronScriptPath, 0755);
|
||||
shell_exec("sh $cronScriptPath");
|
||||
|
|
|
@ -742,32 +742,30 @@ add_firewall_rule() {
|
|||
ipset -! create $IPSET_WHITELIST6 nethash family inet6 maxelem 1048576 timeout 172800
|
||||
ipset -! create $IPSET_BLOCKLIST6 nethash family inet6 maxelem 1048576 timeout 172800
|
||||
|
||||
#分流规则的IP列表
|
||||
process_shunt_rules() {
|
||||
local _node=$1
|
||||
local node_protocol=$(config_n_get $_node protocol)
|
||||
if [ "$node_protocol" = "_shunt" ]; then
|
||||
local default_node_id=$(config_n_get $_node default_node "_direct")
|
||||
local shunt_ids=$(uci show $CONFIG | grep "=shunt_rules" | awk -F '.' '{print $2}' | awk -F '=' '{print $1}')
|
||||
for shunt_id in $shunt_ids; do
|
||||
local _node_id=$(config_n_get $_node $shunt_id "nil")
|
||||
[ "$_node_id" != "nil" ] && {
|
||||
[ "$_node_id" = "_default" ] && _node_id=$default_node_id
|
||||
if [ "$_node_id" = "_direct" ]; then
|
||||
config_n_get $shunt_id ip_list | tr -s "\r\n" "\n" | sed -e "/^$/d" | grep -E "(\.((2(5[0-5]|[0-4][0-9]))|[0-1]?[0-9]{1,2})){3}" | sed -e "s/^/add $IPSET_WHITELIST &/g" -e "s/$/ timeout 0/g" | awk '{print $0} END{print "COMMIT"}' | ipset -! -R
|
||||
config_n_get $shunt_id ip_list | tr -s "\r\n" "\n" | sed -e "/^$/d" | grep -E "([A-Fa-f0-9]{1,4}::?){1,7}[A-Fa-f0-9]{1,4}" | sed -e "s/^/add $IPSET_WHITELIST6 &/g" -e "s/$/ timeout 0/g" | awk '{print $0} END{print "COMMIT"}' | ipset -! -R
|
||||
else
|
||||
config_n_get $shunt_id ip_list | tr -s "\r\n" "\n" | sed -e "/^$/d" | grep -E "(\.((2(5[0-5]|[0-4][0-9]))|[0-1]?[0-9]{1,2})){3}" | sed -e "s/^/add $IPSET_SHUNTLIST &/g" -e "s/$/ timeout 0/g" | awk '{print $0} END{print "COMMIT"}' | ipset -! -R
|
||||
[ "$PROXY_IPV6" = "1" ] && {
|
||||
config_n_get $shunt_id ip_list | tr -s "\r\n" "\n" | sed -e "/^$/d" | grep -E "([A-Fa-f0-9]{1,4}::?){1,7}[A-Fa-f0-9]{1,4}" | sed -e "s/^/add $IPSET_SHUNTLIST6 &/g" -e "s/$/ timeout 0/g" | awk '{print $0} END{print "COMMIT"}' | ipset -! -R
|
||||
}
|
||||
fi
|
||||
}
|
||||
#分流规则的IP列表(使用分流节点时导入)
|
||||
local USE_SHUNT_NODE=0
|
||||
for _node in $TCP_NODE $UDP_NODE; do
|
||||
node_protocol=$(config_n_get $_node protocol)
|
||||
[ "$node_protocol" = "_shunt" ] && { USE_SHUNT_NODE=1; break; }
|
||||
done
|
||||
[ "$USE_SHUNT_NODE" = "0" ] && {
|
||||
for acl_section in $(uci show ${CONFIG} | grep "=acl_rule" | cut -d '.' -sf 2 | cut -d '=' -sf 1); do
|
||||
[ "$(config_n_get $acl_section enabled)" != "1" ] && continue
|
||||
for _node in $(config_n_get $acl_section tcp_node) $(config_n_get $acl_section udp_node); do
|
||||
node_protocol=$(config_n_get $_node protocol)
|
||||
[ "$node_protocol" = "_shunt" ] && { USE_SHUNT_NODE=1; break 2; }
|
||||
done
|
||||
fi
|
||||
done
|
||||
}
|
||||
[ "$USE_SHUNT_NODE" = "1" ] && {
|
||||
local shunt_ids=$(uci show $CONFIG | grep "=shunt_rules" | awk -F '.' '{print $2}' | awk -F '=' '{print $1}')
|
||||
for shunt_id in $shunt_ids; do
|
||||
config_n_get $shunt_id ip_list | tr -s "\r\n" "\n" | sed -e "/^$/d" | grep -E "(\.((2(5[0-5]|[0-4][0-9]))|[0-1]?[0-9]{1,2})){3}" | sed -e "s/^/add $IPSET_SHUNTLIST &/g" -e "s/$/ timeout 0/g" | awk '{print $0} END{print "COMMIT"}' | ipset -! -R
|
||||
[ "$PROXY_IPV6" = "1" ] && {
|
||||
config_n_get $shunt_id ip_list | tr -s "\r\n" "\n" | sed -e "/^$/d" | grep -E "([A-Fa-f0-9]{1,4}::?){1,7}[A-Fa-f0-9]{1,4}" | sed -e "s/^/add $IPSET_SHUNTLIST6 &/g" -e "s/$/ timeout 0/g" | awk '{print $0} END{print "COMMIT"}' | ipset -! -R
|
||||
}
|
||||
done
|
||||
}
|
||||
[ "$TCP_NODE" ] && process_shunt_rules $TCP_NODE
|
||||
[ "$UDP_NODE" ] && [ "$TCP_UDP" = "0" ] && process_shunt_rules $UDP_NODE
|
||||
|
||||
cat $RULES_PATH/chnroute | tr -s '\n' | grep -v "^#" | sed -e "/^$/d" | sed -e "s/^/add $IPSET_CHN &/g" -e "s/$/ timeout 0/g" | awk '{print $0} END{print "COMMIT"}' | ipset -! -R
|
||||
cat $RULES_PATH/proxy_ip | tr -s '\n' | grep -v "^#" | sed -e "/^$/d" | grep -E "(\.((2(5[0-5]|[0-4][0-9]))|[0-1]?[0-9]{1,2})){3}" | sed -e "s/^/add $IPSET_BLACKLIST &/g" -e "s/$/ timeout 0/g" | awk '{print $0} END{print "COMMIT"}' | ipset -! -R
|
||||
|
|
|
@ -166,9 +166,8 @@ insert_nftset() {
|
|||
fi
|
||||
mkdir -p $TMP_PATH2/nftset
|
||||
cat > "$TMP_PATH2/nftset/$nftset_name" <<-EOF
|
||||
#define $nftset_name = {$nftset_elements}
|
||||
#add element $NFTABLE_NAME $nftset_name \$$nftset_name
|
||||
add element $NFTABLE_NAME $nftset_name {$nftset_elements}
|
||||
define $nftset_name = {$nftset_elements}
|
||||
add element $NFTABLE_NAME $nftset_name \$$nftset_name
|
||||
EOF
|
||||
nft -f "$TMP_PATH2/nftset/$nftset_name"
|
||||
rm -rf "$TMP_PATH2/nftset"
|
||||
|
@ -828,32 +827,30 @@ add_firewall_rule() {
|
|||
gen_nftset $NFTSET_BLOCKLIST6 ipv6_addr "2d" 0 $(cat $RULES_PATH/block_ip | tr -s '\n' | grep -v "^#" | grep -E "([A-Fa-f0-9]{1,4}::?){1,7}[A-Fa-f0-9]{1,4}")
|
||||
gen_nftset $NFTSET_SHUNTLIST6 ipv6_addr "2d" 0
|
||||
|
||||
#分流规则的IP列表
|
||||
process_shunt_rules() {
|
||||
local _node=$1
|
||||
local node_protocol=$(config_n_get $_node protocol)
|
||||
if [ "$node_protocol" = "_shunt" ]; then
|
||||
local default_node_id=$(config_n_get $_node default_node "_direct")
|
||||
local shunt_ids=$(uci show $CONFIG | grep "=shunt_rules" | awk -F '.' '{print $2}' | awk -F '=' '{print $1}')
|
||||
for shunt_id in $shunt_ids; do
|
||||
local _node_id=$(config_n_get $_node $shunt_id "nil")
|
||||
[ "$_node_id" != "nil" ] && {
|
||||
[ "$_node_id" = "_default" ] && _node_id=$default_node_id
|
||||
if [ "$_node_id" = "_direct" ]; then
|
||||
insert_nftset $NFTSET_WHITELIST "0" $(config_n_get $shunt_id ip_list | tr -s "\r\n" "\n" | sed -e "/^$/d" | grep -E "(\.((2(5[0-5]|[0-4][0-9]))|[0-1]?[0-9]{1,2})){3}")
|
||||
insert_nftset $NFTSET_WHITELIST6 "0" $(config_n_get $shunt_id ip_list | tr -s "\r\n" "\n" | sed -e "/^$/d" | grep -E "([A-Fa-f0-9]{1,4}::?){1,7}[A-Fa-f0-9]{1,4}")
|
||||
else
|
||||
insert_nftset $NFTSET_SHUNTLIST "0" $(config_n_get $shunt_id ip_list | tr -s "\r\n" "\n" | sed -e "/^$/d" | grep -E "(\.((2(5[0-5]|[0-4][0-9]))|[0-1]?[0-9]{1,2})){3}")
|
||||
[ "$PROXY_IPV6" = "1" ] && {
|
||||
insert_nftset $NFTSET_SHUNTLIST6 "0" $(config_n_get $shunt_id ip_list | tr -s "\r\n" "\n" | sed -e "/^$/d" | grep -E "([A-Fa-f0-9]{1,4}::?){1,7}[A-Fa-f0-9]{1,4}")
|
||||
}
|
||||
fi
|
||||
}
|
||||
#分流规则的IP列表(使用分流节点时导入)
|
||||
local USE_SHUNT_NODE=0
|
||||
for _node in $TCP_NODE $UDP_NODE; do
|
||||
node_protocol=$(config_n_get $_node protocol)
|
||||
[ "$node_protocol" = "_shunt" ] && { USE_SHUNT_NODE=1; break; }
|
||||
done
|
||||
[ "$USE_SHUNT_NODE" = "0" ] && {
|
||||
for acl_section in $(uci show ${CONFIG} | grep "=acl_rule" | cut -d '.' -sf 2 | cut -d '=' -sf 1); do
|
||||
[ "$(config_n_get $acl_section enabled)" != "1" ] && continue
|
||||
for _node in $(config_n_get $acl_section tcp_node) $(config_n_get $acl_section udp_node); do
|
||||
node_protocol=$(config_n_get $_node protocol)
|
||||
[ "$node_protocol" = "_shunt" ] && { USE_SHUNT_NODE=1; break 2; }
|
||||
done
|
||||
fi
|
||||
done
|
||||
}
|
||||
[ "$USE_SHUNT_NODE" = "1" ] && {
|
||||
local shunt_ids=$(uci show $CONFIG | grep "=shunt_rules" | awk -F '.' '{print $2}' | awk -F '=' '{print $1}')
|
||||
for shunt_id in $shunt_ids; do
|
||||
insert_nftset $NFTSET_SHUNTLIST "0" $(config_n_get $shunt_id ip_list | tr -s "\r\n" "\n" | sed -e "/^$/d" | grep -E "(\.((2(5[0-5]|[0-4][0-9]))|[0-1]?[0-9]{1,2})){3}")
|
||||
[ "$PROXY_IPV6" = "1" ] && {
|
||||
insert_nftset $NFTSET_SHUNTLIST6 "0" $(config_n_get $shunt_id ip_list | tr -s "\r\n" "\n" | sed -e "/^$/d" | grep -E "([A-Fa-f0-9]{1,4}::?){1,7}[A-Fa-f0-9]{1,4}")
|
||||
}
|
||||
done
|
||||
}
|
||||
[ "$TCP_NODE" ] && process_shunt_rules $TCP_NODE
|
||||
[ "$UDP_NODE" ] && [ "$TCP_UDP" = "0" ] && process_shunt_rules $UDP_NODE
|
||||
|
||||
# 忽略特殊IP段
|
||||
local lan_ifname lan_ip
|
||||
|
|
|
@ -16,36 +16,15 @@ s = m:section(TypedSection, "server_subscribe")
|
|||
s.anonymous = true
|
||||
|
||||
o = s:option(Flag, "auto_update", translate("Auto Update"))
|
||||
o.rmempty = false
|
||||
o.description = translate("Auto Update Server subscription, GFW list and CHN route")
|
||||
|
||||
o = s:option(ListValue, "auto_update_week_time", translate("Update Time (Every Week)"))
|
||||
o:value('*', translate("Every Day"))
|
||||
o:value("1", translate("Every Monday"))
|
||||
o:value("2", translate("Every Tuesday"))
|
||||
o:value("3", translate("Every Wednesday"))
|
||||
o:value("4", translate("Every Thursday"))
|
||||
o:value("5", translate("Every Friday"))
|
||||
o:value("6", translate("Every Saturday"))
|
||||
o:value("0", translate("Every Sunday"))
|
||||
o.default = "*"
|
||||
o.rmempty = false
|
||||
o:depends("auto_update", "1")
|
||||
|
||||
o = s:option(ListValue, "auto_update_day_time", translate("Update time (every day)"))
|
||||
o = s:option(ListValue, "auto_update_time", translate("Update time (every day)"))
|
||||
for t = 0, 23 do
|
||||
o:value(t, t .. ":00")
|
||||
end
|
||||
o.default = 2
|
||||
o.rmempty = false
|
||||
o:depends("auto_update", "1")
|
||||
|
||||
o = s:option(ListValue, "auto_update_min_time", translate("Update Interval (min)"))
|
||||
for i = 0, 59 do
|
||||
o:value(i, i .. ":00")
|
||||
end
|
||||
o.default = 30
|
||||
o.rmempty = false
|
||||
o:depends("auto_update", "1")
|
||||
|
||||
o = s:option(DynamicList, "subscribe_url", translate("Subscribe URL"))
|
||||
o.rmempty = true
|
||||
|
|
|
@ -596,36 +596,6 @@ msgstr "格式为 IP:PORT(默认:禁用)"
|
|||
msgid "Update time (every day)"
|
||||
msgstr "更新时间(每天)"
|
||||
|
||||
msgid "Update Time (Every Week)"
|
||||
msgstr "更新时间(每周)"
|
||||
|
||||
msgid "Update Interval (min)"
|
||||
msgstr "更新间隔 (分钟)"
|
||||
|
||||
msgid "Every Day"
|
||||
msgstr "每天"
|
||||
|
||||
msgid "Every Monday"
|
||||
msgstr "每周一"
|
||||
|
||||
msgid "Every Tuesday"
|
||||
msgstr "每周二"
|
||||
|
||||
msgid "Every Wednesday"
|
||||
msgstr "每周三"
|
||||
|
||||
msgid "Every Thursday"
|
||||
msgstr "每周四"
|
||||
|
||||
msgid "Every Friday"
|
||||
msgstr "每周五"
|
||||
|
||||
msgid "Every Saturday"
|
||||
msgstr "每周六"
|
||||
|
||||
msgid "Every Sunday"
|
||||
msgstr "每周日"
|
||||
|
||||
msgid "Auto Update Server subscription, GFW list and CHN route"
|
||||
msgstr "自动更新服务器订阅、GFW 列表和中国大陆 IP 段"
|
||||
|
||||
|
|
|
@ -61,12 +61,12 @@ PS="/bin/busybox ps"
|
|||
|
||||
uci_get_by_name() {
|
||||
local ret=$(uci get $NAME.$1.$2 2>/dev/null)
|
||||
echo "${ret:=$3}"
|
||||
echo ${ret:=$3}
|
||||
}
|
||||
|
||||
uci_get_by_type() {
|
||||
local ret=$(uci get $NAME.@$1[0].$2 2>/dev/null)
|
||||
echo "${ret:=$3}"
|
||||
echo ${ret:=$3}
|
||||
}
|
||||
|
||||
uci_set_by_name() {
|
||||
|
@ -81,7 +81,7 @@ uci_set_by_type() {
|
|||
|
||||
uci_get_by_cfgid() {
|
||||
local ret=$(uci show $NAME.@$1[0].$2 | awk -F '.' '{print $2}' 2>/dev/null)
|
||||
echo "${ret:=$3}"
|
||||
echo ${ret:=$3}
|
||||
}
|
||||
|
||||
get_host_ip() {
|
||||
|
@ -120,7 +120,7 @@ echolog() {
|
|||
add_cron() {
|
||||
touch $CRON_FILE
|
||||
sed -i '/ssrplus.log/d' $CRON_FILE
|
||||
[ $(uci_get_by_type server_subscribe auto_update 0) -eq 1 ] && echo "$(uci_get_by_type server_subscribe auto_update_min_time) $(uci_get_by_type server_subscribe auto_update_day_time) * * $(uci_get_by_type server_subscribe auto_update_week_time) /usr/share/shadowsocksr/ssrplusupdate.sh >$LOG_FILE" >>$CRON_FILE
|
||||
[ $(uci_get_by_type server_subscribe auto_update 0) -eq 1 ] && echo "0 $(uci_get_by_type server_subscribe auto_update_time) * * * /usr/share/shadowsocksr/ssrplusupdate.sh >$LOG_FILE" >>$CRON_FILE
|
||||
crontab $CRON_FILE
|
||||
}
|
||||
|
||||
|
|
|
@ -22,10 +22,8 @@ config global
|
|||
|
||||
config server_subscribe
|
||||
option proxy '0'
|
||||
option auto_update_time '2'
|
||||
option auto_update '1'
|
||||
option auto_update_week_time '*'
|
||||
option auto_update_day_time '2'
|
||||
option auto_update_min_time '0'
|
||||
option filter_words '过期时间/剩余流量/QQ群/官网/防失联地址/回国'
|
||||
|
||||
config access_control
|
||||
|
|
Loading…
Reference in New Issue