From 532d5b9b9affc3816f655ac94659fcb99d6aab3e Mon Sep 17 00:00:00 2001 From: Aria Moradi Date: Mon, 19 Feb 2024 02:17:29 +0330 Subject: [PATCH 1/5] Add auth support to socsk proxy --- .../graphql/mutations/SettingsMutation.kt | 2 ++ .../tachidesk/graphql/types/SettingsType.kt | 8 ++++++++ .../suwayomi/tachidesk/server/ServerConfig.kt | 2 ++ .../suwayomi/tachidesk/server/ServerSetup.kt | 17 ++++++++++++++--- server/src/main/resources/server-reference.conf | 2 ++ server/src/test/resources/server-reference.conf | 2 ++ 6 files changed, 30 insertions(+), 3 deletions(-) diff --git a/server/src/main/kotlin/suwayomi/tachidesk/graphql/mutations/SettingsMutation.kt b/server/src/main/kotlin/suwayomi/tachidesk/graphql/mutations/SettingsMutation.kt index 2da0455a0..e6c0de505 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/graphql/mutations/SettingsMutation.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/graphql/mutations/SettingsMutation.kt @@ -39,6 +39,8 @@ class SettingsMutation { updateSetting(settings.socksProxyEnabled, serverConfig.socksProxyEnabled) updateSetting(settings.socksProxyHost, serverConfig.socksProxyHost) updateSetting(settings.socksProxyPort, serverConfig.socksProxyPort) + updateSetting(settings.socksProxyUsername, serverConfig.socksProxyUsername) + updateSetting(settings.socksProxyPassword, serverConfig.socksProxyPassword) // webUI updateSetting(settings.webUIFlavor?.uiName, serverConfig.webUIFlavor) diff --git a/server/src/main/kotlin/suwayomi/tachidesk/graphql/types/SettingsType.kt b/server/src/main/kotlin/suwayomi/tachidesk/graphql/types/SettingsType.kt index 0c4f45efb..4b3b15386 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/graphql/types/SettingsType.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/graphql/types/SettingsType.kt @@ -23,6 +23,8 @@ interface Settings : Node { val socksProxyEnabled: Boolean? val socksProxyHost: String? val socksProxyPort: String? + val socksProxyUsername: String? + val socksProxyPassword: String? // webUI // requires restart (found no way to mutate (serve + "unserve") served files during runtime), exclude for now @@ -94,6 +96,8 @@ data class PartialSettingsType( override val socksProxyEnabled: Boolean?, override val socksProxyHost: String?, override val socksProxyPort: String?, + override val socksProxyUsername: String?, + override val socksProxyPassword: String?, // webUI override val webUIFlavor: WebUIFlavor?, override val initialOpenInBrowserEnabled: Boolean?, @@ -152,6 +156,8 @@ class SettingsType( override val socksProxyEnabled: Boolean, override val socksProxyHost: String, override val socksProxyPort: String, + override val socksProxyUsername: String, + override val socksProxyPassword: String, // webUI override val webUIFlavor: WebUIFlavor, override val initialOpenInBrowserEnabled: Boolean, @@ -209,6 +215,8 @@ class SettingsType( config.socksProxyEnabled.value, config.socksProxyHost.value, config.socksProxyPort.value, + config.socksProxyUsername.value, + config.socksProxyPassword.value, // webUI WebUIFlavor.from(config.webUIFlavor.value), config.initialOpenInBrowserEnabled.value, diff --git a/server/src/main/kotlin/suwayomi/tachidesk/server/ServerConfig.kt b/server/src/main/kotlin/suwayomi/tachidesk/server/ServerConfig.kt index 8e811314d..7e1edc678 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/server/ServerConfig.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/server/ServerConfig.kt @@ -82,6 +82,8 @@ class ServerConfig(getConfig: () -> Config, val moduleName: String = SERVER_CONF val socksProxyEnabled: MutableStateFlow by OverrideConfigValue(BooleanConfigAdapter) val socksProxyHost: MutableStateFlow by OverrideConfigValue(StringConfigAdapter) val socksProxyPort: MutableStateFlow by OverrideConfigValue(StringConfigAdapter) + val socksProxyUsername: MutableStateFlow by OverrideConfigValue(StringConfigAdapter) + val socksProxyPassword: MutableStateFlow by OverrideConfigValue(StringConfigAdapter) // webUI val webUIEnabled: MutableStateFlow by OverrideConfigValue(BooleanConfigAdapter) diff --git a/server/src/main/kotlin/suwayomi/tachidesk/server/ServerSetup.kt b/server/src/main/kotlin/suwayomi/tachidesk/server/ServerSetup.kt index f1b9cbc65..5c986cb15 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/server/ServerSetup.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/server/ServerSetup.kt @@ -236,14 +236,25 @@ fun applicationSetup() { serverConfig.socksProxyEnabled, serverConfig.socksProxyHost, serverConfig.socksProxyPort, - ) { proxyEnabled, proxyHost, proxyPort -> - Triple(proxyEnabled, proxyHost, proxyPort) + serverConfig.socksProxyUsername, + serverConfig.socksProxyPassword, + ) { proxyEnabled, proxyHost, proxyPort, proxyUsername, proxyPassword -> + data class DataClassForDestruction( + val proxyEnabled: Boolean, + val proxyHost: String, + val proxyPort: String, + val proxyUsername: String, + val proxyPassword: String, + ) + DataClassForDestruction(proxyEnabled, proxyHost, proxyPort, proxyUsername, proxyPassword) }, - { (proxyEnabled, proxyHost, proxyPort) -> + { (proxyEnabled, proxyHost, proxyPort, proxyUsername, proxyPassword) -> logger.info("Socks Proxy changed - enabled= $proxyEnabled, proxy= $proxyHost:$proxyPort") if (proxyEnabled) { System.getProperties()["socksProxyHost"] = proxyHost System.getProperties()["socksProxyPort"] = proxyPort + System.getProperties()["java.net.socks.username"] = proxyUsername + System.getProperties()["java.net.socks.password"] = proxyPassword } else { System.getProperties()["socksProxyHost"] = "" System.getProperties()["socksProxyPort"] = "" diff --git a/server/src/main/resources/server-reference.conf b/server/src/main/resources/server-reference.conf index 9ff691b76..fa9218bee 100644 --- a/server/src/main/resources/server-reference.conf +++ b/server/src/main/resources/server-reference.conf @@ -6,6 +6,8 @@ server.port = 4567 server.socksProxyEnabled = false server.socksProxyHost = "" server.socksProxyPort = "" +server.socksProxyUsername = "" +server.socksProxyPassword = "" # webUI server.webUIEnabled = true diff --git a/server/src/test/resources/server-reference.conf b/server/src/test/resources/server-reference.conf index 99566947e..2cc7351c4 100644 --- a/server/src/test/resources/server-reference.conf +++ b/server/src/test/resources/server-reference.conf @@ -6,6 +6,8 @@ server.port = 4567 server.socksProxyEnabled = false server.socksProxyHost = "" server.socksProxyPort = "" +server.socksProxyUsername = "" +server.socksProxyPassword = "" # downloader server.downloadAsCbz = false From 7b013bb391b27c427deef675b758203eac8836fb Mon Sep 17 00:00:00 2001 From: Aria Moradi Date: Mon, 19 Feb 2024 02:21:32 +0330 Subject: [PATCH 2/5] better logging --- server/src/main/kotlin/suwayomi/tachidesk/server/ServerSetup.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/main/kotlin/suwayomi/tachidesk/server/ServerSetup.kt b/server/src/main/kotlin/suwayomi/tachidesk/server/ServerSetup.kt index 5c986cb15..2f306cd06 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/server/ServerSetup.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/server/ServerSetup.kt @@ -249,7 +249,7 @@ fun applicationSetup() { DataClassForDestruction(proxyEnabled, proxyHost, proxyPort, proxyUsername, proxyPassword) }, { (proxyEnabled, proxyHost, proxyPort, proxyUsername, proxyPassword) -> - logger.info("Socks Proxy changed - enabled= $proxyEnabled, proxy= $proxyHost:$proxyPort") + logger.info("Socks Proxy changed - enabled=$proxyEnabled address=$proxyHost:$proxyPort , username=$proxyUsername, password=[REDACTED]") if (proxyEnabled) { System.getProperties()["socksProxyHost"] = proxyHost System.getProperties()["socksProxyPort"] = proxyPort From 0194a6d52e397c8bf771ad2557389e2bf6087616 Mon Sep 17 00:00:00 2001 From: Aria Moradi Date: Mon, 19 Feb 2024 02:28:59 +0330 Subject: [PATCH 3/5] fix lint issue --- .../src/main/kotlin/suwayomi/tachidesk/server/ServerSetup.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server/src/main/kotlin/suwayomi/tachidesk/server/ServerSetup.kt b/server/src/main/kotlin/suwayomi/tachidesk/server/ServerSetup.kt index 2f306cd06..4dc34d14b 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/server/ServerSetup.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/server/ServerSetup.kt @@ -249,7 +249,9 @@ fun applicationSetup() { DataClassForDestruction(proxyEnabled, proxyHost, proxyPort, proxyUsername, proxyPassword) }, { (proxyEnabled, proxyHost, proxyPort, proxyUsername, proxyPassword) -> - logger.info("Socks Proxy changed - enabled=$proxyEnabled address=$proxyHost:$proxyPort , username=$proxyUsername, password=[REDACTED]") + logger.info( + "Socks Proxy changed - enabled=$proxyEnabled address=$proxyHost:$proxyPort , username=$proxyUsername, password=[REDACTED]", + ) if (proxyEnabled) { System.getProperties()["socksProxyHost"] = proxyHost System.getProperties()["socksProxyPort"] = proxyPort From d9ead789a25420efb1246b94d3cdc528decb23b2 Mon Sep 17 00:00:00 2001 From: Aria Moradi Date: Mon, 19 Feb 2024 14:23:41 +0330 Subject: [PATCH 4/5] implement fixes and version --- .../graphql/mutations/SettingsMutation.kt | 1 + .../tachidesk/graphql/types/SettingsType.kt | 4 ++ .../suwayomi/tachidesk/server/ServerConfig.kt | 1 + .../suwayomi/tachidesk/server/ServerSetup.kt | 43 ++++++++++++++----- .../src/main/resources/server-reference.conf | 1 + 5 files changed, 39 insertions(+), 11 deletions(-) diff --git a/server/src/main/kotlin/suwayomi/tachidesk/graphql/mutations/SettingsMutation.kt b/server/src/main/kotlin/suwayomi/tachidesk/graphql/mutations/SettingsMutation.kt index e6c0de505..c88b1e85e 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/graphql/mutations/SettingsMutation.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/graphql/mutations/SettingsMutation.kt @@ -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) diff --git a/server/src/main/kotlin/suwayomi/tachidesk/graphql/types/SettingsType.kt b/server/src/main/kotlin/suwayomi/tachidesk/graphql/types/SettingsType.kt index 4b3b15386..5a28e5135 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/graphql/types/SettingsType.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/graphql/types/SettingsType.kt @@ -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, diff --git a/server/src/main/kotlin/suwayomi/tachidesk/server/ServerConfig.kt b/server/src/main/kotlin/suwayomi/tachidesk/server/ServerConfig.kt index 7e1edc678..afab08317 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/server/ServerConfig.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/server/ServerConfig.kt @@ -80,6 +80,7 @@ class ServerConfig(getConfig: () -> Config, val moduleName: String = SERVER_CONF // proxy val socksProxyEnabled: MutableStateFlow by OverrideConfigValue(BooleanConfigAdapter) + val socksProxyVersion: MutableStateFlow by OverrideConfigValue(IntConfigAdapter) val socksProxyHost: MutableStateFlow by OverrideConfigValue(StringConfigAdapter) val socksProxyPort: MutableStateFlow by OverrideConfigValue(StringConfigAdapter) val socksProxyUsername: MutableStateFlow by OverrideConfigValue(StringConfigAdapter) diff --git a/server/src/main/kotlin/suwayomi/tachidesk/server/ServerSetup.kt b/server/src/main/kotlin/suwayomi/tachidesk/server/ServerSetup.kt index 4dc34d14b..1661fc5c8 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/server/ServerSetup.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/server/ServerSetup.kt @@ -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, diff --git a/server/src/main/resources/server-reference.conf b/server/src/main/resources/server-reference.conf index fa9218bee..5b4bd174c 100644 --- a/server/src/main/resources/server-reference.conf +++ b/server/src/main/resources/server-reference.conf @@ -4,6 +4,7 @@ server.port = 4567 # Socks5 proxy server.socksProxyEnabled = false +server.socksProxyVersion = 5 # 4 or 5 server.socksProxyHost = "" server.socksProxyPort = "" server.socksProxyUsername = "" From 47d5a34012fb022fbbbbf8020a1b56bda67f5fec Mon Sep 17 00:00:00 2001 From: Aria Moradi Date: Mon, 19 Feb 2024 14:26:04 +0330 Subject: [PATCH 5/5] add to test reference too --- server/src/test/resources/server-reference.conf | 1 + 1 file changed, 1 insertion(+) diff --git a/server/src/test/resources/server-reference.conf b/server/src/test/resources/server-reference.conf index 2cc7351c4..7670bb577 100644 --- a/server/src/test/resources/server-reference.conf +++ b/server/src/test/resources/server-reference.conf @@ -4,6 +4,7 @@ server.port = 4567 # Socks5 proxy server.socksProxyEnabled = false +server.socksProxyVersion = 5 # 4 or 5 server.socksProxyHost = "" server.socksProxyPort = "" server.socksProxyUsername = ""