mirror of
https://github.com/MatsuriDayo/NekoBoxForAndroid.git
synced 2025-12-19 06:30:05 +08:00
chore: listByLineOrComma
This commit is contained in:
parent
e376369493
commit
0ac26db5ba
@ -41,6 +41,7 @@ import moe.matsuri.nb4a.proxy.shadowtls.ShadowTLSBean
|
||||
import moe.matsuri.nb4a.proxy.shadowtls.buildSingBoxOutboundShadowTLSBean
|
||||
import moe.matsuri.nb4a.utils.JavaUtil.gson
|
||||
import moe.matsuri.nb4a.utils.Util
|
||||
import moe.matsuri.nb4a.utils.listByLineOrComma
|
||||
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
|
||||
|
||||
const val TAG_MIXED = "mixed-in"
|
||||
@ -544,16 +545,16 @@ fun buildConfig(
|
||||
}
|
||||
var domainList: List<String>? = null
|
||||
if (rule.domains.isNotBlank()) {
|
||||
domainList = rule.domains.split("\n")
|
||||
domainList = rule.domains.listByLineOrComma()
|
||||
makeSingBoxRule(domainList, false)
|
||||
}
|
||||
if (rule.ip.isNotBlank()) {
|
||||
makeSingBoxRule(rule.ip.split("\n"), true)
|
||||
makeSingBoxRule(rule.ip.listByLineOrComma(), true)
|
||||
}
|
||||
if (rule.port.isNotBlank()) {
|
||||
port = mutableListOf<Int>()
|
||||
port_range = mutableListOf<String>()
|
||||
rule.port.split(",").map {
|
||||
rule.port.listByLineOrComma().map {
|
||||
if (it.contains(":")) {
|
||||
port_range.add(it)
|
||||
} else {
|
||||
@ -564,7 +565,7 @@ fun buildConfig(
|
||||
if (rule.sourcePort.isNotBlank()) {
|
||||
source_port = mutableListOf<Int>()
|
||||
source_port_range = mutableListOf<String>()
|
||||
rule.sourcePort.split(",").map {
|
||||
rule.sourcePort.listByLineOrComma().map {
|
||||
if (it.contains(":")) {
|
||||
source_port_range.add(it)
|
||||
} else {
|
||||
@ -576,10 +577,10 @@ fun buildConfig(
|
||||
network = listOf(rule.network)
|
||||
}
|
||||
if (rule.source.isNotBlank()) {
|
||||
source_ip_cidr = rule.source.split("\n")
|
||||
source_ip_cidr = rule.source.listByLineOrComma()
|
||||
}
|
||||
if (rule.protocol.isNotBlank()) {
|
||||
protocol = rule.protocol.split("\n")
|
||||
protocol = rule.protocol.listByLineOrComma()
|
||||
}
|
||||
|
||||
fun makeDnsRuleObj(): DNSRule_DefaultOptions {
|
||||
|
||||
@ -4,6 +4,7 @@ import io.nekohasekai.sagernet.database.DataStore
|
||||
import io.nekohasekai.sagernet.fmt.LOCALHOST
|
||||
import io.nekohasekai.sagernet.ktx.*
|
||||
import moe.matsuri.nb4a.SingBoxOptions
|
||||
import moe.matsuri.nb4a.utils.listByLineOrComma
|
||||
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
|
||||
import org.json.JSONObject
|
||||
import java.io.File
|
||||
@ -226,7 +227,7 @@ fun buildSingBoxOutboundHysteriaBean(bean: HysteriaBean): SingBoxOptions.Outboun
|
||||
server_name = bean.sni
|
||||
}
|
||||
if (bean.alpn.isNotBlank()) {
|
||||
alpn = bean.alpn.split("\n")
|
||||
alpn = bean.alpn.listByLineOrComma()
|
||||
}
|
||||
if (bean.caText.isNotBlank()) {
|
||||
certificate = bean.caText
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package io.nekohasekai.sagernet.fmt.ssh
|
||||
|
||||
import moe.matsuri.nb4a.SingBoxOptions
|
||||
import moe.matsuri.nb4a.utils.listByLineOrComma
|
||||
|
||||
fun buildSingBoxOutboundSSHBean(bean: SSHBean): SingBoxOptions.Outbound_SSHOptions {
|
||||
return SingBoxOptions.Outbound_SSHOptions().apply {
|
||||
@ -9,7 +10,7 @@ fun buildSingBoxOutboundSSHBean(bean: SSHBean): SingBoxOptions.Outbound_SSHOptio
|
||||
server_port = bean.serverPort
|
||||
user = bean.username
|
||||
if (bean.publicKey.isNotBlank()) {
|
||||
host_key = bean.publicKey.split("\n")
|
||||
host_key = bean.publicKey.listByLineOrComma()
|
||||
}
|
||||
when (bean.authType) {
|
||||
SSHBean.AUTH_TYPE_PRIVATE_KEY -> {
|
||||
|
||||
@ -2,9 +2,9 @@ package io.nekohasekai.sagernet.fmt.tuic
|
||||
|
||||
import io.nekohasekai.sagernet.fmt.LOCALHOST
|
||||
import io.nekohasekai.sagernet.ktx.isIpAddress
|
||||
import io.nekohasekai.sagernet.ktx.wrapIPV6Host
|
||||
import moe.matsuri.nb4a.utils.JavaUtil
|
||||
import moe.matsuri.nb4a.utils.Util
|
||||
import moe.matsuri.nb4a.utils.listByLineOrComma
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
import java.io.File
|
||||
@ -61,7 +61,7 @@ fun TuicBean.buildTuicConfigV5(port: Int, cacheFile: (() -> File)?): JSONObject
|
||||
|
||||
put("udp_relay_mode", udpRelayMode)
|
||||
if (alpn.isNotBlank()) {
|
||||
put("alpn", JSONArray(alpn.split("\n")))
|
||||
put("alpn", JSONArray(alpn.listByLineOrComma()))
|
||||
}
|
||||
put("congestion_control", congestionController)
|
||||
put("disable_sni", disableSNI2)
|
||||
@ -109,7 +109,7 @@ fun TuicBean.buildTuicConfigV4(port: Int, cacheFile: (() -> File)?): JSONObject
|
||||
|
||||
put("udp_relay_mode", udpRelayMode)
|
||||
if (alpn.isNotBlank()) {
|
||||
put("alpn", JSONArray(alpn.split("\n")))
|
||||
put("alpn", JSONArray(alpn.listByLineOrComma()))
|
||||
}
|
||||
put("congestion_controller", congestionController)
|
||||
put("disable_sni", disableSNI2)
|
||||
|
||||
@ -7,6 +7,7 @@ import io.nekohasekai.sagernet.fmt.trojan.TrojanBean
|
||||
import io.nekohasekai.sagernet.ktx.*
|
||||
import moe.matsuri.nb4a.SingBoxOptions.*
|
||||
import moe.matsuri.nb4a.utils.NGUtil
|
||||
import moe.matsuri.nb4a.utils.listByLineOrComma
|
||||
import okhttp3.HttpUrl
|
||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||
import org.json.JSONObject
|
||||
@ -580,7 +581,7 @@ fun buildSingBoxOutboundTLS(bean: StandardV2RayBean): OutboundTLSOptions? {
|
||||
enabled = true
|
||||
insecure = bean.allowInsecure
|
||||
if (bean.sni.isNotBlank()) server_name = bean.sni
|
||||
if (bean.alpn.isNotBlank()) alpn = bean.alpn.split("\n")
|
||||
if (bean.alpn.isNotBlank()) alpn = bean.alpn.listByLineOrComma()
|
||||
if (bean.certificates.isNotBlank()) certificate = bean.certificates
|
||||
if (bean.utlsFingerprint.isNotBlank()) {
|
||||
utls = OutboundUTLSOptions().apply {
|
||||
|
||||
@ -1,13 +1,14 @@
|
||||
package io.nekohasekai.sagernet.fmt.wireguard
|
||||
|
||||
import moe.matsuri.nb4a.SingBoxOptions
|
||||
import moe.matsuri.nb4a.utils.listByLineOrComma
|
||||
|
||||
fun buildSingBoxOutboundWireguardBean(bean: WireGuardBean): SingBoxOptions.Outbound_WireGuardOptions {
|
||||
return SingBoxOptions.Outbound_WireGuardOptions().apply {
|
||||
type = "wireguard"
|
||||
server = bean.serverAddress
|
||||
server_port = bean.serverPort
|
||||
local_address = bean.localAddress.split("\n")
|
||||
local_address = bean.localAddress.listByLineOrComma()
|
||||
private_key = bean.privateKey
|
||||
peer_public_key = bean.peerPublicKey
|
||||
pre_shared_key = bean.peerPreSharedKey
|
||||
|
||||
@ -48,8 +48,15 @@ fun Long.toBytesString(): String {
|
||||
this > 1024 * 1024 * 1024 -> String.format(
|
||||
"%.2f GiB", (this.toDouble() / 1024 / 1024 / 1024)
|
||||
)
|
||||
|
||||
this > 1024 * 1024 -> String.format("%.2f MiB", (this.toDouble() / 1024 / 1024))
|
||||
this > 1024 -> String.format("%.2f KiB", (this.toDouble() / 1024))
|
||||
else -> "$this Bytes"
|
||||
}
|
||||
}
|
||||
|
||||
// List
|
||||
|
||||
fun String.listByLineOrComma(): List<String> {
|
||||
return this.replace(",", "\n").split("\n")
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user