Add auth support to socsk proxy

This commit is contained in:
Aria Moradi
2024-02-19 02:17:29 +03:30
parent af0dde5ae8
commit 532d5b9b9a
6 changed files with 30 additions and 3 deletions

View File

@@ -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)

View File

@@ -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,

View File

@@ -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)

View File

@@ -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"] = ""

View File

@@ -6,6 +6,8 @@ server.port = 4567
server.socksProxyEnabled = false
server.socksProxyHost = ""
server.socksProxyPort = ""
server.socksProxyUsername = ""
server.socksProxyPassword = ""
# webUI
server.webUIEnabled = true

View File

@@ -6,6 +6,8 @@ server.port = 4567
server.socksProxyEnabled = false
server.socksProxyHost = ""
server.socksProxyPort = ""
server.socksProxyUsername = ""
server.socksProxyPassword = ""
# downloader
server.downloadAsCbz = false