代理日志导出

This commit is contained in:
wangwei
2018-12-17 01:11:50 +08:00
parent 15ce103372
commit 6429fa386f
3 changed files with 166 additions and 56 deletions

View File

@@ -1,22 +1,38 @@
package com.nis.domain.log;
import com.nis.util.excel.ExcelField;
public class PxyHttpLog extends BaseLogEntity<NtcIpLog> {
private static final long serialVersionUID = -3046458130302949428L;
@ExcelField(title="URL",sort=8)
private String url;
@ExcelField(title="req_line",sort=9)
private String reqLine;
@ExcelField(title="res_line",sort=10)
private String resLine;
@ExcelField(title="cookie",sort=11)
private String cookie;
@ExcelField(title="referer",sort=12)
private String referer;
@ExcelField(title="user_agent",sort=13)
private String userAgent;
@ExcelField(title="content_len",sort=14)
private String contentLen;
@ExcelField(title="content_type",sort=15)
private String contentType;
@ExcelField(title="set_cookie",sort=16)
private String setCookie;
@ExcelField(title="req_header",sort=17)
private String reqHeader;
@ExcelField(title="resp_header",sort=18)
private String respHeader;
private String reqBody;
private String resBody;
@ExcelField(title="website",sort=19)
private String website;

View File

@@ -1,5 +1,6 @@
package com.nis.web.controller.log.pxy;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -7,11 +8,13 @@ import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import org.springframework.web.servlet.support.RequestContext;
import com.google.gson.Gson;
@@ -20,6 +23,8 @@ import com.google.gson.reflect.TypeToken;
import com.nis.domain.FunctionServiceDict;
import com.nis.domain.Page;
import com.nis.domain.PageLog;
import com.nis.domain.SysUser;
import com.nis.domain.log.NtcCollectRadiusLog;
import com.nis.domain.log.NtcSslLog;
import com.nis.domain.log.PxyHttpLog;
import com.nis.domain.maat.LogRecvData;
@@ -27,33 +32,35 @@ import com.nis.util.Constants;
import com.nis.util.DictUtils;
import com.nis.util.httpclient.HttpClientUtil;
import com.nis.web.controller.BaseController;
import com.nis.web.security.UserUtils;
@Controller
@RequestMapping("${adminPath}/log/pxy")
public class PxyHttpLogController extends BaseController {
@RequestMapping(value = {"list", "ipInterceptlogs", "domainInterceptlogs", "httpBlocklogs",
"httpRedirectlogs", "httpReplacelogs", "httpMonitogs"})
public String list(@ModelAttribute("log") PxyHttpLog log, Model model, HttpServletRequest request, HttpServletResponse response) {
@RequestMapping(value = { "list", "ipInterceptlogs", "domainInterceptlogs", "httpBlocklogs", "httpRedirectlogs",
"httpReplacelogs", "httpMonitogs" })
public String list(@ModelAttribute("log") PxyHttpLog log, Model model, HttpServletRequest request,
HttpServletResponse response) {
try {
setLogInfo(request, model, log);
PageLog<PxyHttpLog> page = new PageLog<PxyHttpLog>(request, response);
Map<String, Object> params = new HashMap<String, Object>();
params.put("pageSize", page.getPageSize());
params.put("pageNo", page.getPageNo());
initLogSearchValue(log, params);
List<FunctionServiceDict> serviceList = DictUtils.getFunctionServiceDictList(log.getFunctionId());
model.addAttribute("serviceList", serviceList);
String url = Constants.LOG_BASE_URL + Constants.PXY_HTTP_LOG;
String recv = HttpClientUtil.getMsg(url, params, request);
Gson gson = new GsonBuilder().create();
LogRecvData<PxyHttpLog> fromJson = gson.fromJson(recv, new TypeToken<LogRecvData<PxyHttpLog>>(){}.getType());
LogRecvData<PxyHttpLog> fromJson = gson.fromJson(recv, new TypeToken<LogRecvData<PxyHttpLog>>() {
}.getType());
if (fromJson.getStatus().intValue() == 200) {
Page<PxyHttpLog> data = fromJson.getData();
page.setCount(data.getCount());
@@ -62,24 +69,24 @@ public class PxyHttpLogController extends BaseController {
List<PxyHttpLog> list = page.getList();
for (PxyHttpLog l : list) {
l.setFunctionId(log.getFunctionId());
setLogAction(l,serviceList);
setLogAction(l, serviceList);
}
model.addAttribute("page", page);
}
} catch (Exception e) {
logger.error("查询失败", e);
addMessageLog(model, e.getMessage());
}
return "/log/pxy/pxyHttpList";
}
private void setLogInfo(HttpServletRequest request, Model model, PxyHttpLog log) {
int functionId = log.getFunctionId();
RequestContext requestContext = new RequestContext(request);
if (functionId == 200) {
model.addAttribute("logTitle", requestContext.getMessage("ip_intercept"));
log.setAction(1);
@@ -100,4 +107,81 @@ public class PxyHttpLogController extends BaseController {
log.setAction(1);
}
}
// proxy配置导出
@RequestMapping(value = "exportPxy")
public void exportPxy(@ModelAttribute("log") PxyHttpLog log, Model model, String hColumns, String type,
HttpServletRequest request, HttpServletResponse response, RedirectAttributes redirectAttributes) {
String name= "pxy";
try {
// export data info
setLogInfo(request, model, log);
List<String> titleList = new ArrayList<String>();
Map<String, Class<?>> classMap = new HashMap<String, Class<?>>();
Map<String, List> dataMap = new HashMap<String, List>();
Map<String, String> noExportMap = new HashMap<String, String>();
// ---------------------------
PageLog<PxyHttpLog> page = new PageLog<PxyHttpLog>(request, response);
page.setPageNo(1);
page.setPageSize(Constants.MAX_LOG_EXPORT_SIZE);
Map<String, Object> params = new HashMap<String, Object>();
params.put("pageSize", page.getPageSize());
params.put("pageNo", page.getPageNo());
initLogSearchValue(log, params);
List<FunctionServiceDict> serviceList = DictUtils.getFunctionServiceDictList(log.getFunctionId());
System.out.print(log.getFunctionId());
model.addAttribute("serviceList", serviceList);
String url = Constants.LOG_BASE_URL + Constants.PXY_HTTP_LOG;
String recv = HttpClientUtil.getMsg(url, params, request);
List<PxyHttpLog> list = new ArrayList<PxyHttpLog>();
if (StringUtils.isNotBlank(recv)) {
Gson gson = new GsonBuilder().create();
LogRecvData<PxyHttpLog> fromJson = gson.fromJson(recv, new TypeToken<LogRecvData<PxyHttpLog>>() {
}.getType());
if (fromJson.getStatus().intValue() == 200) {
Page<PxyHttpLog> data = fromJson.getData();
list = data.getList();
}
}
for (PxyHttpLog l : list) {
l.setFunctionId(log.getFunctionId());
setLogAction(l, serviceList);
}
if(log.getFunctionId()==210){
name="http_monit";
}else if(log.getFunctionId()==207){
name="http_block";
}else if(log.getFunctionId()==208){
name="http_redirect";
}else if(log.getFunctionId()==209){
name="http_replace";
}
titleList.add(name);
classMap.put(name, PxyHttpLog.class);
SysUser user = UserUtils.getUser();
if (!user.isAdmin()) {
hColumns += ",scene_file,";
} else {
hColumns += ",";
}
String cfgIndexInfoNoExport = "," + hColumns;
noExportMap.put(name, cfgIndexInfoNoExport);
dataMap.put(name, list);
if ("csv".equals(type)) {
this._exportCsv(model, request, response, redirectAttributes, name, titleList, classMap,
dataMap, noExportMap);
} else {
this._export(model, request, response, redirectAttributes, name, titleList, classMap, dataMap,
noExportMap);
}
} catch (Exception e) {
logger.error(name +" export failed", e);
addMessage(redirectAttributes, "error", "export_failed");
}
}
}

View File

@@ -113,6 +113,16 @@
<button type="button" class="btn btn-default" id="filter-btn"> <spring:message code="filter"/><i class="fa fa-angle-double-down"></i></button>
</div>
<div class="pull-right">
<div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
<i class="fa fa-wrench"></i> <spring:message code="export"></spring:message>
<i class="fa fa-angle-down"></i>
</button>
<ul class="dropdown-menu pull-right" style="min-width: 110px;" >
<li><sys:delRow url="${ctx}/log/pxy/exportPxy?type=excel" searchUrl="${ctx}/log/pxy/list" id="contentTable" maxRow="10000" label="excel"></sys:delRow></li>
<li><sys:delRow url="${ctx}/log/pxy/exportPxy?type=csv" searchUrl="${ctx}/log/pxy/list" id="contentTable" maxRow="10000" label="csv"></sys:delRow></li>
</ul>
</div>
<a class="btn btn-icon-only btn-default setfields tooltips"
data-container="body" data-placement="top" data-original-title=<spring:message code="custom_columns"/> href="javascript:;">
<i class="icon-wrench"></i>
@@ -197,54 +207,54 @@
<thead>
<tr>
<th><spring:message code="log"/></th>
<th class="sort-column cfg_id " isVisible="false" ><spring:message code="cfg_id"/></th>
<th class="sort-column service" isVisible="false"><spring:message code="action"/></th>
<th class="sort-column found_time"><spring:message code="found_time"/></th>
<th class="sort-column recv_time" isVisible="false"><spring:message code="recv_time"/></th>
<th class="sort-column cfg_id " isVisible="false" column="cfg_id" ><spring:message code="cfg_id"/></th>
<th class="sort-column service" isVisible="false" column="action" ><spring:message code="action"/></th>
<th class="sort-column found_time" column="found_time" ><spring:message code="found_time"/></th>
<th class="sort-column recv_time" isVisible="false" column="recv_time" ><spring:message code="recv_time"/></th>
<th class="sort-column entrance_id" isVisible="false"><spring:message code="entrance_id"/></th>
<th class="sort-column entrance_id" isVisible="false" column="entrance_id" ><spring:message code="entrance_id"/></th>
<th class="sort-column url"> URL &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>
<c:if test="${fns:getUser().isAdmin()}">
<th class="sort-column req_line"><spring:message code="req_line"/></th>
<th class="sort-column res_line"><spring:message code="res_line"/></th>
<th class="sort-column req_line" column="req_line" ><spring:message code="req_line"/></th>
<th class="sort-column res_line" column="res_line" ><spring:message code="res_line"/></th>
</c:if>
<th class="sort-column cookie"><spring:message code="cookie"/></th>
<th class="sort-column referer"><spring:message code="referer"/></th>
<th class="sort-column user_agent"><spring:message code="user_agent"/></th>
<th class="sort-column content_len"><spring:message code="content_len"/></th>
<th class="sort-column content_type"><spring:message code="content_type"/></th>
<th class="sort-column set_cookie"><spring:message code="set_cookie"/></th>
<th class="sort-column req_header"><spring:message code="req_header"/></th>
<th class="sort-column resp_header"><spring:message code="resp_header"/></th>
<th class="sort-column cookie" column="cookie" ><spring:message code="cookie"/></th>
<th class="sort-column referer" column="referer" ><spring:message code="referer"/></th>
<th class="sort-column user_agent" column="user_agent" ><spring:message code="user_agent"/></th>
<th class="sort-column content_len" column="content_len" ><spring:message code="content_len"/></th>
<th class="sort-column content_type" column="content_type" ><spring:message code="content_type"/></th>
<th class="sort-column set_cookie" column="set_cookie" ><spring:message code="set_cookie"/></th>
<th class="sort-column req_header" column="req_header" ><spring:message code="req_header"/></th>
<th class="sort-column resp_header" column="resp_header" ><spring:message code="resp_header"/></th>
<%-- <th class="sort-column req_body"><spring:message code="req_body"/></th>
<th class="sort-column res_body"><spring:message code="res_body"/></th> --%>
<th class="sort-column website"><spring:message code="website"/></th>
<th class="sort-column website" column="website" ><spring:message code="website"/></th>
<th class="sort-column cap_ip" isVisible="false"><spring:message code="clj_ip"/></th>
<th class="sort-column trans_proto"><spring:message code="transport_layer_protocol"/></th>
<th class="sort-column addr_type"><spring:message code='addr_type'/></th>
<th class="sort-column d_ip"><spring:message code="server_ip"/></th>
<th class="sort-column s_ip"><spring:message code="client_ip"/></th>
<th class="sort-column d_port"><spring:message code="server_port"/></th>
<th class="sort-column s_port"><spring:message code="client_port"/></th>
<th class="sort-column device_id" isVisible="false"><spring:message code="deviceid"/></th>
<th class="sort-column link_id" isVisible="false"><spring:message code="link_id"/></th>
<th class="sort-column encap_type"><spring:message code="encap_type"/></th>
<th class="sort-column direction"><spring:message code="direction"/></th>
<th class="sort-column inner_smac"><spring:message code="inner_smac"/></th>
<th class="sort-column inner_dmac"><spring:message code="inner_dmac"/></th>
<th class="sort-column stream_dir"><spring:message code="stream_type"/></th>
<th class="sort-column cap_ip" isVisible="false" column="clj_ip" ><spring:message code="clj_ip"/></th>
<th class="sort-column trans_proto" column="transport_layer_protocol" ><spring:message code="transport_layer_protocol"/></th>
<th class="sort-column addr_type" column="addr_type" ><spring:message code='addr_type'/></th>
<th class="sort-column d_ip" column="server_ip" ><spring:message code="server_ip"/></th>
<th class="sort-column s_ip" column="client_ip" ><spring:message code="client_ip"/></th>
<th class="sort-column d_port" column="server_port" ><spring:message code="server_port"/></th>
<th class="sort-column s_port" column="client_port" ><spring:message code="client_port"/></th>
<th class="sort-column device_id" isVisible="false" column="deviceid" ><spring:message code="deviceid"/></th>
<th class="sort-column link_id" isVisible="false" column="link_id" ><spring:message code="link_id"/></th>
<th class="sort-column encap_type" column="encap_type" ><spring:message code="encap_type"/></th>
<th class="sort-column direction" column="direction" ><spring:message code="direction"/></th>
<th class="sort-column inner_smac" column="inner_smac" ><spring:message code="inner_smac"/></th>
<th class="sort-column inner_dmac" column="inner_dmac" ><spring:message code="inner_dmac"/></th>
<th class="sort-column stream_dir" column="stream_type" ><spring:message code="stream_type"/></th>
<th class="sort-column addr_list"><spring:message code="nest_addr_list"/></th>
<th class="sort-column server_locate"><spring:message code='server_locate'/></th>
<th class="sort-column client_locate"><spring:message code='client_locate'/></th>
<th class="sort-column s_asn" isVisible="false"><spring:message code='s_asn'/></th>
<th class="sort-column d_asn" isVisible="false"><spring:message code='d_asn'/></th>
<th class="sort-column s_subscribe_id" isVisible="false"><spring:message code='s_subscribe_id'/></th>
<th class="sort-column d_subscribe_id" isVisible="false"><spring:message code='d_subscribe_id'/></th>
<th class="sort-column user_region" isVisible="false"><spring:message code='user_region'/></th>
<c:if test="${fns:getUser().isAdmin()}"><th class="sort-column scene_file"><spring:message code='scene_file'/></th></c:if>
<th class="sort-column addr_list" column="nest_addr_list" ><spring:message code="nest_addr_list"/></th>
<th class="sort-column server_locate" column="server_locate" ><spring:message code='server_locate'/></th>
<th class="sort-column client_locate" column="client_locate" ><spring:message code='client_locate'/></th>
<th class="sort-column s_asn" isVisible="false" column="s_asn" ><spring:message code='s_asn'/></th>
<th class="sort-column d_asn" isVisible="false" column="d_asn" ><spring:message code='d_asn'/></th>
<th class="sort-column s_subscribe_id" isVisible="false" column="s_subscribe_id" ><spring:message code='s_subscribe_id'/></th>
<th class="sort-column d_subscribe_id" isVisible="false" column="d_subscribe_id" ><spring:message code='d_subscribe_id'/></th>
<th class="sort-column user_region" isVisible="false" column="user_region" ><spring:message code='user_region'/></th>
<c:if test="${fns:getUser().isAdmin()}"><th class="sort-column scene_file" column="scene_file" ><spring:message code='scene_file'/></th></c:if>
</tr>
</thead>
<tbody>