-
Notifications
You must be signed in to change notification settings - Fork 5.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Please add regular WireGuard configuration parsing. #3497
Comments
Waiting for someone to pr |
@2dust I have done this before, should I do it and submit a pr? |
Please add the same thing to v2rayN too |
Thank you for your work.
|
Hi guys Im little busy now, but I'm giving code for parsing the wireguard config, Just use it and it will work fine. This is the data class for wireguard config data class WireGuardConfig(
val interface: WireGuardInterface,
val peer: WireGuardPeer
)
data class WireGuardInterface(
val privateKey: String,
val address: String
)
data class WireGuardPeer(
val publicKey: String,
val presharedKey: String,
val allowedIPs: List<String>,
val persistentKeepalive: Int,
val endpoint: String
) This is the function which will take string config and returns data class fun parseWireGuardConfig(config: String): WireGuardConfig {
val lines = config.split("\n").map { it.trim() }.filter { it.isNotEmpty() }
var interfaceSection = true
val interfaceMap = mutableMapOf<String, String>()
val peerMap = mutableMapOf<String, String>()
for (line in lines) {
when {
line.startsWith("[Interface]") -> {
interfaceSection = true
}
line.startsWith("[Peer]") -> {
interfaceSection = false
}
interfaceSection -> {
val (key, value) = line.split("=", limit = 2).map { it.trim() }
interfaceMap[key] = value
}
else -> {
val (key, value) = line.split("=", limit = 2).map { it.trim() }
peerMap[key] = value
}
}
}
val `interface` = WireGuardInterface(
privateKey = interfaceMap["PrivateKey"] ?: "",
address = interfaceMap["Address"] ?: ""
)
val peer = WireGuardPeer(
publicKey = peerMap["PublicKey"] ?: "",
presharedKey = peerMap["PresharedKey"] ?: "",
allowedIPs = peerMap["AllowedIPs"]?.split(",")?.map { it.trim() } ?: emptyList(),
persistentKeepalive = peerMap["PersistentKeepalive"]?.toIntOrNull() ?: 0,
endpoint = peerMap["Endpoint"] ?: ""
)
return WireGuardConfig(`interface`, peer)
} |
you should add default remark with unix time or endpoint to prevent empty config names. |
yeah I saw it shows blank name |
now, if you go to edit mode, you have to set a remark to submit that. |
ok fix in new pr |
data class WireGuardConfig( data class WireGuardInterface( data class WireGuardPeer( |
still when i import a wireguard config which was created using wireguard core, the wireguard config does not work #3252 |
Please add regular WireGuard configuration parsing.
Example:
The text was updated successfully, but these errors were encountered: