Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions src/main/java/core/packetproxy/PrivateDNS.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public boolean isRunning() throws Exception {
return state.getState();
}

public void start(DNSSpoofingIPGetter dnsSpoofingIPGetter) {
public boolean start(DNSSpoofingIPGetter dnsSpoofingIPGetter) {
synchronized (lock) {
if (dns == null) {

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

dns = null;
state.setState(false);
return false;
}
} catch (Exception e) {

errWithStackTrace(e);
dns = null;
try {
state.setState(false);
} catch (Exception ignored) {
}
return false;
}
}
}
return true;
}

public void restart(DNSSpoofingIPGetter dnsSpoofingIPGetter) {
public boolean restart(DNSSpoofingIPGetter dnsSpoofingIPGetter) {
synchronized (lock) {
if (dns != null) {

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

dns = null;
state.setState(false);
return false;
}
} catch (Exception e) {

errWithStackTrace(e);
dns = null;
try {
state.setState(false);
} catch (Exception ignored) {
}
return false;
}
}
return true;
}

public int getConfiguredPort() {
Expand Down Expand Up @@ -236,8 +254,8 @@ public void setPort(int port, DNSSpoofingIPGetter dnsSpoofingIPGetter) {
}

try {
if (isRunning()) {
restart(dnsSpoofingIPGetter);
if (isRunning() && !restart(dnsSpoofingIPGetter)) {
state.setState(false);
}
} catch (Exception e) {
errWithStackTrace(e);
Expand Down
31 changes: 25 additions & 6 deletions src/main/java/core/packetproxy/gui/GUIOptionPrivateDNS.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
Expand Down Expand Up @@ -384,10 +385,15 @@ public String getSpoofingIP6() {
private JCheckBox createCheckBox() {
checkBox = new JCheckBox(I18nString.get("Use private DNS server"));
checkBox.addActionListener(e -> {
if (checkBox.isSelected())
privateDNS.start(new DNSSpoofingIPGetter(this));
else
if (!checkBox.isSelected()) {
privateDNS.stop();
return;
}

if (!privateDNS.start(new DNSSpoofingIPGetter(this))) {
checkBox.setSelected(false);
showPrivateDnsStartErrorDialog();
}
});
checkBox.setMinimumSize(new Dimension(Short.MAX_VALUE, checkBox.getMaximumSize().height));
return checkBox;
Expand Down Expand Up @@ -428,8 +434,13 @@ public void updateState() {

checkBox.setSelected(new ConfigBoolean("PrivateDNS").getState());
updateDnsPortFieldText(Integer.toString(privateDNS.getConfiguredPort()));
if (checkBox.isSelected())
privateDNS.start(new DNSSpoofingIPGetter(this));
if (!checkBox.isSelected()) {
return;
}
if (!privateDNS.start(new DNSSpoofingIPGetter(this))) {
checkBox.setSelected(false);
showPrivateDnsStartErrorDialog();
}
} catch (Exception e) {

errWithStackTrace(e);
Expand Down Expand Up @@ -493,12 +504,20 @@ private void restartPrivateDnsForBindingInterfaceChange() {
if (!privateDNS.isRunning()) {
return;
}
privateDNS.restart(new DNSSpoofingIPGetter(this));
if (!privateDNS.restart(new DNSSpoofingIPGetter(this))) {
checkBox.setSelected(false);
showPrivateDnsStartErrorDialog();
}
} catch (Exception e) {
errWithStackTrace(e);
}
}

private void showPrivateDnsStartErrorDialog() {
var message = I18nString.get("Failed to start private DNS server. Please check permissions and listen port.");
JOptionPane.showMessageDialog(null, message, I18nString.get("Error"), JOptionPane.ERROR_MESSAGE);
}

@Override
public void propertyChange(PropertyChangeEvent evt) {
if (CONFIGS.matches(evt)) {
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/strings_ja.properties
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ Use_*_to_apply_all_ports=全てのポートに適用するために * が使え
Use_SSL/TLS\:=SSL/TLSを利用:
Use_private_DNS_server=プライベートDNSサーバを起動する
Use_private_DNS_server_that_resolves_server_name_to_the_IP_address_of_this_pc.=サーバの名前を自分自身のIPアドレスに名前解決したいときに利用します
Failed_to_start_private_DNS_server._Please_check_permissions_and_listen_port.=プライベートDNSサーバの起動に失敗しました。権限と待ち受けポートを確認してください。
Use_OpenVPN_Server_as_Docker_Container_to_proxy_HTTP/HTTPS_without_DNS_Spoofing.=OpenVPNサーバをDocker Containerとして利用し、DNS Spoofingを用いずに通信を取得する
will_be_used_for_VPN=をOpenVPNのプロトコルとして使います
Use_OpenVPN=OpenVPNサーバを起動する
Expand Down