mirror of
https://github.com/ReaJason/MemShellParty.git
synced 2026-09-22 07:00:43 +08:00
feat: support boot-ui
This commit is contained in:
@@ -13,4 +13,4 @@ public class BootApplication {
|
||||
SpringApplication.run(BootApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.reajason.javaweb.boot.api;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @author ReaJason
|
||||
* @since 2024/5/30
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ErrorResponse {
|
||||
private String error;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.reajason.javaweb.boot.api;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
/**
|
||||
* @author ReaJason
|
||||
* @since 2024/5/30
|
||||
*/
|
||||
@RestControllerAdvice
|
||||
@Slf4j
|
||||
public class GlobalExceptionHandler {
|
||||
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
@ExceptionHandler(Throwable.class)
|
||||
public ErrorResponse handleThrowable(Throwable throwable) {
|
||||
log.error("请求出错", throwable);
|
||||
return new ErrorResponse(throwable.getMessage());
|
||||
}
|
||||
}
|
||||
@@ -3,28 +3,27 @@ package com.reajason.javaweb.boot.controller;
|
||||
import com.reajason.javaweb.boot.entity.Config;
|
||||
import com.reajason.javaweb.config.Server;
|
||||
import com.reajason.javaweb.config.ShellTool;
|
||||
import com.reajason.javaweb.deserialize.PayloadType;
|
||||
import com.reajason.javaweb.memsell.AbstractShell;
|
||||
import com.reajason.javaweb.memsell.packer.Packer;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author ReaJason
|
||||
* @since 2024/12/13
|
||||
*/
|
||||
@RestController("/config")
|
||||
@RestController
|
||||
@RequestMapping("/config")
|
||||
@CrossOrigin("*")
|
||||
public class ConfigController {
|
||||
@RequestMapping
|
||||
public ResponseEntity<?> config() {
|
||||
Map<String, Map<?, ?>> coreMap = new HashMap<>(16);
|
||||
List<String> servers = new ArrayList<>();
|
||||
for (Server value : Server.values()) {
|
||||
AbstractShell shell = value.getShell();
|
||||
if (shell != null) {
|
||||
@@ -34,22 +33,24 @@ public class ConfigController {
|
||||
List<String> supportedShellTypes = shell.getSupportedShellTypes(shellTool);
|
||||
map.put(shellTool.name(), supportedShellTypes);
|
||||
}
|
||||
servers.add(value.name());
|
||||
coreMap.put(value.name(), map);
|
||||
}
|
||||
}
|
||||
Config config = new Config();
|
||||
config.setServers(servers);
|
||||
config.setServers(
|
||||
Arrays.stream(Server.values())
|
||||
.filter(s -> s.getShell() != null)
|
||||
.map(Server::name)
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
config.setCore(coreMap);
|
||||
Map<String, Map<?, ?>> packerMap = new HashMap<>(16);
|
||||
for (Packer.INSTANCE value : Packer.INSTANCE.values()) {
|
||||
if (value.equals(Packer.INSTANCE.Deserialize)) {
|
||||
packerMap.put(value.name(), Map.of("payloads", PayloadType.values()));
|
||||
} else {
|
||||
packerMap.put(value.name(), null);
|
||||
}
|
||||
}
|
||||
config.setPacker(packerMap);
|
||||
config.setPackers(Arrays.stream(Packer.INSTANCE.values())
|
||||
.collect(Collectors.toMap(
|
||||
Packer.INSTANCE::getDesc,
|
||||
Packer.INSTANCE::name,
|
||||
(e1, e2) -> e1,
|
||||
LinkedHashMap::new
|
||||
)));
|
||||
return ResponseEntity.ok(config);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.reajason.javaweb.boot.controller;
|
||||
|
||||
import com.reajason.javaweb.GeneratorMain;
|
||||
import com.reajason.javaweb.boot.dto.GenerateRequest;
|
||||
import com.reajason.javaweb.boot.dto.GenerateResponse;
|
||||
import com.reajason.javaweb.config.GenerateResult;
|
||||
import com.reajason.javaweb.config.InjectorConfig;
|
||||
import com.reajason.javaweb.config.ShellConfig;
|
||||
import com.reajason.javaweb.config.ShellToolConfig;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* @author ReaJason
|
||||
* @since 2024/12/18
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/generate")
|
||||
@CrossOrigin("*")
|
||||
public class GeneratorController {
|
||||
@PostMapping
|
||||
public ResponseEntity<?> generate(@RequestBody GenerateRequest request) {
|
||||
ShellConfig shellConfig = request.getShellConfig();
|
||||
ShellToolConfig shellToolConfig = request.parseShellToolConfig();
|
||||
InjectorConfig injectorConfig = request.getInjectorConfig();
|
||||
GenerateResult generateResult = GeneratorMain.generate(shellConfig, injectorConfig, shellToolConfig);
|
||||
String packResult = request.getPacker().getPacker().pack(generateResult);
|
||||
return ResponseEntity.ok(new GenerateResponse(generateResult, packResult));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.reajason.javaweb.boot.controller;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
/**
|
||||
* @author ReaJason
|
||||
* @since 2024/12/19
|
||||
*/
|
||||
@Controller
|
||||
public class ViewController {
|
||||
@GetMapping("/")
|
||||
public String index() {
|
||||
return "index";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.reajason.javaweb.boot.dto;
|
||||
|
||||
import com.reajason.javaweb.config.*;
|
||||
import com.reajason.javaweb.memsell.packer.Packer;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author ReaJason
|
||||
* @since 2024/12/18
|
||||
*/
|
||||
@Data
|
||||
public class GenerateRequest {
|
||||
private ShellConfig shellConfig;
|
||||
private ShellToolConfigDTO shellToolConfig;
|
||||
private InjectorConfig injectorConfig;
|
||||
private Packer.INSTANCE packer;
|
||||
|
||||
public ShellToolConfig parseShellToolConfig() {
|
||||
if (shellConfig.getShellTool().equals(ShellTool.Godzilla)) {
|
||||
return GodzillaConfig.builder()
|
||||
.shellClassName(shellToolConfig.getShellClassName())
|
||||
.pass(shellToolConfig.getGodzillaPass())
|
||||
.key(shellToolConfig.getGodzillaKey())
|
||||
.headerName(shellToolConfig.getGodzillaHeaderName())
|
||||
.headerValue(shellToolConfig.getGodzillaHeaderValue())
|
||||
.build();
|
||||
}
|
||||
if (shellConfig.getShellTool().equals(ShellTool.Command)) {
|
||||
return CommandConfig.builder()
|
||||
.shellClassName(shellToolConfig.getShellClassName())
|
||||
.paramName(shellToolConfig.getCommandParamName())
|
||||
.build();
|
||||
}
|
||||
throw new UnsupportedOperationException("unknown shell tool " + shellConfig.getShellTool());
|
||||
}
|
||||
|
||||
@Data
|
||||
static class ShellToolConfigDTO {
|
||||
private String shellClassName;
|
||||
private String godzillaPass;
|
||||
private String godzillaKey;
|
||||
private String godzillaHeaderName;
|
||||
private String godzillaHeaderValue;
|
||||
private String commandParamName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.reajason.javaweb.boot.dto;
|
||||
|
||||
import com.reajason.javaweb.config.GenerateResult;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author ReaJason
|
||||
* @since 2024/12/18
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class GenerateResponse {
|
||||
private GenerateResult generateResult;
|
||||
private String packResult;
|
||||
}
|
||||
@@ -13,5 +13,5 @@ import java.util.Map;
|
||||
public class Config {
|
||||
private List<String> servers;
|
||||
private Map<String, Map<?, ?>> core;
|
||||
private Map<String, Map<?, ?>> packer;
|
||||
private Map<String, String> packers;
|
||||
}
|
||||
Reference in New Issue
Block a user