Commit 39c70f65 authored by Max Lv's avatar Max Lv

fix redsocks conf

parent 2e0a6fc6
...@@ -3,9 +3,7 @@ global { ...@@ -3,9 +3,7 @@ global {
cache_dir = "/data/data/com.github.shadowsocks"; cache_dir = "/data/data/com.github.shadowsocks";
server_ip = 127.0.0.1; server_ip = 127.0.0.1;
server_port = 8053; server_port = 8053;
status_ctl = on; query_method = tcp_only;
paranoid = on;
query_method = tcp_only;
min_ttl = 15m; min_ttl = 15m;
max_ttl = 1w; max_ttl = 1w;
timeout = 10; timeout = 10;
...@@ -15,7 +13,6 @@ global { ...@@ -15,7 +13,6 @@ global {
server { server {
label = "root-servers"; label = "root-servers";
root_server = on;
ip = 8.8.8.8 ip = 8.8.8.8
, 8.8.4.4 , 8.8.4.4
...@@ -24,14 +21,6 @@ server { ...@@ -24,14 +21,6 @@ server {
; ;
timeout = 5; 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 { rr {
......
...@@ -409,8 +409,8 @@ public class Shadowsocks extends PreferenceActivity implements ...@@ -409,8 +409,8 @@ public class Shadowsocks extends PreferenceActivity implements
getString(R.string.port_summary))); getString(R.string.port_summary)));
if (!settings.getString("remotePort", "").equals("")) if (!settings.getString("remotePort", "").equals(""))
portText.setSummary(settings.getString("remotePort", remotePortText.setSummary(settings.getString("remotePort",
getString(R.string.port_summary))); getString(R.string.remote_port_summary)));
if (!settings.getString("proxy", "").equals("")) if (!settings.getString("proxy", "").equals(""))
proxyText.setSummary(settings.getString("proxy", proxyText.setSummary(settings.getString("proxy",
......
...@@ -64,65 +64,42 @@ import java.util.HashSet; ...@@ -64,65 +64,42 @@ import java.util.HashSet;
public class ShadowsocksService extends Service { 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/"; public static final String BASE = "/data/data/com.github.shadowsocks/";
private static final int MSG_CONNECT_START = 0; final static String REDSOCKS_CONF = "base {" +
private static final int MSG_CONNECT_FINISH = 1; " log_debug = off;" +
private static final int MSG_CONNECT_SUCCESS = 2; " log_info = off;" +
private static final int MSG_CONNECT_FAIL = 3; " log = stderr;" +
private static final int MSG_HOST_CHANGE = 4; " daemon = on;" +
private static final int MSG_STOP_SELF = 5; " 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_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 " final static String CMD_IPTABLES_REDIRECT_ADD_HTTP = " -t nat -A OUTPUT -p tcp "
+ "--dport 80 -j REDIRECT --to 8123\n"; + "--dport 80 -j REDIRECT --to 8123\n";
final static String CMD_IPTABLES_REDIRECT_ADD_HTTPS = " -t nat -A OUTPUT -p tcp " final static String CMD_IPTABLES_REDIRECT_ADD_HTTPS = " -t nat -A OUTPUT -p tcp "
+ "--dport 443 -j REDIRECT --to 8124\n"; + "--dport 443 -j REDIRECT --to 8124\n";
final static String CMD_IPTABLES_DNAT_ADD_HTTP = " -t nat -A OUTPUT -p tcp " 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"; + "--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 " 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"; + "--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;
private static final String TAG = "ShadowsocksService"; private static final String TAG = "ShadowsocksService";
private static final String DEFAULT_HOST = "74.125.128.18";
private final static int DNS_PORT = 8053; 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[]{ private static final Class<?>[] mStartForegroundSignature = new Class[]{
int.class, Notification.class}; int.class, Notification.class};
private static final Class<?>[] mStopForegroundSignature = new Class[]{boolean.class}; private static final Class<?>[] mStopForegroundSignature = new Class[]{boolean.class};
private static final Class<?>[] mSetForegroundSignature = 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 * This is a hack see
* http://www.mail-archive.com/android-developers@googlegroups * http://www.mail-archive.com/android-developers@googlegroups
...@@ -132,20 +109,6 @@ public class ShadowsocksService extends Service { ...@@ -132,20 +109,6 @@ public class ShadowsocksService extends Service {
* reference will hopefully vanish * reference will hopefully vanish
*/ */
private static WeakReference<ShadowsocksService> sRunningInstance = null; private static WeakReference<ShadowsocksService> 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() { final Handler handler = new Handler() {
@Override @Override
public void handleMessage(Message msg) { public void handleMessage(Message msg) {
...@@ -185,6 +148,41 @@ public class ShadowsocksService extends Service { ...@@ -185,6 +148,41 @@ public class ShadowsocksService extends Service {
super.handleMessage(msg); 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() { public void startShadowsocksDaemon() {
final String cmd = String.format(BASE final String cmd = String.format(BASE
...@@ -269,6 +267,15 @@ public class ShadowsocksService extends Service { ...@@ -269,6 +267,15 @@ public class ShadowsocksService extends Service {
markServiceStarted(); 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. * Called when the activity is first created.
*/ */
...@@ -276,6 +283,7 @@ public class ShadowsocksService extends Service { ...@@ -276,6 +283,7 @@ public class ShadowsocksService extends Service {
startShadowsocksDaemon(); startShadowsocksDaemon();
startDnsDaemon(); startDnsDaemon();
startRedsocksDaemon();
setupIptables(); setupIptables();
return true; return true;
......
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