parent
79802955f4
commit
0a00f0d5c5
@ -3,24 +3,30 @@
|
|||||||
|
|
||||||
module("luci.controller.passwall", package.seeall)
|
module("luci.controller.passwall", package.seeall)
|
||||||
local api = require "luci.passwall.api"
|
local api = require "luci.passwall.api"
|
||||||
local appname = "passwall"
|
local appname = "passwall" -- not available
|
||||||
local ucic = luci.model.uci.cursor()
|
local uci = luci.model.uci.cursor() -- in funtion index()
|
||||||
local http = require "luci.http"
|
local http = require "luci.http"
|
||||||
local util = require "luci.util"
|
local util = require "luci.util"
|
||||||
local i18n = require "luci.i18n"
|
local i18n = require "luci.i18n"
|
||||||
|
|
||||||
function index()
|
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}).dependent = true
|
||||||
entry({"admin", "services", appname, "reset_config"}, call("reset_config")).leaf = 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, "show"}, call("show_menu")).leaf = true
|
||||||
entry({"admin", "services", appname, "hide"}, call("hide_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 uci:get(appname, "@global[0]", "hide_from_luci") == "1" then
|
||||||
if nixio.fs.access("/etc/config/passwall_show") then
|
return
|
||||||
e = entry({"admin", "services", appname}, alias("admin", "services", appname, "settings"), _("Pass Wall"), -1)
|
|
||||||
e.dependent = true
|
|
||||||
e.acl_depends = { "luci-app-passwall" }
|
|
||||||
end
|
end
|
||||||
|
e = entry({"admin", "services", appname}, alias("admin", "services", appname, "settings"), _("Pass Wall"), -1)
|
||||||
|
e.dependent = true
|
||||||
|
e.acl_depends = { "luci-app-passwall" }
|
||||||
--[[ Client ]]
|
--[[ Client ]]
|
||||||
entry({"admin", "services", appname, "settings"}, cbi(appname .. "/client/global"), _("Basic Settings"), 1).dependent = true
|
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
|
entry({"admin", "services", appname, "node_list"}, cbi(appname .. "/client/node_list"), _("Node List"), 2).dependent = true
|
||||||
@ -91,14 +97,16 @@ function reset_config()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function show_menu()
|
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("rm -rf /tmp/luci-*")
|
||||||
luci.sys.call("/etc/init.d/rpcd restart >/dev/null")
|
luci.sys.call("/etc/init.d/rpcd restart >/dev/null")
|
||||||
luci.http.redirect(api.url())
|
luci.http.redirect(api.url())
|
||||||
end
|
end
|
||||||
|
|
||||||
function hide_menu()
|
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("rm -rf /tmp/luci-*")
|
||||||
luci.sys.call("/etc/init.d/rpcd restart >/dev/null")
|
luci.sys.call("/etc/init.d/rpcd restart >/dev/null")
|
||||||
luci.http.redirect(luci.dispatcher.build_url("admin", "status", "overview"))
|
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 id = luci.http.formvalue("id")
|
||||||
local key = luci.http.formvalue("key")
|
local key = luci.http.formvalue("key")
|
||||||
if id and id ~= "" and key and key ~= "" then
|
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
|
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)
|
table.remove(new_list, i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -126,8 +134,8 @@ function socks_autoswitch_add_node()
|
|||||||
table.insert(new_list, e.id)
|
table.insert(new_list, e.id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
ucic:set_list(appname, id, "autoswitch_backup_node", new_list)
|
uci:set_list(appname, id, "autoswitch_backup_node", new_list)
|
||||||
ucic:commit(appname)
|
uci:commit(appname)
|
||||||
end
|
end
|
||||||
luci.http.redirect(api.url("socks_config", id))
|
luci.http.redirect(api.url("socks_config", id))
|
||||||
end
|
end
|
||||||
@ -136,14 +144,14 @@ function socks_autoswitch_remove_node()
|
|||||||
local id = luci.http.formvalue("id")
|
local id = luci.http.formvalue("id")
|
||||||
local key = luci.http.formvalue("key")
|
local key = luci.http.formvalue("key")
|
||||||
if id and id ~= "" and key and key ~= "" then
|
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
|
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)
|
table.remove(new_list, i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
ucic:set_list(appname, id, "autoswitch_backup_node", new_list)
|
uci:set_list(appname, id, "autoswitch_backup_node", new_list)
|
||||||
ucic:commit(appname)
|
uci:commit(appname)
|
||||||
end
|
end
|
||||||
luci.http.redirect(api.url("socks_config", id))
|
luci.http.redirect(api.url("socks_config", id))
|
||||||
end
|
end
|
||||||
@ -168,7 +176,7 @@ function get_redir_log()
|
|||||||
local proto = luci.http.formvalue("proto")
|
local proto = luci.http.formvalue("proto")
|
||||||
local path = "/tmp/etc/passwall/acl/" .. name
|
local path = "/tmp/etc/passwall/acl/" .. name
|
||||||
proto = proto:upper()
|
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"
|
proto = "TCP"
|
||||||
end
|
end
|
||||||
if nixio.fs.access(path .. "/" .. proto .. ".log") then
|
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.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
|
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"]
|
e["udp_node_status"] = e["tcp_node_status"]
|
||||||
else
|
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
|
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")
|
local id = luci.http.formvalue("id")
|
||||||
e.index = index
|
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
|
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
|
e.use_http = 0
|
||||||
if tonumber(use_http) > 0 then
|
if tonumber(use_http) > 0 then
|
||||||
e.use_http = 1
|
e.use_http = 1
|
||||||
@ -298,8 +306,8 @@ end
|
|||||||
function set_node()
|
function set_node()
|
||||||
local protocol = luci.http.formvalue("protocol")
|
local protocol = luci.http.formvalue("protocol")
|
||||||
local section = luci.http.formvalue("section")
|
local section = luci.http.formvalue("section")
|
||||||
ucic:set(appname, "@global[0]", protocol .. "_node", section)
|
uci:set(appname, "@global[0]", protocol .. "_node", section)
|
||||||
ucic:commit(appname)
|
uci:commit(appname)
|
||||||
luci.sys.call("/etc/init.d/passwall restart > /dev/null 2>&1 &")
|
luci.sys.call("/etc/init.d/passwall restart > /dev/null 2>&1 &")
|
||||||
luci.http.redirect(api.url("log"))
|
luci.http.redirect(api.url("log"))
|
||||||
end
|
end
|
||||||
@ -307,84 +315,84 @@ end
|
|||||||
function copy_node()
|
function copy_node()
|
||||||
local section = luci.http.formvalue("section")
|
local section = luci.http.formvalue("section")
|
||||||
local uuid = api.gen_short_uuid()
|
local uuid = api.gen_short_uuid()
|
||||||
ucic:section(appname, "nodes", uuid)
|
uci:section(appname, "nodes", uuid)
|
||||||
for k, v in pairs(ucic:get_all(appname, section)) do
|
for k, v in pairs(uci:get_all(appname, section)) do
|
||||||
local filter = k:find("%.")
|
local filter = k:find("%.")
|
||||||
if filter and filter == 1 then
|
if filter and filter == 1 then
|
||||||
else
|
else
|
||||||
xpcall(function()
|
xpcall(function()
|
||||||
ucic:set(appname, uuid, k, v)
|
uci:set(appname, uuid, k, v)
|
||||||
end,
|
end,
|
||||||
function(e)
|
function(e)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
ucic:delete(appname, uuid, "add_from")
|
uci:delete(appname, uuid, "add_from")
|
||||||
ucic:set(appname, uuid, "add_mode", 1)
|
uci:set(appname, uuid, "add_mode", 1)
|
||||||
ucic:commit(appname)
|
uci:commit(appname)
|
||||||
luci.http.redirect(api.url("node_config", uuid))
|
luci.http.redirect(api.url("node_config", uuid))
|
||||||
end
|
end
|
||||||
|
|
||||||
function clear_all_nodes()
|
function clear_all_nodes()
|
||||||
ucic:set(appname, '@global[0]', "enabled", "0")
|
uci:set(appname, '@global[0]', "enabled", "0")
|
||||||
ucic:set(appname, '@global[0]', "tcp_node", "nil")
|
uci:set(appname, '@global[0]', "tcp_node", "nil")
|
||||||
ucic:set(appname, '@global[0]', "udp_node", "nil")
|
uci:set(appname, '@global[0]', "udp_node", "nil")
|
||||||
ucic:foreach(appname, "socks", function(t)
|
uci:foreach(appname, "socks", function(t)
|
||||||
ucic:delete(appname, t[".name"])
|
uci:delete(appname, t[".name"])
|
||||||
ucic:set_list(appname, t[".name"], "autoswitch_backup_node", {})
|
uci:set_list(appname, t[".name"], "autoswitch_backup_node", {})
|
||||||
end)
|
end)
|
||||||
ucic:foreach(appname, "haproxy_config", function(t)
|
uci:foreach(appname, "haproxy_config", function(t)
|
||||||
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)
|
||||||
ucic:set(appname, t[".name"], "tcp_node", "default")
|
uci:set(appname, t[".name"], "tcp_node", "default")
|
||||||
ucic:set(appname, t[".name"], "udp_node", "default")
|
uci:set(appname, t[".name"], "udp_node", "default")
|
||||||
end)
|
end)
|
||||||
ucic:foreach(appname, "nodes", function(node)
|
uci:foreach(appname, "nodes", function(node)
|
||||||
ucic:delete(appname, node['.name'])
|
uci:delete(appname, node['.name'])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
ucic:commit(appname)
|
uci:commit(appname)
|
||||||
luci.sys.call("/etc/init.d/" .. appname .. " stop")
|
luci.sys.call("/etc/init.d/" .. appname .. " stop")
|
||||||
end
|
end
|
||||||
|
|
||||||
function delete_select_nodes()
|
function delete_select_nodes()
|
||||||
local ids = luci.http.formvalue("ids")
|
local ids = luci.http.formvalue("ids")
|
||||||
string.gsub(ids, '[^' .. "," .. ']+', function(w)
|
string.gsub(ids, '[^' .. "," .. ']+', function(w)
|
||||||
if (ucic:get(appname, "@global[0]", "tcp_node") or "nil") == w then
|
if (uci:get(appname, "@global[0]", "tcp_node") or "nil") == w then
|
||||||
ucic:set(appname, '@global[0]', "tcp_node", "nil")
|
uci:set(appname, '@global[0]', "tcp_node", "nil")
|
||||||
end
|
end
|
||||||
if (ucic:get(appname, "@global[0]", "udp_node") or "nil") == w then
|
if (uci:get(appname, "@global[0]", "udp_node") or "nil") == w then
|
||||||
ucic:set(appname, '@global[0]', "udp_node", "nil")
|
uci:set(appname, '@global[0]', "udp_node", "nil")
|
||||||
end
|
end
|
||||||
ucic:foreach(appname, "socks", function(t)
|
uci:foreach(appname, "socks", function(t)
|
||||||
if t["node"] == w then
|
if t["node"] == w then
|
||||||
ucic:delete(appname, t[".name"])
|
uci:delete(appname, t[".name"])
|
||||||
end
|
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
|
for i = #auto_switch_node_list, 1, -1 do
|
||||||
if w == auto_switch_node_list[i] then
|
if w == auto_switch_node_list[i] then
|
||||||
table.remove(auto_switch_node_list, i)
|
table.remove(auto_switch_node_list, i)
|
||||||
end
|
end
|
||||||
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)
|
end)
|
||||||
ucic:foreach(appname, "haproxy_config", function(t)
|
uci:foreach(appname, "haproxy_config", function(t)
|
||||||
if t["lbss"] == w then
|
if t["lbss"] == w then
|
||||||
ucic:delete(appname, t[".name"])
|
uci:delete(appname, t[".name"])
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
ucic:foreach(appname, "acl_rule", function(t)
|
uci:foreach(appname, "acl_rule", function(t)
|
||||||
if t["tcp_node"] == w then
|
if t["tcp_node"] == w then
|
||||||
ucic:set(appname, t[".name"], "tcp_node", "default")
|
uci:set(appname, t[".name"], "tcp_node", "default")
|
||||||
end
|
end
|
||||||
if t["udp_node"] == w then
|
if t["udp_node"] == w then
|
||||||
ucic:set(appname, t[".name"], "udp_node", "default")
|
uci:set(appname, t[".name"], "udp_node", "default")
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
ucic:delete(appname, w)
|
uci:delete(appname, w)
|
||||||
end)
|
end)
|
||||||
ucic:commit(appname)
|
uci:commit(appname)
|
||||||
luci.sys.call("/etc/init.d/" .. appname .. " restart > /dev/null 2>&1 &")
|
luci.sys.call("/etc/init.d/" .. appname .. " restart > /dev/null 2>&1 &")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -31,11 +31,12 @@ uci -q batch <<-EOF >/dev/null
|
|||||||
commit uhttpd
|
commit uhttpd
|
||||||
EOF
|
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
|
[ ! -s "/etc/config/passwall" ] && cp -f /usr/share/passwall/0_default_config /etc/config/passwall
|
||||||
|
|
||||||
chmod +x /usr/share/passwall/*.sh
|
chmod +x /usr/share/passwall/*.sh
|
||||||
|
|
||||||
|
[ -e "/etc/config/passwall_show" ] && rm -rf /etc/config/passwall_show
|
||||||
|
|
||||||
rm -f /tmp/luci-indexcache
|
rm -f /tmp/luci-indexcache
|
||||||
rm -rf /tmp/luci-modulecache/
|
rm -rf /tmp/luci-modulecache/
|
||||||
killall -HUP rpcd 2>/dev/null
|
killall -HUP rpcd 2>/dev/null
|
||||||
|
@ -11,10 +11,10 @@ index 1fb70f5..e1a5538 100644
|
|||||||
|
|
||||||
include $(TOPDIR)/feeds/luci/luci.mk
|
include $(TOPDIR)/feeds/luci/luci.mk
|
||||||
diff --git a/luci-app-passwall/luasrc/controller/passwall.lua b/luci-app-passwall/luasrc/controller/passwall.lua
|
diff --git a/luci-app-passwall/luasrc/controller/passwall.lua b/luci-app-passwall/luasrc/controller/passwall.lua
|
||||||
index bfb8f79..31a6164 100644
|
index 9b6f6c0..1c91506 100644
|
||||||
--- a/luci-app-passwall/luasrc/controller/passwall.lua
|
--- a/luci-app-passwall/luasrc/controller/passwall.lua
|
||||||
+++ b/luci-app-passwall/luasrc/controller/passwall.lua
|
+++ b/luci-app-passwall/luasrc/controller/passwall.lua
|
||||||
@@ -242,7 +242,7 @@ function connect_status()
|
@@ -250,7 +250,7 @@ function connect_status()
|
||||||
local e = {}
|
local e = {}
|
||||||
e.use_time = ""
|
e.use_time = ""
|
||||||
local url = luci.http.formvalue("url")
|
local url = luci.http.formvalue("url")
|
||||||
|
Loading…
Reference in New Issue
Block a user