Commit 0f24d7c0 authored by Max Lv's avatar Max Lv

Add cloud based ACL updating

parent bbf61448
...@@ -30,6 +30,8 @@ resolvers += Resolver.jcenterRepo ...@@ -30,6 +30,8 @@ resolvers += Resolver.jcenterRepo
useSupportVectors useSupportVectors
googleServicesSettings
libraryDependencies ++= Seq( libraryDependencies ++= Seq(
"com.android.support" % "design" % "24.2.1", "com.android.support" % "design" % "24.2.1",
"com.android.support" % "gridlayout-v7" % "24.2.1", "com.android.support" % "gridlayout-v7" % "24.2.1",
...@@ -39,6 +41,8 @@ libraryDependencies ++= Seq( ...@@ -39,6 +41,8 @@ libraryDependencies ++= Seq(
"com.github.kevinsawicki" % "http-request" % "6.0", "com.github.kevinsawicki" % "http-request" % "6.0",
"com.google.android.gms" % "play-services-ads" % "9.6.1", "com.google.android.gms" % "play-services-ads" % "9.6.1",
"com.google.android.gms" % "play-services-analytics" % "9.6.1", "com.google.android.gms" % "play-services-analytics" % "9.6.1",
"com.google.firebase" % "firebase-core" % "9.6.1",
"com.google.firebase" % "firebase-storage" % "9.6.1",
"com.j256.ormlite" % "ormlite-android" % "5.0", "com.j256.ormlite" % "ormlite-android" % "5.0",
"com.twofortyfouram" % "android-plugin-api-for-locale" % "1.0.2", "com.twofortyfouram" % "android-plugin-api-for-locale" % "1.0.2",
"dnsjava" % "dnsjava" % "2.1.7", "dnsjava" % "dnsjava" % "2.1.7",
...@@ -52,6 +56,7 @@ proguardVersion in Android := "5.3" ...@@ -52,6 +56,7 @@ proguardVersion in Android := "5.3"
proguardCache in Android := Seq() proguardCache in Android := Seq()
proguardOptions in Android ++= Seq( proguardOptions in Android ++= Seq(
"-keepattributes Signature",
"-keep class com.github.shadowsocks.System { *; }", "-keep class com.github.shadowsocks.System { *; }",
"-dontwarn com.google.android.gms.internal.**", "-dontwarn com.google.android.gms.internal.**",
"-dontwarn com.j256.ormlite.**", "-dontwarn com.j256.ormlite.**",
......
addSbtPlugin("org.scala-android" % "sbt-android" % "1.6.18") addSbtPlugin("org.scala-android" % "sbt-android" % "1.6.18")
addSbtPlugin("org.scala-android" % "sbt-android-gms" % "0.2")
addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.1.10") addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.1.10")
addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.8.2") addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.8.2")
...@@ -121,9 +121,6 @@ ...@@ -121,9 +121,6 @@
android:summary="@string/nat_summary"/> android:summary="@string/nat_summary"/>
<Preference android:key="recovery" android:title="@string/recovery" <Preference android:key="recovery" android:title="@string/recovery"
android:summary="@string/recovery_summary"/> android:summary="@string/recovery_summary"/>
<Preference android:key="flush_dnscache"
android:title="@string/flush_dnscache"
android:summary="@string/flush_dnscache_summary"/>
<Preference android:key="about" android:title="@string/about"/> <Preference android:key="about" android:title="@string/about"/>
</be.mygod.preference.PreferenceCategory> </be.mygod.preference.PreferenceCategory>
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
package com.github.shadowsocks package com.github.shadowsocks
import java.io.File
import java.io.IOException import java.io.IOException
import java.util.{Timer, TimerTask} import java.util.{Timer, TimerTask}
...@@ -55,6 +56,10 @@ import com.github.shadowsocks.utils._ ...@@ -55,6 +56,10 @@ import com.github.shadowsocks.utils._
import com.github.shadowsocks.ShadowsocksApplication.app import com.github.shadowsocks.ShadowsocksApplication.app
import com.github.shadowsocks.database.Profile import com.github.shadowsocks.database.Profile
import com.google.firebase.FirebaseApp
import com.google.firebase.storage.FileDownloadTask
import com.google.firebase.storage.FirebaseStorage
trait BaseService extends Service { trait BaseService extends Service {
@volatile private var state = State.STOPPED @volatile private var state = State.STOPPED
...@@ -276,6 +281,7 @@ trait BaseService extends Service { ...@@ -276,6 +281,7 @@ trait BaseService extends Service {
override def onCreate() { override def onCreate() {
super.onCreate() super.onCreate()
FirebaseApp.initializeApp(this)
app.refreshContainerHolder app.refreshContainerHolder
} }
...@@ -311,4 +317,28 @@ trait BaseService extends Service { ...@@ -311,4 +317,28 @@ trait BaseService extends Service {
case ex: Exception => "exclude = " + default + ";" case ex: Exception => "exclude = " + default + ";"
} }
} }
def getAcl(route: String) {
val localAcl = route match {
case Route.BYPASS_LAN => "bypass_lan.acl"
case Route.BYPASS_CHN => "bypass_chn.acl"
case Route.BYPASS_LAN_CHN => "bypass_lan_chn.acl"
case Route.GFWLIST => "gfwlist.acl"
case Route.CHINALIST => "chinalist.acl"
}
val cloudAclFile = new File(getApplicationInfo.dataDir + "/" + localAcl)
if (!cloudAclFile.exists) cloudAclFile.createNewFile
val tempFile = File.createTempFile(localAcl, "acl")
val storage = FirebaseStorage.getInstance
val storageRef = storage.getReferenceFromUrl("gs://admob-app-id-3330146721.appspot.com/acl/")
val aclRef = storageRef.child(localAcl)
val task = aclRef.getFile(tempFile)
task.addOnSuccessListener((_) => {
tempFile.renameTo(cloudAclFile)
return
})
task.addOnFailureListener((_) => Log.e("shadowsocks", "Unable to download " + localAcl))
tempFile.deleteOnExit()
}
} }
...@@ -545,15 +545,6 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext { ...@@ -545,15 +545,6 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext {
} }
} }
def flushDnsCache() {
val h = showProgress(R.string.flushing)
Utils.ThrowableFuture {
if (!Utils.toggleAirplaneMode(getBaseContext)) h.post(() => Snackbar.make(findViewById(android.R.id.content),
R.string.flush_dnscache_no_root, Snackbar.LENGTH_LONG).show)
h.sendEmptyMessage(0)
}
}
override def onActivityResult(requestCode: Int, resultCode: Int, data: Intent) = resultCode match { override def onActivityResult(requestCode: Int, resultCode: Int, data: Intent) = resultCode match {
case Activity.RESULT_OK => case Activity.RESULT_OK =>
serviceLoad() serviceLoad()
......
...@@ -96,6 +96,7 @@ class ShadowsocksNatService extends BaseService { ...@@ -96,6 +96,7 @@ class ShadowsocksNatService extends BaseService {
if (profile.route != Route.ALL) { if (profile.route != Route.ALL) {
cmd += "--acl" cmd += "--acl"
profile.route match { profile.route match {
case Route.BYPASS_LAN => cmd += (getApplicationInfo.dataDir + "/bypass_lan.acl") case Route.BYPASS_LAN => cmd += (getApplicationInfo.dataDir + "/bypass_lan.acl")
case Route.BYPASS_CHN => cmd += (getApplicationInfo.dataDir + "/bypass_chn.acl") case Route.BYPASS_CHN => cmd += (getApplicationInfo.dataDir + "/bypass_chn.acl")
...@@ -336,8 +337,10 @@ class ShadowsocksNatService extends BaseService { ...@@ -336,8 +337,10 @@ class ShadowsocksNatService extends BaseService {
} }
handleConnection() handleConnection()
// Set DNS
su.addCommand(Utils.FLUSH_DNS) // lazily get ACL from cloud
getAcl(profile.route)
changeState(State.CONNECTED) changeState(State.CONNECTED)
notification = new ShadowsocksNotification(this, profile.name, true) notification = new ShadowsocksNotification(this, profile.name, true)
} }
......
...@@ -170,12 +170,6 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan ...@@ -170,12 +170,6 @@ class ShadowsocksSettings extends PreferenceFragment with OnSharedPreferenceChan
true true
}) })
findPreference("flush_dnscache").setOnPreferenceClickListener(_ => {
app.track(TAG, "flush_dnscache")
activity.flushDnsCache()
true
})
findPreference("about").setOnPreferenceClickListener((preference: Preference) => { findPreference("about").setOnPreferenceClickListener((preference: Preference) => {
app.track(TAG, "about") app.track(TAG, "about")
val web = new WebView(activity) val web = new WebView(activity)
......
...@@ -162,6 +162,10 @@ class ShadowsocksVpnService extends VpnService with BaseService { ...@@ -162,6 +162,10 @@ class ShadowsocksVpnService extends VpnService with BaseService {
handleConnection() handleConnection()
changeState(State.CONNECTED) changeState(State.CONNECTED)
// lazily get ACL from cloud
getAcl(profile.route)
notification = new ShadowsocksNotification(this, profile.name) notification = new ShadowsocksNotification(this, profile.name)
} }
...@@ -257,6 +261,7 @@ class ShadowsocksVpnService extends VpnService with BaseService { ...@@ -257,6 +261,7 @@ class ShadowsocksVpnService extends VpnService with BaseService {
if (profile.route != Route.ALL) { if (profile.route != Route.ALL) {
cmd += "--acl" cmd += "--acl"
profile.route match { profile.route match {
case Route.BYPASS_LAN => cmd += (getApplicationInfo.dataDir + "/bypass_lan.acl") case Route.BYPASS_LAN => cmd += (getApplicationInfo.dataDir + "/bypass_lan.acl")
case Route.BYPASS_CHN => cmd += (getApplicationInfo.dataDir + "/bypass_chn.acl") case Route.BYPASS_CHN => cmd += (getApplicationInfo.dataDir + "/bypass_chn.acl")
......
...@@ -169,19 +169,6 @@ object Utils { ...@@ -169,19 +169,6 @@ object Utils {
result result
} }
// Because /sys/class/net/* isn't accessible since API level 24
final val FLUSH_DNS = "for if in /sys/class/net/*; do " +
"if [ \"down\" != $(cat $if/operstate) ]; then " + // up or unknown
"ndc resolver flushif ${if##*/}; " +
"fi " +
"done; echo done"
// Blocked > 3 seconds
def toggleAirplaneMode(context: Context) = {
val result = Shell.SU.run(FLUSH_DNS)
result != null && !result.isEmpty
}
def resolve(host: String, addrType: Int): Option[String] = { def resolve(host: String, addrType: Int): Option[String] = {
try { try {
val lookup = new Lookup(host, addrType) val lookup = new Lookup(host, addrType)
......
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