修复 启动隧道时,隧道修改设置的bug

去除无用import
This commit is contained in:
octopusYan 2022-04-11 16:14:13 +08:00
parent 9c581f3a7c
commit 21045b6e1a
17 changed files with 171 additions and 170 deletions

View File

@ -6,7 +6,7 @@
<groupId>top.octopusyan</groupId> <groupId>top.octopusyan</groupId>
<artifactId>YanFrp</artifactId> <artifactId>YanFrp</artifactId>
<version>0.1.2-SNAPSHOT</version> <version>1.0.3-SNAPSHOT</version>
<name>YanFrp</name> <name>YanFrp</name>
<properties> <properties>

View File

@ -52,7 +52,6 @@ public class MainController extends BaseController<StackPane> implements Initial
public static final String PROXY_LIST_ITEM_RUN_CLASS = "proxyListItem-run"; public static final String PROXY_LIST_ITEM_RUN_CLASS = "proxyListItem-run";
public static final String PROXY_LIST_ITEM_CLOSE_CLASS = "proxyListItem-close"; public static final String PROXY_LIST_ITEM_CLOSE_CLASS = "proxyListItem-close";
public static final String PROXY_LIST_ITEM_SELECT_CLASS = "proxyListItem-select"; public static final String PROXY_LIST_ITEM_SELECT_CLASS = "proxyListItem-select";
public static final String INPUT_CLASS = "inputText";
@FXML @FXML
public StackPane root; public StackPane root;
@ -93,12 +92,13 @@ public class MainController extends BaseController<StackPane> implements Initial
@FXML @FXML
public JFXButton logoutBtn; public JFXButton logoutBtn;
private ToggleGroup openProxyGroup = new ToggleGroup(); private final ToggleGroup openProxyGroup = new ToggleGroup();
private SimpleBooleanProperty customizeDomain = new SimpleBooleanProperty(false); private final SimpleBooleanProperty customizeDomain = new SimpleBooleanProperty(false);
private Map<String, FrpManager> frpUtilMap = new HashMap<>(); private final Map<Integer, FrpManager> frpUtilMap = new HashMap<>();
private final Map<Integer, ProxySetup> userProxy = new HashMap<>();
private ProxySetupModel proxySetupModel; private ProxySetupModel proxySetupModel;
private ProxySetup proxySetup; private ProxySetup proxySetup;
private SimpleBooleanProperty setup = new SimpleBooleanProperty(false); private final SimpleBooleanProperty setup = new SimpleBooleanProperty(false);
@Override @Override
public boolean dragWindow() { public boolean dragWindow() {
@ -156,6 +156,20 @@ public class MainController extends BaseController<StackPane> implements Initial
// 如果用户隧道列表不为空 // 如果用户隧道列表不为空
if (result != null && result.size() > 0) { if (result != null && result.size() > 0) {
// 上次关闭时选择的隧道
if (selectProxyName != null)
for (int i = 0; i < result.size(); i++) {
if (result.get(i).getProxy_name().equals(selectProxyName))
selectProxy(i);
selectProxyName = null;
}
// 保存用户隧道信息
for (ProxySetup setup : result) {
userProxy.put(setup.getId(), setup);
}
proxySetup = result.get(selectProxy()); proxySetup = result.get(selectProxy());
proxySetupModel.set(result.get(selectProxy())); proxySetupModel.set(result.get(selectProxy()));
// 初始化用户隧道列表 // 初始化用户隧道列表
@ -163,10 +177,7 @@ public class MainController extends BaseController<StackPane> implements Initial
// 重置隧道列表视图 // 重置隧道列表视图
initProxyListView(); initProxyListView();
} }
// else {
// }
//
// bindDataView();
}); });
} }
@ -264,7 +275,6 @@ public class MainController extends BaseController<StackPane> implements Initial
// 是否切换为自定义域名 // 是否切换为自定义域名
if (newValue) { if (newValue) {
// 隐藏系统域名 // 隐藏系统域名
if (parent.getChildren().contains(domainSuffixTextField))
parent.getChildren().remove(domainSuffixTextField); parent.getChildren().remove(domainSuffixTextField);
// 用户域名是否自定义 // 用户域名是否自定义
if (!DomainUtil.isCustomize(proxySetupModel.get())) { if (!DomainUtil.isCustomize(proxySetupModel.get())) {
@ -298,7 +308,9 @@ public class MainController extends BaseController<StackPane> implements Initial
tabPane.getSelectionModel().select(1); tabPane.getSelectionModel().select(1);
} }
/** 设置访问链接 */ /**
* 设置访问链接
*/
private void setDomainLink() { private void setDomainLink() {
// 外网访问连接 // 外网访问连接
if (DomainUtil.isHttp(proxySetupModel)) { if (DomainUtil.isHttp(proxySetupModel)) {
@ -315,15 +327,16 @@ public class MainController extends BaseController<StackPane> implements Initial
public void initViewAction() { public void initViewAction() {
// 重置 // 重置
resetProxyBtn.setOnMouseClicked(event -> { resetProxyBtn.setOnMouseClicked(event -> {
proxySetup.setRuning(false); proxySetup = userProxy.get(proxySetup.getId());
proxySetup.setRuning(proxySetupModel.isRunning());
proxySetupModel.set(proxySetup); proxySetupModel.set(proxySetup);
domainTextField.resetValidation(); domainTextField.resetValidation();
}); });
// 日志清理 // 日志清理
clearLogBtn.setOnMouseClicked(event -> { clearLogBtn.setOnMouseClicked(event -> {
if (frpUtilMap.get(proxySetupModel.getProxyName()) != null) if (frpUtilMap.get(proxySetup.getId()) != null)
frpUtilMap.get(proxySetupModel.getProxyName()).clearLog(); frpUtilMap.get(proxySetup.getId()).clearLog();
}); });
// 更换服务器地址 // 更换服务器地址
@ -356,16 +369,12 @@ public class MainController extends BaseController<StackPane> implements Initial
// 本地IP检查 // 本地IP检查
localHostTextField.getValidators().add(TextValidate.IpRequired); localHostTextField.getValidators().add(TextValidate.IpRequired);
localHostTextField.getValidators().add(TextValidate.IpFormat); localHostTextField.getValidators().add(TextValidate.IpFormat);
localHostTextField.textProperty().addListener((observable, oldValue, newValue) -> { localHostTextField.textProperty().addListener((observable, oldValue, newValue) -> localHostTextField.validate());
localHostTextField.validate();
});
// 端口检查 // 端口检查
localPortTextField.getValidators().add(TextValidate.PortRequired); localPortTextField.getValidators().add(TextValidate.PortRequired);
localPortTextField.getValidators().add(TextValidate.PortFormat); localPortTextField.getValidators().add(TextValidate.PortFormat);
localPortTextField.textProperty().addListener((observable, oldValue, newValue) -> { localPortTextField.textProperty().addListener((observable, oldValue, newValue) -> localPortTextField.validate());
localPortTextField.validate();
});
// 域名检查 // 域名检查
setup.addListener((observable, oldValue, newValue) -> { setup.addListener((observable, oldValue, newValue) -> {
@ -403,7 +412,7 @@ public class MainController extends BaseController<StackPane> implements Initial
Platform.runLater(() -> { Platform.runLater(() -> {
setup.set(false); setup.set(false);
proxySetupModel.set(proxySetup); proxySetupModel.set(proxySetup);
FrpManager frpManager = frpUtilMap.get(proxySetup.getProxy_name()); FrpManager frpManager = frpUtilMap.get(proxySetup.getId());
proxyLogPane.contentProperty().set(frpManager == null ? null : frpManager.getConsole()); proxyLogPane.contentProperty().set(frpManager == null ? null : frpManager.getConsole());
setup.set(true); setup.set(true);
setDomainLink(); setDomainLink();
@ -430,9 +439,7 @@ public class MainController extends BaseController<StackPane> implements Initial
}); });
// 链接跳转 // 链接跳转
domainLink.setOnMouseClicked(event -> { domainLink.setOnMouseClicked(event -> getApplication().getHostServices().showDocument(domainLink.getText()));
getApplication().getHostServices().showDocument(domainLink.getText());
});
// 复制外网访问地址 // 复制外网访问地址
copyDomainBtn.setOnMouseClicked(event -> { copyDomainBtn.setOnMouseClicked(event -> {
@ -448,7 +455,7 @@ public class MainController extends BaseController<StackPane> implements Initial
// 退出登录 // 退出登录
logoutBtn.setOnMouseClicked(event -> { logoutBtn.setOnMouseClicked(event -> {
for (String key : frpUtilMap.keySet()) { for (Integer key : frpUtilMap.keySet()) {
frpUtilMap.get(key).stop(); frpUtilMap.get(key).stop();
} }
ApplicatonStore.logout(); ApplicatonStore.logout();
@ -516,14 +523,13 @@ public class MainController extends BaseController<StackPane> implements Initial
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
proxyListView.getSelectionModel().select(items.size() - 1);
} }
/** /**
* 启动代理 * 启动代理
*/ */
private void startProxy() { private void startProxy() {
// 验证 // 验证
if (!domainTextField.validate() || !localHostTextField.validate() || !localPortTextField.validate()) if (!domainTextField.validate() || !localHostTextField.validate() || !localPortTextField.validate())
return; return;
@ -533,45 +539,37 @@ public class MainController extends BaseController<StackPane> implements Initial
proxySetupModel.setRemotePort(String.valueOf(ProxyManager.randomPort())); proxySetupModel.setRemotePort(String.valueOf(ProxyManager.randomPort()));
} }
// 是用户隧道 // 是否有修改
if (proxySetupModel.getId() != null && !proxySetupModel.get().equals(proxySetup)) { if (!proxySetupModel.get().equals(userProxy.get(proxySetup.getId()))) {
// 删除旧隧道
ProxyManager.delete(Integer.parseInt(proxySetupModel.getId()));
// 添加隧道 // 添加隧道
ProxyManager.add(new OnHttpListener<ProxySetup>() { ProxyManager.add(new OnHttpListener<ProxySetup>() {
@Override @Override
public void onSucceed(ProxySetup result) { public void onSucceed(ProxySetup result) {
result.setRuning(frpUtilMap.containsKey(result.getProxy_name())); // 如果添加成功
proxySetupModel.set(result); if (result != null) {
userProxy.put(result.getId(), result);
start(result);
}
} }
@Override @Override
public void onFail(Exception e) { public void onFail(Exception e) {
} }
}, proxySetupModel.get()); }, proxySetupModel.get());
} else if(proxySetupModel.getId() == null) { } else {
start(proxySetup);
// 添加隧道 }
ProxyManager.add(new OnHttpListener<ProxySetup>() {
@Override
public void onSucceed(ProxySetup result) {
result.setRuning(frpUtilMap.containsKey(result.getProxy_name()));
proxySetupModel.set(result);
} }
@Override private void start(ProxySetup setup) {
public void onFail(Exception e) { // 添加成功设置运行状态
setup.setRuning(frpUtilMap.containsKey(setup.getId()));
} proxySetupModel.set(setup);
}, proxySetupModel.get());
}
// 初始化frputil // 初始化frputil
FrpManager frpManager; FrpManager frpManager;
if ((frpManager = frpUtilMap.get(proxySetupModel.getProxyName())) == null) if ((frpManager = frpUtilMap.get(setup.getId())) == null)
frpUtilMap.put(proxySetupModel.getProxyName(), frpManager = FrpManager.init(proxySetupModel)); frpUtilMap.put(proxySetup.getId(), frpManager = FrpManager.init(proxySetupModel));
// 设置文本域对象 // 设置文本域对象
if (proxyLogPane.getContent() == null) proxyLogPane.contentProperty().set(frpManager.getConsole()); if (proxyLogPane.getContent() == null) proxyLogPane.contentProperty().set(frpManager.getConsole());
@ -588,7 +586,7 @@ public class MainController extends BaseController<StackPane> implements Initial
*/ */
private void stopProxy() { private void stopProxy() {
// 关闭CMD // 关闭CMD
FrpManager frpManager = frpUtilMap.get(proxySetupModel.getProxyName()); FrpManager frpManager = frpUtilMap.get(proxySetup.getId());
if (frpManager != null) frpManager.stop(); if (frpManager != null) frpManager.stop();
} }

View File

@ -1,12 +1,12 @@
package top.octopusyan.http; package top.octopusyan.http;
import top.octopusyan.http.request.*; import top.octopusyan.http.request.*;
import top.octopusyan.manager.ProxyManager;
import top.octopusyan.manager.http.api.NotParamApi; import top.octopusyan.manager.http.api.NotParamApi;
import top.octopusyan.manager.http.api.ParamApi; import top.octopusyan.manager.http.api.ParamApi;
import top.octopusyan.manager.http.api.PathParamApi; import top.octopusyan.manager.http.api.PathParamApi;
import top.octopusyan.manager.http.config.BodyType; import top.octopusyan.manager.http.config.BodyType;
import top.octopusyan.manager.http.config.HttpConstant; import top.octopusyan.manager.http.config.HttpConstant;
import top.octopusyan.manager.ProxyManager;
/** /**
* @author : octopus yan * @author : octopus yan

View File

@ -3,14 +3,19 @@ package top.octopusyan.manager;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.scene.control.TextArea; import javafx.scene.control.TextArea;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import top.octopusyan.http.Api;
import top.octopusyan.manager.http.EasyHttp;
import top.octopusyan.manager.http.model.ResponseClass;
import top.octopusyan.model.ApplicatonStore; import top.octopusyan.model.ApplicatonStore;
import top.octopusyan.model.ProxySetupModel; import top.octopusyan.model.ProxySetupModel;
import top.octopusyan.utils.JsoupUtil;
import java.io.*; import java.io.*;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.*;
import java.util.List;
/** /**
* @author : octopus yan * @author : octopus yan
@ -24,6 +29,7 @@ public class FrpManager {
public static final String FRPC_CLIENT_FILE_NAME = "frpclienttmpfile.exe"; public static final String FRPC_CLIENT_FILE_NAME = "frpclienttmpfile.exe";
private final String FRPC_CONF_PREFIX_NAME = "proxy_"; private final String FRPC_CONF_PREFIX_NAME = "proxy_";
private final String FRPC_CONF_SUFFIX_NAME = ".ini"; private final String FRPC_CONF_SUFFIX_NAME = ".ini";
private static final Map<Integer, String> serverConfigraution = new HashMap<>(3);
/** /**
* 应用临时目录 地址 * 应用临时目录 地址
*/ */
@ -65,6 +71,7 @@ public class FrpManager {
*/ */
public void start() { public void start() {
thread = new ProxyThread(); thread = new ProxyThread();
thread.setName(FRPC_CONF_PREFIX_NAME + model.getSort());
thread.start(); thread.start();
} }
@ -98,14 +105,14 @@ public class FrpManager {
*/ */
public void clearLog() { public void clearLog() {
if (console != null) if (console != null)
Platform.runLater(() -> console.clear()); Platform.runLater(console::clear);
} }
/** /**
* 隧道配置文件地址 * 隧道配置文件地址
*/ */
private String getConfigFilePath() { private String getConfigFilePath() {
return YAN_FRP_TEMP_DIR_PATH + File.separator + FRPC_CONF_PREFIX_NAME + model.getProxyName() + FRPC_CONF_SUFFIX_NAME; return YAN_FRP_TEMP_DIR_PATH + File.separator + FRPC_CONF_PREFIX_NAME + model.getSort() + FRPC_CONF_SUFFIX_NAME;
} }
/** /**
@ -121,11 +128,62 @@ public class FrpManager {
frpcConfigFile.deleteOnExit(); frpcConfigFile.deleteOnExit();
// 写入服务配置 // 写入服务配置
FileUtils.write(frpcConfigFile, ProxyManager.getUserServerConfig(model.get().getNode()), StandardCharsets.UTF_8); FileUtils.write(frpcConfigFile, getUserFrpServerConfig(model.get().getNode()), StandardCharsets.UTF_8);
// 写入隧道配置 // 写入隧道配置
FileUtils.write(frpcConfigFile, ProxyManager.getProxyConfig(model), StandardCharsets.UTF_8, true); FileUtils.write(frpcConfigFile, getProxyFrpConfig(model), StandardCharsets.UTF_8, true);
} }
public static String getUserFrpServerConfig(int node) {
String config = serverConfigraution.get(node);
if (StringUtils.isNotEmpty(config)) return config;
try {
String result = EasyHttp.builder()
.api(Api.getServerConfiguration(node))
.pathParam(String.valueOf(node))
.execute(new ResponseClass<String>() {
});
config = JsoupUtil.getServerConfiguration(result);
if (StringUtils.isNotEmpty(config)) serverConfigraution.put(node, config);
return config;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static String getProxyFrpConfig(ProxySetupModel setup) {
String n = "\n";
// 基础配置
StringBuilder stringBuilder = new StringBuilder("[" + ApplicatonStore.getAccount() + "_" + setup.getSort() + "]\n");
stringBuilder.append("privilege_mode = true\n")
.append("type = ").append(setup.getProxyType().contains("http") ? "http" : setup.getProxyType()).append(n)
.append("local_ip = ").append(setup.getLocalIp()).append(n)
.append("local_port = ").append(setup.getLocalPort()).append(n).append(n);
if ("http".equals(setup.getProxyType()) || "https".equals(setup.getProxyType())) {
// HTTP / HTTPS
stringBuilder.append("custom_domains = ").append(setup.getDomain()).append(setup.getDomainSuffix()).append(n);
if (!StringUtils.isEmpty(setup.getLocations()))
stringBuilder.append("locations = ").append(setup.getLocations()).append(n);
if (!StringUtils.isEmpty(setup.getLocations()))
stringBuilder.append("host_header_rewrite = ").append(setup.getHostHeaderRewrite()).append(n);
if (!StringUtils.isEmpty(setup.getLocations()))
stringBuilder.append("header_X-From-Where = ").append(setup.getHeader_X_From_Where()).append(n);
} else {
// TCP / UDP / XTCP / STCP
stringBuilder.append("remote_port = ").append(setup.getRemotePort()).append(n);
if (!StringUtils.isEmpty(setup.getSk()))
stringBuilder.append("sk = ").append(setup.getSk()).append(n);
}
// 压缩和加密
stringBuilder.append("use_encryption = ").append(setup.isUseEncryption()).append(n)
.append("use_compression = ").append(setup.isUseCompression()).append(n).append(n);
return stringBuilder.toString();
}
/** /**
* 初始化frpc客户端文件 * 初始化frpc客户端文件
*/ */
@ -135,7 +193,7 @@ public class FrpManager {
frpc.createNewFile(); frpc.createNewFile();
// 复制 frpc // 复制 frpc
copyFileUsingFileStreams(FrpManager.class.getResourceAsStream("/static/frpc.exe"), frpc); copyFileUsingFileStreams(Objects.requireNonNull(FrpManager.class.getResourceAsStream("/static/frpc.exe")));
} }
// frpc 临时配置文件 // frpc 临时配置文件
@ -154,7 +212,7 @@ public class FrpManager {
try { try {
FileUtils.deleteDirectory(frpconfigDir); FileUtils.deleteDirectory(frpconfigDir);
for (File file : FileUtils.getTempDirectory().listFiles()) { for (File file : Objects.requireNonNull(FileUtils.getTempDirectory().listFiles())) {
if (file.getPath().contains(YAN_FRP_TEMP_DIR_NAME) && file.canWrite() && file.isDirectory()) { if (file.getPath().contains(YAN_FRP_TEMP_DIR_NAME) && file.canWrite() && file.isDirectory()) {
FileUtils.deleteDirectory(file); FileUtils.deleteDirectory(file);
} }
@ -171,11 +229,11 @@ public class FrpManager {
} }
} }
private static void copyFileUsingFileStreams(InputStream input, File dest) private static void copyFileUsingFileStreams(InputStream input)
throws IOException { throws IOException {
OutputStream output = null; OutputStream output = null;
try { try {
output = new FileOutputStream(dest); output = new FileOutputStream(FrpManager.frpc);
byte[] buf = new byte[1024]; byte[] buf = new byte[1024];
int bytesRead; int bytesRead;
while ((bytesRead = input.read(buf)) > 0) { while ((bytesRead = input.read(buf)) > 0) {
@ -183,10 +241,11 @@ public class FrpManager {
} }
} finally { } finally {
input.close(); input.close();
output.close(); if (output != null) output.close();
} }
} }
@EqualsAndHashCode(callSuper = true)
@Data @Data
class ProxyThread extends Thread { class ProxyThread extends Thread {
private volatile boolean exit = false; private volatile boolean exit = false;
@ -216,13 +275,13 @@ public class FrpManager {
String line; String line;
while ((line = readStdout.readLine()) != null && !exit) { while ((line = readStdout.readLine()) != null && !exit) {
String finalLine = line; String finalLine = line;
System.out.println("yan-frp-info:" + line); System.out.println(line);
Platform.runLater(() -> console.appendText("yan-frp-info:" + finalLine + "\n")); Platform.runLater(() -> console.appendText(finalLine + "\n"));
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
// // TODO 报错
Platform.runLater(() -> console.appendText("yan-frp-error:" + e.getMessage() + "\n")); Platform.runLater(() -> console.appendText("yan-frp-error:" + e.getMessage() + "\n"));
Platform.runLater(() -> console.appendText("yan-frp-error:启动失败\n")); Platform.runLater(() -> console.appendText("yan-frp-error:启动失败\n"));
} }

View File

@ -13,14 +13,9 @@ import top.octopusyan.http.request.ProxySetup;
import top.octopusyan.manager.http.EasyHttp; import top.octopusyan.manager.http.EasyHttp;
import top.octopusyan.manager.http.listener.OnHttpListener; import top.octopusyan.manager.http.listener.OnHttpListener;
import top.octopusyan.manager.http.model.ResponseClass; import top.octopusyan.manager.http.model.ResponseClass;
import top.octopusyan.model.ApplicatonStore;
import top.octopusyan.model.ProxySetupModel;
import top.octopusyan.utils.AlertUtil; import top.octopusyan.utils.AlertUtil;
import top.octopusyan.utils.JsoupUtil;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -32,7 +27,6 @@ import java.util.stream.Collectors;
*/ */
public class ProxyManager { public class ProxyManager {
private static String csrf; private static String csrf;
private static Map<Integer, String> serverConfigraution = new HashMap<>(3);
/** /**
* 初始化隧道设置 * 初始化隧道设置
@ -170,6 +164,14 @@ public class ProxyManager {
.request(new OnHttpListener<String>() { .request(new OnHttpListener<String>() {
@Override @Override
public void onSucceed(String result) { public void onSucceed(String result) {
// 不成功
if(!result.contains("成功")){
Platform.runLater(() -> AlertUtil.error(result).header(null).show());
listener.onSucceed(null);
return;
}
getList(new OnHttpListener<List<ProxySetup>>() { getList(new OnHttpListener<List<ProxySetup>>() {
@Override @Override
public void onSucceed(List<ProxySetup> result) { public void onSucceed(List<ProxySetup> result) {
@ -181,7 +183,9 @@ public class ProxyManager {
return; return;
} }
} }
listener.onSucceed(null);
} }
listener.onSucceed(null);
} }
@Override @Override
@ -207,53 +211,4 @@ public class ProxyManager {
int i1 = htmlStr.indexOf("\"", i + 18); int i1 = htmlStr.indexOf("\"", i + 18);
ProxyManager.csrf = htmlStr.substring(i + 18, i1); ProxyManager.csrf = htmlStr.substring(i + 18, i1);
} }
public static String getUserServerConfig(int node) {
String config = serverConfigraution.get(node);
if (StringUtils.isNotEmpty(config)) return config;
try {
String result = EasyHttp.builder()
.api(Api.getServerConfiguration(node))
.pathParam(String.valueOf(node))
.execute(new ResponseClass<String>() {
});
config = JsoupUtil.getServerConfiguration(result);
if (StringUtils.isNotEmpty(config)) serverConfigraution.put(node, config);
return config;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static String getProxyConfig(ProxySetupModel setup) {
String n = "\n";
// 基础配置
StringBuilder stringBuilder = new StringBuilder("[" + ApplicatonStore.getAccount() + "_" + setup.getProxyName() + "]\n");
stringBuilder.append("privilege_mode = true\n")
.append("type = ").append(setup.getProxyType().contains("http") ? "http" : setup.getProxyType()).append(n)
.append("local_ip = ").append(setup.getLocalIp()).append(n)
.append("local_port = ").append(setup.getLocalPort()).append(n).append(n);
if ("http".equals(setup.getProxyType()) || "https".equals(setup.getProxyType())) {
// HTTP / HTTPS
stringBuilder.append("custom_domains = ").append(setup.getDomain()).append(setup.getDomainSuffix()).append(n);
if (!StringUtils.isEmpty(setup.getLocations()))
stringBuilder.append("locations = ").append(setup.getLocations()).append(n);
if (!StringUtils.isEmpty(setup.getLocations()))
stringBuilder.append("host_header_rewrite = ").append(setup.getHostHeaderRewrite()).append(n);
if (!StringUtils.isEmpty(setup.getLocations()))
stringBuilder.append("header_X-From-Where = ").append(setup.getHeader_X_From_Where()).append(n);
} else {
// TCP / UDP / XTCP / STCP
stringBuilder.append("remote_port = ").append(setup.getRemotePort()).append(n);
if (!StringUtils.isEmpty(setup.getSk()))
stringBuilder.append("sk = ").append(setup.getSk()).append(n);
}
// 压缩和加密
stringBuilder.append("use_encryption = ").append(setup.isUseEncryption()).append(n)
.append("use_compression = ").append(setup.isUseCompression()).append(n).append(n);
return stringBuilder.toString();
}
} }

View File

@ -9,15 +9,11 @@ import top.octopusyan.manager.http.api.ParamApi;
import top.octopusyan.manager.http.api.PathParamApi; import top.octopusyan.manager.http.api.PathParamApi;
import top.octopusyan.manager.http.api.RequestApi; import top.octopusyan.manager.http.api.RequestApi;
import top.octopusyan.manager.http.callback.NormalCallback; import top.octopusyan.manager.http.callback.NormalCallback;
import top.octopusyan.manager.http.listener.OnHttpListener;
import top.octopusyan.manager.http.model.CallProxy;
import top.octopusyan.manager.http.model.HttpHeaders;
import top.octopusyan.manager.http.model.HttpParams;
import top.octopusyan.manager.http.model.JsonBody;
import top.octopusyan.manager.http.config.BodyType; import top.octopusyan.manager.http.config.BodyType;
import top.octopusyan.manager.http.config.HttpConstant; import top.octopusyan.manager.http.config.HttpConstant;
import top.octopusyan.manager.http.listener.OnHttpListener;
import top.octopusyan.manager.http.model.*;
import top.octopusyan.manager.http.request.IRequestHandler; import top.octopusyan.manager.http.request.IRequestHandler;
import top.octopusyan.manager.http.model.ResponseClass;
import java.io.File; import java.io.File;
import java.io.InputStream; import java.io.InputStream;
@ -195,7 +191,7 @@ public class EasyHttp<Param, Result> {
try { try {
mCallProxy = new CallProxy(createCall()); mCallProxy = new CallProxy(createCall());
Response response = mCallProxy.execute(); Response response = mCallProxy.execute();
return (Result) mHandler.requestSucceed(getRequestApi(), response, mHandler.getType(responseClass)); return mHandler.requestSucceed(getRequestApi(), response, mHandler.getType(responseClass));
} catch (Exception e) { } catch (Exception e) {
throw mHandler.requestFail(getRequestApi(), e); throw mHandler.requestFail(getRequestApi(), e);
} }

View File

@ -7,11 +7,11 @@ import okhttp3.MediaType;
import okhttp3.MultipartBody; import okhttp3.MultipartBody;
import okhttp3.RequestBody; import okhttp3.RequestBody;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import top.octopusyan.manager.ThreadPoolManager;
import top.octopusyan.manager.http.annotation.HttpIgnore; import top.octopusyan.manager.http.annotation.HttpIgnore;
import top.octopusyan.manager.http.annotation.HttpRename; import top.octopusyan.manager.http.annotation.HttpRename;
import top.octopusyan.manager.http.config.ContentType; import top.octopusyan.manager.http.config.ContentType;
import top.octopusyan.manager.http.model.UpdateBody; import top.octopusyan.manager.http.model.UpdateBody;
import top.octopusyan.manager.ThreadPoolManager;
import java.io.*; import java.io.*;
import java.lang.reflect.Field; import java.lang.reflect.Field;

View File

@ -1,6 +1,6 @@
package top.octopusyan.manager.http; package top.octopusyan.manager.http;
import okhttp3.*; import okhttp3.OkHttpClient;
import top.octopusyan.manager.http.config.ILogStrategy; import top.octopusyan.manager.http.config.ILogStrategy;
import top.octopusyan.manager.http.request.IRequestHandler; import top.octopusyan.manager.http.request.IRequestHandler;
@ -47,11 +47,11 @@ public class HttpConfig {
private HttpConfig(OkHttpClient client) { private HttpConfig(OkHttpClient client) {
mClient = client; mClient = client;
mParams = new HashMap<String, Object>(); mParams = new HashMap<>();
mHeaders = new HashMap<>(); mHeaders = new HashMap<>();
} }
private HttpConfig() { private HttpConfig() {
mParams = new HashMap<String, Object>(); mParams = new HashMap<>();
mHeaders = new HashMap<>(); mHeaders = new HashMap<>();
initHttpClient(); initHttpClient();
} }
@ -81,7 +81,7 @@ public class HttpConfig {
public HttpConfig setParams(HashMap<String, Object> params) { public HttpConfig setParams(HashMap<String, Object> params) {
if (params == null) { if (params == null) {
params = new HashMap<String, Object>(); params = new HashMap<>();
} }
mParams = params; mParams = params;
return this; return this;
@ -207,6 +207,6 @@ public class HttpConfig {
} }
private void initHttpClient() { private void initHttpClient() {
;
} }
} }

View File

@ -3,10 +3,11 @@ package top.octopusyan.manager.http.callback;
import okhttp3.Call; import okhttp3.Call;
import okhttp3.Callback; import okhttp3.Callback;
import okhttp3.Response; import okhttp3.Response;
import org.jetbrains.annotations.NotNull;
import top.octopusyan.manager.http.EasyUtils;
import top.octopusyan.manager.http.HttpConfig; import top.octopusyan.manager.http.HttpConfig;
import top.octopusyan.manager.http.HttpLog; import top.octopusyan.manager.http.HttpLog;
import top.octopusyan.manager.http.model.CallProxy; import top.octopusyan.manager.http.model.CallProxy;
import top.octopusyan.manager.http.EasyUtils;
import java.io.IOException; import java.io.IOException;
import java.net.SocketTimeoutException; import java.net.SocketTimeoutException;
@ -34,7 +35,7 @@ public abstract class BaseCallback implements Callback {
} }
@Override @Override
public void onResponse(Call call, Response response) { public void onResponse(@NotNull Call call, @NotNull Response response) {
try { try {
// 收到响应 // 收到响应
onResponse(response); onResponse(response);
@ -48,7 +49,7 @@ public abstract class BaseCallback implements Callback {
} }
@Override @Override
public void onFailure(Call call, IOException e) { public void onFailure(@NotNull Call call, @NotNull IOException e) {
// 服务器请求超时重试 // 服务器请求超时重试
if (e instanceof SocketTimeoutException && mRetryCount < HttpConfig.getInstance().getRetryCount()) { if (e instanceof SocketTimeoutException && mRetryCount < HttpConfig.getInstance().getRetryCount()) {
// 设置延迟 N 秒后重试该请求 // 设置延迟 N 秒后重试该请求

View File

@ -2,12 +2,12 @@ package top.octopusyan.manager.http.callback;
import javafx.application.Platform; import javafx.application.Platform;
import okhttp3.Response; import okhttp3.Response;
import top.octopusyan.manager.http.listener.OnHttpListener;
import top.octopusyan.manager.http.HttpLog;
import top.octopusyan.manager.http.model.CallProxy;
import top.octopusyan.manager.http.api.RequestApi;
import top.octopusyan.manager.http.request.IRequestHandler;
import top.octopusyan.manager.http.EasyUtils; import top.octopusyan.manager.http.EasyUtils;
import top.octopusyan.manager.http.HttpLog;
import top.octopusyan.manager.http.api.RequestApi;
import top.octopusyan.manager.http.listener.OnHttpListener;
import top.octopusyan.manager.http.model.CallProxy;
import top.octopusyan.manager.http.request.IRequestHandler;
/** /**
* @author : octopus yan * @author : octopus yan

View File

@ -1,8 +1,8 @@
package top.octopusyan.manager.http.config; package top.octopusyan.manager.http.config;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.apache.commons.lang3.StringUtils;
import top.octopusyan.manager.http.EasyHttp; import top.octopusyan.manager.http.EasyHttp;
import top.octopusyan.manager.http.HttpConfig; import top.octopusyan.manager.http.HttpConfig;

View File

@ -5,8 +5,8 @@ import okhttp3.RequestBody;
import okio.BufferedSink; import okio.BufferedSink;
import okio.Okio; import okio.Okio;
import okio.Source; import okio.Source;
import top.octopusyan.manager.http.config.ContentType;
import top.octopusyan.manager.http.EasyUtils; import top.octopusyan.manager.http.EasyUtils;
import top.octopusyan.manager.http.config.ContentType;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;

View File

@ -1,12 +1,12 @@
package top.octopusyan.manager.http.request; package top.octopusyan.manager.http.request;
import java.lang.reflect.Type;
import okhttp3.Request; import okhttp3.Request;
import okhttp3.Response; import okhttp3.Response;
import top.octopusyan.manager.http.EasyUtils; import top.octopusyan.manager.http.EasyUtils;
import top.octopusyan.manager.http.api.RequestApi; import top.octopusyan.manager.http.api.RequestApi;
import java.lang.reflect.Type;
public interface IRequestHandler { public interface IRequestHandler {
/** /**
@ -28,7 +28,7 @@ public interface IRequestHandler {
* *
* @throws Exception 如果抛出则回调失败 * @throws Exception 如果抛出则回调失败
*/ */
<Param, Result> Object requestSucceed(RequestApi<Param, Result> api, Response response, Type type) throws Exception; <Param, Result> Result requestSucceed(RequestApi<Param, Result> api, Response response, Type type) throws Exception;
/** /**
* 请求失败 * 请求失败

View File

@ -8,8 +8,8 @@ import okhttp3.Headers;
import okhttp3.Request; import okhttp3.Request;
import okhttp3.Response; import okhttp3.Response;
import okhttp3.ResponseBody; import okhttp3.ResponseBody;
import top.octopusyan.manager.http.api.RequestApi;
import top.octopusyan.manager.http.HttpLog; import top.octopusyan.manager.http.HttpLog;
import top.octopusyan.manager.http.api.RequestApi;
import top.octopusyan.manager.http.exception.*; import top.octopusyan.manager.http.exception.*;
import top.octopusyan.manager.http.response.BaseRest; import top.octopusyan.manager.http.response.BaseRest;
@ -24,8 +24,8 @@ import java.net.UnknownHostException;
/** /**
* @author octopus yan * @author octopus yan
* @email octopus_yan@foxmail.com * @email octopus_yan@foxmail.com
* @Description 请求处理类 * @description 请求处理类
* @createTime 2021-07-23 11:55:26 * @create 2021-07-23 11:55:26
*/ */
public final class RequestHandler implements IRequestHandler { public final class RequestHandler implements IRequestHandler {
@ -125,7 +125,7 @@ public final class RequestHandler implements IRequestHandler {
} }
@Override @Override
public Exception requestFail(RequestApi api, Exception e) { public <Param, Result> Exception requestFail(RequestApi<Param, Result> api, Exception e) {
// 判断这个异常是不是自己抛的 // 判断这个异常是不是自己抛的
if (e instanceof HttpException) { if (e instanceof HttpException) {
if (e instanceof TokenException) { if (e instanceof TokenException) {
@ -159,9 +159,6 @@ public final class RequestHandler implements IRequestHandler {
/** /**
* 传入需要连接的IP返回是否连接成功 * 传入需要连接的IP返回是否连接成功
*
* @param remoteInetAddr
* @return
*/ */
public static boolean isReachable(String remoteInetAddr) { public static boolean isReachable(String remoteInetAddr) {
boolean reachable = false; boolean reachable = false;

View File

@ -41,6 +41,7 @@ public class ApplicatonStore {
private static final SimpleBooleanProperty registerSuccess = new SimpleBooleanProperty(); private static final SimpleBooleanProperty registerSuccess = new SimpleBooleanProperty();
private static final ObservableList<ProxySetup> proxyList = FXCollections.observableList(new ArrayList<>()); private static final ObservableList<ProxySetup> proxyList = FXCollections.observableList(new ArrayList<>());
private static final SimpleIntegerProperty selectProxy = new SimpleIntegerProperty(0); private static final SimpleIntegerProperty selectProxy = new SimpleIntegerProperty(0);
public static String selectProxyName = null;
public static void setAccount(String account) { public static void setAccount(String account) {
ApplicatonStore.account.set(account); ApplicatonStore.account.set(account);
@ -153,11 +154,8 @@ public class ApplicatonStore {
if (appDataJson.containsKey(AUTO_LOGIN_KEY)) autoLogin.set(appDataJson.getBoolean(AUTO_LOGIN_KEY)); if (appDataJson.containsKey(AUTO_LOGIN_KEY)) autoLogin.set(appDataJson.getBoolean(AUTO_LOGIN_KEY));
// 记住 // 记住
if (appDataJson.containsKey(REMEMBER_ME_KEY)) rememberMe.set(appDataJson.getBoolean(REMEMBER_ME_KEY)); if (appDataJson.containsKey(REMEMBER_ME_KEY)) rememberMe.set(appDataJson.getBoolean(REMEMBER_ME_KEY));
// TODO 已选择隧道 // 已选择隧道
if (appDataJson.containsKey(SELECT_PROXY_NAME_KEY)) { if (appDataJson.containsKey(SELECT_PROXY_NAME_KEY)) selectProxyName = appDataJson.getString(SELECT_PROXY_NAME_KEY);
// String proxtName = appDataJson.getString(SELECT_PROXY_NAME_KEY);
// proxyListProperty().addListener(new );
}
} }
/** /**
@ -174,7 +172,7 @@ public class ApplicatonStore {
if (rememberMe.get() && password.get() != null) appDataJson.put(PASSWORD_KEY, password.get()); if (rememberMe.get() && password.get() != null) appDataJson.put(PASSWORD_KEY, password.get());
// 选择隧道 // 选择隧道
if (selectProxy.getValue() != null && proxyList.size() > 0 && proxyList.size() > selectProxy.get()) if (selectProxy.getValue() != null && proxyList.size() > 0 && proxyList.size() > selectProxy.get())
appDataJson.put(SELECT_PROXY_NAME_KEY, proxyList.get(selectProxy.getValue())); appDataJson.put(SELECT_PROXY_NAME_KEY, proxyList.get(selectProxy.getValue()).getProxy_name());
// 自动登录 // 自动登录
appDataJson.put(AUTO_LOGIN_KEY, autoLogin.get()); appDataJson.put(AUTO_LOGIN_KEY, autoLogin.get());
// 记住 // 记住

View File

@ -2,9 +2,7 @@ package top.octopusyan.utils;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.fxml.JavaFXBuilderFactory; import javafx.fxml.JavaFXBuilderFactory;
import sun.reflect.Reflection;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
/** /**

View File

@ -1,6 +1,5 @@
package top.octopusyan.utils; package top.octopusyan.utils;
import com.google.code.kaptcha.Producer;
import com.google.code.kaptcha.impl.DefaultKaptcha; import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config; import com.google.code.kaptcha.util.Config;
@ -15,7 +14,7 @@ import java.util.Properties;
*/ */
public class KaptchaUtil { public class KaptchaUtil {
public static volatile KaptchaUtil util; public static volatile KaptchaUtil util;
private DefaultKaptcha defaultKaptcha; private final DefaultKaptcha defaultKaptcha;
private KaptchaUtil(DefaultKaptcha kaptcha){ private KaptchaUtil(DefaultKaptcha kaptcha){
this.defaultKaptcha = kaptcha; this.defaultKaptcha = kaptcha;