Skip to content

Commit

Permalink
Fix bug\Add node memory
Browse files Browse the repository at this point in the history
  • Loading branch information
houzi- committed Sep 3, 2022
1 parent da74df5 commit f95e2fc
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 8 deletions.
Binary file modified koolclash/bin/subconverter.tar.gz
Binary file not shown.
20 changes: 15 additions & 5 deletions koolclash/scripts/koolclash_control.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ kill_process() {
# echo "cache-size=0" >>/tmp/dnsmasq.d/koolclash.conf
#}

load_rule_mode () {
load_rule_mode() {
if [ "$(cat /koolshare/koolclash/config/config.yaml | grep "mode: Rule")" == "mode: Rule" ]; then
echo_date "代理模式为 Rule"
dbus set koolclash_switch_config_mode=1
Expand All @@ -88,6 +88,14 @@ load_rule_mode () {
fi
}

node_memory() {
if [ "$koolclash_node_memory_enable" == "1" ]; then
yq w -i $KSROOT/koolclash/config/config.yaml profile.store-selected "true"
else
yq w -i $KSROOT/koolclash/config/config.yaml profile.store-selected "false"
fi
}

restart_dnsmasq() {
# Restart dnsmasq
echo_date "重启 dnsmasq..."
Expand Down Expand Up @@ -244,16 +252,16 @@ add_white_black_ip() {
echo_date '应用外网目标域名白名单'
ISP_DNS=$(ubus call network.interface.wan status | jsonfilter -e '@["dns-server"][0]')
rm -rf /tmp/dnsmasq.d/koolclash_ipset.conf >/dev/null 2>&1
rm -rf /tmp/dnsmasq.d/koolclash_white_server.conf >/dev/null 2>&1
#rm -rf /tmp/dnsmasq.d/koolclash_white_server.conf >/dev/null 2>&1
echo "#for koolclash white_domain" >> /tmp/dnsmasq.d/koolclash_ipset.conf
echo "#for koolclash white_domain_server" >> /tmp/dnsmasq.d/koolclash_white_server.conf
#echo "#for koolclash white_domain_server" >> /tmp/dnsmasq.d/koolclash_white_server.conf
for domain in $ip_white_domain; do
echo "$domain" | sed "s/^/ipset=&\/./g" | sed "s/$/\/koolclash_white/g" >> /tmp/dnsmasq.d/koolclash_ipset.conf
echo "$domain" | sed "s/^/server=&\//g" | sed "s/$/\/$ISP_DNS/g" >> /tmp/dnsmasq.d/koolclash_white_server.conf
#echo "$domain" | sed "s/^/server=&\//g" | sed "s/$/\/$ISP_DNS/g" >> /tmp/dnsmasq.d/koolclash_white_server.conf
done
else
rm -rf /tmp/dnsmasq.d/koolclash_ipset.conf >/dev/null 2>&1
rm -rf /tmp/dnsmasq.d/koolclash_white_server.conf >/dev/null 2>&1
#rm -rf /tmp/dnsmasq.d/koolclash_white_server.conf >/dev/null 2>&1
fi

if [ ! -n "$(ipset -L | grep -E "koolclash_white_ac_ips|koolclash_white_ac_macs")" ]; then
Expand Down Expand Up @@ -636,6 +644,8 @@ start_koolclash() {
flush_nat
restore_start_file
kill_process
# node_memory
node_memory
echo_date ---------------------------------------------------------------------------------
# create_dnsmasq_conf
auto_start
Expand Down
10 changes: 10 additions & 0 deletions koolclash/scripts/koolclash_node_memory.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh

export KSROOT=/koolshare
source $KSROOT/scripts/base.sh
alias echo_date='echo 【$(date +%Y年%m月%d日\ %X)】:'
eval $(dbus export koolclash_)

dbus set koolclash_node_memory_enable=$2

http_response "ok"
72 changes: 69 additions & 3 deletions koolclash/webs/Module_koolclash.asp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@
margin-left: 8px;
}
#koolclash-btn-submit-node-memory {
margin-bottom: 5px;
margin-left: 8px;
}
#koolclash-btn-submit-update-sub {
margin-bottom: 5px;
margin-left: 8px;
Expand Down Expand Up @@ -619,6 +624,14 @@
<div id="koolclash-watchdog-panel" style="margin-top: 16px"></div>
</div>
</div>
<div class="box">
<div class="heading">Clash 节点记忆</div>
<div class="content">
<p>Clash 自带的节点记忆功能,每 1 分钟保存一次节点配置信息,下次 Clash 启动将会沿用上次启动时的配置。</p>
<p style="color:red; margin-top: 8px">注意!Clash 节点记忆只针对 proxy group name!Clash 其它配置信息将不会进行保存!</p>
<div id="koolclash-node-memory-panel" style="margin-top: 16px"></div>
</div>
</div>
<div class="box">
<div class="heading">Clash 配置定时更新</div>
<div class="content">
Expand Down Expand Up @@ -1108,7 +1121,7 @@
type: 'select',
//style: select_style,
options: [
['off', '关闭'],
['off', '禁用'],
['80443', '80,443'],
['1', '常用端口'],
['0', '自定义端口']
Expand Down Expand Up @@ -1173,6 +1186,19 @@
value: window.dbus.koolclash_watchdog_enable || '0',
},
]);
$('#koolclash-node-memory-panel').forms([
{
title: 'Clash 节点记忆开关',
name: 'koolclash-select-node-memory',
type: 'select',
options: [
['0', '禁用'],
['1', '开启']
],
suffix: '<span> &nbsp;&nbsp;</span><button type="button" id="koolclash-btn-submit-node-memory" onclick="KoolClash.submitNodeMemory();" class="btn btn-primary">提交</button>',
value: window.dbus.koolclash_node_memory_enable || '0',
},
]);
$('#koolclash-update-sub-panel').forms([
{ title: 'Clash 更新开关', multi: [
{ name: 'koolclash-select-update-sub', type: 'select', options:[['0', '禁用'],['1', '开启']], value: window.dbus.koolclash_update_sub_enable || '0', suffix: ' &nbsp;&nbsp;', },
Expand Down Expand Up @@ -1204,7 +1230,9 @@
if (E('_koolclash-acl-default-mode').value === '0') {
$('#koolclash-acl-port-panel > fieldset:nth-child(3)').show();
$('#koolclash-acl-port-panel > fieldset:nth-child(2)').hide();
$('#_koolclash-acl-default-port-user').show();
if (E('_koolclash-acl-base-port').value === '0') {
$('#_koolclash-acl-default-port-user').show();
}
} else if (E('_koolclash-acl-default-mode').value === '1') {
$('#koolclash-acl-port-panel > fieldset:nth-child(2)').show();
$('#koolclash-acl-port-panel > fieldset:nth-child(3)').hide();
Expand Down Expand Up @@ -2435,6 +2463,40 @@ ${Base64.decode(data.firewall_ipset_list)}
}
});
},
submitNodeMemory: () => {
KoolClash.disableAllButton();
E('koolclash-btn-submit-node-memory').innerHTML = `正在提交`;
let id = parseInt(Math.random() * 100000000),
postData = JSON.stringify({
id,
"method": "koolclash_node_memory.sh",
"params": [`${E('_koolclash-select-node-memory').value}`],
"fields": ""
});
$.ajax({
type: "POST",
cache: false,
url: "/_api/",
data: postData,
dataType: "json",
success: (resp) => {
E('koolclash-btn-submit-node-memory').innerHTML = `提交成功,下次启动 Clash 时生效!`;
setTimeout(() => {
KoolClash.enableAllButton();
E('koolclash-btn-submit-node-memory').innerHTML = '提交';
}, 2500)
},
error: () => {
E('koolclash-btn-submit-node-memory').innerHTML = `提交失败,请重试!`;
setTimeout(() => {
KoolClash.enableAllButton();
E('koolclash-btn-submit-node-memory').innerHTML = '提交';
}, 2500)
}
});
},
submitUpdateSub: () => {
KoolClash.disableAllButton();
E('koolclash-btn-submit-update-sub').innerHTML = `正在提交`;
Expand Down Expand Up @@ -2536,7 +2598,11 @@ ${Base64.decode(data.firewall_ipset_list)}
if (E('_koolclash-acl-default-mode').value === '0') {
$('#koolclash-acl-port-panel > fieldset:nth-child(3)').show();
$('#koolclash-acl-port-panel > fieldset:nth-child(2)').hide();
$('#_koolclash-acl-default-port-user').show();
if (r.getAttribute('id') === '_koolclash-acl-base-port') {
if (E('_koolclash-acl-base-port').value === '0') {
$('#_koolclash-acl-default-port-user').show();
}
}
} else if (E('_koolclash-acl-default-mode').value === '1') {
$('#koolclash-acl-port-panel > fieldset:nth-child(2)').show();
$('#koolclash-acl-port-panel > fieldset:nth-child(3)').hide();
Expand Down

0 comments on commit f95e2fc

Please sign in to comment.