iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/common/enums/CommonConstant.java
对比新文件 @@ -0,0 +1,18 @@ package com.iailab.module.model.common.enums; import java.math.BigDecimal; /** * @Description: 通用常量 */ public interface CommonConstant { int IS_ENABLE = 1; BigDecimal BAD_VALUE = new BigDecimal("-2"); BigDecimal ZERO_VALUE = new BigDecimal("0"); String HTTP_API_ZXZK_IH = "ZXZK_IH"; } iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/common/enums/CommonDict.java
对比新文件 @@ -0,0 +1,13 @@ package com.iailab.module.model.common.enums; /** * @author PanZhibao * @Description * @createTime 2022年06月26日 12:12:00 */ public class CommonDict { public static final Integer ONE = 1; public static final Integer TOW = 2; } iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/common/enums/DataSourceType.java
对比新文件 @@ -0,0 +1,35 @@ package com.iailab.module.model.common.enums; import lombok.AllArgsConstructor; import lombok.Getter; /** * @author PanZhibao * @Description * @createTime 2024年05月12日 */ @Getter @AllArgsConstructor public enum DataSourceType { OPCUA("OPCUA", "OPC UA"), OPCDA("OPCDA", "OPC DA"), ModBus("ModBus", "ModBus"), KIO("KIO", "KIO"), HTTP("HTTP", "HTTP"); private String code; private String desc; public static DataSourceType getEumByCode(String code) { if (code == null) { return null; } for (DataSourceType statusEnum : DataSourceType.values()) { if (statusEnum.getCode().equals(code)) { return statusEnum; } } return null; } } iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/common/enums/DataTypeEnum.java
对比新文件 @@ -0,0 +1,22 @@ package com.iailab.module.model.common.enums; import lombok.AllArgsConstructor; import lombok.Getter; /** * @author PanZhibao * @Description * @createTime 2023年05月03日 19:10:00 */ @Getter @AllArgsConstructor public enum DataTypeEnum { INT("int"), FLOAT("float"), BOOLEAN("boolean"); private String code; } iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/common/enums/DatabaseType.java
对比新文件 @@ -0,0 +1,9 @@ package com.iailab.module.model.common.enums; /** * @author PanZhibao * @date 2021年09月01日 15:06 */ public enum DatabaseType { DB2, MY_SQL, SQL_SERVER } iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/common/enums/IsEnableEnum.java
对比新文件 @@ -0,0 +1,21 @@ package com.iailab.module.model.common.enums; /** * @author PanZhibao * @Description * @createTime 2023年07月17日 17:41:00 */ public enum IsEnableEnum { DISABLE(0), // 手动 ENABLE(1); //自动 private Integer value; IsEnableEnum(Integer value) { this.value = value; } public Integer value() { return this.value; } } iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/common/enums/JsErrorCode.java
对比新文件 @@ -0,0 +1,10 @@ package com.iailab.module.model.common.enums; /** * @author PanZhibao * @Description * @createTime 2022年03月28日 17:46:00 */ public enum JsErrorCode { Infinity, NaN } iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/common/enums/RequestMethodType.java
对比新文件 @@ -0,0 +1,18 @@ package com.iailab.module.model.common.enums; /** * @author PanZhibao * @date 2021年08月17日 11:28 */ public enum RequestMethodType { /** * GET */ GET, /** * POST */ POST } iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/common/enums/RowAction.java
对比新文件 @@ -0,0 +1,15 @@ package com.iailab.module.model.common.enums; /** * @author PanZhibao * @Description * @createTime 2022年06月25日 10:48:00 */ public class RowAction { public static final String ADD = "add"; public static final String UPDATE = "update"; public static final String DELETE = "delete"; } iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/common/enums/TagValueTypeConstant.java
对比新文件 @@ -0,0 +1,35 @@ package com.iailab.module.model.common.enums; /** * @author PanZhibao * @Description * @createTime 2023年04月25日 15:43:00 */ public class TagValueTypeConstant { public static final String QUALITY_GOOD = "Good"; public static final String BOOLEAN = "Boolean"; public static final String INT8 = "Int8"; public static final String INT16 = "Int16"; public static final String INT32 = "Int32"; public static final String INT64 = "Int64"; public static final String UINT8 = "UInt8"; public static final String UINT16 = "UInt16"; public static final String UINT32 = "UInt32"; public static final String UINT64 = "UInt64"; public static final String FLOAT = "Float"; public static final String DOUBLE = "Double"; public static final String STRING = "String"; } iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/common/exception/RRException.java
对比新文件 @@ -0,0 +1,53 @@ package com.iailab.module.model.common.exception; /** * 自定义异常 * * @author Mark sunlightcs@gmail.com */ public class RRException extends RuntimeException { private static final long serialVersionUID = 1L; private String msg; private int code = 500; public RRException(String msg) { super(msg); this.msg = msg; } public RRException(String msg, Throwable e) { super(msg, e); this.msg = msg; } public RRException(String msg, int code) { super(msg); this.msg = msg; this.code = code; } public RRException(String msg, int code, Throwable e) { super(msg, e); this.msg = msg; this.code = code; } public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } public int getCode() { return code; } public void setCode(int code) { this.code = code; } } iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/common/exception/RRExceptionHandler.java
对比新文件 @@ -0,0 +1,56 @@ package com.iailab.module.model.common.exception;//package com.iailab.module.data.common.exception; // //import com.iailab.module.data.common.utils.R; //import org.apache.shiro.authz.AuthorizationException; //import org.slf4j.Logger; //import org.slf4j.LoggerFactory; //import org.springframework.dao.DuplicateKeyException; //import org.springframework.web.bind.annotation.ExceptionHandler; //import org.springframework.web.bind.annotation.RestControllerAdvice; //import org.springframework.web.servlet.NoHandlerFoundException; // ///** // * 异常处理器 // * // * @author Mark sunlightcs@gmail.com // */ //@RestControllerAdvice //public class RRExceptionHandler { // private Logger logger = LoggerFactory.getLogger(getClass()); // // /** // * 处理自定义异常 // */ // @ExceptionHandler(RRException.class) // public R handleRRException(RRException e){ // R r = new R(); // r.put("code", e.getCode()); // r.put("msg", e.getMessage()); // // return r; // } // // @ExceptionHandler(NoHandlerFoundException.class) // public R handlerNoFoundException(Exception e) { // logger.error(e.getMessage(), e); // return R.error(404, "路径不存在,请检查路径是否正确"); // } // // @ExceptionHandler(DuplicateKeyException.class) // public R handleDuplicateKeyException(DuplicateKeyException e){ // logger.error(e.getMessage(), e); // return R.error("数据库中已存在该记录"); // } // // @ExceptionHandler(AuthorizationException.class) // public R handleAuthorizationException(AuthorizationException e){ // logger.error(e.getMessage(), e); // return R.error("没有权限,请联系管理员授权"); // } // // @ExceptionHandler(Exception.class) // public R handleException(Exception e){ // logger.error(e.getMessage(), e); // return R.error(); // } //} iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/common/interceptor/DataFilterInterceptor.java
对比新文件 @@ -0,0 +1,81 @@ package com.iailab.module.model.common.interceptor; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.toolkit.PluginUtils; import com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor; import net.sf.jsqlparser.JSQLParserException; import net.sf.jsqlparser.expression.Expression; import net.sf.jsqlparser.expression.StringValue; import net.sf.jsqlparser.expression.operators.conditional.AndExpression; import net.sf.jsqlparser.parser.CCJSqlParserUtil; import net.sf.jsqlparser.statement.select.PlainSelect; import net.sf.jsqlparser.statement.select.Select; import org.apache.ibatis.executor.Executor; import org.apache.ibatis.mapping.BoundSql; import org.apache.ibatis.mapping.MappedStatement; import org.apache.ibatis.session.ResultHandler; import org.apache.ibatis.session.RowBounds; import java.util.Map; /** * 数据过滤 * * @author Mark sunlightcs@gmail.com */ public class DataFilterInterceptor implements InnerInterceptor { @Override public void beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) { DataScope scope = getDataScope(parameter); // 不进行数据过滤 if(scope == null || StrUtil.isBlank(scope.getSqlFilter())){ return; } // 拼接新SQL String buildSql = getSelect(boundSql.getSql(), scope); // 重写SQL PluginUtils.mpBoundSql(boundSql).sql(buildSql); } private DataScope getDataScope(Object parameter){ if (parameter == null){ return null; } // 判断参数里是否有DataScope对象 if (parameter instanceof Map) { Map<?, ?> parameterMap = (Map<?, ?>) parameter; for (Map.Entry entry : parameterMap.entrySet()) { if (entry.getValue() != null && entry.getValue() instanceof DataScope) { return (DataScope) entry.getValue(); } } } else if (parameter instanceof DataScope) { return (DataScope) parameter; } return null; } private String getSelect(String buildSql, DataScope scope){ try { Select select = (Select) CCJSqlParserUtil.parse(buildSql); PlainSelect plainSelect = (PlainSelect) select.getSelectBody(); Expression expression = plainSelect.getWhere(); if(expression == null){ plainSelect.setWhere(new StringValue(scope.getSqlFilter())); }else{ AndExpression andExpression = new AndExpression(expression, new StringValue(scope.getSqlFilter())); plainSelect.setWhere(andExpression); } return select.toString().replaceAll("'", ""); }catch (JSQLParserException e){ return buildSql; } } } iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/common/interceptor/DataScope.java
对比新文件 @@ -0,0 +1,28 @@ package com.iailab.module.model.common.interceptor; /** * 数据范围 * * @author Mark sunlightcs@gmail.com * @since 1.0.0 */ public class DataScope { private String sqlFilter; public DataScope(String sqlFilter) { this.sqlFilter = sqlFilter; } public String getSqlFilter() { return sqlFilter; } public void setSqlFilter(String sqlFilter) { this.sqlFilter = sqlFilter; } @Override public String toString() { return this.sqlFilter; } } iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/common/xss/HTMLFilter.java
对比新文件 @@ -0,0 +1,530 @@ package com.iailab.module.model.common.xss; import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * * HTML filtering utility for protecting against XSS (Cross Site Scripting). * * This code is licensed LGPLv3 * * This code is a Java port of the original work in PHP by Cal Hendersen. * http://code.iamcal.com/php/lib_filter/ * * The trickiest part of the translation was handling the differences in regex handling * between PHP and Java. These resources were helpful in the process: * * http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html * http://us2.php.net/manual/en/reference.pcre.pattern.modifiers.php * http://www.regular-expressions.info/modifiers.html * * A note on naming conventions: instance variables are prefixed with a "v"; global * constants are in all caps. * * Sample use: * String input = ... * String clean = new HTMLFilter().filter( input ); * * The class is not thread safe. Create a new instance if in doubt. * * If you find bugs or have suggestions on improvement (especially regarding * performance), please contact us. The latest version of this * source, and our contact details, can be found at http://xss-html-filter.sf.net * * @author Joseph O'Connell * @author Cal Hendersen * @author Michael Semb Wever */ public final class HTMLFilter { /** regex flag union representing /si modifiers in php **/ private static final int REGEX_FLAGS_SI = Pattern.CASE_INSENSITIVE | Pattern.DOTALL; private static final Pattern P_COMMENTS = Pattern.compile("<!--(.*?)-->", Pattern.DOTALL); private static final Pattern P_COMMENT = Pattern.compile("^!--(.*)--$", REGEX_FLAGS_SI); private static final Pattern P_TAGS = Pattern.compile("<(.*?)>", Pattern.DOTALL); private static final Pattern P_END_TAG = Pattern.compile("^/([a-z0-9]+)", REGEX_FLAGS_SI); private static final Pattern P_START_TAG = Pattern.compile("^([a-z0-9]+)(.*?)(/?)$", REGEX_FLAGS_SI); private static final Pattern P_QUOTED_ATTRIBUTES = Pattern.compile("([a-z0-9]+)=([\"'])(.*?)\\2", REGEX_FLAGS_SI); private static final Pattern P_UNQUOTED_ATTRIBUTES = Pattern.compile("([a-z0-9]+)(=)([^\"\\s']+)", REGEX_FLAGS_SI); private static final Pattern P_PROTOCOL = Pattern.compile("^([^:]+):", REGEX_FLAGS_SI); private static final Pattern P_ENTITY = Pattern.compile("&#(\\d+);?"); private static final Pattern P_ENTITY_UNICODE = Pattern.compile("&#x([0-9a-f]+);?"); private static final Pattern P_ENCODE = Pattern.compile("%([0-9a-f]{2});?"); private static final Pattern P_VALID_ENTITIES = Pattern.compile("&([^&;]*)(?=(;|&|$))"); private static final Pattern P_VALID_QUOTES = Pattern.compile("(>|^)([^<]+?)(<|$)", Pattern.DOTALL); private static final Pattern P_END_ARROW = Pattern.compile("^>"); private static final Pattern P_BODY_TO_END = Pattern.compile("<([^>]*?)(?=<|$)"); private static final Pattern P_XML_CONTENT = Pattern.compile("(^|>)([^<]*?)(?=>)"); private static final Pattern P_STRAY_LEFT_ARROW = Pattern.compile("<([^>]*?)(?=<|$)"); private static final Pattern P_STRAY_RIGHT_ARROW = Pattern.compile("(^|>)([^<]*?)(?=>)"); private static final Pattern P_AMP = Pattern.compile("&"); private static final Pattern P_QUOTE = Pattern.compile("<"); private static final Pattern P_LEFT_ARROW = Pattern.compile("<"); private static final Pattern P_RIGHT_ARROW = Pattern.compile(">"); private static final Pattern P_BOTH_ARROWS = Pattern.compile("<>"); // @xxx could grow large... maybe use sesat's ReferenceMap private static final ConcurrentMap<String,Pattern> P_REMOVE_PAIR_BLANKS = new ConcurrentHashMap<String, Pattern>(); private static final ConcurrentMap<String,Pattern> P_REMOVE_SELF_BLANKS = new ConcurrentHashMap<String, Pattern>(); /** set of allowed html elements, along with allowed attributes for each element **/ private final Map<String, List<String>> vAllowed; /** counts of open tags for each (allowable) html element **/ private final Map<String, Integer> vTagCounts = new HashMap<String, Integer>(); /** html elements which must always be self-closing (e.g. "<img />") **/ private final String[] vSelfClosingTags; /** html elements which must always have separate opening and closing tags (e.g. "<b></b>") **/ private final String[] vNeedClosingTags; /** set of disallowed html elements **/ private final String[] vDisallowed; /** attributes which should be checked for valid protocols **/ private final String[] vProtocolAtts; /** allowed protocols **/ private final String[] vAllowedProtocols; /** tags which should be removed if they contain no content (e.g. "<b></b>" or "<b />") **/ private final String[] vRemoveBlanks; /** entities allowed within html markup **/ private final String[] vAllowedEntities; /** flag determining whether comments are allowed in input String. */ private final boolean stripComment; private final boolean encodeQuotes; private boolean vDebug = false; /** * flag determining whether to try to make tags when presented with "unbalanced" * angle brackets (e.g. "<b text </b>" becomes "<b> text </b>"). If set to false, * unbalanced angle brackets will be html escaped. */ private final boolean alwaysMakeTags; /** Default constructor. * */ public HTMLFilter() { vAllowed = new HashMap<>(); final ArrayList<String> a_atts = new ArrayList<String>(); a_atts.add("href"); a_atts.add("target"); vAllowed.put("a", a_atts); final ArrayList<String> img_atts = new ArrayList<String>(); img_atts.add("src"); img_atts.add("width"); img_atts.add("height"); img_atts.add("alt"); vAllowed.put("img", img_atts); final ArrayList<String> no_atts = new ArrayList<String>(); vAllowed.put("b", no_atts); vAllowed.put("strong", no_atts); vAllowed.put("i", no_atts); vAllowed.put("em", no_atts); vSelfClosingTags = new String[]{"img"}; vNeedClosingTags = new String[]{"a", "b", "strong", "i", "em"}; vDisallowed = new String[]{}; vAllowedProtocols = new String[]{"http", "mailto", "https"}; // no ftp. vProtocolAtts = new String[]{"src", "href"}; vRemoveBlanks = new String[]{"a", "b", "strong", "i", "em"}; vAllowedEntities = new String[]{"amp", "gt", "lt", "quot"}; stripComment = true; encodeQuotes = true; alwaysMakeTags = true; } /** Set debug flag to true. Otherwise use default settings. See the default constructor. * * @param debug turn debug on with a true argument */ public HTMLFilter(final boolean debug) { this(); vDebug = debug; } /** Map-parameter configurable constructor. * * @param conf map containing configuration. keys match field names. */ public HTMLFilter(final Map<String,Object> conf) { assert conf.containsKey("vAllowed") : "configuration requires vAllowed"; assert conf.containsKey("vSelfClosingTags") : "configuration requires vSelfClosingTags"; assert conf.containsKey("vNeedClosingTags") : "configuration requires vNeedClosingTags"; assert conf.containsKey("vDisallowed") : "configuration requires vDisallowed"; assert conf.containsKey("vAllowedProtocols") : "configuration requires vAllowedProtocols"; assert conf.containsKey("vProtocolAtts") : "configuration requires vProtocolAtts"; assert conf.containsKey("vRemoveBlanks") : "configuration requires vRemoveBlanks"; assert conf.containsKey("vAllowedEntities") : "configuration requires vAllowedEntities"; vAllowed = Collections.unmodifiableMap((HashMap<String, List<String>>) conf.get("vAllowed")); vSelfClosingTags = (String[]) conf.get("vSelfClosingTags"); vNeedClosingTags = (String[]) conf.get("vNeedClosingTags"); vDisallowed = (String[]) conf.get("vDisallowed"); vAllowedProtocols = (String[]) conf.get("vAllowedProtocols"); vProtocolAtts = (String[]) conf.get("vProtocolAtts"); vRemoveBlanks = (String[]) conf.get("vRemoveBlanks"); vAllowedEntities = (String[]) conf.get("vAllowedEntities"); stripComment = conf.containsKey("stripComment") ? (Boolean) conf.get("stripComment") : true; encodeQuotes = conf.containsKey("encodeQuotes") ? (Boolean) conf.get("encodeQuotes") : true; alwaysMakeTags = conf.containsKey("alwaysMakeTags") ? (Boolean) conf.get("alwaysMakeTags") : true; } private void reset() { vTagCounts.clear(); } private void debug(final String msg) { if (vDebug) { Logger.getAnonymousLogger().info(msg); } } //--------------------------------------------------------------- // my versions of some PHP library functions public static String chr(final int decimal) { return String.valueOf((char) decimal); } public static String htmlSpecialChars(final String s) { String result = s; result = regexReplace(P_AMP, "&", result); result = regexReplace(P_QUOTE, """, result); result = regexReplace(P_LEFT_ARROW, "<", result); result = regexReplace(P_RIGHT_ARROW, ">", result); return result; } //--------------------------------------------------------------- /** * given a user submitted input String, filter out any invalid or restricted * html. * * @param input text (i.e. submitted by a user) than may contain html * @return "clean" version of input, with only valid, whitelisted html elements allowed */ public String filter(final String input) { reset(); String s = input; debug("************************************************"); debug(" INPUT: " + input); s = escapeComments(s); debug(" escapeComments: " + s); s = balanceHTML(s); debug(" balanceHTML: " + s); s = checkTags(s); debug(" checkTags: " + s); s = processRemoveBlanks(s); debug("processRemoveBlanks: " + s); s = validateEntities(s); debug(" validateEntites: " + s); debug("************************************************\n\n"); return s; } public boolean isAlwaysMakeTags(){ return alwaysMakeTags; } public boolean isStripComments(){ return stripComment; } private String escapeComments(final String s) { final Matcher m = P_COMMENTS.matcher(s); final StringBuffer buf = new StringBuffer(); if (m.find()) { final String match = m.group(1); //(.*?) m.appendReplacement(buf, Matcher.quoteReplacement("<!--" + htmlSpecialChars(match) + "-->")); } m.appendTail(buf); return buf.toString(); } private String balanceHTML(String s) { if (alwaysMakeTags) { // // try and form html // s = regexReplace(P_END_ARROW, "", s); s = regexReplace(P_BODY_TO_END, "<$1>", s); s = regexReplace(P_XML_CONTENT, "$1<$2", s); } else { // // escape stray brackets // s = regexReplace(P_STRAY_LEFT_ARROW, "<$1", s); s = regexReplace(P_STRAY_RIGHT_ARROW, "$1$2><", s); // // the last regexp causes '<>' entities to appear // (we need to do a lookahead assertion so that the last bracket can // be used in the next pass of the regexp) // s = regexReplace(P_BOTH_ARROWS, "", s); } return s; } private String checkTags(String s) { Matcher m = P_TAGS.matcher(s); final StringBuffer buf = new StringBuffer(); while (m.find()) { String replaceStr = m.group(1); replaceStr = processTag(replaceStr); m.appendReplacement(buf, Matcher.quoteReplacement(replaceStr)); } m.appendTail(buf); s = buf.toString(); // these get tallied in processTag // (remember to reset before subsequent calls to filter method) for (String key : vTagCounts.keySet()) { for (int ii = 0; ii < vTagCounts.get(key); ii++) { s += "</" + key + ">"; } } return s; } private String processRemoveBlanks(final String s) { String result = s; for (String tag : vRemoveBlanks) { if(!P_REMOVE_PAIR_BLANKS.containsKey(tag)){ P_REMOVE_PAIR_BLANKS.putIfAbsent(tag, Pattern.compile("<" + tag + "(\\s[^>]*)?></" + tag + ">")); } result = regexReplace(P_REMOVE_PAIR_BLANKS.get(tag), "", result); if(!P_REMOVE_SELF_BLANKS.containsKey(tag)){ P_REMOVE_SELF_BLANKS.putIfAbsent(tag, Pattern.compile("<" + tag + "(\\s[^>]*)?/>")); } result = regexReplace(P_REMOVE_SELF_BLANKS.get(tag), "", result); } return result; } private static String regexReplace(final Pattern regex_pattern, final String replacement, final String s) { Matcher m = regex_pattern.matcher(s); return m.replaceAll(replacement); } private String processTag(final String s) { // ending tags Matcher m = P_END_TAG.matcher(s); if (m.find()) { final String name = m.group(1).toLowerCase(); if (allowed(name)) { if (!inArray(name, vSelfClosingTags)) { if (vTagCounts.containsKey(name)) { vTagCounts.put(name, vTagCounts.get(name) - 1); return "</" + name + ">"; } } } } // starting tags m = P_START_TAG.matcher(s); if (m.find()) { final String name = m.group(1).toLowerCase(); final String body = m.group(2); String ending = m.group(3); //debug( "in a starting tag, name='" + name + "'; body='" + body + "'; ending='" + ending + "'" ); if (allowed(name)) { String params = ""; final Matcher m2 = P_QUOTED_ATTRIBUTES.matcher(body); final Matcher m3 = P_UNQUOTED_ATTRIBUTES.matcher(body); final List<String> paramNames = new ArrayList<String>(); final List<String> paramValues = new ArrayList<String>(); while (m2.find()) { paramNames.add(m2.group(1)); //([a-z0-9]+) paramValues.add(m2.group(3)); //(.*?) } while (m3.find()) { paramNames.add(m3.group(1)); //([a-z0-9]+) paramValues.add(m3.group(3)); //([^\"\\s']+) } String paramName, paramValue; for (int ii = 0; ii < paramNames.size(); ii++) { paramName = paramNames.get(ii).toLowerCase(); paramValue = paramValues.get(ii); // debug( "paramName='" + paramName + "'" ); // debug( "paramValue='" + paramValue + "'" ); // debug( "allowed? " + vAllowed.get( name ).contains( paramName ) ); if (allowedAttribute(name, paramName)) { if (inArray(paramName, vProtocolAtts)) { paramValue = processParamProtocol(paramValue); } params += " " + paramName + "=\"" + paramValue + "\""; } } if (inArray(name, vSelfClosingTags)) { ending = " /"; } if (inArray(name, vNeedClosingTags)) { ending = ""; } if (ending == null || ending.length() < 1) { if (vTagCounts.containsKey(name)) { vTagCounts.put(name, vTagCounts.get(name) + 1); } else { vTagCounts.put(name, 1); } } else { ending = " /"; } return "<" + name + params + ending + ">"; } else { return ""; } } // comments m = P_COMMENT.matcher(s); if (!stripComment && m.find()) { return "<" + m.group() + ">"; } return ""; } private String processParamProtocol(String s) { s = decodeEntities(s); final Matcher m = P_PROTOCOL.matcher(s); if (m.find()) { final String protocol = m.group(1); if (!inArray(protocol, vAllowedProtocols)) { // bad protocol, turn into local anchor link instead s = "#" + s.substring(protocol.length() + 1, s.length()); if (s.startsWith("#//")) { s = "#" + s.substring(3, s.length()); } } } return s; } private String decodeEntities(String s) { StringBuffer buf = new StringBuffer(); Matcher m = P_ENTITY.matcher(s); while (m.find()) { final String match = m.group(1); final int decimal = Integer.decode(match).intValue(); m.appendReplacement(buf, Matcher.quoteReplacement(chr(decimal))); } m.appendTail(buf); s = buf.toString(); buf = new StringBuffer(); m = P_ENTITY_UNICODE.matcher(s); while (m.find()) { final String match = m.group(1); final int decimal = Integer.valueOf(match, 16).intValue(); m.appendReplacement(buf, Matcher.quoteReplacement(chr(decimal))); } m.appendTail(buf); s = buf.toString(); buf = new StringBuffer(); m = P_ENCODE.matcher(s); while (m.find()) { final String match = m.group(1); final int decimal = Integer.valueOf(match, 16).intValue(); m.appendReplacement(buf, Matcher.quoteReplacement(chr(decimal))); } m.appendTail(buf); s = buf.toString(); s = validateEntities(s); return s; } private String validateEntities(final String s) { StringBuffer buf = new StringBuffer(); // validate entities throughout the string Matcher m = P_VALID_ENTITIES.matcher(s); while (m.find()) { final String one = m.group(1); //([^&;]*) final String two = m.group(2); //(?=(;|&|$)) m.appendReplacement(buf, Matcher.quoteReplacement(checkEntity(one, two))); } m.appendTail(buf); return encodeQuotes(buf.toString()); } private String encodeQuotes(final String s){ if(encodeQuotes){ StringBuffer buf = new StringBuffer(); Matcher m = P_VALID_QUOTES.matcher(s); while (m.find()) { final String one = m.group(1); //(>|^) final String two = m.group(2); //([^<]+?) final String three = m.group(3); //(<|$) m.appendReplacement(buf, Matcher.quoteReplacement(one + regexReplace(P_QUOTE, """, two) + three)); } m.appendTail(buf); return buf.toString(); }else{ return s; } } private String checkEntity(final String preamble, final String term) { return ";".equals(term) && isValidEntity(preamble) ? '&' + preamble : "&" + preamble; } private boolean isValidEntity(final String entity) { return inArray(entity, vAllowedEntities); } private static boolean inArray(final String s, final String[] array) { for (String item : array) { if (item != null && item.equals(s)) { return true; } } return false; } private boolean allowed(final String name) { return (vAllowed.isEmpty() || vAllowed.containsKey(name)) && !inArray(name, vDisallowed); } private boolean allowedAttribute(final String name, final String paramName) { return allowed(name) && (vAllowed.isEmpty() || vAllowed.get(name).contains(paramName)); } } iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/common/xss/SQLFilter.java
对比新文件 @@ -0,0 +1,42 @@ package com.iailab.module.model.common.xss; import com.iailab.module.model.common.exception.RRException; import org.apache.commons.lang3.StringUtils; /** * SQL过滤 * * @author Mark sunlightcs@gmail.com */ public class SQLFilter { /** * SQL注入过滤 * @param str 待验证的字符串 */ public static String sqlInject(String str){ if(StringUtils.isBlank(str)){ return null; } //去掉'|"|;|\字符 str = StringUtils.replace(str, "'", ""); str = StringUtils.replace(str, "\"", ""); str = StringUtils.replace(str, ";", ""); str = StringUtils.replace(str, "\\", ""); //转换成小写 str = str.toLowerCase(); //非法字符 String[] keywords = {"master", "truncate", "insert", "select", "delete", "update", "declare", "alter", "drop"}; //判断是否包含非法字符 for(String keyword : keywords){ if(str.indexOf(keyword) != -1){ throw new RRException("包含非法字符"); } } return str; } } iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/common/xss/XssFilter.java
对比新文件 @@ -0,0 +1,29 @@ package com.iailab.module.model.common.xss; import javax.servlet.*; import javax.servlet.http.HttpServletRequest; import java.io.IOException; /** * XSS过滤 * * @author Mark sunlightcs@gmail.com */ public class XssFilter implements Filter { @Override public void init(FilterConfig config) throws ServletException { } public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { XssHttpServletRequestWrapper xssRequest = new XssHttpServletRequestWrapper( (HttpServletRequest) request); chain.doFilter(xssRequest, response); } @Override public void destroy() { } } iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/common/xss/XssHttpServletRequestWrapper.java
对比新文件 @@ -0,0 +1,139 @@ package com.iailab.module.model.common.xss; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import javax.servlet.ReadListener; import javax.servlet.ServletInputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequestWrapper; import java.io.ByteArrayInputStream; import java.io.IOException; import java.util.LinkedHashMap; import java.util.Map; /** * XSS过滤处理 * * @author Mark sunlightcs@gmail.com */ public class XssHttpServletRequestWrapper extends HttpServletRequestWrapper { //没被包装过的HttpServletRequest(特殊场景,需要自己过滤) HttpServletRequest orgRequest; //html过滤 private final static HTMLFilter htmlFilter = new HTMLFilter(); public XssHttpServletRequestWrapper(HttpServletRequest request) { super(request); orgRequest = request; } @Override public ServletInputStream getInputStream() throws IOException { //非json类型,直接返回 if(!MediaType.APPLICATION_JSON_VALUE.equalsIgnoreCase(super.getHeader(HttpHeaders.CONTENT_TYPE))){ return super.getInputStream(); } //为空,直接返回 String json = IOUtils.toString(super.getInputStream(), "utf-8"); if (StringUtils.isBlank(json)) { return super.getInputStream(); } //xss过滤 json = xssEncode(json); final ByteArrayInputStream bis = new ByteArrayInputStream(json.getBytes("utf-8")); return new ServletInputStream() { @Override public boolean isFinished() { return true; } @Override public boolean isReady() { return true; } @Override public void setReadListener(ReadListener readListener) { } @Override public int read() throws IOException { return bis.read(); } }; } @Override public String getParameter(String name) { String value = super.getParameter(xssEncode(name)); if (StringUtils.isNotBlank(value)) { value = xssEncode(value); } return value; } @Override public String[] getParameterValues(String name) { String[] parameters = super.getParameterValues(name); if (parameters == null || parameters.length == 0) { return null; } for (int i = 0; i < parameters.length; i++) { parameters[i] = xssEncode(parameters[i]); } return parameters; } @Override public Map<String,String[]> getParameterMap() { Map<String,String[]> map = new LinkedHashMap<>(); Map<String,String[]> parameters = super.getParameterMap(); for (String key : parameters.keySet()) { String[] values = parameters.get(key); for (int i = 0; i < values.length; i++) { values[i] = xssEncode(values[i]); } map.put(key, values); } return map; } @Override public String getHeader(String name) { String value = super.getHeader(xssEncode(name)); if (StringUtils.isNotBlank(value)) { value = xssEncode(value); } return value; } private String xssEncode(String input) { return htmlFilter.filter(input); } /** * 获取最原始的request */ public HttpServletRequest getOrgRequest() { return orgRequest; } /** * 获取最原始的request */ public static HttpServletRequest getOrgRequest(HttpServletRequest request) { if (request instanceof XssHttpServletRequestWrapper) { return ((XssHttpServletRequestWrapper) request).getOrgRequest(); } return request; } } iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/framework/rpc/config/RpcConfiguration.java
@@ -2,10 +2,11 @@ import com.iailab.module.data.api.point.DataPointApi; import com.iailab.module.infra.api.config.ConfigApi; import com.iailab.module.system.api.tenant.TenantApi; import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.context.annotation.Configuration; @Configuration(proxyBeanMethods = false) @EnableFeignClients(clients = {DataPointApi.class,ConfigApi.class}) @EnableFeignClients(clients = {DataPointApi.class, ConfigApi.class, TenantApi.class}) public class RpcConfiguration { } iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/sche/entity/StScheduleModelEntity.java
@@ -14,7 +14,7 @@ * @date 2021年07月19日 15:03 */ @Data @TableName("T_ST_SCHEDULE_MODEL") @TableName("t_st_schedule_model") public class StScheduleModelEntity extends BaseDO { private static final long serialVersionUID = 1L; iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/sche/service/StScheduleModelService.java
@@ -12,7 +12,7 @@ * @author PanZhibao * @date 2021年07月20日 14:13 */ public interface StScheduleModelService extends BaseService<StScheduleModelEntity> { public interface StScheduleModelService { PageResult<StScheduleModelEntity> page(StScheduleModelPageReqVO reqVO); iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/sche/service/impl/StScheduleModelServiceImpl.java
@@ -1,8 +1,8 @@ package com.iailab.module.model.mcs.sche.service.impl; import com.baomidou.dynamic.datasource.annotation.DSTransactional; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.iailab.framework.common.pojo.PageResult; import com.iailab.framework.common.service.impl.BaseServiceImpl; import com.iailab.framework.common.util.object.BeanUtils; import com.iailab.module.model.mcs.sche.dao.StScheduleModelDao; import com.iailab.module.model.mcs.sche.entity.StScheduleModelEntity; @@ -16,6 +16,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.List; import java.util.UUID; @@ -24,7 +25,10 @@ * @date 2021年07月20日 14:23 */ @Service public class StScheduleModelServiceImpl extends BaseServiceImpl<StScheduleModelDao, StScheduleModelEntity> implements StScheduleModelService { public class StScheduleModelServiceImpl implements StScheduleModelService { @Resource private StScheduleModelDao stScheduleModelDao; @Autowired private StScheduleModelParamService stScheduleModelParamService; @@ -34,43 +38,43 @@ @Override public PageResult<StScheduleModelEntity> page(StScheduleModelPageReqVO reqVO) { return baseDao.selectPage(reqVO); return stScheduleModelDao.selectPage(reqVO); } @Override public List<StScheduleModelEntity> list() { return baseDao.selectList(null); return stScheduleModelDao.selectList(null); } @Override @Transactional(rollbackFor = Exception.class) @DSTransactional(rollbackFor = Exception.class) public void create(StScheduleModelSaveReqVO reqVO) { StScheduleModelEntity entity = BeanUtils.toBean(reqVO, StScheduleModelEntity.class); entity.setId(UUID.randomUUID().toString()); baseDao.insert(entity); stScheduleModelDao.insert(entity); stScheduleModelParamService.saveList(entity.getId(), reqVO.getParamList()); stScheduleModelSettingService.saveList(entity.getId(), reqVO.getSettingList()); } @Override @Transactional(rollbackFor = Exception.class) @DSTransactional(rollbackFor = Exception.class) public void update(StScheduleModelSaveReqVO reqVO) { StScheduleModelEntity entity = BeanUtils.toBean(reqVO, StScheduleModelEntity.class); baseDao.updateById(entity); stScheduleModelDao.updateById(entity); stScheduleModelParamService.saveList(entity.getId(), reqVO.getParamList()); stScheduleModelSettingService.saveList(entity.getId(), reqVO.getSettingList()); } @Override public StScheduleModelEntity get(String id) { return baseDao.selectById(id); return stScheduleModelDao.selectById(id); } @Override @Transactional(rollbackFor = Exception.class) @DSTransactional(rollbackFor = Exception.class) public void delete(String id) { baseDao.deleteById(id); stScheduleModelDao.deleteById(id); stScheduleModelParamService.deleteByModelId(id); stScheduleModelSettingService.deleteByModelId(id); } @@ -82,12 +86,12 @@ QueryWrapper<StScheduleModelEntity> scheduleModelWrapper = new QueryWrapper<>(); scheduleModelWrapper.ne(StringUtils.isNotBlank(id), "id", id); scheduleModelWrapper.and(wrapper -> wrapper.eq("model_name", modelname)); return baseDao.selectCount(scheduleModelWrapper); return stScheduleModelDao.selectCount(scheduleModelWrapper); } @Override public Long count() { QueryWrapper<StScheduleModelEntity> wrapper = new QueryWrapper<>(); return baseDao.selectCount(wrapper); return stScheduleModelDao.selectCount(wrapper); } } iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/common/dto/MdkDataDTO.java
文件已删除 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/common/enums/ItemPredictStatus.java
@@ -1,10 +1,13 @@ package com.iailab.module.model.mdk.common.enums; import org.jetbrains.annotations.Contract; import lombok.AllArgsConstructor; import lombok.Getter; /** * 预测项的预测状态 */ @Getter @AllArgsConstructor public enum ItemPredictStatus { PREDICTING(1), @@ -15,13 +18,4 @@ private Integer value; @Contract(pure = true) ItemPredictStatus(Integer value) { this.value = value; } @Contract(pure = true) public Integer getValue() { return value; } } iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mdk/schedule/impl/ScheduleModelHandlerImpl.java
@@ -49,7 +49,7 @@ public ScheduleResultVO doSchedule(String schemeCode, Date scheduleTime) throws ModelInvokeException { ScheduleResultVO scheduleResult = new ScheduleResultVO(); StScheduleSchemeEntity scheduleScheme = stScheduleSchemeService.getByCode(schemeCode); StScheduleModelEntity scheduleModel = stScheduleModelService.selectById(scheduleScheme.getModelId()); StScheduleModelEntity scheduleModel = stScheduleModelService.get(scheduleScheme.getModelId()); if (scheduleModel == null) { throw new ModelInvokeException(MessageFormat.format("{0},modelId={1}", ModelInvokeException.errorGetModelEntity, scheduleModel.getId())); iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/controller/admin/MpkFileController.java
@@ -7,6 +7,7 @@ import io.swagger.v3.oas.annotations.Operation; import org.apache.commons.io.IOUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; @@ -30,12 +31,14 @@ @GetMapping("page") @Operation(summary = "分页") @PreAuthorize("@ss.hasPermission('mpk:file:query')") public CommonResult<PageData<MpkFileDTO>> page(@RequestParam Map<String, Object> params) { PageData<MpkFileDTO> page = mpkFileService.page(params); return success(page); } @PreAuthorize("@ss.hasPermission('mpk:file:query')") @GetMapping("{id}") public CommonResult<MpkFileDTO> info(@PathVariable("id") String id) { MpkFileDTO schedule = mpkFileService.get(id); @@ -43,6 +46,7 @@ return success(schedule); } @PreAuthorize("@ss.hasPermission('mpk:file:query')") @GetMapping("list") public CommonResult<List<MpkFileDTO>> list() { List<MpkFileDTO> list = mpkFileService.list(new HashMap<>()); @@ -50,22 +54,25 @@ return success(list); } @PreAuthorize("@ss.hasPermission('mpk:file:create')") @PostMapping public CommonResult save(@RequestBody MpkFileDTO dto) { public CommonResult<Boolean> save(@RequestBody MpkFileDTO dto) { mpkFileService.save(dto); return CommonResult.success(); return CommonResult.success(true); } @PreAuthorize("@ss.hasPermission('mpk:file:delete')") @DeleteMapping public CommonResult delete(String id) { public CommonResult<Boolean> delete(String id) { mpkFileService.delete(id); return CommonResult.success(); return CommonResult.success(true); } @PreAuthorize("@ss.hasPermission('mpk:file:update')") @PutMapping public CommonResult update(@RequestBody MpkFileDTO dto) { public CommonResult<Boolean> update(@RequestBody MpkFileDTO dto) { mpkFileService.update(dto); return CommonResult.success(); return CommonResult.success(true); } @GetMapping("generat") iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/controller/admin/ProjectController.java
@@ -7,6 +7,7 @@ import com.iailab.module.model.mpk.dto.ProjectPackageHistoryModelDTO; import com.iailab.module.model.mpk.service.ProjectService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; import java.util.Date; @@ -28,6 +29,7 @@ @Autowired private ProjectService projectService; @PreAuthorize("@ss.hasPermission('mpk:project:query')") @GetMapping("page") public CommonResult<PageData<ProjectDTO>> page(@RequestParam Map<String, Object> params){ PageData<ProjectDTO> page = projectService.page(params); @@ -35,6 +37,7 @@ return success(page); } @PreAuthorize("@ss.hasPermission('mpk:project:query')") @GetMapping("list") public CommonResult<List<ProjectDTO>> list() { List<ProjectDTO> list = projectService.list(new HashMap<>()); @@ -42,6 +45,7 @@ return success(list); } @PreAuthorize("@ss.hasPermission('mpk:project:query')") @GetMapping("{id}") public CommonResult<ProjectDTO> get(@PathVariable("id") String id){ ProjectDTO data = projectService.get(id); @@ -49,27 +53,30 @@ return success(data); } @PreAuthorize("@ss.hasPermission('mpk:project:create')") @PostMapping public CommonResult save(@RequestBody ProjectDTO dto){ public CommonResult<Boolean> save(@RequestBody ProjectDTO dto){ projectService.save(dto); return CommonResult.success(); return CommonResult.success(true); } @PreAuthorize("@ss.hasPermission('mpk:project:update')") @PutMapping public CommonResult update(@RequestBody ProjectDTO dto){ public CommonResult<Boolean> update(@RequestBody ProjectDTO dto){ dto.setUpdateTime(new Date()); projectService.update(dto); return CommonResult.success(); return CommonResult.success(true); } @PreAuthorize("@ss.hasPermission('mpk:project:delete')") @DeleteMapping public CommonResult delete(String id){ public CommonResult<Boolean> delete(String id){ projectService.delete(id); return CommonResult.success(); return CommonResult.success(true); } @GetMapping("getProjectModel") iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/controller/package-info.java
对比新文件 @@ -0,0 +1 @@ package com.iailab.module.model.mpk.controller;