Commit cc5fafbd authored by Max Lv's avatar Max Lv

Merge pull request #67 from shadowsocks/udp-dns

Add UDP DNS feature
parents a029f276 a89ca2d1
...@@ -35,7 +35,7 @@ after_success: ...@@ -35,7 +35,7 @@ after_success:
- sbt deploy - sbt deploy
env: env:
global: global:
- "ARTIFACTS_AWS_REGION=ap-northeast-1" - "ARTIFACTS_AWS_REGION=us-east-1"
- "ARTIFACTS_S3_BUCKET=travis-ci" - "ARTIFACTS_S3_BUCKET=travis-nightly"
- secure: "GkAdnMh07id2VKhpCW16lE73A0LK2Jsk3hzkFvdx76JKW8FjLgaimLJ2T/+i\nxFfDw8XBinLE09dqg8JxSNS6JbLHLcav8P3yJIlzFh1NqfJABU9U4I8atb6P\nITSdSo9nb3LX6sB8SOU0nqXb5U+nj7jiekQqiBhmEmu6iDmMtfU=" - secure: "GkAdnMh07id2VKhpCW16lE73A0LK2Jsk3hzkFvdx76JKW8FjLgaimLJ2T/+i\nxFfDw8XBinLE09dqg8JxSNS6JbLHLcav8P3yJIlzFh1NqfJABU9U4I8atb6P\nITSdSo9nb3LX6sB8SOU0nqXb5U+nj7jiekQqiBhmEmu6iDmMtfU="
- secure: "eCh5BjCFccp+sB/FIrjsmxJU4475D4qiWvDV++khcIHLel6lgUjDX18ImBlJ\n+IdiCKxvR6EpRDV1Cs4gJ2jZEAV0PbojQMoQOXbs1FLggM8RRq/Re1qWQFq7\nWkBRjjr8w8ddjJZHRo459cTUvgvD7krhp07coabAnEahDaGWSUo=" - secure: "eCh5BjCFccp+sB/FIrjsmxJU4475D4qiWvDV++khcIHLel6lgUjDX18ImBlJ\n+IdiCKxvR6EpRDV1Cs4gJ2jZEAV0PbojQMoQOXbs1FLggM8RRq/Re1qWQFq7\nWkBRjjr8w8ddjJZHRo459cTUvgvD7krhp07coabAnEahDaGWSUo="
...@@ -5,7 +5,7 @@ ndk-build ...@@ -5,7 +5,7 @@ ndk-build
mkdir -p assets/armeabi mkdir -p assets/armeabi
mkdir -p assets/armeabi-v7a mkdir -p assets/armeabi-v7a
mkdir -p assets/x86 mkdir -p assets/x86
for app in iptables pdnsd redsocks shadowsocks tun2socks for app in iptables pdnsd redsocks ss-local ss-tunnel tun2socks
do do
mv libs/armeabi/$app assets/armeabi/ mv libs/armeabi/$app assets/armeabi/
mv libs/armeabi-v7a/$app assets/armeabi-v7a/ mv libs/armeabi-v7a/$app assets/armeabi-v7a/
......
...@@ -5,8 +5,8 @@ import sbtandroid._ ...@@ -5,8 +5,8 @@ import sbtandroid._
import sbtandroid.AndroidPlugin._ import sbtandroid.AndroidPlugin._
object App { object App {
val version = "2.1.1" val version = "2.1.2"
val versionCode = 62 val versionCode = 63
} }
object General { object General {
......
...@@ -274,7 +274,7 @@ img { ...@@ -274,7 +274,7 @@ img {
</head> </head>
<body> <body>
<p>A <a href="http://shadowsocks.org">Shadowsocks</a> client for Android, written in Scala.</p> <p>A <a href="http://shadowsocks.org">Shadowsocks</a> client for Android, written in Scala.</p>
<p>Copyright (C) 2013 Max Lv <a href="&#x6d;&#97;&#x69;&#108;&#116;&#111;&#x3a;&#x6d;&#97;x&#46;&#99;.&#108;&#118;&#x40;&#103;&#109;&#97;&#x69;&#108;&#46;&#x63;&#x6f;&#109;">&#x6d;&#97;&#x78;.&#x63;&#x2e;&#108;v&#64;&#x67;&#109;&#x61;&#x69;&#108;&#x2e;&#99;&#111;&#109;</a></p> <p>Copyright (C) 2014 Max Lv <a href="&#x6d;&#97;&#x69;&#108;&#116;&#111;&#x3a;&#x6d;&#97;x&#46;&#99;.&#108;&#118;&#x40;&#103;&#109;&#97;&#x69;&#108;&#46;&#x63;&#x6f;&#109;">&#x6d;&#97;&#x78;.&#x63;&#x2e;&#108;v&#64;&#x67;&#109;&#x61;&#x69;&#108;&#x2e;&#99;&#111;&#109;</a></p>
<p>This program is free software: you can redistribute it and/or modify <p>This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
......
...@@ -9,6 +9,7 @@ public class Config implements Parcelable { ...@@ -9,6 +9,7 @@ public class Config implements Parcelable {
public boolean isGFWList = true; public boolean isGFWList = true;
public boolean isBypassApps = false; public boolean isBypassApps = false;
public boolean isTrafficStat = false; public boolean isTrafficStat = false;
public boolean isUdpDns = false;
public String profileName = "Untitled"; public String profileName = "Untitled";
public String proxy = "127.0.0.1"; public String proxy = "127.0.0.1";
...@@ -20,8 +21,7 @@ public class Config implements Parcelable { ...@@ -20,8 +21,7 @@ public class Config implements Parcelable {
public int remotePort = 1984; public int remotePort = 1984;
public int localPort = 1080; public int localPort = 1080;
public static final Parcelable.Creator<Config> CREATOR = new public static final Parcelable.Creator<Config> CREATOR = new Parcelable.Creator<Config>() {
Parcelable.Creator<Config>() {
public Config createFromParcel(Parcel in) { public Config createFromParcel(Parcel in) {
return new Config(in); return new Config(in);
} }
...@@ -32,12 +32,13 @@ public class Config implements Parcelable { ...@@ -32,12 +32,13 @@ public class Config implements Parcelable {
}; };
public Config(boolean isGlobalProxy, boolean isGFWList, boolean isBypassApps, public Config(boolean isGlobalProxy, boolean isGFWList, boolean isBypassApps,
boolean isTrafficStat, String profileName, String proxy, String sitekey, String encMethod, boolean isTrafficStat, boolean isUdpDns, String profileName, String proxy, String sitekey,
String proxiedAppString, int remotePort, int localPort) { String encMethod, String proxiedAppString, int remotePort, int localPort) {
this.isGlobalProxy = isGlobalProxy; this.isGlobalProxy = isGlobalProxy;
this.isGFWList = isGFWList; this.isGFWList = isGFWList;
this.isBypassApps = isBypassApps; this.isBypassApps = isBypassApps;
this.isTrafficStat = isTrafficStat; this.isTrafficStat = isTrafficStat;
this.isUdpDns = isUdpDns;
this.profileName = profileName; this.profileName = profileName;
this.proxy = proxy; this.proxy = proxy;
this.sitekey = sitekey; this.sitekey = sitekey;
...@@ -56,6 +57,7 @@ public class Config implements Parcelable { ...@@ -56,6 +57,7 @@ public class Config implements Parcelable {
isGFWList = in.readInt() == 1; isGFWList = in.readInt() == 1;
isBypassApps = in.readInt() == 1; isBypassApps = in.readInt() == 1;
isTrafficStat = in.readInt() == 1; isTrafficStat = in.readInt() == 1;
isUdpDns = in.readInt() == 1;
profileName = in.readString(); profileName = in.readString();
proxy = in.readString(); proxy = in.readString();
sitekey = in.readString(); sitekey = in.readString();
...@@ -70,10 +72,11 @@ public class Config implements Parcelable { ...@@ -70,10 +72,11 @@ public class Config implements Parcelable {
} }
@Override public void writeToParcel(Parcel out, int flags) { @Override public void writeToParcel(Parcel out, int flags) {
out.writeInt(isGlobalProxy ? 1: 0); out.writeInt(isGlobalProxy ? 1 : 0);
out.writeInt(isGFWList ? 1: 0); out.writeInt(isGFWList ? 1 : 0);
out.writeInt(isBypassApps ? 1: 0); out.writeInt(isBypassApps ? 1 : 0);
out.writeInt(isTrafficStat ? 1: 0); out.writeInt(isTrafficStat ? 1 : 0);
out.writeInt(isUdpDns ? 1 : 0);
out.writeString(profileName); out.writeString(profileName);
out.writeString(proxy); out.writeString(proxy);
out.writeString(sitekey); out.writeString(sitekey);
...@@ -81,6 +84,5 @@ public class Config implements Parcelable { ...@@ -81,6 +84,5 @@ public class Config implements Parcelable {
out.writeString(proxiedAppString); out.writeString(proxiedAppString);
out.writeInt(remotePort); out.writeInt(remotePort);
out.writeInt(localPort); out.writeInt(localPort);
} }
} }
...@@ -7,8 +7,8 @@ interface IShadowsocksService { ...@@ -7,8 +7,8 @@ interface IShadowsocksService {
int getMode(); int getMode();
int getState(); int getState();
void registerCallback(IShadowsocksServiceCallback cb); oneway void registerCallback(IShadowsocksServiceCallback cb);
void unregisterCallback(IShadowsocksServiceCallback cb); oneway void unregisterCallback(IShadowsocksServiceCallback cb);
oneway void start(in Config config); oneway void start(in Config config);
oneway void stop(); oneway void stop();
......
package com.github.shadowsocks.aidl; package com.github.shadowsocks.aidl;
interface IShadowsocksServiceCallback { interface IShadowsocksServiceCallback {
void stateChanged(int state, String msg); oneway void stateChanged(int state, String msg);
} }
...@@ -89,14 +89,14 @@ LOCAL_CFLAGS := -Wall -O2 -I$(LOCAL_PATH)/pdnsd ...@@ -89,14 +89,14 @@ LOCAL_CFLAGS := -Wall -O2 -I$(LOCAL_PATH)/pdnsd
include $(BUILD_EXECUTABLE) include $(BUILD_EXECUTABLE)
######################################################## ########################################################
## shadowsocks ## shadowsocks local
######################################################## ########################################################
include $(CLEAR_VARS) include $(CLEAR_VARS)
SHADOWSOCKS_SOURCES := local.c cache.c udprelay.c encrypt.c utils.c json.c jconf.c SHADOWSOCKS_SOURCES := local.c cache.c udprelay.c encrypt.c utils.c json.c jconf.c
LOCAL_MODULE := shadowsocks LOCAL_MODULE := ss-local
LOCAL_SRC_FILES := $(addprefix shadowsocks/src/, $(SHADOWSOCKS_SOURCES)) LOCAL_SRC_FILES := $(addprefix shadowsocks/src/, $(SHADOWSOCKS_SOURCES))
LOCAL_CFLAGS := -Wall -O2 -fno-strict-aliasing -DUDPRELAY_LOCAL \ LOCAL_CFLAGS := -Wall -O2 -fno-strict-aliasing -DUDPRELAY_LOCAL \
-DUSE_CRYPTO_OPENSSL -DANDROID -DHAVE_CONFIG_H \ -DUSE_CRYPTO_OPENSSL -DANDROID -DHAVE_CONFIG_H \
...@@ -109,6 +109,27 @@ LOCAL_LDLIBS := -llog ...@@ -109,6 +109,27 @@ LOCAL_LDLIBS := -llog
include $(BUILD_EXECUTABLE) include $(BUILD_EXECUTABLE)
########################################################
## shadowsocks tunnel
########################################################
include $(CLEAR_VARS)
SHADOWSOCKS_SOURCES := tunnel.c cache.c udprelay.c encrypt.c utils.c json.c jconf.c
LOCAL_MODULE := ss-tunnel
LOCAL_SRC_FILES := $(addprefix shadowsocks/src/, $(SHADOWSOCKS_SOURCES))
LOCAL_CFLAGS := -Wall -O2 -fno-strict-aliasing -DUDPRELAY_LOCAL -DUDPRELAY_TUNNEL \
-DUSE_CRYPTO_OPENSSL -DANDROID -DHAVE_CONFIG_H \
-I$(LOCAL_PATH)/libev/ \
-I$(LOCAL_PATH)/openssl/include
LOCAL_STATIC_LIBRARIES := libev libcrypto
LOCAL_LDLIBS := -llog
include $(BUILD_EXECUTABLE)
######################################################## ########################################################
## termExec ## termExec
######################################################## ########################################################
......
Subproject commit 69f8bd61c096337abb34a9e64534865d08022957 Subproject commit b2df5a4c26d293469237fd89153e16f1fa47000c
...@@ -67,6 +67,9 @@ ...@@ -67,6 +67,9 @@
<string name="flushing">刷新中...</string> <string name="flushing">刷新中...</string>
<string name="add_profile">添加配置文件</string> <string name="add_profile">添加配置文件</string>
<string name="udp_dns">DNS转发</string>
<string name="udp_dns_summary">向远程服务器转发UDP协议的DNS请求</string>
<!-- profile --> <!-- profile -->
<string name="add_profile_dialog">为影梭添加此配置文件?</string> <string name="add_profile_dialog">为影梭添加此配置文件?</string>
<string-array name="add_profile_methods"> <string-array name="add_profile_methods">
......
...@@ -45,6 +45,8 @@ ...@@ -45,6 +45,8 @@
<string name="auto_connect_summary">Enable Shadowsocks on startup</string> <string name="auto_connect_summary">Enable Shadowsocks on startup</string>
<string name="traffic_stat">Traffic Stats</string> <string name="traffic_stat">Traffic Stats</string>
<string name="traffic_stat_summary">Show traffic stats in notification bar</string> <string name="traffic_stat_summary">Show traffic stats in notification bar</string>
<string name="udp_dns">DNS Forwarding</string>
<string name="udp_dns_summary">Forward DNS\'s UDP packets to remote server</string>
<!-- notification category --> <!-- notification category -->
<string name="forward_success">Shadowsocks started.</string> <string name="forward_success">Shadowsocks started.</string>
......
...@@ -26,6 +26,12 @@ ...@@ -26,6 +26,12 @@
android:defaultValue="true" android:defaultValue="true"
android:summary="@string/traffic_stat_summary" android:summary="@string/traffic_stat_summary"
android:title="@string/traffic_stat"> android:title="@string/traffic_stat">
</CheckBoxPreference>
<CheckBoxPreference
android:key="isUdpDns"
android:defaultValue="false"
android:summary="@string/udp_dns_summary"
android:title="@string/udp_dns">
</CheckBoxPreference> </CheckBoxPreference>
<CheckBoxPreference <CheckBoxPreference
android:key="isAutoConnect" android:key="isAutoConnect"
......
...@@ -106,9 +106,8 @@ trait BaseService { ...@@ -106,9 +106,8 @@ trait BaseService {
override def run() { override def run() {
if (state != s) { if (state != s) {
val n = callbacks.beginBroadcast() val n = callbacks.beginBroadcast()
val m = if (msg != null) msg.substring(0, 64) else null
for (i <- 0 to n - 1) { for (i <- 0 to n - 1) {
callbacks.getBroadcastItem(i).stateChanged(s, m) callbacks.getBroadcastItem(i).stateChanged(s, msg)
} }
callbacks.finishBroadcast() callbacks.finishBroadcast()
state = s state = s
......
...@@ -122,7 +122,7 @@ object Shadowsocks { ...@@ -122,7 +122,7 @@ object 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, Key.isTrafficStat, val FEATRUE_PREFS = Array(Key.isGFWList, Key.isGlobalProxy, Key.proxyedApps, Key.isTrafficStat,
Key.isAutoConnect) Key.isUdpDns, Key.isAutoConnect)
val TAG = "Shadowsocks" val TAG = "Shadowsocks"
val REQUEST_CONNECT = 1 val REQUEST_CONNECT = 1
...@@ -162,6 +162,7 @@ object Shadowsocks { ...@@ -162,6 +162,7 @@ object Shadowsocks {
case Key.isGFWList => updateCheckBoxPreference(pref, profile.chnroute) case Key.isGFWList => updateCheckBoxPreference(pref, profile.chnroute)
case Key.isGlobalProxy => updateCheckBoxPreference(pref, profile.global) case Key.isGlobalProxy => updateCheckBoxPreference(pref, profile.global)
case Key.isTrafficStat => updateCheckBoxPreference(pref, profile.traffic) case Key.isTrafficStat => updateCheckBoxPreference(pref, profile.traffic)
case Key.isUdpDns => updateCheckBoxPreference(pref, profile.udpdns)
case _ => case _ =>
} }
} }
...@@ -417,10 +418,12 @@ class Shadowsocks ...@@ -417,10 +418,12 @@ class Shadowsocks
val sb = new StringBuilder val sb = new StringBuilder
sb.append("kill -9 `cat /data/data/com.github.shadowsocks/pdnsd.pid`").append("\n") sb.append("kill -9 `cat /data/data/com.github.shadowsocks/pdnsd.pid`").append("\n")
sb.append("kill -9 `cat /data/data/com.github.shadowsocks/shadowsocks.pid`").append("\n") sb.append("kill -9 `cat /data/data/com.github.shadowsocks/ss-local.pid`").append("\n")
sb.append("kill -9 `cat /data/data/com.github.shadowsocks/ss-tunnel.pid`").append("\n")
sb.append("kill -9 `cat /data/data/com.github.shadowsocks/tun2socks.pid`").append("\n") sb.append("kill -9 `cat /data/data/com.github.shadowsocks/tun2socks.pid`").append("\n")
sb.append("killall -9 pdnsd").append("\n") sb.append("killall -9 pdnsd").append("\n")
sb.append("killall -9 shadowsocks").append("\n") sb.append("killall -9 ss-local").append("\n")
sb.append("killall -9 ss-tunnel").append("\n")
sb.append("killall -9 tun2socks").append("\n") sb.append("killall -9 tun2socks").append("\n")
sb.append("rm /data/data/com.github.shadowsocks/pdnsd.conf").append("\n") sb.append("rm /data/data/com.github.shadowsocks/pdnsd.conf").append("\n")
sb.append("rm /data/data/com.github.shadowsocks/pdnsd.cache").append("\n") sb.append("rm /data/data/com.github.shadowsocks/pdnsd.cache").append("\n")
...@@ -908,7 +911,8 @@ class Shadowsocks ...@@ -908,7 +911,8 @@ class Shadowsocks
Utils.runCommand("chmod 755 /data/data/com.github.shadowsocks/iptables\n" Utils.runCommand("chmod 755 /data/data/com.github.shadowsocks/iptables\n"
+ "chmod 755 /data/data/com.github.shadowsocks/redsocks\n" + "chmod 755 /data/data/com.github.shadowsocks/redsocks\n"
+ "chmod 755 /data/data/com.github.shadowsocks/pdnsd\n" + "chmod 755 /data/data/com.github.shadowsocks/pdnsd\n"
+ "chmod 755 /data/data/com.github.shadowsocks/shadowsocks\n" + "chmod 755 /data/data/com.github.shadowsocks/ss-local\n"
+ "chmod 755 /data/data/com.github.shadowsocks/ss-tunnel\n"
+ "chmod 755 /data/data/com.github.shadowsocks/tun2socks\n") + "chmod 755 /data/data/com.github.shadowsocks/tun2socks\n")
} }
......
...@@ -102,20 +102,28 @@ class ShadowsocksNatService extends Service with BaseService { ...@@ -102,20 +102,28 @@ class ShadowsocksNatService extends Service with BaseService {
val handler: Handler = new Handler() val handler: Handler = new Handler()
def startShadowsocksDaemon() { def startShadowsocksDaemon() {
val cmd: String = (Path.BASE + val cmd = (Path.BASE +
"shadowsocks -b 127.0.0.1 -s \"%s\" -p \"%d\" -l \"%d\" -k \"%s\" -m \"%s\" -f " + "ss-local -b 127.0.0.1 -s \"%s\" -p \"%d\" -l \"%d\" -k \"%s\" -m \"%s\" -f " +
Path.BASE + "shadowsocks.pid") Path.BASE + "ss-local.pid")
.format(config.proxy, config.remotePort, config.localPort, config.sitekey, config.encMethod) .format(config.proxy, config.remotePort, config.localPort, config.sitekey, config.encMethod)
if (BuildConfig.DEBUG) Log.d(TAG, cmd) if (BuildConfig.DEBUG) Log.d(TAG, cmd)
Utils.runCommand(cmd) Utils.runCommand(cmd)
} }
def startDnsDaemon() { def startDnsDaemon() {
val cmd: String = Path.BASE + "pdnsd -c " + Path.BASE + "pdnsd.conf" val cmd = if (config.isUdpDns) {
val conf: String = ConfigUtils.PDNSD.format("127.0.0.1") (Path.BASE +
"ss-tunnel -b 127.0.0.1 -s \"%s\" -p \"%d\" -l \"%d\" -k \"%s\" -m \"%s\" -L 8.8.8.8:53 -u -f " +
Path.BASE + "ss-local.pid")
.format(config.proxy, config.remotePort, 8153, config.sitekey, config.encMethod)
} else {
val conf = ConfigUtils.PDNSD.format("127.0.0.1")
ConfigUtils.printToFile(new File(Path.BASE + "pdnsd.conf"))(p => { ConfigUtils.printToFile(new File(Path.BASE + "pdnsd.conf"))(p => {
p.println(conf) p.println(conf)
}) })
Path.BASE + "pdnsd -c " + Path.BASE + "pdnsd.conf"
}
Utils.runCommand(cmd) Utils.runCommand(cmd)
} }
...@@ -271,8 +279,10 @@ class ShadowsocksNatService extends Service with BaseService { ...@@ -271,8 +279,10 @@ class ShadowsocksNatService extends Service with BaseService {
sb ++= "kill -9 `cat " ++= Path.BASE ++= "pdnsd.pid`" ++= "\n" sb ++= "kill -9 `cat " ++= Path.BASE ++= "pdnsd.pid`" ++= "\n"
sb ++= "killall -9 pdnsd" ++= "\n" sb ++= "killall -9 pdnsd" ++= "\n"
sb ++= "kill -9 `cat " ++= Path.BASE ++= "shadowsocks.pid`" ++= "\n" sb ++= "kill -9 `cat " ++= Path.BASE ++= "ss-local.pid`" ++= "\n"
sb ++= "killall -9 shadowsocks" ++= "\n" sb ++= "killall -9 ss-local" ++= "\n"
sb ++= "kill -9 `cat " ++= Path.BASE ++= "ss-tunnel.pid`" ++= "\n"
sb ++= "killall -9 ss-tunnel" ++= "\n"
Utils.runCommand(sb.toString()) Utils.runCommand(sb.toString())
} }
......
...@@ -76,19 +76,26 @@ class ShadowsocksVpnService extends VpnService with BaseService { ...@@ -76,19 +76,26 @@ class ShadowsocksVpnService extends VpnService with BaseService {
def startShadowsocksDaemon() { def startShadowsocksDaemon() {
val cmd: String = (Path.BASE + val cmd: String = (Path.BASE +
"shadowsocks -b 127.0.0.1 -s \"%s\" -p \"%d\" -l \"%d\" -k \"%s\" -m \"%s\" -f " + "ss-local -b 127.0.0.1 -s \"%s\" -p \"%d\" -l \"%d\" -k \"%s\" -m \"%s\" -f " +
Path.BASE + "shadowsocks.pid") Path.BASE + "ss-local.pid")
.format(config.proxy, config.remotePort, config.localPort, config.sitekey, config.encMethod) .format(config.proxy, config.remotePort, config.localPort, config.sitekey, config.encMethod)
if (BuildConfig.DEBUG) Log.d(TAG, cmd) if (BuildConfig.DEBUG) Log.d(TAG, cmd)
System.exec(cmd) System.exec(cmd)
} }
def startDnsDaemon() { def startDnsDaemon() {
val cmd: String = Path.BASE + "pdnsd -c " + Path.BASE + "pdnsd.conf" val cmd = if (config.isUdpDns) {
val conf: String = ConfigUtils.PDNSD.format("0.0.0.0") (Path.BASE +
"ss-tunnel -b 0.0.0.0 -s \"%s\" -p \"%d\" -l \"%d\" -k \"%s\" -m \"%s\" -L 8.8.8.8:53 -u -f " +
Path.BASE + "ss-tunnel.pid")
.format(config.proxy, config.remotePort, 8153, config.sitekey, config.encMethod)
} else {
val conf = ConfigUtils.PDNSD.format("0.0.0.0")
ConfigUtils.printToFile(new File(Path.BASE + "pdnsd.conf"))(p => { ConfigUtils.printToFile(new File(Path.BASE + "pdnsd.conf"))(p => {
p.println(conf) p.println(conf)
}) })
Path.BASE + "pdnsd -c " + Path.BASE + "pdnsd.conf"
}
Utils.runCommand(cmd) Utils.runCommand(cmd)
} }
...@@ -243,12 +250,14 @@ class ShadowsocksVpnService extends VpnService with BaseService { ...@@ -243,12 +250,14 @@ class ShadowsocksVpnService extends VpnService with BaseService {
def killProcesses() { def killProcesses() {
val sb = new StringBuilder val sb = new StringBuilder
sb ++= "kill -9 `cat " ++= Path.BASE ++= "shadowsocks.pid`" ++= "\n" sb ++= "kill -9 `cat " ++= Path.BASE ++= "ss-local.pid`" ++= "\n"
sb ++= "killall -9 shadowsocks" ++= "\n" sb ++= "killall -9 ss-local" ++= "\n"
sb ++= "kill -9 `cat " ++= Path.BASE ++= "ss-tunnel.pid`" ++= "\n"
sb ++= "killall -9 ss-tunnel" ++= "\n"
sb ++= "kill -9 `cat " ++= Path.BASE ++= "tun2socks.pid`" ++= "\n" sb ++= "kill -9 `cat " ++= Path.BASE ++= "tun2socks.pid`" ++= "\n"
sb ++= "killall -9 tun2socks" ++= "\n" sb ++= "killall -9 tun2socks" ++= "\n"
sb ++= "kill -9 `cat " ++= Path.BASE ++= "pdnsd.pid`" ++= "\n" // sb ++= "kill -9 `cat " ++= Path.BASE ++= "pdnsd.pid`" ++= "\n"
sb ++= "killall -9 pdnsd" ++= "\n" // sb ++= "killall -9 pdnsd" ++= "\n"
Utils.runCommand(sb.toString()) Utils.runCommand(sb.toString())
} }
......
...@@ -50,7 +50,7 @@ object DBHelper { ...@@ -50,7 +50,7 @@ object DBHelper {
val PROFILE = "profile.db" val PROFILE = "profile.db"
} }
class DBHelper(val context: Context) extends OrmLiteSqliteOpenHelper(context, DBHelper.PROFILE, null, 7) { class DBHelper(val context: Context) extends OrmLiteSqliteOpenHelper(context, DBHelper.PROFILE, null, 8) {
lazy val profileDao:Dao[Profile,Int] = getDao(classOf[Profile]) lazy val profileDao:Dao[Profile,Int] = getDao(classOf[Profile])
...@@ -59,7 +59,11 @@ class DBHelper(val context: Context) extends OrmLiteSqliteOpenHelper(context, DB ...@@ -59,7 +59,11 @@ class DBHelper(val context: Context) extends OrmLiteSqliteOpenHelper(context, DB
} }
def onUpgrade(database: SQLiteDatabase, connectionSource: ConnectionSource, oldVersion: Int, newVersion: Int) { def onUpgrade(database: SQLiteDatabase, connectionSource: ConnectionSource, oldVersion: Int, newVersion: Int) {
if (oldVersion < 8) {
profileDao.executeRaw("ALTER TABLE `profile` ADD COLUMN udpdns INTEGER;")
} else {
TableUtils.dropTable(connectionSource, classOf[Profile], true) TableUtils.dropTable(connectionSource, classOf[Profile], true)
}
onCreate(database, connectionSource) onCreate(database, connectionSource)
} }
} }
...@@ -84,6 +84,9 @@ class Profile { ...@@ -84,6 +84,9 @@ class Profile {
@DatabaseField @DatabaseField
var traffic: Boolean = false var traffic: Boolean = false
@DatabaseField
var udpdns: Boolean = false
@DatabaseField(dataType = DataType.LONG_STRING) @DatabaseField(dataType = DataType.LONG_STRING)
var individual: String = "" var individual: String = ""
......
...@@ -121,6 +121,7 @@ class ProfileManager(settings: SharedPreferences, dbHelper: DBHelper) { ...@@ -121,6 +121,7 @@ class ProfileManager(settings: SharedPreferences, dbHelper: DBHelper) {
edit.putBoolean(Key.isGFWList, profile.chnroute) edit.putBoolean(Key.isGFWList, profile.chnroute)
edit.putBoolean(Key.isBypassApps, profile.bypass) edit.putBoolean(Key.isBypassApps, profile.bypass)
edit.putBoolean(Key.isTrafficStat, profile.traffic) edit.putBoolean(Key.isTrafficStat, profile.traffic)
edit.putBoolean(Key.isUdpDns, profile.udpdns)
edit.putString(Key.profileName, profile.name) edit.putString(Key.profileName, profile.name)
edit.putString(Key.proxy, profile.host) edit.putString(Key.proxy, profile.host)
edit.putString(Key.sitekey, profile.password) edit.putString(Key.sitekey, profile.password)
...@@ -143,6 +144,7 @@ class ProfileManager(settings: SharedPreferences, dbHelper: DBHelper) { ...@@ -143,6 +144,7 @@ class ProfileManager(settings: SharedPreferences, dbHelper: DBHelper) {
profile.chnroute = settings.getBoolean(Key.isGFWList, false) profile.chnroute = settings.getBoolean(Key.isGFWList, false)
profile.bypass = settings.getBoolean(Key.isBypassApps, false) profile.bypass = settings.getBoolean(Key.isBypassApps, false)
profile.traffic = settings.getBoolean(Key.isTrafficStat, false) profile.traffic = settings.getBoolean(Key.isTrafficStat, false)
profile.udpdns = settings.getBoolean(Key.isUdpDns, false)
profile.name = settings.getString(Key.profileName, "default") profile.name = settings.getString(Key.profileName, "default")
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")
......
...@@ -84,7 +84,8 @@ object ConfigUtils { ...@@ -84,7 +84,8 @@ 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.profileName, host, password, method, config.proxiedAppString, port, config.localPort) config.isUdpDns, config.profileName, host, password, method, config.proxiedAppString, port,
config.localPort)
} }
def load(settings: SharedPreferences): Config = { def load(settings: SharedPreferences): Config = {
...@@ -92,6 +93,7 @@ object ConfigUtils { ...@@ -92,6 +93,7 @@ object ConfigUtils {
val isGFWList = settings.getBoolean(Key.isGFWList, false) val isGFWList = settings.getBoolean(Key.isGFWList, false)
val isBypassApps = settings.getBoolean(Key.isBypassApps, false) val isBypassApps = settings.getBoolean(Key.isBypassApps, false)
val isTrafficStat = settings.getBoolean(Key.isTrafficStat, false) val isTrafficStat = settings.getBoolean(Key.isTrafficStat, false)
val isUdpDns = settings.getBoolean(Key.isUdpDns, false)
val profileName = settings.getString(Key.profileName, "default") val profileName = settings.getString(Key.profileName, "default")
val proxy = settings.getString(Key.proxy, "127.0.0.1") val proxy = settings.getString(Key.proxy, "127.0.0.1")
...@@ -111,7 +113,7 @@ object ConfigUtils { ...@@ -111,7 +113,7 @@ object ConfigUtils {
} }
val proxiedAppString = settings.getString(Key.proxied, "") val proxiedAppString = settings.getString(Key.proxied, "")
new Config(isGlobalProxy, isGFWList, isBypassApps, isTrafficStat, profileName, proxy, sitekey, new Config(isGlobalProxy, isGFWList, isBypassApps, isTrafficStat, isUdpDns, profileName, proxy, sitekey,
encMethod, proxiedAppString, remotePort, localPort) encMethod, proxiedAppString, remotePort, localPort)
} }
......
...@@ -70,6 +70,7 @@ object Key { ...@@ -70,6 +70,7 @@ object Key {
val isGFWList = "isGFWList" val isGFWList = "isGFWList"
val isBypassApps = "isBypassApps" val isBypassApps = "isBypassApps"
val isTrafficStat = "isTrafficStat" val isTrafficStat = "isTrafficStat"
val isUdpDns = "isUdpDns"
val proxy = "proxy" val proxy = "proxy"
val sitekey = "sitekey" val sitekey = "sitekey"
......
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