diff --git a/src/main/java/top/octopusyan/YanFrpApplication.java b/src/main/java/top/octopusyan/YanFrpApplication.java
index 0912428..45612b7 100644
--- a/src/main/java/top/octopusyan/YanFrpApplication.java
+++ b/src/main/java/top/octopusyan/YanFrpApplication.java
@@ -3,7 +3,6 @@ package top.octopusyan;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.fxml.FXMLLoader;
-import javafx.fxml.JavaFXBuilderFactory;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
@@ -12,13 +11,14 @@ import javafx.stage.StageStyle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import top.octopusyan.base.BaseController;
+import top.octopusyan.http.OkHttpClientConfig;
+import top.octopusyan.manager.FrpManager;
import top.octopusyan.manager.http.HttpConfig;
import top.octopusyan.manager.http.config.LogStrategy;
import top.octopusyan.manager.http.request.RequestHandler;
-import top.octopusyan.http.OkHttpClientConfig;
+import top.octopusyan.model.ApplicatonStore;
import top.octopusyan.utils.AlertUtil;
-import top.octopusyan.utils.ApplicatonStore;
-import top.octopusyan.utils.FrpUtil;
+import top.octopusyan.utils.EncryptionUtil;
import top.octopusyan.utils.FxmlUtil;
/**
@@ -35,8 +35,14 @@ public class YanFrpApplication extends Application {
super.init();
logger.info("init...");
+ // 初始化加密工具
+ EncryptionUtil.init();
+
+ // 初始化应用数据
+ ApplicatonStore.init();
+
// 初始化frp客户端临时文件
- FrpUtil.initFrpc();
+ FrpManager.initFrpc();
// 网络请求设置
HttpConfig.with(OkHttpClientConfig.httpClient())
@@ -64,8 +70,6 @@ public class YanFrpApplication extends Application {
// 初始化弹窗
AlertUtil.initOwner(stage);
- // 初始化应用数据
- ApplicatonStore.setRegisterSuccess(false);
try {
// 静态写法无法获取controler
@@ -102,7 +106,7 @@ public class YanFrpApplication extends Application {
@Override
public void stop() throws Exception {
super.stop();
- FrpUtil.clearTmp();
+ FrpManager.clearTmp();
logger.info("stop...");
}
diff --git a/src/main/java/top/octopusyan/YanFrpLuncher.java b/src/main/java/top/octopusyan/YanFrpLuncher.java
index 76db4fe..32db0e4 100644
--- a/src/main/java/top/octopusyan/YanFrpLuncher.java
+++ b/src/main/java/top/octopusyan/YanFrpLuncher.java
@@ -1,24 +1,9 @@
package top.octopusyan;
import javafx.application.Application;
-import javafx.application.Platform;
-import javafx.fxml.FXMLLoader;
-import javafx.scene.Scene;
-import javafx.scene.layout.StackPane;
-import javafx.scene.paint.Color;
-import javafx.stage.Stage;
-import javafx.stage.StageStyle;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import top.octopusyan.base.BaseController;
-import top.octopusyan.http.OkHttpClientConfig;
-import top.octopusyan.manager.http.HttpConfig;
-import top.octopusyan.manager.http.config.LogStrategy;
-import top.octopusyan.manager.http.request.RequestHandler;
-import top.octopusyan.utils.AlertUtil;
-import top.octopusyan.utils.ApplicatonStore;
-import top.octopusyan.utils.FrpUtil;
-import top.octopusyan.utils.FxmlUtil;
+import top.octopusyan.manager.FrpManager;
+
+import java.io.IOException;
/**
* @author : octopus yan
@@ -28,6 +13,12 @@ import top.octopusyan.utils.FxmlUtil;
*/
public class YanFrpLuncher {
public static void main(String[] args) {
+ try {
+ Runtime.getRuntime().exec("Taskkill /IM " + FrpManager.FRPC_CLIENT_FILE_NAME + " /f");
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
Application.launch(YanFrpApplication.class, args);
}
}
diff --git a/src/main/java/top/octopusyan/base/BaseController.java b/src/main/java/top/octopusyan/base/BaseController.java
index 174ac65..f6423fb 100644
--- a/src/main/java/top/octopusyan/base/BaseController.java
+++ b/src/main/java/top/octopusyan/base/BaseController.java
@@ -12,6 +12,9 @@ import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
+import top.octopusyan.manager.FrpManager;
+import top.octopusyan.manager.http.EasyHttp;
+import top.octopusyan.model.ApplicatonStore;
import top.octopusyan.utils.FxmlUtil;
import top.octopusyan.utils.Loading;
@@ -184,11 +187,18 @@ public abstract class BaseController implements Initializable {
* 关闭窗口
*/
public void onDestroy() {
+ // 取消所有请求
+ EasyHttp.cancel();
+ // 停止所有代理隧道
+ FrpManager.frpcList.forEach(FrpManager::stop);
+ // 保存应用数据
+ ApplicatonStore.save();
+
Stage stage = (Stage) getRootPanel().getScene().getWindow();
stage.hide();
stage.close();
try {
- Thread.sleep(2000);
+ Thread.sleep(1000);
Platform.exit();
System.exit(0);
} catch (InterruptedException e) {
diff --git a/src/main/java/top/octopusyan/config/ProxyConfig.java b/src/main/java/top/octopusyan/config/ProxyConfig.java
index c7b34f9..9fff32d 100644
--- a/src/main/java/top/octopusyan/config/ProxyConfig.java
+++ b/src/main/java/top/octopusyan/config/ProxyConfig.java
@@ -31,6 +31,7 @@ public class ProxyConfig {
typePort.put("https", 80);
typePort.put("ssh", 22);
typePort.put("tcp", 0);
+ typePort.put("udp", 0);
}
@@ -60,6 +61,7 @@ public class ProxyConfig {
HTTPS("https"),
SSH("tcp"),
TCP("tcp"),
+ UDP("udp"),
;
private final String type;
diff --git a/src/main/java/top/octopusyan/config/TextValidate.java b/src/main/java/top/octopusyan/config/TextValidate.java
index d5655f6..4d24786 100644
--- a/src/main/java/top/octopusyan/config/TextValidate.java
+++ b/src/main/java/top/octopusyan/config/TextValidate.java
@@ -4,7 +4,6 @@ import com.jfoenix.validation.RegexValidator;
import com.jfoenix.validation.RequiredFieldValidator;
import com.jfoenix.validation.StringLengthValidator;
import com.jfoenix.validation.base.ValidatorBase;
-import top.octopusyan.config.ProxyConfig;
import top.octopusyan.model.ProxySetupModel;
import top.octopusyan.utils.DomainUtil;
@@ -100,12 +99,19 @@ public class TextValidate {
*/
public static ValidatorBase domainFormatValidator(ProxySetupModel model) {
- return new ValidatorBase("域名格式错误") {
+ return new ValidatorBase("域名格式错误,支持数字字母下划线") {
@Override
protected void eval() {
- if (!DomainUtil.isCustomize(model.get()))
- hasErrors.set(false);
- else {
+ if (!DomainUtil.isCustomize(model.get())) {
+ if (DomainUtil.isHttp(model)) {
+ // http / https
+ boolean matches = Pattern.compile("^[a-zA-Z0-9_-]{3,18}$").matcher(model.getDomain()).matches();
+ hasErrors.set(!matches);
+ } else {
+ // tcp / udp
+ hasErrors.set(false);
+ }
+ } else {
boolean matches = Pattern.compile("^(?=^.{3,255}$)[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+$")
.matcher(model.getDomain() + model.getDomainSuffix()).matches();
hasErrors.set(!matches);
@@ -119,7 +125,7 @@ public class TextValidate {
*/
public static ValidatorBase domainLengthValidator(ProxySetupModel model) {
- return new RegexValidator("请输入子域名,长度不小于3个字符") {
+ return new RegexValidator("子域名长度不小于3个字符") {
@Override
protected void eval() {
setRegexPattern("^[a-zA-Z0-9_-]{3,18}$");
diff --git a/src/main/java/top/octopusyan/controller/LoginController.java b/src/main/java/top/octopusyan/controller/LoginController.java
index dca73da..0384272 100644
--- a/src/main/java/top/octopusyan/controller/LoginController.java
+++ b/src/main/java/top/octopusyan/controller/LoginController.java
@@ -5,6 +5,7 @@ import com.jfoenix.controls.JFXCheckBox;
import com.jfoenix.controls.JFXPasswordField;
import com.jfoenix.controls.JFXTextField;
import javafx.application.Platform;
+import javafx.beans.property.SimpleStringProperty;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
@@ -17,14 +18,18 @@ import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.kordamp.ikonli.javafx.FontIcon;
import top.octopusyan.base.BaseController;
+import top.octopusyan.config.TextValidate;
+import top.octopusyan.http.Api;
+import top.octopusyan.http.request.FindPassParam;
+import top.octopusyan.http.request.LoginParam;
+import top.octopusyan.manager.ProxyManager;
import top.octopusyan.manager.http.EasyHttp;
import top.octopusyan.manager.http.api.NotParamApi;
import top.octopusyan.manager.http.config.HttpConstant;
import top.octopusyan.manager.http.listener.OnHttpListener;
-import top.octopusyan.config.TextValidate;
-import top.octopusyan.http.Api;
-import top.octopusyan.http.request.LoginParam;
-import top.octopusyan.utils.*;
+import top.octopusyan.model.ApplicatonStore;
+import top.octopusyan.utils.AlertUtil;
+import top.octopusyan.utils.JsoupUtil;
import java.io.IOException;
@@ -69,8 +74,10 @@ public class LoginController extends BaseController implements Initia
public JFXCheckBox autoLoginCBox;
@FXML
public JFXCheckBox rememberCBox;
+ @FXML
+ public JFXButton findpassBtn;
- private boolean autoLogin;
+ private SimpleStringProperty tmppwd = new SimpleStringProperty();
@Override
public boolean dragWindow() {
@@ -105,19 +112,27 @@ public class LoginController extends BaseController implements Initia
@Override
public void initData() {
- String account = ApplicatonStore.getAccount();
- String password = ApplicatonStore.getPassword();
+ // 数据绑定
+ // 账号
+ accountTextField.textProperty().bindBidirectional(ApplicatonStore.accountProperty());
+ // 密码
+ if (ApplicatonStore.isRememberMe()) tmppwd.set(ApplicatonStore.getPassword());
+ // 自动登录
+ autoLoginCBox.selectedProperty().bindBidirectional(ApplicatonStore.autoLoginProperty());
+ // 记住我
+ rememberCBox.selectedProperty().bindBidirectional(ApplicatonStore.rememberMeProperty());
+
+
+ passwordTextField.textProperty().bindBidirectional(tmppwd);
+ seePwdTextField.textProperty().bindBidirectional(tmppwd);
- if (!StringUtils.isEmpty(account)) accountTextField.setText(account);
- if (!StringUtils.isEmpty(password)) {
- passwordTextField.setText(password);
- seePwdTextField.setText(password);
- }
}
// 隐藏展示密码框
private AnchorPane pwdParent;
+ private AlertUtil.Builder findpassAlert;
+
@Override
public void initViewStyle() {
@@ -136,11 +151,6 @@ public class LoginController extends BaseController implements Initia
pwdParent = (AnchorPane) passwordTextField.getParent();
pwdParent.getChildren().remove(seePwdTextField);
- // 同步用户数据
- accountTextField.textProperty().addListener((observable, oldValue, newValue) -> ApplicatonStore.setAccount(newValue));
- passwordTextField.textProperty().addListener((observable, oldValue, newValue) -> ApplicatonStore.setPassword(newValue));
- seePwdTextField.textProperty().addListener((observable, oldValue, newValue) -> ApplicatonStore.setPassword(newValue));
-
// 添加文本校验
accountTextField.getValidators().add(TextValidate.AccoountRequired);
accountTextField.getValidators().add(TextValidate.AccoountValidator);
@@ -148,12 +158,9 @@ public class LoginController extends BaseController implements Initia
passwordTextField.getValidators().add(TextValidate.PasswordRequired);
seePwdTextField.getValidators().add(TextValidate.PasswordRequired);
- // 记住密码
- rememberCBox.selectedProperty().addListener((observable, oldValue, newValue) -> ApplicatonStore.setRememberMe(newValue));
// 自动登录
autoLoginCBox.selectedProperty().addListener((observable, oldValue, newValue) -> {
- ApplicatonStore.setAutoLogin(newValue);
- if (newValue && !ApplicatonStore.isRememberMe()) rememberCBox.selectedProperty().set(true);
+ if (newValue) ApplicatonStore.setRememberMe(true);
});
}
@@ -162,6 +169,7 @@ public class LoginController extends BaseController implements Initia
// 注册
registerBtn.setOnMouseClicked(event -> {
+ ApplicatonStore.setPassword(tmppwd.get());
try {
jumpTo(new RegisterController());
} catch (IOException e) {
@@ -175,7 +183,7 @@ public class LoginController extends BaseController implements Initia
pwdParent.getChildren().remove(isHide ? passwordTextField : seePwdTextField);
pwdParent.getChildren().add(1, isHide ? seePwdTextField : passwordTextField);
- (isHide ? seePwdTextField : passwordTextField).setText(ApplicatonStore.getPassword());
+ (isHide ? seePwdTextField : passwordTextField).setText(tmppwd.get());
seePwdIcon.setIconColor(isHide ? Color.BLUE : Color.BLACK);
});
@@ -188,6 +196,14 @@ public class LoginController extends BaseController implements Initia
if (event.getCode() == KeyCode.ENTER) login();
});
+ // 找回密码
+ findpassBtn.setOnMouseClicked(event -> {
+ findpassAlert = AlertUtil.input("请输入您的账号或邮箱")
+ .title("找回密码")
+ .header(null);
+ findpass(findpassAlert.getInput());
+ });
+
// 自动登录
if ((ApplicatonStore.isAutoLogin() || ApplicatonStore.isRegisterSuccess()) &&
!StringUtils.isEmpty(ApplicatonStore.getAccount()) &&
@@ -197,6 +213,33 @@ public class LoginController extends BaseController implements Initia
}
}
+ /**
+ * 找回密码
+ */
+ private void findpass(String input) {
+ if (StringUtils.isNotEmpty(input))
+ EasyHttp.builder()
+ .api(Api.findpass)
+ .param(new FindPassParam(input))
+ .request(new OnHttpListener() {
+ @Override
+ public void onSucceed(String result) {
+ Platform.runLater(() -> {
+ if (JsoupUtil.isAlertSuccess(result)) {
+ AlertUtil.info(JsoupUtil.getSuccessMessage(result)).show();
+ } else {
+ AlertUtil.error(JsoupUtil.getErrorMessage(result)).show();
+ }
+ });
+ }
+
+ @Override
+ public void onFail(Exception e) {
+ Platform.runLater(() -> AlertUtil.exceptionAlert(e).show());
+ }
+ });
+ }
+
private void login() {
// 获取文本校验结果
@@ -207,7 +250,7 @@ public class LoginController extends BaseController implements Initia
if (pwdValidate && accountValidate)
EasyHttp.builder()
.api(Api.Login)
- .param(new LoginParam(accountTextField.getText(), ApplicatonStore.getPassword()))
+ .param(new LoginParam(accountTextField.getText(), tmppwd.get()))
.request(new OnHttpListener() {
@Override
public void onSucceed(String result) {
@@ -216,8 +259,11 @@ public class LoginController extends BaseController implements Initia
Platform.runLater(() -> AlertUtil.error(JsoupUtil.getErrorMessage(result)).show());
return;
}
- // TODO 登录成功
+ // 登录成功
setCsrf();
+ // 记住我
+ ApplicatonStore.rememberMe(tmppwd.get());
+ // 跳转
Platform.runLater(() -> {
try {
jumpTo(new MainController());
@@ -243,7 +289,7 @@ public class LoginController extends BaseController implements Initia
.request(new OnHttpListener() {
@Override
public void onSucceed(String result) {
- ProxyUtil.setCsrf(result);
+ ProxyManager.setCsrf(result);
}
@Override
@@ -255,7 +301,6 @@ public class LoginController extends BaseController implements Initia
@Override
public void onDestroy() {
- EasyHttp.cancel();
super.onDestroy();
}
}
diff --git a/src/main/java/top/octopusyan/controller/MainController.java b/src/main/java/top/octopusyan/controller/MainController.java
index d1c3e87..33af128 100644
--- a/src/main/java/top/octopusyan/controller/MainController.java
+++ b/src/main/java/top/octopusyan/controller/MainController.java
@@ -1,23 +1,17 @@
package top.octopusyan.controller;
import com.jfoenix.controls.*;
-import com.jfoenix.validation.IntegerValidator;
-import com.jfoenix.validation.RequiredFieldValidator;
-import javafx.application.HostServices;
import javafx.application.Platform;
import javafx.beans.property.SimpleBooleanProperty;
-import javafx.beans.property.SimpleIntegerProperty;
-import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.ObservableList;
-import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
-import javafx.scene.control.*;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
-import javafx.scene.input.MouseEvent;
+import javafx.scene.control.*;
+import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import org.apache.commons.lang3.StringUtils;
@@ -26,21 +20,24 @@ import top.octopusyan.base.BaseController;
import top.octopusyan.config.ProxyConfig;
import top.octopusyan.config.ProxyConfig.ProxyServer;
import top.octopusyan.config.ProxyConfig.ProxyType;
+import top.octopusyan.config.TextValidate;
import top.octopusyan.http.request.ProxySetup;
+import top.octopusyan.manager.FrpManager;
+import top.octopusyan.manager.ProxyManager;
import top.octopusyan.manager.http.listener.OnHttpListener;
+import top.octopusyan.model.ApplicatonStore;
import top.octopusyan.model.ProxySetupModel;
import top.octopusyan.utils.AlertUtil;
import top.octopusyan.utils.DomainUtil;
-import top.octopusyan.utils.FrpUtil;
-import top.octopusyan.utils.ProxyUtil;
-import top.octopusyan.config.TextValidate;
import java.awt.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.io.IOException;
-import java.util.*;
import java.util.List;
+import java.util.*;
+
+import static top.octopusyan.model.ApplicatonStore.*;
/**
* @author : octopus yan
@@ -55,7 +52,6 @@ public class MainController extends BaseController implements Initial
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_SELECT_CLASS = "proxyListItem-select";
- public static final String INPUT_LEFT_CLASS = "inputText-left";
public static final String INPUT_CLASS = "inputText";
@FXML
@@ -94,15 +90,15 @@ public class MainController extends BaseController implements Initial
public Hyperlink domainLink;
@FXML
public HBox proxyStatusPane;
+ @FXML
+ public JFXButton logoutBtn;
private ToggleGroup openProxyGroup = new ToggleGroup();
private SimpleBooleanProperty customizeDomain = new SimpleBooleanProperty(false);
- private List proxyList = new ArrayList<>();
- private Map frpUtilMap = new HashMap<>();
- private SimpleIntegerProperty selectProxy = new SimpleIntegerProperty(0);
+ private Map frpUtilMap = new HashMap<>();
private ProxySetupModel proxySetupModel;
private ProxySetup proxySetup;
- private SimpleBooleanProperty setting = new SimpleBooleanProperty(false);
+ private SimpleBooleanProperty setup = new SimpleBooleanProperty(false);
@Override
public boolean dragWindow() {
@@ -138,8 +134,12 @@ public class MainController extends BaseController implements Initial
@Override
public void initData() {
// 初始化视图模型
- proxySetup = ProxyUtil.initProxy(null);
+ proxySetup = ProxyManager.initProxy(null);
proxySetupModel = new ProxySetupModel(proxySetup);
+ // 初始化用户隧道列表
+ setProxyList(Collections.singletonList(proxySetup));
+ // 重置隧道列表视图
+ initProxyListView();
// 隧道类型
Arrays.asList(ProxyType.values()).forEach((type) -> proxyProtocolComboBox.getItems().add(type.name()));
@@ -148,24 +148,26 @@ public class MainController extends BaseController implements Initial
Arrays.asList(ProxyServer.values()).forEach((server) -> proxyServerComboBox.getItems().add(server.getServerName()));
// 获取用户隧道列表
- ProxyUtil.getList(new OnHttpListener>() {
+ ProxyManager.getList(new OnHttpListener>() {
@Override
public void onSucceed(List result) {
- if (result != null)
- proxyList = result;
+ Platform.runLater(() -> {
- // 如果用户隧道列表不为空
- if (proxyList != null && proxyList.size() > 0) {
- // 显示隧道列表
- initProxyList(proxyList);
- // 默认选中第一个(配置隧道设置模型)
- proxyListView.getSelectionModel().select(0);
- } else {
- // 配置隧道设置模型
- proxyList = new ArrayList<>();
- proxyList.add(proxySetup);
- }
+ // 如果用户隧道列表不为空
+ if (result != null && result.size() > 0) {
+ proxySetup = result.get(selectProxy());
+ proxySetupModel.set(result.get(selectProxy()));
+ // 初始化用户隧道列表
+ setProxyList(result);
+ // 重置隧道列表视图
+ initProxyListView();
+ }
+// else {
+// }
+//
+// bindDataView();
+ });
}
@Override
@@ -199,6 +201,8 @@ public class MainController extends BaseController implements Initial
@Override
public void initViewStyle() {
+ // 设置列表
+ proxyListView.getSelectionModel().select(0);
// 启用链接
openProxyRBtn.setToggleGroup(openProxyGroup);
closeProxyRBtn.setToggleGroup(openProxyGroup);
@@ -232,7 +236,8 @@ public class MainController extends BaseController implements Initial
// 隧道名称
proxySetupModel.proxyNameProperty().addListener((observable, oldValue, newValue) -> {
- proxyListView.getItems().get(selectProxy.get()).setText(newValue);
+ if (proxyListView.getItems().size() > 0)
+ proxyListView.getItems().get(selectProxy()).setText(newValue);
});
// 运行状态监听
@@ -245,42 +250,29 @@ public class MainController extends BaseController implements Initial
startProxyBtn.getStyleClass().add(newValue ? stopClass : startClass);
startProxyBtn.setText(newValue ? "停止" : "启动");
// 列表显示
- ObservableList styleClass = proxyListView.getItems().get(selectProxy.get()).getStyleClass();
+ ObservableList styleClass = proxyListView.getItems().get(selectProxy()).getStyleClass();
styleClass.remove(PROXY_LIST_ITEM_RUN_CLASS);
styleClass.remove(PROXY_LIST_ITEM_STOP_CLASS);
styleClass.add(newValue ? PROXY_LIST_ITEM_RUN_CLASS : PROXY_LIST_ITEM_STOP_CLASS);
- // 外网访问连接
- if (DomainUtil.isHttp(proxySetupModel)) {
- // http / TODO https
-// String prefix = DomainUtil.isHttps(proxySetupModel) ? "https://" : "http://";
-// domainLink.textProperty().set(prefix + proxySetupModel.getDomain() + proxySetupModel.getDomainSuffix());
- domainLink.textProperty().set(proxySetupModel.getDomain() + proxySetupModel.getDomainSuffix());
- } else {
- // ssh / tcp
- domainLink.textProperty().set(ProxyConfig.getServerIP(ProxyConfig.getServerNode(proxySetupModel.getServer())) + ":" + proxySetupModel.getRemotePort());
- }
+ setDomainLink();
});
// 自定义外网访问地址按钮
customizeDomain.addListener((observable, oldValue, newValue) -> {
- HBox parent = (HBox) domainTextField.getParent();
- ObservableList styleClass = domainTextField.getStyleClass();
- styleClass.remove(INPUT_LEFT_CLASS);
- styleClass.remove(INPUT_CLASS);
+ AnchorPane parent = (AnchorPane) domainTextField.getParent();
// 是否切换为自定义域名
if (newValue) {
// 隐藏系统域名
if (parent.getChildren().contains(domainSuffixTextField))
parent.getChildren().remove(domainSuffixTextField);
// 用户域名是否自定义
- if (!DomainUtil.isCustomize(proxySetup)) {
+ if (!DomainUtil.isCustomize(proxySetupModel.get())) {
proxySetupModel.setDomain("");
} else {
- proxySetupModel.setDomain(proxySetup.getDomain());
+ proxySetupModel.setDomain(proxySetupModel.getDomain());
}
proxySetupModel.setDomainSuffix("");
- styleClass.add(INPUT_CLASS);
domainTextField.promptTextProperty().set("自定义域名");
customizeDomainBtn.setText("系统分配");
domainHtinTextField.setText("请输入您的域名,并解析至: " + ProxyConfig.getServerIP(proxySetupModel.getServer()));
@@ -289,14 +281,13 @@ public class MainController extends BaseController implements Initial
if (!parent.getChildren().contains(domainSuffixTextField))
parent.getChildren().add(domainSuffixTextField);
// 用户域名是否自定义
- if (DomainUtil.isCustomize(proxySetup)) {
+ if (DomainUtil.isCustomize(proxySetupModel.get())) {
proxySetupModel.setDomain("");
proxySetupModel.setDomainSuffix("." + ProxyConfig.getServerPath(proxySetupModel.getServer()));
} else {
- proxySetupModel.setDomain(DomainUtil.getCustomize(proxySetup));
+ proxySetupModel.setDomain(DomainUtil.getCustomize(proxySetupModel.get()));
proxySetupModel.setDomainSuffix(DomainUtil.getSuffix(proxySetup));
}
- styleClass.add(INPUT_LEFT_CLASS);
domainTextField.promptTextProperty().set("自定义子域名 大于3位");
customizeDomainBtn.setText("自定义");
domainHtinTextField.setText("请输入子域名,长度不小于3个字符");
@@ -307,10 +298,27 @@ public class MainController extends BaseController implements Initial
tabPane.getSelectionModel().select(1);
}
+ /** 设置访问链接 */
+ private void setDomainLink() {
+ // 外网访问连接
+ if (DomainUtil.isHttp(proxySetupModel)) {
+ // http / https
+ String prefix = proxySetupModel.getProxyType() + "://";
+ domainLink.textProperty().set(prefix + proxySetupModel.getDomain() + proxySetupModel.getDomainSuffix());
+ } else {
+ // ssh / tcp
+ domainLink.textProperty().set(ProxyConfig.getServerIP(ProxyConfig.getServerNode(proxySetupModel.getServer())) + ":" + proxySetupModel.getRemotePort());
+ }
+ }
+
@Override
public void initViewAction() {
// 重置
- resetProxyBtn.setOnMouseClicked(event -> proxySetupModel.set(proxySetup));
+ resetProxyBtn.setOnMouseClicked(event -> {
+ proxySetup.setRuning(false);
+ proxySetupModel.set(proxySetup);
+ domainTextField.resetValidation();
+ });
// 日志清理
clearLogBtn.setOnMouseClicked(event -> {
@@ -360,7 +368,7 @@ public class MainController extends BaseController implements Initial
});
// 域名检查
- setting.addListener((observable, oldValue, newValue) -> {
+ setup.addListener((observable, oldValue, newValue) -> {
if (newValue) domainTextField.validate();
});
domainTextField.textProperty().addListener((observable, oldValue, newValue) -> {
@@ -376,6 +384,9 @@ public class MainController extends BaseController implements Initial
// 点击隧道列表
proxyListView.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
ObservableList