<% local msg = {} if _SESSION["logined"] ~= nil then local domain = _GET["domain"] or _POST["domain"] local type = _GET["type"] or _POST["type"] or "" local username = _GET["username"] or _POST["username"] or "" local starttime = _GET["starttime"] or _POST["starttime"] or "" local endtime = _GET["endtime"] or _POST["endtime"] or "" local strSQL = "" if (_SESSION["admin_readonly"] ~= nil and _SESSION["admin_readonly"] == 1) then rawset(msg, "code", -2) print(json.encode(msg)) end if type == "0" then strSQL = "f_time >= datetime('now','localtime','-7 day')" end if type == "1" then strSQL = "f_time >= datetime('now','localtime','-30 day')" end if type == "2" then starttime = starttime.gsub(starttime,"'", "") endtime = endtime.gsub(endtime,"'", "") username = username.gsub(username,"'", "") strSQL = "f_time >= '"..starttime.."' and f_time <= '"..endtime.."'" if username ~= "" then strSQL = strSQL.." and f_username = '"..username.."' " end end --total sessions local result = c_DoSQL("select count(*), count(DISTINCT(f_ip)) from wftp_dblogs where f_domain = '"..domain.."' and "..strSQL.." and f_action = 0") local totalsessions = result[1][0] or 0 --total unique ip local uniqueip = 0 if result[1] ~= nil then uniqueip = result[1][1] or 0 else uniqueip = "no" end --total download files result = c_DoSQL("select count(*), sum(f_filesize) from wftp_dblogs where f_domain = '"..domain.."' and "..strSQL.." and f_action = 8") local downloadfiles = result[1][0] or 0 local downloadbytes = result[1][1] or 0 --total upload files result = c_DoSQL("select count(*), sum(f_filesize) from wftp_dblogs where f_domain = '"..domain.."' and "..strSQL.." and f_action = 10") local uploadfiles = result[1][0] or 0 local uploadbytes = result[1][1] or 0 --top 10 downloads local top10downloads = c_DoSQL("select f_filename, count(f_filename) as f_num from wftp_dblogs where f_domain = '"..domain.."' and "..strSQL.." and f_action = 8 group by f_filename order by f_num desc limit 10") --top 10 uploads local top10uploads = c_DoSQL("select f_filename, count(f_filename) as f_num from wftp_dblogs where f_domain = '"..domain.."' and "..strSQL.." and f_action = 10 group by f_filename order by f_num desc limit 10") --top 10 logins local top10logins = c_DoSQL("select f_ip, count(f_ip) as f_num from wftp_dblogs where f_domain = '"..domain.."' and "..strSQL.." and f_action = 0 group by f_ip order by f_num desc limit 10") local weblinkfiles = 0 local weblinkbytes = 0 local top10users = {} if username == "" then --total download weblink files result = c_DoSQL("select count(*),sum(f_filesize) from wftp_dblogs where f_domain = '"..domain.."' and "..strSQL.." and f_username = '' and f_action = 8") weblinkfiles = result[1][0] or 0 weblinkbytes = result[1][1] or 0 --top 10 login users top10users = c_DoSQL("select f_username, count(f_username) as f_num from wftp_dblogs where f_domain = '"..domain.."' and "..strSQL.." and f_action = 0 group by f_username order by f_num desc limit 10") end rawset(msg, "code", 0) rawset(msg, "data", { ["totalsessions"] = totalsessions, ["uniqueip"] = uniqueip, ["downloadfiles"] = downloadfiles, ["downloadbytes"] = downloadbytes, ["uploadfiles"] = uploadfiles, ["uploadbytes"] = uploadbytes, ["top10downloads"] = top10downloads, ["top10uploads"] = top10uploads, ["top10logins"] = top10logins, ["weblinkfiles"] = weblinkfiles, ["weblinkbytes"] = weblinkbytes, ["top10users"] = top10users }) print(json.encode(msg)) else rawset(msg, "code", -1) rawset(msg, "error", "Not logged in") print(json.encode(msg)) end %>