This commit is contained in:
bwcx_jzy 2023-01-08 23:43:23 +08:00
parent 2635510502
commit b119fc2350
No known key found for this signature in database
GPG Key ID: 5E48E9372088B9E5
14 changed files with 66 additions and 74 deletions

View File

@ -121,8 +121,7 @@ public class ProjectFileBackupController extends BaseAgentController {
* @param backupId 备份id
*/
@GetMapping(value = "backup-download", produces = MediaType.APPLICATION_JSON_VALUE)
public void download(String id, @ValidatorItem String backupId, @ValidatorItem String filename, String levelName) {
HttpServletResponse response = getResponse();
public void download(String id, @ValidatorItem String backupId, @ValidatorItem String filename, String levelName, HttpServletResponse response) {
try {
super.getProjectInfoModel();
File lib = ProjectFileBackupUtil.path(id, backupId);

View File

@ -45,6 +45,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@ -288,12 +289,12 @@ public class CertificateController extends BaseAgentController {
* @param id 项目id
*/
@RequestMapping(value = "/export", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public void export(String id) {
public void export(String id, HttpServletResponse response) {
CertModel item = certService.getItem(id);
Assert.notNull(item, "导出失败");
String parent = FileUtil.file(item.getCert()).getParent();
File zip = ZipUtil.zip(parent);
ServletUtil.write(getResponse(), zip);
ServletUtil.write(response, zip);
FileUtil.del(zip);
}
}

View File

@ -39,6 +39,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.util.concurrent.TimeUnit;
@ -77,10 +78,10 @@ public class LogManageController extends BaseAgentController {
@RequestMapping(value = "log_download", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public void logDownload(@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "path错误") String path) {
public void logDownload(@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "path错误") String path, HttpServletResponse response) {
File file = FileUtil.file(LogbackConfig.getPath(), path);
if (file.isFile()) {
ServletUtil.write(getResponse(), file);
ServletUtil.write(response, file);
}
}
}

View File

@ -323,32 +323,6 @@ public abstract class BaseJpomController {
return request;
}
public HttpServletResponse getResponse() {
HttpServletResponse response = getRequestAttributes().getResponse();
Objects.requireNonNull(response, "response null");
return response;
}
/**
* 获取session
*
* @return session
*/
public HttpSession getSession() {
HttpSession session = getRequestAttributes().getRequest().getSession();
Objects.requireNonNull(session, "session null");
return session;
}
/**
* 获取Application
*
* @return Application
*/
public ServletContext getApplication() {
return getRequest().getServletContext();
}
/**
* 获取session 字符串
*

View File

@ -60,6 +60,7 @@ import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.awt.*;
import java.io.IOException;
import java.util.List;
@ -105,9 +106,9 @@ public class LoginControl extends BaseServerController {
*/
@RequestMapping(value = "randCode.png", method = RequestMethod.GET, produces = MediaType.IMAGE_PNG_VALUE)
@NotLogin
public void randCode() throws IOException {
public void randCode(HttpServletResponse response) throws IOException {
if (webConfig.isDisabledCaptcha()) {
ServletUtil.write(getResponse(), JsonMessage.success("验证码已禁用").toString(), MediaType.APPLICATION_JSON_VALUE);
ServletUtil.write(response, JsonMessage.success("验证码已禁用").toString(), MediaType.APPLICATION_JSON_VALUE);
return;
}
int height = 50;
@ -115,7 +116,6 @@ public class LoginControl extends BaseServerController {
// 设置为默认字体
circleCaptcha.setFont(new Font(null, Font.PLAIN, (int) (height * 0.75)));
circleCaptcha.createCode();
HttpServletResponse response = getResponse();
circleCaptcha.write(response.getOutputStream());
String code = circleCaptcha.getCode();
setSessionAttribute(LOGIN_CODE, code);
@ -261,8 +261,8 @@ public class LoginControl extends BaseServerController {
*/
@RequestMapping(value = "logout2", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@NotLogin
public JsonMessage<Object> logout() {
getSession().invalidate();
public JsonMessage<Object> logout(HttpSession session) {
session.invalidate();
return JsonMessage.success("退出成功");
}

View File

@ -76,9 +76,9 @@ public class BuildInfoHistoryController extends BaseServerController {
*/
@RequestMapping(value = "/build/history/download_file.html", method = RequestMethod.GET)
@Feature(method = MethodFeature.DOWNLOAD)
public void downloadFile(@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "没有数据") String logId) {
public void downloadFile(@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "没有数据") String logId, HttpServletResponse response) {
BuildHistoryLog buildHistoryLog = dbBuildHistoryLogService.getByKey(logId, getRequest());
this.downloadFile(buildHistoryLog);
this.downloadFile(buildHistoryLog, response);
}
/**
@ -89,7 +89,9 @@ public class BuildInfoHistoryController extends BaseServerController {
*/
@RequestMapping(value = "/build/history/download_file_by_build", method = RequestMethod.GET)
@Feature(method = MethodFeature.DOWNLOAD)
public void downloadFile(@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "没有数据") String buildId, @ValidatorItem(ValidatorRule.NUMBERS) int buildNumberId) {
public void downloadFile(@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "没有数据") String buildId,
@ValidatorItem(ValidatorRule.NUMBERS) int buildNumberId,
HttpServletResponse response) {
String workspaceId = dbBuildHistoryLogService.getCheckUserWorkspace(getRequest());
//
BuildHistoryLog historyLog = new BuildHistoryLog();
@ -98,11 +100,10 @@ public class BuildInfoHistoryController extends BaseServerController {
historyLog.setBuildNumberId(buildNumberId);
List<BuildHistoryLog> buildHistoryLogs = dbBuildHistoryLogService.listByBean(historyLog);
BuildHistoryLog first = CollUtil.getFirst(buildHistoryLogs);
this.downloadFile(first);
this.downloadFile(first, response);
}
private void downloadFile(BuildHistoryLog buildHistoryLog) {
HttpServletResponse response = getResponse();
private void downloadFile(BuildHistoryLog buildHistoryLog, HttpServletResponse response) {
if (buildHistoryLog == null) {
ServletUtil.write(response, JsonMessage.getString(404, "构建记录不存在"), MediaType.APPLICATION_JSON_VALUE);
return;
@ -124,7 +125,7 @@ public class BuildInfoHistoryController extends BaseServerController {
@RequestMapping(value = "/build/history/download_log.html", method = RequestMethod.GET)
@Feature(method = MethodFeature.DOWNLOAD)
public void downloadLog(@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "没有数据") String logId) {
public void downloadLog(@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "没有数据") String logId, HttpServletResponse response) {
BuildHistoryLog buildHistoryLog = dbBuildHistoryLogService.getByKey(logId, getRequest());
Objects.requireNonNull(buildHistoryLog);
BuildInfoModel item = buildInfoService.getByKey(buildHistoryLog.getBuildDataId());
@ -134,7 +135,7 @@ public class BuildInfoHistoryController extends BaseServerController {
return;
}
if (logFile.isFile()) {
ServletUtil.write(getResponse(), logFile);
ServletUtil.write(response, logFile);
}
}

View File

@ -37,6 +37,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* @author bwcx_jzy
* @since 2022/5/11
@ -80,8 +83,10 @@ public class ProjectFileBackupController extends BaseServerController {
* @param backupId 备份id
*/
@GetMapping(value = "backup-download", produces = MediaType.APPLICATION_JSON_VALUE)
public void download(String id, @ValidatorItem String backupId, @ValidatorItem String filename, String levelName) {
NodeForward.requestDownload(getNode(), getRequest(), getResponse(), NodeUrl.MANAGE_FILE_BACKUP_DOWNLOAD);
public void download(String id, @ValidatorItem String backupId, @ValidatorItem String filename, String levelName,
HttpServletResponse response,
HttpServletRequest request) {
NodeForward.requestDownload(getNode(), request, response, NodeUrl.MANAGE_FILE_BACKUP_DOWNLOAD);
}
/**
@ -94,8 +99,8 @@ public class ProjectFileBackupController extends BaseServerController {
* @return msg
*/
@RequestMapping(value = "backup-delete", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public String deleteFile(String id, @ValidatorItem String backupId, @ValidatorItem String filename, String levelName) {
return NodeForward.request(getNode(), getRequest(), NodeUrl.MANAGE_FILE_BACKUP_DELETE).toString();
public String deleteFile(String id, @ValidatorItem String backupId, @ValidatorItem String filename, String levelName, HttpServletRequest request) {
return NodeForward.request(getNode(), request, NodeUrl.MANAGE_FILE_BACKUP_DELETE).toString();
}
/**
@ -109,7 +114,7 @@ public class ProjectFileBackupController extends BaseServerController {
* @return msg
*/
@RequestMapping(value = "backup-recover", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public String recoverFile(String id, @ValidatorItem String backupId, String type, String filename, String levelName) {
return NodeForward.request(getNode(), getRequest(), NodeUrl.MANAGE_FILE_BACKUP_RECOVER).toString();
public String recoverFile(String id, @ValidatorItem String backupId, String type, String filename, String levelName, HttpServletRequest request) {
return NodeForward.request(getNode(), request, NodeUrl.MANAGE_FILE_BACKUP_RECOVER).toString();
}
}

View File

@ -36,6 +36,7 @@ import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* 文件管理
@ -106,8 +107,8 @@ public class ProjectFileControl extends BaseServerController {
*/
@RequestMapping(value = "download", method = RequestMethod.GET)
@Feature(cls = ClassFeature.PROJECT_FILE, method = MethodFeature.DOWNLOAD)
public void download() {
NodeForward.requestDownload(getNode(), getRequest(), getResponse(), NodeUrl.Manage_File_Download);
public void download(HttpServletRequest request, HttpServletResponse response) {
NodeForward.requestDownload(getNode(), request, response, NodeUrl.Manage_File_Download);
}
/**
@ -117,8 +118,8 @@ public class ProjectFileControl extends BaseServerController {
*/
@RequestMapping(value = "deleteFile", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(cls = ClassFeature.PROJECT_FILE, method = MethodFeature.DEL)
public String deleteFile() {
return NodeForward.request(getNode(), getRequest(), NodeUrl.Manage_File_DeleteFile).toString();
public String deleteFile(HttpServletRequest request) {
return NodeForward.request(getNode(), request, NodeUrl.Manage_File_DeleteFile).toString();
}
@ -129,8 +130,8 @@ public class ProjectFileControl extends BaseServerController {
*/
@PostMapping(value = "update_config_file", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(cls = ClassFeature.PROJECT_FILE, method = MethodFeature.EDIT)
public String updateConfigFile() {
return NodeForward.request(getNode(), getRequest(), NodeUrl.Manage_File_UpdateConfigFile).toString();
public String updateConfigFile(HttpServletRequest request) {
return NodeForward.request(getNode(), request, NodeUrl.Manage_File_UpdateConfigFile).toString();
}
/**
@ -140,8 +141,8 @@ public class ProjectFileControl extends BaseServerController {
*/
@GetMapping(value = "read_file", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(cls = ClassFeature.PROJECT_FILE, method = MethodFeature.LIST)
public String readFile() {
return NodeForward.request(getNode(), getRequest(), NodeUrl.Manage_File_ReadFile).toString();
public String readFile(HttpServletRequest request) {
return NodeForward.request(getNode(), request, NodeUrl.Manage_File_ReadFile).toString();
}
/**

View File

@ -38,6 +38,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* 控制台日志备份管理
*
@ -59,8 +62,8 @@ public class LogBackController extends BaseServerController {
@RequestMapping(value = "export.html", method = RequestMethod.GET)
@ResponseBody
@Feature(method = MethodFeature.DOWNLOAD)
public void export() {
NodeForward.requestDownload(getNode(), getRequest(), getResponse(), NodeUrl.Manage_Log_export);
public void export(HttpServletRequest request, HttpServletResponse response) {
NodeForward.requestDownload(getNode(), request, response, NodeUrl.Manage_Log_export);
}
/**
@ -81,8 +84,8 @@ public class LogBackController extends BaseServerController {
@RequestMapping(value = "logBack_download", method = RequestMethod.GET)
@ResponseBody
@Feature(method = MethodFeature.DOWNLOAD)
public void download() {
NodeForward.requestDownload(getNode(), getRequest(), getResponse(), NodeUrl.Manage_Log_logBack_download);
public void download(HttpServletResponse response) {
NodeForward.requestDownload(getNode(), getRequest(), response, NodeUrl.Manage_Log_logBack_download);
}
@RequestMapping(value = "logBack_delete", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)

View File

@ -38,6 +38,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
@ -116,7 +117,7 @@ public class CertificateController extends BaseServerController {
@RequestMapping(value = "/export", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@Feature(method = MethodFeature.DOWNLOAD)
public void export() {
NodeForward.requestDownload(getNode(), getRequest(), getResponse(), NodeUrl.System_Certificate_export);
public void export(HttpServletResponse response) {
NodeForward.requestDownload(getNode(), getRequest(), response, NodeUrl.System_Certificate_export);
}
}

View File

@ -41,6 +41,7 @@ import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;
import top.jpom.model.PageResultDto;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.util.List;
@ -176,7 +177,7 @@ public class CommandLogController extends BaseServerController {
@RequestMapping(value = "download_log", method = RequestMethod.GET)
@ResponseBody
@Feature(method = MethodFeature.DOWNLOAD)
public void downloadLog(@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "没有数据") String logId) {
public void downloadLog(@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "没有数据") String logId, HttpServletResponse response) {
CommandExecLogModel item = commandExecLogService.getByKey(logId);
Assert.notNull(item, "没有对应数据");
File logFile = item.logFile();
@ -184,7 +185,7 @@ public class CommandLogController extends BaseServerController {
return;
}
if (logFile.isFile()) {
ServletUtil.write(getResponse(), logFile);
ServletUtil.write(response, logFile);
}
}
}

View File

@ -91,8 +91,7 @@ public class SshFileController extends BaseServerController {
@RequestMapping(value = "download.html", method = RequestMethod.GET)
@Feature(method = MethodFeature.DOWNLOAD)
public void download(String id, String path, String name) throws IOException {
HttpServletResponse response = getResponse();
public void download(String id, String path, String name, HttpServletResponse response) throws IOException {
SshModel sshModel = sshService.getByKey(id, false);
if (sshModel == null) {
ServletUtil.write(response, "ssh error", MediaType.TEXT_HTML_VALUE);

View File

@ -45,6 +45,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.util.concurrent.TimeUnit;
@ -102,14 +104,16 @@ public class LogManageController extends BaseServerController {
@RequestMapping(value = "log_download", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.DOWNLOAD)
public void logDownload(String nodeId,
@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "path错误") String path) {
@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "path错误") String path,
HttpServletResponse response,
HttpServletRequest request) {
if (StrUtil.isNotEmpty(nodeId)) {
NodeForward.requestDownload(getNode(), getRequest(), getResponse(), NodeUrl.DownloadSystemLog);
NodeForward.requestDownload(getNode(), request, response, NodeUrl.DownloadSystemLog);
return;
}
File file = FileUtil.file(LogbackConfig.getPath(), path);
if (file.isFile()) {
ServletUtil.write(getResponse(), file);
ServletUtil.write(response, file);
}
}
}

View File

@ -40,6 +40,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpSession;
import java.util.List;
/**
@ -71,7 +72,8 @@ public class UserInfoController extends BaseServerController {
*/
@RequestMapping(value = "updatePwd", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public JsonMessage<String> updatePwd(@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "密码不能为空") String oldPwd,
@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "密码不能为空") String newPwd) {
@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "密码不能为空") String newPwd,
HttpSession session) {
Assert.state(!StrUtil.equals(oldPwd, newPwd), "新旧密码一致");
UserModel userName = getUser();
Assert.state(!userName.isDemoUser(), "当前账户为演示账号,不支持修改密码");
@ -82,7 +84,7 @@ public class UserInfoController extends BaseServerController {
userService.updatePwd(userName.getId(), newPwd);
// 如果修改成功则销毁会话
getSession().invalidate();
session.invalidate();
return JsonMessage.success("修改密码成功!");
} catch (Exception e) {
log.error(e.getMessage(), e);