mirror of
https://github.com/dromara/RuoYi-Vue-Plus.git
synced 2026-05-08 18:54:27 +08:00
fix 修复 前端输入性CVE漏洞 禁止使用代码生成到本地路径
This commit is contained in:
@@ -172,20 +172,6 @@ public class GenController extends BaseController {
|
|||||||
genCode(response, data);
|
genCode(response, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成代码(自定义路径)
|
|
||||||
*
|
|
||||||
* @param tableId 表ID
|
|
||||||
* @return 操作结果
|
|
||||||
*/
|
|
||||||
@SaCheckPermission("tool:gen:code")
|
|
||||||
@Log(title = "代码生成", businessType = BusinessType.GENCODE)
|
|
||||||
@GetMapping("/genCode/{tableId}")
|
|
||||||
public R<Void> genCode(@PathVariable("tableId") Long tableId) {
|
|
||||||
genTableService.generatorCode(tableId);
|
|
||||||
return R.ok();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 同步数据库
|
* 同步数据库
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package org.dromara.gen.domain;
|
package org.dromara.gen.domain;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.FieldStrategy;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
@@ -92,17 +91,6 @@ public class GenTable extends BaseEntity {
|
|||||||
@NotBlank(message = "作者不能为空")
|
@NotBlank(message = "作者不能为空")
|
||||||
private String functionAuthor;
|
private String functionAuthor;
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成代码方式(0zip压缩包 1自定义路径)
|
|
||||||
*/
|
|
||||||
private String genType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成路径(不填默认项目路径)
|
|
||||||
*/
|
|
||||||
@TableField(updateStrategy = FieldStrategy.NOT_EMPTY)
|
|
||||||
private String genPath;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 主键信息
|
* 主键信息
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import org.dromara.common.core.exception.ServiceException;
|
|||||||
import org.dromara.common.core.utils.SpringUtils;
|
import org.dromara.common.core.utils.SpringUtils;
|
||||||
import org.dromara.common.core.utils.StreamUtils;
|
import org.dromara.common.core.utils.StreamUtils;
|
||||||
import org.dromara.common.core.utils.StringUtils;
|
import org.dromara.common.core.utils.StringUtils;
|
||||||
import org.dromara.common.core.utils.file.FileUtils;
|
|
||||||
import org.dromara.common.json.utils.JsonUtils;
|
import org.dromara.common.json.utils.JsonUtils;
|
||||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||||
import org.dromara.common.mybatis.utils.IdGeneratorUtil;
|
import org.dromara.common.mybatis.utils.IdGeneratorUtil;
|
||||||
@@ -38,7 +37,6 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -341,39 +339,11 @@ public class GenTableServiceImpl implements IGenTableService {
|
|||||||
public byte[] downloadCode(Long tableId) {
|
public byte[] downloadCode(Long tableId) {
|
||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
ZipOutputStream zip = new ZipOutputStream(outputStream);
|
ZipOutputStream zip = new ZipOutputStream(outputStream);
|
||||||
generatorCode(tableId, zip);
|
writeCodeToZip(tableId, zip);
|
||||||
IoUtil.close(zip);
|
IoUtil.close(zip);
|
||||||
return outputStream.toByteArray();
|
return outputStream.toByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成代码(自定义路径)
|
|
||||||
*
|
|
||||||
* @param tableId 表名称
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void generatorCode(Long tableId) {
|
|
||||||
// 查询表信息
|
|
||||||
GenTable table = getGenTable(tableId);
|
|
||||||
// 设置主键列信息
|
|
||||||
setPkColumn(table);
|
|
||||||
|
|
||||||
Dict context = TemplateEngineUtils.buildContext(table);
|
|
||||||
// 获取模板列表
|
|
||||||
List<PathNamedTemplate> templates = TemplateEngineUtils.getTemplateList(table.getTplCategory(), table.getDataName());
|
|
||||||
for (PathNamedTemplate template : templates) {
|
|
||||||
String pathName = template.getPathName();
|
|
||||||
try {
|
|
||||||
String render = template.render(context);
|
|
||||||
String path = getGenPath(table, pathName);
|
|
||||||
FileUtils.writeUtf8String(render, path);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("渲染模板失败,表名:{},模板:{}", table.getTableName(), pathName, e);
|
|
||||||
throw new ServiceException("渲染模板失败,表名:" + table.getTableName() + ",模板:" + pathName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 同步数据库
|
* 同步数据库
|
||||||
*
|
*
|
||||||
@@ -437,7 +407,7 @@ public class GenTableServiceImpl implements IGenTableService {
|
|||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
ZipOutputStream zip = new ZipOutputStream(outputStream);
|
ZipOutputStream zip = new ZipOutputStream(outputStream);
|
||||||
for (String tableId : tableIds) {
|
for (String tableId : tableIds) {
|
||||||
generatorCode(Long.parseLong(tableId), zip);
|
writeCodeToZip(Long.parseLong(tableId), zip);
|
||||||
}
|
}
|
||||||
IoUtil.close(zip);
|
IoUtil.close(zip);
|
||||||
return outputStream.toByteArray();
|
return outputStream.toByteArray();
|
||||||
@@ -449,7 +419,7 @@ public class GenTableServiceImpl implements IGenTableService {
|
|||||||
* @param tableId 业务表主键
|
* @param tableId 业务表主键
|
||||||
* @param zip 代码压缩输出流
|
* @param zip 代码压缩输出流
|
||||||
*/
|
*/
|
||||||
private void generatorCode(Long tableId, ZipOutputStream zip) {
|
private void writeCodeToZip(Long tableId, ZipOutputStream zip) {
|
||||||
RenderContext rc = buildRenderContext(tableId);
|
RenderContext rc = buildRenderContext(tableId);
|
||||||
GenTable table = rc.table();
|
GenTable table = rc.table();
|
||||||
for (PathNamedTemplate template : rc.templates()) {
|
for (PathNamedTemplate template : rc.templates()) {
|
||||||
@@ -653,20 +623,5 @@ public class GenTableServiceImpl implements IGenTableService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取代码生成地址
|
|
||||||
*
|
|
||||||
* @param table 业务表信息
|
|
||||||
* @param template 模板文件路径
|
|
||||||
* @return 生成地址
|
|
||||||
*/
|
|
||||||
public static String getGenPath(GenTable table, String template) {
|
|
||||||
String relativePath = StringUtils.replace(TemplateEngineUtils.getFileName(template, table), "/", File.separator);
|
|
||||||
String genPath = table.getGenPath();
|
|
||||||
if (StringUtils.equals(genPath, "/")) {
|
|
||||||
return System.getProperty("user.dir") + File.separator + "src" + File.separator + relativePath;
|
|
||||||
}
|
|
||||||
return genPath + File.separator + relativePath;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -105,13 +105,6 @@ public interface IGenTableService {
|
|||||||
*/
|
*/
|
||||||
byte[] downloadCode(Long tableId);
|
byte[] downloadCode(Long tableId);
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成代码(自定义路径)
|
|
||||||
*
|
|
||||||
* @param tableId 表名称
|
|
||||||
*/
|
|
||||||
void generatorCode(Long tableId);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 同步数据库
|
* 同步数据库
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user