add udp dns option

This commit is contained in:
Max Lv
2014-02-28 20:14:47 +08:00
parent c442963394
commit a89ca2d154
12 changed files with 78 additions and 45 deletions
@@ -122,7 +122,7 @@ object Shadowsocks {
val PROXY_PREFS = Array(Key.profileName, Key.proxy, Key.remotePort, Key.localPort, Key.sitekey,
Key.encMethod)
val FEATRUE_PREFS = Array(Key.isGFWList, Key.isGlobalProxy, Key.proxyedApps, Key.isTrafficStat,
Key.isAutoConnect)
Key.isUdpDns, Key.isAutoConnect)
val TAG = "Shadowsocks"
val REQUEST_CONNECT = 1
@@ -162,6 +162,7 @@ object Shadowsocks {
case Key.isGFWList => updateCheckBoxPreference(pref, profile.chnroute)
case Key.isGlobalProxy => updateCheckBoxPreference(pref, profile.global)
case Key.isTrafficStat => updateCheckBoxPreference(pref, profile.traffic)
case Key.isUdpDns => updateCheckBoxPreference(pref, profile.udpdns)
case _ =>
}
}
@@ -111,15 +111,19 @@ class ShadowsocksNatService extends Service with BaseService {
}
def startDnsDaemon() {
val cmd = (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)
// val cmd = Path.BASE + "pdnsd -c " + Path.BASE + "pdnsd.conf"
// val conf = ConfigUtils.PDNSD.format("127.0.0.1")
// ConfigUtils.printToFile(new File(Path.BASE + "pdnsd.conf"))(p => {
// p.println(conf)
// })
val cmd = if (config.isUdpDns) {
(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 => {
p.println(conf)
})
Path.BASE + "pdnsd -c " + Path.BASE + "pdnsd.conf"
}
Utils.runCommand(cmd)
}
@@ -76,23 +76,26 @@ class ShadowsocksVpnService extends VpnService with BaseService {
def startShadowsocksDaemon() {
val cmd: String = (Path.BASE +
"shadowsocks -b 127.0.0.1 -s \"%s\" -p \"%d\" -l \"%d\" -k \"%s\" -m \"%s\" -f " +
Path.BASE + "shadowsocks.pid")
"ss-local -b 127.0.0.1 -s \"%s\" -p \"%d\" -l \"%d\" -k \"%s\" -m \"%s\" -f " +
Path.BASE + "ss-local.pid")
.format(config.proxy, config.remotePort, config.localPort, config.sitekey, config.encMethod)
if (BuildConfig.DEBUG) Log.d(TAG, cmd)
System.exec(cmd)
}
def startDnsDaemon() {
val cmd = (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)
// val cmd: String = Path.BASE + "pdnsd -c " + Path.BASE + "pdnsd.conf"
// val conf: String = ConfigUtils.PDNSD.format("0.0.0.0")
// ConfigUtils.printToFile(new File(Path.BASE + "pdnsd.conf"))(p => {
// p.println(conf)
// })
val cmd = if (config.isUdpDns) {
(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 => {
p.println(conf)
})
Path.BASE + "pdnsd -c " + Path.BASE + "pdnsd.conf"
}
Utils.runCommand(cmd)
}
@@ -50,7 +50,7 @@ object DBHelper {
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])
@@ -59,7 +59,11 @@ class DBHelper(val context: Context) extends OrmLiteSqliteOpenHelper(context, DB
}
def onUpgrade(database: SQLiteDatabase, connectionSource: ConnectionSource, oldVersion: Int, newVersion: Int) {
TableUtils.dropTable(connectionSource, classOf[Profile], true)
if (oldVersion < 8) {
profileDao.executeRaw("ALTER TABLE `profile` ADD COLUMN udpdns INTEGER;")
} else {
TableUtils.dropTable(connectionSource, classOf[Profile], true)
}
onCreate(database, connectionSource)
}
}
@@ -84,6 +84,9 @@ class Profile {
@DatabaseField
var traffic: Boolean = false
@DatabaseField
var udpdns: Boolean = false
@DatabaseField(dataType = DataType.LONG_STRING)
var individual: String = ""
@@ -121,6 +121,7 @@ class ProfileManager(settings: SharedPreferences, dbHelper: DBHelper) {
edit.putBoolean(Key.isGFWList, profile.chnroute)
edit.putBoolean(Key.isBypassApps, profile.bypass)
edit.putBoolean(Key.isTrafficStat, profile.traffic)
edit.putBoolean(Key.isUdpDns, profile.udpdns)
edit.putString(Key.profileName, profile.name)
edit.putString(Key.proxy, profile.host)
edit.putString(Key.sitekey, profile.password)
@@ -143,6 +144,7 @@ class ProfileManager(settings: SharedPreferences, dbHelper: DBHelper) {
profile.chnroute = settings.getBoolean(Key.isGFWList, false)
profile.bypass = settings.getBoolean(Key.isBypassApps, false)
profile.traffic = settings.getBoolean(Key.isTrafficStat, false)
profile.udpdns = settings.getBoolean(Key.isUdpDns, false)
profile.name = settings.getString(Key.profileName, "default")
profile.host = settings.getString(Key.proxy, "127.0.0.1")
profile.password = settings.getString(Key.sitekey, "default")
@@ -84,7 +84,8 @@ object ConfigUtils {
val method = proxy(3).trim
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 = {
@@ -92,6 +93,7 @@ object ConfigUtils {
val isGFWList = settings.getBoolean(Key.isGFWList, false)
val isBypassApps = settings.getBoolean(Key.isBypassApps, false)
val isTrafficStat = settings.getBoolean(Key.isTrafficStat, false)
val isUdpDns = settings.getBoolean(Key.isUdpDns, false)
val profileName = settings.getString(Key.profileName, "default")
val proxy = settings.getString(Key.proxy, "127.0.0.1")
@@ -111,7 +113,7 @@ object ConfigUtils {
}
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)
}
@@ -70,6 +70,7 @@ object Key {
val isGFWList = "isGFWList"
val isBypassApps = "isBypassApps"
val isTrafficStat = "isTrafficStat"
val isUdpDns = "isUdpDns"
val proxy = "proxy"
val sitekey = "sitekey"