diff --git a/luci-app-passwall/luasrc/controller/passwall.lua b/luci-app-passwall/luasrc/controller/passwall.lua index bfb8f7961..9b6f6c001 100644 --- a/luci-app-passwall/luasrc/controller/passwall.lua +++ b/luci-app-passwall/luasrc/controller/passwall.lua @@ -3,24 +3,30 @@ module("luci.controller.passwall", package.seeall) local api = require "luci.passwall.api" -local appname = "passwall" -local ucic = luci.model.uci.cursor() +local appname = "passwall" -- not available +local uci = luci.model.uci.cursor() -- in funtion index() local http = require "luci.http" local util = require "luci.util" local i18n = require "luci.i18n" function index() - appname = "passwall" + if not nixio.fs.access("/etc/config/passwall") then + if nixio.fs.access("/usr/share/passwall/0_default_config") then + luci.sys.call('cp -f /usr/share/passwall/0_default_config /etc/config/passwall') + else return end + end + local appname = "passwall" -- global definitions not available + local uci = luci.model.uci.cursor() -- in function index() entry({"admin", "services", appname}).dependent = true entry({"admin", "services", appname, "reset_config"}, call("reset_config")).leaf = true entry({"admin", "services", appname, "show"}, call("show_menu")).leaf = true entry({"admin", "services", appname, "hide"}, call("hide_menu")).leaf = true - if not nixio.fs.access("/etc/config/passwall") then return end - if nixio.fs.access("/etc/config/passwall_show") then - e = entry({"admin", "services", appname}, alias("admin", "services", appname, "settings"), _("Pass Wall"), -1) - e.dependent = true - e.acl_depends = { "luci-app-passwall" } + if uci:get(appname, "@global[0]", "hide_from_luci") == "1" then + return end + e = entry({"admin", "services", appname}, alias("admin", "services", appname, "settings"), _("Pass Wall"), -1) + e.dependent = true + e.acl_depends = { "luci-app-passwall" } --[[ Client ]] entry({"admin", "services", appname, "settings"}, cbi(appname .. "/client/global"), _("Basic Settings"), 1).dependent = true entry({"admin", "services", appname, "node_list"}, cbi(appname .. "/client/node_list"), _("Node List"), 2).dependent = true @@ -91,14 +97,16 @@ function reset_config() end function show_menu() - luci.sys.call("touch /etc/config/passwall_show") + uci:delete(appname, "@global[0]", "hide_from_luci") + uci:commit(appname) luci.sys.call("rm -rf /tmp/luci-*") luci.sys.call("/etc/init.d/rpcd restart >/dev/null") luci.http.redirect(api.url()) end function hide_menu() - luci.sys.call("rm -rf /etc/config/passwall_show") + ucic:set(appname, "@global[0]", "hide_from_luci","1") + ucic:commit(appname) luci.sys.call("rm -rf /tmp/luci-*") luci.sys.call("/etc/init.d/rpcd restart >/dev/null") luci.http.redirect(luci.dispatcher.build_url("admin", "status", "overview")) @@ -115,9 +123,9 @@ function socks_autoswitch_add_node() local id = luci.http.formvalue("id") local key = luci.http.formvalue("key") if id and id ~= "" and key and key ~= "" then - local new_list = ucic:get(appname, id, "autoswitch_backup_node") or {} + local new_list = uci:get(appname, id, "autoswitch_backup_node") or {} for i = #new_list, 1, -1 do - if (ucic:get(appname, new_list[i], "remarks") or ""):find(key) then + if (uci:get(appname, new_list[i], "remarks") or ""):find(key) then table.remove(new_list, i) end end @@ -126,8 +134,8 @@ function socks_autoswitch_add_node() table.insert(new_list, e.id) end end - ucic:set_list(appname, id, "autoswitch_backup_node", new_list) - ucic:commit(appname) + uci:set_list(appname, id, "autoswitch_backup_node", new_list) + uci:commit(appname) end luci.http.redirect(api.url("socks_config", id)) end @@ -136,14 +144,14 @@ function socks_autoswitch_remove_node() local id = luci.http.formvalue("id") local key = luci.http.formvalue("key") if id and id ~= "" and key and key ~= "" then - local new_list = ucic:get(appname, id, "autoswitch_backup_node") or {} + local new_list = uci:get(appname, id, "autoswitch_backup_node") or {} for i = #new_list, 1, -1 do - if (ucic:get(appname, new_list[i], "remarks") or ""):find(key) then + if (uci:get(appname, new_list[i], "remarks") or ""):find(key) then table.remove(new_list, i) end end - ucic:set_list(appname, id, "autoswitch_backup_node", new_list) - ucic:commit(appname) + uci:set_list(appname, id, "autoswitch_backup_node", new_list) + uci:commit(appname) end luci.http.redirect(api.url("socks_config", id)) end @@ -168,7 +176,7 @@ function get_redir_log() local proto = luci.http.formvalue("proto") local path = "/tmp/etc/passwall/acl/" .. name proto = proto:upper() - if proto == "UDP" and (ucic:get(appname, "@global[0]", "udp_node") or "nil") == "tcp" and not nixio.fs.access(path .. "/" .. proto .. ".log") then + if proto == "UDP" and (uci:get(appname, "@global[0]", "udp_node") or "nil") == "tcp" and not nixio.fs.access(path .. "/" .. proto .. ".log") then proto = "TCP" end if nixio.fs.access(path .. "/" .. proto .. ".log") then @@ -207,7 +215,7 @@ function index_status() e.haproxy_status = luci.sys.call(string.format("/bin/busybox top -bn1 | grep -v grep | grep '%s/bin/' | grep haproxy >/dev/null", appname)) == 0 e["tcp_node_status"] = luci.sys.call("/bin/busybox top -bn1 | grep -v 'grep' | grep '/tmp/etc/passwall/bin/' | grep 'default' | grep 'TCP' >/dev/null") == 0 - if (ucic:get(appname, "@global[0]", "udp_node") or "nil") == "tcp" then + if (uci:get(appname, "@global[0]", "udp_node") or "nil") == "tcp" then e["udp_node_status"] = e["tcp_node_status"] else e["udp_node_status"] = luci.sys.call("/bin/busybox top -bn1 | grep -v 'grep' | grep '/tmp/etc/passwall/bin/' | grep 'default' | grep 'UDP' >/dev/null") == 0 @@ -228,7 +236,7 @@ function socks_status() local id = luci.http.formvalue("id") e.index = index e.socks_status = luci.sys.call(string.format("/bin/busybox top -bn1 | grep -v 'grep' | grep '/tmp/etc/passwall/bin/' | grep -v '_acl_' | grep '%s' | grep 'SOCKS_' > /dev/null", id)) == 0 - local use_http = ucic:get(appname, id, "http_port") or 0 + local use_http = uci:get(appname, id, "http_port") or 0 e.use_http = 0 if tonumber(use_http) > 0 then e.use_http = 1 @@ -298,8 +306,8 @@ end function set_node() local protocol = luci.http.formvalue("protocol") local section = luci.http.formvalue("section") - ucic:set(appname, "@global[0]", protocol .. "_node", section) - ucic:commit(appname) + uci:set(appname, "@global[0]", protocol .. "_node", section) + uci:commit(appname) luci.sys.call("/etc/init.d/passwall restart > /dev/null 2>&1 &") luci.http.redirect(api.url("log")) end @@ -307,84 +315,84 @@ end function copy_node() local section = luci.http.formvalue("section") local uuid = api.gen_short_uuid() - ucic:section(appname, "nodes", uuid) - for k, v in pairs(ucic:get_all(appname, section)) do + uci:section(appname, "nodes", uuid) + for k, v in pairs(uci:get_all(appname, section)) do local filter = k:find("%.") if filter and filter == 1 then else xpcall(function() - ucic:set(appname, uuid, k, v) + uci:set(appname, uuid, k, v) end, function(e) end) end end - ucic:delete(appname, uuid, "add_from") - ucic:set(appname, uuid, "add_mode", 1) - ucic:commit(appname) + uci:delete(appname, uuid, "add_from") + uci:set(appname, uuid, "add_mode", 1) + uci:commit(appname) luci.http.redirect(api.url("node_config", uuid)) end function clear_all_nodes() - ucic:set(appname, '@global[0]', "enabled", "0") - ucic:set(appname, '@global[0]', "tcp_node", "nil") - ucic:set(appname, '@global[0]', "udp_node", "nil") - ucic:foreach(appname, "socks", function(t) - ucic:delete(appname, t[".name"]) - ucic:set_list(appname, t[".name"], "autoswitch_backup_node", {}) + uci:set(appname, '@global[0]', "enabled", "0") + uci:set(appname, '@global[0]', "tcp_node", "nil") + uci:set(appname, '@global[0]', "udp_node", "nil") + uci:foreach(appname, "socks", function(t) + uci:delete(appname, t[".name"]) + uci:set_list(appname, t[".name"], "autoswitch_backup_node", {}) end) - ucic:foreach(appname, "haproxy_config", function(t) - ucic:delete(appname, t[".name"]) + uci:foreach(appname, "haproxy_config", function(t) + uci:delete(appname, t[".name"]) end) - ucic:foreach(appname, "acl_rule", function(t) - ucic:set(appname, t[".name"], "tcp_node", "default") - ucic:set(appname, t[".name"], "udp_node", "default") + uci:foreach(appname, "acl_rule", function(t) + uci:set(appname, t[".name"], "tcp_node", "default") + uci:set(appname, t[".name"], "udp_node", "default") end) - ucic:foreach(appname, "nodes", function(node) - ucic:delete(appname, node['.name']) + uci:foreach(appname, "nodes", function(node) + uci:delete(appname, node['.name']) end) - ucic:commit(appname) + uci:commit(appname) luci.sys.call("/etc/init.d/" .. appname .. " stop") end function delete_select_nodes() local ids = luci.http.formvalue("ids") string.gsub(ids, '[^' .. "," .. ']+', function(w) - if (ucic:get(appname, "@global[0]", "tcp_node") or "nil") == w then - ucic:set(appname, '@global[0]', "tcp_node", "nil") + if (uci:get(appname, "@global[0]", "tcp_node") or "nil") == w then + uci:set(appname, '@global[0]', "tcp_node", "nil") end - if (ucic:get(appname, "@global[0]", "udp_node") or "nil") == w then - ucic:set(appname, '@global[0]', "udp_node", "nil") + if (uci:get(appname, "@global[0]", "udp_node") or "nil") == w then + uci:set(appname, '@global[0]', "udp_node", "nil") end - ucic:foreach(appname, "socks", function(t) + uci:foreach(appname, "socks", function(t) if t["node"] == w then - ucic:delete(appname, t[".name"]) + uci:delete(appname, t[".name"]) end - local auto_switch_node_list = ucic:get(appname, t[".name"], "autoswitch_backup_node") or {} + local auto_switch_node_list = uci:get(appname, t[".name"], "autoswitch_backup_node") or {} for i = #auto_switch_node_list, 1, -1 do if w == auto_switch_node_list[i] then table.remove(auto_switch_node_list, i) end end - ucic:set_list(appname, t[".name"], "autoswitch_backup_node", auto_switch_node_list) + uci:set_list(appname, t[".name"], "autoswitch_backup_node", auto_switch_node_list) end) - ucic:foreach(appname, "haproxy_config", function(t) + uci:foreach(appname, "haproxy_config", function(t) if t["lbss"] == w then - ucic:delete(appname, t[".name"]) + uci:delete(appname, t[".name"]) end end) - ucic:foreach(appname, "acl_rule", function(t) + uci:foreach(appname, "acl_rule", function(t) if t["tcp_node"] == w then - ucic:set(appname, t[".name"], "tcp_node", "default") + uci:set(appname, t[".name"], "tcp_node", "default") end if t["udp_node"] == w then - ucic:set(appname, t[".name"], "udp_node", "default") + uci:set(appname, t[".name"], "udp_node", "default") end end) - ucic:delete(appname, w) + uci:delete(appname, w) end) - ucic:commit(appname) + uci:commit(appname) luci.sys.call("/etc/init.d/" .. appname .. " restart > /dev/null 2>&1 &") end diff --git a/luci-app-passwall/root/etc/uci-defaults/luci-passwall b/luci-app-passwall/root/etc/uci-defaults/luci-passwall index 2a5a32404..dacae273a 100755 --- a/luci-app-passwall/root/etc/uci-defaults/luci-passwall +++ b/luci-app-passwall/root/etc/uci-defaults/luci-passwall @@ -31,11 +31,12 @@ uci -q batch <<-EOF >/dev/null commit uhttpd EOF -touch /etc/config/passwall_show >/dev/null 2>&1 [ ! -s "/etc/config/passwall" ] && cp -f /usr/share/passwall/0_default_config /etc/config/passwall chmod +x /usr/share/passwall/*.sh +[ -e "/etc/config/passwall_show" ] && rm -rf /etc/config/passwall_show + rm -f /tmp/luci-indexcache rm -rf /tmp/luci-modulecache/ killall -HUP rpcd 2>/dev/null