Skip to content

Commit

Permalink
Add share 4 Wireguard
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Jan 18, 2024
1 parent 68e08e3 commit ea383c4
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
30 changes: 28 additions & 2 deletions V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/AngConfigManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import com.v2ray.ang.AppConfig
import com.v2ray.ang.AppConfig.ANG_CONFIG
import com.v2ray.ang.AppConfig.HTTPS_PROTOCOL
import com.v2ray.ang.AppConfig.HTTP_PROTOCOL
import com.v2ray.ang.AppConfig.WIREGUARD_LOCAL_ADDRESS_V4
import com.v2ray.ang.AppConfig.WIREGUARD_LOCAL_MTU
import com.v2ray.ang.R
import com.v2ray.ang.dto.*
import com.v2ray.ang.dto.V2rayConfig.Companion.DEFAULT_SECURITY
Expand Down Expand Up @@ -432,6 +434,28 @@ object AngConfigManager {
queryParam["security"] ?: "", allowInsecure,
queryParam["sni"] ?: sni, fingerprint, queryParam["alpn"], pbk, sid, spx
)
} else if (str.startsWith(EConfigType.WIREGUARD.protocolScheme)) {
val uri = URI(Utils.fixIllegalUrl(str))
config = ServerConfig.create(EConfigType.WIREGUARD)
config.remarks = Utils.urlDecode(uri.fragment ?: "")

if (uri.rawQuery != null) {
val queryParam = uri.rawQuery.split("&")
.associate { it.split("=").let { (k, v) -> k to Utils.urlDecode(v) } }

config.outboundBean?.settings?.let { wireguard ->
wireguard.secretKey = uri.userInfo
wireguard.address =
(queryParam["address"] ?: WIREGUARD_LOCAL_ADDRESS_V4).replace(" ", "")
.split(",")
wireguard.peers?.get(0)?.publicKey = queryParam["publickey"] ?: ""
wireguard.peers?.get(0)?.endpoint = "${uri.idnHost}:${uri.port}"
wireguard.mtu = Utils.parseInt(queryParam["mtu"] ?: WIREGUARD_LOCAL_MTU)
wireguard.reserved =
(queryParam["reserved"] ?: "0,0,0").replace(" ", "").split(",")
.map { it.toInt() }
}
}
}
if (config == null) {
return R.string.toast_incorrect_protocol
Expand All @@ -443,7 +467,8 @@ object AngConfigManager {
?.getServerAddress() == removedSelectedServer.getProxyOutbound()
?.getServerAddress() &&
config.getProxyOutbound()
?.getServerPort() == removedSelectedServer.getProxyOutbound()?.getServerPort()
?.getServerPort() == removedSelectedServer.getProxyOutbound()
?.getServerPort()
) {
mainStorage?.encode(KEY_SELECTED_SERVER, guid)
}
Expand Down Expand Up @@ -680,7 +705,8 @@ object AngConfigManager {
dicQuery["spx"] = Utils.urlEncode(tlsSetting.spiderX!!)
}
}
dicQuery["type"] = streamSetting.network.ifEmpty { V2rayConfig.DEFAULT_NETWORK }
dicQuery["type"] =
streamSetting.network.ifEmpty { V2rayConfig.DEFAULT_NETWORK }

outbound.getTransportSettingDetails()?.let { transportDetails ->
when (streamSetting.network) {
Expand Down
2 changes: 1 addition & 1 deletion V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ object Utils {

fun urlDecode(url: String): String {
return try {
URLDecoder.decode(URLDecoder.decode(url), "utf-8")
URLDecoder.decode(url, "UTF-8")
} catch (e: Exception) {
e.printStackTrace()
url
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ object V2rayConfigUtil {
} else {
raw
}
Log.d(ANG_PACKAGE, customConfig)
//Log.d(ANG_PACKAGE, customConfig)
return Result(true, customConfig)
}
val outbound = config.getProxyOutbound() ?: return Result(false, "")
val result = getV2rayNonCustomConfig(context, outbound)
Log.d(ANG_PACKAGE, result.content)
//Log.d(ANG_PACKAGE, result.content)
return result
} catch (e: Exception) {
e.printStackTrace()
Expand Down
10 changes: 5 additions & 5 deletions V2rayNG/app/src/main/res/layout/activity_server_wireguard.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,10 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/server_lab_public_key" />

android:text="@string/server_lab_secret_key" />

<EditText
android:id="@+id/et_public_key"
android:id="@+id/et_id"
android:layout_width="match_parent"
android:layout_height="@dimen/edit_height"
android:inputType="text" />
Expand All @@ -108,10 +107,11 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/server_lab_secret_key" />
android:text="@string/server_lab_public_key" />


<EditText
android:id="@+id/et_id"
android:id="@+id/et_public_key"
android:layout_width="match_parent"
android:layout_height="@dimen/edit_height"
android:inputType="text" />
Expand Down

0 comments on commit ea383c4

Please sign in to comment.