Skip to content

Commit

Permalink
chore: refine
Browse files Browse the repository at this point in the history
  • Loading branch information
vernesong committed Jul 5, 2022
1 parent 97eaec8 commit 820738a
Show file tree
Hide file tree
Showing 15 changed files with 138 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,5 @@ o.write = function()
luci.http.redirect(m.redirect)
end

m:append(Template("openclash/toolbar_show"))
return m
25 changes: 20 additions & 5 deletions luci-app-openclash/luasrc/model/cbi/openclash/custom-dns-edit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,26 @@ o.default = o.disbled
---- Proxy group
o = s:option(Value, "specific_group", translate("Specific Group"))
o.description = translate("Group Use For Proxy The DNS")..translate("(Only Meta Core)")
uci:foreach("openclash", "groups",
function(s)
if s.name ~= "" and s.name ~= nil then
o:value(s.name)
local groupnames,filename
filename = m.uci:get(openclash, "config", "config_path")
if filename then
groupnames = SYS.exec(string.format('ruby -ryaml -E UTF-8 -e "YAML.load_file(\'%s\')[\'proxy-groups\'].each do |i| puts i[\'name\']+\'##\' end" 2>/dev/null',filename))
if groupnames then
for groupname in string.gmatch(groupnames, "([^'##\n']+)##") do
if groupname ~= nil and groupname ~= "" then
o:value(groupname)
end
end)
end
end
end

m.uci:foreach("openclash", "groups",
function(s)
if s.name ~= "" and s.name ~= nil then
o:value(s.name)
end
end)

o:value("DIRECT")
o:value("REJECT")
o:value("Disable", translate("Disable"))
Expand Down Expand Up @@ -108,4 +122,5 @@ o.write = function()
luci.http.redirect(m.redirect)
end

m:append(Template("openclash/toolbar_show"))
return m
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,5 @@ o.write = function()
HTTP.redirect(DISP.build_url("admin", "services", "openclash", "config"))
end

rule_form:append(Template("openclash/toolbar_show"))
return rule_form
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,5 @@ o.write = function()
luci.http.redirect(m.redirect)
end

m:append(Template("openclash/toolbar_show"))
return m
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@ o.write = function()
end

m:append(Template("openclash/config_editor"))

m:append(Template("openclash/toolbar_show"))
return m
Original file line number Diff line number Diff line change
Expand Up @@ -403,4 +403,5 @@ o.write = function()
luci.http.redirect(m.redirect)
end

m:append(Template("openclash/toolbar_show"))
return m
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,5 @@ o.write = function()
luci.http.redirect(m.redirect)
end

m:append(Template("openclash/toolbar_show"))
return m
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,5 @@ o.write = function()
HTTP.redirect(DISP.build_url("admin", "services", "openclash", "config"))
end

proxy_form:append(Template("openclash/toolbar_show"))
return proxy_form
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,26 @@ o:value("1", translate("Extended Match"))
o = s:option(ListValue, "group", translate("Set Proxy Group"))
o.description = font_red..bold_on..translate("The Added Proxy Groups Must Exist Except 'DIRECT' & 'REJECT'")..bold_off..font_off
o.rmempty = true
local groupnames,filename
filename = m.uci:get(openclash, "config", "config_path")
if filename then
groupnames = sys.exec(string.format('ruby -ryaml -E UTF-8 -e "YAML.load_file(\'%s\')[\'proxy-groups\'].each do |i| puts i[\'name\']+\'##\' end" 2>/dev/null',filename))
if groupnames then
for groupname in string.gmatch(groupnames, "([^'##\n']+)##") do
if groupname ~= nil and groupname ~= "" then
o:value(groupname)
end
end
end
end

m.uci:foreach("openclash", "groups",
function(s)
if s.name ~= "" and s.name ~= nil then
o:value(s.name)
end
end)
function(s)
if s.name ~= "" and s.name ~= nil then
o:value(s.name)
end
end)

o:value("DIRECT")
o:value("REJECT")

Expand All @@ -137,4 +151,5 @@ o.write = function()
luci.http.redirect(m.redirect)
end

