2021-06-10 22:59:27 +08:00
|
|
|
package burp.yaml;
|
|
|
|
|
|
|
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
|
import org.yaml.snakeyaml.Yaml;
|
|
|
|
|
|
2021-09-07 22:09:42 +08:00
|
|
|
import burp.Config;
|
|
|
|
|
|
2021-06-10 22:59:27 +08:00
|
|
|
import java.io.*;
|
2021-09-07 22:09:42 +08:00
|
|
|
import java.nio.charset.StandardCharsets;
|
2021-06-10 22:59:27 +08:00
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* @author LinChen
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
public class LoadConfigFile {
|
2021-09-07 22:09:42 +08:00
|
|
|
private static final Yaml yaml = new Yaml();
|
2021-06-10 22:59:27 +08:00
|
|
|
private static final String SettingPath = "Setting.yml";
|
|
|
|
|
private static final String ConfigPath = "Config.yml";
|
|
|
|
|
|
|
|
|
|
public LoadConfigFile(){
|
|
|
|
|
init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 初始化配置
|
|
|
|
|
public void init(){
|
|
|
|
|
File yamlSetting = new File(SettingPath);
|
|
|
|
|
if (!(yamlSetting.exists() && yamlSetting.isFile())) {
|
|
|
|
|
Map<String,Object> r = new HashMap<>();
|
|
|
|
|
r.put("configPath", ConfigPath);
|
|
|
|
|
r.put("excludeSuffix", getExcludeSuffix());
|
|
|
|
|
try{
|
2021-09-07 22:09:42 +08:00
|
|
|
Writer ws = new OutputStreamWriter(new FileOutputStream(SettingPath), StandardCharsets.UTF_8);
|
2021-06-10 22:59:27 +08:00
|
|
|
yaml.dump(r, ws);
|
|
|
|
|
}catch (Exception ex){
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getExcludeSuffix(){
|
|
|
|
|
try {
|
|
|
|
|
InputStream inorder = new FileInputStream(SettingPath);
|
|
|
|
|
Map<String,Object> r;
|
|
|
|
|
r = yaml.load(inorder);
|
|
|
|
|
return r.get("excludeSuffix").toString();
|
|
|
|
|
} catch (FileNotFoundException e) {
|
|
|
|
|
e.printStackTrace();
|
2021-09-07 22:09:42 +08:00
|
|
|
return Config.excludeSuffix;
|
2021-06-10 22:59:27 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-07 22:09:42 +08:00
|
|
|
public static String getConfigPath(){
|
2021-06-10 22:59:27 +08:00
|
|
|
try {
|
|
|
|
|
InputStream inorder = new FileInputStream(SettingPath);
|
|
|
|
|
Map<String,Object> r;
|
|
|
|
|
r = yaml.load(inorder);
|
|
|
|
|
return r.get("configPath").toString();
|
|
|
|
|
} catch (FileNotFoundException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
return ConfigPath;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setExcludeSuffix(@NotNull String excludeSuffix){
|
|
|
|
|
Map<String,Object> r = new HashMap<>();
|
|
|
|
|
r.put("excludeSuffix", excludeSuffix);
|
|
|
|
|
r.put("configPath", getConfigPath());
|
|
|
|
|
try{
|
2021-09-07 22:09:42 +08:00
|
|
|
Writer ws = new OutputStreamWriter(new FileOutputStream(SettingPath), StandardCharsets.UTF_8);
|
2021-06-10 22:59:27 +08:00
|
|
|
yaml.dump(r, ws);
|
|
|
|
|
}catch (Exception ex){
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setConfigPath(@NotNull String filePath){
|
|
|
|
|
Map<String,Object> r = new HashMap<>();
|
|
|
|
|
r.put("configPath", filePath);
|
|
|
|
|
r.put("excludeSuffix", getExcludeSuffix());
|
|
|
|
|
try{
|
2021-09-07 22:09:42 +08:00
|
|
|
Writer ws = new OutputStreamWriter(new FileOutputStream(SettingPath), StandardCharsets.UTF_8);
|
2021-06-10 22:59:27 +08:00
|
|
|
yaml.dump(r, ws);
|
|
|
|
|
}catch (Exception ex){
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|