implement fixes and version

This commit is contained in:
Aria Moradi
2024-02-19 14:23:41 +03:30
parent 0194a6d52e
commit d9ead789a2
5 changed files with 39 additions and 11 deletions

View File

@@ -37,6 +37,7 @@ class SettingsMutation {
// proxy
updateSetting(settings.socksProxyEnabled, serverConfig.socksProxyEnabled)
updateSetting(settings.socksProxyVersion, serverConfig.socksProxyVersion)
updateSetting(settings.socksProxyHost, serverConfig.socksProxyHost)
updateSetting(settings.socksProxyPort, serverConfig.socksProxyPort)
updateSetting(settings.socksProxyUsername, serverConfig.socksProxyUsername)

View File

@@ -21,6 +21,7 @@ interface Settings : Node {
// proxy
val socksProxyEnabled: Boolean?
val socksProxyVersion: Int?
val socksProxyHost: String?
val socksProxyPort: String?
val socksProxyUsername: String?
@@ -94,6 +95,7 @@ data class PartialSettingsType(
override val port: Int?,
// proxy
override val socksProxyEnabled: Boolean?,
override val socksProxyVersion: Int?,
override val socksProxyHost: String?,
override val socksProxyPort: String?,
override val socksProxyUsername: String?,
@@ -154,6 +156,7 @@ class SettingsType(
override val port: Int,
// proxy
override val socksProxyEnabled: Boolean,
override val socksProxyVersion: Int,
override val socksProxyHost: String,
override val socksProxyPort: String,
override val socksProxyUsername: String,
@@ -213,6 +216,7 @@ class SettingsType(
config.port.value,
// proxy
config.socksProxyEnabled.value,
config.socksProxyVersion.value,
config.socksProxyHost.value,
config.socksProxyPort.value,
config.socksProxyUsername.value,

View File

@@ -80,6 +80,7 @@ class ServerConfig(getConfig: () -> Config, val moduleName: String = SERVER_CONF
// proxy
val socksProxyEnabled: MutableStateFlow<Boolean> by OverrideConfigValue(BooleanConfigAdapter)
val socksProxyVersion: MutableStateFlow<Int> by OverrideConfigValue(IntConfigAdapter)
val socksProxyHost: MutableStateFlow<String> by OverrideConfigValue(StringConfigAdapter)
val socksProxyPort: MutableStateFlow<String> by OverrideConfigValue(StringConfigAdapter)
val socksProxyUsername: MutableStateFlow<String> by OverrideConfigValue(StringConfigAdapter)

View File

@@ -17,6 +17,7 @@ import io.javalin.plugin.json.JavalinJackson
import io.javalin.plugin.json.JsonMapper
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.serialization.json.Json
import mu.KotlinLogging
import org.bouncycastle.jce.provider.BouncyCastleProvider
@@ -234,32 +235,52 @@ fun applicationSetup() {
serverConfig.subscribeTo(
combine(
serverConfig.socksProxyEnabled,
serverConfig.socksProxyVersion,
serverConfig.socksProxyHost,
serverConfig.socksProxyPort,
serverConfig.socksProxyUsername,
serverConfig.socksProxyPassword,
) { proxyEnabled, proxyHost, proxyPort, proxyUsername, proxyPassword ->
data class DataClassForDestruction(
) { vargs ->
data class ProxySettings(
val proxyEnabled: Boolean,
val socksProxyVersion: Int,
val proxyHost: String,
val proxyPort: String,
val proxyUsername: String,
val proxyPassword: String,
)
DataClassForDestruction(proxyEnabled, proxyHost, proxyPort, proxyUsername, proxyPassword)
},
{ (proxyEnabled, proxyHost, proxyPort, proxyUsername, proxyPassword) ->
ProxySettings(
vargs[0] as Boolean,
vargs[1] as Int,
vargs[2] as String,
vargs[3] as String,
vargs[4] as String,
vargs[5] as String,
)
}.distinctUntilChanged(),
{ (proxyEnabled, proxyVersion, proxyHost, proxyPort, proxyUsername, proxyPassword) ->
logger.info(
"Socks Proxy changed - enabled=$proxyEnabled address=$proxyHost:$proxyPort , username=$proxyUsername, password=[REDACTED]",
)
if (proxyEnabled) {
System.getProperties()["socksProxyHost"] = proxyHost
System.getProperties()["socksProxyPort"] = proxyPort
System.getProperties()["java.net.socks.username"] = proxyUsername
System.getProperties()["java.net.socks.password"] = proxyPassword
System.setProperty("socksProxyHost", proxyHost)
System.setProperty("socksProxyPort", proxyPort)
System.setProperty("socksProxyVersion", proxyVersion.toString())
if (proxyUsername.isNotBlank()) {
System.setProperty("java.net.socks.username", proxyUsername)
} else {
System.clearProperty("java.net.socks.username")
}
if (proxyPassword.isNotBlank()) {
System.setProperty("java.net.socks.password", proxyPassword)
} else {
System.clearProperty("java.net.socks.password")
}
} else {
System.getProperties()["socksProxyHost"] = ""
System.getProperties()["socksProxyPort"] = ""
System.clearProperty("socksProxyHost")
System.clearProperty("socksProxyPort")
System.clearProperty("socksProxyVersion")
}
},
ignoreInitialValue = false,

View File

@@ -4,6 +4,7 @@ server.port = 4567
# Socks5 proxy
server.socksProxyEnabled = false
server.socksProxyVersion = 5 # 4 or 5
server.socksProxyHost = ""
server.socksProxyPort = ""
server.socksProxyUsername = ""