diff --git a/assets/pdnsd.conf b/assets/pdnsd.conf index 93ca5de8..98b48792 100644 --- a/assets/pdnsd.conf +++ b/assets/pdnsd.conf @@ -3,9 +3,7 @@ global { cache_dir = "/data/data/com.github.shadowsocks"; server_ip = 127.0.0.1; server_port = 8053; - status_ctl = on; - paranoid = on; - query_method = tcp_only; + query_method = tcp_only; min_ttl = 15m; max_ttl = 1w; timeout = 10; @@ -15,7 +13,6 @@ global { server { label = "root-servers"; - root_server = on; ip = 8.8.8.8 , 8.8.4.4 @@ -24,14 +21,6 @@ server { ; timeout = 5; - - uptest = query; - interval = 30m; // Test every half hour. - ping_timeout = 300; // 30 seconds. - purge_cache = off; - exclude = .localdomain; - policy = included; - preset = off; } rr { diff --git a/src/com/github/shadowsocks/Shadowsocks.java b/src/com/github/shadowsocks/Shadowsocks.java index 584a565c..13973aa2 100644 --- a/src/com/github/shadowsocks/Shadowsocks.java +++ b/src/com/github/shadowsocks/Shadowsocks.java @@ -409,8 +409,8 @@ public class Shadowsocks extends PreferenceActivity implements getString(R.string.port_summary))); if (!settings.getString("remotePort", "").equals("")) - portText.setSummary(settings.getString("remotePort", - getString(R.string.port_summary))); + remotePortText.setSummary(settings.getString("remotePort", + getString(R.string.remote_port_summary))); if (!settings.getString("proxy", "").equals("")) proxyText.setSummary(settings.getString("proxy", diff --git a/src/com/github/shadowsocks/ShadowsocksService.java b/src/com/github/shadowsocks/ShadowsocksService.java index 32ae7fbe..0675e4bf 100755 --- a/src/com/github/shadowsocks/ShadowsocksService.java +++ b/src/com/github/shadowsocks/ShadowsocksService.java @@ -64,65 +64,42 @@ import java.util.HashSet; public class ShadowsocksService extends Service { - private Notification notification; - private NotificationManager notificationManager; - private PendingIntent pendIntent; - private PowerManager.WakeLock mWakeLock; - public static final String BASE = "/data/data/com.github.shadowsocks/"; + final static String REDSOCKS_CONF = "base {" + + " log_debug = off;" + + " log_info = off;" + + " log = stderr;" + + " daemon = on;" + + " redirector = iptables;" + + "}" + + "redsocks {" + + " local_ip = 127.0.0.1;" + + " local_port = 8123;" + + " ip = 127.0.0.1;" + + " port = %d;" + + " type = socks5;" + + "}"; + final static String CMD_IPTABLES_RETURN = " -t nat -A OUTPUT -p tcp -d 0.0.0.0 -j RETURN\n"; + final static String CMD_IPTABLES_REDIRECT_ADD_HTTP = " -t nat -A OUTPUT -p tcp " + + "--dport 80 -j REDIRECT --to 8123\n"; + final static String CMD_IPTABLES_REDIRECT_ADD_HTTPS = " -t nat -A OUTPUT -p tcp " + + "--dport 443 -j REDIRECT --to 8124\n"; + final static String CMD_IPTABLES_DNAT_ADD_HTTP = " -t nat -A OUTPUT -p tcp " + + "--dport 80 -j DNAT --to-destination 127.0.0.1:8123\n"; + final static String CMD_IPTABLES_DNAT_ADD_HTTPS = " -t nat -A OUTPUT -p tcp " + + "--dport 443 -j DNAT --to-destination 127.0.0.1:8124\n"; private static final int MSG_CONNECT_START = 0; private static final int MSG_CONNECT_FINISH = 1; private static final int MSG_CONNECT_SUCCESS = 2; private static final int MSG_CONNECT_FAIL = 3; private static final int MSG_HOST_CHANGE = 4; private static final int MSG_STOP_SELF = 5; - - final static String CMD_IPTABLES_RETURN = " -t nat -A OUTPUT -p tcp -d 0.0.0.0 -j RETURN\n"; - - final static String CMD_IPTABLES_REDIRECT_ADD_HTTP = " -t nat -A OUTPUT -p tcp " - + "--dport 80 -j REDIRECT --to 8123\n"; - final static String CMD_IPTABLES_REDIRECT_ADD_HTTPS = " -t nat -A OUTPUT -p tcp " - + "--dport 443 -j REDIRECT --to 8124\n"; - - final static String CMD_IPTABLES_DNAT_ADD_HTTP = " -t nat -A OUTPUT -p tcp " - + "--dport 80 -j DNAT --to-destination 127.0.0.1:8123\n"; - final static String CMD_IPTABLES_DNAT_ADD_HTTPS = " -t nat -A OUTPUT -p tcp " - + "--dport 443 -j DNAT --to-destination 127.0.0.1:8124\n"; - private static final String TAG = "ShadowsocksService"; - private static final String DEFAULT_HOST = "74.125.128.18"; private final static int DNS_PORT = 8053; - - private Process httpProcess = null; - private DataOutputStream httpOS = null; - - private String appHost; - private int remotePort; - private int port; - private String sitekey; - - private SharedPreferences settings = null; - - private boolean hasRedirectSupport = true; - private boolean isGlobalProxy = false; - private boolean isGFWList = false; - private boolean isBypassApps = false; - - private ProxyedApp apps[]; - private static final Class[] mStartForegroundSignature = new Class[]{ int.class, Notification.class}; private static final Class[] mStopForegroundSignature = new Class[]{boolean.class}; private static final Class[] mSetForegroundSignature = new Class[]{boolean.class}; - - private Method mSetForeground; - private Method mStartForeground; - private Method mStopForeground; - - private Object[] mSetForegroundArgs = new Object[1]; - private Object[] mStartForegroundArgs = new Object[2]; - private Object[] mStopForegroundArgs = new Object[1]; - /* * This is a hack see * http://www.mail-archive.com/android-developers@googlegroups @@ -132,20 +109,6 @@ public class ShadowsocksService extends Service { * reference will hopefully vanish */ private static WeakReference sRunningInstance = null; - - public static boolean isServiceStarted() { - final boolean isServiceStarted; - if (sRunningInstance == null) { - isServiceStarted = false; - } else if (sRunningInstance.get() == null) { - isServiceStarted = false; - sRunningInstance = null; - } else { - isServiceStarted = true; - } - return isServiceStarted; - } - final Handler handler = new Handler() { @Override public void handleMessage(Message msg) { @@ -185,6 +148,41 @@ public class ShadowsocksService extends Service { super.handleMessage(msg); } }; + private Notification notification; + private NotificationManager notificationManager; + private PendingIntent pendIntent; + private PowerManager.WakeLock mWakeLock; + private Process httpProcess = null; + private DataOutputStream httpOS = null; + private String appHost; + private int remotePort; + private int port; + private String sitekey; + private SharedPreferences settings = null; + private boolean hasRedirectSupport = true; + private boolean isGlobalProxy = false; + private boolean isGFWList = false; + private boolean isBypassApps = false; + private ProxyedApp apps[]; + private Method mSetForeground; + private Method mStartForeground; + private Method mStopForeground; + private Object[] mSetForegroundArgs = new Object[1]; + private Object[] mStartForegroundArgs = new Object[2]; + private Object[] mStopForegroundArgs = new Object[1]; + + public static boolean isServiceStarted() { + final boolean isServiceStarted; + if (sRunningInstance == null) { + isServiceStarted = false; + } else if (sRunningInstance.get() == null) { + isServiceStarted = false; + sRunningInstance = null; + } else { + isServiceStarted = true; + } + return isServiceStarted; + } public void startShadowsocksDaemon() { final String cmd = String.format(BASE @@ -269,6 +267,15 @@ public class ShadowsocksService extends Service { markServiceStarted(); } + private void startRedsocksDaemon() { + String conf = String.format(REDSOCKS_CONF, port); + String cmd = String.format("%sredsocks -p %sredsocks.pid -c %sredsocks.conf", + BASE, BASE, BASE); + Utils.runRootCommand("echo \"" + conf + "\" > " + BASE + "redsocks.conf\n" + + cmd); + + } + /** * Called when the activity is first created. */ @@ -276,6 +283,7 @@ public class ShadowsocksService extends Service { startShadowsocksDaemon(); startDnsDaemon(); + startRedsocksDaemon(); setupIptables(); return true;