Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bannedbook committed Jan 10, 2020
1 parent 6a90965 commit 172d6d5
Show file tree
Hide file tree
Showing 18 changed files with 313 additions and 80 deletions.
3 changes: 2 additions & 1 deletion V2rayNG/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ android {
}

defaultConfig {
applicationId "com.v2ray.ang"
applicationId "free.v2ray.proxy.VPN"
minSdkVersion 17
targetSdkVersion Integer.parseInt("$targetSdkVer")
multiDexEnabled true
Expand Down Expand Up @@ -85,6 +85,7 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
// Android support library
implementation "com.google.android.gms:play-services-ads:12.0.1"
implementation "com.android.support:support-v4:$supportLibVersion"
implementation "com.android.support:appcompat-v7:$supportLibVersion"
implementation "com.android.support:design:$supportLibVersion"
Expand Down

This file was deleted.

4 changes: 3 additions & 1 deletion V2rayNG/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@
</intent-filter>
</receiver>
<!-- =====================Tasker===================== -->

<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-2194043486084479~8520668797"/>
</application>

</manifest>
65 changes: 65 additions & 0 deletions V2rayNG/app/src/main/kotlin/SpeedUpVPN/VpnEncrypt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package SpeedUpVPN

import android.os.Build
import android.support.annotation.RequiresApi
import android.util.Log
import java.io.File
import javax.crypto.Cipher
import javax.crypto.spec.IvParameterSpec
import javax.crypto.spec.SecretKeySpec


object VpnEncrypt{
private const val theKey="your key"
const val vpnRemark="v2ray.vpn"
val vpnGroupName="SpeedUp.VPN"
@JvmField var builtinServersUpdated=false
@JvmField var builtinSubID="999"
@JvmStatic fun aesEncrypt(v:String, secretKey:String=theKey) = AES256.encrypt(v, secretKey)
@JvmStatic fun aesDecrypt(v:String, secretKey:String=theKey) = AES256.decrypt(v, secretKey)
@JvmStatic fun readFileAsTextUsingInputStream(fileName: String) = File(fileName).inputStream().readBytes().toString(Charsets.UTF_8)
}


private object AES256{
private fun cipher(opmode:Int, secretKey:String):Cipher{
if(secretKey.length != 32) throw RuntimeException("SecretKey length is not 32 chars")
val c = Cipher.getInstance("AES/CBC/PKCS5Padding")
val sk = SecretKeySpec(secretKey.toByteArray(Charsets.UTF_8), "AES")
val iv = IvParameterSpec(secretKey.substring(0, 16).toByteArray(Charsets.UTF_8))
c.init(opmode, sk, iv)
return c
}
fun encrypt(str:String, secretKey:String):String{
val encrypted = cipher(Cipher.ENCRYPT_MODE, secretKey).doFinal(str.toByteArray(Charsets.UTF_8))
var encstr: String
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O || isWindows())
encstr = java.util.Base64.getEncoder().encodeToString(encrypted)
else
encstr = android.util.Base64.encodeToString(encrypted, android.util.Base64.DEFAULT)

return encstr
}
fun decrypt(str:String, secretKey:String):String{
try {
val byteStr: ByteArray;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O || isWindows())
byteStr = java.util.Base64.getDecoder().decode(str.toByteArray(Charsets.UTF_8))
else
byteStr = android.util.Base64.decode(str.toByteArray(Charsets.UTF_8), android.util.Base64.DEFAULT)

return String(cipher(Cipher.DECRYPT_MODE, secretKey).doFinal(byteStr))
} catch (e: Exception) {
Log.e("VpnEncrypt","decrypt failed",e)
return ""
}
}
fun isWindows(): Boolean {
var os= System.getProperty("os.name")
if(os.isNullOrEmpty())
return false
else
return os.contains("Windows")
}
}

