mirror of
https://github.com/MatsuriDayo/NekoBoxForAndroid.git
synced 2025-12-19 14:40:06 +08:00
fix
This commit is contained in:
parent
4b0886e9fb
commit
6dec4d058b
@ -612,11 +612,7 @@ fun buildConfig(
|
|||||||
tag = TAG_DNS_IN
|
tag = TAG_DNS_IN
|
||||||
listen = bind
|
listen = bind
|
||||||
listen_port = DataStore.localDNSPort
|
listen_port = DataStore.localDNSPort
|
||||||
override_address = if (!remoteDns.first().isIpAddress()) {
|
override_address = "8.8.8.8"
|
||||||
"8.8.8.8"
|
|
||||||
} else {
|
|
||||||
remoteDns.first()
|
|
||||||
}
|
|
||||||
override_port = 53
|
override_port = 53
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -631,23 +627,6 @@ fun buildConfig(
|
|||||||
directDNS = listOf(LOCAL_DNS_SERVER)
|
directDNS = listOf(LOCAL_DNS_SERVER)
|
||||||
}
|
}
|
||||||
|
|
||||||
// routing for DNS server
|
|
||||||
for (dns in remoteDns) {
|
|
||||||
if (!dns.isIpAddress()) continue
|
|
||||||
route.rules.add(Rule_DefaultOptions().apply {
|
|
||||||
outbound = TAG_PROXY
|
|
||||||
ip_cidr = listOf(dns)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
for (dns in directDNS) {
|
|
||||||
if (!dns.isIpAddress()) continue
|
|
||||||
route.rules.add(Rule_DefaultOptions().apply {
|
|
||||||
outbound = TAG_DIRECT
|
|
||||||
ip_cidr = listOf(dns)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bypass Lookup for the first profile
|
// Bypass Lookup for the first profile
|
||||||
bypassDNSBeans.forEach {
|
bypassDNSBeans.forEach {
|
||||||
var serverAddr = it.serverAddress
|
var serverAddr = it.serverAddress
|
||||||
@ -680,10 +659,9 @@ fun buildConfig(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// remote dns obj
|
// remote dns obj
|
||||||
remoteDns.firstOrNull()?.apply {
|
remoteDns.firstOrNull().let {
|
||||||
val d = this
|
|
||||||
dns.servers.add(DNSServerOptions().apply {
|
dns.servers.add(DNSServerOptions().apply {
|
||||||
address = d
|
address = it ?: throw Exception("No remote DNS, check your settings!")
|
||||||
tag = "dns-remote"
|
tag = "dns-remote"
|
||||||
address_resolver = "dns-direct"
|
address_resolver = "dns-direct"
|
||||||
applyDNSNetworkSettings(false)
|
applyDNSNetworkSettings(false)
|
||||||
@ -691,10 +669,9 @@ fun buildConfig(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// add directDNS objects here
|
// add directDNS objects here
|
||||||
directDNS.firstOrNull()?.apply {
|
directDNS.firstOrNull().let {
|
||||||
val d = this
|
|
||||||
dns.servers.add(DNSServerOptions().apply {
|
dns.servers.add(DNSServerOptions().apply {
|
||||||
address = d
|
address = it ?: throw Exception("No direct DNS, check your settings!")
|
||||||
tag = "dns-direct"
|
tag = "dns-direct"
|
||||||
detour = "direct"
|
detour = "direct"
|
||||||
address_resolver = "dns-local"
|
address_resolver = "dns-local"
|
||||||
@ -774,13 +751,11 @@ fun buildConfig(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable DNS for test
|
|
||||||
if (forTest) {
|
if (forTest) {
|
||||||
dns.servers.clear()
|
// Disable DNS for test
|
||||||
dns.rules.clear()
|
dns.rules.clear()
|
||||||
}
|
} else {
|
||||||
|
// built-in DNS rules
|
||||||
if (!forTest) {
|
|
||||||
route.rules.add(0, Rule_DefaultOptions().apply {
|
route.rules.add(0, Rule_DefaultOptions().apply {
|
||||||
inbound = listOf(TAG_DNS_IN)
|
inbound = listOf(TAG_DNS_IN)
|
||||||
outbound = TAG_DNS_OUT
|
outbound = TAG_DNS_OUT
|
||||||
@ -806,6 +781,13 @@ fun buildConfig(
|
|||||||
server = "dns-block"
|
server = "dns-block"
|
||||||
disable_cache = true
|
disable_cache = true
|
||||||
})
|
})
|
||||||
|
// force bypass
|
||||||
|
if (domainListDNSDirectForce.isNotEmpty()) {
|
||||||
|
dns.rules.add(0, DNSRule_DefaultOptions().apply {
|
||||||
|
makeSingBoxRule(domainListDNSDirectForce.toHashSet().toList())
|
||||||
|
server = "dns-direct"
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// fakedns obj
|
// fakedns obj
|
||||||
@ -825,14 +807,6 @@ fun buildConfig(
|
|||||||
disable_cache = true
|
disable_cache = true
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// force bypass
|
|
||||||
if (domainListDNSDirectForce.isNotEmpty()) {
|
|
||||||
dns.rules.add(0, DNSRule_DefaultOptions().apply {
|
|
||||||
makeSingBoxRule(domainListDNSDirectForce.toHashSet().toList())
|
|
||||||
server = "dns-direct"
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}.let {
|
}.let {
|
||||||
ConfigBuildResult(
|
ConfigBuildResult(
|
||||||
gson.toJson(it.asMap().apply {
|
gson.toJson(it.asMap().apply {
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import com.esotericsoftware.kryo.io.ByteBufferInput;
|
|||||||
import com.esotericsoftware.kryo.io.ByteBufferOutput;
|
import com.esotericsoftware.kryo.io.ByteBufferOutput;
|
||||||
|
|
||||||
import io.nekohasekai.sagernet.fmt.AbstractBean;
|
import io.nekohasekai.sagernet.fmt.AbstractBean;
|
||||||
|
import io.nekohasekai.sagernet.fmt.trojan.TrojanBean;
|
||||||
import moe.matsuri.nb4a.utils.JavaUtil;
|
import moe.matsuri.nb4a.utils.JavaUtil;
|
||||||
|
|
||||||
public abstract class StandardV2RayBean extends AbstractBean {
|
public abstract class StandardV2RayBean extends AbstractBean {
|
||||||
@ -63,7 +64,13 @@ public abstract class StandardV2RayBean extends AbstractBean {
|
|||||||
if (JavaUtil.isNullOrBlank(host)) host = "";
|
if (JavaUtil.isNullOrBlank(host)) host = "";
|
||||||
if (JavaUtil.isNullOrBlank(path)) path = "";
|
if (JavaUtil.isNullOrBlank(path)) path = "";
|
||||||
|
|
||||||
if (JavaUtil.isNullOrBlank(security)) security = "none";
|
if (JavaUtil.isNullOrBlank(security)) {
|
||||||
|
if (this instanceof TrojanBean || isVLESS()) {
|
||||||
|
security = "tls";
|
||||||
|
} else {
|
||||||
|
security = "none";
|
||||||
|
}
|
||||||
|
}
|
||||||
if (JavaUtil.isNullOrBlank(sni)) sni = "";
|
if (JavaUtil.isNullOrBlank(sni)) sni = "";
|
||||||
if (JavaUtil.isNullOrBlank(alpn)) alpn = "";
|
if (JavaUtil.isNullOrBlank(alpn)) alpn = "";
|
||||||
|
|
||||||
|
|||||||
@ -70,7 +70,7 @@ class BackupFragment : NamedFragment(R.layout.layout_backup) {
|
|||||||
)
|
)
|
||||||
onMainDispatcher {
|
onMainDispatcher {
|
||||||
startFilesForResult(
|
startFilesForResult(
|
||||||
exportSettings, "matsuri_backup_${Date().toLocaleString()}.json"
|
exportSettings, "nekobox_backup_${Date().toLocaleString()}.json"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -85,7 +85,7 @@ class BackupFragment : NamedFragment(R.layout.layout_backup) {
|
|||||||
)
|
)
|
||||||
app.cacheDir.mkdirs()
|
app.cacheDir.mkdirs()
|
||||||
val cacheFile = File(
|
val cacheFile = File(
|
||||||
app.cacheDir, "matsuri_backup_${Date().toLocaleString()}.json"
|
app.cacheDir, "nekobox_backup_${Date().toLocaleString()}.json"
|
||||||
)
|
)
|
||||||
cacheFile.writeText(content)
|
cacheFile.writeText(content)
|
||||||
onMainDispatcher {
|
onMainDispatcher {
|
||||||
|
|||||||
@ -45,11 +45,7 @@ abstract class StandardV2RaySettingsActivity : ProfileSettingsActivity<StandardV
|
|||||||
private val realityShortId = pbm.add(PreferenceBinding(Type.Text, "realityShortId"))
|
private val realityShortId = pbm.add(PreferenceBinding(Type.Text, "realityShortId"))
|
||||||
|
|
||||||
override fun StandardV2RayBean.init() {
|
override fun StandardV2RayBean.init() {
|
||||||
if (this is VMessBean) {
|
if (this is TrojanBean) {
|
||||||
if (intent?.getBooleanExtra("vless", false) == true) {
|
|
||||||
alterId = -1
|
|
||||||
}
|
|
||||||
} else if (this is TrojanBean) {
|
|
||||||
this@StandardV2RaySettingsActivity.uuid.fieldName = "password"
|
this@StandardV2RaySettingsActivity.uuid.fieldName = "password"
|
||||||
this@StandardV2RaySettingsActivity.password.disable = true
|
this@StandardV2RaySettingsActivity.password.disable = true
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,10 @@ import io.nekohasekai.sagernet.fmt.v2ray.VMessBean
|
|||||||
|
|
||||||
class VMessSettingsActivity : StandardV2RaySettingsActivity() {
|
class VMessSettingsActivity : StandardV2RaySettingsActivity() {
|
||||||
|
|
||||||
override fun createEntity() = VMessBean()
|
override fun createEntity() = VMessBean().apply {
|
||||||
|
if (intent?.getBooleanExtra("vless", false) == true) {
|
||||||
|
alterId = -1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user