m:append(Template("openclash/toolbar_show"))
return m
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,5 @@ o.write = function()
HTTP.redirect(DISP.build_url("admin", "services", "openclash", "config"))
end

rule_form:append(Template("openclash/toolbar_show"))
return rule_form
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,26 @@ o.rmempty = true

---- Proxy Group
o = s:option(ListValue, "group", translate("Select Proxy Group"))
uci:foreach("openclash", "groups",
function(s)
if s.name ~= "" and s.name ~= nil then
o:value(s.name)
local groupnames,filename
filename = m.uci:get(openclash, "config", "config_path")
if filename then
groupnames = SYS.exec(string.format('ruby -ryaml -E UTF-8 -e "YAML.load_file(\'%s\')[\'proxy-groups\'].each do |i| puts i[\'name\']+\'##\' end" 2>/dev/null',filename))
if groupnames then
for groupname in string.gmatch(groupnames, "([^'##\n']+)##") do
if groupname ~= nil and groupname ~= "" then
o:value(groupname)
end
end)
end
end
end

uci:foreach("openclash", "groups",
function(s)
if s.name ~= "" and s.name ~= nil then
o:value(s.name)
end
end)

o:value("DIRECT")
o:value("REJECT")
o.rmempty = true
Expand Down Expand Up @@ -155,12 +169,26 @@ o.rmempty = true

---- Proxy Group
o = s:option(ListValue, "group", translate("Select Proxy Group"))
uci:foreach("openclash", "groups",
function(s)
if s.name ~= "" and s.name ~= nil then
o:value(s.name)
local groupnames,filename
filename = m.uci:get(openclash, "config", "config_path")
if filename then
groupnames = SYS.exec(string.format('ruby -ryaml -E UTF-8 -e "YAML.load_file(\'%s\')[\'proxy-groups\'].each do |i| puts i[\'name\']+\'##\' end" 2>/dev/null',filename))
if groupnames then
for groupname in string.gmatch(groupnames, "([^'##\n']+)##") do
if groupname ~= nil and groupname ~= "" then
o:value(groupname)
end
end)
end
end
end

uci:foreach("openclash", "groups",
function(s)
if s.name ~= "" and s.name ~= nil then
o:value(s.name)
end
end)

o:value("DIRECT")
o:value("REJECT")
o.rmempty = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -570,4 +570,5 @@ o.write = function()
luci.http.redirect(m.redirect)
end

m:append(Template("openclash/toolbar_show"))
return m
51 changes: 29 additions & 22 deletions luci-app-openclash/luasrc/view/openclash/toolbar_show.htm
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
var tool_label = document.getElementById('tool_label');
var Commit = document.getElementById('cbi-table-1-Commit');
var Apply = document.getElementById('cbi-table-1-Apply');
var Back = document.getElementById('cbi-table-1-Back');
var Load_Config = document.getElementById('cbi-table-1-Load_Config');
var Delete_Unused_Servers = document.getElementById('cbi-table-1-Delete_Unused_Servers');
var Delete_Servers = document.getElementById('cbi-table-1-Delete_Servers');
Expand All @@ -35,29 +36,34 @@

if (Commit) {
Commit.style.textAlign="center";
Apply.style.textAlign="center";
}
if (Apply) {
Apply.style.textAlign="center";
}
if (Back) {
Back.style.textAlign="center";
}
if (Load_Config) {
Load_Config.style.textAlign="center";
Delete_Unused_Servers.style.textAlign="center";
Delete_Servers.style.textAlign="center";
Delete_Proxy_Provider.style.textAlign="center";
Delete_Groups.style.textAlign="center";
Load_Config.style.textAlign="center";
Delete_Unused_Servers.style.textAlign="center";
Delete_Servers.style.textAlign="center";
Delete_Proxy_Provider.style.textAlign="center";
Delete_Groups.style.textAlign="center";
}
if (rule_mg) {
rule_mg.style.textAlign="center";
pro_mg.style.textAlign="center";
rule_mg.style.textAlign="center";
pro_mg.style.textAlign="center";
}

