修复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();
// 用户token
setUSerToken();
// 记住我
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() {
EasyHttp.builder()
.api(new NotParamApi<String>(

View File

@ -310,7 +310,7 @@ public class MainController extends BaseController<StackPane> 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<StackPane> 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<Node> children = p2pRolePane.getChildren();
JFXButton remove = proxySetupModel.isProvider ? importP2pConfig : copyP2pConfig;
@ -547,7 +548,7 @@ public class MainController extends BaseController<StackPane> 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);

View File

@ -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 {
if (StringUtils.isEmpty(config)) {
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);
}
// 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());

View File

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

View File

@ -43,6 +43,7 @@ public class ApplicatonStore {
private static final SimpleBooleanProperty registerSuccess = new SimpleBooleanProperty();
private static final ObservableList<ProxySetup> 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);
}