2015-01-12 06:42:12 +00:00
|
|
|
-- WIPF Log Reader
|
|
|
|
|
|
|
|
local sys = require"sys"
|
2015-01-15 08:17:03 +00:00
|
|
|
local sock = require"sys.sock"
|
2015-01-12 06:42:12 +00:00
|
|
|
|
2015-01-18 07:55:04 +00:00
|
|
|
local wipf = require"wipflua"
|
2015-02-02 08:37:27 +00:00
|
|
|
local util_conf = require"wipf.util.conf"
|
2015-01-26 03:08:04 +00:00
|
|
|
local util_fs = require"wipf.util.fs"
|
2015-01-12 06:42:12 +00:00
|
|
|
|
2015-02-02 08:37:27 +00:00
|
|
|
local mem, win32 = sys.mem, sys.win32
|
|
|
|
|
|
|
|
|
|
|
|
function set_conf(device)
|
|
|
|
local conf = util_conf.new_conf()
|
|
|
|
|
|
|
|
conf:set_ip_include_all(true)
|
|
|
|
conf:set_ip_exclude_all(false)
|
|
|
|
|
|
|
|
conf:set_app_log_blocked(true)
|
|
|
|
conf:set_app_block_all(true)
|
|
|
|
conf:set_app_allow_all(false)
|
|
|
|
|
|
|
|
conf:set_ip_exclude[[
|
|
|
|
10.0.0.0/24
|
|
|
|
127.0.0.0/24
|
|
|
|
169.254.0.0/16
|
|
|
|
172.16.0.0/20
|
|
|
|
192.168.0.0/16
|
|
|
|
]]
|
|
|
|
|
|
|
|
local buf = assert(mem.pointer():alloc())
|
|
|
|
assert(conf:write(buf))
|
|
|
|
|
|
|
|
return device:ioctl(wipf.ioctl_setconf(), buf)
|
|
|
|
end
|
2015-01-16 11:11:59 +00:00
|
|
|
|
2015-01-14 15:06:56 +00:00
|
|
|
function print_logs(buf)
|
|
|
|
local size = buf:seek()
|
|
|
|
local ptr = buf:getptr()
|
|
|
|
local off = 0
|
|
|
|
|
|
|
|
while off < size do
|
2015-01-18 07:55:04 +00:00
|
|
|
local len, ip, pid, dos_path = wipf.log_read(ptr, off)
|
2015-01-15 08:17:03 +00:00
|
|
|
local ip_str = sock.inet_ntop(ip)
|
2015-01-16 11:11:59 +00:00
|
|
|
|
2015-01-18 07:55:04 +00:00
|
|
|
if not dos_path then
|
2015-01-20 14:48:43 +00:00
|
|
|
dos_path = util_fs.pid_dospath(pid)
|
2015-01-16 11:11:59 +00:00
|
|
|
end
|
|
|
|
|
2015-01-20 14:48:43 +00:00
|
|
|
local path = util_fs.dospath_to_path(dos_path)
|
2015-01-18 07:55:04 +00:00
|
|
|
|
2015-01-15 08:17:03 +00:00
|
|
|
print(ip_str, pid, path)
|
2015-01-16 11:11:59 +00:00
|
|
|
|
|
|
|
off = off + len
|
2015-01-14 15:06:56 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
buf:seek(0)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2015-01-12 12:49:02 +00:00
|
|
|
local device = assert(sys.handle():open(wipf.device_name(), "rw"))
|
2015-01-12 06:42:12 +00:00
|
|
|
|
2015-02-02 08:37:27 +00:00
|
|
|
assert(set_conf(device))
|
|
|
|
|
2015-01-14 12:33:52 +00:00
|
|
|
local BUFSIZ = wipf.buffer_size()
|
2015-01-12 06:42:12 +00:00
|
|
|
local buf = assert(sys.mem.pointer(BUFSIZ))
|
|
|
|
|
|
|
|
while true do
|
|
|
|
assert(device:ioctl(wipf.ioctl_getlog(), nil, buf))
|
2015-01-14 15:06:56 +00:00
|
|
|
print_logs(buf)
|
2015-01-12 06:42:12 +00:00
|
|
|
end
|