8 changes: 5 additions & 3 deletions V2rayNG/app/src/main/kotlin/com/v2ray/ang/AppConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package com.v2ray.ang
* App Config Const
*/
object AppConfig {
const val ANG_PACKAGE = "com.v2ray.ang"
const val ANG_PACKAGE = "free.v2ray.proxy.VPN"
const val ANG_CONFIG = "ang_config"
const val PREF_CURR_CONFIG = "pref_v2ray_config"
const val PREF_CURR_CONFIG_GUID = "pref_v2ray_config_guid"
Expand All @@ -14,6 +14,7 @@ object AppConfig {
const val PREF_INAPP_BUY_IS_PREMIUM = "pref_inapp_buy_is_premium"
const val VMESS_PROTOCOL: String = "vmess://"
const val SS_PROTOCOL: String = "ss://"
const val SSR_PROTOCOL: String = "ssr://"
const val SOCKS_PROTOCOL: String = "socks://"
const val BROADCAST_ACTION_SERVICE = "com.v2ray.ang.action.service"
const val BROADCAST_ACTION_ACTIVITY = "com.v2ray.ang.action.activity"
Expand All @@ -34,8 +35,9 @@ object AppConfig {

const val androidpackagenamelistUrl = "https://raw.githubusercontent.com/2dust/androidpackagenamelist/master/proxy.txt"
const val v2rayCustomRoutingListUrl = "https://raw.githubusercontent.com/2dust/v2rayCustomRoutingList/master/"
const val v2rayNGIssues = "https://github.com/2dust/v2rayNG/issues"
const val promotionUrl = "https://1.2345345.xyz/ads.html"
const val v2rayNGIssues = "https://github.com/bannedbook/v2ray.vpn/issues"
const val promotionUrl = "https://lihi1.com/mWZJL"
const val abloutUrl = "https://github.com/bannedbook/v2ray.vpn"

const val DNS_AGENT = "1.1.1.1"
const val DNS_DIRECT = "223.5.5.5"
Expand Down
52 changes: 49 additions & 3 deletions V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.v2ray.ang.ui

import SpeedUpVPN.VpnEncrypt
import android.Manifest
import android.content.*
import android.net.Uri
Expand All @@ -22,6 +23,7 @@ import org.jetbrains.anko.*
import java.lang.ref.SoftReference
import java.net.URL
import android.content.IntentFilter
import android.graphics.Color
import android.support.design.widget.NavigationView
import android.support.v4.view.GravityCompat
import android.support.v7.app.ActionBarDrawerToggle
Expand All @@ -33,6 +35,7 @@ import rx.android.schedulers.AndroidSchedulers
import java.util.concurrent.TimeUnit
import com.v2ray.ang.helper.SimpleItemTouchHelperCallback
import com.v2ray.ang.util.AngConfigManager.configs
import com.google.android.gms.ads.*

class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedListener {
companion object {
Expand All @@ -58,10 +61,14 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList

private val adapter by lazy { MainRecyclerAdapter(this) }
private var mItemTouchHelper: ItemTouchHelper? = null

lateinit var mAdView : AdView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
MobileAds.initialize(this)
mAdView = findViewById(R.id.adView)
val adRequest = AdRequest.Builder().build()
mAdView.loadAd(adRequest)
title = getString(R.string.title_server)
setSupportActionBar(toolbar)

Expand Down Expand Up @@ -93,6 +100,10 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList
}
}

var recsite1= getResources().getString(R.string.recommended_site_1)
recommended_site_1.setBackgroundColor(Color.TRANSPARENT);
recommended_site_1.loadData(recsite1,"text/html; charset=utf-8", "UTF-8")

recycler_view.setHasFixedSize(true)
recycler_view.layoutManager = LinearLayoutManager(this)
recycler_view.adapter = adapter
Expand All @@ -107,6 +118,7 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList
drawer_layout.addDrawerListener(toggle)
toggle.syncState()
nav_view.setNavigationItemSelectedListener(this)
importConfigViaBuildinSub()
}

fun startV2Ray() {
Expand Down Expand Up @@ -305,13 +317,15 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList
return true
}

fun importBatchConfig(server: String?, subid: String = "") {
fun importBatchConfig(server: String?, subid: String = "") : Boolean {
val count = AngConfigManager.importBatchConfig(server, subid)
if (count > 0) {
toast(R.string.toast_success)
adapter.updateConfigList()
return true
} else {
toast(R.string.toast_failure)
return false
}
}

Expand Down Expand Up @@ -380,7 +394,38 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList
}
return true
}

/**
* import config from BuildinSub
*/
fun importConfigViaBuildinSub(){
toast(R.string.update_builtin_servers)
var builtinSubUrls = getResources().getStringArray(R.array.builtinSubUrls)
doAsync {
for (i in 0 until builtinSubUrls.size) {
try {
val url = builtinSubUrls.get(i)
//Log.d("Main", url)
val configText = URL(url).readText()
//if (configText.isNotEmpty()&&configText.isNotBlank())VpnEncrypt.builtinServersUpdated=true
uiThread {
// builtinSub set id 999
VpnEncrypt.builtinServersUpdated = importBatchConfig(VpnEncrypt.aesDecrypt(configText), VpnEncrypt.builtinSubID)
}
Thread.sleep(10_000)
Log.d("VpnEncrypt", VpnEncrypt.builtinServersUpdated.toString())
if(VpnEncrypt.builtinServersUpdated){
Log.d("VpnEncrypt", "VpnEncrypt builtinServersUpdated,break")
break
}
}
catch (e: Exception) {
//Log.e("VpnEncrypt","",e)
//Log.e("VpnEncrypt",e.toString()) //with url
Log.e("VpnEncrypt",e.stackTrace.first().toString())
}
}
}
}
/**
* import config from sub
*/
Expand Down Expand Up @@ -561,6 +606,7 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList
Utils.openUri(this, AppConfig.promotionUrl)
}
R.id.donate -> {
Utils.openUri(this, AppConfig.abloutUrl)
// startActivity<InappBuyActivity>()
}
R.id.logcat -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.v2ray.ang.ui

