修复p2p监听访问服务名称问题

This commit is contained in:
octopusYan 2022-04-19 00:40:56 +08:00
parent db9a3c2272
commit bf64df28f1
5 changed files with 61 additions and 17 deletions

View File

@ -270,6 +270,8 @@ public class LoginController extends BaseController<StackPane> implements Initia
} }
// 登录成功 // 登录成功
setCsrf(); setCsrf();
// 用户token
setUSerToken();
// 记住我 // 记住我
ApplicatonStore.rememberMe(tmpPwd.get()); ApplicatonStore.rememberMe(tmpPwd.get());
// 跳转 // 跳转
@ -289,6 +291,25 @@ public class LoginController extends BaseController<StackPane> implements Initia
}); });
} }
private void setUSerToken() {
EasyHttp.builder()
.api(Api.getServerConfiguration(1))
.request(new OnHttpListener<String>() {
@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() { private void setCsrf() {
EasyHttp.builder() EasyHttp.builder()
.api(new NotParamApi<String>( .api(new NotParamApi<String>(

View File

@ -376,7 +376,8 @@ public class MainController extends BaseController<StackPane> implements Initial
copyP2pConfig.setVisible(false); copyP2pConfig.setVisible(false);
importP2pConfig.setVisible(true); importP2pConfig.setVisible(true);
if (!children.contains(serverNamePane)) children.add(children.size() - 3, serverNamePane); if (!children.contains(serverNamePane)) children.add(children.size() - 3, serverNamePane);
proxySetupModel.setServerName(""); String serverName = proxySetupModel.getServerName();
proxySetupModel.setServerName("提供者".equals(serverName) ? "" : serverName);
} }
ObservableList<Node> children = p2pRolePane.getChildren(); ObservableList<Node> children = p2pRolePane.getChildren();
JFXButton remove = proxySetupModel.isProvider ? importP2pConfig : copyP2pConfig; JFXButton remove = proxySetupModel.isProvider ? importP2pConfig : copyP2pConfig;
@ -547,7 +548,7 @@ public class MainController extends BaseController<StackPane> implements Initial
ProxySetup setup = proxySetupModel.get(); ProxySetup setup = proxySetupModel.get();
String serverName = getAccount() + "_" + setup.getSort(); 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.setId(null);
setup.setRuning(false); setup.setRuning(false);
setup.setSort(null); setup.setSort(null);

View File

@ -129,6 +129,7 @@ public class FrpManager {
} }
frpcConfigFile.deleteOnExit(); frpcConfigFile.deleteOnExit();
// 写入服务配置 // 写入服务配置
FileUtils.write(frpcConfigFile, getUserFrpServerConfig(model.get().getNode()), StandardCharsets.UTF_8); 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); String config = serverConfigraution.get(node);
if (StringUtils.isNotEmpty(config)) return config; if (StringUtils.isNotEmpty(config) && !isp2p) return config;
try { try {
if (StringUtils.isEmpty(config)) {
String result = EasyHttp.builder() String result = EasyHttp.builder()
.api(Api.getServerConfiguration(node)) .api(Api.getServerConfiguration(node))
.pathParam(String.valueOf(node))
.execute(new ResponseClass<String>() { .execute(new ResponseClass<String>() {
}); });
config = JsoupUtil.getServerConfiguration(result); config = JsoupUtil.getServerConfiguration(result);
if (StringUtils.isNotEmpty(config)) serverConfigraution.put(node, config); if (StringUtils.isNotEmpty(config)) serverConfigraution.put(node, config);
}
// user配置 会加在访问服务端名称的前边 , 清空让访问到
if (isp2p && !model.isProvider())
config = config.replaceAll("user = .*", "");
return config; return config;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -154,7 +163,7 @@ public class FrpManager {
return null; return null;
} }
public static String getProxyFrpConfig(ProxySetupModel setup) { public String getProxyFrpConfig(ProxySetupModel setup) {
String n = "\n"; String n = "\n";
boolean ishttp = setup.getProxyType().contains("http"); boolean ishttp = setup.getProxyType().contains("http");
boolean isp2p = "xtcp".equals(setup.getProxyType()) || "stcp".equals(setup.getProxyType()); boolean isp2p = "xtcp".equals(setup.getProxyType()) || "stcp".equals(setup.getProxyType());
@ -169,7 +178,7 @@ public class FrpManager {
serverName = new StringBuilder(EncryptionUtil.MD5_16(serverName.toString())); serverName = new StringBuilder(EncryptionUtil.MD5_16(serverName.toString()));
} else { } else {
// 访问者 // 访问者
serverName.append(setup.getServerName()).append("_visitor"); serverName = new StringBuilder(setup.getServerName()).append("_visitor");
} }
} else { } else {
serverName.append(ApplicatonStore.getAccount()).append("_").append(setup.getSort()); serverName.append(ApplicatonStore.getAccount()).append("_").append(setup.getSort());

View File

@ -44,8 +44,8 @@ public class Api {
); );
/** 获取服务器配置 */ /** 获取服务器配置 */
public static PathParamApi<String> getServerConfiguration(int node){ public static NotParamApi<String> getServerConfiguration(int node){
return new PathParamApi<>( return new NotParamApi<>(
"/?page=panel&module=configuration&server="+node, "/?page=panel&module=configuration&server="+node,
HttpConstant.Method.GET HttpConstant.Method.GET
); );

View File

@ -43,6 +43,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);
private static final SimpleStringProperty userToken = new SimpleStringProperty();
public static String selectProxyName = null; public static String selectProxyName = null;
public static void setAccount(String account) { public static void setAccount(String account) {
@ -121,6 +122,18 @@ public class ApplicatonStore {
proxyList.add(proxySetup); 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) { public static void selectProxy(int selectProxy) {
ApplicatonStore.selectProxy.set(selectProxy); ApplicatonStore.selectProxy.set(selectProxy);
} }