diff --git a/class/core/db.py b/class/core/db.py index db42265ea..de1426031 100755 --- a/class/core/db.py +++ b/class/core/db.py @@ -49,10 +49,21 @@ class Sql(): self.__OPT_PARAM = param return self + def andWhere(self, where, param): + # WHERE条件 + if where: + self.__OPT_WHERE = self.__OPT_WHERE + " and " + where + # print(param) + # print(self.__OPT_PARAM) + self.__OPT_PARAM = self.__OPT_PARAM + param + return self + def order(self, order): # ORDER条件 if len(order): self.__OPT_ORDER = " ORDER BY " + order + else: + self.__OPT_ORDER = "" return self def limit(self, limit): @@ -108,7 +119,6 @@ class Sql(): try: sql = "SELECT " + self.__OPT_FIELD + " FROM " + self.__DB_TABLE + \ self.__OPT_WHERE + self.__OPT_ORDER + self.__OPT_LIMIT - # print(sql) result = self.__DB_CONN.execute(sql, self.__OPT_PARAM) data = result.fetchall() # 构造字曲系列 @@ -229,8 +239,8 @@ class Sql(): opt = opt[0:len(opt) - 1] sql = "UPDATE " + self.__DB_TABLE + " SET " + opt + self.__OPT_WHERE - import mw - mw.writeFile('/tmp/test.pl', sql) + # import mw + # mw.writeFile('/tmp/test.pl', sql) # 处理拼接WHERE与UPDATE参数 tmp = list(param) diff --git a/class/core/mw.py b/class/core/mw.py index cfc385ca3..a76db43cd 100755 --- a/class/core/mw.py +++ b/class/core/mw.py @@ -165,9 +165,9 @@ def restartMw(): def checkWebConfig(): - op_dir = getServerDir() + '/openresty' + op_dir = getServerDir() + '/openresty/nginx' cmd = "ulimit -n 10240 && " + op_dir + \ - "/nginx/sbin/nginx -t -c " + op_dir + "/nginx/conf/nginx.conf" + "/sbin/nginx -t -c " + op_dir + "/conf/nginx.conf" result = execShell(cmd) searchStr = 'successful' if result[1].find(searchStr) == -1: diff --git a/plugins/webstats/index.py b/plugins/webstats/index.py index 6bf02459a..2193bbe8a 100755 --- a/plugins/webstats/index.py +++ b/plugins/webstats/index.py @@ -311,7 +311,7 @@ def setDefaultSite(name): def getLogsList(): args = getArgs() check = checkArgs(args, ['page', 'page_size', - 'site', 'method', 'status_code', 'spider_type']) + 'site', 'method', 'status_code', 'spider_type', 'query_date', 'search_uri']) if not check[0]: return check[1] @@ -322,7 +322,8 @@ def getLogsList(): method = args['method'] status_code = args['status_code'] spider_type = args['spider_type'] - + query_date = args['query_date'] + search_uri = args['search_uri'] setDefaultSite(domain) limit = str(page_size) + ' offset ' + str(page_size * (page - 1)) @@ -331,26 +332,44 @@ def getLogsList(): field = 'time,ip,domain,server_name,method,status_code,request_time,uri,body_length' condition = '' conn = conn.field(field) + conn = conn.where("1=1", ()) if method != "all": - conn = conn.where("method=?", (method,)) + conn = conn.andWhere("method=?", (method,)) if status_code != "all": - conn = conn.where("status_code=?", (status_code,)) + conn = conn.andWhere("status_code=?", (status_code,)) if spider_type == "normal": pass elif spider_type == "only_spider": - conn = conn.where("is_spider>?", (0,)) + conn = conn.andWhere("is_spider>?", (0,)) elif spider_type == "no_spider": - conn = conn.where("is_spider=?", (0,)) + conn = conn.andWhere("is_spider=?", (0,)) elif int(spider_type) > 0: - conn = conn.where("is_spider=?", (spider_type,)) + conn = conn.andWhere("is_spider=?", (spider_type,)) + + todayTime = time.strftime('%Y-%m-%d 00:00:00', time.localtime()) + todayUt = int(time.mktime(time.strptime(todayTime, "%Y-%m-%d %H:%M:%S"))) + if query_date == 'today': + conn = conn.andWhere("time>=?", (todayUt,)) + elif query_date == "yesterday": + conn = conn.andWhere("time>=? and time<=?", (todayUt - 86400, todayUt)) + elif query_date == "l7": + conn = conn.andWhere("time>=?", (todayUt - 7 * 86400,)) + elif query_date == "l30": + conn = conn.andWhere("time>=?", (todayUt - 30 * 86400,)) + else: + exlist = query_date.split("-") + conn = conn.andWhere("time>=? and time<=?", (exlist[0], exlist[1])) - clist = conn.limit(limit).order('time desc').inquiry() + if search_uri != "": + conn = conn.andWhere("uri like '%" + search_uri + "%'", ()) + clist = conn.limit(limit).order('time desc').inquiry() count_key = "count(*) as num" - count = conn.field(count_key).limit('').inquiry() + count = conn.field(count_key).limit('').order('').inquiry() + # print(count) count = count[0][count_key] data = {} diff --git a/plugins/webstats/js/stats.js b/plugins/webstats/js/stats.js index 1f45c11aa..6bbc59425 100644 --- a/plugins/webstats/js/stats.js +++ b/plugins/webstats/js/stats.js @@ -173,7 +173,7 @@ function wsSitesErrorLog(){ args['tojs'] = 'wsSitesErrorLog'; wsPost('get_logs_list', '' ,args, function(rdata){ var rdata = $.parseJSON(rdata.data); - console.log(rdata); + // console.log(rdata); var list = ''; var data = rdata.data.data; for(i in data){ @@ -266,8 +266,7 @@ function wsSitesErrorLog(){ function wsTableLogRequest(page){ - - // console.log("wsTableRequest:",$('select[name="site"]').val()); + var args = {}; args['page'] = page; args['page_size'] = 10; @@ -276,23 +275,43 @@ function wsTableLogRequest(page){ args['method'] = $('select[name="method"]').val(); args['status_code'] = $('select[name="status_code"]').val(); args['spider_type'] = $('select[name="spider_type"]').val(); + + var query_date = 'today'; + if ($('#time_choose').attr("data-name") != ''){ + query_date = $('#time_choose').attr("data-name"); + } else { + query_date = $('#search_time button.cur').attr("data-name"); + } + args['query_date'] = query_date; + // console.log("query_date:",query_date); + + + var search_uri = $('input[name="search_uri"]').val(); + args['search_uri'] = search_uri; + args['tojs'] = 'wsTableLogRequest'; wsPost('get_logs_list', '' ,args, function(rdata){ var rdata = $.parseJSON(rdata.data); + console.log(rdata); var list = ''; var data = rdata.data.data; - for(i in data){ - list += ''; - list += '' + getLocalTime(data[i]['time'])+''; - list += '' + data[i]['domain'] +''; - list += '' + data[i]['ip'] +''; - list += '' + toSize(data[i]['body_length']) +''; - list += '' + data[i]['request_time'] +'ms'; - list += '' + data[i]['uri'] +''; - list += '' + data[i]['status_code']+'/' + data[i]['method'] +''; - list += '详情'; - list += ''; + if (data.length > 0){ + for(i in data){ + list += ''; + list += '' + getLocalTime(data[i]['time'])+''; + list += '' + data[i]['domain'] +''; + list += '' + data[i]['ip'] +''; + list += '' + toSize(data[i]['body_length']) +''; + list += '' + data[i]['request_time'] +'ms'; + list += '' + data[i]['uri'] +''; + list += '' + data[i]['status_code']+'/' + data[i]['method'] +''; + list += '详情'; + list += ''; + } + } else{ + list += '网站日志为空'; } + var table = '
\ \ \ @@ -326,13 +345,13 @@ var html = '
\ \ 时间: \
\ -
\ - \ - \ - \ - \ +
\ + \ + \ + \ + \
\ - \ + \
\
\
\ @@ -374,9 +393,9 @@ var html = '
\ \ URL过滤: \
\ - \ + \
\ - \ + \
\
\
\ @@ -391,19 +410,40 @@ laydate.render({ range:true, done:function(value, startDate, endDate){ if(!value){ - $('#time_choose').remove("cur"); return false; } + $('#search_time button').each(function(){ + $(this).removeClass('cur'); + }); + var timeA = value.split('-') var start = $.trim(timeA[0]+'-'+timeA[1]+'-'+timeA[2]) var end = $.trim(timeA[3]+'-'+timeA[4]+'-'+timeA[5]) query_txt = toUnixTime(start + " 00:00:00") + "-"+ toUnixTime(end + " 00:00:00") - console.log(query_txt) + + $('#time_choose').attr("data-name",query_txt); $('#time_choose').addClass("cur"); + + wsTableLogRequest(1); }, }); +$('#search_time button:eq(0)').addClass('cur'); +$('#search_time button').click(function(){ + $('#search_time button').each(function(){ + if ($(this).hasClass('cur')){ + $(this).removeClass('cur'); + } + }); + $('#time_choose').attr("data-name",''); + $('#time_choose').removeClass("cur"); + + $(this).addClass('cur'); + + wsTableLogRequest(1); +}); + $('select[name="method"]').change(function(){ wsTableLogRequest(1); }); @@ -416,6 +456,10 @@ $('select[name="spider_type"]').change(function(){ wsTableLogRequest(1); }); +$('#logs_search').click(function(){ + wsTableLogRequest(1); +}); + wsPost('get_default_site','',{},function(rdata){ $('select[name="site"]').html('');