|
| 1 | +package com.sqlmapwebui.burp; |
| 2 | + |
| 3 | +import com.google.gson.Gson; |
| 4 | +import com.google.gson.GsonBuilder; |
| 5 | +import com.google.gson.reflect.TypeToken; |
| 6 | +import com.sqlmapwebui.burp.util.TitleRule; |
| 7 | + |
| 8 | +import java.lang.reflect.Type; |
| 9 | +import java.util.ArrayList; |
| 10 | +import java.util.List; |
| 11 | + |
| 12 | +/** |
| 13 | + * 命令行执行配置数据模型 |
| 14 | + * 存储剪贴板复制和直接执行的共用配置 |
| 15 | + */ |
| 16 | +public class CommandExecConfig { |
| 17 | + |
| 18 | + private boolean autoCopy = true; // 自动复制到剪贴板 |
| 19 | + private String tempDir = ""; // HTTP请求临时存储目录 |
| 20 | + private String scriptTempDir = ""; // 临时执行脚本存储目录 |
| 21 | + private String pythonPath = ""; // Python解释器路径 |
| 22 | + private String sqlmapPath = ""; // SQLMap脚本路径 |
| 23 | + private String terminalType = "AUTO"; // 终端类型 |
| 24 | + private boolean keepTerminal = true; // 执行后保持终端打开 |
| 25 | + private List<TitleRule> titleRules = new ArrayList<>(); // 标题提取规则 |
| 26 | + private String titleFallback = "SQLMap"; // 回退标题 |
| 27 | + private int titleMaxLength = 50; // 标题最大长度 |
| 28 | + |
| 29 | + private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); |
| 30 | + |
| 31 | + /** |
| 32 | + * 创建默认配置 |
| 33 | + */ |
| 34 | + public static CommandExecConfig createDefault() { |
| 35 | + CommandExecConfig config = new CommandExecConfig(); |
| 36 | + config.setAutoCopy(true); |
| 37 | + config.setTempDir(""); |
| 38 | + config.setScriptTempDir(""); |
| 39 | + config.setPythonPath(""); |
| 40 | + config.setSqlmapPath(""); |
| 41 | + config.setTerminalType("AUTO"); |
| 42 | + config.setKeepTerminal(true); |
| 43 | + config.setTitleRules(new ArrayList<>()); |
| 44 | + config.setTitleFallback("SQLMap"); |
| 45 | + config.setTitleMaxLength(50); |
| 46 | + return config; |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * 从JSON字符串解析配置 |
| 51 | + */ |
| 52 | + public static CommandExecConfig fromJson(String json) { |
| 53 | + if (json == null || json.trim().isEmpty()) { |
| 54 | + return createDefault(); |
| 55 | + } |
| 56 | + try { |
| 57 | + CommandExecConfig config = GSON.fromJson(json, CommandExecConfig.class); |
| 58 | + if (config == null) { |
| 59 | + return createDefault(); |
| 60 | + } |
| 61 | + // 确保 titleRules 不为 null |
| 62 | + if (config.getTitleRules() == null) { |
| 63 | + config.setTitleRules(new ArrayList<>()); |
| 64 | + } |
| 65 | + return config; |
| 66 | + } catch (Exception e) { |
| 67 | + return createDefault(); |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * 转换为JSON字符串 |
| 73 | + */ |
| 74 | + public String toJson() { |
| 75 | + return GSON.toJson(this); |
| 76 | + } |
| 77 | + |
| 78 | + /** |
| 79 | + * 从标题规则JSON解析 |
| 80 | + */ |
| 81 | + public static List<TitleRule> parseTitleRules(String json) { |
| 82 | + if (json == null || json.trim().isEmpty()) { |
| 83 | + return new ArrayList<>(); |
| 84 | + } |
| 85 | + try { |
| 86 | + Type listType = new TypeToken<ArrayList<TitleRule>>(){}.getType(); |
| 87 | + List<TitleRule> rules = GSON.fromJson(json, listType); |
| 88 | + return rules != null ? rules : new ArrayList<>(); |
| 89 | + } catch (Exception e) { |
| 90 | + return new ArrayList<>(); |
| 91 | + } |
| 92 | + } |
| 93 | + |
| 94 | + /** |
| 95 | + * 将标题规则转换为JSON |
| 96 | + */ |
| 97 | + public static String titleRulesToJson(List<TitleRule> rules) { |
| 98 | + if (rules == null) { |
| 99 | + return "[]"; |
| 100 | + } |
| 101 | + return GSON.toJson(rules); |
| 102 | + } |
| 103 | + |
| 104 | + // ==================== Getters and Setters ==================== |
| 105 | + |
| 106 | + public boolean isAutoCopy() { |
| 107 | + return autoCopy; |
| 108 | + } |
| 109 | + |
| 110 | + public void setAutoCopy(boolean autoCopy) { |
| 111 | + this.autoCopy = autoCopy; |
| 112 | + } |
| 113 | + |
| 114 | + public String getTempDir() { |
| 115 | + return tempDir != null ? tempDir : ""; |
| 116 | + } |
| 117 | + |
| 118 | + public void setTempDir(String tempDir) { |
| 119 | + this.tempDir = tempDir != null ? tempDir : ""; |
| 120 | + } |
| 121 | + |
| 122 | + public String getScriptTempDir() { |
| 123 | + return scriptTempDir != null ? scriptTempDir : ""; |
| 124 | + } |
| 125 | + |
| 126 | + public void setScriptTempDir(String scriptTempDir) { |
| 127 | + this.scriptTempDir = scriptTempDir != null ? scriptTempDir : ""; |
| 128 | + } |
| 129 | + |
| 130 | + public String getPythonPath() { |
| 131 | + return pythonPath != null ? pythonPath : ""; |
| 132 | + } |
| 133 | + |
| 134 | + public void setPythonPath(String pythonPath) { |
| 135 | + this.pythonPath = pythonPath != null ? pythonPath : ""; |
| 136 | + } |
| 137 | + |
| 138 | + public String getSqlmapPath() { |
| 139 | + return sqlmapPath != null ? sqlmapPath : ""; |
| 140 | + } |
| 141 | + |
| 142 | + public void setSqlmapPath(String sqlmapPath) { |
| 143 | + this.sqlmapPath = sqlmapPath != null ? sqlmapPath : ""; |
| 144 | + } |
| 145 | + |
| 146 | + public String getTerminalType() { |
| 147 | + return terminalType != null ? terminalType : "AUTO"; |
| 148 | + } |
| 149 | + |
| 150 | + public void setTerminalType(String terminalType) { |
| 151 | + this.terminalType = terminalType != null ? terminalType : "AUTO"; |
| 152 | + } |
| 153 | + |
| 154 | + public boolean isKeepTerminal() { |
| 155 | + return keepTerminal; |
| 156 | + } |
| 157 | + |
| 158 | + public void setKeepTerminal(boolean keepTerminal) { |
| 159 | + this.keepTerminal = keepTerminal; |
| 160 | + } |
| 161 | + |
| 162 | + public List<TitleRule> getTitleRules() { |
| 163 | + return titleRules != null ? titleRules : new ArrayList<>(); |
| 164 | + } |
| 165 | + |
| 166 | + public void setTitleRules(List<TitleRule> titleRules) { |
| 167 | + this.titleRules = titleRules != null ? titleRules : new ArrayList<>(); |
| 168 | + } |
| 169 | + |
| 170 | + public String getTitleFallback() { |
| 171 | + return titleFallback != null ? titleFallback : "SQLMap"; |
| 172 | + } |
| 173 | + |
| 174 | + public void setTitleFallback(String titleFallback) { |
| 175 | + this.titleFallback = titleFallback != null ? titleFallback : "SQLMap"; |
| 176 | + } |
| 177 | + |
| 178 | + public int getTitleMaxLength() { |
| 179 | + return titleMaxLength > 0 ? titleMaxLength : 50; |
| 180 | + } |
| 181 | + |
| 182 | + public void setTitleMaxLength(int titleMaxLength) { |
| 183 | + this.titleMaxLength = titleMaxLength > 0 ? titleMaxLength : 50; |
| 184 | + } |
| 185 | + |
| 186 | + @Override |
| 187 | + public String toString() { |
| 188 | + return "CommandExecConfig{" + |
| 189 | + "autoCopy=" + autoCopy + |
| 190 | + ", tempDir='" + tempDir + '\'' + |
| 191 | + ", pythonPath='" + pythonPath + '\'' + |
| 192 | + ", sqlmapPath='" + sqlmapPath + '\'' + |
| 193 | + ", terminalType='" + terminalType + '\'' + |
| 194 | + ", keepTerminal=" + keepTerminal + |
| 195 | + ", titleRulesCount=" + (titleRules != null ? titleRules.size() : 0) + |
| 196 | + ", titleFallback='" + titleFallback + '\'' + |
| 197 | + ", titleMaxLength=" + titleMaxLength + |
| 198 | + '}'; |
| 199 | + } |
| 200 | +} |
0 commit comments