Commit 1e2b3c8d authored by Max Lv's avatar Max Lv

force DNS queries through socks proxy

parent e4991a30
...@@ -495,11 +495,7 @@ public class Shadowsocks extends PreferenceActivity implements ...@@ -495,11 +495,7 @@ public class Shadowsocks extends PreferenceActivity implements
public boolean serviceStart() { public boolean serviceStart() {
if (ShadowsocksService.isServiceStarted()) { if (ShadowsocksService.isServiceStarted()) {
try {
stopService(new Intent(this, ShadowsocksService.class)); stopService(new Intent(this, ShadowsocksService.class));
} catch (Exception e) {
// Nothing
}
return false; return false;
} }
...@@ -510,29 +506,6 @@ public class Shadowsocks extends PreferenceActivity implements ...@@ -510,29 +506,6 @@ public class Shadowsocks extends PreferenceActivity implements
if (isTextEmpty(proxy, getString(R.string.proxy_empty))) if (isTextEmpty(proxy, getString(R.string.proxy_empty)))
return false; return false;
if (proxy.contains("proxyofmax.appspot.com")) {
final TextView message = new TextView(this);
message.setPadding(10, 5, 10, 5);
final SpannableString s = new SpannableString(
getText(R.string.default_proxy_alert));
Linkify.addLinks(s, Linkify.WEB_URLS);
message.setText(s);
message.setMovementMethod(LinkMovementMethod.getInstance());
new AlertDialog.Builder(this)
.setTitle(R.string.warning)
.setCancelable(false)
.setIcon(android.R.drawable.ic_dialog_info)
.setNegativeButton(getString(R.string.ok_iknow),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int id) {
dialog.cancel();
}
}).setView(message).create().show();
}
String portText = settings.getString("port", ""); String portText = settings.getString("port", "");
if (isTextEmpty(portText, getString(R.string.port_empty))) if (isTextEmpty(portText, getString(R.string.port_empty)))
return false; return false;
...@@ -547,13 +520,8 @@ public class Shadowsocks extends PreferenceActivity implements ...@@ -547,13 +520,8 @@ public class Shadowsocks extends PreferenceActivity implements
return false; return false;
} }
try {
Intent it = new Intent(this, ShadowsocksService.class); Intent it = new Intent(this, ShadowsocksService.class);
startService(it); startService(it);
} catch (Exception e) {
// Nothing
return false;
}
return true; return true;
} }
......
...@@ -60,6 +60,8 @@ import java.io.*; ...@@ -60,6 +60,8 @@ import java.io.*;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.HashSet; import java.util.HashSet;
public class ShadowsocksService extends Service { public class ShadowsocksService extends Service {
...@@ -254,6 +256,20 @@ public class ShadowsocksService extends Service { ...@@ -254,6 +256,20 @@ public class ShadowsocksService extends Service {
@Override @Override
public void run() { public void run() {
boolean resolved = false;
if (appHost != null) {
InetAddress addr = null;
try {
addr = InetAddress.getByName(appHost);
} catch (UnknownHostException ignored) {
}
if (addr != null) {
appHost = addr.getHostAddress();
resolved = true;
}
}
handler.sendEmptyMessage(MSG_CONNECT_START); handler.sendEmptyMessage(MSG_CONNECT_START);
Log.d(TAG, "IPTABLES: " + Utils.getIptables()); Log.d(TAG, "IPTABLES: " + Utils.getIptables());
...@@ -261,7 +277,7 @@ public class ShadowsocksService extends Service { ...@@ -261,7 +277,7 @@ public class ShadowsocksService extends Service {
// Test for Redirect Support // Test for Redirect Support
hasRedirectSupport = Utils.getHasRedirectSupport(); hasRedirectSupport = Utils.getHasRedirectSupport();
if (handleConnection()) { if (resolved && handleConnection()) {
// Connection and forward successful // Connection and forward successful
notifyAlert(getString(R.string.forward_success), notifyAlert(getString(R.string.forward_success),
getString(R.string.service_running)); getString(R.string.service_running));
...@@ -510,10 +526,10 @@ public class ShadowsocksService extends Service { ...@@ -510,10 +526,10 @@ public class ShadowsocksService extends Service {
String cmd_bypass = Utils.getIptables() + CMD_IPTABLES_RETURN; String cmd_bypass = Utils.getIptables() + CMD_IPTABLES_RETURN;
init_sb.append(cmd_bypass.replace("-d 0.0.0.0", "--dport " + remotePort)); init_sb.append(cmd_bypass.replace("-d 0.0.0.0", "--dport " + remotePort));
init_sb.append(cmd_bypass.replace("-d 0.0.0.0", "--dport " + 53)); //init_sb.append(cmd_bypass.replace("-d 0.0.0.0", "--dport " + 53));
init_sb.append(cmd_bypass.replace("0.0.0.0", "127.0.0.1")); init_sb.append(cmd_bypass.replace("0.0.0.0", "127.0.0.1"));
init_sb.append(cmd_bypass.replace("-d 0.0.0.0", "-m owner --uid-owner " //init_sb.append(cmd_bypass.replace("-d 0.0.0.0", "-m owner --uid-owner "
+ getApplicationInfo().uid)); //+ getApplicationInfo().uid));
if (hasRedirectSupport) { if (hasRedirectSupport) {
init_sb.append(Utils.getIptables()).append(" -t nat -A OUTPUT -p udp --dport 53 -j REDIRECT --to ").append(DNS_PORT).append("\n"); init_sb.append(Utils.getIptables()).append(" -t nat -A OUTPUT -p udp --dport 53 -j REDIRECT --to ").append(DNS_PORT).append("\n");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment