Commit 9a724cd0 authored by Max Lv's avatar Max Lv

fix #148

parent b15a4604
...@@ -14,6 +14,7 @@ public class Config implements Parcelable { ...@@ -14,6 +14,7 @@ public class Config implements Parcelable {
public String profileName = "Untitled"; public String profileName = "Untitled";
public String proxy = "127.0.0.1"; public String proxy = "127.0.0.1";
public String sitekey = "null"; public String sitekey = "null";
public String route = "all";
public String encMethod = "rc4"; public String encMethod = "rc4";
public String proxiedAppString = ""; public String proxiedAppString = "";
...@@ -33,7 +34,7 @@ public class Config implements Parcelable { ...@@ -33,7 +34,7 @@ public class Config implements Parcelable {
public Config(boolean isGlobalProxy, boolean isGFWList, boolean isBypassApps, public Config(boolean isGlobalProxy, boolean isGFWList, boolean isBypassApps,
boolean isTrafficStat, boolean isUdpDns, String profileName, String proxy, String sitekey, boolean isTrafficStat, boolean isUdpDns, String profileName, String proxy, String sitekey,
String encMethod, String proxiedAppString, int remotePort, int localPort) { String encMethod, String proxiedAppString, String route, int remotePort, int localPort) {
this.isGlobalProxy = isGlobalProxy; this.isGlobalProxy = isGlobalProxy;
this.isGFWList = isGFWList; this.isGFWList = isGFWList;
this.isBypassApps = isBypassApps; this.isBypassApps = isBypassApps;
...@@ -44,6 +45,7 @@ public class Config implements Parcelable { ...@@ -44,6 +45,7 @@ public class Config implements Parcelable {
this.sitekey = sitekey; this.sitekey = sitekey;
this.encMethod = encMethod; this.encMethod = encMethod;
this.proxiedAppString = proxiedAppString; this.proxiedAppString = proxiedAppString;
this.route = route;
this.remotePort = remotePort; this.remotePort = remotePort;
this.localPort = localPort; this.localPort = localPort;
} }
...@@ -63,6 +65,7 @@ public class Config implements Parcelable { ...@@ -63,6 +65,7 @@ public class Config implements Parcelable {
sitekey = in.readString(); sitekey = in.readString();
encMethod = in.readString(); encMethod = in.readString();
proxiedAppString = in.readString(); proxiedAppString = in.readString();
route = in.readString();
remotePort = in.readInt(); remotePort = in.readInt();
localPort = in.readInt(); localPort = in.readInt();
} }
...@@ -82,6 +85,7 @@ public class Config implements Parcelable { ...@@ -82,6 +85,7 @@ public class Config implements Parcelable {
out.writeString(sitekey); out.writeString(sitekey);
out.writeString(encMethod); out.writeString(encMethod);
out.writeString(proxiedAppString); out.writeString(proxiedAppString);
out.writeString(route);
out.writeInt(remotePort); out.writeInt(remotePort);
out.writeInt(localPort); out.writeInt(localPort);
} }
......
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
<string name="dns_proxy_summary">重定向 DNS 查询到远程服务器</string> <string name="dns_proxy_summary">重定向 DNS 查询到远程服务器</string>
<string name="auto_set_gfwlist">国内路由</string> <string name="auto_set_gfwlist">国内路由</string>
<string name="auto_set_gfwlist_summary">绕过所有位于中国的网站</string> <string name="auto_set_gfwlist_summary">绕过所有位于中国的网站</string>
<string name="route_list">路由</string>
<string name="route_list_summary">绕过指定路由列表中的地址</string>
<string name="auto_set_proxy">全局代理</string> <string name="auto_set_proxy">全局代理</string>
<string name="auto_set_proxy_summary">设置系统代理</string> <string name="auto_set_proxy_summary">设置系统代理</string>
<string name="proxied_apps">局部代理</string> <string name="proxied_apps">局部代理</string>
...@@ -76,4 +78,10 @@ ...@@ -76,4 +78,10 @@
<item>手动设置</item> <item>手动设置</item>
</string-array> </string-array>
<string-array name="route_entry">
<item>全局</item>
<item>绕过局域网地址</item>
<item>绕过局域网及中国大陆地址</item>
</string-array>
</resources> </resources>
...@@ -38,7 +38,36 @@ ...@@ -38,7 +38,36 @@
<item>seed-cfb</item> <item>seed-cfb</item>
</string-array> </string-array>
<string-array name="private_list"> <string-array name="route_entry">
<item>All</item>
<item>Bypass LAN</item>
<item>Bypass LAN &amp; China</item>
</string-array>
<string-array name="route_value">
<item>all</item>
<item>bypass-lan</item>
<item>bypass-china</item>
</string-array>
<string-array name="private_route">
<item>0.0.0.0/8</item>
<item>10.0.0.0/8</item>
<item>100.64.0.0/10</item>
<item>127.0.0.0/8</item>
<item>169.254.0.0/16</item>
<item>172.16.0.0/12</item>
<item>192.0.0.0/29</item>
<item>192.0.2.0/24</item>
<item>192.88.99.0/24</item>
<item>192.168.0.0/16</item>
<item>198.18.0.0/15</item>
<item>198.51.100.0/24</item>
<item>203.0.113.0/24</item>
<item>224.0.0.0/3</item>
</string-array>
<string-array name="bypass_private_route">
<item>1.0.0.0/8</item> <item>1.0.0.0/8</item>
<item>2.0.0.0/7</item> <item>2.0.0.0/7</item>
<item>4.0.0.0/6</item> <item>4.0.0.0/6</item>
...@@ -162,7 +191,10 @@ ...@@ -162,7 +191,10 @@
<item>208.0.0.0/4</item> <item>208.0.0.0/4</item>
</string-array> </string-array>
<string-array name="chn_list_full"> <string-array name="chn_route_full">
<item>10.0.0.0/8</item>
<item>172.16.0.0/12</item>
<item>192.168.0.0/16</item>
<item>1.0.1.0/24</item> <item>1.0.1.0/24</item>
<item>1.0.2.0/23</item> <item>1.0.2.0/23</item>
<item>1.0.8.0/21</item> <item>1.0.8.0/21</item>
...@@ -222,7 +254,6 @@ ...@@ -222,7 +254,6 @@
<item>1.192.0.0/13</item> <item>1.192.0.0/13</item>
<item>1.202.0.0/15</item> <item>1.202.0.0/15</item>
<item>1.204.0.0/14</item> <item>1.204.0.0/14</item>
<item>10.0.0.0/8</item>
<item>14.0.0.0/21</item> <item>14.0.0.0/21</item>
<item>14.0.12.0/22</item> <item>14.0.12.0/22</item>
<item>14.1.0.0/22</item> <item>14.1.0.0/22</item>
...@@ -1924,7 +1955,6 @@ ...@@ -1924,7 +1955,6 @@
<item>171.116.0.0/14</item> <item>171.116.0.0/14</item>
<item>171.120.0.0/13</item> <item>171.120.0.0/13</item>
<item>171.208.0.0/12</item> <item>171.208.0.0/12</item>
<item>172.16.0.0/12</item>
<item>175.0.0.0/12</item> <item>175.0.0.0/12</item>
<item>175.16.0.0/13</item> <item>175.16.0.0/13</item>
<item>175.24.0.0/14</item> <item>175.24.0.0/14</item>
...@@ -2028,7 +2058,6 @@ ...@@ -2028,7 +2058,6 @@
<item>183.184.0.0/13</item> <item>183.184.0.0/13</item>
<item>183.192.0.0/10</item> <item>183.192.0.0/10</item>
<item>192.124.154.0/24</item> <item>192.124.154.0/24</item>
<item>192.168.0.0/16</item>
<item>192.188.170.0/24</item> <item>192.188.170.0/24</item>
<item>202.0.100.0/23</item> <item>202.0.100.0/23</item>
<item>202.0.122.0/23</item> <item>202.0.122.0/23</item>
...@@ -3970,9 +3999,8 @@ ...@@ -3970,9 +3999,8 @@
<item>223.255.252.0/23</item> <item>223.255.252.0/23</item>
</string-array> </string-array>
<string-array name="chn_list"> <string-array name="chn_route">
<item>0.0.0.0/7</item> <item>0.0.0.0/7</item>
<item>10.0.0.0/8</item>
<item>14.0.0.0/8</item> <item>14.0.0.0/8</item>
<item>27.0.0.0/8</item> <item>27.0.0.0/8</item>
<item>36.0.0.0/8</item> <item>36.0.0.0/8</item>
...@@ -4017,7 +4045,7 @@ ...@@ -4017,7 +4045,7 @@
<item>220.0.0.0/6</item> <item>220.0.0.0/6</item>
</string-array> </string-array>
<string-array name="gfw_list"> <string-array name="gfw_route">
<item>1.0.0.0/23</item> <item>1.0.0.0/23</item>
<item>1.0.4.0/22</item> <item>1.0.4.0/22</item>
<item>1.0.16.0/20</item> <item>1.0.16.0/20</item>
...@@ -8507,7 +8535,7 @@ ...@@ -8507,7 +8535,7 @@
<item>223.255.254.0/23</item> <item>223.255.254.0/23</item>
</string-array> </string-array>
<string-array name="simple_list"> <string-array name="simple_route">
<item>1.0.0.0/15</item> <item>1.0.0.0/15</item>
<item>1.2.0.0/16</item> <item>1.2.0.0/16</item>
<item>1.4.0.0/14</item> <item>1.4.0.0/14</item>
......
...@@ -32,6 +32,8 @@ ...@@ -32,6 +32,8 @@
<string name="auto_set_gfwlist">CHN Route</string> <string name="auto_set_gfwlist">CHN Route</string>
<string name="auto_set_gfwlist_summary">Bypass all sites located in China <string name="auto_set_gfwlist_summary">Bypass all sites located in China
</string> </string>
<string name="route_list">Route</string>
<string name="route_list_summary">Bypass IP addresses in the route list</string>
<string name="auto_set_proxy">Global Proxy</string> <string name="auto_set_proxy">Global Proxy</string>
<string name="auto_set_proxy_summary">Set up system-wide proxy <string name="auto_set_proxy_summary">Set up system-wide proxy
</string> </string>
......
...@@ -48,12 +48,14 @@ ...@@ -48,12 +48,14 @@
<PreferenceCategory <PreferenceCategory
android:title="@string/feature_cat"> android:title="@string/feature_cat">
<CheckBoxPreference <com.github.shadowsocks.preferences.SummaryListPreference
android:defaultValue="true" android:defaultValue="all"
android:key="isGFWList" android:key="route"
android:summary="@string/auto_set_gfwlist_summary" android:entries="@array/route_entry"
android:title="@string/auto_set_gfwlist"> android:entryValues="@array/route_value"
</CheckBoxPreference> android:summary="@string/route_list_summary"
android:title="@string/route_list">
</com.github.shadowsocks.preferences.SummaryListPreference>
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="true" android:defaultValue="true"
android:key="isGlobalProxy" android:key="isGlobalProxy"
......
...@@ -120,15 +120,15 @@ object Shadowsocks { ...@@ -120,15 +120,15 @@ object Shadowsocks {
val PREFS_NAME = "Shadowsocks" val PREFS_NAME = "Shadowsocks"
val PROXY_PREFS = Array(Key.profileName, Key.proxy, Key.remotePort, Key.localPort, Key.sitekey, val PROXY_PREFS = Array(Key.profileName, Key.proxy, Key.remotePort, Key.localPort, Key.sitekey,
Key.encMethod) Key.encMethod)
val FEATRUE_PREFS = Array(Key.isGFWList, Key.isGlobalProxy, Key.proxyedApps, val FEATRUE_PREFS = Array(Key.route, Key.isGlobalProxy, Key.proxyedApps,
Key.isUdpDns, Key.isAutoConnect) Key.isUdpDns, Key.isAutoConnect)
val EXECUTABLES = Array(Executable.PDNSD, Executable.REDSOCKS, Executable.IPTABLES) val EXECUTABLES = Array(Executable.PDNSD, Executable.REDSOCKS, Executable.IPTABLES)
// Helper functions // Helper functions
def updateListPreference(pref: Preference, value: String) { def updateListPreference(pref: Preference, value: String) {
pref.setSummary(value)
pref.asInstanceOf[ListPreference].setValue(value) pref.asInstanceOf[ListPreference].setValue(value)
pref.setSummary(pref.asInstanceOf[ListPreference].getEntry)
} }
def updatePasswordEditTextPreference(pref: Preference, value: String) { def updatePasswordEditTextPreference(pref: Preference, value: String) {
...@@ -158,7 +158,7 @@ object Shadowsocks { ...@@ -158,7 +158,7 @@ object Shadowsocks {
case Key.localPort => updateSummaryEditTextPreference(pref, profile.localPort.toString) case Key.localPort => updateSummaryEditTextPreference(pref, profile.localPort.toString)
case Key.sitekey => updatePasswordEditTextPreference(pref, profile.password) case Key.sitekey => updatePasswordEditTextPreference(pref, profile.password)
case Key.encMethod => updateListPreference(pref, profile.method) case Key.encMethod => updateListPreference(pref, profile.method)
case Key.isGFWList => updateCheckBoxPreference(pref, profile.chnroute) case Key.route => updateListPreference(pref, profile.route)
case Key.isGlobalProxy => updateCheckBoxPreference(pref, profile.global) case Key.isGlobalProxy => updateCheckBoxPreference(pref, profile.global)
case Key.isUdpDns => updateCheckBoxPreference(pref, profile.udpdns) case Key.isUdpDns => updateCheckBoxPreference(pref, profile.udpdns)
case _ => case _ =>
......
...@@ -93,19 +93,14 @@ class ShadowsocksNatService extends Service with BaseService { ...@@ -93,19 +93,14 @@ class ShadowsocksNatService extends Service with BaseService {
private lazy val application = getApplication.asInstanceOf[ShadowsocksApplication] private lazy val application = getApplication.asInstanceOf[ShadowsocksApplication]
def isACLEnabled: Boolean = {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
true
} else {
false
}
}
def startShadowsocksDaemon() { def startShadowsocksDaemon() {
if (isACLEnabled && config.isGFWList) { if (config.route != Route.ALL) {
val chn_list: Array[String] = getResources.getStringArray(R.array.chn_list_full) val acl: Array[String] = config.route match {
ConfigUtils.printToFile(new File(Path.BASE + "chn.acl"))(p => { case Route.BYPASS_LAN => getResources.getStringArray(R.array.private_route)
chn_list.foreach(item => p.println(item)) case Route.BYPASS_CHN => getResources.getStringArray(R.array.chn_route_full)
}
ConfigUtils.printToFile(new File(Path.BASE + "acl.list"))(p => {
acl.foreach(item => p.println(item))
}) })
} }
...@@ -117,11 +112,11 @@ class ShadowsocksNatService extends Service with BaseService { ...@@ -117,11 +112,11 @@ class ShadowsocksNatService extends Service with BaseService {
, "-l" , config.localPort.toString , "-l" , config.localPort.toString
, "-k" , config.sitekey , "-k" , config.sitekey
, "-m" , config.encMethod , "-m" , config.encMethod
, "-f" , (Path.BASE + "ss-local.pid")) , "-f" , Path.BASE + "ss-local.pid")
if (config.isGFWList && isACLEnabled) { if (config.route != Route.ALL) {
cmd += "--acl" cmd += "--acl"
cmd += (Path.BASE + "chn.acl") cmd += (Path.BASE + "acl.list")
} }
if (BuildConfig.DEBUG) Log.d(TAG, cmd.mkString(" ")) if (BuildConfig.DEBUG) Log.d(TAG, cmd.mkString(" "))
...@@ -140,7 +135,7 @@ class ShadowsocksNatService extends Service with BaseService { ...@@ -140,7 +135,7 @@ class ShadowsocksNatService extends Service with BaseService {
, "-p" , config.remotePort.toString , "-p" , config.remotePort.toString
, "-k" , config.sitekey , "-k" , config.sitekey
, "-m" , config.encMethod , "-m" , config.encMethod
, "-f" , (Path.BASE + "ss-tunnel.pid")) , "-f" , Path.BASE + "ss-tunnel.pid")
if (BuildConfig.DEBUG) Log.d(TAG, cmd.mkString(" ")) if (BuildConfig.DEBUG) Log.d(TAG, cmd.mkString(" "))
Core.sstunnel(cmd.toArray) Core.sstunnel(cmd.toArray)
} else { } else {
...@@ -298,15 +293,6 @@ class ShadowsocksNatService extends Service with BaseService { ...@@ -298,15 +293,6 @@ class ShadowsocksNatService extends Service with BaseService {
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 " + myUid)) init_sb.append(cmd_bypass.replace("-d 0.0.0.0", "-m owner --uid-owner " + myUid))
if (config.isGFWList) {
if (!isACLEnabled)
{
val chn_list: Array[String] = getResources.getStringArray(R.array.chn_list)
for (item <- chn_list) {
init_sb.append(cmd_bypass.replace("0.0.0.0", item))
}
}
}
if (hasRedirectSupport) { if (hasRedirectSupport) {
init_sb init_sb
.append(Utils.getIptables + " -t nat -A OUTPUT -p udp --dport 53 -j REDIRECT --to " .append(Utils.getIptables + " -t nat -A OUTPUT -p udp --dport 53 -j REDIRECT --to "
......
...@@ -64,7 +64,6 @@ class ShadowsocksVpnService extends VpnService with BaseService { ...@@ -64,7 +64,6 @@ class ShadowsocksVpnService extends VpnService with BaseService {
val TAG = "ShadowsocksVpnService" val TAG = "ShadowsocksVpnService"
val VPN_MTU = 1500 val VPN_MTU = 1500
val PRIVATE_VLAN = "26.26.26.%s" val PRIVATE_VLAN = "26.26.26.%s"
var conn: ParcelFileDescriptor = null var conn: ParcelFileDescriptor = null
...@@ -88,28 +87,47 @@ class ShadowsocksVpnService extends VpnService with BaseService { ...@@ -88,28 +87,47 @@ class ShadowsocksVpnService extends VpnService with BaseService {
info.isInRange(config.proxy) info.isInRange(config.proxy)
} }
def isPrivateA(a: Int): Boolean = {
if (a == 10 || a == 192 || a == 172) {
true
} else {
false
}
}
def isPrivateB(a: Int, b: Int): Boolean = {
if (a == 10 || (a == 192 && b == 168) || (a == 172 && b >= 16 && b < 32)) {
true
} else {
false
}
}
def startShadowsocksDaemon() { def startShadowsocksDaemon() {
if (isLollipopOrAbove && config.isGFWList) { if (isLollipopOrAbove && config.route != Route.ALL) {
val chn_list: Array[String] = getResources.getStringArray(R.array.chn_list_full) val acl: Array[String] = config.route match {
ConfigUtils.printToFile(new File(Path.BASE + "chn.acl"))(p => { case Route.BYPASS_LAN => getResources.getStringArray(R.array.private_route)
chn_list.foreach(item => p.println(item)) case Route.BYPASS_CHN => getResources.getStringArray(R.array.chn_route_full)
}
ConfigUtils.printToFile(new File(Path.BASE + "acl.list"))(p => {
acl.foreach(item => p.println(item))
}) })
} }
val cmd = new ArrayBuffer[String] val cmd = new ArrayBuffer[String]
cmd += ("ss-local" , "-u" cmd +=("ss-local", "-u"
, "-b" , "127.0.0.1" , "-b", "127.0.0.1"
, "-s" , config.proxy , "-s", config.proxy
, "-p" , config.remotePort.toString , "-p", config.remotePort.toString
, "-l" , config.localPort.toString , "-l", config.localPort.toString
, "-k" , config.sitekey , "-k", config.sitekey
, "-m" , config.encMethod , "-m", config.encMethod
, "-f" , Path.BASE + "ss-local.pid") , "-f", Path.BASE + "ss-local.pid")
if (config.isGFWList && isLollipopOrAbove) { if (isLollipopOrAbove && config.route != Route.ALL) {
cmd += "--acl" cmd += "--acl"
cmd += (Path.BASE + "chn.acl") cmd += (Path.BASE + "acl.list")
} }
if (BuildConfig.DEBUG) Log.d(TAG, cmd.mkString(" ")) if (BuildConfig.DEBUG) Log.d(TAG, cmd.mkString(" "))
...@@ -118,15 +136,15 @@ class ShadowsocksVpnService extends VpnService with BaseService { ...@@ -118,15 +136,15 @@ class ShadowsocksVpnService extends VpnService with BaseService {
def startDnsTunnel() = { def startDnsTunnel() = {
val cmd = new ArrayBuffer[String] val cmd = new ArrayBuffer[String]
cmd += ("ss-tunnel" cmd +=("ss-tunnel"
, "-b" , "127.0.0.1" , "-b", "127.0.0.1"
, "-l" , "8163" , "-l", "8163"
, "-L" , "8.8.8.8:53" , "-L", "8.8.8.8:53"
, "-s" , config.proxy , "-s", config.proxy
, "-p" , config.remotePort.toString , "-p", config.remotePort.toString
, "-k" , config.sitekey , "-k", config.sitekey
, "-m" , config.encMethod , "-m", config.encMethod
, "-f" , Path.BASE + "ss-tunnel.pid") , "-f", Path.BASE + "ss-tunnel.pid")
if (BuildConfig.DEBUG) Log.d(TAG, cmd.mkString(" ")) if (BuildConfig.DEBUG) Log.d(TAG, cmd.mkString(" "))
Core.sstunnel(cmd.toArray) Core.sstunnel(cmd.toArray)
} }
...@@ -195,52 +213,76 @@ class ShadowsocksVpnService extends VpnService with BaseService { ...@@ -195,52 +213,76 @@ class ShadowsocksVpnService extends VpnService with BaseService {
if (InetAddressUtils.isIPv6Address(config.proxy)) { if (InetAddressUtils.isIPv6Address(config.proxy)) {
builder.addRoute("0.0.0.0", 0) builder.addRoute("0.0.0.0", 0)
} else if (!isLollipopOrAbove && config.isGFWList) {
val gfwList = {
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
getResources.getStringArray(R.array.simple_list)
} else {
getResources.getStringArray(R.array.gfw_list)
}
}
gfwList.foreach(cidr => {
val net = new SubnetUtils(cidr)
if (!isByass(net)) {
val addr = cidr.split('/')
builder.addRoute(addr(0), addr(1).toInt)
}
})
} else { } else {
if (isLollipopOrAbove) { if (!isLollipopOrAbove) {
val privateList = getResources.getStringArray(R.array.private_list) config.route match {
privateList.foreach(cidr => { case Route.ALL =>
val addr = cidr.split('/') for (i <- 1 to 223) {
builder.addRoute(addr(0), addr(1).toInt) if (i != 26 && i != 127) {
}) val addr = i.toString + ".0.0.0"
} else { val cidr = addr + "/8"
for (i <- 1 to 223) { val net = new SubnetUtils(cidr)
if (i != 26 && i != 127) {
val addr = i.toString + ".0.0.0" if (!isByass(net)) {
val cidr = addr + "/8" builder.addRoute(addr, 8)
val net = new SubnetUtils(cidr) } else {
for (j <- 0 to 255) {
if (!isByass(net)) { val subAddr = i.toString + "." + j.toString + ".0.0"
if (!InetAddress.getByName(addr).isSiteLocalAddress) { val subCidr = subAddr + "/16"
builder.addRoute(addr, 8) val subNet = new SubnetUtils(subCidr)
if (!isByass(subNet)) {
builder.addRoute(subAddr, 16)
}
}
}
} }
} else { }
for (j <- 0 to 255) { case Route.BYPASS_LAN =>
val subAddr = i.toString + "." + j.toString + ".0.0" for (i <- 1 to 223) {
val subCidr = subAddr + "/16" if (i != 26 && i != 127) {
val subNet = new SubnetUtils(subCidr) val addr = i.toString + ".0.0.0"
if (!isByass(subNet)) { val cidr = addr + "/8"
if (!InetAddress.getByName(subAddr).isSiteLocalAddress) { val net = new SubnetUtils(cidr)
builder.addRoute(subAddr, 16)
if (!isByass(net) && !isPrivateA(i)) {
builder.addRoute(addr, 8)
} else {
for (j <- 0 to 255) {
val subAddr = i.toString + "." + j.toString + ".0.0"
val subCidr = subAddr + "/16"
val subNet = new SubnetUtils(subCidr)
if (!isByass(subNet) && !isPrivateB(i, j)) {
builder.addRoute(subAddr, 16)
}
} }
} }
} }
} }
} case Route.BYPASS_CHN =>
val list = {
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
getResources.getStringArray(R.array.simple_route)
} else {
getResources.getStringArray(R.array.gfw_route)
}
}
list.foreach(cidr => {
val net = new SubnetUtils(cidr)
if (!isByass(net)) {
val addr = cidr.split('/')
builder.addRoute(addr(0), addr(1).toInt)
}
})
}
} else {
if (config.route == Route.ALL) {
builder.addRoute("0.0.0.0", 0)
} else {
val privateList = getResources.getStringArray(R.array.bypass_private_route)
privateList.foreach(cidr => {
val addr = cidr.split('/')
builder.addRoute(addr(0), addr(1).toInt)
})
} }
} }
} }
...@@ -440,6 +482,8 @@ class ShadowsocksVpnService extends VpnService with BaseService { ...@@ -440,6 +482,8 @@ class ShadowsocksVpnService extends VpnService with BaseService {
} }
override def getTag = TAG override def getTag = TAG
override def getServiceMode = Mode.VPN override def getServiceMode = Mode.VPN
override def getContext = getBaseContext override def getContext = getBaseContext
} }
...@@ -51,7 +51,7 @@ object DBHelper { ...@@ -51,7 +51,7 @@ object DBHelper {
} }
class DBHelper(val context: Context) class DBHelper(val context: Context)
extends OrmLiteSqliteOpenHelper(context, DBHelper.PROFILE, null, 8) { extends OrmLiteSqliteOpenHelper(context, DBHelper.PROFILE, null, 9) {
lazy val profileDao: Dao[Profile, Int] = getDao(classOf[Profile]) lazy val profileDao: Dao[Profile, Int] = getDao(classOf[Profile])
...@@ -64,6 +64,9 @@ class DBHelper(val context: Context) ...@@ -64,6 +64,9 @@ class DBHelper(val context: Context)
if (oldVersion != newVersion) { if (oldVersion != newVersion) {
if (oldVersion < 8) { if (oldVersion < 8) {
profileDao.executeRaw("ALTER TABLE `profile` ADD COLUMN udpdns SMALLINT;") profileDao.executeRaw("ALTER TABLE `profile` ADD COLUMN udpdns SMALLINT;")
profileDao.executeRaw("ALTER TABLE `profile` ADD COLUMN route VARCHAR;")
} else if (oldVersion < 9) {
profileDao.executeRaw("ALTER TABLE `profile` ADD COLUMN route VARCHAR;")
} else { } else {
profileDao.executeRaw("DROP TABLE IF EXISTS 'profile';") profileDao.executeRaw("DROP TABLE IF EXISTS 'profile';")
onCreate(database, connectionSource) onCreate(database, connectionSource)
......
...@@ -66,6 +66,9 @@ class Profile { ...@@ -66,6 +66,9 @@ class Profile {
@DatabaseField @DatabaseField
var date: String = "" var date: String = ""
@DatabaseField
var route: String = ""
@DatabaseField @DatabaseField
var upload: Int = 0 var upload: Int = 0
......
...@@ -77,7 +77,7 @@ class ProfileManager(settings: SharedPreferences, dbHelper: DBHelper) { ...@@ -77,7 +77,7 @@ class ProfileManager(settings: SharedPreferences, dbHelper: DBHelper) {
} catch { } catch {
case ex: Exception => case ex: Exception =>
Log.e(Shadowsocks.TAG, "getProfile", ex) Log.e(Shadowsocks.TAG, "getProfile", ex)
return None None
} }
} }
...@@ -130,6 +130,7 @@ class ProfileManager(settings: SharedPreferences, dbHelper: DBHelper) { ...@@ -130,6 +130,7 @@ class ProfileManager(settings: SharedPreferences, dbHelper: DBHelper) {
edit.putString(Key.localPort, profile.localPort.toString) edit.putString(Key.localPort, profile.localPort.toString)
edit.putString(Key.proxied, profile.individual) edit.putString(Key.proxied, profile.individual)
edit.putInt(Key.profileId, profile.id) edit.putInt(Key.profileId, profile.id)
edit.putString(Key.route, profile.route)
edit.commit() edit.commit()
profile profile
...@@ -149,19 +150,18 @@ class ProfileManager(settings: SharedPreferences, dbHelper: DBHelper) { ...@@ -149,19 +150,18 @@ class ProfileManager(settings: SharedPreferences, dbHelper: DBHelper) {
profile.host = settings.getString(Key.proxy, "127.0.0.1") profile.host = settings.getString(Key.proxy, "127.0.0.1")
profile.password = settings.getString(Key.sitekey, "default") profile.password = settings.getString(Key.sitekey, "default")
profile.method = settings.getString(Key.encMethod, "table") profile.method = settings.getString(Key.encMethod, "table")
profile.route = settings.getString(Key.route, "all")
profile.remotePort = try { profile.remotePort = try {
Integer.valueOf(settings.getString(Key.remotePort, "1984")) Integer.valueOf(settings.getString(Key.remotePort, "1984"))
} catch { } catch {
case ex: NumberFormatException => { case ex: NumberFormatException =>
1984 1984
}
} }
profile.localPort = try { profile.localPort = try {
Integer.valueOf(settings.getString(Key.localPort, "1984")) Integer.valueOf(settings.getString(Key.localPort, "1984"))
} catch { } catch {
case ex: NumberFormatException => { case ex: NumberFormatException =>
1984 1984
}
} }
profile.individual = settings.getString(Key.proxied, "") profile.individual = settings.getString(Key.proxied, "")
......
...@@ -48,7 +48,7 @@ class SummaryListPreference(context: Context, attrs: AttributeSet) ...@@ -48,7 +48,7 @@ class SummaryListPreference(context: Context, attrs: AttributeSet)
override def setValue(text: String) { override def setValue(text: String) {
super.setValue(text) super.setValue(text)
setSummary(text.toUpperCase) setSummary(getEntry)
} }
override def setSummary(summary: CharSequence) { override def setSummary(summary: CharSequence) {
......
...@@ -198,7 +198,7 @@ object ConfigUtils { ...@@ -198,7 +198,7 @@ object ConfigUtils {
val method = proxy(3).trim val method = proxy(3).trim
new Config(config.isGlobalProxy, config.isGFWList, config.isBypassApps, config.isTrafficStat, new Config(config.isGlobalProxy, config.isGFWList, config.isBypassApps, config.isTrafficStat,
config.isUdpDns, config.profileName, host, password, method, config.proxiedAppString, port, config.isUdpDns, config.profileName, host, password, method, config.proxiedAppString, config.route, port,
config.localPort) config.localPort)
} }
...@@ -213,6 +213,8 @@ object ConfigUtils { ...@@ -213,6 +213,8 @@ object ConfigUtils {
val proxy = settings.getString(Key.proxy, "127.0.0.1") val proxy = settings.getString(Key.proxy, "127.0.0.1")
val sitekey = settings.getString(Key.sitekey, "default") val sitekey = settings.getString(Key.sitekey, "default")
val encMethod = settings.getString(Key.encMethod, "table") val encMethod = settings.getString(Key.encMethod, "table")
val route = settings.getString(Key.route, "all")
val remotePort: Int = try { val remotePort: Int = try {
settings.getString(Key.remotePort, "1984").toInt settings.getString(Key.remotePort, "1984").toInt
} catch { } catch {
...@@ -228,6 +230,6 @@ object ConfigUtils { ...@@ -228,6 +230,6 @@ object ConfigUtils {
val proxiedAppString = settings.getString(Key.proxied, "") val proxiedAppString = settings.getString(Key.proxied, "")
new Config(isGlobalProxy, isGFWList, isBypassApps, isTrafficStat, isUdpDns, profileName, proxy, new Config(isGlobalProxy, isGFWList, isBypassApps, isTrafficStat, isUdpDns, profileName, proxy,
sitekey, encMethod, proxiedAppString, remotePort, localPort) sitekey, encMethod, proxiedAppString, route, remotePort, localPort)
} }
} }
...@@ -68,6 +68,7 @@ object Key { ...@@ -68,6 +68,7 @@ object Key {
val isRoot = "isRoot" val isRoot = "isRoot"
val status = "status" val status = "status"
val proxyedApps = "proxyedApps" val proxyedApps = "proxyedApps"
val route = "route"
val isRunning = "isRunning" val isRunning = "isRunning"
val isAutoConnect = "isAutoConnect" val isAutoConnect = "isAutoConnect"
...@@ -110,3 +111,9 @@ object Action { ...@@ -110,3 +111,9 @@ object Action {
val UPDATE_FRAGMENT = "com.github.shadowsocks.ACTION_UPDATE_FRAGMENT" val UPDATE_FRAGMENT = "com.github.shadowsocks.ACTION_UPDATE_FRAGMENT"
val UPDATE_PREFS = "com.github.shadowsocks.ACTION_UPDATE_PREFS" val UPDATE_PREFS = "com.github.shadowsocks.ACTION_UPDATE_PREFS"
} }
object Route {
val ALL = "all"
val BYPASS_LAN = "bypass-lan"
val BYPASS_CHN = "bypass-china"
}
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