diff --git a/luci-app-passwall2/luasrc/controller/passwall2.lua b/luci-app-passwall2/luasrc/controller/passwall2.lua index 1fac463a..9a9b1c35 100644 --- a/luci-app-passwall2/luasrc/controller/passwall2.lua +++ b/luci-app-passwall2/luasrc/controller/passwall2.lua @@ -70,6 +70,7 @@ function index() entry({"admin", "services", appname, "get_now_use_node"}, call("get_now_use_node")).leaf = true entry({"admin", "services", appname, "get_redir_log"}, call("get_redir_log")).leaf = true entry({"admin", "services", appname, "get_socks_log"}, call("get_socks_log")).leaf = true + entry({"admin", "services", appname, "get_acl_log"}, call("get_acl_log")).leaf = true entry({"admin", "services", appname, "get_log"}, call("get_log")).leaf = true entry({"admin", "services", appname, "clear_log"}, call("clear_log")).leaf = true entry({"admin", "services", appname, "index_status"}, call("index_status")).leaf = true @@ -266,6 +267,18 @@ function get_socks_log() end end +function get_acl_log() + local id = http.formvalue("id") + local path = "/tmp/log/passwall2_acl_" .. id .. ".log" + if nixio.fs.access(path) then + local content = luci.sys.exec("tail -n 5000 '" .. path .. "'") + content = content:gsub("\n", "
") + http.write(content) + else + http.write(string.format("", i18n.translate("Not enabled log"))) + end +end + function get_log() -- luci.sys.exec("[ -f /tmp/log/passwall2.log ] && sed '1!G;h;$!d' /tmp/log/passwall2.log > /tmp/log/passwall2_show.log") http.write(luci.sys.exec("[ -f '/tmp/log/passwall2.log' ] && cat /tmp/log/passwall2.log")) diff --git a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/acl_config.lua b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/acl_config.lua index b366d623..2a766582 100644 --- a/luci-app-passwall2/luasrc/model/cbi/passwall2/client/acl_config.lua +++ b/luci-app-passwall2/luasrc/model/cbi/passwall2/client/acl_config.lua @@ -78,6 +78,33 @@ o = s:option(Value, "remarks", translate("Remarks")) o.default = arg[1] o.rmempty = false +---- Log +o = s:option(Flag, "log", translate("Enable Log")) +o.default = 0 +o.rmempty = false + +o = s:option(ListValue, "loglevel", translate("Log Level")) +o.default = "warn" +o:value("debug", "Debug") +o:value("info", "Info") +o:value("warn", "Warning") +o:value("error", "Error") +o:depends("log", "1") + +o = s:option(DummyValue, "_acl_log", translate("Log File")) +o.rawhtml = true +o.cfgvalue = function(t, n) + local log_path = "/tmp/log/passwall2_acl_" .. arg[1] .. ".log" + local log_url = api.url("get_acl_log") .. "?id=" .. arg[1] + return string.format( + '%s  ', + log_path, + translate("View Log"), + log_url + ) +end +o:depends("log", "1") + o = s:option(Value, "interface", translate("Source Interface")) o:value("", translate("All")) local iface = api.get_network_devices() diff --git a/luci-app-passwall2/root/usr/share/passwall2/app.sh b/luci-app-passwall2/root/usr/share/passwall2/app.sh index da00585d..63fb6c83 100755 --- a/luci-app-passwall2/root/usr/share/passwall2/app.sh +++ b/luci-app-passwall2/root/usr/share/passwall2/app.sh @@ -1021,11 +1021,15 @@ acl_app() { dnsmasq_port=${GLOBAL_DNSMASQ_PORT:-11400} for item in $items; do index=$(expr $index + 1) - local enabled sid remarks sources interface tcp_no_redir_ports udp_no_redir_ports node direct_dns_query_strategy remote_dns_protocol remote_dns remote_dns_doh remote_dns_client_ip remote_dns_detour remote_fakedns remote_dns_query_strategy + local enabled sid remarks sources interface tcp_no_redir_ports udp_no_redir_ports node direct_dns_query_strategy remote_dns_protocol remote_dns remote_dns_doh remote_dns_client_ip remote_dns_detour remote_fakedns remote_dns_query_strategy log loglevel log_file local _ip _mac _iprange _ipset _ip_or_mac source_list config_file local sid=$(uci -q show "${CONFIG}.${item}" | grep "=acl_rule" | awk -F '=' '{print $1}' | awk -F '.' '{print $2}') [ "$(config_n_get $sid enabled)" = "1" ] || continue eval $(uci -q show "${CONFIG}.${item}" | cut -d'.' -sf 3-) + log=${log:-0} + loglevel=${loglevel:-warn} + log_file="/dev/null" + [ "${log}" = "1" ] && log_file="/tmp/log/passwall2_acl_${sid}.log" if [ -n "${sources}" ]; then for s in $sources; do @@ -1121,7 +1125,8 @@ acl_app() { direct_dns_query_strategy=${direct_dns_query_strategy} \ remote_dns_protocol=${remote_dns_protocol} remote_dns_tcp_server=${remote_dns} remote_dns_udp_server=${remote_dns} remote_dns_doh="${remote_dns}" \ remote_dns_client_ip=${remote_dns_client_ip} remote_dns_detour=${remote_dns_detour} remote_fakedns=${remote_fakedns} remote_dns_query_strategy=${remote_dns_query_strategy} \ - config_file=${config_file} + config_file=${config_file} \ + log_file="${log_file}" loglevel="${loglevel}" local status=$? if [ "$status" != 0 ]; then log_i18n 2 "[%s] process %s error, skip this transparent proxy!" "${remarks}" "${config_file}"