Skip to content
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

Add auth and version support to socks proxy #883

Merged
merged 5 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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?,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ class ServerConfig(getConfig: () -> Config, val moduleName: String = SERVER_CONF
val socksProxyEnabled: MutableStateFlow<Boolean> by OverrideConfigValue(BooleanConfigAdapter)
val socksProxyHost: MutableStateFlow<String> by OverrideConfigValue(StringConfigAdapter)
val socksProxyPort: MutableStateFlow<String> by OverrideConfigValue(StringConfigAdapter)
val socksProxyUsername: MutableStateFlow<String> by OverrideConfigValue(StringConfigAdapter)
val socksProxyPassword: MutableStateFlow<String> by OverrideConfigValue(StringConfigAdapter)

// webUI
val webUIEnabled: MutableStateFlow<Boolean> by OverrideConfigValue(BooleanConfigAdapter)
Expand Down
19 changes: 15 additions & 4 deletions server/src/main/kotlin/suwayomi/tachidesk/server/ServerSetup.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
AriaMoradi marked this conversation as resolved.
Show resolved Hide resolved
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)
},
serverConfig.socksProxyUsername,
serverConfig.socksProxyPassword,
) { proxyEnabled, proxyHost, proxyPort, proxyUsername, proxyPassword ->
data class ProxySettings(
val proxyEnabled: Boolean,
val proxyHost: String,
val proxyPort: String,
val proxyUsername: String,
val proxyPassword: String,
)
ProxySettings(proxyEnabled, proxyHost, proxyPort, proxyUsername, proxyPassword)
}.distinctUntilChanged(),

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API says it doesn't need distinctUntilChanged()
image

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its just to be safe.

{ (proxyEnabled, proxyHost, proxyPort) ->
logger.info("Socks Proxy changed - enabled= $proxyEnabled, proxy= $proxyHost:$proxyPort")
{ (proxyEnabled, 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
} else {
System.getProperties()["socksProxyHost"] = ""
System.getProperties()["socksProxyPort"] = ""
AriaMoradi marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
2 changes: 2 additions & 0 deletions server/src/main/resources/server-reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ server.port = 4567
server.socksProxyEnabled = false
server.socksProxyHost = ""
server.socksProxyPort = ""
server.socksProxyUsername = ""
server.socksProxyPassword = ""

# webUI
server.webUIEnabled = true
Expand Down
2 changes: 2 additions & 0 deletions server/src/test/resources/server-reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ server.port = 4567
server.socksProxyEnabled = false
server.socksProxyHost = ""
server.socksProxyPort = ""
server.socksProxyUsername = ""
server.socksProxyPassword = ""

# downloader
server.downloadAsCbz = false
Expand Down
Loading