Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
Subscribe to add alias regular filter Add const LOOPBACK
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust authored and AnGgIt86 committed Sep 28, 2024
1 parent bf6d43c commit 8693ba8
Show file tree
Hide file tree
Showing 20 changed files with 55 additions and 8 deletions.
1 change: 1 addition & 0 deletions app/src/main/kotlin/com/neko/v2ray/AppConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ object AppConfig {
const val WIREGUARD_LOCAL_ADDRESS_V4 = "172.16.0.2/32"
const val WIREGUARD_LOCAL_ADDRESS_V6 = "2606:4700:110:8f81:d551:a0:532e:a2b3/128"
const val WIREGUARD_LOCAL_MTU = "1420"
const val LOOPBACK = "127.0.0.1"

/** Message constants for communication. */
const val MSG_REGISTER_CLIENT = 1
Expand Down
1 change: 1 addition & 0 deletions app/src/main/kotlin/com/neko/v2ray/dto/SubscriptionItem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ data class SubscriptionItem(
val updateInterval: Int? = null,
var prevProfile: String? = null,
var nextProfile: String? = null,
var filter: String? = null,
)

5 changes: 3 additions & 2 deletions app/src/main/kotlin/com/neko/v2ray/service/V2RayVpnService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import android.os.StrictMode
import android.util.Log
import androidx.annotation.RequiresApi
import com.neko.v2ray.AppConfig
import com.neko.v2ray.AppConfig.LOOPBACK
import com.neko.v2ray.BuildConfig
import com.neko.v2ray.R
import com.neko.v2ray.util.MmkvManager.settingsStorage
Expand Down Expand Up @@ -207,7 +208,7 @@ class V2RayVpnService : VpnService(), ServiceControl {
File(applicationContext.applicationInfo.nativeLibraryDir, TUN2SOCKS).absolutePath,
"--netif-ipaddr", PRIVATE_VLAN4_ROUTER,
"--netif-netmask", "255.255.255.252",
"--socks-server-addr", "127.0.0.1:${socksPort}",
"--socks-server-addr", "$LOOPBACK:${socksPort}",
"--tunmtu", VPN_MTU.toString(),
"--sock-path", "sock_path",//File(applicationContext.filesDir, "sock_path").absolutePath,
"--enable-udprelay",
Expand All @@ -221,7 +222,7 @@ class V2RayVpnService : VpnService(), ServiceControl {
if (settingsStorage?.decodeBool(AppConfig.PREF_LOCAL_DNS_ENABLED) == true) {
val localDnsPort = Utils.parseInt(settingsStorage?.decodeString(AppConfig.PREF_LOCAL_DNS_PORT), AppConfig.PORT_LOCAL_DNS.toInt())
cmd.add("--dnsgw")
cmd.add("127.0.0.1:${localDnsPort}")
cmd.add("$LOOPBACK:${localDnsPort}")
}
Log.d(packageName, cmd.toString())

Expand Down
5 changes: 4 additions & 1 deletion app/src/main/kotlin/com/neko/v2ray/ui/SubEditActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class SubEditActivity : BaseActivity() {
private fun bindingServer(subItem: SubscriptionItem): Boolean {
binding.etRemarks.text = Utils.getEditable(subItem.remarks)
binding.etUrl.text = Utils.getEditable(subItem.url)
binding.etFilter.text = Utils.getEditable(subItem.filter)
binding.chkEnable.isChecked = subItem.enabled
binding.autoUpdateCheck.isChecked = subItem.autoUpdate
binding.etPreProfile.text = Utils.getEditable(subItem.prevProfile)
Expand All @@ -109,6 +110,7 @@ class SubEditActivity : BaseActivity() {
private fun clearServer(): Boolean {
binding.etRemarks.text = null
binding.etUrl.text = null
binding.etFilter.text = null
binding.chkEnable.isChecked = true
binding.etPreProfile.text = null
binding.etNextProfile.text = null
Expand All @@ -119,10 +121,11 @@ class SubEditActivity : BaseActivity() {
* save server config
*/
private fun saveServer(): Boolean {
val subItem = MmkvManager.decodeSubscription(editSubId)?:SubscriptionItem()
val subItem = MmkvManager.decodeSubscription(editSubId) ?: SubscriptionItem()

subItem.remarks = binding.etRemarks.text.toString()
subItem.url = binding.etUrl.text.toString()
subItem.filter = binding.etFilter.text.toString()
subItem.enabled = binding.chkEnable.isChecked
subItem.autoUpdate = binding.autoUpdateCheck.isChecked
subItem.prevProfile = binding.etPreProfile.text.toString()
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/kotlin/com/neko/v2ray/ui/UserAssetActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.tbruyelle.rxpermissions3.RxPermissions
import com.neko.v2ray.AppConfig
import com.neko.v2ray.AppConfig.LOOPBACK
import com.neko.v2ray.R
import com.neko.v2ray.databinding.ActivityUserAssetBinding
import com.neko.v2ray.databinding.ActivitySubSettingBinding
import com.neko.v2ray.databinding.ItemRecyclerUserAssetBinding
import com.neko.v2ray.databinding.LayoutProgressBinding
import com.neko.v2ray.dto.AssetUrlItem
Expand Down Expand Up @@ -218,7 +219,7 @@ class UserAssetActivity : BaseActivity() {
URL(item.url).openConnection(
Proxy(
Proxy.Type.HTTP,
InetSocketAddress("127.0.0.1", httpPort)
InetSocketAddress(LOOPBACK, httpPort)
)
) as HttpURLConnection
}
Expand Down
11 changes: 10 additions & 1 deletion app/src/main/kotlin/com/neko/v2ray/util/AngConfigManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ object AngConfigManager {
private fun parseConfig(
str: String?,
subid: String,
subItem: SubscriptionItem?,
removedSelectedServer: ServerConfig?
): Int {
try {
Expand Down Expand Up @@ -59,6 +60,13 @@ object AngConfigManager {
if (config == null) {
return R.string.toast_incorrect_protocol
}
//filter
if (subItem?.filter != null && subItem.filter?.isNotEmpty() == true && config.remarks.isNotEmpty()) {
val matched = Regex(pattern = subItem.filter ?: "")
.containsMatchIn(input = config.remarks)
if (!matched) return -1
}

config.subscriptionId = subid
val guid = MmkvManager.encodeServerConfig("", config)
if (removedSelectedServer != null &&
Expand Down Expand Up @@ -243,11 +251,12 @@ object AngConfigManager {
MmkvManager.removeServerViaSubid(subid)
}

val subItem = MmkvManager.decodeSubscription(subid)
var count = 0
servers.lines()
.reversed()
.forEach {
val resId = parseConfig(it, subid, removedSelectedServer)
val resId = parseConfig(it, subid, subItem, removedSelectedServer)
if (resId == 0) {
count++
}
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/kotlin/com/neko/v2ray/util/SpeedtestUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.os.SystemClock
import android.text.TextUtils
import android.util.Log
import com.neko.v2ray.AppConfig
import com.neko.v2ray.AppConfig.LOOPBACK
import com.neko.v2ray.R
import com.neko.v2ray.extension.responseLength
import kotlinx.coroutines.isActive
Expand Down Expand Up @@ -108,7 +109,7 @@ object SpeedtestUtil {
conn = url.openConnection(
Proxy(
Proxy.Type.HTTP,
InetSocketAddress("127.0.0.1", port)
InetSocketAddress(LOOPBACK, port)
)
) as HttpURLConnection
conn.connectTimeout = 30000
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/kotlin/com/neko/v2ray/util/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import android.webkit.URLUtil
import androidx.appcompat.app.AppCompatDelegate
import com.neko.v2ray.AppConfig
import com.neko.v2ray.AppConfig.ANG_PACKAGE
import com.neko.v2ray.AppConfig.LOOPBACK
import com.neko.v2ray.BuildConfig
import com.neko.v2ray.R
import com.neko.v2ray.extension.toast
Expand Down Expand Up @@ -359,7 +360,7 @@ object Utils {
url.openConnection(
Proxy(
Proxy.Type.HTTP,
InetSocketAddress("127.0.0.1", httpPort)
InetSocketAddress(LOOPBACK, httpPort)
)
)
}
Expand Down
18 changes: 18 additions & 0 deletions app/src/main/res/layout/activity_sub_edit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,24 @@
tools:ignore="TextFields" />
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8.0dip"
android:layout_marginBottom="8.0dip">
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/sub_setting_filter"
style="@style/Outline_TextInputLayout">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/et_filter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text" />
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@
<string name="title_sub_setting">الاشتراك</string>
<string name="sub_setting_remarks">ملاحظات</string>
<string name="sub_setting_url">عنوان URL اختياري</string>
<string name="sub_setting_filter">ملاحظات الفلتر العادي</string>
<string name="sub_setting_enable">تمكين التحديث</string>
<string name="sub_auto_update">تمكين التحديث التلقائي</string>
<string name="sub_setting_pre_profile">تصريحات الوكالة السابقة</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-fa/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@
<string name="title_sub_setting">اشتراک</string>
<string name="sub_setting_remarks">ملاحظات</string>
<string name="sub_setting_url">URL اختیاری</string>
<string name="sub_setting_filter">اظهارات فیلتر معمولی</string>
<string name="sub_setting_enable">فعال کردن آپدیت</string>
<string name="sub_auto_update">فعال کردن به روز رسانی خودکار</string>
<string name="sub_setting_pre_profile">اظهارات نیابتی قبلی</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-in/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@
<string name="title_sub_setting">Berlangganan</string>
<string name="sub_setting_remarks">keterangan</string>
<string name="sub_setting_url">URL Opsi</string>
<string name="sub_setting_filter">Komentar filter biasa</string>
<string name="sub_setting_enable">Aktifkan pembaruan</string>
<string name="sub_auto_update">Aktifkan pembaruan otomatis</string>
<string name="sub_setting_pre_profile">Pernyataan proksi sebelumnya</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@
<string name="title_sub_setting">サブスクリプション</string>
<string name="sub_setting_remarks">備考</string>
<string name="sub_setting_url">オプションの URL</string>
<string name="sub_setting_filter">備考 通常フィルター</string>
<string name="sub_setting_enable">アップデートを有効にする</string>
<string name="sub_auto_update">自動更新を有効にする</string>
<string name="sub_setting_pre_profile">以前の代理人の発言</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-jw/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@
<string name="title_sub_setting">Langganan</string>
<string name="sub_setting_remarks">deskripsi</string>
<string name="sub_setting_url">URL Pilihan</string>
<string name="sub_setting_filter">Cathetan filter biasa</string>
<string name="sub_setting_enable">Aktifake nganyari</string>
<string name="sub_auto_update">Aktifake nganyari otomatis</string>
<string name="sub_setting_pre_profile">Komentar proxy sadurunge</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@
<string name="title_sub_setting">Подписка</string>
<string name="sub_setting_remarks">замечания</string>
<string name="sub_setting_url">Необязательный URL-адрес</string>
<string name="sub_setting_filter">Примечания регулярный фильтр</string>
<string name="sub_setting_enable">Включить обновление</string>
<string name="sub_auto_update">Включить автоматическое обновление</string>
<string name="sub_setting_pre_profile">Предыдущие замечания доверенности</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-su/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@
<string name="title_sub_setting">Ngalangganan</string>
<string name="sub_setting_remarks">inpormasi</string>
<string name="sub_setting_url">URL pilihan</string>
<string name="sub_setting_filter">Catetan filter biasa</string>
<string name="sub_setting_enable">Aktipkeun apdet</string>
<string name="sub_auto_update">Aktipkeun apdet otomatis</string>
<string name="sub_setting_pre_profile">Ucapan proxy saméméhna</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-vi/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@
<string name="title_sub_setting">Đăng ký</string>
<string name="sub_setting_remarks">nhận xét</string>
<string name="sub_setting_url">URL tùy chọn</string>
<string name="sub_setting_filter">Nhận xét bộ lọc thông thường</string>
<string name="sub_setting_enable">Bật cập nhật</string>
<string name="sub_auto_update">Bật cập nhật tự động</string>
<string name="sub_setting_pre_profile">Nhận xét ủy quyền trước đó</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@
<string name="title_sub_setting">订阅</string>
<string name="sub_setting_remarks">评论</string>
<string name="sub_setting_url">可选网址</string>
<string name="sub_setting_filter">备注常规过滤器</string>
<string name="sub_setting_enable">启用更新</string>
<string name="sub_auto_update">启用自动更新</string>
<string name="sub_setting_pre_profile">先前的代理意见</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@
<string name="title_sub_setting">訂閱</string>
<string name="sub_setting_remarks">評論</string>
<string name="sub_setting_url">可選網址</string>
<string name="sub_setting_filter">備註 常規過濾器</string>
<string name="sub_setting_enable">啟用更新</string>
<string name="sub_auto_update">啟用自動更新</string>
<string name="sub_setting_pre_profile">之前的代理備註</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@
<string name="title_sub_setting">Subscription</string>
<string name="sub_setting_remarks">remarks</string>
<string name="sub_setting_url">Optional URL</string>
<string name="sub_setting_filter">Remarks regular filter</string>
<string name="sub_setting_enable">Enable update</string>
<string name="sub_auto_update">Enable automatic update</string>
<string name="sub_setting_pre_profile">Previous proxy remarks</string>
Expand Down

0 comments on commit 8693ba8

Please sign in to comment.