luci: reduce duplicate code
This commit is contained in:
parent
3320fcc2fc
commit
f6d56838c7
@ -7,7 +7,7 @@ include $(TOPDIR)/rules.mk
|
|||||||
|
|
||||||
PKG_NAME:=luci-app-passwall
|
PKG_NAME:=luci-app-passwall
|
||||||
PKG_VERSION:=4.61
|
PKG_VERSION:=4.61
|
||||||
PKG_RELEASE:=3
|
PKG_RELEASE:=4
|
||||||
|
|
||||||
PKG_CONFIG_DEPENDS:= \
|
PKG_CONFIG_DEPENDS:= \
|
||||||
CONFIG_PACKAGE_$(PKG_NAME)_Iptables_Transparent_Proxy \
|
CONFIG_PACKAGE_$(PKG_NAME)_Iptables_Transparent_Proxy \
|
||||||
|
@ -17,6 +17,15 @@ DISTRIB_ARCH = nil
|
|||||||
LOG_FILE = "/tmp/log/" .. appname .. ".log"
|
LOG_FILE = "/tmp/log/" .. appname .. ".log"
|
||||||
CACHE_PATH = "/tmp/etc/" .. appname .. "_tmp"
|
CACHE_PATH = "/tmp/etc/" .. appname .. "_tmp"
|
||||||
|
|
||||||
|
function log(...)
|
||||||
|
local result = os.date("%Y-%m-%d %H:%M:%S: ") .. table.concat({...}, " ")
|
||||||
|
local f, err = io.open(LOG_FILE, "a")
|
||||||
|
if f and err == nil then
|
||||||
|
f:write(result .. "\n")
|
||||||
|
f:close()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function exec_call(cmd)
|
function exec_call(cmd)
|
||||||
local process = io.popen(cmd .. '; echo -e "\n$?"')
|
local process = io.popen(cmd .. '; echo -e "\n$?"')
|
||||||
local lines = {}
|
local lines = {}
|
||||||
|
@ -8,12 +8,7 @@ local uci = api.uci
|
|||||||
local sys = api.sys
|
local sys = api.sys
|
||||||
|
|
||||||
local log = function(...)
|
local log = function(...)
|
||||||
local result = os.date("%Y-%m-%d %H:%M:%S: ") .. table.concat({...}, " ")
|
api.log(...)
|
||||||
local f, err = io.open("/tmp/log/passwall.log", "a")
|
|
||||||
if f and err == nil then
|
|
||||||
f:write(result .. "\n")
|
|
||||||
f:close()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function get_ip_port_from(str)
|
function get_ip_port_from(str)
|
||||||
|
@ -16,7 +16,6 @@ local PROXY_MODE = var["-PROXY_MODE"]
|
|||||||
local NO_PROXY_IPV6 = var["-NO_PROXY_IPV6"]
|
local NO_PROXY_IPV6 = var["-NO_PROXY_IPV6"]
|
||||||
local NO_LOGIC_LOG = var["-NO_LOGIC_LOG"]
|
local NO_LOGIC_LOG = var["-NO_LOGIC_LOG"]
|
||||||
local NFTFLAG = var["-NFTFLAG"]
|
local NFTFLAG = var["-NFTFLAG"]
|
||||||
local LOG_FILE = api.LOG_FILE
|
|
||||||
local CACHE_PATH = api.CACHE_PATH
|
local CACHE_PATH = api.CACHE_PATH
|
||||||
local CACHE_FLAG = "dnsmasq_" .. FLAG
|
local CACHE_FLAG = "dnsmasq_" .. FLAG
|
||||||
local CACHE_DNS_PATH = CACHE_PATH .. "/" .. CACHE_FLAG
|
local CACHE_DNS_PATH = CACHE_PATH .. "/" .. CACHE_FLAG
|
||||||
@ -36,12 +35,7 @@ local function log(...)
|
|||||||
if NO_LOGIC_LOG == "1" then
|
if NO_LOGIC_LOG == "1" then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local f, err = io.open(LOG_FILE, "a")
|
api.log(...)
|
||||||
if f and err == nil then
|
|
||||||
local str = os.date("%Y-%m-%d %H:%M:%S: ") .. table.concat({...}, " ")
|
|
||||||
f:write(str .. "\n")
|
|
||||||
f:close()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function check_dns(domain, dns)
|
local function check_dns(domain, dns)
|
||||||
|
@ -36,14 +36,10 @@ local v2ray_asset_location = ucic:get_first(name, 'global_rules', "v2ray_locatio
|
|||||||
|
|
||||||
local log = function(...)
|
local log = function(...)
|
||||||
if arg1 then
|
if arg1 then
|
||||||
local result = os.date("%Y-%m-%d %H:%M:%S: ") .. table.concat({...}, " ")
|
|
||||||
if arg1 == "log" then
|
if arg1 == "log" then
|
||||||
local f, err = io.open("/tmp/log/passwall.log", "a")
|
api.log(...)
|
||||||
if f and err == nil then
|
|
||||||
f:write(result .. "\n")
|
|
||||||
f:close()
|
|
||||||
end
|
|
||||||
elseif arg1 == "print" then
|
elseif arg1 == "print" then
|
||||||
|
local result = os.date("%Y-%m-%d %H:%M:%S: ") .. table.concat({...}, " ")
|
||||||
print(result)
|
print(result)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -83,15 +83,11 @@ local nodeResult = {} -- update result
|
|||||||
local debug = false
|
local debug = false
|
||||||
|
|
||||||
local log = function(...)
|
local log = function(...)
|
||||||
local result = os.date("%Y-%m-%d %H:%M:%S: ") .. table.concat({...}, " ")
|
|
||||||
if debug == true then
|
if debug == true then
|
||||||
|
local result = os.date("%Y-%m-%d %H:%M:%S: ") .. table.concat({...}, " ")
|
||||||
print(result)
|
print(result)
|
||||||
else
|
else
|
||||||
local f, err = io.open("/tmp/log/" .. appname .. ".log", "a")
|
api.log(...)
|
||||||
if f and err == nil then
|
|
||||||
f:write(result .. "\n")
|
|
||||||
f:close()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user