mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-06-23 02:00:20 +07:00
Merge branch 'dev' into android_pt_transport_source
This commit is contained in:
+17
-7
@@ -588,13 +588,23 @@ elseif(APPLE AND NOT IOS)
|
||||
endif()
|
||||
|
||||
if(NOT IOS)
|
||||
add_custom_command(
|
||||
TARGET ${PROJECT} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E $<IF:$<CONFIG:Debug>,copy_directory,true>
|
||||
${CMAKE_SOURCE_DIR}/deploy/data/${DEPLOY_ARTIFACT_PATH}
|
||||
$<TARGET_FILE_DIR:${PROJECT}>
|
||||
COMMAND_EXPAND_LISTS
|
||||
)
|
||||
add_custom_command(
|
||||
TARGET ${PROJECT} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E $<IF:$<CONFIG:Debug>,copy_directory,true>
|
||||
${CMAKE_SOURCE_DIR}/deploy/data/${DEPLOY_ARTIFACT_PATH}
|
||||
$<TARGET_FILE_DIR:${PROJECT}>
|
||||
COMMAND_EXPAND_LISTS
|
||||
)
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
add_custom_command(
|
||||
TARGET ${PROJECT} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E $<IF:$<CONFIG:Debug>,copy,true>
|
||||
$<TARGET_FILE_DIR:${PROJECT}>/../service/wireguard-service/wireguard-service.exe
|
||||
$<TARGET_FILE_DIR:${PROJECT}>/wireguard/wireguard-service.exe
|
||||
COMMAND_EXPAND_LISTS
|
||||
)
|
||||
endif()
|
||||
if(IOS)
|
||||
#include(cmake/ios-arch-fixup.cmake)
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
android:extractNativeLibs="true"
|
||||
android:requestLegacyExternalStorage="true"
|
||||
android:allowNativeHeapPointerTagging="false"
|
||||
android:theme="@style/Theme.AppCompat.NoActionBar"
|
||||
android:icon="@drawable/icon">
|
||||
|
||||
<activity
|
||||
@@ -113,6 +114,10 @@
|
||||
android:value="-- %%INSERT_APP_ARGUMENTS%% --" />
|
||||
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".qt.CameraActivity"
|
||||
android:exported="false" />
|
||||
|
||||
<service
|
||||
android:name=".VPNService"
|
||||
|
||||
@@ -2,7 +2,7 @@ apply plugin: 'com.github.ben-manes.versions'
|
||||
|
||||
buildscript {
|
||||
ext{
|
||||
kotlin_version = "1.4.30-M1"
|
||||
kotlin_version = "1.7.22"
|
||||
// for libwg
|
||||
appcompatVersion = '1.1.0'
|
||||
annotationsVersion = '1.0.1'
|
||||
@@ -29,12 +29,6 @@ buildscript {
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'kotlin-android-extensions'
|
||||
@@ -44,14 +38,32 @@ apply plugin: 'kotlin-kapt'
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
|
||||
implementation group: 'org.json', name: 'json', version: '20220924'
|
||||
implementation 'androidx.core:core-ktx:1.1.0'
|
||||
implementation 'androidx.core:core-ktx:1.7.0'
|
||||
implementation 'androidx.appcompat:appcompat:1.4.1'
|
||||
|
||||
implementation "androidx.security:security-crypto:1.1.0-alpha03"
|
||||
implementation "androidx.security:security-identity-credential:1.0.0-alpha02"
|
||||
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.2.2"
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.0"
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.0"
|
||||
|
||||
coreLibraryDesugaring "com.android.tools:desugar_jdk_libs:1.1.5"
|
||||
|
||||
implementation project(path: ':shadowsocks')
|
||||
|
||||
// CameraX core library using the camera2 implementation
|
||||
def camerax_version = "1.2.1"
|
||||
implementation("androidx.camera:camera-core:${camerax_version}")
|
||||
implementation("androidx.camera:camera-camera2:${camerax_version}")
|
||||
implementation("androidx.camera:camera-lifecycle:${camerax_version}")
|
||||
implementation("androidx.camera:camera-view:${camerax_version}")
|
||||
implementation("androidx.camera:camera-extensions:${camerax_version}")
|
||||
|
||||
def camerax_ml_version = "1.2.0-beta02"
|
||||
def ml_kit_version = "17.0.3"
|
||||
implementation("androidx.camera:camera-mlkit-vision:${camerax_ml_version}")
|
||||
implementation("com.google.mlkit:barcode-scanning:${ml_kit_version}")
|
||||
}
|
||||
|
||||
androidExtensions {
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".CameraActivity">
|
||||
|
||||
<androidx.camera.view.PreviewView
|
||||
android:id="@+id/viewFinder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -1 +1,19 @@
|
||||
pluginManagement {
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
jcenter()
|
||||
gradlePluginPortal()
|
||||
}
|
||||
}
|
||||
|
||||
dependencyResolutionManagement {
|
||||
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
jcenter()
|
||||
}
|
||||
}
|
||||
|
||||
include ':shadowsocks'
|
||||
|
||||
@@ -1,21 +1,9 @@
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
apply plugin: 'com.android.library'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'kotlin-android-extensions'
|
||||
apply plugin: 'kotlin-kapt'
|
||||
//apply plugin: 'com.novoda.bintray-release'
|
||||
|
||||
|
||||
|
||||
android {
|
||||
compileSdkVersion 30
|
||||
defaultConfig {
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
package org.amnezia.vpn.qt
|
||||
|
||||
import android.Manifest
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.camera.core.*
|
||||
import androidx.camera.lifecycle.ProcessCameraProvider
|
||||
import androidx.camera.view.PreviewView
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.google.mlkit.vision.barcode.BarcodeScannerOptions
|
||||
import com.google.mlkit.vision.barcode.BarcodeScanning
|
||||
import com.google.mlkit.vision.barcode.common.Barcode
|
||||
import com.google.mlkit.vision.common.InputImage
|
||||
import java.util.concurrent.ExecutorService
|
||||
import java.util.concurrent.Executors
|
||||
import org.amnezia.vpn.R
|
||||
|
||||
|
||||
class CameraActivity : AppCompatActivity() {
|
||||
|
||||
private val CAMERA_REQUEST = 100
|
||||
|
||||
private lateinit var cameraExecutor: ExecutorService
|
||||
private lateinit var analyzerExecutor: ExecutorService
|
||||
|
||||
private lateinit var viewFinder: PreviewView
|
||||
|
||||
companion object {
|
||||
private lateinit var instance: CameraActivity
|
||||
|
||||
@JvmStatic fun getInstance(): CameraActivity {
|
||||
return instance
|
||||
}
|
||||
|
||||
@JvmStatic fun stopQrCodeReader() {
|
||||
CameraActivity.getInstance().finish()
|
||||
}
|
||||
}
|
||||
|
||||
external fun passDataToDecoder(data: String)
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_camera)
|
||||
|
||||
viewFinder = findViewById(R.id.viewFinder)
|
||||
|
||||
cameraExecutor = Executors.newSingleThreadExecutor()
|
||||
analyzerExecutor = Executors.newSingleThreadExecutor()
|
||||
|
||||
instance = this
|
||||
|
||||
checkPermissions()
|
||||
|
||||
configureVideoPreview()
|
||||
}
|
||||
|
||||
private fun checkPermissions() {
|
||||
if (checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
|
||||
requestPermissions(arrayOf(Manifest.permission.CAMERA), CAMERA_REQUEST)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
|
||||
if (requestCode == CAMERA_REQUEST) {
|
||||
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
Toast.makeText(this, "CameraX permission granted", Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
Toast.makeText(this, "CameraX permission denied", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("UnsafeOptInUsageError")
|
||||
private fun configureVideoPreview() {
|
||||
val cameraProviderFuture = ProcessCameraProvider.getInstance(this)
|
||||
val imageCapture = ImageCapture.Builder().build()
|
||||
|
||||
cameraProviderFuture.addListener({
|
||||
val cameraProvider: ProcessCameraProvider = cameraProviderFuture.get()
|
||||
|
||||
val preview = Preview.Builder().build()
|
||||
|
||||
val cameraSelector = CameraSelector.DEFAULT_BACK_CAMERA
|
||||
|
||||
val imageAnalyzer = BarCodeAnalyzer()
|
||||
|
||||
val analysisUseCase = ImageAnalysis.Builder()
|
||||
.setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
|
||||
.build()
|
||||
|
||||
analysisUseCase.setAnalyzer(analyzerExecutor, imageAnalyzer)
|
||||
|
||||
try {
|
||||
preview.setSurfaceProvider(viewFinder.surfaceProvider)
|
||||
cameraProvider.unbindAll()
|
||||
cameraProvider.bindToLifecycle(this, cameraSelector, preview, imageCapture, analysisUseCase)
|
||||
} catch(exc: Exception) {
|
||||
Log.e("WUTT", "Use case binding failed", exc)
|
||||
}
|
||||
}, ContextCompat.getMainExecutor(this))
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
cameraExecutor.shutdown()
|
||||
analyzerExecutor.shutdown()
|
||||
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
val barcodesSet = mutableSetOf<String>()
|
||||
|
||||
private inner class BarCodeAnalyzer(): ImageAnalysis.Analyzer {
|
||||
|
||||
private val options = BarcodeScannerOptions.Builder()
|
||||
.setBarcodeFormats(Barcode.FORMAT_QR_CODE)
|
||||
.build()
|
||||
|
||||
private val scanner = BarcodeScanning.getClient(options)
|
||||
|
||||
@SuppressLint("UnsafeOptInUsageError")
|
||||
override fun analyze(imageProxy: ImageProxy) {
|
||||
val mediaImage = imageProxy.image
|
||||
|
||||
if (mediaImage != null) {
|
||||
val image = InputImage.fromMediaImage(mediaImage, imageProxy.imageInfo.rotationDegrees)
|
||||
|
||||
scanner.process(image)
|
||||
.addOnSuccessListener { barcodes ->
|
||||
if (barcodes.isNotEmpty()) {
|
||||
val barcode = barcodes[0]
|
||||
if (barcode != null) {
|
||||
val str = barcode?.displayValue ?: ""
|
||||
if (str.isNotEmpty()) {
|
||||
val isAdded = barcodesSet.add(str)
|
||||
if (isAdded) {
|
||||
passDataToDecoder(str)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
imageProxy.close()
|
||||
}
|
||||
.addOnFailureListener {
|
||||
imageProxy.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,6 +36,8 @@ class VPNActivity : org.qtproject.qt.android.bindings.QtActivity() {
|
||||
private val TAG = "VPNActivity"
|
||||
private val STORAGE_PERMISSION_CODE = 42
|
||||
|
||||
private val CAMERA_ACTION_CODE = 101
|
||||
|
||||
companion object {
|
||||
private lateinit var instance: VPNActivity
|
||||
|
||||
@@ -47,6 +49,10 @@ class VPNActivity : org.qtproject.qt.android.bindings.QtActivity() {
|
||||
VPNActivity.getInstance().initServiceConnection()
|
||||
}
|
||||
|
||||
@JvmStatic fun startQrCodeReader() {
|
||||
VPNActivity.getInstance().startQrCodeActivity()
|
||||
}
|
||||
|
||||
@JvmStatic fun sendToService(actionCode: Int, body: String) {
|
||||
VPNActivity.getInstance().dispatchParcel(actionCode, body)
|
||||
}
|
||||
@@ -62,7 +68,12 @@ class VPNActivity : org.qtproject.qt.android.bindings.QtActivity() {
|
||||
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
instance = this;
|
||||
instance = this
|
||||
}
|
||||
|
||||
private fun startQrCodeActivity() {
|
||||
val intent = Intent(this, CameraActivity::class.java)
|
||||
startActivityForResult(intent, CAMERA_ACTION_CODE)
|
||||
}
|
||||
|
||||
override fun getSystemService(name: String): Any? {
|
||||
@@ -82,6 +93,7 @@ class VPNActivity : org.qtproject.qt.android.bindings.QtActivity() {
|
||||
external fun onServiceMessage(actionCode: Int, body: String?)
|
||||
external fun qtOnServiceConnected()
|
||||
external fun qtOnServiceDisconnected()
|
||||
external fun onActivityMessage(actionCode: Int, body: String?)
|
||||
|
||||
private fun dispatchParcel(actionCode: Int, body: String) {
|
||||
if (!isBound) {
|
||||
@@ -286,6 +298,7 @@ class VPNActivity : org.qtproject.qt.android.bindings.QtActivity() {
|
||||
private val EVENT_PERMISSION_REQURED = 6
|
||||
private val EVENT_DISCONNECTED = 2
|
||||
|
||||
private val UI_EVENT_QR_CODE_RECEIVED = 0
|
||||
|
||||
fun onPermissionRequest(code: Int, data: Parcel?) {
|
||||
if (code != EVENT_PERMISSION_REQURED) {
|
||||
@@ -310,7 +323,13 @@ class VPNActivity : org.qtproject.qt.android.bindings.QtActivity() {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
|
||||
if (requestCode == CAMERA_ACTION_CODE && resultCode == RESULT_OK) {
|
||||
val extra = data?.getStringExtra("result") ?: ""
|
||||
onActivityMessage(UI_EVENT_QR_CODE_RECEIVED, extra)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
|
||||
|
||||
@@ -27,6 +27,16 @@ QString ContainerProps::containerToString(amnezia::DockerContainer c){
|
||||
return "amnezia-" + containerKey.toLower();
|
||||
}
|
||||
|
||||
QString ContainerProps::containerTypeToString(amnezia::DockerContainer c){
|
||||
if (c == DockerContainer::None) return "none";
|
||||
if (c == DockerContainer::Ipsec) return "ikev2";
|
||||
|
||||
QMetaEnum metaEnum = QMetaEnum::fromType<DockerContainer>();
|
||||
QString containerKey = metaEnum.valueToKey(static_cast<int>(c));
|
||||
|
||||
return containerKey.toLower();
|
||||
}
|
||||
|
||||
QVector<amnezia::Proto> ContainerProps::protocolsForContainer(amnezia::DockerContainer container)
|
||||
{
|
||||
switch (container) {
|
||||
@@ -172,3 +182,10 @@ return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
QStringList ContainerProps::fixedPortsForContainer(DockerContainer c)
|
||||
{
|
||||
switch (c) {
|
||||
case DockerContainer::Ipsec : return QStringList{"500", "4500"};
|
||||
default: return {};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,24 +37,26 @@ class ContainerProps : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Q_INVOKABLE static DockerContainer containerFromString(const QString &container);
|
||||
Q_INVOKABLE static QString containerToString(DockerContainer container);
|
||||
Q_INVOKABLE static amnezia::DockerContainer containerFromString(const QString &container);
|
||||
Q_INVOKABLE static QString containerToString(amnezia::DockerContainer container);
|
||||
Q_INVOKABLE static QString containerTypeToString(amnezia::DockerContainer c);
|
||||
|
||||
Q_INVOKABLE static QList<DockerContainer> allContainers();
|
||||
Q_INVOKABLE static QList<amnezia::DockerContainer> allContainers();
|
||||
|
||||
Q_INVOKABLE static QMap<DockerContainer, QString> containerHumanNames();
|
||||
Q_INVOKABLE static QMap<DockerContainer, QString> containerDescriptions();
|
||||
Q_INVOKABLE static QMap<amnezia::DockerContainer, QString> containerHumanNames();
|
||||
Q_INVOKABLE static QMap<amnezia::DockerContainer, QString> containerDescriptions();
|
||||
|
||||
// these protocols will be displayed in container settings
|
||||
Q_INVOKABLE static QVector<Proto> protocolsForContainer(DockerContainer container);
|
||||
Q_INVOKABLE static QVector<amnezia::Proto> protocolsForContainer(amnezia::DockerContainer container);
|
||||
|
||||
Q_INVOKABLE static ServiceType containerService(DockerContainer c);
|
||||
Q_INVOKABLE static amnezia::ServiceType containerService(amnezia::DockerContainer c);
|
||||
|
||||
// binding between Docker container and main protocol of given container
|
||||
// it may be changed fot future containers :)
|
||||
Q_INVOKABLE static Proto defaultProtocol(DockerContainer c);
|
||||
Q_INVOKABLE static amnezia::Proto defaultProtocol(amnezia::DockerContainer c);
|
||||
|
||||
Q_INVOKABLE static bool isSupportedByCurrentPlatform(DockerContainer c);
|
||||
Q_INVOKABLE static bool isSupportedByCurrentPlatform(amnezia::DockerContainer c);
|
||||
Q_INVOKABLE static QStringList fixedPortsForContainer(amnezia::DockerContainer c);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -409,12 +409,18 @@ ErrorCode ServerController::removeContainer(const ServerCredentials &credentials
|
||||
genVarsForScript(credentials, container)));
|
||||
}
|
||||
|
||||
ErrorCode ServerController::setupContainer(const ServerCredentials &credentials, DockerContainer container, QJsonObject &config)
|
||||
ErrorCode ServerController::setupContainer(const ServerCredentials &credentials, DockerContainer container,
|
||||
QJsonObject &config, bool isUpdate)
|
||||
{
|
||||
qDebug().noquote() << "ServerController::setupContainer" << ContainerProps::containerToString(container);
|
||||
//qDebug().noquote() << QJsonDocument(config).toJson();
|
||||
ErrorCode e = ErrorCode::NoError;
|
||||
|
||||
if (!isUpdate) {
|
||||
e = isServerPortBusy(credentials, container, config);
|
||||
if (e) return e;
|
||||
}
|
||||
|
||||
e = installDockerWorker(credentials, container);
|
||||
if (e) return e;
|
||||
qDebug().noquote() << "ServerController::setupContainer installDockerWorker finished";
|
||||
@@ -451,7 +457,7 @@ ErrorCode ServerController::updateContainer(const ServerCredentials &credentials
|
||||
qDebug() << "ServerController::updateContainer for container" << container << "reinstall required is" << reinstallRequred;
|
||||
|
||||
if (reinstallRequred) {
|
||||
return setupContainer(credentials, container, newConfig);
|
||||
return setupContainer(credentials, container, newConfig, true);
|
||||
}
|
||||
else {
|
||||
ErrorCode e = configureContainerWorker(credentials, container, newConfig);
|
||||
@@ -856,3 +862,79 @@ QString ServerController::replaceVars(const QString &script, const Vars &vars)
|
||||
//qDebug().noquote() << script;
|
||||
return s;
|
||||
}
|
||||
|
||||
ErrorCode ServerController::isServerPortBusy(const ServerCredentials &credentials, DockerContainer container, const QJsonObject &config)
|
||||
{
|
||||
QString stdOut;
|
||||
auto cbReadStdOut = [&](const QString &data, QSharedPointer<QSsh::SshRemoteProcess> proc) {
|
||||
stdOut += data + "\n";
|
||||
};
|
||||
auto cbReadStdErr = [&](const QString &data, QSharedPointer<QSsh::SshRemoteProcess> ) {
|
||||
stdOut += data + "\n";
|
||||
};
|
||||
|
||||
const QString containerString = ProtocolProps::protoToString(ContainerProps::defaultProtocol(container));
|
||||
const QJsonObject containerConfig = config.value(containerString).toObject();
|
||||
|
||||
QStringList fixedPorts = ContainerProps::fixedPortsForContainer(container);
|
||||
|
||||
QString port = containerConfig.value(config_key::port).toString();
|
||||
QString transportProto = containerConfig.value(config_key::transport_proto).toString();
|
||||
|
||||
QString script = QString("sudo lsof -i -P -n | grep -E ':%1").arg(port);
|
||||
for (auto &port : fixedPorts) {
|
||||
script = script.append("|:%1").arg(port);
|
||||
}
|
||||
script = script.append("' | grep -i %1").arg(transportProto);
|
||||
runScript(credentials,
|
||||
replaceVars(script, genVarsForScript(credentials, container)), cbReadStdOut, cbReadStdErr);
|
||||
|
||||
if (!stdOut.isEmpty()) {
|
||||
return ErrorCode::ServerPortAlreadyAllocatedError;
|
||||
}
|
||||
return ErrorCode::NoError;
|
||||
}
|
||||
|
||||
ErrorCode ServerController::getAlreadyInstalledContainers(const ServerCredentials &credentials, QMap<DockerContainer, QJsonObject> &installedContainers)
|
||||
{
|
||||
QString stdOut;
|
||||
auto cbReadStdOut = [&](const QString &data, QSharedPointer<QSsh::SshRemoteProcess> proc) {
|
||||
stdOut += data + "\n";
|
||||
};
|
||||
auto cbReadStdErr = [&](const QString &data, QSharedPointer<QSsh::SshRemoteProcess> ) {
|
||||
stdOut += data + "\n";
|
||||
};
|
||||
|
||||
QString script = QString("sudo docker ps --format '{{.Names}} {{.Ports}}'");
|
||||
|
||||
ErrorCode errorCode = runScript(credentials, script, cbReadStdOut, cbReadStdErr);
|
||||
if (errorCode != ErrorCode::NoError) {
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
auto containersInfo = stdOut.split("\n");
|
||||
for (auto &containerInfo : containersInfo) {
|
||||
if (containerInfo.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
const static QRegularExpression containerAndPortRegExp("(amnezia[-a-z]*).*?>([0-9]*)/(udp|tcp).*");
|
||||
QRegularExpressionMatch containerAndPortMatch = containerAndPortRegExp.match(containerInfo);
|
||||
if (containerAndPortMatch.hasMatch()) {
|
||||
QString name = containerAndPortMatch.captured(1);
|
||||
QString port = containerAndPortMatch.captured(2);
|
||||
QString transportProto = containerAndPortMatch.captured(3);
|
||||
DockerContainer container = ContainerProps::containerFromString(name);
|
||||
Proto mainProto = ContainerProps::defaultProtocol(container);
|
||||
QJsonObject config {
|
||||
{ config_key::container, name },
|
||||
{ ProtocolProps::protoToString(mainProto), QJsonObject {
|
||||
{ config_key::port, port },
|
||||
{ config_key::transport_proto, transportProto }}
|
||||
}
|
||||
};
|
||||
installedContainers.insert(container, config);
|
||||
}
|
||||
}
|
||||
|
||||
return ErrorCode::NoError;
|
||||
}
|
||||
|
||||
@@ -35,9 +35,10 @@ public:
|
||||
|
||||
ErrorCode removeAllContainers(const ServerCredentials &credentials);
|
||||
ErrorCode removeContainer(const ServerCredentials &credentials, DockerContainer container);
|
||||
ErrorCode setupContainer(const ServerCredentials &credentials, DockerContainer container, QJsonObject &config);
|
||||
ErrorCode setupContainer(const ServerCredentials &credentials, DockerContainer container,
|
||||
QJsonObject &config, bool isUpdate = false);
|
||||
ErrorCode updateContainer(const ServerCredentials &credentials, DockerContainer container,
|
||||
const QJsonObject &oldConfig, QJsonObject &newConfig);
|
||||
const QJsonObject &oldConfig, QJsonObject &newConfig);
|
||||
|
||||
// create initial config - generate passwords, etc
|
||||
QJsonObject createContainerInitialConfig(DockerContainer container, int port, TransportProto tp);
|
||||
@@ -74,6 +75,7 @@ public:
|
||||
QSsh::SshConnection *connectToHost(const QSsh::SshConnectionParameters &sshParams);
|
||||
|
||||
void setCancelInstallation(const bool cancel);
|
||||
ErrorCode getAlreadyInstalledContainers(const ServerCredentials &credentials, QMap<DockerContainer, QJsonObject> &installedContainers);
|
||||
private:
|
||||
|
||||
ErrorCode installDockerWorker(const ServerCredentials &credentials, DockerContainer container);
|
||||
@@ -82,6 +84,7 @@ private:
|
||||
ErrorCode runContainerWorker(const ServerCredentials &credentials, DockerContainer container, QJsonObject &config);
|
||||
ErrorCode configureContainerWorker(const ServerCredentials &credentials, DockerContainer container, QJsonObject &config);
|
||||
ErrorCode startupContainerWorker(const ServerCredentials &credentials, DockerContainer container, const QJsonObject &config = QJsonObject());
|
||||
ErrorCode isServerPortBusy(const ServerCredentials &credentials, DockerContainer container, const QJsonObject &config);
|
||||
|
||||
std::shared_ptr<Settings> m_settings;
|
||||
std::shared_ptr<VpnConfigurator> m_configurator;
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#include "private/qandroidextras_p.h"
|
||||
#include "ui/pages_logic/StartPageLogic.h"
|
||||
|
||||
#include "androidvpnactivity.h"
|
||||
#include "androidutils.h"
|
||||
|
||||
namespace {
|
||||
@@ -262,6 +261,11 @@ void AndroidController::setVpnConfig(const QJsonObject &newVpnConfig)
|
||||
m_vpnConfig = newVpnConfig;
|
||||
}
|
||||
|
||||
void AndroidController::startQrReaderActivity()
|
||||
{
|
||||
AndroidVPNActivity::instance()->startQrCodeReader();
|
||||
}
|
||||
|
||||
void AndroidController::scheduleStatusCheckSlot()
|
||||
{
|
||||
QTimer::singleShot(1000, [this]() {
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "ui/pages_logic/StartPageLogic.h"
|
||||
|
||||
#include "protocols/vpnprotocol.h"
|
||||
#include "androidvpnactivity.h"
|
||||
|
||||
using namespace amnezia;
|
||||
|
||||
@@ -42,6 +43,8 @@ public:
|
||||
const QJsonObject &vpnConfig() const;
|
||||
void setVpnConfig(const QJsonObject &newVpnConfig);
|
||||
|
||||
void startQrReaderActivity();
|
||||
|
||||
signals:
|
||||
void connectionStateChanged(VpnProtocol::VpnConnectionState state);
|
||||
|
||||
@@ -50,8 +53,7 @@ signals:
|
||||
// to true and the "connectionDate" should be set to the activation date if
|
||||
// known.
|
||||
// If "status" is set to false, the backend service is considered unavailable.
|
||||
void initialized(bool status, bool connected,
|
||||
const QDateTime& connectionDate);
|
||||
void initialized(bool status, bool connected, const QDateTime& connectionDate);
|
||||
|
||||
void statusUpdated(QString totalRx, QString totalTx, QString endpoint, QString deviceIPv4);
|
||||
void scheduleStatusCheckSignal();
|
||||
@@ -59,9 +61,6 @@ signals:
|
||||
protected slots:
|
||||
void scheduleStatusCheckSlot();
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
private:
|
||||
bool m_init = false;
|
||||
|
||||
|
||||
@@ -22,12 +22,10 @@ AndroidVPNActivity::AndroidVPNActivity() {
|
||||
AndroidUtils::runOnAndroidThreadAsync([]() {
|
||||
JNINativeMethod methods[]{
|
||||
{"handleBackButton", "()Z", reinterpret_cast<bool*>(handleBackButton)},
|
||||
{"onServiceMessage", "(ILjava/lang/String;)V",
|
||||
reinterpret_cast<void*>(onServiceMessage)},
|
||||
{"qtOnServiceConnected", "()V",
|
||||
reinterpret_cast<void*>(onServiceConnected)},
|
||||
{"qtOnServiceDisconnected", "()V",
|
||||
reinterpret_cast<void*>(onServiceDisconnected)},
|
||||
{"onServiceMessage", "(ILjava/lang/String;)V", reinterpret_cast<void*>(onServiceMessage)},
|
||||
{"qtOnServiceConnected", "()V", reinterpret_cast<void*>(onServiceConnected)},
|
||||
{"qtOnServiceDisconnected", "()V", reinterpret_cast<void*>(onServiceDisconnected)},
|
||||
{"onActivityMessage", "(ILjava/lang/String;)V", reinterpret_cast<void*>(onAndroidVpnActivityMessage)}
|
||||
};
|
||||
|
||||
QJniObject javaClass(CLASSNAME);
|
||||
@@ -54,6 +52,11 @@ void AndroidVPNActivity::connectService() {
|
||||
QJniObject::callStaticMethod<void>(CLASSNAME, "connectService", "()V");
|
||||
}
|
||||
|
||||
void AndroidVPNActivity::startQrCodeReader()
|
||||
{
|
||||
QJniObject::callStaticMethod<void>(CLASSNAME, "startQrCodeReader", "()V");
|
||||
}
|
||||
|
||||
// static
|
||||
AndroidVPNActivity* AndroidVPNActivity::instance() {
|
||||
if (s_instance == nullptr) {
|
||||
@@ -121,6 +124,19 @@ void AndroidVPNActivity::handleServiceMessage(int code, const QString& data) {
|
||||
}
|
||||
}
|
||||
|
||||
void AndroidVPNActivity::handleActivityMessage(int code, const QString &data)
|
||||
{
|
||||
auto mode = (UIEvents)code;
|
||||
|
||||
switch (mode) {
|
||||
case UIEvents::QR_CODED_DECODED:
|
||||
emit eventQrCodeReceived(data);
|
||||
break;
|
||||
default:
|
||||
Q_ASSERT(false);
|
||||
}
|
||||
}
|
||||
|
||||
void AndroidVPNActivity::onServiceConnected(JNIEnv* env, jobject thiz) {
|
||||
Q_UNUSED(env);
|
||||
Q_UNUSED(thiz);
|
||||
@@ -134,3 +150,19 @@ void AndroidVPNActivity::onServiceDisconnected(JNIEnv* env, jobject thiz) {
|
||||
|
||||
emit AndroidVPNActivity::instance()->serviceDisconnected();
|
||||
}
|
||||
|
||||
void AndroidVPNActivity::onAndroidVpnActivityMessage(JNIEnv *env, jobject thiz, jint messageType, jstring message)
|
||||
{
|
||||
Q_UNUSED(thiz);
|
||||
const char* buffer = env->GetStringUTFChars(message, nullptr);
|
||||
if (!buffer) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString parcelBody(buffer);
|
||||
env->ReleaseStringUTFChars(message, buffer);
|
||||
|
||||
AndroidUtils::dispatchToMainThread([messageType, parcelBody] {
|
||||
AndroidVPNActivity::instance()->handleActivityMessage(messageType, parcelBody);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -59,6 +59,11 @@ enum ServiceEvents {
|
||||
};
|
||||
typedef enum ServiceEvents ServiceEvents;
|
||||
|
||||
enum UIEvents {
|
||||
QR_CODED_DECODED = 0,
|
||||
};
|
||||
typedef enum UIEvents UIEvents;
|
||||
|
||||
class AndroidVPNActivity : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -69,6 +74,7 @@ public:
|
||||
static bool handleBackButton(JNIEnv* env, jobject thiz);
|
||||
static void sendToService(ServiceAction type, const QString& data);
|
||||
static void connectService();
|
||||
static void startQrCodeReader();
|
||||
|
||||
signals:
|
||||
void serviceConnected();
|
||||
@@ -80,6 +86,7 @@ signals:
|
||||
void eventBackendLogs(const QString& data);
|
||||
void eventActivationError(const QString& data);
|
||||
void eventConfigImport(const QString& data);
|
||||
void eventQrCodeReceived(const QString& data);
|
||||
|
||||
private:
|
||||
AndroidVPNActivity();
|
||||
@@ -87,7 +94,9 @@ private:
|
||||
static void onServiceMessage(JNIEnv* env, jobject thiz, jint messageType, jstring body);
|
||||
static void onServiceConnected(JNIEnv* env, jobject thiz);
|
||||
static void onServiceDisconnected(JNIEnv* env, jobject thiz);
|
||||
static void onAndroidVpnActivityMessage(JNIEnv* env, jobject thiz, jint messageType, jstring message);
|
||||
void handleServiceMessage(int code, const QString& data);
|
||||
void handleActivityMessage(int code, const QString& data);
|
||||
};
|
||||
|
||||
#endif // ANDROIDVPNACTIVITY_H
|
||||
|
||||
@@ -81,7 +81,6 @@
|
||||
<file>ui/qml/Pages/PageSites.qml</file>
|
||||
<file>ui/qml/Pages/PageStart.qml</file>
|
||||
<file>ui/qml/Pages/PageVPN.qml</file>
|
||||
<file>ui/qml/Pages/PageQrDecoder.qml</file>
|
||||
<file>ui/qml/Pages/PageAbout.qml</file>
|
||||
<file>ui/qml/Pages/PageQrDecoderIos.qml</file>
|
||||
<file>ui/qml/Pages/PageViewConfig.qml</file>
|
||||
@@ -164,5 +163,7 @@
|
||||
<file>images/svg/settings_suggest_black_24dp.svg</file>
|
||||
<file>server_scripts/website_tor/Dockerfile</file>
|
||||
<file>ui/qml/Controls/PopupWithQuestion.qml</file>
|
||||
<file>ui/qml/Pages/PageAdvancedServerSettings.qml</file>
|
||||
<file>ui/qml/Controls/PopupWarning.qml</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ enum class Page {Start = 0, NewServer, NewServerProtocols, Vpn,
|
||||
Wizard, WizardLow, WizardMedium, WizardHigh, WizardVpnMode, ServerConfiguringProgress,
|
||||
GeneralSettings, AppSettings, NetworkSettings, ServerSettings,
|
||||
ServerContainers, ServersList, ShareConnection, Sites,
|
||||
ProtocolSettings, ProtocolShare, QrDecoder, QrDecoderIos, About, ViewConfig};
|
||||
ProtocolSettings, ProtocolShare, QrDecoder, QrDecoderIos, About, ViewConfig, AdvancedServerSettings};
|
||||
Q_ENUM_NS(Page)
|
||||
|
||||
static void declareQmlPageEnum() {
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
#include "AdvancedServerSettingsLogic.h"
|
||||
|
||||
#include "VpnLogic.h"
|
||||
#include "ui/uilogic.h"
|
||||
#include "core/errorstrings.h"
|
||||
#include "core/servercontroller.h"
|
||||
|
||||
AdvancedServerSettingsLogic::AdvancedServerSettingsLogic(UiLogic *uiLogic, QObject *parent): PageLogicBase(uiLogic, parent),
|
||||
m_labelWaitInfoVisible{true},
|
||||
m_pushButtonClearVisible{true},
|
||||
m_pushButtonClearText{tr("Clear server from Amnezia software")}
|
||||
{
|
||||
}
|
||||
|
||||
void AdvancedServerSettingsLogic::onUpdatePage()
|
||||
{
|
||||
set_labelWaitInfoVisible(false);
|
||||
set_labelWaitInfoText("");
|
||||
set_pushButtonClearVisible(m_settings->haveAuthData(uiLogic()->m_selectedServerIndex));
|
||||
const QJsonObject &server = m_settings->server(uiLogic()->m_selectedServerIndex);
|
||||
const QString &port = server.value(config_key::port).toString();
|
||||
|
||||
const QString &userName = server.value(config_key::userName).toString();
|
||||
const QString &hostName = server.value(config_key::hostName).toString();
|
||||
QString name = QString("%1%2%3%4%5").arg(userName,
|
||||
userName.isEmpty() ? "" : "@",
|
||||
hostName,
|
||||
port.isEmpty() ? "" : ":",
|
||||
port);
|
||||
|
||||
set_labelServerText(name);
|
||||
|
||||
DockerContainer selectedContainer = m_settings->defaultContainer(uiLogic()->m_selectedServerIndex);
|
||||
QString selectedContainerName = ContainerProps::containerHumanNames().value(selectedContainer);
|
||||
set_labelCurrentVpnProtocolText(tr("Service: ") + selectedContainerName);
|
||||
}
|
||||
|
||||
void AdvancedServerSettingsLogic::onPushButtonClearServerClicked()
|
||||
{
|
||||
set_pageEnabled(false);
|
||||
set_pushButtonClearText(tr("Uninstalling Amnezia software..."));
|
||||
|
||||
if (m_settings->defaultServerIndex() == uiLogic()->m_selectedServerIndex) {
|
||||
uiLogic()->pageLogic<VpnLogic>()->onDisconnect();
|
||||
}
|
||||
|
||||
ErrorCode e = m_serverController->removeAllContainers(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex));
|
||||
m_serverController->disconnectFromHost(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex));
|
||||
if (e) {
|
||||
emit uiLogic()->showWarningMessage(tr("Error occurred while cleaning the server.") + "\n" +
|
||||
tr("Error message: ") + errorString(e) + "\n" +
|
||||
tr("See logs for details."));
|
||||
} else {
|
||||
set_labelWaitInfoVisible(true);
|
||||
set_labelWaitInfoText(tr("Amnezia server successfully uninstalled"));
|
||||
}
|
||||
|
||||
m_settings->setContainers(uiLogic()->m_selectedServerIndex, {});
|
||||
m_settings->setDefaultContainer(uiLogic()->m_selectedServerIndex, DockerContainer::None);
|
||||
|
||||
set_pageEnabled(true);
|
||||
set_pushButtonClearText(tr("Clear server from Amnezia software"));
|
||||
}
|
||||
|
||||
void AdvancedServerSettingsLogic::onPushButtonScanServerClicked()
|
||||
{
|
||||
set_labelWaitInfoVisible(false);
|
||||
set_pageEnabled(false);
|
||||
|
||||
bool isServerCreated;
|
||||
auto containersCount = m_settings->containers(uiLogic()->m_selectedServerIndex).size();
|
||||
ErrorCode errorCode = uiLogic()->addAlreadyInstalledContainersGui(false, isServerCreated);
|
||||
if (errorCode != ErrorCode::NoError) {
|
||||
emit uiLogic()->showWarningMessage(tr("Error occurred while scanning the server.") + "\n" +
|
||||
tr("Error message: ") + errorString(errorCode) + "\n" +
|
||||
tr("See logs for details."));
|
||||
}
|
||||
auto newContainersCount = m_settings->containers(uiLogic()->m_selectedServerIndex).size();
|
||||
if (containersCount != newContainersCount) {
|
||||
emit uiLogic()->showWarningMessage(tr("All containers installed on the server are added to the GUI"));
|
||||
} else {
|
||||
emit uiLogic()->showWarningMessage(tr("No installed containers found on the server"));
|
||||
}
|
||||
|
||||
|
||||
onUpdatePage();
|
||||
set_pageEnabled(true);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#ifndef ADVANCEDSERVERSETTINGSLOGIC_H
|
||||
#define ADVANCEDSERVERSETTINGSLOGIC_H
|
||||
|
||||
#include "PageLogicBase.h"
|
||||
|
||||
class UiLogic;
|
||||
|
||||
class AdvancedServerSettingsLogic : public PageLogicBase
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
AUTO_PROPERTY(bool, labelWaitInfoVisible)
|
||||
AUTO_PROPERTY(QString, labelWaitInfoText)
|
||||
|
||||
AUTO_PROPERTY(QString, pushButtonClearText)
|
||||
AUTO_PROPERTY(bool, pushButtonClearVisible)
|
||||
|
||||
AUTO_PROPERTY(QString, labelServerText)
|
||||
AUTO_PROPERTY(QString, labelCurrentVpnProtocolText)
|
||||
|
||||
public:
|
||||
explicit AdvancedServerSettingsLogic(UiLogic *uiLogic, QObject *parent = nullptr);
|
||||
~AdvancedServerSettingsLogic() = default;
|
||||
|
||||
Q_INVOKABLE void onUpdatePage() override;
|
||||
|
||||
Q_INVOKABLE void onPushButtonClearServerClicked();
|
||||
Q_INVOKABLE void onPushButtonScanServerClicked();
|
||||
};
|
||||
|
||||
#endif // ADVANCEDSERVERSETTINGSLOGIC_H
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
#include <QDesktopServices>
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
#include <QStandardPaths>
|
||||
|
||||
using namespace amnezia;
|
||||
@@ -96,10 +95,8 @@ void AppSettingsLogic::onPushButtonRestoreAppConfigClicked()
|
||||
if (ok) {
|
||||
emit uiLogic()->goToPage(Page::Vpn);
|
||||
emit uiLogic()->setStartPage(Page::Vpn);
|
||||
}
|
||||
else {
|
||||
QMessageBox::warning(nullptr, APPLICATION_NAME,
|
||||
tr("Can't import config, file is corrupted."));
|
||||
} else {
|
||||
emit uiLogic()->showWarningMessage(tr("Can't import config, file is corrupted."));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,29 +12,29 @@ GeneralSettingsLogic::GeneralSettingsLogic(UiLogic *logic, QObject *parent):
|
||||
|
||||
void GeneralSettingsLogic::onUpdatePage()
|
||||
{
|
||||
uiLogic()->selectedServerIndex = m_settings->defaultServerIndex();
|
||||
set_existsAnyServer(uiLogic()->selectedServerIndex >= 0);
|
||||
uiLogic()->selectedDockerContainer = m_settings->defaultContainer(m_settings->defaultServerIndex());
|
||||
uiLogic()->m_selectedServerIndex = m_settings->defaultServerIndex();
|
||||
set_existsAnyServer(uiLogic()->m_selectedServerIndex >= 0);
|
||||
uiLogic()->m_selectedDockerContainer = m_settings->defaultContainer(m_settings->defaultServerIndex());
|
||||
|
||||
set_pushButtonGeneralSettingsShareConnectionEnable(m_settings->haveAuthData(m_settings->defaultServerIndex()));
|
||||
}
|
||||
|
||||
void GeneralSettingsLogic::onPushButtonGeneralSettingsServerSettingsClicked()
|
||||
{
|
||||
uiLogic()->selectedServerIndex = m_settings->defaultServerIndex();
|
||||
uiLogic()->selectedDockerContainer = m_settings->defaultContainer(m_settings->defaultServerIndex());
|
||||
uiLogic()->m_selectedServerIndex = m_settings->defaultServerIndex();
|
||||
uiLogic()->m_selectedDockerContainer = m_settings->defaultContainer(m_settings->defaultServerIndex());
|
||||
|
||||
emit uiLogic()->goToPage(Page::ServerSettings);
|
||||
}
|
||||
|
||||
void GeneralSettingsLogic::onPushButtonGeneralSettingsShareConnectionClicked()
|
||||
{
|
||||
uiLogic()->selectedServerIndex = m_settings->defaultServerIndex();
|
||||
uiLogic()->selectedDockerContainer = m_settings->defaultContainer(uiLogic()->selectedServerIndex);
|
||||
uiLogic()->m_selectedServerIndex = m_settings->defaultServerIndex();
|
||||
uiLogic()->m_selectedDockerContainer = m_settings->defaultContainer(uiLogic()->m_selectedServerIndex);
|
||||
|
||||
qobject_cast<ProtocolsModel *>(uiLogic()->protocolsModel())->setSelectedServerIndex(uiLogic()->selectedServerIndex);
|
||||
qobject_cast<ProtocolsModel *>(uiLogic()->protocolsModel())->setSelectedDockerContainer(uiLogic()->selectedDockerContainer);
|
||||
qobject_cast<ProtocolsModel *>(uiLogic()->protocolsModel())->setSelectedServerIndex(uiLogic()->m_selectedServerIndex);
|
||||
qobject_cast<ProtocolsModel *>(uiLogic()->protocolsModel())->setSelectedDockerContainer(uiLogic()->m_selectedDockerContainer);
|
||||
|
||||
uiLogic()->pageLogic<ShareConnectionLogic>()->updateSharingPage(uiLogic()->selectedServerIndex, uiLogic()->selectedDockerContainer);
|
||||
uiLogic()->pageLogic<ShareConnectionLogic>()->updateSharingPage(uiLogic()->m_selectedServerIndex, uiLogic()->m_selectedDockerContainer);
|
||||
emit uiLogic()->goToPage(Page::ShareConnection);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ void NewServerProtocolsLogic::onUpdatePage()
|
||||
|
||||
void NewServerProtocolsLogic::onPushButtonConfigureClicked(DockerContainer c, int port, TransportProto tp)
|
||||
{
|
||||
QMap<DockerContainer, QJsonObject> containers;
|
||||
Proto mainProto = ContainerProps::defaultProtocol(c);
|
||||
|
||||
QJsonObject config {
|
||||
@@ -28,8 +27,8 @@ void NewServerProtocolsLogic::onPushButtonConfigureClicked(DockerContainer c, in
|
||||
}
|
||||
};
|
||||
|
||||
containers.insert(c, config);
|
||||
QPair<DockerContainer, QJsonObject> container(c, config);
|
||||
|
||||
uiLogic()->installServer(containers);
|
||||
uiLogic()->installServer(container);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,15 +3,70 @@
|
||||
#include "ui/uilogic.h"
|
||||
#include "ui/pages_logic/StartPageLogic.h"
|
||||
|
||||
#ifdef Q_OS_ANDROID
|
||||
#include <QJniEnvironment>
|
||||
#include <QJniObject>
|
||||
#include "../../platforms/android/androidutils.h"
|
||||
#endif
|
||||
|
||||
using namespace amnezia;
|
||||
using namespace PageEnumNS;
|
||||
|
||||
namespace {
|
||||
QrDecoderLogic* mInstance = nullptr;
|
||||
constexpr auto CLASSNAME = "org.amnezia.vpn.qt.CameraActivity";
|
||||
}
|
||||
|
||||
QrDecoderLogic::QrDecoderLogic(UiLogic *logic, QObject *parent):
|
||||
PageLogicBase(logic, parent)
|
||||
{
|
||||
mInstance = this;
|
||||
|
||||
#if (defined(Q_OS_ANDROID))
|
||||
AndroidUtils::runOnAndroidThreadAsync([]() {
|
||||
JNINativeMethod methods[]{
|
||||
{"passDataToDecoder", "(Ljava/lang/String;)V", reinterpret_cast<void*>(onNewDataChunk)},
|
||||
};
|
||||
|
||||
QJniObject javaClass(CLASSNAME);
|
||||
QJniEnvironment env;
|
||||
jclass objectClass = env->GetObjectClass(javaClass.object<jobject>());
|
||||
env->RegisterNatives(objectClass, methods, sizeof(methods) / sizeof(methods[0]));
|
||||
env->DeleteLocalRef(objectClass);
|
||||
});
|
||||
#endif
|
||||
}
|
||||
|
||||
void QrDecoderLogic::stopDecodingQr()
|
||||
{
|
||||
#if (defined(Q_OS_ANDROID))
|
||||
QJniObject::callStaticMethod<void>(CLASSNAME, "stopQrCodeReader", "()V");
|
||||
#endif
|
||||
|
||||
emit stopDecode();
|
||||
}
|
||||
|
||||
#ifdef Q_OS_ANDROID
|
||||
void QrDecoderLogic::onNewDataChunk(JNIEnv *env, jobject thiz, jstring data)
|
||||
{
|
||||
Q_UNUSED(thiz);
|
||||
const char* buffer = env->GetStringUTFChars(data, nullptr);
|
||||
if (!buffer) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString parcelBody(buffer);
|
||||
env->ReleaseStringUTFChars(data, buffer);
|
||||
|
||||
if (mInstance != nullptr) {
|
||||
if (!mInstance->m_detectingEnabled) {
|
||||
mInstance->onUpdatePage();
|
||||
}
|
||||
mInstance->onDetectedQrCode(parcelBody);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void QrDecoderLogic::onUpdatePage()
|
||||
{
|
||||
m_chunks.clear();
|
||||
@@ -24,7 +79,6 @@ void QrDecoderLogic::onUpdatePage()
|
||||
void QrDecoderLogic::onDetectedQrCode(const QString &code)
|
||||
{
|
||||
//qDebug() << code;
|
||||
|
||||
if (!detectingEnabled()) return;
|
||||
|
||||
// check if chunk received
|
||||
@@ -32,12 +86,12 @@ void QrDecoderLogic::onDetectedQrCode(const QString &code)
|
||||
QDataStream s(&ba, QIODevice::ReadOnly);
|
||||
qint16 magic; s >> magic;
|
||||
|
||||
|
||||
if (magic == amnezia::qrMagicCode) {
|
||||
quint8 chunksCount; s >> chunksCount;
|
||||
if (totalChunksCount() != chunksCount) {
|
||||
m_chunks.clear();
|
||||
}
|
||||
|
||||
set_totalChunksCount(chunksCount);
|
||||
|
||||
quint8 chunkId; s >> chunkId;
|
||||
@@ -46,6 +100,7 @@ void QrDecoderLogic::onDetectedQrCode(const QString &code)
|
||||
|
||||
if (m_chunks.size() == totalChunksCount()) {
|
||||
QByteArray data;
|
||||
|
||||
for (int i = 0; i < totalChunksCount(); ++i) {
|
||||
data.append(m_chunks.value(i));
|
||||
}
|
||||
@@ -53,21 +108,18 @@ void QrDecoderLogic::onDetectedQrCode(const QString &code)
|
||||
bool ok = uiLogic()->pageLogic<StartPageLogic>()->importConnectionFromQr(data);
|
||||
if (ok) {
|
||||
set_detectingEnabled(false);
|
||||
emit stopDecode();
|
||||
}
|
||||
else {
|
||||
stopDecodingQr();
|
||||
} else {
|
||||
m_chunks.clear();
|
||||
set_totalChunksCount(0);
|
||||
set_receivedChunksCount(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
bool ok = uiLogic()->pageLogic<StartPageLogic>()->importConnectionFromQr(ba);
|
||||
if (ok) {
|
||||
set_detectingEnabled(false);
|
||||
emit stopDecode();
|
||||
stopDecodingQr();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,10 @@
|
||||
|
||||
#include "PageLogicBase.h"
|
||||
|
||||
#ifdef Q_OS_ANDROID
|
||||
#include "jni.h"
|
||||
#endif
|
||||
|
||||
class UiLogic;
|
||||
|
||||
class QrDecoderLogic : public PageLogicBase
|
||||
@@ -16,10 +20,17 @@ public:
|
||||
Q_INVOKABLE void onUpdatePage() override;
|
||||
Q_INVOKABLE void onDetectedQrCode(const QString &code);
|
||||
|
||||
#ifdef Q_OS_ANDROID
|
||||
static void onNewDataChunk(JNIEnv *env, jobject thiz, jstring data);
|
||||
#endif
|
||||
|
||||
public:
|
||||
explicit QrDecoderLogic(UiLogic *uiLogic, QObject *parent = nullptr);
|
||||
~QrDecoderLogic() = default;
|
||||
|
||||
private:
|
||||
void stopDecodingQr();
|
||||
|
||||
signals:
|
||||
void startDecode();
|
||||
void stopDecode();
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
#include "core/errorstrings.h"
|
||||
#include <QTimer>
|
||||
#include <QEventLoop>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "core/servercontroller.h"
|
||||
|
||||
@@ -142,9 +141,6 @@ ErrorCode ServerConfiguringProgressLogic::doInstallAction(const std::function<Er
|
||||
if (waitInfo.setVisibleFunc) {
|
||||
waitInfo.setVisibleFunc(false);
|
||||
}
|
||||
QMessageBox::warning(nullptr, APPLICATION_NAME,
|
||||
tr("Error occurred while configuring server.") + "\n" +
|
||||
errorString(e));
|
||||
|
||||
progress.setVisibleFunc(false);
|
||||
return e;
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "../uilogic.h"
|
||||
#include "../pages_logic/VpnLogic.h"
|
||||
#include "vpnconnection.h"
|
||||
#include "core/errorstrings.h"
|
||||
|
||||
|
||||
ServerContainersLogic::ServerContainersLogic(UiLogic *logic, QObject *parent):
|
||||
@@ -24,34 +25,34 @@ ServerContainersLogic::ServerContainersLogic(UiLogic *logic, QObject *parent):
|
||||
void ServerContainersLogic::onUpdatePage()
|
||||
{
|
||||
ContainersModel *c_model = qobject_cast<ContainersModel *>(uiLogic()->containersModel());
|
||||
c_model->setSelectedServerIndex(uiLogic()->selectedServerIndex);
|
||||
c_model->setSelectedServerIndex(uiLogic()->m_selectedServerIndex);
|
||||
|
||||
ProtocolsModel *p_model = qobject_cast<ProtocolsModel *>(uiLogic()->protocolsModel());
|
||||
p_model->setSelectedServerIndex(uiLogic()->selectedServerIndex);
|
||||
p_model->setSelectedServerIndex(uiLogic()->m_selectedServerIndex);
|
||||
|
||||
set_isManagedServer(m_settings->haveAuthData(uiLogic()->selectedServerIndex));
|
||||
set_isManagedServer(m_settings->haveAuthData(uiLogic()->m_selectedServerIndex));
|
||||
emit updatePage();
|
||||
}
|
||||
|
||||
void ServerContainersLogic::onPushButtonProtoSettingsClicked(DockerContainer c, Proto p)
|
||||
{
|
||||
qDebug()<< "ServerContainersLogic::onPushButtonProtoSettingsClicked" << c << p;
|
||||
uiLogic()->selectedDockerContainer = c;
|
||||
uiLogic()->protocolLogic(p)->updateProtocolPage(m_settings->protocolConfig(uiLogic()->selectedServerIndex, uiLogic()->selectedDockerContainer, p),
|
||||
uiLogic()->selectedDockerContainer,
|
||||
m_settings->haveAuthData(uiLogic()->selectedServerIndex));
|
||||
uiLogic()->m_selectedDockerContainer = c;
|
||||
uiLogic()->protocolLogic(p)->updateProtocolPage(m_settings->protocolConfig(uiLogic()->m_selectedServerIndex, uiLogic()->m_selectedDockerContainer, p),
|
||||
uiLogic()->m_selectedDockerContainer,
|
||||
m_settings->haveAuthData(uiLogic()->m_selectedServerIndex));
|
||||
|
||||
emit uiLogic()->goToProtocolPage(p);
|
||||
}
|
||||
|
||||
void ServerContainersLogic::onPushButtonDefaultClicked(DockerContainer c)
|
||||
{
|
||||
if (m_settings->defaultContainer(uiLogic()->selectedServerIndex) == c) return;
|
||||
if (m_settings->defaultContainer(uiLogic()->m_selectedServerIndex) == c) return;
|
||||
|
||||
m_settings->setDefaultContainer(uiLogic()->selectedServerIndex, c);
|
||||
m_settings->setDefaultContainer(uiLogic()->m_selectedServerIndex, c);
|
||||
uiLogic()->onUpdateAllPages();
|
||||
|
||||
if (uiLogic()->selectedServerIndex != m_settings->defaultServerIndex()) return;
|
||||
if (uiLogic()->m_selectedServerIndex != m_settings->defaultServerIndex()) return;
|
||||
if (!uiLogic()->m_vpnConnection) return;
|
||||
if (!uiLogic()->m_vpnConnection->isConnected()) return;
|
||||
|
||||
@@ -61,21 +62,21 @@ void ServerContainersLogic::onPushButtonDefaultClicked(DockerContainer c)
|
||||
|
||||
void ServerContainersLogic::onPushButtonShareClicked(DockerContainer c)
|
||||
{
|
||||
uiLogic()->pageLogic<ShareConnectionLogic>()->updateSharingPage(uiLogic()->selectedServerIndex, c);
|
||||
uiLogic()->pageLogic<ShareConnectionLogic>()->updateSharingPage(uiLogic()->m_selectedServerIndex, c);
|
||||
emit uiLogic()->goToPage(Page::ShareConnection);
|
||||
}
|
||||
|
||||
void ServerContainersLogic::onPushButtonRemoveClicked(DockerContainer container)
|
||||
{
|
||||
//buttonSetEnabledFunc(false);
|
||||
ErrorCode e = m_serverController->removeContainer(m_settings->serverCredentials(uiLogic()->selectedServerIndex), container);
|
||||
m_settings->removeContainerConfig(uiLogic()->selectedServerIndex, container);
|
||||
ErrorCode e = m_serverController->removeContainer(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex), container);
|
||||
m_settings->removeContainerConfig(uiLogic()->m_selectedServerIndex, container);
|
||||
//buttonSetEnabledFunc(true);
|
||||
|
||||
if (m_settings->defaultContainer(uiLogic()->selectedServerIndex) == container) {
|
||||
const auto &c = m_settings->containers(uiLogic()->selectedServerIndex);
|
||||
if (c.isEmpty()) m_settings->setDefaultContainer(uiLogic()->selectedServerIndex, DockerContainer::None);
|
||||
else m_settings->setDefaultContainer(uiLogic()->selectedServerIndex, c.keys().first());
|
||||
if (m_settings->defaultContainer(uiLogic()->m_selectedServerIndex) == container) {
|
||||
const auto &c = m_settings->containers(uiLogic()->m_selectedServerIndex);
|
||||
if (c.isEmpty()) m_settings->setDefaultContainer(uiLogic()->m_selectedServerIndex, DockerContainer::None);
|
||||
else m_settings->setDefaultContainer(uiLogic()->m_selectedServerIndex, c.keys().first());
|
||||
}
|
||||
uiLogic()->onUpdateAllPages();
|
||||
}
|
||||
@@ -87,17 +88,33 @@ void ServerContainersLogic::onPushButtonContinueClicked(DockerContainer c, int p
|
||||
emit uiLogic()->goToPage(Page::ServerConfiguringProgress);
|
||||
qApp->processEvents();
|
||||
|
||||
ErrorCode e = uiLogic()->pageLogic<ServerConfiguringProgressLogic>()->doInstallAction([this, c, &config](){
|
||||
return m_serverController->setupContainer(m_settings->serverCredentials(uiLogic()->selectedServerIndex), c, config);
|
||||
});
|
||||
bool isServerCreated = false;
|
||||
ErrorCode errorCode = uiLogic()->addAlreadyInstalledContainersGui(false, isServerCreated);
|
||||
|
||||
if (!e) {
|
||||
m_settings->setContainerConfig(uiLogic()->selectedServerIndex, c, config);
|
||||
if (ContainerProps::containerService(c) == ServiceType::Vpn) {
|
||||
m_settings->setDefaultContainer(uiLogic()->selectedServerIndex, c);
|
||||
if (errorCode == ErrorCode::NoError) {
|
||||
if (!uiLogic()->isContainerAlreadyAddedToGui(c)) {
|
||||
auto installAction = [this, c, &config]() {
|
||||
return m_serverController->setupContainer(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex), c, config);
|
||||
};
|
||||
errorCode = uiLogic()->pageLogic<ServerConfiguringProgressLogic>()->doInstallAction(installAction);
|
||||
|
||||
if (errorCode == ErrorCode::NoError) {
|
||||
m_settings->setContainerConfig(uiLogic()->m_selectedServerIndex, c, config);
|
||||
if (ContainerProps::containerService(c) == ServiceType::Vpn) {
|
||||
m_settings->setDefaultContainer(uiLogic()->m_selectedServerIndex, c);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
emit uiLogic()->showWarningMessage("Attention! The container you are trying to install is already installed on the server. "
|
||||
"All installed containers have been added to the application ");
|
||||
}
|
||||
}
|
||||
|
||||
uiLogic()->onUpdateAllPages();
|
||||
uiLogic()->onUpdateAllPages();
|
||||
}
|
||||
if (errorCode != ErrorCode::NoError) {
|
||||
emit uiLogic()->showWarningMessage(tr("Error occurred while configuring server.") + "\n" +
|
||||
tr("Error message: ") + errorString(errorCode) + "\n" +
|
||||
tr("See logs for details."));
|
||||
}
|
||||
emit uiLogic()->closePage();
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ void ServerListLogic::onServerListPushbuttonDefaultClicked(int index)
|
||||
|
||||
void ServerListLogic::onServerListPushbuttonSettingsClicked(int index)
|
||||
{
|
||||
uiLogic()->selectedServerIndex = index;
|
||||
uiLogic()->m_selectedServerIndex = index;
|
||||
uiLogic()->goToPage(Page::ServerSettings);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,10 +16,8 @@
|
||||
ServerSettingsLogic::ServerSettingsLogic(UiLogic *logic, QObject *parent):
|
||||
PageLogicBase(logic, parent),
|
||||
m_labelWaitInfoVisible{true},
|
||||
m_pushButtonClearVisible{true},
|
||||
m_pushButtonClearClientCacheVisible{true},
|
||||
m_pushButtonShareFullVisible{true},
|
||||
m_pushButtonClearText{tr("Clear server from Amnezia software")},
|
||||
m_pushButtonClearClientCacheText{tr("Clear client cached profile")}
|
||||
{ }
|
||||
|
||||
@@ -27,10 +25,9 @@ void ServerSettingsLogic::onUpdatePage()
|
||||
{
|
||||
set_labelWaitInfoVisible(false);
|
||||
set_labelWaitInfoText("");
|
||||
set_pushButtonClearVisible(m_settings->haveAuthData(uiLogic()->selectedServerIndex));
|
||||
set_pushButtonClearClientCacheVisible(m_settings->haveAuthData(uiLogic()->selectedServerIndex));
|
||||
set_pushButtonShareFullVisible(m_settings->haveAuthData(uiLogic()->selectedServerIndex));
|
||||
const QJsonObject &server = m_settings->server(uiLogic()->selectedServerIndex);
|
||||
set_pushButtonClearClientCacheVisible(m_settings->haveAuthData(uiLogic()->m_selectedServerIndex));
|
||||
set_pushButtonShareFullVisible(m_settings->haveAuthData(uiLogic()->m_selectedServerIndex));
|
||||
const QJsonObject &server = m_settings->server(uiLogic()->m_selectedServerIndex);
|
||||
const QString &port = server.value(config_key::port).toString();
|
||||
|
||||
const QString &userName = server.value(config_key::userName).toString();
|
||||
@@ -45,52 +42,22 @@ void ServerSettingsLogic::onUpdatePage()
|
||||
set_labelServerText(name);
|
||||
set_lineEditDescriptionText(server.value(config_key::description).toString());
|
||||
|
||||
DockerContainer selectedContainer = m_settings->defaultContainer(uiLogic()->selectedServerIndex);
|
||||
DockerContainer selectedContainer = m_settings->defaultContainer(uiLogic()->m_selectedServerIndex);
|
||||
QString selectedContainerName = ContainerProps::containerHumanNames().value(selectedContainer);
|
||||
set_labelCurrentVpnProtocolText(tr("Service: ") + selectedContainerName);
|
||||
}
|
||||
|
||||
void ServerSettingsLogic::onPushButtonClearServer()
|
||||
{
|
||||
set_pageEnabled(false);
|
||||
set_pushButtonClearText(tr("Uninstalling Amnezia software..."));
|
||||
|
||||
if (m_settings->defaultServerIndex() == uiLogic()->selectedServerIndex) {
|
||||
uiLogic()->pageLogic<VpnLogic>()->onDisconnect();
|
||||
}
|
||||
|
||||
ErrorCode e = m_serverController->removeAllContainers(m_settings->serverCredentials(uiLogic()->selectedServerIndex));
|
||||
m_serverController->disconnectFromHost(m_settings->serverCredentials(uiLogic()->selectedServerIndex));
|
||||
if (e) {
|
||||
uiLogic()->set_dialogConnectErrorText(
|
||||
tr("Error occurred while configuring server.") + "\n" +
|
||||
errorString(e) + "\n" +
|
||||
tr("See logs for details."));
|
||||
emit uiLogic()->showConnectErrorDialog();
|
||||
}
|
||||
else {
|
||||
set_labelWaitInfoVisible(true);
|
||||
set_labelWaitInfoText(tr("Amnezia server successfully uninstalled"));
|
||||
}
|
||||
|
||||
m_settings->setContainers(uiLogic()->selectedServerIndex, {});
|
||||
m_settings->setDefaultContainer(uiLogic()->selectedServerIndex, DockerContainer::None);
|
||||
|
||||
set_pageEnabled(true);
|
||||
set_pushButtonClearText(tr("Clear server from Amnezia software"));
|
||||
}
|
||||
|
||||
void ServerSettingsLogic::onPushButtonForgetServer()
|
||||
{
|
||||
if (m_settings->defaultServerIndex() == uiLogic()->selectedServerIndex && uiLogic()->m_vpnConnection->isConnected()) {
|
||||
if (m_settings->defaultServerIndex() == uiLogic()->m_selectedServerIndex && uiLogic()->m_vpnConnection->isConnected()) {
|
||||
uiLogic()->pageLogic<VpnLogic>()->onDisconnect();
|
||||
}
|
||||
m_settings->removeServer(uiLogic()->selectedServerIndex);
|
||||
m_settings->removeServer(uiLogic()->m_selectedServerIndex);
|
||||
|
||||
if (m_settings->defaultServerIndex() == uiLogic()->selectedServerIndex) {
|
||||
if (m_settings->defaultServerIndex() == uiLogic()->m_selectedServerIndex) {
|
||||
m_settings->setDefaultServer(0);
|
||||
}
|
||||
else if (m_settings->defaultServerIndex() > uiLogic()->selectedServerIndex) {
|
||||
else if (m_settings->defaultServerIndex() > uiLogic()->m_selectedServerIndex) {
|
||||
m_settings->setDefaultServer(m_settings->defaultServerIndex() - 1);
|
||||
}
|
||||
|
||||
@@ -99,7 +66,7 @@ void ServerSettingsLogic::onPushButtonForgetServer()
|
||||
}
|
||||
|
||||
|
||||
uiLogic()->selectedServerIndex = -1;
|
||||
uiLogic()->m_selectedServerIndex = -1;
|
||||
uiLogic()->onUpdateAllPages();
|
||||
|
||||
if (m_settings->serversCount() == 0) {
|
||||
@@ -114,9 +81,9 @@ void ServerSettingsLogic::onPushButtonClearClientCacheClicked()
|
||||
{
|
||||
set_pushButtonClearClientCacheText(tr("Cache cleared"));
|
||||
|
||||
const auto &containers = m_settings->containers(uiLogic()->selectedServerIndex);
|
||||
for (DockerContainer container: containers.keys()) {
|
||||
m_settings->clearLastConnectionConfig(uiLogic()->selectedServerIndex, container);
|
||||
const auto &containers = m_settings->containers(uiLogic()->m_selectedServerIndex);
|
||||
for (DockerContainer container : containers.keys()) {
|
||||
m_settings->clearLastConnectionConfig(uiLogic()->m_selectedServerIndex, container);
|
||||
}
|
||||
|
||||
QTimer::singleShot(3000, this, [this]() {
|
||||
@@ -127,9 +94,9 @@ void ServerSettingsLogic::onPushButtonClearClientCacheClicked()
|
||||
void ServerSettingsLogic::onLineEditDescriptionEditingFinished()
|
||||
{
|
||||
const QString &newText = lineEditDescriptionText();
|
||||
QJsonObject server = m_settings->server(uiLogic()->selectedServerIndex);
|
||||
QJsonObject server = m_settings->server(uiLogic()->m_selectedServerIndex);
|
||||
server.insert(config_key::description, newText);
|
||||
m_settings->editServer(uiLogic()->selectedServerIndex, server);
|
||||
m_settings->editServer(uiLogic()->m_selectedServerIndex, server);
|
||||
uiLogic()->onUpdateAllPages();
|
||||
}
|
||||
|
||||
@@ -154,7 +121,7 @@ void ServerSettingsLogic::onPushButtonShareFullClicked()
|
||||
auto appContext = activity.callObjectMethod(
|
||||
"getApplicationContext", "()Landroid/content/Context;");
|
||||
if (appContext.isValid()) {
|
||||
QAndroidActivityResultReceiver *receiver = new authResultReceiver(uiLogic(), uiLogic()->selectedServerIndex);
|
||||
QAndroidActivityResultReceiver *receiver = new authResultReceiver(uiLogic(), uiLogic()->m_selectedServerIndex);
|
||||
auto intent = QJniObject::callStaticObjectMethod(
|
||||
"org/amnezia/vpn/AuthHelper", "getAuthIntent",
|
||||
"(Landroid/content/Context;)Landroid/content/Intent;", appContext.object());
|
||||
@@ -163,12 +130,12 @@ void ServerSettingsLogic::onPushButtonShareFullClicked()
|
||||
QtAndroidPrivate::startActivity(intent.object<jobject>(), 1, receiver);
|
||||
}
|
||||
} else {
|
||||
uiLogic()->pageLogic<ShareConnectionLogic>()->updateSharingPage(uiLogic()->selectedServerIndex, DockerContainer::None);
|
||||
uiLogic()->pageLogic<ShareConnectionLogic>()->updateSharingPage(uiLogic()->m_selectedServerIndex, DockerContainer::None);
|
||||
emit uiLogic()->goToShareProtocolPage(Proto::Any);
|
||||
}
|
||||
}
|
||||
#else
|
||||
uiLogic()->pageLogic<ShareConnectionLogic>()->updateSharingPage(uiLogic()->selectedServerIndex, DockerContainer::None);
|
||||
uiLogic()->pageLogic<ShareConnectionLogic>()->updateSharingPage(uiLogic()->m_selectedServerIndex, DockerContainer::None);
|
||||
emit uiLogic()->goToShareProtocolPage(Proto::Any);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -16,9 +16,7 @@ class ServerSettingsLogic : public PageLogicBase
|
||||
|
||||
AUTO_PROPERTY(bool, labelWaitInfoVisible)
|
||||
AUTO_PROPERTY(QString, labelWaitInfoText)
|
||||
AUTO_PROPERTY(QString, pushButtonClearText)
|
||||
AUTO_PROPERTY(QString, pushButtonClearClientCacheText)
|
||||
AUTO_PROPERTY(bool, pushButtonClearVisible)
|
||||
AUTO_PROPERTY(bool, pushButtonClearClientCacheVisible)
|
||||
AUTO_PROPERTY(bool, pushButtonShareFullVisible)
|
||||
AUTO_PROPERTY(QString, labelServerText)
|
||||
@@ -28,7 +26,6 @@ class ServerSettingsLogic : public PageLogicBase
|
||||
public:
|
||||
Q_INVOKABLE void onUpdatePage() override;
|
||||
|
||||
Q_INVOKABLE void onPushButtonClearServer();
|
||||
Q_INVOKABLE void onPushButtonForgetServer();
|
||||
Q_INVOKABLE void onPushButtonShareFullClicked();
|
||||
Q_INVOKABLE void onPushButtonClearClientCacheClicked();
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include <QBuffer>
|
||||
#include <QImage>
|
||||
#include <QDataStream>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "qrcodegen.hpp"
|
||||
|
||||
@@ -68,8 +67,8 @@ void ShareConnectionLogic::onPushButtonShareAmneziaGenerateClicked()
|
||||
set_shareAmneziaQrCodeTextSeriesLength(0);
|
||||
|
||||
QJsonObject serverConfig;
|
||||
int serverIndex = uiLogic()->selectedServerIndex;
|
||||
DockerContainer container = uiLogic()->selectedDockerContainer;
|
||||
int serverIndex = uiLogic()->m_selectedServerIndex;
|
||||
DockerContainer container = uiLogic()->m_selectedDockerContainer;
|
||||
|
||||
// Full access
|
||||
if (shareFullAccess()) {
|
||||
@@ -127,8 +126,8 @@ void ShareConnectionLogic::onPushButtonShareAmneziaGenerateClicked()
|
||||
|
||||
void ShareConnectionLogic::onPushButtonShareOpenVpnGenerateClicked()
|
||||
{
|
||||
int serverIndex = uiLogic()->selectedServerIndex;
|
||||
DockerContainer container = uiLogic()->selectedDockerContainer;
|
||||
int serverIndex = uiLogic()->m_selectedServerIndex;
|
||||
DockerContainer container = uiLogic()->m_selectedDockerContainer;
|
||||
ServerCredentials credentials = m_settings->serverCredentials(serverIndex);
|
||||
|
||||
const QJsonObject &containerConfig = m_settings->containerConfig(serverIndex, container);
|
||||
@@ -142,8 +141,8 @@ void ShareConnectionLogic::onPushButtonShareOpenVpnGenerateClicked()
|
||||
|
||||
void ShareConnectionLogic::onPushButtonShareShadowSocksGenerateClicked()
|
||||
{
|
||||
int serverIndex = uiLogic()->selectedServerIndex;
|
||||
DockerContainer container = uiLogic()->selectedDockerContainer;
|
||||
int serverIndex = uiLogic()->m_selectedServerIndex;
|
||||
DockerContainer container = uiLogic()->m_selectedDockerContainer;
|
||||
ServerCredentials credentials = m_settings->serverCredentials(serverIndex);
|
||||
|
||||
QJsonObject protoConfig = m_settings->protocolConfig(serverIndex, container, Proto::ShadowSocks);
|
||||
@@ -186,8 +185,8 @@ void ShareConnectionLogic::onPushButtonShareShadowSocksGenerateClicked()
|
||||
|
||||
void ShareConnectionLogic::onPushButtonShareCloakGenerateClicked()
|
||||
{
|
||||
int serverIndex = uiLogic()->selectedServerIndex;
|
||||
DockerContainer container = uiLogic()->selectedDockerContainer;
|
||||
int serverIndex = uiLogic()->m_selectedServerIndex;
|
||||
DockerContainer container = uiLogic()->m_selectedDockerContainer;
|
||||
ServerCredentials credentials = m_settings->serverCredentials(serverIndex);
|
||||
|
||||
QJsonObject protoConfig = m_settings->protocolConfig(serverIndex, container, Proto::Cloak);
|
||||
@@ -209,8 +208,8 @@ void ShareConnectionLogic::onPushButtonShareCloakGenerateClicked()
|
||||
|
||||
void ShareConnectionLogic::onPushButtonShareWireGuardGenerateClicked()
|
||||
{
|
||||
int serverIndex = uiLogic()->selectedServerIndex;
|
||||
DockerContainer container = uiLogic()->selectedDockerContainer;
|
||||
int serverIndex = uiLogic()->m_selectedServerIndex;
|
||||
DockerContainer container = uiLogic()->m_selectedDockerContainer;
|
||||
ServerCredentials credentials = m_settings->serverCredentials(serverIndex);
|
||||
|
||||
const QJsonObject &containerConfig = m_settings->containerConfig(serverIndex, container);
|
||||
@@ -218,9 +217,9 @@ void ShareConnectionLogic::onPushButtonShareWireGuardGenerateClicked()
|
||||
ErrorCode e = ErrorCode::NoError;
|
||||
QString cfg = m_configurator->wireguardConfigurator->genWireguardConfig(credentials, container, containerConfig, &e);
|
||||
if (e) {
|
||||
QMessageBox::warning(nullptr, APPLICATION_NAME,
|
||||
tr("Error occurred while configuring server.") + "\n" +
|
||||
errorString(e));
|
||||
emit uiLogic()->showWarningMessage(tr("Error occurred while generating the config.") + "\n" +
|
||||
tr("Error message: ") + errorString(e) + "\n" +
|
||||
tr("See logs for details."));
|
||||
return;
|
||||
}
|
||||
cfg = m_configurator->processConfigWithExportSettings(serverIndex, container, Proto::WireGuard, cfg);
|
||||
@@ -236,8 +235,8 @@ void ShareConnectionLogic::onPushButtonShareWireGuardGenerateClicked()
|
||||
|
||||
void ShareConnectionLogic::onPushButtonShareIkev2GenerateClicked()
|
||||
{
|
||||
int serverIndex = uiLogic()->selectedServerIndex;
|
||||
DockerContainer container = uiLogic()->selectedDockerContainer;
|
||||
int serverIndex = uiLogic()->m_selectedServerIndex;
|
||||
DockerContainer container = uiLogic()->m_selectedDockerContainer;
|
||||
ServerCredentials credentials = m_settings->serverCredentials(serverIndex);
|
||||
|
||||
Ikev2Configurator::ConnectionData connData = m_configurator->ikev2Configurator->prepareIkev2Config(credentials, container);
|
||||
@@ -259,8 +258,8 @@ void ShareConnectionLogic::onPushButtonShareIkev2GenerateClicked()
|
||||
|
||||
void ShareConnectionLogic::updateSharingPage(int serverIndex, DockerContainer container)
|
||||
{
|
||||
uiLogic()->selectedDockerContainer = container;
|
||||
uiLogic()->selectedServerIndex = serverIndex;
|
||||
uiLogic()->m_selectedDockerContainer = container;
|
||||
uiLogic()->m_selectedServerIndex = serverIndex;
|
||||
set_shareFullAccess(container == DockerContainer::None);
|
||||
|
||||
m_shareAmneziaQrCodeTextSeries.clear();
|
||||
|
||||
@@ -50,6 +50,5 @@ public:
|
||||
QList<QString> genQrCodeImageSeries(const QByteArray &data);
|
||||
|
||||
QString svgToBase64(const QString &image);
|
||||
|
||||
};
|
||||
#endif // SHARE_CONNECTION_LOGIC_H
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#ifdef Q_OS_ANDROID
|
||||
#include <QJniObject>
|
||||
#include "../../platforms/android/androidutils.h"
|
||||
#include "../../platforms/android/android_controller.h"
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
@@ -155,7 +156,7 @@ void StartPageLogic::onPushButtonConnect()
|
||||
set_pushButtonConnectEnabled(true);
|
||||
set_pushButtonConnectText(tr("Connect"));
|
||||
|
||||
uiLogic()->installCredentials = serverCredentials;
|
||||
uiLogic()->m_installCredentials = serverCredentials;
|
||||
if (ok) emit uiLogic()->goToPage(Page::NewServer);
|
||||
}
|
||||
|
||||
@@ -184,6 +185,13 @@ void StartPageLogic::onPushButtonImportOpenFile()
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef Q_OS_ANDROID
|
||||
void StartPageLogic::startQrDecoder()
|
||||
{
|
||||
AndroidController::instance()->startQrReaderActivity();
|
||||
}
|
||||
#endif
|
||||
|
||||
bool StartPageLogic::importConnection(const QJsonObject &profile)
|
||||
{
|
||||
ServerCredentials credentials;
|
||||
|
||||
@@ -31,6 +31,10 @@ public:
|
||||
Q_INVOKABLE void onPushButtonImport();
|
||||
Q_INVOKABLE void onPushButtonImportOpenFile();
|
||||
|
||||
#ifdef Q_OS_ANDROID
|
||||
Q_INVOKABLE void startQrDecoder();
|
||||
#endif
|
||||
|
||||
bool importConnection(const QJsonObject &profile);
|
||||
bool importConnectionFromCode(QString code);
|
||||
bool importConnectionFromQr(const QByteArray &data);
|
||||
|
||||
@@ -79,8 +79,8 @@ void ViewConfigLogic::importConfig()
|
||||
|
||||
|
||||
if (!configJson().contains(config_key::containers) || configJson().value(config_key::containers).toArray().isEmpty()) {
|
||||
uiLogic()->selectedServerIndex = m_settings->defaultServerIndex();
|
||||
uiLogic()->selectedDockerContainer = m_settings->defaultContainer(uiLogic()->selectedServerIndex);
|
||||
uiLogic()->m_selectedServerIndex = m_settings->defaultServerIndex();
|
||||
uiLogic()->m_selectedDockerContainer = m_settings->defaultContainer(uiLogic()->m_selectedServerIndex);
|
||||
uiLogic()->onUpdateAllPages();
|
||||
emit uiLogic()->goToPage(Page::Vpn);
|
||||
emit uiLogic()->setStartPage(Page::Vpn);
|
||||
|
||||
@@ -18,7 +18,7 @@ void WizardLogic::onUpdatePage()
|
||||
set_radioButtonMediumChecked(true);
|
||||
}
|
||||
|
||||
QMap<DockerContainer, QJsonObject> WizardLogic::getInstallConfigsFromWizardPage() const
|
||||
QPair<DockerContainer, QJsonObject> WizardLogic::getInstallConfigsFromWizardPage() const
|
||||
{
|
||||
QJsonObject cloakConfig {
|
||||
{ config_key::container, ContainerProps::containerToString(DockerContainer::Cloak) },
|
||||
@@ -33,27 +33,29 @@ QMap<DockerContainer, QJsonObject> WizardLogic::getInstallConfigsFromWizardPage(
|
||||
{ config_key::container, ContainerProps::containerToString(DockerContainer::OpenVpn) }
|
||||
};
|
||||
|
||||
QMap<DockerContainer, QJsonObject> containers;
|
||||
QPair<DockerContainer, QJsonObject> container;
|
||||
|
||||
DockerContainer dockerContainer;
|
||||
|
||||
if (radioButtonHighChecked()) {
|
||||
containers.insert(DockerContainer::Cloak, cloakConfig);
|
||||
container = {DockerContainer::Cloak, cloakConfig};
|
||||
}
|
||||
|
||||
if (radioButtonMediumChecked()) {
|
||||
containers.insert(DockerContainer::ShadowSocks, ssConfig);
|
||||
container = {DockerContainer::ShadowSocks, ssConfig};
|
||||
}
|
||||
|
||||
if (radioButtonLowChecked()) {
|
||||
containers.insert(DockerContainer::OpenVpn, openVpnConfig);
|
||||
container = {DockerContainer::OpenVpn, openVpnConfig};
|
||||
}
|
||||
|
||||
return containers;
|
||||
return container;
|
||||
}
|
||||
|
||||
void WizardLogic::onPushButtonVpnModeFinishClicked()
|
||||
{
|
||||
auto containers = getInstallConfigsFromWizardPage();
|
||||
uiLogic()->installServer(containers);
|
||||
auto container = getInstallConfigsFromWizardPage();
|
||||
uiLogic()->installServer(container);
|
||||
if (checkBoxVpnModeChecked()) {
|
||||
m_settings->setRouteMode(Settings::VpnOnlyForwardSites);
|
||||
} else {
|
||||
@@ -63,6 +65,6 @@ void WizardLogic::onPushButtonVpnModeFinishClicked()
|
||||
|
||||
void WizardLogic::onPushButtonLowFinishClicked()
|
||||
{
|
||||
auto containers = getInstallConfigsFromWizardPage();
|
||||
uiLogic()->installServer(containers);
|
||||
auto container = getInstallConfigsFromWizardPage();
|
||||
uiLogic()->installServer(container);
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ public:
|
||||
explicit WizardLogic(UiLogic *uiLogic, QObject *parent = nullptr);
|
||||
~WizardLogic() = default;
|
||||
|
||||
QMap<DockerContainer, QJsonObject> getInstallConfigsFromWizardPage() const;
|
||||
QPair<DockerContainer, QJsonObject> getInstallConfigsFromWizardPage() const;
|
||||
|
||||
};
|
||||
#endif // WIZARD_LOGIC_H
|
||||
|
||||
@@ -55,10 +55,10 @@ QJsonObject CloakLogic::getProtocolConfigFromPage(QJsonObject oldConfig)
|
||||
|
||||
void CloakLogic::onPushButtonSaveClicked()
|
||||
{
|
||||
QJsonObject protocolConfig = m_settings->protocolConfig(uiLogic()->selectedServerIndex, uiLogic()->selectedDockerContainer, Proto::Cloak);
|
||||
QJsonObject protocolConfig = m_settings->protocolConfig(uiLogic()->m_selectedServerIndex, uiLogic()->m_selectedDockerContainer, Proto::Cloak);
|
||||
protocolConfig = getProtocolConfigFromPage(protocolConfig);
|
||||
|
||||
QJsonObject containerConfig = m_settings->containerConfig(uiLogic()->selectedServerIndex, uiLogic()->selectedDockerContainer);
|
||||
QJsonObject containerConfig = m_settings->containerConfig(uiLogic()->m_selectedServerIndex, uiLogic()->m_selectedDockerContainer);
|
||||
QJsonObject newContainerConfig = containerConfig;
|
||||
newContainerConfig.insert(ProtocolProps::protoToString(Proto::Cloak), protocolConfig);
|
||||
|
||||
@@ -113,8 +113,8 @@ void CloakLogic::onPushButtonSaveClicked()
|
||||
progressBarFunc.setTextVisibleFunc(true);
|
||||
progressBarFunc.setTextFunc(QString("Configuring..."));
|
||||
ErrorCode e = uiLogic()->pageLogic<ServerConfiguringProgressLogic>()->doInstallAction([this, containerConfig, &newContainerConfig](){
|
||||
return m_serverController->updateContainer(m_settings->serverCredentials(uiLogic()->selectedServerIndex),
|
||||
uiLogic()->selectedDockerContainer,
|
||||
return m_serverController->updateContainer(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex),
|
||||
uiLogic()->m_selectedDockerContainer,
|
||||
containerConfig,
|
||||
newContainerConfig);
|
||||
},
|
||||
@@ -123,11 +123,11 @@ void CloakLogic::onPushButtonSaveClicked()
|
||||
busyInfoFuncy, cancelButtonFunc);
|
||||
|
||||
if (!e) {
|
||||
m_settings->setContainerConfig(uiLogic()->selectedServerIndex, uiLogic()->selectedDockerContainer, newContainerConfig);
|
||||
m_settings->clearLastConnectionConfig(uiLogic()->selectedServerIndex, uiLogic()->selectedDockerContainer);
|
||||
m_settings->setContainerConfig(uiLogic()->m_selectedServerIndex, uiLogic()->m_selectedDockerContainer, newContainerConfig);
|
||||
m_settings->clearLastConnectionConfig(uiLogic()->m_selectedServerIndex, uiLogic()->m_selectedDockerContainer);
|
||||
}
|
||||
|
||||
qDebug() << "Protocol saved with code:" << e << "for" << uiLogic()->selectedServerIndex << uiLogic()->selectedDockerContainer;
|
||||
qDebug() << "Protocol saved with code:" << e << "for" << uiLogic()->m_selectedServerIndex << uiLogic()->m_selectedDockerContainer;
|
||||
}
|
||||
|
||||
void CloakLogic::onPushButtonCancelClicked()
|
||||
|
||||
@@ -105,10 +105,10 @@ void OpenVpnLogic::updateProtocolPage(const QJsonObject &openvpnConfig, DockerCo
|
||||
|
||||
void OpenVpnLogic::onPushButtonSaveClicked()
|
||||
{
|
||||
QJsonObject protocolConfig = m_settings->protocolConfig(uiLogic()->selectedServerIndex, uiLogic()->selectedDockerContainer, Proto::OpenVpn);
|
||||
QJsonObject protocolConfig = m_settings->protocolConfig(uiLogic()->m_selectedServerIndex, uiLogic()->m_selectedDockerContainer, Proto::OpenVpn);
|
||||
protocolConfig = getProtocolConfigFromPage(protocolConfig);
|
||||
|
||||
QJsonObject containerConfig = m_settings->containerConfig(uiLogic()->selectedServerIndex, uiLogic()->selectedDockerContainer);
|
||||
QJsonObject containerConfig = m_settings->containerConfig(uiLogic()->m_selectedServerIndex, uiLogic()->m_selectedDockerContainer);
|
||||
QJsonObject newContainerConfig = containerConfig;
|
||||
newContainerConfig.insert(ProtocolProps::protoToString(Proto::OpenVpn), protocolConfig);
|
||||
|
||||
@@ -163,8 +163,8 @@ void OpenVpnLogic::onPushButtonSaveClicked()
|
||||
progressBarFunc.setTextVisibleFunc(true);
|
||||
progressBarFunc.setTextFunc(QString("Configuring..."));
|
||||
ErrorCode e = uiLogic()->pageLogic<ServerConfiguringProgressLogic>()->doInstallAction([this, containerConfig, &newContainerConfig](){
|
||||
return m_serverController->updateContainer(m_settings->serverCredentials(uiLogic()->selectedServerIndex),
|
||||
uiLogic()->selectedDockerContainer,
|
||||
return m_serverController->updateContainer(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex),
|
||||
uiLogic()->m_selectedDockerContainer,
|
||||
containerConfig,
|
||||
newContainerConfig);
|
||||
},
|
||||
@@ -173,10 +173,10 @@ void OpenVpnLogic::onPushButtonSaveClicked()
|
||||
busyInfoFuncy, cancelButtonFunc);
|
||||
|
||||
if (!e) {
|
||||
m_settings->setContainerConfig(uiLogic()->selectedServerIndex, uiLogic()->selectedDockerContainer, newContainerConfig);
|
||||
m_settings->clearLastConnectionConfig(uiLogic()->selectedServerIndex, uiLogic()->selectedDockerContainer);
|
||||
m_settings->setContainerConfig(uiLogic()->m_selectedServerIndex, uiLogic()->m_selectedDockerContainer, newContainerConfig);
|
||||
m_settings->clearLastConnectionConfig(uiLogic()->m_selectedServerIndex, uiLogic()->m_selectedDockerContainer);
|
||||
}
|
||||
qDebug() << "Protocol saved with code:" << e << "for" << uiLogic()->selectedServerIndex << uiLogic()->selectedDockerContainer;
|
||||
qDebug() << "Protocol saved with code:" << e << "for" << uiLogic()->m_selectedServerIndex << uiLogic()->m_selectedDockerContainer;
|
||||
}
|
||||
|
||||
QJsonObject OpenVpnLogic::getProtocolConfigFromPage(QJsonObject oldConfig)
|
||||
|
||||
@@ -81,7 +81,7 @@ void OtherProtocolsLogic::onPushButtonSftpMountDriveClicked()
|
||||
{
|
||||
QString mountPath;
|
||||
QString cmd;
|
||||
QString host = m_settings->serverCredentials(uiLogic()->selectedServerIndex).hostName;
|
||||
QString host = m_settings->serverCredentials(uiLogic()->m_selectedServerIndex).hostName;
|
||||
|
||||
|
||||
#ifdef Q_OS_WINDOWS
|
||||
|
||||
@@ -49,9 +49,9 @@ QJsonObject ShadowSocksLogic::getProtocolConfigFromPage(QJsonObject oldConfig)
|
||||
|
||||
void ShadowSocksLogic::onPushButtonSaveClicked()
|
||||
{
|
||||
QJsonObject protocolConfig = m_settings->protocolConfig(uiLogic()->selectedServerIndex, uiLogic()->selectedDockerContainer, Proto::ShadowSocks);
|
||||
QJsonObject protocolConfig = m_settings->protocolConfig(uiLogic()->m_selectedServerIndex, uiLogic()->m_selectedDockerContainer, Proto::ShadowSocks);
|
||||
|
||||
QJsonObject containerConfig = m_settings->containerConfig(uiLogic()->selectedServerIndex, uiLogic()->selectedDockerContainer);
|
||||
QJsonObject containerConfig = m_settings->containerConfig(uiLogic()->m_selectedServerIndex, uiLogic()->m_selectedDockerContainer);
|
||||
QJsonObject newContainerConfig = containerConfig;
|
||||
newContainerConfig.insert(ProtocolProps::protoToString(Proto::ShadowSocks), protocolConfig);
|
||||
ServerConfiguringProgressLogic::PageFunc pageFunc;
|
||||
@@ -105,8 +105,8 @@ void ShadowSocksLogic::onPushButtonSaveClicked()
|
||||
progressBarFunc.setTextVisibleFunc(true);
|
||||
progressBarFunc.setTextFunc(QString("Configuring..."));
|
||||
ErrorCode e = uiLogic()->pageLogic<ServerConfiguringProgressLogic>()->doInstallAction([this, containerConfig, &newContainerConfig](){
|
||||
return m_serverController->updateContainer(m_settings->serverCredentials(uiLogic()->selectedServerIndex),
|
||||
uiLogic()->selectedDockerContainer,
|
||||
return m_serverController->updateContainer(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex),
|
||||
uiLogic()->m_selectedDockerContainer,
|
||||
containerConfig,
|
||||
newContainerConfig);
|
||||
},
|
||||
@@ -115,10 +115,10 @@ void ShadowSocksLogic::onPushButtonSaveClicked()
|
||||
busyInfoFuncy, cancelButtonFunc);
|
||||
|
||||
if (!e) {
|
||||
m_settings->setContainerConfig(uiLogic()->selectedServerIndex, uiLogic()->selectedDockerContainer, newContainerConfig);
|
||||
m_settings->clearLastConnectionConfig(uiLogic()->selectedServerIndex, uiLogic()->selectedDockerContainer);
|
||||
m_settings->setContainerConfig(uiLogic()->m_selectedServerIndex, uiLogic()->m_selectedDockerContainer, newContainerConfig);
|
||||
m_settings->clearLastConnectionConfig(uiLogic()->m_selectedServerIndex, uiLogic()->m_selectedDockerContainer);
|
||||
}
|
||||
qDebug() << "Protocol saved with code:" << e << "for" << uiLogic()->selectedServerIndex << uiLogic()->selectedDockerContainer;
|
||||
qDebug() << "Protocol saved with code:" << e << "for" << uiLogic()->m_selectedServerIndex << uiLogic()->m_selectedDockerContainer;
|
||||
}
|
||||
|
||||
void ShadowSocksLogic::onPushButtonCancelClicked()
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import QtQuick.Layouts
|
||||
|
||||
Popup {
|
||||
id: root
|
||||
|
||||
property string popupWarningText
|
||||
|
||||
anchors.centerIn: Overlay.overlay
|
||||
modal: true
|
||||
closePolicy: Popup.NoAutoClose
|
||||
width: parent.width - 20
|
||||
|
||||
ColumnLayout {
|
||||
width: parent.width
|
||||
Text {
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
Layout.fillWidth: true
|
||||
wrapMode: Text.WordWrap
|
||||
font.pixelSize: 16
|
||||
text: root.popupWarningText
|
||||
}
|
||||
|
||||
BlueButtonType {
|
||||
Layout.preferredWidth: parent.width / 2
|
||||
Layout.fillWidth: true
|
||||
text: "Continue"
|
||||
onClicked: {
|
||||
root.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import QtQuick.Layouts
|
||||
import PageEnum 1.0
|
||||
import "./"
|
||||
import "../Controls"
|
||||
import "../Config"
|
||||
|
||||
PageBase {
|
||||
id: root
|
||||
page: PageEnum.AdvancedServerSettings
|
||||
logic: AdvancedServerSettingsLogic
|
||||
|
||||
enabled: AdvancedServerSettingsLogic.pageEnabled
|
||||
|
||||
BackButton {
|
||||
id: back
|
||||
}
|
||||
|
||||
Caption {
|
||||
id: caption
|
||||
text: qsTr("Advanced server settings")
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
}
|
||||
|
||||
BusyIndicator {
|
||||
z: 99
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
visible: !AdvancedServerSettingsLogic.pageEnabled
|
||||
running: !AdvancedServerSettingsLogic.pageEnabled
|
||||
}
|
||||
|
||||
FlickableType {
|
||||
id: fl
|
||||
anchors.top: caption.bottom
|
||||
anchors.bottom: logo.top
|
||||
contentHeight: content.height
|
||||
|
||||
ColumnLayout {
|
||||
id: content
|
||||
enabled: logic.pageEnabled
|
||||
anchors.top: parent.top
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.rightMargin: 15
|
||||
|
||||
LabelType {
|
||||
Layout.fillWidth: true
|
||||
font.pixelSize: 20
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
text: AdvancedServerSettingsLogic.labelCurrentVpnProtocolText
|
||||
}
|
||||
|
||||
TextFieldType {
|
||||
Layout.fillWidth: true
|
||||
font.pixelSize: 20
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
text: AdvancedServerSettingsLogic.labelServerText
|
||||
readOnly: true
|
||||
background: Item {}
|
||||
}
|
||||
|
||||
LabelType {
|
||||
Layout.fillWidth: true
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
text: AdvancedServerSettingsLogic.labelWaitInfoText
|
||||
visible: AdvancedServerSettingsLogic.labelWaitInfoVisible
|
||||
}
|
||||
|
||||
BlueButtonType {
|
||||
Layout.fillWidth: true
|
||||
Layout.topMargin: 10
|
||||
text: "Scan the server for installed containers"
|
||||
visible: AdvancedServerSettingsLogic.pushButtonClearVisible
|
||||
onClicked: {
|
||||
AdvancedServerSettingsLogic.onPushButtonScanServerClicked()
|
||||
}
|
||||
}
|
||||
|
||||
BlueButtonType {
|
||||
Layout.fillWidth: true
|
||||
Layout.topMargin: 10
|
||||
text: AdvancedServerSettingsLogic.pushButtonClearText
|
||||
visible: AdvancedServerSettingsLogic.pushButtonClearVisible
|
||||
onClicked: {
|
||||
popupClearServer.open()
|
||||
}
|
||||
}
|
||||
|
||||
PopupWithQuestion {
|
||||
id: popupClearServer
|
||||
questionText: "Attention! All containers will be deleted on the server. This means that configuration files, keys and certificates will be deleted. Continue?"
|
||||
yesFunc: function() {
|
||||
close()
|
||||
AdvancedServerSettingsLogic.onPushButtonClearServerClicked()
|
||||
}
|
||||
noFunc: function() {
|
||||
close()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Logo {
|
||||
id : logo
|
||||
anchors.bottom: parent.bottom
|
||||
}
|
||||
}
|
||||
@@ -1,164 +0,0 @@
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import QtMultimedia
|
||||
import PageEnum 1.0
|
||||
import QZXing 3.2
|
||||
|
||||
import "./"
|
||||
import "../Controls"
|
||||
import "../Config"
|
||||
|
||||
PageBase {
|
||||
id: root
|
||||
page: PageEnum.QrDecoder
|
||||
logic: QrDecoderLogic
|
||||
|
||||
onDeactivated: {
|
||||
console.debug("Stopping QR decoder")
|
||||
loader.sourceComponent = undefined
|
||||
}
|
||||
|
||||
BackButton {
|
||||
}
|
||||
Caption {
|
||||
id: caption
|
||||
text: qsTr("Import configuration")
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: Qt.platform.os != "ios" ? QrDecoderLogic : null
|
||||
function onStartDecode() {
|
||||
console.debug("Starting QR decoder")
|
||||
loader.sourceComponent = component
|
||||
}
|
||||
function onStopDecode() {
|
||||
console.debug("Stopping QR decoder")
|
||||
loader.sourceComponent = undefined
|
||||
}
|
||||
}
|
||||
|
||||
Loader {
|
||||
id: loader
|
||||
|
||||
anchors.top: caption.bottom
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
}
|
||||
|
||||
Component {
|
||||
id: component
|
||||
|
||||
Item {
|
||||
anchors.fill: parent
|
||||
|
||||
Camera
|
||||
{
|
||||
id:camera
|
||||
focus {
|
||||
focusMode: CameraFocus.FocusContinuous
|
||||
focusPointMode: CameraFocus.FocusPointAuto
|
||||
}
|
||||
}
|
||||
|
||||
VideoOutput
|
||||
{
|
||||
id: videoOutput
|
||||
source: camera
|
||||
anchors.top: parent.top
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
autoOrientation: true
|
||||
fillMode: VideoOutput.PreserveAspectFit
|
||||
// filters: [ zxingFilter ]
|
||||
|
||||
|
||||
Rectangle {
|
||||
color: "black"
|
||||
opacity: 0.5
|
||||
width: videoOutput.contentRect.width * 0.15
|
||||
height: videoOutput.contentRect.height
|
||||
x: (videoOutput.width - videoOutput.contentRect.width)/2
|
||||
anchors.verticalCenter: videoOutput.verticalCenter
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
color: "black"
|
||||
opacity: 0.5
|
||||
width: videoOutput.contentRect.width * 0.15
|
||||
height: videoOutput.contentRect.height
|
||||
x: videoOutput.width/2 + videoOutput.contentRect.width/2 - videoOutput.contentRect.width * 0.15
|
||||
anchors.verticalCenter: videoOutput.verticalCenter
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
color: "black"
|
||||
opacity: 0.5
|
||||
width: videoOutput.contentRect.width * 0.7
|
||||
height: videoOutput.contentRect.height * 0.15
|
||||
x: (videoOutput.width - videoOutput.contentRect.width)/2 + videoOutput.contentRect.width * 0.15
|
||||
y: (videoOutput.height - videoOutput.contentRect.height)/2
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
color: "black"
|
||||
opacity: 0.5
|
||||
width: videoOutput.contentRect.width * 0.7
|
||||
height: videoOutput.contentRect.height * 0.15
|
||||
x: (videoOutput.width - videoOutput.contentRect.width)/2 + videoOutput.contentRect.width * 0.15
|
||||
y: videoOutput.height/2 + videoOutput.contentRect.height/2 - videoOutput.contentRect.height * 0.15
|
||||
}
|
||||
|
||||
LabelType {
|
||||
width: parent.width
|
||||
text: qsTr("Decoded QR chunks " + QrDecoderLogic.receivedChunksCount + "/" + QrDecoderLogic.totalChunksCount)
|
||||
horizontalAlignment: Text.AlignLeft
|
||||
visible: QrDecoderLogic.totalChunksCount > 0
|
||||
anchors.horizontalCenter: videoOutput.horizontalCenter
|
||||
y: videoOutput.height/2 + videoOutput.contentRect.height/2
|
||||
}
|
||||
}
|
||||
|
||||
QZXingFilter
|
||||
{
|
||||
id: zxingFilter
|
||||
orientation: videoOutput.orientation
|
||||
captureRect: {
|
||||
// setup bindings
|
||||
videoOutput.contentRect;
|
||||
videoOutput.sourceRect;
|
||||
return videoOutput.mapRectToSource(videoOutput.mapNormalizedRectToItem(Qt.rect(
|
||||
0.15, 0.15, 0.7, 0.7 //0, 0, 1.0, 1.0
|
||||
)));
|
||||
}
|
||||
|
||||
decoder {
|
||||
enabledDecoders: QZXing.DecoderFormat_QR_CODE
|
||||
|
||||
onTagFound: {
|
||||
QrDecoderLogic.onDetectedQrCode(tag)
|
||||
}
|
||||
|
||||
tryHarder: true
|
||||
}
|
||||
|
||||
property int framesDecoded: 0
|
||||
property real timePerFrameDecode: 0
|
||||
|
||||
onDecodingFinished:
|
||||
{
|
||||
timePerFrameDecode = (decodeTime + framesDecoded * timePerFrameDecode) / (framesDecoded + 1);
|
||||
framesDecoded++;
|
||||
if(succeeded)
|
||||
console.log("frame finished: " + succeeded, decodeTime, timePerFrameDecode, framesDecoded);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -74,6 +74,7 @@ PageBase {
|
||||
UiLogic.goToPage(PageEnum.ServerContainers)
|
||||
}
|
||||
}
|
||||
|
||||
BlueButtonType {
|
||||
Layout.fillWidth: true
|
||||
Layout.topMargin: 10
|
||||
@@ -86,33 +87,21 @@ PageBase {
|
||||
|
||||
BlueButtonType {
|
||||
Layout.fillWidth: true
|
||||
Layout.topMargin: 60
|
||||
text: ServerSettingsLogic.pushButtonClearClientCacheText
|
||||
visible: ServerSettingsLogic.pushButtonClearClientCacheVisible
|
||||
Layout.topMargin: 10
|
||||
text: qsTr("Advanced server settings")
|
||||
visible: ServerSettingsLogic.pushButtonShareFullVisible //todo
|
||||
onClicked: {
|
||||
ServerSettingsLogic.onPushButtonClearClientCacheClicked()
|
||||
UiLogic.goToPage(PageEnum.AdvancedServerSettings)
|
||||
}
|
||||
}
|
||||
|
||||
BlueButtonType {
|
||||
Layout.fillWidth: true
|
||||
Layout.topMargin: 10
|
||||
text: ServerSettingsLogic.pushButtonClearText
|
||||
visible: ServerSettingsLogic.pushButtonClearVisible
|
||||
onClicked: {
|
||||
popupClearServer.open()
|
||||
}
|
||||
}
|
||||
|
||||
PopupWithQuestion {
|
||||
id: popupClearServer
|
||||
questionText: "Attention! All containers will be deleted on the server. This means that configuration files, keys and certificates will be deleted. Continue?"
|
||||
yesFunc: function() {
|
||||
ServerSettingsLogic.onPushButtonClearServer()
|
||||
close()
|
||||
}
|
||||
noFunc: function() {
|
||||
close()
|
||||
Layout.topMargin: 60
|
||||
text: ServerSettingsLogic.pushButtonClearClientCacheText
|
||||
visible: ServerSettingsLogic.pushButtonClearClientCacheVisible
|
||||
onClicked: {
|
||||
ServerSettingsLogic.onPushButtonClearClientCacheClicked()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,7 +128,6 @@ PageBase {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Logo {
|
||||
id : logo
|
||||
anchors.bottom: parent.bottom
|
||||
|
||||
@@ -154,7 +154,7 @@ PageBase {
|
||||
if (Qt.platform.os === "ios") {
|
||||
UiLogic.goToPage(PageEnum.QrDecoderIos)
|
||||
} else {
|
||||
UiLogic.goToPage(PageEnum.QrDecoder)
|
||||
StartPageLogic.startQrDecoder()
|
||||
}
|
||||
}
|
||||
enabled: StartPageLogic.pushButtonConnectEnabled
|
||||
|
||||
@@ -230,6 +230,10 @@ Window {
|
||||
function onToggleLogPanel() {
|
||||
drawer_log.visible = !drawer_log.visible
|
||||
}
|
||||
function onShowWarningMessage(message) {
|
||||
popupWarning.popupWarningText = message
|
||||
popupWarning.open()
|
||||
}
|
||||
}
|
||||
|
||||
MessageDialog {
|
||||
@@ -238,12 +242,6 @@ Window {
|
||||
text: qsTr("It's public key. Private key required")
|
||||
visible: false
|
||||
}
|
||||
MessageDialog {
|
||||
id: connectErrorDialog
|
||||
title: "AmneziaVPN"
|
||||
text: UiLogic.dialogConnectErrorText
|
||||
visible: false
|
||||
}
|
||||
|
||||
Drawer {
|
||||
id: drawer_log
|
||||
@@ -353,4 +351,8 @@ Window {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PopupWarning {
|
||||
id: popupWarning
|
||||
}
|
||||
}
|
||||
|
||||
+119
-41
@@ -10,7 +10,6 @@
|
||||
#include <QJsonObject>
|
||||
#include <QKeyEvent>
|
||||
#include <QMenu>
|
||||
#include <QMessageBox>
|
||||
#include <QMetaEnum>
|
||||
#include <QSysInfo>
|
||||
#include <QThread>
|
||||
@@ -67,6 +66,7 @@
|
||||
#include "pages_logic/ViewConfigLogic.h"
|
||||
#include "pages_logic/VpnLogic.h"
|
||||
#include "pages_logic/WizardLogic.h"
|
||||
#include "pages_logic/AdvancedServerSettingsLogic.h"
|
||||
|
||||
#include "pages_logic/protocols/CloakLogic.h"
|
||||
#include "pages_logic/protocols/OpenVpnLogic.h"
|
||||
@@ -157,7 +157,7 @@ void UiLogic::initalizeUiLogic()
|
||||
emit goToPage(Page::Start, true, false);
|
||||
}
|
||||
|
||||
selectedServerIndex = m_settings->defaultServerIndex();
|
||||
m_selectedServerIndex = m_settings->defaultServerIndex();
|
||||
|
||||
qInfo().noquote() << QString("Started %1 version %2").arg(APPLICATION_NAME).arg(APP_VERSION);
|
||||
qInfo().noquote() << QString("%1 (%2)").arg(QSysInfo::prettyProductName()).arg(QSysInfo::currentCpuArchitecture());
|
||||
@@ -199,8 +199,8 @@ void UiLogic::keyPressEvent(Qt::Key key)
|
||||
qApp->quit();
|
||||
break;
|
||||
case Qt::Key_H:
|
||||
selectedServerIndex = m_settings->defaultServerIndex();
|
||||
selectedDockerContainer = m_settings->defaultContainer(selectedServerIndex);
|
||||
m_selectedServerIndex = m_settings->defaultServerIndex();
|
||||
m_selectedDockerContainer = m_settings->defaultContainer(m_selectedServerIndex);
|
||||
|
||||
//updateSharingPage(selectedServerIndex, m_settings->serverCredentials(selectedServerIndex), selectedDockerContainer);
|
||||
emit goToPage(Page::ShareConnection);
|
||||
@@ -214,7 +214,7 @@ void UiLogic::keyPressEvent(Qt::Key key)
|
||||
emit goToPage(Page::Start);
|
||||
break;
|
||||
case Qt::Key_S:
|
||||
selectedServerIndex = m_settings->defaultServerIndex();
|
||||
m_selectedServerIndex = m_settings->defaultServerIndex();
|
||||
emit goToPage(Page::ServerSettings);
|
||||
break;
|
||||
case Qt::Key_P:
|
||||
@@ -262,15 +262,13 @@ QString UiLogic::containerDesc(int container)
|
||||
|
||||
void UiLogic::onGotoCurrentProtocolsPage()
|
||||
{
|
||||
selectedServerIndex = m_settings->defaultServerIndex();
|
||||
selectedDockerContainer = m_settings->defaultContainer(selectedServerIndex);
|
||||
m_selectedServerIndex = m_settings->defaultServerIndex();
|
||||
m_selectedDockerContainer = m_settings->defaultContainer(m_selectedServerIndex);
|
||||
emit goToPage(Page::ServerContainers);
|
||||
}
|
||||
|
||||
void UiLogic::installServer(QMap<DockerContainer, QJsonObject> &containers)
|
||||
void UiLogic::installServer(QPair<DockerContainer, QJsonObject> &container)
|
||||
{
|
||||
if (containers.isEmpty()) return;
|
||||
|
||||
emit goToPage(Page::ServerConfiguringProgress);
|
||||
QEventLoop loop;
|
||||
QTimer::singleShot(500, &loop, SLOT(quit()));
|
||||
@@ -325,43 +323,55 @@ void UiLogic::installServer(QMap<DockerContainer, QJsonObject> &containers)
|
||||
pageLogic<ServerConfiguringProgressLogic>()->set_pushButtonCancelVisible(visible);
|
||||
};
|
||||
|
||||
int count = 0;
|
||||
ErrorCode error;
|
||||
for (QMap<DockerContainer, QJsonObject>::iterator i = containers.begin(); i != containers.end(); i++, count++) {
|
||||
progressBarFunc.setTextFunc(QString("Installing %1 %2 %3").arg(count+1).arg(tr("of")).arg(containers.size()));
|
||||
bool isServerCreated = false;
|
||||
ErrorCode errorCode = addAlreadyInstalledContainersGui(true, isServerCreated);
|
||||
if (errorCode == ErrorCode::NoError) {
|
||||
if (!isContainerAlreadyAddedToGui(container.first)) {
|
||||
progressBarFunc.setTextFunc(QString("Installing %1").arg(ContainerProps::containerToString(container.first)));
|
||||
auto installAction = [&] () {
|
||||
return m_serverController->setupContainer(m_installCredentials, container.first, container.second);
|
||||
};
|
||||
errorCode = pageLogic<ServerConfiguringProgressLogic>()->doInstallAction(installAction, pageFunc, progressBarFunc,
|
||||
noButton, waitInfoFunc,
|
||||
busyInfoFunc, cancelButtonFunc);
|
||||
m_serverController->disconnectFromHost(m_installCredentials);
|
||||
|
||||
error = pageLogic<ServerConfiguringProgressLogic>()->doInstallAction([&] () {
|
||||
return m_serverController->setupContainer(installCredentials, i.key(), i.value());
|
||||
}, pageFunc, progressBarFunc, noButton, waitInfoFunc, busyInfoFunc, cancelButtonFunc);
|
||||
if (errorCode == ErrorCode::NoError) {
|
||||
if (!isServerCreated) {
|
||||
QJsonObject server;
|
||||
server.insert(config_key::hostName, m_installCredentials.hostName);
|
||||
server.insert(config_key::userName, m_installCredentials.userName);
|
||||
server.insert(config_key::password, m_installCredentials.password);
|
||||
server.insert(config_key::port, m_installCredentials.port);
|
||||
server.insert(config_key::description, m_settings->nextAvailableServerName());
|
||||
|
||||
m_serverController->disconnectFromHost(installCredentials);
|
||||
}
|
||||
server.insert(config_key::containers, QJsonArray{container.second});
|
||||
server.insert(config_key::defaultContainer, ContainerProps::containerToString(container.first));
|
||||
|
||||
if (error == ErrorCode::NoError) {
|
||||
QJsonObject server;
|
||||
server.insert(config_key::hostName, installCredentials.hostName);
|
||||
server.insert(config_key::userName, installCredentials.userName);
|
||||
server.insert(config_key::password, installCredentials.password);
|
||||
server.insert(config_key::port, installCredentials.port);
|
||||
server.insert(config_key::description, m_settings->nextAvailableServerName());
|
||||
m_settings->addServer(server);
|
||||
m_settings->setDefaultServer(m_settings->serversCount() - 1);
|
||||
} else {
|
||||
m_settings->setContainerConfig(m_settings->serversCount() - 1, container.first, container.second);
|
||||
m_settings->setDefaultContainer(m_settings->serversCount() - 1, container.first);
|
||||
}
|
||||
onUpdateAllPages();
|
||||
|
||||
QJsonArray containerConfigs;
|
||||
for (const QJsonObject &cfg : containers) {
|
||||
containerConfigs.append(cfg);
|
||||
emit setStartPage(Page::Vpn);
|
||||
qApp->processEvents();
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
onUpdateAllPages();
|
||||
emit showWarningMessage("Attention! The container you are trying to install is already installed on the server. "
|
||||
"All installed containers have been added to the application ");
|
||||
emit setStartPage(Page::Vpn);
|
||||
return;
|
||||
}
|
||||
server.insert(config_key::containers, containerConfigs);
|
||||
server.insert(config_key::defaultContainer, ContainerProps::containerToString(containers.firstKey()));
|
||||
|
||||
m_settings->addServer(server);
|
||||
m_settings->setDefaultServer(m_settings->serversCount() - 1);
|
||||
onUpdateAllPages();
|
||||
|
||||
emit setStartPage(Page::Vpn);
|
||||
qApp->processEvents();
|
||||
}
|
||||
else {
|
||||
emit closePage();
|
||||
}
|
||||
emit showWarningMessage(tr("Error occurred while configuring server.") + "\n" +
|
||||
tr("Error message: ") + errorString(errorCode) + "\n" +
|
||||
tr("See logs for details."));
|
||||
emit closePage();
|
||||
}
|
||||
|
||||
PageProtocolLogicBase *UiLogic::protocolLogic(Proto p)
|
||||
@@ -497,4 +507,72 @@ void UiLogic::registerPagesLogic()
|
||||
registerPageLogic<ViewConfigLogic>();
|
||||
registerPageLogic<VpnLogic>();
|
||||
registerPageLogic<WizardLogic>();
|
||||
registerPageLogic<AdvancedServerSettingsLogic>();
|
||||
}
|
||||
|
||||
ErrorCode UiLogic::addAlreadyInstalledContainersGui(bool createNewServer, bool &isServerCreated)
|
||||
{
|
||||
isServerCreated = false;
|
||||
ServerCredentials credentials;
|
||||
if (createNewServer) {
|
||||
credentials = m_installCredentials;
|
||||
} else {
|
||||
credentials = m_settings->serverCredentials(m_selectedServerIndex);
|
||||
}
|
||||
|
||||
QMap<DockerContainer, QJsonObject> installedContainers;
|
||||
ErrorCode errorCode = m_serverController->getAlreadyInstalledContainers(credentials, installedContainers);
|
||||
m_serverController->disconnectFromHost(credentials);
|
||||
if (errorCode != ErrorCode::NoError) {
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
if (!installedContainers.empty()) {
|
||||
QJsonObject server;
|
||||
QJsonArray containerConfigs;
|
||||
if (createNewServer) {
|
||||
server.insert(config_key::hostName, credentials.hostName);
|
||||
server.insert(config_key::userName, credentials.userName);
|
||||
server.insert(config_key::password, credentials.password);
|
||||
server.insert(config_key::port, credentials.port);
|
||||
server.insert(config_key::description, m_settings->nextAvailableServerName());
|
||||
}
|
||||
|
||||
for (auto container = installedContainers.begin(); container != installedContainers.end(); container++) {
|
||||
if (isContainerAlreadyAddedToGui(container.key())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (createNewServer) {
|
||||
containerConfigs.append(container.value());
|
||||
server.insert(config_key::containers, containerConfigs);
|
||||
} else {
|
||||
m_settings->setContainerConfig(m_selectedServerIndex, container.key(), container.value());
|
||||
m_settings->setDefaultContainer(m_selectedServerIndex, installedContainers.firstKey());
|
||||
}
|
||||
}
|
||||
|
||||
if (createNewServer) {
|
||||
server.insert(config_key::defaultContainer, ContainerProps::containerToString(installedContainers.firstKey()));
|
||||
m_settings->addServer(server);
|
||||
m_settings->setDefaultServer(m_settings->serversCount() - 1);
|
||||
isServerCreated = true;
|
||||
}
|
||||
}
|
||||
|
||||
return ErrorCode::NoError;
|
||||
}
|
||||
|
||||
bool UiLogic::isContainerAlreadyAddedToGui(DockerContainer container)
|
||||
{
|
||||
for (int i = 0; i < m_settings->serversCount(); i++) {
|
||||
const ServerCredentials credentials = m_settings->serverCredentials(i);
|
||||
if (m_installCredentials.hostName == credentials.hostName && m_installCredentials.port == credentials.port) {
|
||||
const QJsonObject containerConfig = m_settings->containerConfig(i, container);
|
||||
if (!containerConfig.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
+14
-7
@@ -42,6 +42,7 @@ class StartPageLogic;
|
||||
class ViewConfigLogic;
|
||||
class VpnLogic;
|
||||
class WizardLogic;
|
||||
class AdvancedServerSettingsLogic;
|
||||
|
||||
class PageProtocolLogicBase;
|
||||
class OpenVpnLogic;
|
||||
@@ -52,6 +53,7 @@ class OtherProtocolsLogic;
|
||||
|
||||
class VpnConnection;
|
||||
|
||||
class CreateServerTest;
|
||||
|
||||
class UiLogic : public QObject
|
||||
{
|
||||
@@ -60,7 +62,7 @@ class UiLogic : public QObject
|
||||
AUTO_PROPERTY(bool, pageEnabled)
|
||||
AUTO_PROPERTY(int, pagesStackDepth)
|
||||
AUTO_PROPERTY(int, currentPageValue)
|
||||
AUTO_PROPERTY(QString, dialogConnectErrorText)
|
||||
AUTO_PROPERTY(QString, popupWarningText)
|
||||
|
||||
READONLY_PROPERTY(QObject *, containersModel)
|
||||
READONLY_PROPERTY(QObject *, protocolsModel)
|
||||
@@ -87,6 +89,7 @@ public:
|
||||
friend class ViewConfigLogic;
|
||||
friend class VpnLogic;
|
||||
friend class WizardLogic;
|
||||
friend class AdvancedServerSettingsLogic;
|
||||
|
||||
friend class PageProtocolLogicBase;
|
||||
friend class OpenVpnLogic;
|
||||
@@ -95,6 +98,8 @@ public:
|
||||
|
||||
friend class OtherProtocolsLogic;
|
||||
|
||||
friend class CreateServerTest;
|
||||
|
||||
Q_INVOKABLE virtual void onUpdatePage() {} // UiLogic is set as logic class for some qml pages
|
||||
Q_INVOKABLE void onUpdateAllPages();
|
||||
|
||||
@@ -112,11 +117,11 @@ public:
|
||||
Q_INVOKABLE void saveBinaryFile(const QString& desc, QString ext, const QString& data);
|
||||
Q_INVOKABLE void copyToClipboard(const QString& text);
|
||||
|
||||
Q_INVOKABLE amnezia::ErrorCode addAlreadyInstalledContainersGui(bool createNewServer, bool &isServerCreated);
|
||||
|
||||
void shareTempFile(const QString &suggestedName, QString ext, const QString& data);
|
||||
|
||||
signals:
|
||||
void dialogConnectErrorTextChanged();
|
||||
|
||||
void goToPage(PageEnumNS::Page page, bool reset = true, bool slide = true);
|
||||
void goToProtocolPage(Proto protocol, bool reset = true, bool slide = true);
|
||||
void goToShareProtocolPage(Proto protocol, bool reset = true, bool slide = true);
|
||||
@@ -129,13 +134,15 @@ signals:
|
||||
void hide();
|
||||
void raise();
|
||||
void toggleLogPanel();
|
||||
void showWarningMessage(QString message);
|
||||
|
||||
private slots:
|
||||
// containers - INOUT arg
|
||||
void installServer(QMap<DockerContainer, QJsonObject> &containers);
|
||||
void installServer(QPair<amnezia::DockerContainer, QJsonObject> &container);
|
||||
|
||||
private:
|
||||
PageEnumNS::Page currentPage();
|
||||
bool isContainerAlreadyAddedToGui(DockerContainer container);
|
||||
|
||||
public:
|
||||
Q_INVOKABLE PageProtocolLogicBase *protocolLogic(Proto p);
|
||||
@@ -178,8 +185,8 @@ private:
|
||||
|
||||
NotificationHandler* m_notificationHandler;
|
||||
|
||||
int selectedServerIndex = -1; // server index to use when proto settings page opened
|
||||
DockerContainer selectedDockerContainer; // same
|
||||
ServerCredentials installCredentials; // used to save cred between pages new_server and new_server_protocols and wizard
|
||||
int m_selectedServerIndex = -1; // server index to use when proto settings page opened
|
||||
DockerContainer m_selectedDockerContainer; // same
|
||||
ServerCredentials m_installCredentials; // used to save cred between pages new_server and new_server_protocols and wizard
|
||||
};
|
||||
#endif // UILOGIC_H
|
||||
|
||||
Reference in New Issue
Block a user