From bf64df28f1730c01d8b090af2f5f3bca020025e1 Mon Sep 17 00:00:00 2001 From: octopusYan <935540320@qq.com> Date: Tue, 19 Apr 2022 00:40:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dp2p=E7=9B=91=E5=90=AC?= =?UTF-8?q?=E8=AE=BF=E9=97=AE=E6=9C=8D=E5=8A=A1=E5=90=8D=E7=A7=B0=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/LoginController.java | 21 ++++++++++++ .../octopusyan/controller/MainController.java | 7 ++-- .../top/octopusyan/manager/FrpManager.java | 33 ++++++++++++------- .../java/top/octopusyan/manager/http/Api.java | 4 +-- .../top/octopusyan/model/ApplicatonStore.java | 13 ++++++++ 5 files changed, 61 insertions(+), 17 deletions(-) diff --git a/src/main/java/top/octopusyan/controller/LoginController.java b/src/main/java/top/octopusyan/controller/LoginController.java index 7294be8..5e0d526 100644 --- a/src/main/java/top/octopusyan/controller/LoginController.java +++ b/src/main/java/top/octopusyan/controller/LoginController.java @@ -270,6 +270,8 @@ public class LoginController extends BaseController implements Initia } // 登录成功 setCsrf(); + // 用户token + setUSerToken(); // 记住我 ApplicatonStore.rememberMe(tmpPwd.get()); // 跳转 @@ -289,6 +291,25 @@ public class LoginController extends BaseController implements Initia }); } + private void setUSerToken() { + EasyHttp.builder() + .api(Api.getServerConfiguration(1)) + .request(new OnHttpListener() { + @Override + public void onSucceed(String result) { + String config = JsoupUtil.getServerConfiguration(result); + int start = config.indexOf("user = "); + String userToken = config.substring(start + 7, config.indexOf("\n", start)); + Platform.runLater(() -> ApplicatonStore.setUserToken(userToken)); + } + + @Override + public void onFail(Exception e) { + + } + }); + } + private void setCsrf() { EasyHttp.builder() .api(new NotParamApi( diff --git a/src/main/java/top/octopusyan/controller/MainController.java b/src/main/java/top/octopusyan/controller/MainController.java index 867e356..7be0705 100644 --- a/src/main/java/top/octopusyan/controller/MainController.java +++ b/src/main/java/top/octopusyan/controller/MainController.java @@ -310,7 +310,7 @@ public class MainController extends BaseController implements Initial if (!children.contains(p2pRolePane)) { children.add(index, p2pPwdPane); children.add(index - 1, p2pRolePane); - if(proxySetupModel.isProvider != null && !proxySetupModel.isProvider){ + if (proxySetupModel.isProvider != null && !proxySetupModel.isProvider) { children.add(index, serverNamePane); } } @@ -376,7 +376,8 @@ public class MainController extends BaseController implements Initial copyP2pConfig.setVisible(false); importP2pConfig.setVisible(true); if (!children.contains(serverNamePane)) children.add(children.size() - 3, serverNamePane); - proxySetupModel.setServerName(""); + String serverName = proxySetupModel.getServerName(); + proxySetupModel.setServerName("提供者".equals(serverName) ? "" : serverName); } ObservableList children = p2pRolePane.getChildren(); JFXButton remove = proxySetupModel.isProvider ? importP2pConfig : copyP2pConfig; @@ -547,7 +548,7 @@ public class MainController extends BaseController implements Initial ProxySetup setup = proxySetupModel.get(); String serverName = getAccount() + "_" + setup.getSort(); - setup.setServer_name(EncryptionUtil.MD5_16(serverName)); + setup.setServer_name(ApplicatonStore.getUserToken() + "." + EncryptionUtil.MD5_16(serverName)); setup.setId(null); setup.setRuning(false); setup.setSort(null); diff --git a/src/main/java/top/octopusyan/manager/FrpManager.java b/src/main/java/top/octopusyan/manager/FrpManager.java index 304dd89..2826471 100644 --- a/src/main/java/top/octopusyan/manager/FrpManager.java +++ b/src/main/java/top/octopusyan/manager/FrpManager.java @@ -129,6 +129,7 @@ public class FrpManager { } frpcConfigFile.deleteOnExit(); + // 写入服务配置 FileUtils.write(frpcConfigFile, getUserFrpServerConfig(model.get().getNode()), StandardCharsets.UTF_8); // 写入隧道配置 @@ -136,17 +137,25 @@ public class FrpManager { } - public static String getUserFrpServerConfig(int node) { + public String getUserFrpServerConfig(int node) { + boolean isp2p = "xtcp".equals(model.getProxyType()) || "stcp".equals(model.getProxyType()); String config = serverConfigraution.get(node); - if (StringUtils.isNotEmpty(config)) return config; + if (StringUtils.isNotEmpty(config) && !isp2p) return config; + try { - String result = EasyHttp.builder() - .api(Api.getServerConfiguration(node)) - .pathParam(String.valueOf(node)) - .execute(new ResponseClass() { - }); - config = JsoupUtil.getServerConfiguration(result); - if (StringUtils.isNotEmpty(config)) serverConfigraution.put(node, config); + if (StringUtils.isEmpty(config)) { + String result = EasyHttp.builder() + .api(Api.getServerConfiguration(node)) + .execute(new ResponseClass() { + }); + config = JsoupUtil.getServerConfiguration(result); + if (StringUtils.isNotEmpty(config)) serverConfigraution.put(node, config); + } + + // user配置 会加在访问服务端名称的前边 , 清空让访问到 + if (isp2p && !model.isProvider()) + config = config.replaceAll("user = .*", ""); + return config; } catch (Exception e) { e.printStackTrace(); @@ -154,14 +163,14 @@ public class FrpManager { return null; } - public static String getProxyFrpConfig(ProxySetupModel setup) { + public String getProxyFrpConfig(ProxySetupModel setup) { String n = "\n"; boolean ishttp = setup.getProxyType().contains("http"); boolean isp2p = "xtcp".equals(setup.getProxyType()) || "stcp".equals(setup.getProxyType()); // 基础配置 StringBuilder stringBuilder = new StringBuilder("["); // 服务名称 - StringBuilder serverName = new StringBuilder(ApplicatonStore.getAccount()+"_"+setup.getSort()); + StringBuilder serverName = new StringBuilder(ApplicatonStore.getAccount() + "_" + setup.getSort()); // p2p 服务名 if (isp2p) { if (setup.isProvider()) { @@ -169,7 +178,7 @@ public class FrpManager { serverName = new StringBuilder(EncryptionUtil.MD5_16(serverName.toString())); } else { // 访问者 - serverName.append(setup.getServerName()).append("_visitor"); + serverName = new StringBuilder(setup.getServerName()).append("_visitor"); } } else { serverName.append(ApplicatonStore.getAccount()).append("_").append(setup.getSort()); diff --git a/src/main/java/top/octopusyan/manager/http/Api.java b/src/main/java/top/octopusyan/manager/http/Api.java index 9345532..c801ea9 100644 --- a/src/main/java/top/octopusyan/manager/http/Api.java +++ b/src/main/java/top/octopusyan/manager/http/Api.java @@ -44,8 +44,8 @@ public class Api { ); /** 获取服务器配置 */ - public static PathParamApi getServerConfiguration(int node){ - return new PathParamApi<>( + public static NotParamApi getServerConfiguration(int node){ + return new NotParamApi<>( "/?page=panel&module=configuration&server="+node, HttpConstant.Method.GET ); diff --git a/src/main/java/top/octopusyan/model/ApplicatonStore.java b/src/main/java/top/octopusyan/model/ApplicatonStore.java index 438ba47..763a71d 100644 --- a/src/main/java/top/octopusyan/model/ApplicatonStore.java +++ b/src/main/java/top/octopusyan/model/ApplicatonStore.java @@ -43,6 +43,7 @@ public class ApplicatonStore { private static final SimpleBooleanProperty registerSuccess = new SimpleBooleanProperty(); private static final ObservableList proxyList = FXCollections.observableList(new ArrayList<>()); private static final SimpleIntegerProperty selectProxy = new SimpleIntegerProperty(0); + private static final SimpleStringProperty userToken = new SimpleStringProperty(); public static String selectProxyName = null; public static void setAccount(String account) { @@ -121,6 +122,18 @@ public class ApplicatonStore { proxyList.add(proxySetup); } + public static SimpleStringProperty userTokenProperty() { + return userToken; + } + + public static String getUserToken() { + return userToken.get(); + } + + public static void setUserToken(String token) { + userToken.set(token); + } + public static void selectProxy(int selectProxy) { ApplicatonStore.selectProxy.set(selectProxy); }