aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/src/main/java/org/pacien/tincapp/service/ConfigurationAccessService.kt25
1 files changed, 21 insertions, 4 deletions
diff --git a/app/src/main/java/org/pacien/tincapp/service/ConfigurationAccessService.kt b/app/src/main/java/org/pacien/tincapp/service/ConfigurationAccessService.kt
index b083a83..32f74fc 100644
--- a/app/src/main/java/org/pacien/tincapp/service/ConfigurationAccessService.kt
+++ b/app/src/main/java/org/pacien/tincapp/service/ConfigurationAccessService.kt
@@ -25,6 +25,8 @@ import android.os.IBinder
25import androidx.databinding.ObservableBoolean 25import androidx.databinding.ObservableBoolean
26import ch.qos.logback.classic.Level 26import ch.qos.logback.classic.Level
27import ch.qos.logback.classic.Logger 27import ch.qos.logback.classic.Logger
28import org.apache.ftpserver.ConnectionConfigFactory
29import org.apache.ftpserver.DataConnectionConfigurationFactory
28import org.apache.ftpserver.FtpServer 30import org.apache.ftpserver.FtpServer
29import org.apache.ftpserver.FtpServerFactory 31import org.apache.ftpserver.FtpServerFactory
30import org.apache.ftpserver.ftplet.* 32import org.apache.ftpserver.ftplet.*
@@ -53,6 +55,7 @@ class ConfigurationAccessService : Service() {
53 private val MINA_FTP_LOGGER_OVERRIDER = MinaLoggerOverrider(Level.WARN) 55 private val MINA_FTP_LOGGER_OVERRIDER = MinaLoggerOverrider(Level.WARN)
54 56
55 const val FTP_PORT = 65521 // tinc port `concat` FTP port 57 const val FTP_PORT = 65521 // tinc port `concat` FTP port
58 val FTP_DATA_PORT_RANGE = FTP_PORT + 1..FTP_PORT + 11
56 const val FTP_USERNAME = "tincapp" 59 const val FTP_USERNAME = "tincapp"
57 val FTP_HOME_DIR = App.getContext().applicationInfo.dataDir!! 60 val FTP_HOME_DIR = App.getContext().applicationInfo.dataDir!!
58 val FTP_PASSWORD = generateRandomString(8) 61 val FTP_PASSWORD = generateRandomString(8)
@@ -115,12 +118,26 @@ class ConfigurationAccessService : Service() {
115 ) 118 )
116 } 119 }
117 120
118 private fun setupSingleUserServer(ftpUser: User): FtpServer { 121 private fun setupSingleUserServer(ftpUser: User): FtpServer =
119 return FtpServerFactory() 122 FtpServerFactory()
120 .apply { addListener("default", ListenerFactory().apply { port = FTP_PORT }.createListener()) } 123 .apply {
124 addListener("default", ListenerFactory()
125 .apply {
126 connectionConfig = ConnectionConfigFactory()
127 .apply { maxThreads = 1 } // library has issues with multiple threads
128 .createConnectionConfig()
129 }
130 .apply { port = FTP_PORT }
131 .apply {
132 dataConnectionConfiguration = DataConnectionConfigurationFactory()
133 .apply { passivePorts = "${FTP_DATA_PORT_RANGE.first}-${FTP_DATA_PORT_RANGE.last}" }
134 .createDataConnectionConfiguration()
135 }
136 .createListener()
137 )
138 }
121 .apply { userManager = StaticFtpUserManager(listOf(ftpUser)) } 139 .apply { userManager = StaticFtpUserManager(listOf(ftpUser)) }
122 .createServer() 140 .createServer()
123 }
124 141
125 private class StaticFtpUserManager(users: List<User>) : UserManager { 142 private class StaticFtpUserManager(users: List<User>) : UserManager {
126 private val userMap: Map<String, User> = users.map { it.name to it }.toMap() 143 private val userMap: Map<String, User> = users.map { it.name to it }.toMap()