diff options
Diffstat (limited to 'app/src/main/java/org')
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 | |||
19 | package org.pacien.tincapp.activities.configure | ||
20 | |||
21 | import android.content.Intent | ||
22 | import android.os.Bundle | ||
23 | import android.view.LayoutInflater | ||
24 | import android.view.View | ||
25 | import android.view.ViewGroup | ||
26 | import androidx.databinding.Observable | ||
27 | import androidx.databinding.ObservableBoolean | ||
28 | import org.pacien.tincapp.activities.BaseFragment | ||
29 | import org.pacien.tincapp.databinding.ConfigureToolsConfigurationAccessFragmentBinding | ||
30 | import org.pacien.tincapp.service.ConfigurationAccessService | ||
31 | |||
32 | /** | ||
33 | * @author pacien | ||
34 | */ | ||
35 | class 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 | |||
36 | class AppNotificationManager(private val context: Context) { | 36 | class 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 | |||
19 | package org.pacien.tincapp.service | ||
20 | |||
21 | import android.app.Service | ||
22 | import android.content.Context | ||
23 | import android.content.Intent | ||
24 | import android.os.IBinder | ||
25 | import androidx.databinding.ObservableBoolean | ||
26 | import ch.qos.logback.classic.Level | ||
27 | import ch.qos.logback.classic.Logger | ||
28 | import org.apache.ftpserver.ConnectionConfigFactory | ||
29 | import org.apache.ftpserver.DataConnectionConfigurationFactory | ||
30 | import org.apache.ftpserver.FtpServer | ||
31 | import org.apache.ftpserver.FtpServerFactory | ||
32 | import org.apache.ftpserver.ftplet.* | ||
33 | import org.apache.ftpserver.listener.ListenerFactory | ||
34 | import org.apache.ftpserver.usermanager.UsernamePasswordAuthentication | ||
35 | import org.apache.ftpserver.usermanager.impl.WritePermission | ||
36 | import org.pacien.tincapp.R | ||
37 | import org.pacien.tincapp.activities.configure.ConfigureActivity | ||
38 | import org.pacien.tincapp.context.App | ||
39 | import org.pacien.tincapp.context.AppNotificationManager | ||
40 | import org.pacien.tincapp.extensions.Java.defaultMessage | ||
41 | import org.pacien.tincapp.utils.PendingIntentUtils | ||
42 | import org.slf4j.LoggerFactory | ||
43 | import 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 | */ | ||
51 | class 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 getFtpHomeDir(): String = context.applicationInfo.dataDir!! | ||
63 | fun getFtpUsername() = storeGetOrInsertString("username") { "tincapp" } | ||
64 | fun getFtpPassword() = storeGetOrInsertString("password") { generateRandomString(8) } |