diff options
Diffstat (limited to 'app/src/main/java/org/pacien')
13 files changed, 397 insertions, 160 deletions
diff --git a/app/src/main/java/org/pacien/tincapp/activities/BaseActivity.kt b/app/src/main/java/org/pacien/tincapp/activities/BaseActivity.kt index 4dc2381..af71544 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/BaseActivity.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/BaseActivity.kt | |||
@@ -19,19 +19,18 @@ | |||
19 | package org.pacien.tincapp.activities | 19 | package org.pacien.tincapp.activities |
20 | 20 | ||
21 | import android.os.Bundle | 21 | import android.os.Bundle |
22 | import android.support.annotation.LayoutRes | ||
22 | import android.support.annotation.StringRes | 23 | import android.support.annotation.StringRes |
23 | import android.support.design.widget.Snackbar | 24 | import android.support.design.widget.Snackbar |
24 | import android.support.v7.app.AlertDialog | 25 | import android.support.v7.app.AlertDialog |
25 | import android.support.v7.app.AppCompatActivity | 26 | import android.support.v7.app.AppCompatActivity |
26 | import android.view.Menu | 27 | import android.view.* |
27 | import android.view.MenuItem | ||
28 | import kotlinx.android.synthetic.main.base.* | 28 | import kotlinx.android.synthetic.main.base.* |
29 | import org.pacien.tincapp.R | 29 | import org.pacien.tincapp.R |
30 | import org.pacien.tincapp.context.App | 30 | import org.pacien.tincapp.context.App |
31 | import org.pacien.tincapp.context.AppInfo | 31 | import org.pacien.tincapp.context.AppInfo |
32 | import org.pacien.tincapp.context.AppPaths | 32 | import org.pacien.tincapp.context.AppPaths |
33 | import org.pacien.tincapp.context.CrashRecorder | 33 | import org.pacien.tincapp.context.CrashRecorder |
34 | import org.pacien.tincapp.utils.ProgressModal | ||
35 | 34 | ||
36 | /** | 35 | /** |
37 | * @author pacien | 36 | * @author pacien |
@@ -105,10 +104,13 @@ abstract class BaseActivity : AppCompatActivity() { | |||
105 | .show() | 104 | .show() |
106 | } | 105 | } |
107 | 106 | ||
108 | protected fun notify(@StringRes msg: Int) = Snackbar.make(activity_base, msg, Snackbar.LENGTH_LONG).show() | 107 | fun inflate(@LayoutRes layout: Int) = layoutInflater.inflate(layout, main_content, false)!! |
109 | protected fun notify(msg: String) = Snackbar.make(activity_base, msg, Snackbar.LENGTH_LONG).show() | 108 | fun inflate(inflateFunc: (LayoutInflater, ViewGroup, Boolean) -> View) = inflateFunc(layoutInflater, main_content, false) |
110 | protected fun showProgressDialog(@StringRes msg: Int): AlertDialog = ProgressModal.show(this, getString(msg)) | 109 | |
111 | protected fun showErrorDialog(msg: String): AlertDialog = AlertDialog.Builder(this) | 110 | fun notify(@StringRes msg: Int) = Snackbar.make(activity_base, msg, Snackbar.LENGTH_LONG).show() |
111 | fun notify(msg: String) = Snackbar.make(activity_base, msg, Snackbar.LENGTH_LONG).show() | ||
112 | |||
113 | fun showErrorDialog(msg: String): AlertDialog = AlertDialog.Builder(this) | ||
112 | .setTitle(R.string.title_error).setMessage(msg) | 114 | .setTitle(R.string.title_error).setMessage(msg) |
113 | .setPositiveButton(R.string.action_close) { _, _ -> Unit }.show() | 115 | .setPositiveButton(R.string.action_close) { _, _ -> Unit }.show() |
114 | } | 116 | } |
diff --git a/app/src/main/java/org/pacien/tincapp/activities/ConfigureActivity.kt b/app/src/main/java/org/pacien/tincapp/activities/ConfigureActivity.kt deleted file mode 100644 index 2aab304..0000000 --- a/app/src/main/java/org/pacien/tincapp/activities/ConfigureActivity.kt +++ /dev/null | |||
@@ -1,145 +0,0 @@ | |||
1 | /* | ||
2 | * Tinc App, an Android binding and user interface for the tinc mesh VPN daemon | ||
3 | * Copyright (C) 2017-2018 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 | ||
20 | |||
21 | import android.content.Intent | ||
22 | import android.os.Bundle | ||
23 | import android.support.annotation.StringRes | ||
24 | import android.support.v7.app.AlertDialog | ||
25 | import android.view.View | ||
26 | import com.google.zxing.integration.android.IntentIntegrator | ||
27 | import com.google.zxing.integration.android.IntentResult | ||
28 | import java8.util.concurrent.CompletableFuture | ||
29 | import kotlinx.android.synthetic.main.base.* | ||
30 | import kotlinx.android.synthetic.main.dialog_encrypt_decrypt_keys.view.* | ||
31 | import kotlinx.android.synthetic.main.dialog_network_generate.view.* | ||
32 | import kotlinx.android.synthetic.main.dialog_network_join.view.* | ||
33 | import kotlinx.android.synthetic.main.page_configure.* | ||
34 | import org.pacien.tincapp.R | ||
35 | import org.pacien.tincapp.commands.Tinc | ||
36 | import org.pacien.tincapp.commands.TincApp | ||
37 | import org.pacien.tincapp.context.AppPaths | ||
38 | import org.pacien.tincapp.extensions.Java.exceptionallyAccept | ||
39 | import java.util.regex.Pattern | ||
40 | |||
41 | /** | ||
42 | * @author pacien | ||
43 | */ | ||
44 | class ConfigureActivity : BaseActivity() { | ||
45 | companion object { | ||
46 | private val NETWORK_NAME_PATTERN = Pattern.compile("^[^\\x00/]*$") | ||
47 | } | ||
48 | |||
49 | private var joinDialog: View? = null | ||
50 | |||
51 | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { | ||
52 | super.onActivityResult(requestCode, resultCode, data) | ||
53 | |||
54 | IntentIntegrator.parseActivityResult(requestCode, resultCode, data) | ||
55 | ?.let(IntentResult::getContents) | ||
56 | ?.let(String::trim) | ||
57 | ?.let { joinDialog?.invitation_url?.setText(it) } | ||
58 | } | ||
59 | |||
60 | override fun onCreate(savedInstanceState: Bundle?) { | ||
61 | super.onCreate(savedInstanceState) | ||
62 | supportActionBar!!.setDisplayHomeAsUpEnabled(true) | ||
63 | layoutInflater.inflate(R.layout.page_configure, main_content) | ||
64 | writeContent() | ||
65 | } | ||
66 | |||
67 | fun scanCode(@Suppress("UNUSED_PARAMETER") v: View) { | ||
68 | IntentIntegrator(this).initiateScan() | ||
69 | } | ||
70 | |||
71 | fun openGenerateConfDialog(@Suppress("UNUSED_PARAMETER") v: View) { | ||
72 | val genDialog = layoutInflater.inflate(R.layout.dialog_network_generate, main_content, false) | ||
73 | AlertDialog.Builder(this).setTitle(R.string.title_new_network).setView(genDialog) | ||
74 | .setPositiveButton(R.string.action_create) { _, _ -> | ||
75 | generateConf( | ||
76 | genDialog.new_net_name.text.toString(), | ||
77 | genDialog.new_node_name.text.toString(), | ||
78 | genDialog.new_passphrase.text.toString()) | ||
79 | }.setNegativeButton(R.string.action_cancel) { _, _ -> Unit }.show() | ||
80 | } | ||
81 | |||
82 | fun openJoinNetworkDialog(@Suppress("UNUSED_PARAMETER") v: View) { | ||
83 | joinDialog = layoutInflater.inflate(R.layout.dialog_network_join, main_content, false) | ||
84 | AlertDialog.Builder(this).setTitle(R.string.title_join_network).setView(joinDialog) | ||
85 | .setPositiveButton(R.string.action_join) { _, _ -> | ||
86 | joinNetwork( | ||
87 | joinDialog!!.net_name.text.toString(), | ||
88 | joinDialog!!.invitation_url.text.toString(), | ||
89 | joinDialog!!.join_passphrase.text.toString()) | ||
90 | }.setNegativeButton(R.string.action_cancel) { _, _ -> Unit }.show() | ||
91 | } | ||
92 | |||
93 | fun openEncryptDecryptPrivateKeyDialog(@Suppress("UNUSED_PARAMETER") v: View) { | ||
94 | val encryptDecryptDialog = layoutInflater.inflate(R.layout.dialog_encrypt_decrypt_keys, main_content, false) | ||
95 | AlertDialog.Builder(this).setTitle(R.string.title_private_keys_encryption).setView(encryptDecryptDialog) | ||
96 | .setPositiveButton(R.string.action_apply) { _, _ -> | ||
97 | encryptDecryptPrivateKeys( | ||
98 | encryptDecryptDialog!!.enc_dec_net_name.text.toString(), | ||
99 | encryptDecryptDialog.enc_dec_current_passphrase.text.toString(), | ||
100 | encryptDecryptDialog.enc_dec_new_passphrase.text.toString()) | ||
101 | }.setNegativeButton(R.string.action_cancel) { _, _ -> Unit }.show() | ||
102 | } | ||
103 | |||
104 | private fun writeContent() { | ||
105 | text_configuration_directory.text = AppPaths.confDir().absolutePath | ||
106 | text_log_directory.text = AppPaths.cacheDir().absolutePath | ||
107 | text_tinc_binary.text = AppPaths.tinc().absolutePath | ||
108 | } | ||
109 | |||
110 | private fun generateConf(netName: String, nodeName: String, passphrase: String? = null) = execAction( | ||
111 | R.string.message_generating_configuration, | ||
112 | validateNetName(netName) | ||
113 | .thenCompose { Tinc.init(netName, nodeName) } | ||
114 | .thenCompose { TincApp.removeScripts(netName) } | ||
115 | .thenCompose { TincApp.generateIfaceCfgTemplate(netName) } | ||
116 | .thenCompose { TincApp.setPassphrase(netName, newPassphrase = passphrase) }) | ||
117 | |||
118 | private fun joinNetwork(netName: String, url: String, passphrase: String? = null) = execAction( | ||
119 | R.string.message_joining_network, | ||
120 | validateNetName(netName) | ||
121 | .thenCompose { Tinc.join(netName, url) } | ||
122 | .thenCompose { TincApp.removeScripts(netName) } | ||
123 | .thenCompose { TincApp.generateIfaceCfg(netName) } | ||
124 | .thenCompose { TincApp.setPassphrase(netName, newPassphrase = passphrase) }) | ||