if (tool_label.style.display != "none") {
XHR.get('<%=luci.dispatcher.build_url("admin", "services", "openclash", "config_name")%>', null, function(x, status) {
if (x && x.status == 200 && status.config_name != "") {
for(var i in status.config_name){
config_name.options.add(new Option(status.config_name[i].name,status.config_name[i].name));
}
if (status.config_path != "") {
config_name.value = status.config_path;
}
config_name.options.add(new Option(status.config_name[i].name,status.config_name[i].name));
}
if (status.config_path != "") {
config_name.value = status.config_path;
}
else
{
config_name.options.add(new Option("<%:Not Select%>",""));
Expand Down Expand Up @@ -85,13 +91,13 @@
}

function insertAfter(newElement, targetElement) {
var parent = targetElement.parentNode;
if(parent.lastChild == targetElement) {
parent.appendChild(newElement, targetElement);
}
else {
parent.insertBefore(newElement, targetElement.nextSibling);
};
var parent = targetElement.parentNode;
if (parent.lastChild == targetElement) {
parent.appendChild(newElement, targetElement);
}
else {
parent.insertBefore(newElement, targetElement.nextSibling);
};
};

function switch_config(btn)
Expand All @@ -100,8 +106,9 @@
btn.disabled = true;
XHR.get('<%=luci.dispatcher.build_url("admin", "services", "openclash", "switch_config")%>', {config_name: config_name.value}, function(x, status) {
if (x && x.status == 200) {
btn.disabled = false;
alert(' <%:Config File%>: ' + config_name.value + ' <%:switching succeeded!%>')
btn.disabled = false;
alert(' <%:Config File%>: ' + config_name.value + ' <%:switching succeeded!%>')
window.location.href=location.pathname;
}
else {
alert(' <%:Config File%>: ' + config_name.value + ' <%:switching failed!%>')
Expand Down
2 changes: 1 addition & 1 deletion luci-app-openclash/root/etc/init.d/openclash
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ revert_dns() {
config_list_foreach "config" "dnsmasq_server" set_dnsmasq_server
}

if [ "$4" == "0" ] || [ -z "$4" ]; then
if [ "$4" == "0" ] || [ -z "$4" ] || [ -z "$(uci -q show dhcp.@dnsmasq[0].server)" ]; then
uci -q set dhcp.@dnsmasq[0].noresolv=0
if [ -n "$5" ]; then
uci -q set dhcp.@dnsmasq[0].resolvfile="$5"
Expand Down
22 changes: 21 additions & 1 deletion luci-app-openclash/root/usr/share/openclash/yml_change.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ yml_dns_custom()
if [ "$1" = 1 ] || [ "$3" = 1 ]; then
sys_dns_append "$3" "$4"
config_load "openclash"
config_foreach yml_dns_get "dns_servers"
config_foreach yml_dns_get "dns_servers" "$2"
fi
}

Expand Down Expand Up @@ -222,6 +222,26 @@ yml_dns_get()
fi

if [ "$specific_group" != "Disable" ] && [ -n "$specific_group" ] && [ "$enable_meta_core" = "1" ]; then
group_check=$(ruby -ryaml -E UTF-8 -e "
begin
Thread.new{
Value = YAML.load_file('$2');
Value['proxy-groups'].each{
|x|
if x['name'] == '$specific_group' then
if (x.key?('use') and not x['use'].to_a.empty?) or (x.key?('proxies') and not x['proxies'].to_a.empty?) then
puts 'return'
end;
end;
};
}.join;
rescue Exception => e
puts 'return'
end;" 2>/dev/null)

if [ "$group_check" != "return" ]; then
/usr/share/openclash/yml_groups_set.sh >/dev/null 2>&1 "$specific_group"
fi
specific_group="#$specific_group"
elif [ "$specific_group" != "Disable" ] && [ -n "$specific_group" ]; then
LOG_OUT "Warning: Only Meta Core Support Specific Group, Skip Setting【$dns_type$dns_address"
Expand Down

0 comments on commit 820738a

Please sign in to comment.