]] align_mid_off = [[
]] -function IsYamlFile(e) - e=e or"" - local e=string.lower(string.sub(e,-5,-1)) - return e == ".yaml" -end -function IsYmlFile(e) - e=e or"" - local e=string.lower(string.sub(e,-4,-1)) - return e == ".yml" -end - function default_config_set(f) local cf = fs.uci_get_config("config", "config_path") if cf == "/etc/openclash/config/"..f or not cf or cf == "" or not fs.isfile(cf) then @@ -95,14 +84,14 @@ HTTP.setfilehandler( fd = nil if fp == "config" then CHIF = "1" - if IsYamlFile(meta.file) then - default_config_set(meta.file) - end - if IsYmlFile(meta.file) then - local ymlname=string.lower(string.sub(meta.file,0,-5)) - local c=fs.rename(dir .. meta.file,"/etc/openclash/config/".. ymlname .. ".yaml") - local yamlname=ymlname .. ".yaml" - default_config_set(yamlname) + if fs.IsYamlExt(meta.file) then + if string.lower(meta.file):sub(-4) ~= ".yml" then + default_config_set(meta.file) + else + local ymlname=string.lower(string.sub(meta.file,0,-5)) + local c=fs.rename(dir .. meta.file,"/etc/openclash/config/".. ymlname .. ".yaml") + default_config_set(ymlname .. ".yaml") + end end um.value = translate("File saved to") .. ' "/etc/openclash/config/"' elseif fp == "proxy-provider" then @@ -193,7 +182,7 @@ sb.template="openclash/sub_info_show" btnis=tb:option(Button,"switch",translate("SwiTch")) btnis.render=function(o,t,a) if not e[t] then return false end - if IsYamlFile(e[t].name) or IsYmlFile(e[t].name) then + if fs.IsYamlExt(e[t].name) then a.display="" else a.display="none" @@ -233,7 +222,7 @@ actions.render = function(self, t, a) table.insert(self.vallist, translate("Servers Manage")) -- Copy - if IsYamlFile(e[t].name) or IsYmlFile(e[t].name) then + if fs.IsYamlExt(e[t].name) then table.insert(self.keylist, "copy") table.insert(self.vallist, translate("Copy Config")) end @@ -315,9 +304,13 @@ btnapply.write = function(self, t) fd:close() HTTP.close() elseif action == "remove" then + local file_name = fs.basename(e[t].name) + + fs.config_refs(file_name) + fs.unlink("/etc/openclash/history/"..fs.filename(e[t].name)..".db") - fs.unlink("/etc/openclash/"..fs.basename(e[t].name)) - local a=fs.unlink("/etc/openclash/config/"..fs.basename(e[t].name)) + fs.unlink("/etc/openclash/"..file_name) + local a=fs.unlink("/etc/openclash/config/"..file_name) default_config_set(fs.basename(e[t].name)) if a then table.remove(e,t) end HTTP.redirect(DISP.build_url("admin", "services", "openclash","config")) @@ -429,5 +422,6 @@ o.write = function() end m:append(Template("openclash/config_editor")) +m:append(Template("openclash/config_upload")) return ful , form , p , m diff --git a/luci-app-openclash/luasrc/model/cbi/openclash/groups-config.lua b/luci-app-openclash/luasrc/model/cbi/openclash/groups-config.lua index 375090d6..e59608f6 100644 --- a/luci-app-openclash/luasrc/model/cbi/openclash/groups-config.lua +++ b/luci-app-openclash/luasrc/model/cbi/openclash/groups-config.lua @@ -19,17 +19,6 @@ font_off = [[]] bold_on = [[]] bold_off = [[]] -function IsYamlFile(e) - e=e or"" - local e=string.lower(string.sub(e,-5,-1)) - return e == ".yaml" -end -function IsYmlFile(e) - e=e or"" - local e=string.lower(string.sub(e,-4,-1)) - return e == ".yml" -end - m = Map(openclash, translate("Edit Group")) m.pageaction = false m.redirect = DISP.build_url("admin/services/openclash/servers") .. "?file=" .. HTTP.urlencode(file_path) @@ -51,7 +40,7 @@ for t,f in ipairs(fs.glob("/etc/openclash/config/*"))do if a then e[t]={} e[t].name=fs.basename(f) - if IsYamlFile(e[t].name) or IsYmlFile(e[t].name) then + if fs.IsYamlExt(e[t].name) then o:value(e[t].name) end end diff --git a/luci-app-openclash/luasrc/model/cbi/openclash/proxy-provider-config.lua b/luci-app-openclash/luasrc/model/cbi/openclash/proxy-provider-config.lua index 9ec0ac7d..f7a35d0a 100644 --- a/luci-app-openclash/luasrc/model/cbi/openclash/proxy-provider-config.lua +++ b/luci-app-openclash/luasrc/model/cbi/openclash/proxy-provider-config.lua @@ -19,17 +19,6 @@ font_off = [[]] bold_on = [[]] bold_off = [[]] -function IsYamlFile(e) - e=e or"" - local e=string.lower(string.sub(e,-5,-1)) - return e == ".yaml" -end -function IsYmlFile(e) - e=e or"" - local e=string.lower(string.sub(e,-4,-1)) - return e == ".yml" -end - m = Map(openclash, translate("Edit Proxy-Provider")) m.pageaction = false m.redirect = DISP.build_url("admin/services/openclash/servers") .. "?file=" .. HTTP.urlencode(file_path) @@ -51,7 +40,7 @@ for t,f in ipairs(fs.glob("/etc/openclash/config/*"))do if a then e[t]={} e[t].name=fs.basename(f) - if IsYamlFile(e[t].name) or IsYmlFile(e[t].name) then + if fs.IsYamlExt(e[t].name) then o:value(e[t].name) end end @@ -76,7 +65,7 @@ for t,f in ipairs(fs.glob("/etc/openclash/proxy_provider/*"))do if h then p[t]={} p[t].name=fs.basename(f) - if IsYamlFile(p[t].name) or IsYmlFile(p[t].name) then + if fs.IsYamlExt(p[t].name) then o:value("./proxy_provider/"..p[t].name) end end diff --git a/luci-app-openclash/luasrc/model/cbi/openclash/servers-config.lua b/luci-app-openclash/luasrc/model/cbi/openclash/servers-config.lua index 78721948..12ba4c66 100644 --- a/luci-app-openclash/luasrc/model/cbi/openclash/servers-config.lua +++ b/luci-app-openclash/luasrc/model/cbi/openclash/servers-config.lua @@ -20,16 +20,7 @@ font_off = [[]] bold_on = [[]] bold_off = [[]] -function IsYamlFile(e) - e=e or"" - local e=string.lower(string.sub(e,-5,-1)) - return e == ".yaml" -end -function IsYmlFile(e) - e=e or"" - local e=string.lower(string.sub(e,-4,-1)) - return e == ".yml" -end + local encrypt_methods_ss = { -- stream @@ -132,7 +123,7 @@ for t,f in ipairs(fs.glob("/etc/openclash/config/*"))do if a then e[t]={} e[t].name=fs.basename(f) - if IsYamlFile(e[t].name) or IsYmlFile(e[t].name) then + if fs.IsYamlExt(e[t].name) then o:value(e[t].name) end end diff --git a/luci-app-openclash/luasrc/model/cbi/openclash/settings.lua b/luci-app-openclash/luasrc/model/cbi/openclash/settings.lua index cec8e926..b7c9ddba 100644 --- a/luci-app-openclash/luasrc/model/cbi/openclash/settings.lua +++ b/luci-app-openclash/luasrc/model/cbi/openclash/settings.lua @@ -78,7 +78,7 @@ s:tab("chnr_update", translate("Chnroute Update")) s:tab("auto_restart", translate("Auto Restart")) s:tab("version_update", translate("Version Update")) s:tab("developer", translate("Developer Settings")) -s:tab("debug", translate("Debug Logs")) +s:tab("debug", translate("Core Tests")) s:tab("oixcloud", translate("oixCloud")) o = s:taboption("op_mode", ListValue, "en_mode", font_red..bold_on..translate("Select Mode")..bold_off..font_off) diff --git a/luci-app-openclash/luasrc/openclash.lua b/luci-app-openclash/luasrc/openclash.lua index 29955991..b38bee38 100644 --- a/luci-app-openclash/luasrc/openclash.lua +++ b/luci-app-openclash/luasrc/openclash.lua @@ -391,6 +391,7 @@ function get_age_keys(file) if not pub and s.public then pub = s.public end if not sec and s.secret then sec = s.secret end end + return false end end) return { public = pub, secret = sec } @@ -457,7 +458,7 @@ end function decode64(data) if not data then return nil end data = data:gsub('[%s]', '') - if #data % 4 ~= 0 then return data end + if #data % 4 ~= 0 then return nil end local out = {} for i = 1, #data, 4 do @@ -487,6 +488,96 @@ function decode64(data) return table.concat(out) end +function config_refs(old_file_name, new_file_name) + if not old_file_name or old_file_name == "" then return end + local old_name_no_ext = filename(basename(old_file_name)) + local old_file_full = basename(old_file_name) + local is_rename = new_file_name and new_file_name ~= "" + local new_name_no_ext, new_file_full + + if is_rename then + new_name_no_ext = filename(basename(new_file_name)) + new_file_full = basename(new_file_name) + end + + uci:foreach("openclash", "config_subscribe", + function(s) + if s.name == old_name_no_ext then + if is_rename and new_name_no_ext ~= new_file_name then + uci:set("openclash", s[".name"], "name", new_name_no_ext) + else + uci:delete("openclash", s[".name"]) + end + return false + end + end + ) + + uci:foreach("openclash", "subscribe_info", + function(s) + if s.name == old_name_no_ext then + if is_rename and new_name_no_ext ~= new_file_name then + uci:set("openclash", s[".name"], "name", new_name_no_ext) + else + uci:delete("openclash", s[".name"]) + end + return false + end + end + ) + + uci:foreach("openclash", "groups", + function(s) + if s.config == old_file_full then + if is_rename and new_name_no_ext ~= new_file_name then + uci:set("openclash", s[".name"], "config", new_file_full) + else + uci:delete("openclash", s[".name"]) + end + end + end + ) + + uci:foreach("openclash", "proxy-provider", + function(s) + if s.config == old_file_full then + if is_rename and new_name_no_ext ~= new_file_name then + uci:set("openclash", s[".name"], "config", new_file_full) + else + uci:delete("openclash", s[".name"]) + end + end + end + ) + + uci:foreach("openclash", "servers", + function(s) + if s.config == old_file_full then + if is_rename and new_name_no_ext ~= new_file_name then + uci:set("openclash", s[".name"], "config", new_file_full) + else + uci:delete("openclash", s[".name"]) + end + end + end + ) + + uci:foreach("openclash", "config_age_secret", + function(s) + if s.name == old_name_no_ext then + if is_rename and new_name_no_ext ~= new_file_name then + uci:set("openclash", s[".name"], "name", new_name_no_ext) + else + uci:delete("openclash", s[".name"]) + end + return false + end + end + ) + + uci:commit("openclash") +end + --- Returns the appropriate ps command string for the system's ps implementation. -- Detects procps-ng (ps -efw) vs busybox (ps -w). -- @return String containing the ps command prefix @@ -524,3 +615,9 @@ function oc_version() end return v end + +function IsYamlExt(e) + e = e or "" + local lower = string.lower(e) + return lower:sub(-5) == ".yaml" or lower:sub(-4) == ".yml" +end diff --git a/luci-app-openclash/luasrc/view/openclash/config_edit.htm b/luci-app-openclash/luasrc/view/openclash/config_edit.htm index 6ad0f0bd..384c0c4c 100644 --- a/luci-app-openclash/luasrc/view/openclash/config_edit.htm +++ b/luci-app-openclash/luasrc/view/openclash/config_edit.htm @@ -1,3 +1,7 @@ +<% + local fs = require "luci.openclash" + local plugin_version = fs.oc_version() +%>