aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/src/main/java/org/pacien/tincapp/service/ConfigurationFtpService.kt22
1 files changed, 22 insertions, 0 deletions
diff --git a/app/src/main/java/org/pacien/tincapp/service/ConfigurationFtpService.kt b/app/src/main/java/org/pacien/tincapp/service/ConfigurationFtpService.kt
index c562768..2ea4a16 100644
--- a/app/src/main/java/org/pacien/tincapp/service/ConfigurationFtpService.kt
+++ b/app/src/main/java/org/pacien/tincapp/service/ConfigurationFtpService.kt
@@ -22,6 +22,8 @@ import android.app.Service
22import android.content.Intent 22import android.content.Intent
23import android.os.IBinder 23import android.os.IBinder
24import androidx.databinding.ObservableBoolean 24import androidx.databinding.ObservableBoolean
25import ch.qos.logback.classic.Level
26import ch.qos.logback.classic.Logger
25import org.apache.ftpserver.FtpServer 27import org.apache.ftpserver.FtpServer
26import org.apache.ftpserver.FtpServerFactory 28import org.apache.ftpserver.FtpServerFactory
27import org.apache.ftpserver.ftplet.* 29import org.apache.ftpserver.ftplet.*
@@ -42,6 +44,11 @@ import java.io.IOException
42 */ 44 */
43class ConfigurationFtpService : Service() { 45class ConfigurationFtpService : Service() {
44 companion object { 46 companion object {
47 // Apache Mina FtpServer's INFO log level is actually VERBOSE.
48 // The object holds static references to those loggers so that they stay around.
49 @Suppress("unused")
50 private val MINA_FTP_LOGGER_OVERRIDER = MinaLoggerOverrider(Level.WARN)
51
45 const val FTP_PORT = 65521 // tinc port `concat` FTP port 52 const val FTP_PORT = 65521 // tinc port `concat` FTP port
46 const val FTP_USERNAME = "tincapp" 53 const val FTP_USERNAME = "tincapp"
47 val FTP_HOME_DIR = App.getContext().applicationInfo.dataDir!! 54 val FTP_HOME_DIR = App.getContext().applicationInfo.dataDir!!
@@ -125,4 +132,19 @@ class ConfigurationFtpService : Service() {
125 override fun authorize(request: AuthorizationRequest?): AuthorizationRequest? = 132 override fun authorize(request: AuthorizationRequest?): AuthorizationRequest? =
126 authorities.filter { it.canAuthorize(request) }.fold(request) { req, auth -> auth.authorize(req) } 133 authorities.filter { it.canAuthorize(request) }.fold(request) { req, auth -> auth.authorize(req) }
127 } 134 }
135
136 /**
137 * This registers package loggers filtering the output of the Mina FtpServer.
138 * The object holds static references to those loggers so that they stay around.
139 */
140 private class MinaLoggerOverrider(logLevel: Level) {
141 @Suppress("unused")
142 private val ftpServerLogger = forceLogLevel("org.apache.ftpserver", logLevel)
143
144 @Suppress("unused")
145 private val minaLogger = forceLogLevel("org.apache.mina", logLevel)
146
147 private fun forceLogLevel(pkgName: String, logLevel: Level) =
148 (LoggerFactory.getLogger(pkgName) as Logger).apply { level = logLevel }
149 }
128} 150}