🔨 终端文件操作日志.
This commit is contained in:
@@ -26,6 +26,7 @@ import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.visor.framework.biz.operator.log.core.annotation.OperatorLog;
|
||||
import org.dromara.visor.framework.biz.operator.log.core.enums.ReturnType;
|
||||
import org.dromara.visor.framework.log.core.annotation.IgnoreLog;
|
||||
import org.dromara.visor.framework.log.core.enums.IgnoreLogMode;
|
||||
import org.dromara.visor.framework.web.core.annotation.RestWrapper;
|
||||
@@ -58,7 +59,7 @@ public class AuthenticationController {
|
||||
@Resource
|
||||
private AuthenticationService authenticationService;
|
||||
|
||||
@OperatorLog(AuthenticationOperatorType.LOGIN)
|
||||
@OperatorLog(value = AuthenticationOperatorType.LOGIN, ret = ReturnType.IGNORE)
|
||||
@PermitAll
|
||||
@Operation(summary = "登录")
|
||||
@PostMapping("/login")
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (c) 2023 - present Dromara, All rights reserved.
|
||||
*
|
||||
* https://visor.dromara.org
|
||||
* https://visor.dromara.org.cn
|
||||
* https://visor.orionsec.cn
|
||||
*
|
||||
* Members:
|
||||
* Jiahang Li - ljh1553488six@139.com - author
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.dromara.visor.module.terminal.controller;
|
||||
|
||||
import cn.orionsec.kit.lang.define.wrapper.DataGrid;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.visor.common.validator.group.Page;
|
||||
import org.dromara.visor.framework.biz.operator.log.core.annotation.OperatorLog;
|
||||
import org.dromara.visor.framework.log.core.annotation.IgnoreLog;
|
||||
import org.dromara.visor.framework.log.core.enums.IgnoreLogMode;
|
||||
import org.dromara.visor.framework.web.core.annotation.RestWrapper;
|
||||
import org.dromara.visor.module.terminal.define.operator.TerminalFileLogOperatorType;
|
||||
import org.dromara.visor.module.terminal.entity.request.terminal.TerminalFileLogQueryRequest;
|
||||
import org.dromara.visor.module.terminal.entity.vo.TerminalFileLogVO;
|
||||
import org.dromara.visor.module.terminal.service.TerminalFileLogService;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 终端文件日志操作服务 api
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-12-26 22:09
|
||||
*/
|
||||
@Tag(name = "terminal - 终端文件日志操作服务")
|
||||
@Slf4j
|
||||
@Validated
|
||||
@RestWrapper
|
||||
@RestController
|
||||
@RequestMapping("/terminal/terminal-file-log")
|
||||
public class TerminalFileLogController {
|
||||
|
||||
@Resource
|
||||
private TerminalFileLogService terminalFileLogService;
|
||||
|
||||
@IgnoreLog(IgnoreLogMode.RET)
|
||||
@PostMapping("/query")
|
||||
@Operation(summary = "分页查询终端文件操作日志")
|
||||
@PreAuthorize("@ss.hasAnyPermission('infra:operator-log:query', 'terminal:terminal-file-log:management:query')")
|
||||
public DataGrid<TerminalFileLogVO> getTerminalFileLogPage(@Validated(Page.class) @RequestBody TerminalFileLogQueryRequest request) {
|
||||
return terminalFileLogService.getTerminalFileLogPage(request);
|
||||
}
|
||||
|
||||
@IgnoreLog(IgnoreLogMode.RET)
|
||||
@PostMapping("/count")
|
||||
@Operation(summary = "查询终端文件操作日志数量")
|
||||
@PreAuthorize("@ss.hasAnyPermission('infra:operator-log:query', 'terminal:terminal-file-log:management:query')")
|
||||
public Long getTerminalFileLogCount(@Validated @RequestBody TerminalFileLogQueryRequest request) {
|
||||
return terminalFileLogService.getTerminalFileLogCount(request);
|
||||
}
|
||||
|
||||
@OperatorLog(TerminalFileLogOperatorType.DELETE)
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除终端文件操作日志")
|
||||
@Parameter(name = "idList", description = "idList", required = true)
|
||||
@PreAuthorize("@ss.hasAnyPermission('infra:operator-log:delete', 'terminal:terminal-file-log:management:delete')")
|
||||
public Integer deleteTerminalFileLog(@RequestParam("idList") List<Long> idList) {
|
||||
return terminalFileLogService.deleteTerminalFileLog(idList);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,22 +22,15 @@
|
||||
*/
|
||||
package org.dromara.visor.module.terminal.controller;
|
||||
|
||||
import cn.orionsec.kit.lang.define.wrapper.DataGrid;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.visor.common.validator.group.Page;
|
||||
import org.dromara.visor.framework.biz.operator.log.core.annotation.OperatorLog;
|
||||
import org.dromara.visor.framework.log.core.annotation.IgnoreLog;
|
||||
import org.dromara.visor.framework.log.core.enums.IgnoreLogMode;
|
||||
import org.dromara.visor.framework.web.core.annotation.IgnoreWrapper;
|
||||
import org.dromara.visor.framework.web.core.annotation.RestWrapper;
|
||||
import org.dromara.visor.module.terminal.define.operator.TerminalOperatorType;
|
||||
import org.dromara.visor.module.terminal.entity.request.terminal.TerminalSftpLogQueryRequest;
|
||||
import org.dromara.visor.module.terminal.entity.vo.TerminalSftpLogVO;
|
||||
import org.dromara.visor.module.terminal.service.TerminalSftpService;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
@@ -46,7 +39,6 @@ import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBo
|
||||
import javax.annotation.Resource;
|
||||
import javax.annotation.security.PermitAll;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* SFTP 操作服务 api
|
||||
@@ -66,31 +58,6 @@ public class TerminalSftpController {
|
||||
@Resource
|
||||
private TerminalSftpService terminalSftpService;
|
||||
|
||||
@IgnoreLog(IgnoreLogMode.RET)
|
||||
@PostMapping("/query-log")
|
||||
@Operation(summary = "分页查询 SFTP 操作日志")
|
||||
@PreAuthorize("@ss.hasAnyPermission('infra:operator-log:query', 'terminal:terminal-sftp-log:management:query')")
|
||||
public DataGrid<TerminalSftpLogVO> getTerminalSftpLogPage(@Validated(Page.class) @RequestBody TerminalSftpLogQueryRequest request) {
|
||||
return terminalSftpService.getTerminalSftpLogPage(request);
|
||||
}
|
||||
|
||||
@IgnoreLog(IgnoreLogMode.RET)
|
||||
@PostMapping("/log-count")
|
||||
@Operation(summary = "查询 SFTP 操作日志数量")
|
||||
@PreAuthorize("@ss.hasAnyPermission('infra:operator-log:query', 'terminal:terminal-sftp-log:management:query')")
|
||||
public Long getTerminalSftpLogCount(@Validated @RequestBody TerminalSftpLogQueryRequest request) {
|
||||
return terminalSftpService.getTerminalSftpLogCount(request);
|
||||
}
|
||||
|
||||
@OperatorLog(TerminalOperatorType.DELETE_SFTP_LOG)
|
||||
@DeleteMapping("/delete-log")
|
||||
@Operation(summary = "删除 SFTP 操作日志")
|
||||
@Parameter(name = "idList", description = "idList", required = true)
|
||||
@PreAuthorize("@ss.hasAnyPermission('infra:operator-log:delete', 'terminal:terminal-sftp-log:management:delete')")
|
||||
public Integer deleteTerminalSftpLog(@RequestParam("idList") List<Long> idList) {
|
||||
return terminalSftpService.deleteTerminalSftpLog(idList);
|
||||
}
|
||||
|
||||
@IgnoreLog(IgnoreLogMode.RET)
|
||||
@GetMapping("/get-content")
|
||||
@Operation(summary = "获取文件内容")
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2023 - present Dromara, All rights reserved.
|
||||
*
|
||||
* https://visor.dromara.org
|
||||
* https://visor.dromara.org.cn
|
||||
* https://visor.orionsec.cn
|
||||
*
|
||||
* Members:
|
||||
* Jiahang Li - ljh1553488six@139.com - author
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.dromara.visor.module.terminal.convert;
|
||||
|
||||
import org.dromara.visor.module.infra.entity.dto.operator.OperatorLogDTO;
|
||||
import org.dromara.visor.module.terminal.entity.vo.TerminalFileLogVO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
* 终端文件操作日志 内部对象转换器
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-12-26 22:09
|
||||
*/
|
||||
@Mapper
|
||||
public interface TerminalFileLogConvert {
|
||||
|
||||
TerminalFileLogConvert MAPPER = Mappers.getMapper(TerminalFileLogConvert.class);
|
||||
|
||||
@Mapping(target = "extra", ignore = true)
|
||||
TerminalFileLogVO to(OperatorLogDTO request);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (c) 2023 - present Dromara, All rights reserved.
|
||||
*
|
||||
* https://visor.dromara.org
|
||||
* https://visor.dromara.org.cn
|
||||
* https://visor.orionsec.cn
|
||||
*
|
||||
* Members:
|
||||
* Jiahang Li - ljh1553488six@139.com - author
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.dromara.visor.module.terminal.define.operator;
|
||||
|
||||
import cn.orionsec.kit.lang.utils.collect.Lists;
|
||||
import org.dromara.visor.framework.biz.operator.log.core.annotation.Module;
|
||||
import org.dromara.visor.framework.biz.operator.log.core.enums.OperatorRiskLevel;
|
||||
import org.dromara.visor.framework.biz.operator.log.core.factory.InitializingOperatorTypes;
|
||||
import org.dromara.visor.framework.biz.operator.log.core.model.OperatorType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 终端文件日志 操作日志类型
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2024/3/2 14:37
|
||||
*/
|
||||
@Module("terminal:terminal-file-log")
|
||||
public class TerminalFileLogOperatorType extends InitializingOperatorTypes {
|
||||
|
||||
public static final String DELETE = "terminal-file-log:delete";
|
||||
|
||||
public static final List<String> TYPES = Lists.of(
|
||||
TerminalOperatorType.SFTP_MKDIR,
|
||||
TerminalOperatorType.SFTP_TOUCH,
|
||||
TerminalOperatorType.SFTP_MOVE,
|
||||
TerminalOperatorType.SFTP_REMOVE,
|
||||
TerminalOperatorType.SFTP_TRUNCATE,
|
||||
TerminalOperatorType.SFTP_CHMOD,
|
||||
TerminalOperatorType.SFTP_CHOWN,
|
||||
TerminalOperatorType.SFTP_CHGRP,
|
||||
TerminalOperatorType.SFTP_GET_CONTENT,
|
||||
TerminalOperatorType.SFTP_SET_CONTENT,
|
||||
TerminalOperatorType.SFTP_UPLOAD,
|
||||
TerminalOperatorType.SFTP_DOWNLOAD,
|
||||
TerminalOperatorType.RDP_UPLOAD,
|
||||
TerminalOperatorType.RDP_DOWNLOAD
|
||||
);
|
||||
|
||||
@Override
|
||||
public OperatorType[] types() {
|
||||
return new OperatorType[]{
|
||||
new OperatorType(OperatorRiskLevel.H, DELETE, "删除文件操作日志 <sb>${count}</sb> 条"),
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,14 +22,11 @@
|
||||
*/
|
||||
package org.dromara.visor.module.terminal.define.operator;
|
||||
|
||||
import cn.orionsec.kit.lang.utils.collect.Lists;
|
||||
import org.dromara.visor.framework.biz.operator.log.core.annotation.Module;
|
||||
import org.dromara.visor.framework.biz.operator.log.core.enums.OperatorRiskLevel;
|
||||
import org.dromara.visor.framework.biz.operator.log.core.factory.InitializingOperatorTypes;
|
||||
import org.dromara.visor.framework.biz.operator.log.core.model.OperatorType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 终端 操作日志类型
|
||||
*
|
||||
@@ -42,8 +39,6 @@ public class TerminalOperatorType extends InitializingOperatorTypes {
|
||||
|
||||
public static final String CONNECT = "terminal:connect";
|
||||
|
||||
public static final String DELETE_SFTP_LOG = "terminal:delete-sftp-log";
|
||||
|
||||
public static final String SFTP_MKDIR = "terminal:sftp-mkdir";
|
||||
|
||||
public static final String SFTP_TOUCH = "terminal:sftp-touch";
|
||||
@@ -68,26 +63,14 @@ public class TerminalOperatorType extends InitializingOperatorTypes {
|
||||
|
||||
public static final String SFTP_DOWNLOAD = "terminal:sftp-download";
|
||||
|
||||
public static final List<String> SFTP_TYPES = Lists.of(
|
||||
SFTP_MKDIR,
|
||||
SFTP_TOUCH,
|
||||
SFTP_MOVE,
|
||||
SFTP_REMOVE,
|
||||
SFTP_TRUNCATE,
|
||||
SFTP_CHMOD,
|
||||
SFTP_CHOWN,
|
||||
SFTP_CHGRP,
|
||||
SFTP_GET_CONTENT,
|
||||
SFTP_SET_CONTENT,
|
||||
SFTP_UPLOAD,
|
||||
SFTP_DOWNLOAD
|
||||
);
|
||||
public static final String RDP_UPLOAD = "terminal:rdp-upload";
|
||||
|
||||
public static final String RDP_DOWNLOAD = "terminal:rdp-download";
|
||||
|
||||
@Override
|
||||
public OperatorType[] types() {
|
||||
return new OperatorType[]{
|
||||
new OperatorType(OperatorRiskLevel.L, CONNECT, "连接主机 ${connectType} <sb>${hostName}</sb>"),
|
||||
new OperatorType(OperatorRiskLevel.H, DELETE_SFTP_LOG, "删除 SFTP 操作日志 <sb>${count}</sb> 条"),
|
||||
new OperatorType(OperatorRiskLevel.L, SFTP_MKDIR, "创建文件夹 ${hostName} <sb>${path}</sb>"),
|
||||
new OperatorType(OperatorRiskLevel.L, SFTP_TOUCH, "创建文件 ${hostName} <sb>${path}</sb>"),
|
||||
new OperatorType(OperatorRiskLevel.M, SFTP_MOVE, "移动文件 ${hostName} <sb>${path}</sb> 至 <sb>${target}</sb>"),
|
||||
@@ -100,6 +83,8 @@ public class TerminalOperatorType extends InitializingOperatorTypes {
|
||||
new OperatorType(OperatorRiskLevel.M, SFTP_SET_CONTENT, "修改文件内容 ${hostName} <sb>${path}</sb>"),
|
||||
new OperatorType(OperatorRiskLevel.M, SFTP_UPLOAD, "上传文件 ${hostName} <sb>${path}</sb>"),
|
||||
new OperatorType(OperatorRiskLevel.M, SFTP_DOWNLOAD, "下载文件 ${hostName} <sb>${path}</sb>"),
|
||||
new OperatorType(OperatorRiskLevel.M, RDP_UPLOAD, "上传文件 ${hostName} <sb>${path}</sb>"),
|
||||
new OperatorType(OperatorRiskLevel.M, RDP_DOWNLOAD, "下载文件 ${hostName} <sb>${path}</sb>"),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (c) 2023 - present Dromara, All rights reserved.
|
||||
*
|
||||
* https://visor.dromara.org
|
||||
* https://visor.dromara.org.cn
|
||||
* https://visor.orionsec.cn
|
||||
*
|
||||
* Members:
|
||||
* Jiahang Li - ljh1553488six@139.com - author
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.dromara.visor.module.terminal.entity.request.terminal;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import org.dromara.visor.common.entity.BaseQueryRequest;
|
||||
|
||||
import javax.validation.constraints.Size;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 终端文件操作日志 查询请求对象
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2024-3-4 22:59
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Schema(name = "TerminalFileLogQueryRequest", description = "终端文件操作日志 查询请求对象")
|
||||
public class TerminalFileLogQueryRequest extends BaseQueryRequest {
|
||||
|
||||
@Schema(description = "用户id")
|
||||
private Long userId;
|
||||
|
||||
@Schema(description = "hostId")
|
||||
private Long hostId;
|
||||
|
||||
@Size(max = 64)
|
||||
@Schema(description = "操作类型")
|
||||
private String type;
|
||||
|
||||
@Schema(description = "操作结果 0失败 1成功")
|
||||
private Integer result;
|
||||
|
||||
@Schema(description = "开始时间-区间")
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date[] startTimeRange;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (c) 2023 - present Dromara, All rights reserved.
|
||||
*
|
||||
* https://visor.dromara.org
|
||||
* https://visor.dromara.org.cn
|
||||
* https://visor.orionsec.cn
|
||||
*
|
||||
* Members:
|
||||
* Jiahang Li - ljh1553488six@139.com - author
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.dromara.visor.module.terminal.entity.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 终端文件操作日志 实体对象
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-10-10 17:08
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "TerminalFileLogVO", description = "终端文件操作日志 实体对象")
|
||||
public class TerminalFileLogVO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "id")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "用户id")
|
||||
private Long userId;
|
||||
|
||||
@Schema(description = "用户名")
|
||||
private String username;
|
||||
|
||||
@Schema(description = "主机id")
|
||||
private Long hostId;
|
||||
|
||||
@Schema(description = "主机名称")
|
||||
private String hostName;
|
||||
|
||||
@Schema(description = "主机地址")
|
||||
private String hostAddress;
|
||||
|
||||
@Schema(description = "操作文件")
|
||||
private String[] paths;
|
||||
|
||||
@Schema(description = "请求ip")
|
||||
private String address;
|
||||
|
||||
@Schema(description = "请求地址")
|
||||
private String location;
|
||||
|
||||
@Schema(description = "userAgent")
|
||||
private String userAgent;
|
||||
|
||||
@Schema(description = "操作类型")
|
||||
private String type;
|
||||
|
||||
@Schema(description = "参数")
|
||||
private Map<String, Object> extra;
|
||||
|
||||
@Schema(description = "操作结果 0失败 1成功")
|
||||
private Integer result;
|
||||
|
||||
@Schema(description = "开始时间")
|
||||
private Date startTime;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (c) 2023 - present Dromara, All rights reserved.
|
||||
*
|
||||
* https://visor.dromara.org
|
||||
* https://visor.dromara.org.cn
|
||||
* https://visor.orionsec.cn
|
||||
*
|
||||
* Members:
|
||||
* Jiahang Li - ljh1553488six@139.com - author
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.dromara.visor.module.terminal.service;
|
||||
|
||||
import cn.orionsec.kit.lang.define.wrapper.DataGrid;
|
||||
import org.dromara.visor.module.terminal.entity.request.terminal.TerminalFileLogQueryRequest;
|
||||
import org.dromara.visor.module.terminal.entity.vo.TerminalFileLogVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 终端文件日志服务类
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-12-26 22:09
|
||||
*/
|
||||
public interface TerminalFileLogService {
|
||||
|
||||
/**
|
||||
* 分页查询终端文件操作日志
|
||||
*
|
||||
* @param request request
|
||||
* @return rows
|
||||
*/
|
||||
DataGrid<TerminalFileLogVO> getTerminalFileLogPage(TerminalFileLogQueryRequest request);
|
||||
|
||||
/**
|
||||
* 获取终端文件操作日志数量
|
||||
*
|
||||
* @param request request
|
||||
* @return count
|
||||
*/
|
||||
Long getTerminalFileLogCount(TerminalFileLogQueryRequest request);
|
||||
|
||||
/**
|
||||
* 删除终端文件操作日志
|
||||
*
|
||||
* @param idList idList
|
||||
* @return effect
|
||||
*/
|
||||
Integer deleteTerminalFileLog(List<Long> idList);
|
||||
|
||||
}
|
||||
@@ -22,15 +22,11 @@
|
||||
*/
|
||||
package org.dromara.visor.module.terminal.service;
|
||||
|
||||
import cn.orionsec.kit.lang.define.wrapper.DataGrid;
|
||||
import org.dromara.visor.module.terminal.entity.request.terminal.TerminalSftpLogQueryRequest;
|
||||
import org.dromara.visor.module.terminal.entity.vo.TerminalSftpLogVO;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* SFTP 操作 服务类
|
||||
@@ -41,30 +37,6 @@ import java.util.List;
|
||||
*/
|
||||
public interface TerminalSftpService {
|
||||
|
||||
/**
|
||||
* 分页查询 SFTP 操作日志
|
||||
*
|
||||
* @param request request
|
||||
* @return rows
|
||||
*/
|
||||
DataGrid<TerminalSftpLogVO> getTerminalSftpLogPage(TerminalSftpLogQueryRequest request);
|
||||
|
||||
/**
|
||||
* 获取 SFTP 操作日志数量
|
||||
*
|
||||
* @param request request
|
||||
* @return count
|
||||
*/
|
||||
Long getTerminalSftpLogCount(TerminalSftpLogQueryRequest request);
|
||||
|
||||
/**
|
||||
* 删除 SFTP 操作日志
|
||||
*
|
||||
* @param idList idList
|
||||
* @return effect
|
||||
*/
|
||||
Integer deleteTerminalSftpLog(List<Long> idList);
|
||||
|
||||
/**
|
||||
* 设置文件内容
|
||||
*
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Copyright (c) 2023 - present Dromara, All rights reserved.
|
||||
*
|
||||
* https://visor.dromara.org
|
||||
* https://visor.dromara.org.cn
|
||||
* https://visor.orionsec.cn
|
||||
*
|
||||
* Members:
|
||||
* Jiahang Li - ljh1553488six@139.com - author
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.dromara.visor.module.terminal.service.impl;
|
||||
|
||||
import cn.orionsec.kit.lang.define.wrapper.DataGrid;
|
||||
import cn.orionsec.kit.lang.utils.Arrays1;
|
||||
import cn.orionsec.kit.lang.utils.Strings;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.visor.common.constant.ExtraFieldConst;
|
||||
import org.dromara.visor.framework.biz.operator.log.core.utils.OperatorLogs;
|
||||
import org.dromara.visor.module.infra.api.OperatorLogApi;
|
||||
import org.dromara.visor.module.infra.entity.dto.operator.OperatorLogQueryDTO;
|
||||
import org.dromara.visor.module.terminal.convert.TerminalFileLogConvert;
|
||||
import org.dromara.visor.module.terminal.define.operator.TerminalFileLogOperatorType;
|
||||
import org.dromara.visor.module.terminal.entity.request.terminal.TerminalFileLogQueryRequest;
|
||||
import org.dromara.visor.module.terminal.entity.vo.TerminalFileLogVO;
|
||||
import org.dromara.visor.module.terminal.service.TerminalFileLogService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 终端文件日志服务实现类
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2024/3/4 23:35
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class TerminalFileLogServiceImpl implements TerminalFileLogService {
|
||||
|
||||
@Resource
|
||||
private OperatorLogApi operatorLogApi;
|
||||
|
||||
@Override
|
||||
public DataGrid<TerminalFileLogVO> getTerminalFileLogPage(TerminalFileLogQueryRequest request) {
|
||||
// 查询
|
||||
OperatorLogQueryDTO query = this.buildQueryInfo(request);
|
||||
// 转换
|
||||
return operatorLogApi.getOperatorLogPage(query)
|
||||
.map(s -> {
|
||||
JSONObject extra = JSON.parseObject(s.getExtra());
|
||||
TerminalFileLogVO vo = TerminalFileLogConvert.MAPPER.to(s);
|
||||
vo.setHostId(extra.getLong(ExtraFieldConst.HOST_ID));
|
||||
vo.setHostName(extra.getString(ExtraFieldConst.HOST_NAME));
|
||||
vo.setHostAddress(extra.getString(ExtraFieldConst.ADDRESS));
|
||||
String[] paths = Optional.ofNullable(extra.getString(ExtraFieldConst.PATH))
|
||||
.map(p -> p.split("\\|"))
|
||||
.orElse(new String[0]);
|
||||
vo.setPaths(paths);
|
||||
vo.setExtra(extra);
|
||||
return vo;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getTerminalFileLogCount(TerminalFileLogQueryRequest request) {
|
||||
// 查询
|
||||
OperatorLogQueryDTO query = this.buildQueryInfo(request);
|
||||
// 转换
|
||||
return operatorLogApi.getOperatorLogCount(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer deleteTerminalFileLog(List<Long> idList) {
|
||||
log.info("TerminalSftpService.deleteTerminalFileLog start {}", JSON.toJSONString(idList));
|
||||
Integer effect = operatorLogApi.deleteOperatorLog(idList);
|
||||
log.info("TerminalSftpService.deleteTerminalFileLog finish {}", effect);
|
||||
// 设置日志参数
|
||||
OperatorLogs.add(OperatorLogs.COUNT, effect);
|
||||
return effect;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建查询对象
|
||||
*
|
||||
* @param request request
|
||||
* @return query
|
||||
*/
|
||||
private OperatorLogQueryDTO buildQueryInfo(TerminalFileLogQueryRequest request) {
|
||||
Long hostId = request.getHostId();
|
||||
String type = request.getType();
|
||||
// 构建参数
|
||||
OperatorLogQueryDTO query = OperatorLogQueryDTO.builder()
|
||||
.userId(request.getUserId())
|
||||
.result(request.getResult())
|
||||
.startTimeStart(Arrays1.getIfPresent(request.getStartTimeRange(), 0))
|
||||
.startTimeEnd(Arrays1.getIfPresent(request.getStartTimeRange(), 1))
|
||||
.build();
|
||||
query.setPage(request.getPage());
|
||||
query.setLimit(request.getLimit());
|
||||
query.setOrder(request.getOrder());
|
||||
if (Strings.isBlank(type)) {
|
||||
// 查询全部文件操作类型
|
||||
query.setTypeList(TerminalFileLogOperatorType.TYPES);
|
||||
} else {
|
||||
query.setType(type);
|
||||
}
|
||||
// 模糊查询
|
||||
if (hostId != null) {
|
||||
query.setExtra("\"hostId\": " + hostId + ",");
|
||||
}
|
||||
return query;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,9 +23,7 @@
|
||||
package org.dromara.visor.module.terminal.service.impl;
|
||||
|
||||
import cn.orionsec.kit.lang.constant.StandardContentType;
|
||||
import cn.orionsec.kit.lang.define.wrapper.DataGrid;
|
||||
import cn.orionsec.kit.lang.define.wrapper.HttpWrapper;
|
||||
import cn.orionsec.kit.lang.utils.Arrays1;
|
||||
import cn.orionsec.kit.lang.utils.Exceptions;
|
||||
import cn.orionsec.kit.lang.utils.Strings;
|
||||
import cn.orionsec.kit.lang.utils.Valid;
|
||||
@@ -34,27 +32,17 @@ import cn.orionsec.kit.lang.utils.io.Streams;
|
||||
import cn.orionsec.kit.net.host.SessionStore;
|
||||
import cn.orionsec.kit.net.host.sftp.SftpExecutor;
|
||||
import cn.orionsec.kit.web.servlet.web.Servlets;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.visor.common.constant.Const;
|
||||
import org.dromara.visor.common.constant.ErrorMessage;
|
||||
import org.dromara.visor.common.constant.ExtraFieldConst;
|
||||
import org.dromara.visor.common.session.config.SshConnectConfig;
|
||||
import org.dromara.visor.common.session.ssh.SessionStores;
|
||||
import org.dromara.visor.framework.biz.operator.log.core.utils.OperatorLogs;
|
||||
import org.dromara.visor.framework.redis.core.utils.RedisStrings;
|
||||
import org.dromara.visor.framework.security.core.utils.SecurityUtils;
|
||||
import org.dromara.visor.module.asset.api.HostConnectApi;
|
||||
import org.dromara.visor.module.infra.api.OperatorLogApi;
|
||||
import org.dromara.visor.module.infra.entity.dto.operator.OperatorLogQueryDTO;
|
||||
import org.dromara.visor.module.terminal.convert.TerminalSftpLogConvert;
|
||||
import org.dromara.visor.module.terminal.define.cache.TerminalCacheKeyDefine;
|
||||
import org.dromara.visor.module.terminal.define.operator.TerminalOperatorType;
|
||||
import org.dromara.visor.module.terminal.entity.dto.SftpGetContentCacheDTO;
|
||||
import org.dromara.visor.module.terminal.entity.dto.SftpSetContentCacheDTO;
|
||||
import org.dromara.visor.module.terminal.entity.request.terminal.TerminalSftpLogQueryRequest;
|
||||
import org.dromara.visor.module.terminal.entity.vo.TerminalSftpLogVO;
|
||||
import org.dromara.visor.module.terminal.handler.transfer.manager.TerminalTransferManager;
|
||||
import org.dromara.visor.module.terminal.handler.transfer.session.DownloadSession;
|
||||
import org.dromara.visor.module.terminal.service.TerminalSftpService;
|
||||
@@ -67,7 +55,6 @@ import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
@@ -81,54 +68,12 @@ import java.util.Optional;
|
||||
@Service
|
||||
public class TerminalSftpServiceImpl implements TerminalSftpService {
|
||||
|
||||
@Resource
|
||||
private OperatorLogApi operatorLogApi;
|
||||
|
||||
@Resource
|
||||
private HostConnectApi hostConnectApi;
|
||||
|
||||
@Resource
|
||||
private TerminalTransferManager terminalTransferManager;
|
||||
|
||||
@Override
|
||||
public DataGrid<TerminalSftpLogVO> getTerminalSftpLogPage(TerminalSftpLogQueryRequest request) {
|
||||
// 查询
|
||||
OperatorLogQueryDTO query = this.buildQueryInfo(request);
|
||||
// 转换
|
||||
return operatorLogApi.getOperatorLogPage(query)
|
||||
.map(s -> {
|
||||
JSONObject extra = JSON.parseObject(s.getExtra());
|
||||
TerminalSftpLogVO vo = TerminalSftpLogConvert.MAPPER.to(s);
|
||||
vo.setHostId(extra.getLong(ExtraFieldConst.HOST_ID));
|
||||
vo.setHostName(extra.getString(ExtraFieldConst.HOST_NAME));
|
||||
vo.setHostAddress(extra.getString(ExtraFieldConst.ADDRESS));
|
||||
String[] paths = Optional.ofNullable(extra.getString(ExtraFieldConst.PATH))
|
||||
.map(p -> p.split("\\|"))
|
||||
.orElse(new String[0]);
|
||||
vo.setPaths(paths);
|
||||
vo.setExtra(extra);
|
||||
return vo;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getTerminalSftpLogCount(TerminalSftpLogQueryRequest request) {
|
||||
// 查询
|
||||
OperatorLogQueryDTO query = this.buildQueryInfo(request);
|
||||
// 转换
|
||||
return operatorLogApi.getOperatorLogCount(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer deleteTerminalSftpLog(List<Long> idList) {
|
||||
log.info("TerminalSftpService.deleteSftpLog start {}", JSON.toJSONString(idList));
|
||||
Integer effect = operatorLogApi.deleteOperatorLog(idList);
|
||||
log.info("TerminalSftpService.deleteSftpLog finish {}", effect);
|
||||
// 设置日志参数
|
||||
OperatorLogs.add(OperatorLogs.COUNT, effect);
|
||||
return effect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getFileContentByToken(String token, HttpServletResponse response) throws IOException {
|
||||
// 解析 token
|
||||
@@ -215,36 +160,4 @@ public class TerminalSftpServiceImpl implements TerminalSftpService {
|
||||
return session;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建查询对象
|
||||
*
|
||||
* @param request request
|
||||
* @return query
|
||||
*/
|
||||
private OperatorLogQueryDTO buildQueryInfo(TerminalSftpLogQueryRequest request) {
|
||||
Long hostId = request.getHostId();
|
||||
String type = request.getType();
|
||||
// 构建参数
|
||||
OperatorLogQueryDTO query = OperatorLogQueryDTO.builder()
|
||||
.userId(request.getUserId())
|
||||
.result(request.getResult())
|
||||
.startTimeStart(Arrays1.getIfPresent(request.getStartTimeRange(), 0))
|
||||
.startTimeEnd(Arrays1.getIfPresent(request.getStartTimeRange(), 1))
|
||||
.build();
|
||||
query.setPage(request.getPage());
|
||||
query.setLimit(request.getLimit());
|
||||
query.setOrder(request.getOrder());
|
||||
if (Strings.isBlank(type)) {
|
||||
// 查询全部 SFTP 类型
|
||||
query.setTypeList(TerminalOperatorType.SFTP_TYPES);
|
||||
} else {
|
||||
query.setType(type);
|
||||
}
|
||||
// 模糊查询
|
||||
if (hostId != null) {
|
||||
query.setExtra("\"hostId\": " + hostId + ",");
|
||||
}
|
||||
return query;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user