import SpeedUpVPN.VpnEncrypt
import android.graphics.Color
import android.support.v7.widget.RecyclerView
import android.text.TextUtils
Expand Down Expand Up @@ -85,6 +86,12 @@ class MainRecyclerAdapter(val activity: MainActivity) : RecyclerView.Adapter<Mai
holder.layout_share.visibility = View.VISIBLE
}

if(VpnEncrypt.vpnRemark == remarks){
holder.statistics.text = address.toString().substring(0,5)+"..."
holder.layout_share.visibility=View.INVISIBLE
holder.layout_edit.visibility=View.INVISIBLE
}

holder.layout_share.setOnClickListener {
mActivity.selector(null, share_method.asList()) { dialogInterface, i ->
try {
Expand Down
45 changes: 42 additions & 3 deletions V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/AngConfigManager.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.v2ray.ang.util

import SpeedUpVPN.VpnEncrypt
import android.graphics.Bitmap
import android.text.TextUtils
import android.util.Log
Expand All @@ -11,6 +12,7 @@ import com.v2ray.ang.AppConfig.PREF_CURR_CONFIG
import com.v2ray.ang.AppConfig.PREF_CURR_CONFIG_GUID
import com.v2ray.ang.AppConfig.PREF_CURR_CONFIG_NAME
import com.v2ray.ang.AppConfig.SOCKS_PROTOCOL
import com.v2ray.ang.AppConfig.SSR_PROTOCOL
import com.v2ray.ang.AppConfig.SS_PROTOCOL
import com.v2ray.ang.AppConfig.VMESS_PROTOCOL
import com.v2ray.ang.R
Expand Down Expand Up @@ -326,6 +328,30 @@ object AngConfigManager {
vmess.port = match.groupValues[4].toInt()
vmess.subid = subid

addShadowsocksServer(vmess, -1)
} else if (server.startsWith(SSR_PROTOCOL)) {
var server = server.replace(SSR_PROTOCOL, "")
server = Utils.decode(server)
val decodedPattern_ssr = "(?i)^((.+):(\\d+?):(.*):(.+):(.*):(.+)/(.*))".toRegex()
val match = decodedPattern_ssr.matchEntire(server)
//Log.e("------","match="+match.toString())
if (match == null) {
return R.string.toast_incorrect_protocol
}

vmess.remarks=""
val decodedPattern_ssr_groupparam = "(?i)(.*)[?&]group=([A-Za-z0-9_=-]*)(.*)".toRegex()
val match4 = decodedPattern_ssr_groupparam.matchEntire(match.groupValues[8])
if (match4 != null) vmess.remarks = Utils.decode(match4.groupValues[2])
if (vmess.remarks==VpnEncrypt.vpnGroupName)vmess.remarks=VpnEncrypt.vpnRemark
vmess.security = match.groupValues[5].toLowerCase(Locale.ENGLISH)
vmess.id = Utils.decode(match.groupValues[7]) //is passwd?
vmess.address = match.groupValues[2].toLowerCase(Locale.ENGLISH)
if (vmess.address.firstOrNull() == '[' && vmess.address.lastOrNull() == ']')
vmess.address = vmess.address.substring(1, vmess.address.length - 1)
vmess.port = match.groupValues[3].toInt()
vmess.subid = subid

addShadowsocksServer(vmess, -1)
} else if (server.startsWith(SOCKS_PROTOCOL)) {
var result = server.replace(SOCKS_PROTOCOL, "")
Expand Down Expand Up @@ -413,6 +439,7 @@ object AngConfigManager {
}

val vmess = angConfig.vmess[index]
if (vmess.remarks== VpnEncrypt.vpnRemark)return ""
if (angConfig.vmess[index].configType == AppConfig.EConfigType.Vmess) {

val vmessQRCode = VmessQRCode()
Expand Down Expand Up @@ -725,7 +752,7 @@ object AngConfigManager {

fun importBatchConfig(servers: String?, subid: String): Int {
try {
if (servers == null) {
if (servers == null || servers =="") {
return 0
}
removeServerViaSubid(subid)
Expand All @@ -736,8 +763,20 @@ object AngConfigManager {
// }

var count = 0
servers.lines()
.forEach {
var limit = -1
var serverList=servers.trim().lines()
if (servers.indexOf("MAX=") == 0) {
limit = servers.split("\n")[0].split("MAX=")[1]
.replace("\\D+".toRegex(), "").toInt()
serverList=serverList.drop(1)
}
//Log.e("------","limit is "+limit)
//Log.e("------","serverList1:"+serverList)
if (limit != -1 && limit < serverList.size) {
serverList = serverList.shuffled().take(limit)
}
//Log.e("------","serverList2:"+serverList)
serverList.forEach {
val resId = importConfig(it, subid)
if (resId == 0) {
count++
Expand Down
Loading

0 comments on commit 172d6d5

Please sign in to comment.