aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorpacien2023-07-29 23:03:12 +0200
committerpacien2023-07-30 03:53:20 +0200
commitdfb26a0d2c95d56f69f5e1e0c255d9d5d6788120 (patch)
tree5db0f2b80090592c0a8cb30851369f088e65feb7 /app/src/main/java
parent218709850d9db0ad1cddadc115546c446e9461cd (diff)
downloadtincapp-dfb26a0d2c95d56f69f5e1e0c255d9d5d6788120.tar.gz
storage: remove embedded FTP server
Moving back the configuration files and logs to the user-accessible storage. Everything should be accessible through a file manager using the "USB storage" mode. The embedded FTP server is no longer necessary.
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/org/pacien/tincapp/activities/configure/ConfigurationAccessServerFragment.kt77
-rw-r--r--app/src/main/java/org/pacien/tincapp/context/AppNotificationManager.kt13
-rw-r--r--app/src/main/java/org/pacien/tincapp/service/ConfigurationAccessService.kt204
3 files changed, 0 insertions, 294 deletions
diff --git a/app/src/main/java/org/pacien/tincapp/activities/configure/ConfigurationAccessServerFragment.kt b/app/src/main/java/org/pacien/tincapp/activities/configure/ConfigurationAccessServerFragment.kt
deleted file mode 100644
index c90299a..0000000
--- a/app/src/main/java/org/pacien/tincapp/activities/configure/ConfigurationAccessServerFragment.kt
+++ /dev/null
@@ -1,77 +0,0 @@
1/*
2 * Tinc App, an Android binding and user interface for the tinc mesh VPN daemon
3 * Copyright (C) 2017-2020 Pacien TRAN-GIRARD
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
19package org.pacien.tincapp.activities.configure
20
21import android.content.Intent
22import android.os.Bundle
23import android.view.LayoutInflater
24import android.view.View
25import android.view.ViewGroup
26import androidx.databinding.Observable
27import androidx.databinding.ObservableBoolean
28import org.pacien.tincapp.activities.BaseFragment
29import org.pacien.tincapp.databinding.ConfigureToolsConfigurationAccessFragmentBinding
30import org.pacien.tincapp.service.ConfigurationAccessService
31
32/**
33 * @author pacien
34 */
35class ConfigurationAccessServerFragment : BaseFragment() {
36 private val ftpServerStartListener = object : Observable.OnPropertyChangedCallback() {
37 override fun onPropertyChanged(sender: Observable, propertyId: Int) {
38 binding.ftpEnabled = (sender as ObservableBoolean).get()
39 }
40 }
41
42 private lateinit var binding: ConfigureToolsConfigurationAccessFragmentBinding
43
44 override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
45 binding = ConfigureToolsConfigurationAccessFragmentBinding.inflate(inflater, container, false)
46 binding.toggleFtpState = { toggleServer() }
47 setConnectionInfo()
48 return binding.root
49 }
50
51 override fun onResume() {
52 super.onResume()
53 setConnectionInfo()
54 ConfigurationAccessService.runningState.addOnPropertyChangedCallback(ftpServerStartListener)
55 binding.ftpEnabled = ConfigurationAccessService.runningState.get()
56 }
57
58 override fun onPause() {
59 ConfigurationAccessService.runningState.removeOnPropertyChangedCallback(ftpServerStartListener)
60 super.onPause()
61 }
62
63 private fun setConnectionInfo() {
64 binding.ftpUsername = ConfigurationAccessService.getFtpUsername()
65 binding.ftpPassword = ConfigurationAccessService.getFtpPassword()
66 binding.ftpPort = ConfigurationAccessService.getFtpPort()
67 }
68
69 private fun toggleServer() {
70 val targetServiceIntent = Intent(requireContext(), ConfigurationAccessService::class.java)
71
72 if (binding.ftpEnabled)
73 requireContext().stopService(targetServiceIntent)
74 else
75 requireContext().startService(targetServiceIntent)
76 }
77}
diff --git a/app/src/main/java/org/pacien/tincapp/context/AppNotificationManager.kt b/app/src/main/java/org/pacien/tincapp/context/AppNotificationManager.kt
index 5b01a54..d6e21f5 100644
--- a/app/src/main/java/org/pacien/tincapp/context/AppNotificationManager.kt
+++ b/app/src/main/java/org/pacien/tincapp/context/AppNotificationManager.kt
@@ -36,10 +36,7 @@ import org.pacien.tincapp.utils.PendingIntentUtils
36class AppNotificationManager(private val context: Context) { 36class AppNotificationManager(private val context: Context) {
37 companion object { 37 companion object {
38 private const val ERROR_CHANNEL_ID = "org.pacien.tincapp.notification.channels.error" 38 private const val ERROR_CHANNEL_ID = "org.pacien.tincapp.notification.channels.error"
39 private const val CONFIG_ACCESS_CHANNEL_ID = "org.pacien.tincapp.notification.channels.configuration"
40
41 const val ERROR_NOTIFICATION_ID = 0 39 const val ERROR_NOTIFICATION_ID = 0
42 const val CONFIG_ACCESS_NOTIFICATION_ID = 1
43 } 40 }
44 41
45 init { 42 init {
@@ -65,9 +62,6 @@ class AppNotificationManager(private val context: Context) {
65 NotificationManagerCompat.from(context).cancelAll() 62 NotificationManagerCompat.from(context).cancelAll()
66 } 63 }
67 64
68 fun newConfigurationAccessNotificationBuilder() =
69 NotificationCompat.Builder(context, CONFIG_ACCESS_CHANNEL_ID)
70
71 @RequiresApi(Build.VERSION_CODES.O) 65 @RequiresApi(Build.VERSION_CODES.O)
72 private fun registerChannels() { 66 private fun registerChannels() {
73 context.getSystemService(NotificationManager::class.java) 67 context.getSystemService(NotificationManager::class.java)
@@ -78,13 +72,6 @@ class AppNotificationManager(private val context: Context) {
78 NotificationManager.IMPORTANCE_HIGH 72 NotificationManager.IMPORTANCE_HIGH
79 )) 73 ))
80 } 74 }
81 .apply {
82 createNotificationChannel(NotificationChannel(
83 CONFIG_ACCESS_CHANNEL_ID,
84 context.getString(R.string.notification_config_access_channel_name),
85 NotificationManager.IMPORTANCE_MIN
86 ))
87 }
88 } 75 }
89 76
90 private fun NotificationCompat.Builder.setHighPriority() = apply { 77 private fun NotificationCompat.Builder.setHighPriority() = apply {
diff --git a/app/src/main/java/org/pacien/tincapp/service/ConfigurationAccessService.kt b/app/src/main/java/org/pacien/tincapp/service/ConfigurationAccessService.kt
deleted file mode 100644
index 916f19d..0000000
--- a/app/src/main/java/org/pacien/tincapp/service/ConfigurationAccessService.kt
+++ /dev/null
@@ -1,204 +0,0 @@
1/*
2 * Tinc App, an Android binding and user interface for the tinc mesh VPN daemon
3 * Copyright (C) 2017-2023 Pacien TRAN-GIRARD
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
19package org.pacien.tincapp.service
20
21import android.app.Service
22import android.content.Context
23import android.content.Intent
24import android.os.IBinder
25import androidx.databinding.ObservableBoolean
26import ch.qos.logback.classic.Level
27import ch.qos.logback.classic.Logger
28import org.apache.ftpserver.ConnectionConfigFactory
29import org.apache.ftpserver.DataConnectionConfigurationFactory
30import org.apache.ftpserver.FtpServer
31import org.apache.ftpserver.FtpServerFactory
32import org.apache.ftpserver.ftplet.*
33import org.apache.ftpserver.listener.ListenerFactory
34import org.apache.ftpserver.usermanager.UsernamePasswordAuthentication
35import org.apache.ftpserver.usermanager.impl.WritePermission
36import org.pacien.tincapp.R
37import org.pacien.tincapp.activities.configure.ConfigureActivity
38import org.pacien.tincapp.context.App
39import org.pacien.tincapp.context.AppNotificationManager
40import org.pacien.tincapp.extensions.Java.defaultMessage
41import org.pacien.tincapp.utils.PendingIntentUtils
42import org.slf4j.LoggerFactory
43import java.io.IOException
44
45/**
46 * FTP server service allowing a remote and local user to access and modify configuration files in
47 * the application's context.
48 *
49 * @author pacien
50 */
51class ConfigurationAccessService : Service() {
52 companion object {
53 // Apache Mina FtpServer's INFO log level is actually VERBOSE.
54 // The object holds static references to those loggers so that they stay around.
55 @Suppress("unused")
56 private val MINA_FTP_LOGGER_OVERRIDER = MinaLoggerOverrider(Level.WARN)
57
58 private val context by lazy { App.getContext() }
59 private val store by lazy { context.getSharedPreferences("${this::class.java.`package`!!.name}.ftp", Context.MODE_PRIVATE)!! }
60 val runningState = ObservableBoolean(false)
61
62 fun getF