Skip to content

Commit 4eaceaf

Browse files
committed
fix: show error modal when private DNS startup fails
Show an error modal and roll back UI state when private DNS start or restart fails, with Japanese i18n text and dialog parenting to the private DNS panel for multi-display environments. Made-with: Cursor
1 parent 118524c commit 4eaceaf

3 files changed

Lines changed: 48 additions & 10 deletions

File tree

src/main/java/core/packetproxy/PrivateDNS.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public boolean isRunning() throws Exception {
149149
return state.getState();
150150
}
151151

152-
public void start(DNSSpoofingIPGetter dnsSpoofingIPGetter) {
152+
public boolean start(DNSSpoofingIPGetter dnsSpoofingIPGetter) {
153153
synchronized (lock) {
154154
if (dns == null) {
155155

@@ -162,16 +162,26 @@ public void start(DNSSpoofingIPGetter dnsSpoofingIPGetter) {
162162
state.setState(true);
163163
} else {
164164

165+
dns = null;
166+
state.setState(false);
167+
return false;
165168
}
166169
} catch (Exception e) {
167170

168171
errWithStackTrace(e);
172+
dns = null;
173+
try {
174+
state.setState(false);
175+
} catch (Exception ignored) {
176+
}
177+
return false;
169178
}
170179
}
171180
}
181+
return true;
172182
}
173183

174-
public void restart(DNSSpoofingIPGetter dnsSpoofingIPGetter) {
184+
public boolean restart(DNSSpoofingIPGetter dnsSpoofingIPGetter) {
175185
synchronized (lock) {
176186
if (dns != null) {
177187

@@ -190,12 +200,20 @@ public void restart(DNSSpoofingIPGetter dnsSpoofingIPGetter) {
190200

191201
dns = null;
192202
state.setState(false);
203+
return false;
193204
}
194205
} catch (Exception e) {
195206

196207
errWithStackTrace(e);
208+
dns = null;
209+
try {
210+
state.setState(false);
211+
} catch (Exception ignored) {
212+
}
213+
return false;
197214
}
198215
}
216+
return true;
199217
}
200218

201219
public int getConfiguredPort() {
@@ -236,8 +254,8 @@ public void setPort(int port, DNSSpoofingIPGetter dnsSpoofingIPGetter) {
236254
}
237255

238256
try {
239-
if (isRunning()) {
240-
restart(dnsSpoofingIPGetter);
257+
if (isRunning() && !restart(dnsSpoofingIPGetter)) {
258+
state.setState(false);
241259
}
242260
} catch (Exception e) {
243261
errWithStackTrace(e);

src/main/java/core/packetproxy/gui/GUIOptionPrivateDNS.java

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import javax.swing.JComboBox;
4343
import javax.swing.JComponent;
4444
import javax.swing.JLabel;
45+
import javax.swing.JOptionPane;
4546
import javax.swing.JPanel;
4647
import javax.swing.JRadioButton;
4748
import javax.swing.JTextField;
@@ -384,10 +385,15 @@ public String getSpoofingIP6() {
384385
private JCheckBox createCheckBox() {
385386
checkBox = new JCheckBox(I18nString.get("Use private DNS server"));
386387
checkBox.addActionListener(e -> {
387-
if (checkBox.isSelected())
388-
privateDNS.start(new DNSSpoofingIPGetter(this));
389-
else
388+
if (!checkBox.isSelected()) {
390389
privateDNS.stop();
390+
return;
391+
}
392+
393+
if (!privateDNS.start(new DNSSpoofingIPGetter(this))) {
394+
checkBox.setSelected(false);
395+
showPrivateDnsStartErrorDialog();
396+
}
391397
});
392398
checkBox.setMinimumSize(new Dimension(Short.MAX_VALUE, checkBox.getMaximumSize().height));
393399
return checkBox;
@@ -428,8 +434,13 @@ public void updateState() {
428434

429435
checkBox.setSelected(new ConfigBoolean("PrivateDNS").getState());
430436
updateDnsPortFieldText(Integer.toString(privateDNS.getConfiguredPort()));
431-
if (checkBox.isSelected())
432-
privateDNS.start(new DNSSpoofingIPGetter(this));
437+
if (!checkBox.isSelected()) {
438+
return;
439+
}
440+
if (!privateDNS.start(new DNSSpoofingIPGetter(this))) {
441+
checkBox.setSelected(false);
442+
showPrivateDnsStartErrorDialog();
443+
}
433444
} catch (Exception e) {
434445

435446
errWithStackTrace(e);
@@ -493,12 +504,20 @@ private void restartPrivateDnsForBindingInterfaceChange() {
493504
if (!privateDNS.isRunning()) {
494505
return;
495506
}
496-
privateDNS.restart(new DNSSpoofingIPGetter(this));
507+
if (!privateDNS.restart(new DNSSpoofingIPGetter(this))) {
508+
checkBox.setSelected(false);
509+
showPrivateDnsStartErrorDialog();
510+
}
497511
} catch (Exception e) {
498512
errWithStackTrace(e);
499513
}
500514
}
501515

516+
private void showPrivateDnsStartErrorDialog() {
517+
var message = I18nString.get("Failed to start private DNS server. Please check permissions and listen port.");
518+
JOptionPane.showMessageDialog(base, message, I18nString.get("Error"), JOptionPane.ERROR_MESSAGE);
519+
}
520+
502521
@Override
503522
public void propertyChange(PropertyChangeEvent evt) {
504523
if (CONFIGS.matches(evt)) {

src/main/resources/strings_ja.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ Use_*_to_apply_all_ports=全てのポートに適用するために * が使え
142142
Use_SSL/TLS\:=SSL/TLSを利用:
143143
Use_private_DNS_server=プライベートDNSサーバを起動する
144144
Use_private_DNS_server_that_resolves_server_name_to_the_IP_address_of_this_pc.=サーバの名前を自分自身のIPアドレスに名前解決したいときに利用します
145+
Failed_to_start_private_DNS_server._Please_check_permissions_and_listen_port.=プライベートDNSサーバの起動に失敗しました。権限と待ち受けポートを確認してください。
145146
Use_OpenVPN_Server_as_Docker_Container_to_proxy_HTTP/HTTPS_without_DNS_Spoofing.=OpenVPNサーバをDocker Containerとして利用し、DNS Spoofingを用いずに通信を取得する
146147
will_be_used_for_VPN=をOpenVPNのプロトコルとして使います
147148
Use_OpenVPN=OpenVPNサーバを起動する

0 commit comments

Comments
 (0)