Merge branch 'dev' of github.com:amnezia-vpn/desktop-client into feature/qt6-client-management-panel

This commit is contained in:
vladimir.kuznetsov 2023-03-19 14:58:15 +03:00
commit b000eda126
41 changed files with 630 additions and 275 deletions

View file

@ -303,13 +303,14 @@ if(IOS)
find_library(FW_AUTHENTICATIONSERVICES AuthenticationServices) find_library(FW_AUTHENTICATIONSERVICES AuthenticationServices)
find_library(FW_UIKIT UIKit) find_library(FW_UIKIT UIKit)
find_library(FW_AVFOUNDATION AVFoundation)
find_library(FW_FOUNDATION Foundation) find_library(FW_FOUNDATION Foundation)
find_library(FW_STOREKIT StoreKit) find_library(FW_STOREKIT StoreKit)
find_library(FW_USERNOTIFICATIONS UserNotifications) find_library(FW_USERNOTIFICATIONS UserNotifications)
set(LIBS ${LIBS} set(LIBS ${LIBS}
${FW_AUTHENTICATIONSERVICES} ${FW_UIKIT} ${FW_AUTHENTICATIONSERVICES} ${FW_UIKIT}
${FW_FOUNDATION} ${FW_STOREKIT} ${FW_AVFOUNDATION} ${FW_FOUNDATION} ${FW_STOREKIT}
${FW_USERNOTIFICATIONS} ${FW_USERNOTIFICATIONS}
) )
@ -463,14 +464,13 @@ if(IOS)
PROPERTIES MACOSX_PACKAGE_LOCATION "Resources" PROPERTIES MACOSX_PACKAGE_LOCATION "Resources"
) )
target_sources(${PROJECT} PRIVATE target_sources(${PROJECT} PRIVATE
${CMAKE_CURRENT_LIST_DIR}/ios/Media.xcassets ${CMAKE_CURRENT_LIST_DIR}/ios/Media.xcassets
)
) set_source_files_properties(
set_source_files_properties( ${CMAKE_CURRENT_LIST_DIR}/ios/Media.xcassets
${CMAKE_CURRENT_LIST_DIR}/ios/Media.xcassets PROPERTIES MACOSX_PACKAGE_LOCATION "Resources"
PROPERTIES MACOSX_PACKAGE_LOCATION "Resources" )
)
add_subdirectory(ios/networkextension) add_subdirectory(ios/networkextension)
add_dependencies(${PROJECT} networkextension) add_dependencies(${PROJECT} networkextension)
@ -498,19 +498,13 @@ set_source_files_properties(
) )
set_target_properties (${PROJECT} PROPERTIES XCODE_ATTRIBUTE_CODE_SIGN_STYLE Manual) set_target_properties (${PROJECT} PROPERTIES XCODE_ATTRIBUTE_CODE_SIGN_STYLE Manual)
set_target_properties(${PROJECT} PROPERTIES XCODE_ATTRIBUTE_PROVISIONING_PROFILE_SPECIFIER "match AppStore org.amnezia.AmneziaVPN") set_target_properties(${PROJECT} PROPERTIES XCODE_ATTRIBUTE_PROVISIONING_PROFILE_SPECIFIER "match AppStore org.amnezia.AmneziaVPN")
set_target_properties(${PROJECT} PROPERTIES XCODE_ATTRIBUTE_PROVISIONING_PROFILE_SPECIFIER[variant=Debug] "match Development org.amnezia.AmneziaVPN") set_target_properties(${PROJECT} PROPERTIES XCODE_ATTRIBUTE_PROVISIONING_PROFILE_SPECIFIER[variant=Debug] "match Development org.amnezia.AmneziaVPN")
set_target_properties("networkextension" PROPERTIES XCODE_ATTRIBUTE_CODE_SIGN_STYLE Manual)
set_target_properties ("networkextension" PROPERTIES XCODE_ATTRIBUTE_CODE_SIGN_STYLE Manual)
set_target_properties("networkextension" PROPERTIES XCODE_ATTRIBUTE_PROVISIONING_PROFILE_SPECIFIER "match AppStore org.amnezia.AmneziaVPN.network-extension") set_target_properties("networkextension" PROPERTIES XCODE_ATTRIBUTE_PROVISIONING_PROFILE_SPECIFIER "match AppStore org.amnezia.AmneziaVPN.network-extension")
set_target_properties("networkextension" PROPERTIES XCODE_ATTRIBUTE_PROVISIONING_PROFILE_SPECIFIER[variant=Debug] "match Development org.amnezia.AmneziaVPN.network-extension") set_target_properties("networkextension" PROPERTIES XCODE_ATTRIBUTE_PROVISIONING_PROFILE_SPECIFIER[variant=Debug] "match Development org.amnezia.AmneziaVPN.network-extension")
endif() endif()
if(ANDROID) if(ANDROID)

View file

@ -135,7 +135,7 @@ android {
defaultConfig { defaultConfig {
resConfig "en" resConfig "en"
minSdkVersion = 24 minSdkVersion = 24
targetSdkVersion = 30 targetSdkVersion = 31
versionCode 10 // Change to a higher number versionCode 10 // Change to a higher number
versionName "2.0.10" // Change to a higher number versionName "2.0.10" // Change to a higher number

View file

@ -53,7 +53,7 @@ dependencies {
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0" implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"
implementation "androidx.room:room-runtime:2.2.5" // runtime implementation "androidx.room:room-runtime:2.2.5" // runtime
implementation "androidx.preference:preference:1.1.0" implementation "androidx.preference:preference:1.1.0"
implementation "androidx.work:work-runtime-ktx:2.3.4" implementation "androidx.work:work-runtime-ktx:2.7.1"
implementation "androidx.browser:browser:1.3.0-alpha01" implementation "androidx.browser:browser:1.3.0-alpha01"
implementation "androidx.constraintlayout:constraintlayout:1.1.3" implementation "androidx.constraintlayout:constraintlayout:1.1.3"
implementation "com.google.android.material:material:1.2.0-alpha05" implementation "com.google.android.material:material:1.2.0-alpha05"

View file

@ -68,7 +68,8 @@
android:name="org.amnezia.vpn.shadowsocks.core.BootReceiver" android:name="org.amnezia.vpn.shadowsocks.core.BootReceiver"
android:directBootAware="true" android:directBootAware="true"
android:enabled="false" android:enabled="false"
android:process=":QtOnlyProcess"> android:process=":QtOnlyProcess"
android:exported="true">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" /> <action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" /> <action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />

View file

@ -84,8 +84,9 @@ object Core {
fun init(app: Application, configureClass: KClass<out Any>) { fun init(app: Application, configureClass: KClass<out Any>) {
Core.app = app Core.app = app
configureIntent = { configureIntent = {
PendingIntent.getActivity(it, 0, Intent(it, configureClass.java) PendingIntent.getActivity(it, 0,
.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT), 0) Intent(it, configureClass.java).setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT),
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT)
} }
if (Build.VERSION.SDK_INT >= 24) { // migrate old files if (Build.VERSION.SDK_INT >= 24) { // migrate old files
@ -99,7 +100,6 @@ object Core {
// overhead of debug mode is minimal: https://github.com/Kotlin/kotlinx.coroutines/blob/f528898/docs/debugging.md#debug-mode // overhead of debug mode is minimal: https://github.com/Kotlin/kotlinx.coroutines/blob/f528898/docs/debugging.md#debug-mode
System.setProperty(DEBUG_PROPERTY_NAME, DEBUG_PROPERTY_VALUE_ON) System.setProperty(DEBUG_PROPERTY_NAME, DEBUG_PROPERTY_VALUE_ON)
WorkManager.initialize(deviceStorage, Configuration.Builder().build())
// handle data restored/crash // handle data restored/crash
if (Build.VERSION.SDK_INT >= 24 && DataStore.directBootAware && if (Build.VERSION.SDK_INT >= 24 && DataStore.directBootAware &&

View file

@ -99,7 +99,7 @@ object NotificationUtil {
val mainActivityName = "org.amnezia.vpn.qt.VPNActivity" val mainActivityName = "org.amnezia.vpn.qt.VPNActivity"
val activity = Class.forName(mainActivityName) val activity = Class.forName(mainActivityName)
val intent = Intent(service, activity) val intent = Intent(service, activity)
val pendingIntent = PendingIntent.getActivity(service, 0, intent, 0) val pendingIntent = PendingIntent.getActivity(service, 0, intent, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT)
// Build our notification // Build our notification
sNotificationBuilder?.let { sNotificationBuilder?.let {
it.setSmallIcon(org.amnezia.vpn.R.drawable.ic_amnezia_round) it.setSmallIcon(org.amnezia.vpn.R.drawable.ic_amnezia_round)

View file

@ -894,3 +894,47 @@ ErrorCode ServerController::isServerPortBusy(const ServerCredentials &credential
} }
return ErrorCode::NoError; 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]*)->[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;
}

View file

@ -75,8 +75,9 @@ public:
QSsh::SshConnection *connectToHost(const QSsh::SshConnectionParameters &sshParams); QSsh::SshConnection *connectToHost(const QSsh::SshConnectionParameters &sshParams);
void setCancelInstallation(const bool cancel); void setCancelInstallation(const bool cancel);
ErrorCode getAlreadyInstalledContainers(const ServerCredentials &credentials, QMap<DockerContainer, QJsonObject> &installedContainers);
ErrorCode startupContainerWorker(const ServerCredentials &credentials, DockerContainer container, const QJsonObject &config = QJsonObject()); ErrorCode startupContainerWorker(const ServerCredentials &credentials, DockerContainer container, const QJsonObject &config = QJsonObject());
private: private:
ErrorCode installDockerWorker(const ServerCredentials &credentials, DockerContainer container); ErrorCode installDockerWorker(const ServerCredentials &credentials, DockerContainer container);

View file

@ -167,5 +167,7 @@
<file>images/svg/settings_suggest_black_24dp.svg</file> <file>images/svg/settings_suggest_black_24dp.svg</file>
<file>server_scripts/website_tor/Dockerfile</file> <file>server_scripts/website_tor/Dockerfile</file>
<file>ui/qml/Controls/PopupWithQuestion.qml</file> <file>ui/qml/Controls/PopupWithQuestion.qml</file>
<file>ui/qml/Pages/PageAdvancedServerSettings.qml</file>
<file>ui/qml/Controls/PopupWarning.qml</file>
</qresource> </qresource>
</RCC> </RCC>

View file

@ -6,4 +6,5 @@ if [[ -f "$pm_apt" ]]; then export DEBIAN_FRONTEND=noninteractive; fi;\
if [[ -z "$docker_service" ]]; then sudo $pm update -y -q; sudo $pm install -y -q curl $docker_pkg; fi;\ if [[ -z "$docker_service" ]]; then sudo $pm update -y -q; sudo $pm install -y -q curl $docker_pkg; fi;\
docker_service=$(systemctl list-units --full -all | grep docker.service | grep -v inactive | grep -v dead | grep -v failed);\ docker_service=$(systemctl list-units --full -all | grep docker.service | grep -v inactive | grep -v dead | grep -v failed);\
if [[ -z "$docker_service" ]]; then sleep 5 && sudo systemctl start docker && sleep 5; fi;\ if [[ -z "$docker_service" ]]; then sleep 5 && sudo systemctl start docker && sleep 5; fi;\
if [[ -f "$pm_yum" ]]; then sudo systemctl enable docker && sudo systemctl start docker; fi;\
docker --version docker --version

View file

@ -25,7 +25,8 @@ enum class Page {Start = 0, NewServer, NewServerProtocols, Vpn,
Wizard, WizardLow, WizardMedium, WizardHigh, WizardVpnMode, ServerConfiguringProgress, Wizard, WizardLow, WizardMedium, WizardHigh, WizardVpnMode, ServerConfiguringProgress,
GeneralSettings, AppSettings, NetworkSettings, ServerSettings, GeneralSettings, AppSettings, NetworkSettings, ServerSettings,
ServerContainers, ServersList, ShareConnection, Sites, ServerContainers, ServersList, ShareConnection, Sites,
ProtocolSettings, ProtocolShare, QrDecoder, QrDecoderIos, About, ViewConfig, ClientManagement, ClientInfo}; ProtocolSettings, ProtocolShare, QrDecoder, QrDecoderIos, About, ViewConfig,
AdvancedServerSettings, ClientManagement, ClientInfo};
Q_ENUM_NS(Page) Q_ENUM_NS(Page)
static void declareQmlPageEnum() { static void declareQmlPageEnum() {

View file

@ -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);
}

View file

@ -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

View file

@ -7,7 +7,6 @@
#include <QDesktopServices> #include <QDesktopServices>
#include <QFileDialog> #include <QFileDialog>
#include <QMessageBox>
#include <QStandardPaths> #include <QStandardPaths>
using namespace amnezia; using namespace amnezia;
@ -96,10 +95,8 @@ void AppSettingsLogic::onPushButtonRestoreAppConfigClicked()
if (ok) { if (ok) {
emit uiLogic()->goToPage(Page::Vpn); emit uiLogic()->goToPage(Page::Vpn);
emit uiLogic()->setStartPage(Page::Vpn); emit uiLogic()->setStartPage(Page::Vpn);
} } else {
else { emit uiLogic()->showWarningMessage(tr("Can't import config, file is corrupted."));
QMessageBox::warning(nullptr, APPLICATION_NAME,
tr("Can't import config, file is corrupted."));
} }
} }

View file

@ -35,8 +35,8 @@ void ClientInfoLogic::onUpdatePage()
set_pageContentVisible(false); set_pageContentVisible(false);
set_busyIndicatorIsRunning(true); set_busyIndicatorIsRunning(true);
const ServerCredentials credentials = m_settings->serverCredentials(uiLogic()->selectedServerIndex); const ServerCredentials credentials = m_settings->serverCredentials(uiLogic()->m_selectedServerIndex);
const DockerContainer container = m_settings->defaultContainer(uiLogic()->selectedServerIndex); const DockerContainer container = m_settings->defaultContainer(uiLogic()->m_selectedServerIndex);
const QString containerNameString = ContainerProps::containerHumanNames().value(container); const QString containerNameString = ContainerProps::containerHumanNames().value(container);
set_labelCurrentVpnProtocolText(tr("Service: ") + containerNameString); set_labelCurrentVpnProtocolText(tr("Service: ") + containerNameString);
@ -88,8 +88,8 @@ void ClientInfoLogic::onLineEditNameAliasEditingFinished()
const QModelIndex modelIndex = model->index(m_currentClientIndex); const QModelIndex modelIndex = model->index(m_currentClientIndex);
model->setData(modelIndex, m_lineEditNameAliasText, ClientManagementModel::ClientRoles::NameRole); model->setData(modelIndex, m_lineEditNameAliasText, ClientManagementModel::ClientRoles::NameRole);
const DockerContainer selectedContainer = m_settings->defaultContainer(uiLogic()->selectedServerIndex); const DockerContainer selectedContainer = m_settings->defaultContainer(uiLogic()->m_selectedServerIndex);
const ServerCredentials credentials = m_settings->serverCredentials(uiLogic()->selectedServerIndex); const ServerCredentials credentials = m_settings->serverCredentials(uiLogic()->m_selectedServerIndex);
const QVector<amnezia::Proto> protocols = ContainerProps::protocolsForContainer(selectedContainer); const QVector<amnezia::Proto> protocols = ContainerProps::protocolsForContainer(selectedContainer);
if (!protocols.empty()) { if (!protocols.empty()) {
const Proto currentMainProtocol = protocols.front(); const Proto currentMainProtocol = protocols.front();
@ -108,8 +108,8 @@ void ClientInfoLogic::onLineEditNameAliasEditingFinished()
void ClientInfoLogic::onRevokeOpenVpnCertificateClicked() void ClientInfoLogic::onRevokeOpenVpnCertificateClicked()
{ {
set_busyIndicatorIsRunning(true); set_busyIndicatorIsRunning(true);
const DockerContainer container = m_settings->defaultContainer(uiLogic()->selectedServerIndex); const DockerContainer container = m_settings->defaultContainer(uiLogic()->m_selectedServerIndex);
const ServerCredentials credentials = m_settings->serverCredentials(uiLogic()->selectedServerIndex); const ServerCredentials credentials = m_settings->serverCredentials(uiLogic()->m_selectedServerIndex);
auto model = qobject_cast<ClientManagementModel*>(uiLogic()->clientManagementModel()); auto model = qobject_cast<ClientManagementModel*>(uiLogic()->clientManagementModel());
const QModelIndex modelIndex = model->index(m_currentClientIndex); const QModelIndex modelIndex = model->index(m_currentClientIndex);
@ -137,7 +137,7 @@ void ClientInfoLogic::onRevokeOpenVpnCertificateClicked()
return; return;
} }
const QJsonObject &containerConfig = m_settings->containerConfig(uiLogic()->selectedServerIndex, container); const QJsonObject &containerConfig = m_settings->containerConfig(uiLogic()->m_selectedServerIndex, container);
error = m_serverController->startupContainerWorker(credentials, container, containerConfig); error = m_serverController->startupContainerWorker(credentials, container, containerConfig);
if (isErrorOccured(error)) { if (isErrorOccured(error)) {
set_busyIndicatorIsRunning(false); set_busyIndicatorIsRunning(false);
@ -151,8 +151,8 @@ void ClientInfoLogic::onRevokeWireGuardKeyClicked()
{ {
set_busyIndicatorIsRunning(true); set_busyIndicatorIsRunning(true);
ErrorCode error; ErrorCode error;
const DockerContainer container = m_settings->defaultContainer(uiLogic()->selectedServerIndex); const DockerContainer container = m_settings->defaultContainer(uiLogic()->m_selectedServerIndex);
const ServerCredentials credentials = m_settings->serverCredentials(uiLogic()->selectedServerIndex); const ServerCredentials credentials = m_settings->serverCredentials(uiLogic()->m_selectedServerIndex);
const QString wireGuardConfigFile = "opt/amnezia/wireguard/wg0.conf"; const QString wireGuardConfigFile = "opt/amnezia/wireguard/wg0.conf";
const QString wireguardConfigString = m_serverController->getTextFileFromContainer(container, credentials, wireGuardConfigFile, &error); const QString wireguardConfigString = m_serverController->getTextFileFromContainer(container, credentials, wireGuardConfigFile, &error);
if (isErrorOccured(error)) { if (isErrorOccured(error)) {

View file

@ -20,7 +20,7 @@ void ClientManagementLogic::onUpdatePage()
set_busyIndicatorIsRunning(true); set_busyIndicatorIsRunning(true);
qobject_cast<ClientManagementModel*>(uiLogic()->clientManagementModel())->clearData(); qobject_cast<ClientManagementModel*>(uiLogic()->clientManagementModel())->clearData();
DockerContainer selectedContainer = m_settings->defaultContainer(uiLogic()->selectedServerIndex); DockerContainer selectedContainer = m_settings->defaultContainer(uiLogic()->m_selectedServerIndex);
QString selectedContainerName = ContainerProps::containerHumanNames().value(selectedContainer); QString selectedContainerName = ContainerProps::containerHumanNames().value(selectedContainer);
set_labelCurrentVpnProtocolText(tr("Service: ") + selectedContainerName); set_labelCurrentVpnProtocolText(tr("Service: ") + selectedContainerName);
@ -30,7 +30,7 @@ void ClientManagementLogic::onUpdatePage()
if (!protocols.empty()) { if (!protocols.empty()) {
m_currentMainProtocol = protocols.front(); m_currentMainProtocol = protocols.front();
const ServerCredentials credentials = m_settings->serverCredentials(uiLogic()->selectedServerIndex); const ServerCredentials credentials = m_settings->serverCredentials(uiLogic()->m_selectedServerIndex);
ErrorCode error = getClientsList(credentials, selectedContainer, m_currentMainProtocol, clients); ErrorCode error = getClientsList(credentials, selectedContainer, m_currentMainProtocol, clients);
m_serverController->disconnectFromHost(credentials); m_serverController->disconnectFromHost(credentials);

View file

@ -12,29 +12,29 @@ GeneralSettingsLogic::GeneralSettingsLogic(UiLogic *logic, QObject *parent):
void GeneralSettingsLogic::onUpdatePage() void GeneralSettingsLogic::onUpdatePage()
{ {
uiLogic()->selectedServerIndex = m_settings->defaultServerIndex(); uiLogic()->m_selectedServerIndex = m_settings->defaultServerIndex();
set_existsAnyServer(uiLogic()->selectedServerIndex >= 0); set_existsAnyServer(uiLogic()->m_selectedServerIndex >= 0);
uiLogic()->selectedDockerContainer = m_settings->defaultContainer(m_settings->defaultServerIndex()); uiLogic()->m_selectedDockerContainer = m_settings->defaultContainer(m_settings->defaultServerIndex());
set_pushButtonGeneralSettingsShareConnectionEnable(m_settings->haveAuthData(m_settings->defaultServerIndex())); set_pushButtonGeneralSettingsShareConnectionEnable(m_settings->haveAuthData(m_settings->defaultServerIndex()));
} }
void GeneralSettingsLogic::onPushButtonGeneralSettingsServerSettingsClicked() void GeneralSettingsLogic::onPushButtonGeneralSettingsServerSettingsClicked()
{ {
uiLogic()->selectedServerIndex = m_settings->defaultServerIndex(); uiLogic()->m_selectedServerIndex = m_settings->defaultServerIndex();
uiLogic()->selectedDockerContainer = m_settings->defaultContainer(m_settings->defaultServerIndex()); uiLogic()->m_selectedDockerContainer = m_settings->defaultContainer(m_settings->defaultServerIndex());
emit uiLogic()->goToPage(Page::ServerSettings); emit uiLogic()->goToPage(Page::ServerSettings);
} }
void GeneralSettingsLogic::onPushButtonGeneralSettingsShareConnectionClicked() void GeneralSettingsLogic::onPushButtonGeneralSettingsShareConnectionClicked()
{ {
uiLogic()->selectedServerIndex = m_settings->defaultServerIndex(); uiLogic()->m_selectedServerIndex = m_settings->defaultServerIndex();
uiLogic()->selectedDockerContainer = m_settings->defaultContainer(uiLogic()->selectedServerIndex); uiLogic()->m_selectedDockerContainer = m_settings->defaultContainer(uiLogic()->m_selectedServerIndex);
qobject_cast<ProtocolsModel *>(uiLogic()->protocolsModel())->setSelectedServerIndex(uiLogic()->selectedServerIndex); qobject_cast<ProtocolsModel *>(uiLogic()->protocolsModel())->setSelectedServerIndex(uiLogic()->m_selectedServerIndex);
qobject_cast<ProtocolsModel *>(uiLogic()->protocolsModel())->setSelectedDockerContainer(uiLogic()->selectedDockerContainer); 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); emit uiLogic()->goToPage(Page::ShareConnection);
} }

View file

@ -17,7 +17,6 @@ void NewServerProtocolsLogic::onUpdatePage()
void NewServerProtocolsLogic::onPushButtonConfigureClicked(DockerContainer c, int port, TransportProto tp) void NewServerProtocolsLogic::onPushButtonConfigureClicked(DockerContainer c, int port, TransportProto tp)
{ {
QMap<DockerContainer, QJsonObject> containers;
Proto mainProto = ContainerProps::defaultProtocol(c); Proto mainProto = ContainerProps::defaultProtocol(c);
QJsonObject config { 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);
} }

View file

@ -3,7 +3,6 @@
#include "core/errorstrings.h" #include "core/errorstrings.h"
#include <QTimer> #include <QTimer>
#include <QEventLoop> #include <QEventLoop>
#include <QMessageBox>
#include "core/servercontroller.h" #include "core/servercontroller.h"
@ -142,9 +141,6 @@ ErrorCode ServerConfiguringProgressLogic::doInstallAction(const std::function<Er
if (waitInfo.setVisibleFunc) { if (waitInfo.setVisibleFunc) {
waitInfo.setVisibleFunc(false); waitInfo.setVisibleFunc(false);
} }
QMessageBox::warning(nullptr, APPLICATION_NAME,
tr("Error occurred while configuring server.") + "\n" +
errorString(e));
progress.setVisibleFunc(false); progress.setVisibleFunc(false);
return e; return e;

View file

@ -14,6 +14,7 @@
#include "../uilogic.h" #include "../uilogic.h"
#include "../pages_logic/VpnLogic.h" #include "../pages_logic/VpnLogic.h"
#include "vpnconnection.h" #include "vpnconnection.h"
#include "core/errorstrings.h"
ServerContainersLogic::ServerContainersLogic(UiLogic *logic, QObject *parent): ServerContainersLogic::ServerContainersLogic(UiLogic *logic, QObject *parent):
@ -24,34 +25,34 @@ ServerContainersLogic::ServerContainersLogic(UiLogic *logic, QObject *parent):
void ServerContainersLogic::onUpdatePage() void ServerContainersLogic::onUpdatePage()
{ {
ContainersModel *c_model = qobject_cast<ContainersModel *>(uiLogic()->containersModel()); 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()); 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(); emit updatePage();
} }
void ServerContainersLogic::onPushButtonProtoSettingsClicked(DockerContainer c, Proto p) void ServerContainersLogic::onPushButtonProtoSettingsClicked(DockerContainer c, Proto p)
{ {
qDebug()<< "ServerContainersLogic::onPushButtonProtoSettingsClicked" << c << p; qDebug()<< "ServerContainersLogic::onPushButtonProtoSettingsClicked" << c << p;
uiLogic()->selectedDockerContainer = c; uiLogic()->m_selectedDockerContainer = c;
uiLogic()->protocolLogic(p)->updateProtocolPage(m_settings->protocolConfig(uiLogic()->selectedServerIndex, uiLogic()->selectedDockerContainer, p), uiLogic()->protocolLogic(p)->updateProtocolPage(m_settings->protocolConfig(uiLogic()->m_selectedServerIndex, uiLogic()->m_selectedDockerContainer, p),
uiLogic()->selectedDockerContainer, uiLogic()->m_selectedDockerContainer,
m_settings->haveAuthData(uiLogic()->selectedServerIndex)); m_settings->haveAuthData(uiLogic()->m_selectedServerIndex));
emit uiLogic()->goToProtocolPage(p); emit uiLogic()->goToProtocolPage(p);
} }
void ServerContainersLogic::onPushButtonDefaultClicked(DockerContainer c) 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(); 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) return;
if (!uiLogic()->m_vpnConnection->isConnected()) return; if (!uiLogic()->m_vpnConnection->isConnected()) return;
@ -61,21 +62,21 @@ void ServerContainersLogic::onPushButtonDefaultClicked(DockerContainer c)
void ServerContainersLogic::onPushButtonShareClicked(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); emit uiLogic()->goToPage(Page::ShareConnection);
} }
void ServerContainersLogic::onPushButtonRemoveClicked(DockerContainer container) void ServerContainersLogic::onPushButtonRemoveClicked(DockerContainer container)
{ {
//buttonSetEnabledFunc(false); //buttonSetEnabledFunc(false);
ErrorCode e = m_serverController->removeContainer(m_settings->serverCredentials(uiLogic()->selectedServerIndex), container); ErrorCode e = m_serverController->removeContainer(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex), container);
m_settings->removeContainerConfig(uiLogic()->selectedServerIndex, container); m_settings->removeContainerConfig(uiLogic()->m_selectedServerIndex, container);
//buttonSetEnabledFunc(true); //buttonSetEnabledFunc(true);
if (m_settings->defaultContainer(uiLogic()->selectedServerIndex) == container) { if (m_settings->defaultContainer(uiLogic()->m_selectedServerIndex) == container) {
const auto &c = m_settings->containers(uiLogic()->selectedServerIndex); const auto &c = m_settings->containers(uiLogic()->m_selectedServerIndex);
if (c.isEmpty()) m_settings->setDefaultContainer(uiLogic()->selectedServerIndex, DockerContainer::None); if (c.isEmpty()) m_settings->setDefaultContainer(uiLogic()->m_selectedServerIndex, DockerContainer::None);
else m_settings->setDefaultContainer(uiLogic()->selectedServerIndex, c.keys().first()); else m_settings->setDefaultContainer(uiLogic()->m_selectedServerIndex, c.keys().first());
} }
uiLogic()->onUpdateAllPages(); uiLogic()->onUpdateAllPages();
} }
@ -87,17 +88,33 @@ void ServerContainersLogic::onPushButtonContinueClicked(DockerContainer c, int p
emit uiLogic()->goToPage(Page::ServerConfiguringProgress); emit uiLogic()->goToPage(Page::ServerConfiguringProgress);
qApp->processEvents(); qApp->processEvents();
ErrorCode e = uiLogic()->pageLogic<ServerConfiguringProgressLogic>()->doInstallAction([this, c, &config](){ bool isServerCreated = false;
return m_serverController->setupContainer(m_settings->serverCredentials(uiLogic()->selectedServerIndex), c, config); ErrorCode errorCode = uiLogic()->addAlreadyInstalledContainersGui(false, isServerCreated);
});
if (!e) { if (errorCode == ErrorCode::NoError) {
m_settings->setContainerConfig(uiLogic()->selectedServerIndex, c, config); if (!uiLogic()->isContainerAlreadyAddedToGui(c)) {
if (ContainerProps::containerService(c) == ServiceType::Vpn) { auto installAction = [this, c, &config]() {
m_settings->setDefaultContainer(uiLogic()->selectedServerIndex, c); 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(); emit uiLogic()->closePage();
} }

View file

@ -20,7 +20,8 @@ void ServerListLogic::onServerListPushbuttonDefaultClicked(int index)
void ServerListLogic::onServerListPushbuttonSettingsClicked(int index) void ServerListLogic::onServerListPushbuttonSettingsClicked(int index)
{ {
uiLogic()->selectedServerIndex = index; uiLogic()->m_selectedServerIndex = index;
uiLogic()->m_installCredentials = m_settings->serverCredentials(index);
uiLogic()->goToPage(Page::ServerSettings); uiLogic()->goToPage(Page::ServerSettings);
} }

View file

@ -16,10 +16,8 @@
ServerSettingsLogic::ServerSettingsLogic(UiLogic *logic, QObject *parent): ServerSettingsLogic::ServerSettingsLogic(UiLogic *logic, QObject *parent):
PageLogicBase(logic, parent), PageLogicBase(logic, parent),
m_labelWaitInfoVisible{true}, m_labelWaitInfoVisible{true},
m_pushButtonClearVisible{true},
m_pushButtonClearClientCacheVisible{true}, m_pushButtonClearClientCacheVisible{true},
m_pushButtonShareFullVisible{true}, m_pushButtonShareFullVisible{true},
m_pushButtonClearText{tr("Clear server from Amnezia software")},
m_pushButtonClearClientCacheText{tr("Clear client cached profile")} m_pushButtonClearClientCacheText{tr("Clear client cached profile")}
{ } { }
@ -27,10 +25,9 @@ void ServerSettingsLogic::onUpdatePage()
{ {
set_labelWaitInfoVisible(false); set_labelWaitInfoVisible(false);
set_labelWaitInfoText(""); set_labelWaitInfoText("");
set_pushButtonClearVisible(m_settings->haveAuthData(uiLogic()->selectedServerIndex)); set_pushButtonClearClientCacheVisible(m_settings->haveAuthData(uiLogic()->m_selectedServerIndex));
set_pushButtonClearClientCacheVisible(m_settings->haveAuthData(uiLogic()->selectedServerIndex)); set_pushButtonShareFullVisible(m_settings->haveAuthData(uiLogic()->m_selectedServerIndex));
set_pushButtonShareFullVisible(m_settings->haveAuthData(uiLogic()->selectedServerIndex)); const QJsonObject &server = m_settings->server(uiLogic()->m_selectedServerIndex);
const QJsonObject &server = m_settings->server(uiLogic()->selectedServerIndex);
const QString &port = server.value(config_key::port).toString(); const QString &port = server.value(config_key::port).toString();
const QString &userName = server.value(config_key::userName).toString(); const QString &userName = server.value(config_key::userName).toString();
@ -45,52 +42,22 @@ void ServerSettingsLogic::onUpdatePage()
set_labelServerText(name); set_labelServerText(name);
set_lineEditDescriptionText(server.value(config_key::description).toString()); 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); QString selectedContainerName = ContainerProps::containerHumanNames().value(selectedContainer);
set_labelCurrentVpnProtocolText(tr("Service: ") + selectedContainerName); 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() 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(); 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); 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); m_settings->setDefaultServer(m_settings->defaultServerIndex() - 1);
} }
@ -99,7 +66,7 @@ void ServerSettingsLogic::onPushButtonForgetServer()
} }
uiLogic()->selectedServerIndex = -1; uiLogic()->m_selectedServerIndex = -1;
uiLogic()->onUpdateAllPages(); uiLogic()->onUpdateAllPages();
if (m_settings->serversCount() == 0) { if (m_settings->serversCount() == 0) {
@ -114,9 +81,9 @@ void ServerSettingsLogic::onPushButtonClearClientCacheClicked()
{ {
set_pushButtonClearClientCacheText(tr("Cache cleared")); set_pushButtonClearClientCacheText(tr("Cache cleared"));
const auto &containers = m_settings->containers(uiLogic()->selectedServerIndex); const auto &containers = m_settings->containers(uiLogic()->m_selectedServerIndex);
for (DockerContainer container: containers.keys()) { for (DockerContainer container : containers.keys()) {
m_settings->clearLastConnectionConfig(uiLogic()->selectedServerIndex, container); m_settings->clearLastConnectionConfig(uiLogic()->m_selectedServerIndex, container);
} }
QTimer::singleShot(3000, this, [this]() { QTimer::singleShot(3000, this, [this]() {
@ -127,9 +94,9 @@ void ServerSettingsLogic::onPushButtonClearClientCacheClicked()
void ServerSettingsLogic::onLineEditDescriptionEditingFinished() void ServerSettingsLogic::onLineEditDescriptionEditingFinished()
{ {
const QString &newText = lineEditDescriptionText(); 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); server.insert(config_key::description, newText);
m_settings->editServer(uiLogic()->selectedServerIndex, server); m_settings->editServer(uiLogic()->m_selectedServerIndex, server);
uiLogic()->onUpdateAllPages(); uiLogic()->onUpdateAllPages();
} }
@ -154,7 +121,7 @@ void ServerSettingsLogic::onPushButtonShareFullClicked()
auto appContext = activity.callObjectMethod( auto appContext = activity.callObjectMethod(
"getApplicationContext", "()Landroid/content/Context;"); "getApplicationContext", "()Landroid/content/Context;");
if (appContext.isValid()) { if (appContext.isValid()) {
QAndroidActivityResultReceiver *receiver = new authResultReceiver(uiLogic(), uiLogic()->selectedServerIndex); QAndroidActivityResultReceiver *receiver = new authResultReceiver(uiLogic(), uiLogic()->m_selectedServerIndex);
auto intent = QJniObject::callStaticObjectMethod( auto intent = QJniObject::callStaticObjectMethod(
"org/amnezia/vpn/AuthHelper", "getAuthIntent", "org/amnezia/vpn/AuthHelper", "getAuthIntent",
"(Landroid/content/Context;)Landroid/content/Intent;", appContext.object()); "(Landroid/content/Context;)Landroid/content/Intent;", appContext.object());
@ -163,12 +130,12 @@ void ServerSettingsLogic::onPushButtonShareFullClicked()
QtAndroidPrivate::startActivity(intent.object<jobject>(), 1, receiver); QtAndroidPrivate::startActivity(intent.object<jobject>(), 1, receiver);
} }
} else { } else {
uiLogic()->pageLogic<ShareConnectionLogic>()->updateSharingPage(uiLogic()->selectedServerIndex, DockerContainer::None); uiLogic()->pageLogic<ShareConnectionLogic>()->updateSharingPage(uiLogic()->m_selectedServerIndex, DockerContainer::None);
emit uiLogic()->goToShareProtocolPage(Proto::Any); emit uiLogic()->goToShareProtocolPage(Proto::Any);
} }
} }
#else #else
uiLogic()->pageLogic<ShareConnectionLogic>()->updateSharingPage(uiLogic()->selectedServerIndex, DockerContainer::None); uiLogic()->pageLogic<ShareConnectionLogic>()->updateSharingPage(uiLogic()->m_selectedServerIndex, DockerContainer::None);
emit uiLogic()->goToShareProtocolPage(Proto::Any); emit uiLogic()->goToShareProtocolPage(Proto::Any);
#endif #endif
} }

View file

@ -16,9 +16,7 @@ class ServerSettingsLogic : public PageLogicBase
AUTO_PROPERTY(bool, labelWaitInfoVisible) AUTO_PROPERTY(bool, labelWaitInfoVisible)
AUTO_PROPERTY(QString, labelWaitInfoText) AUTO_PROPERTY(QString, labelWaitInfoText)
AUTO_PROPERTY(QString, pushButtonClearText)
AUTO_PROPERTY(QString, pushButtonClearClientCacheText) AUTO_PROPERTY(QString, pushButtonClearClientCacheText)
AUTO_PROPERTY(bool, pushButtonClearVisible)
AUTO_PROPERTY(bool, pushButtonClearClientCacheVisible) AUTO_PROPERTY(bool, pushButtonClearClientCacheVisible)
AUTO_PROPERTY(bool, pushButtonShareFullVisible) AUTO_PROPERTY(bool, pushButtonShareFullVisible)
AUTO_PROPERTY(QString, labelServerText) AUTO_PROPERTY(QString, labelServerText)
@ -28,7 +26,6 @@ class ServerSettingsLogic : public PageLogicBase
public: public:
Q_INVOKABLE void onUpdatePage() override; Q_INVOKABLE void onUpdatePage() override;
Q_INVOKABLE void onPushButtonClearServer();
Q_INVOKABLE void onPushButtonForgetServer(); Q_INVOKABLE void onPushButtonForgetServer();
Q_INVOKABLE void onPushButtonShareFullClicked(); Q_INVOKABLE void onPushButtonShareFullClicked();
Q_INVOKABLE void onPushButtonClearClientCacheClicked(); Q_INVOKABLE void onPushButtonClearClientCacheClicked();

View file

@ -1,7 +1,6 @@
#include <QBuffer> #include <QBuffer>
#include <QImage> #include <QImage>
#include <QDataStream> #include <QDataStream>
#include <QMessageBox>
#include "qrcodegen.hpp" #include "qrcodegen.hpp"
@ -68,8 +67,8 @@ void ShareConnectionLogic::onPushButtonShareAmneziaGenerateClicked()
set_shareAmneziaQrCodeTextSeriesLength(0); set_shareAmneziaQrCodeTextSeriesLength(0);
QJsonObject serverConfig; QJsonObject serverConfig;
int serverIndex = uiLogic()->selectedServerIndex; int serverIndex = uiLogic()->m_selectedServerIndex;
DockerContainer container = uiLogic()->selectedDockerContainer; DockerContainer container = uiLogic()->m_selectedDockerContainer;
// Full access // Full access
if (shareFullAccess()) { if (shareFullAccess()) {
@ -127,8 +126,8 @@ void ShareConnectionLogic::onPushButtonShareAmneziaGenerateClicked()
void ShareConnectionLogic::onPushButtonShareOpenVpnGenerateClicked() void ShareConnectionLogic::onPushButtonShareOpenVpnGenerateClicked()
{ {
int serverIndex = uiLogic()->selectedServerIndex; int serverIndex = uiLogic()->m_selectedServerIndex;
DockerContainer container = uiLogic()->selectedDockerContainer; DockerContainer container = uiLogic()->m_selectedDockerContainer;
ServerCredentials credentials = m_settings->serverCredentials(serverIndex); ServerCredentials credentials = m_settings->serverCredentials(serverIndex);
const QJsonObject &containerConfig = m_settings->containerConfig(serverIndex, container); const QJsonObject &containerConfig = m_settings->containerConfig(serverIndex, container);
@ -142,8 +141,8 @@ void ShareConnectionLogic::onPushButtonShareOpenVpnGenerateClicked()
void ShareConnectionLogic::onPushButtonShareShadowSocksGenerateClicked() void ShareConnectionLogic::onPushButtonShareShadowSocksGenerateClicked()
{ {
int serverIndex = uiLogic()->selectedServerIndex; int serverIndex = uiLogic()->m_selectedServerIndex;
DockerContainer container = uiLogic()->selectedDockerContainer; DockerContainer container = uiLogic()->m_selectedDockerContainer;
ServerCredentials credentials = m_settings->serverCredentials(serverIndex); ServerCredentials credentials = m_settings->serverCredentials(serverIndex);
QJsonObject protoConfig = m_settings->protocolConfig(serverIndex, container, Proto::ShadowSocks); QJsonObject protoConfig = m_settings->protocolConfig(serverIndex, container, Proto::ShadowSocks);
@ -186,8 +185,8 @@ void ShareConnectionLogic::onPushButtonShareShadowSocksGenerateClicked()
void ShareConnectionLogic::onPushButtonShareCloakGenerateClicked() void ShareConnectionLogic::onPushButtonShareCloakGenerateClicked()
{ {
int serverIndex = uiLogic()->selectedServerIndex; int serverIndex = uiLogic()->m_selectedServerIndex;
DockerContainer container = uiLogic()->selectedDockerContainer; DockerContainer container = uiLogic()->m_selectedDockerContainer;
ServerCredentials credentials = m_settings->serverCredentials(serverIndex); ServerCredentials credentials = m_settings->serverCredentials(serverIndex);
QJsonObject protoConfig = m_settings->protocolConfig(serverIndex, container, Proto::Cloak); QJsonObject protoConfig = m_settings->protocolConfig(serverIndex, container, Proto::Cloak);
@ -209,8 +208,8 @@ void ShareConnectionLogic::onPushButtonShareCloakGenerateClicked()
void ShareConnectionLogic::onPushButtonShareWireGuardGenerateClicked() void ShareConnectionLogic::onPushButtonShareWireGuardGenerateClicked()
{ {
int serverIndex = uiLogic()->selectedServerIndex; int serverIndex = uiLogic()->m_selectedServerIndex;
DockerContainer container = uiLogic()->selectedDockerContainer; DockerContainer container = uiLogic()->m_selectedDockerContainer;
ServerCredentials credentials = m_settings->serverCredentials(serverIndex); ServerCredentials credentials = m_settings->serverCredentials(serverIndex);
const QJsonObject &containerConfig = m_settings->containerConfig(serverIndex, container); const QJsonObject &containerConfig = m_settings->containerConfig(serverIndex, container);
@ -218,9 +217,9 @@ void ShareConnectionLogic::onPushButtonShareWireGuardGenerateClicked()
ErrorCode e = ErrorCode::NoError; ErrorCode e = ErrorCode::NoError;
QString cfg = m_configurator->wireguardConfigurator->genWireguardConfig(credentials, container, containerConfig, &e); QString cfg = m_configurator->wireguardConfigurator->genWireguardConfig(credentials, container, containerConfig, &e);
if (e) { if (e) {
QMessageBox::warning(nullptr, APPLICATION_NAME, emit uiLogic()->showWarningMessage(tr("Error occurred while generating the config.") + "\n" +
tr("Error occurred while configuring server.") + "\n" + tr("Error message: ") + errorString(e) + "\n" +
errorString(e)); tr("See logs for details."));
return; return;
} }
cfg = m_configurator->processConfigWithExportSettings(serverIndex, container, Proto::WireGuard, cfg); cfg = m_configurator->processConfigWithExportSettings(serverIndex, container, Proto::WireGuard, cfg);
@ -236,8 +235,8 @@ void ShareConnectionLogic::onPushButtonShareWireGuardGenerateClicked()
void ShareConnectionLogic::onPushButtonShareIkev2GenerateClicked() void ShareConnectionLogic::onPushButtonShareIkev2GenerateClicked()
{ {
int serverIndex = uiLogic()->selectedServerIndex; int serverIndex = uiLogic()->m_selectedServerIndex;
DockerContainer container = uiLogic()->selectedDockerContainer; DockerContainer container = uiLogic()->m_selectedDockerContainer;
ServerCredentials credentials = m_settings->serverCredentials(serverIndex); ServerCredentials credentials = m_settings->serverCredentials(serverIndex);
Ikev2Configurator::ConnectionData connData = m_configurator->ikev2Configurator->prepareIkev2Config(credentials, container); Ikev2Configurator::ConnectionData connData = m_configurator->ikev2Configurator->prepareIkev2Config(credentials, container);
@ -259,8 +258,8 @@ void ShareConnectionLogic::onPushButtonShareIkev2GenerateClicked()
void ShareConnectionLogic::updateSharingPage(int serverIndex, DockerContainer container) void ShareConnectionLogic::updateSharingPage(int serverIndex, DockerContainer container)
{ {
uiLogic()->selectedDockerContainer = container; uiLogic()->m_selectedDockerContainer = container;
uiLogic()->selectedServerIndex = serverIndex; uiLogic()->m_selectedServerIndex = serverIndex;
set_shareFullAccess(container == DockerContainer::None); set_shareFullAccess(container == DockerContainer::None);
m_shareAmneziaQrCodeTextSeries.clear(); m_shareAmneziaQrCodeTextSeries.clear();

View file

@ -50,6 +50,5 @@ public:
QList<QString> genQrCodeImageSeries(const QByteArray &data); QList<QString> genQrCodeImageSeries(const QByteArray &data);
QString svgToBase64(const QString &image); QString svgToBase64(const QString &image);
}; };
#endif // SHARE_CONNECTION_LOGIC_H #endif // SHARE_CONNECTION_LOGIC_H

View file

@ -156,7 +156,7 @@ void StartPageLogic::onPushButtonConnect()
set_pushButtonConnectEnabled(true); set_pushButtonConnectEnabled(true);
set_pushButtonConnectText(tr("Connect")); set_pushButtonConnectText(tr("Connect"));
uiLogic()->installCredentials = serverCredentials; uiLogic()->m_installCredentials = serverCredentials;
if (ok) emit uiLogic()->goToPage(Page::NewServer); if (ok) emit uiLogic()->goToPage(Page::NewServer);
} }

View file

@ -79,8 +79,8 @@ void ViewConfigLogic::importConfig()
if (!configJson().contains(config_key::containers) || configJson().value(config_key::containers).toArray().isEmpty()) { if (!configJson().contains(config_key::containers) || configJson().value(config_key::containers).toArray().isEmpty()) {
uiLogic()->selectedServerIndex = m_settings->defaultServerIndex(); uiLogic()->m_selectedServerIndex = m_settings->defaultServerIndex();
uiLogic()->selectedDockerContainer = m_settings->defaultContainer(uiLogic()->selectedServerIndex); uiLogic()->m_selectedDockerContainer = m_settings->defaultContainer(uiLogic()->m_selectedServerIndex);
uiLogic()->onUpdateAllPages(); uiLogic()->onUpdateAllPages();
emit uiLogic()->goToPage(Page::Vpn); emit uiLogic()->goToPage(Page::Vpn);
emit uiLogic()->setStartPage(Page::Vpn); emit uiLogic()->setStartPage(Page::Vpn);

View file

@ -18,7 +18,7 @@ void WizardLogic::onUpdatePage()
set_radioButtonMediumChecked(true); set_radioButtonMediumChecked(true);
} }
QMap<DockerContainer, QJsonObject> WizardLogic::getInstallConfigsFromWizardPage() const QPair<DockerContainer, QJsonObject> WizardLogic::getInstallConfigsFromWizardPage() const
{ {
QJsonObject cloakConfig { QJsonObject cloakConfig {
{ config_key::container, ContainerProps::containerToString(DockerContainer::Cloak) }, { config_key::container, ContainerProps::containerToString(DockerContainer::Cloak) },
@ -33,27 +33,29 @@ QMap<DockerContainer, QJsonObject> WizardLogic::getInstallConfigsFromWizardPage(
{ config_key::container, ContainerProps::containerToString(DockerContainer::OpenVpn) } { config_key::container, ContainerProps::containerToString(DockerContainer::OpenVpn) }
}; };
QMap<DockerContainer, QJsonObject> containers; QPair<DockerContainer, QJsonObject> container;
DockerContainer dockerContainer;
if (radioButtonHighChecked()) { if (radioButtonHighChecked()) {
containers.insert(DockerContainer::Cloak, cloakConfig); container = {DockerContainer::Cloak, cloakConfig};
} }
if (radioButtonMediumChecked()) { if (radioButtonMediumChecked()) {
containers.insert(DockerContainer::ShadowSocks, ssConfig); container = {DockerContainer::ShadowSocks, ssConfig};
} }
if (radioButtonLowChecked()) { if (radioButtonLowChecked()) {
containers.insert(DockerContainer::OpenVpn, openVpnConfig); container = {DockerContainer::OpenVpn, openVpnConfig};
} }
return containers; return container;
} }
void WizardLogic::onPushButtonVpnModeFinishClicked() void WizardLogic::onPushButtonVpnModeFinishClicked()
{ {
auto containers = getInstallConfigsFromWizardPage(); auto container = getInstallConfigsFromWizardPage();
uiLogic()->installServer(containers); uiLogic()->installServer(container);
if (checkBoxVpnModeChecked()) { if (checkBoxVpnModeChecked()) {
m_settings->setRouteMode(Settings::VpnOnlyForwardSites); m_settings->setRouteMode(Settings::VpnOnlyForwardSites);
} else { } else {
@ -63,6 +65,6 @@ void WizardLogic::onPushButtonVpnModeFinishClicked()
void WizardLogic::onPushButtonLowFinishClicked() void WizardLogic::onPushButtonLowFinishClicked()
{ {
auto containers = getInstallConfigsFromWizardPage(); auto container = getInstallConfigsFromWizardPage();
uiLogic()->installServer(containers); uiLogic()->installServer(container);
} }

View file

@ -25,7 +25,7 @@ public:
explicit WizardLogic(UiLogic *uiLogic, QObject *parent = nullptr); explicit WizardLogic(UiLogic *uiLogic, QObject *parent = nullptr);
~WizardLogic() = default; ~WizardLogic() = default;
QMap<DockerContainer, QJsonObject> getInstallConfigsFromWizardPage() const; QPair<DockerContainer, QJsonObject> getInstallConfigsFromWizardPage() const;
}; };
#endif // WIZARD_LOGIC_H #endif // WIZARD_LOGIC_H

View file

@ -55,10 +55,10 @@ QJsonObject CloakLogic::getProtocolConfigFromPage(QJsonObject oldConfig)
void CloakLogic::onPushButtonSaveClicked() 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); 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; QJsonObject newContainerConfig = containerConfig;
newContainerConfig.insert(ProtocolProps::protoToString(Proto::Cloak), protocolConfig); newContainerConfig.insert(ProtocolProps::protoToString(Proto::Cloak), protocolConfig);
@ -113,8 +113,8 @@ void CloakLogic::onPushButtonSaveClicked()
progressBarFunc.setTextVisibleFunc(true); progressBarFunc.setTextVisibleFunc(true);
progressBarFunc.setTextFunc(QString("Configuring...")); progressBarFunc.setTextFunc(QString("Configuring..."));
ErrorCode e = uiLogic()->pageLogic<ServerConfiguringProgressLogic>()->doInstallAction([this, containerConfig, &newContainerConfig](){ ErrorCode e = uiLogic()->pageLogic<ServerConfiguringProgressLogic>()->doInstallAction([this, containerConfig, &newContainerConfig](){
return m_serverController->updateContainer(m_settings->serverCredentials(uiLogic()->selectedServerIndex), return m_serverController->updateContainer(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex),
uiLogic()->selectedDockerContainer, uiLogic()->m_selectedDockerContainer,
containerConfig, containerConfig,
newContainerConfig); newContainerConfig);
}, },
@ -123,11 +123,11 @@ void CloakLogic::onPushButtonSaveClicked()
busyInfoFuncy, cancelButtonFunc); busyInfoFuncy, cancelButtonFunc);
if (!e) { if (!e) {
m_settings->setContainerConfig(uiLogic()->selectedServerIndex, uiLogic()->selectedDockerContainer, newContainerConfig); m_settings->setContainerConfig(uiLogic()->m_selectedServerIndex, uiLogic()->m_selectedDockerContainer, newContainerConfig);
m_settings->clearLastConnectionConfig(uiLogic()->selectedServerIndex, uiLogic()->selectedDockerContainer); 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() void CloakLogic::onPushButtonCancelClicked()

View file

@ -105,10 +105,10 @@ void OpenVpnLogic::updateProtocolPage(const QJsonObject &openvpnConfig, DockerCo
void OpenVpnLogic::onPushButtonSaveClicked() 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); 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; QJsonObject newContainerConfig = containerConfig;
newContainerConfig.insert(ProtocolProps::protoToString(Proto::OpenVpn), protocolConfig); newContainerConfig.insert(ProtocolProps::protoToString(Proto::OpenVpn), protocolConfig);
@ -163,8 +163,8 @@ void OpenVpnLogic::onPushButtonSaveClicked()
progressBarFunc.setTextVisibleFunc(true); progressBarFunc.setTextVisibleFunc(true);
progressBarFunc.setTextFunc(QString("Configuring...")); progressBarFunc.setTextFunc(QString("Configuring..."));
ErrorCode e = uiLogic()->pageLogic<ServerConfiguringProgressLogic>()->doInstallAction([this, containerConfig, &newContainerConfig](){ ErrorCode e = uiLogic()->pageLogic<ServerConfiguringProgressLogic>()->doInstallAction([this, containerConfig, &newContainerConfig](){
return m_serverController->updateContainer(m_settings->serverCredentials(uiLogic()->selectedServerIndex), return m_serverController->updateContainer(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex),
uiLogic()->selectedDockerContainer, uiLogic()->m_selectedDockerContainer,
containerConfig, containerConfig,
newContainerConfig); newContainerConfig);
}, },
@ -173,10 +173,10 @@ void OpenVpnLogic::onPushButtonSaveClicked()
busyInfoFuncy, cancelButtonFunc); busyInfoFuncy, cancelButtonFunc);
if (!e) { if (!e) {
m_settings->setContainerConfig(uiLogic()->selectedServerIndex, uiLogic()->selectedDockerContainer, newContainerConfig); m_settings->setContainerConfig(uiLogic()->m_selectedServerIndex, uiLogic()->m_selectedDockerContainer, newContainerConfig);
m_settings->clearLastConnectionConfig(uiLogic()->selectedServerIndex, uiLogic()->selectedDockerContainer); 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) QJsonObject OpenVpnLogic::getProtocolConfigFromPage(QJsonObject oldConfig)

View file

@ -81,7 +81,7 @@ void OtherProtocolsLogic::onPushButtonSftpMountDriveClicked()
{ {
QString mountPath; QString mountPath;
QString cmd; QString cmd;
QString host = m_settings->serverCredentials(uiLogic()->selectedServerIndex).hostName; QString host = m_settings->serverCredentials(uiLogic()->m_selectedServerIndex).hostName;
#ifdef Q_OS_WINDOWS #ifdef Q_OS_WINDOWS

View file

@ -49,9 +49,9 @@ QJsonObject ShadowSocksLogic::getProtocolConfigFromPage(QJsonObject oldConfig)
void ShadowSocksLogic::onPushButtonSaveClicked() 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; QJsonObject newContainerConfig = containerConfig;
newContainerConfig.insert(ProtocolProps::protoToString(Proto::ShadowSocks), protocolConfig); newContainerConfig.insert(ProtocolProps::protoToString(Proto::ShadowSocks), protocolConfig);
ServerConfiguringProgressLogic::PageFunc pageFunc; ServerConfiguringProgressLogic::PageFunc pageFunc;
@ -105,8 +105,8 @@ void ShadowSocksLogic::onPushButtonSaveClicked()
progressBarFunc.setTextVisibleFunc(true); progressBarFunc.setTextVisibleFunc(true);
progressBarFunc.setTextFunc(QString("Configuring...")); progressBarFunc.setTextFunc(QString("Configuring..."));
ErrorCode e = uiLogic()->pageLogic<ServerConfiguringProgressLogic>()->doInstallAction([this, containerConfig, &newContainerConfig](){ ErrorCode e = uiLogic()->pageLogic<ServerConfiguringProgressLogic>()->doInstallAction([this, containerConfig, &newContainerConfig](){
return m_serverController->updateContainer(m_settings->serverCredentials(uiLogic()->selectedServerIndex), return m_serverController->updateContainer(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex),
uiLogic()->selectedDockerContainer, uiLogic()->m_selectedDockerContainer,
containerConfig, containerConfig,
newContainerConfig); newContainerConfig);
}, },
@ -115,10 +115,10 @@ void ShadowSocksLogic::onPushButtonSaveClicked()
busyInfoFuncy, cancelButtonFunc); busyInfoFuncy, cancelButtonFunc);
if (!e) { if (!e) {
m_settings->setContainerConfig(uiLogic()->selectedServerIndex, uiLogic()->selectedDockerContainer, newContainerConfig); m_settings->setContainerConfig(uiLogic()->m_selectedServerIndex, uiLogic()->m_selectedDockerContainer, newContainerConfig);
m_settings->clearLastConnectionConfig(uiLogic()->selectedServerIndex, uiLogic()->selectedDockerContainer); 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() void ShadowSocksLogic::onPushButtonCancelClicked()

View file

@ -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()
}
}
}
}

View file

@ -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
}
}

View file

@ -75,6 +75,7 @@ PageBase {
UiLogic.goToPage(PageEnum.ServerContainers) UiLogic.goToPage(PageEnum.ServerContainers)
} }
} }
BlueButtonType { BlueButtonType {
Layout.fillWidth: true Layout.fillWidth: true
Layout.topMargin: 10 Layout.topMargin: 10
@ -85,6 +86,16 @@ PageBase {
} }
} }
BlueButtonType {
Layout.fillWidth: true
Layout.topMargin: 10
text: qsTr("Advanced server settings")
visible: ServerSettingsLogic.pushButtonShareFullVisible //todo
onClicked: {
UiLogic.goToPage(PageEnum.AdvancedServerSettings)
}
}
BlueButtonType { BlueButtonType {
Layout.topMargin: 60 Layout.topMargin: 60
Layout.fillWidth: true Layout.fillWidth: true
@ -103,28 +114,6 @@ PageBase {
} }
} }
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()
}
}
BlueButtonType { BlueButtonType {
Layout.fillWidth: true Layout.fillWidth: true
Layout.topMargin: 10 Layout.topMargin: 10
@ -148,7 +137,6 @@ PageBase {
} }
} }
Logo { Logo {
id : logo id : logo
anchors.bottom: parent.bottom anchors.bottom: parent.bottom

View file

@ -54,12 +54,12 @@ You SHOULD set this website address to some foreign website which is not blocked
text: WizardLogic.lineEditHighWebsiteMaskingText text: WizardLogic.lineEditHighWebsiteMaskingText
onEditingFinished: { onEditingFinished: {
let _text = website_masking.text let _text = website_masking.text
_text.replace("http://", ""); _text = _text.replace("http://", "");
_text.replace("https://", ""); _text = _text.replace("https://", "");
if (!_text) { if (!_text) {
return return
} }
_text = _text.split("/").first(); _text = _text.split("/")[0];
WizardLogic.lineEditHighWebsiteMaskingText = _text WizardLogic.lineEditHighWebsiteMaskingText = _text
} }
onAccepted: { onAccepted: {

View file

@ -252,6 +252,10 @@ Window {
function onToggleLogPanel() { function onToggleLogPanel() {
drawer_log.visible = !drawer_log.visible drawer_log.visible = !drawer_log.visible
} }
function onShowWarningMessage(message) {
popupWarning.popupWarningText = message
popupWarning.open()
}
} }
MessageDialog { MessageDialog {
@ -260,12 +264,6 @@ Window {
text: qsTr("It's public key. Private key required") text: qsTr("It's public key. Private key required")
visible: false visible: false
} }
MessageDialog {
id: connectErrorDialog
title: "AmneziaVPN"
text: UiLogic.dialogConnectErrorText
visible: false
}
Drawer { Drawer {
id: drawer_log id: drawer_log
@ -375,4 +373,8 @@ Window {
} }
} }
} }
PopupWarning {
id: popupWarning
}
} }

View file

@ -10,7 +10,6 @@
#include <QJsonObject> #include <QJsonObject>
#include <QKeyEvent> #include <QKeyEvent>
#include <QMenu> #include <QMenu>
#include <QMessageBox>
#include <QMetaEnum> #include <QMetaEnum>
#include <QSysInfo> #include <QSysInfo>
#include <QThread> #include <QThread>
@ -67,6 +66,7 @@
#include "pages_logic/ViewConfigLogic.h" #include "pages_logic/ViewConfigLogic.h"
#include "pages_logic/VpnLogic.h" #include "pages_logic/VpnLogic.h"
#include "pages_logic/WizardLogic.h" #include "pages_logic/WizardLogic.h"
#include "pages_logic/AdvancedServerSettingsLogic.h"
#include "pages_logic/ClientManagementLogic.h" #include "pages_logic/ClientManagementLogic.h"
#include "pages_logic/ClientInfoLogic.h" #include "pages_logic/ClientInfoLogic.h"
@ -160,7 +160,7 @@ void UiLogic::initalizeUiLogic()
emit goToPage(Page::Start, true, false); 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("Started %1 version %2").arg(APPLICATION_NAME).arg(APP_VERSION);
qInfo().noquote() << QString("%1 (%2)").arg(QSysInfo::prettyProductName()).arg(QSysInfo::currentCpuArchitecture()); qInfo().noquote() << QString("%1 (%2)").arg(QSysInfo::prettyProductName()).arg(QSysInfo::currentCpuArchitecture());
@ -202,8 +202,8 @@ void UiLogic::keyPressEvent(Qt::Key key)
qApp->quit(); qApp->quit();
break; break;
case Qt::Key_H: case Qt::Key_H:
selectedServerIndex = m_settings->defaultServerIndex(); m_selectedServerIndex = m_settings->defaultServerIndex();
selectedDockerContainer = m_settings->defaultContainer(selectedServerIndex); m_selectedDockerContainer = m_settings->defaultContainer(m_selectedServerIndex);
//updateSharingPage(selectedServerIndex, m_settings->serverCredentials(selectedServerIndex), selectedDockerContainer); //updateSharingPage(selectedServerIndex, m_settings->serverCredentials(selectedServerIndex), selectedDockerContainer);
emit goToPage(Page::ShareConnection); emit goToPage(Page::ShareConnection);
@ -217,7 +217,7 @@ void UiLogic::keyPressEvent(Qt::Key key)
emit goToPage(Page::Start); emit goToPage(Page::Start);
break; break;
case Qt::Key_S: case Qt::Key_S:
selectedServerIndex = m_settings->defaultServerIndex(); m_selectedServerIndex = m_settings->defaultServerIndex();
emit goToPage(Page::ServerSettings); emit goToPage(Page::ServerSettings);
break; break;
case Qt::Key_P: case Qt::Key_P:
@ -265,15 +265,13 @@ QString UiLogic::containerDesc(int container)
void UiLogic::onGotoCurrentProtocolsPage() void UiLogic::onGotoCurrentProtocolsPage()
{ {
selectedServerIndex = m_settings->defaultServerIndex(); m_selectedServerIndex = m_settings->defaultServerIndex();
selectedDockerContainer = m_settings->defaultContainer(selectedServerIndex); m_selectedDockerContainer = m_settings->defaultContainer(m_selectedServerIndex);
emit goToPage(Page::ServerContainers); 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); emit goToPage(Page::ServerConfiguringProgress);
QEventLoop loop; QEventLoop loop;
QTimer::singleShot(500, &loop, SLOT(quit())); QTimer::singleShot(500, &loop, SLOT(quit()));
@ -328,43 +326,55 @@ void UiLogic::installServer(QMap<DockerContainer, QJsonObject> &containers)
pageLogic<ServerConfiguringProgressLogic>()->set_pushButtonCancelVisible(visible); pageLogic<ServerConfiguringProgressLogic>()->set_pushButtonCancelVisible(visible);
}; };
int count = 0; bool isServerCreated = false;
ErrorCode error; ErrorCode errorCode = addAlreadyInstalledContainersGui(true, isServerCreated);
for (QMap<DockerContainer, QJsonObject>::iterator i = containers.begin(); i != containers.end(); i++, count++) { if (errorCode == ErrorCode::NoError) {
progressBarFunc.setTextFunc(QString("Installing %1 %2 %3").arg(count+1).arg(tr("of")).arg(containers.size())); 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([&] () { if (errorCode == ErrorCode::NoError) {
return m_serverController->setupContainer(installCredentials, i.key(), i.value()); if (!isServerCreated) {
}, pageFunc, progressBarFunc, noButton, waitInfoFunc, busyInfoFunc, cancelButtonFunc); 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) { m_settings->addServer(server);
QJsonObject server; m_settings->setDefaultServer(m_settings->serversCount() - 1);
server.insert(config_key::hostName, installCredentials.hostName); } else {
server.insert(config_key::userName, installCredentials.userName); m_settings->setContainerConfig(m_settings->serversCount() - 1, container.first, container.second);
server.insert(config_key::password, installCredentials.password); m_settings->setDefaultContainer(m_settings->serversCount() - 1, container.first);
server.insert(config_key::port, installCredentials.port); }
server.insert(config_key::description, m_settings->nextAvailableServerName()); onUpdateAllPages();
QJsonArray containerConfigs; emit setStartPage(Page::Vpn);
for (const QJsonObject &cfg : containers) { qApp->processEvents();
containerConfigs.append(cfg); 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) PageProtocolLogicBase *UiLogic::protocolLogic(Proto p)
@ -502,4 +512,72 @@ void UiLogic::registerPagesLogic()
registerPageLogic<WizardLogic>(); registerPageLogic<WizardLogic>();
registerPageLogic<ClientManagementLogic>(); registerPageLogic<ClientManagementLogic>();
registerPageLogic<ClientInfoLogic>(); registerPageLogic<ClientInfoLogic>();
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;
} }

View file

@ -45,6 +45,7 @@ class VpnLogic;
class WizardLogic; class WizardLogic;
class ClientManagementLogic; class ClientManagementLogic;
class ClientInfoLogic; class ClientInfoLogic;
class AdvancedServerSettingsLogic;
class PageProtocolLogicBase; class PageProtocolLogicBase;
class OpenVpnLogic; class OpenVpnLogic;
@ -55,6 +56,7 @@ class OtherProtocolsLogic;
class VpnConnection; class VpnConnection;
class CreateServerTest;
class UiLogic : public QObject class UiLogic : public QObject
{ {
@ -63,7 +65,7 @@ class UiLogic : public QObject
AUTO_PROPERTY(bool, pageEnabled) AUTO_PROPERTY(bool, pageEnabled)
AUTO_PROPERTY(int, pagesStackDepth) AUTO_PROPERTY(int, pagesStackDepth)
AUTO_PROPERTY(int, currentPageValue) AUTO_PROPERTY(int, currentPageValue)
AUTO_PROPERTY(QString, dialogConnectErrorText) AUTO_PROPERTY(QString, popupWarningText)
READONLY_PROPERTY(QObject *, containersModel) READONLY_PROPERTY(QObject *, containersModel)
READONLY_PROPERTY(QObject *, protocolsModel) READONLY_PROPERTY(QObject *, protocolsModel)
@ -93,6 +95,7 @@ public:
friend class WizardLogic; friend class WizardLogic;
friend class ClientManagementLogic; friend class ClientManagementLogic;
friend class ClientInfoLogic; friend class ClientInfoLogic;
friend class AdvancedServerSettingsLogic;
friend class PageProtocolLogicBase; friend class PageProtocolLogicBase;
friend class OpenVpnLogic; friend class OpenVpnLogic;
@ -101,6 +104,8 @@ public:
friend class OtherProtocolsLogic; friend class OtherProtocolsLogic;
friend class CreateServerTest;
Q_INVOKABLE virtual void onUpdatePage() {} // UiLogic is set as logic class for some qml pages Q_INVOKABLE virtual void onUpdatePage() {} // UiLogic is set as logic class for some qml pages
Q_INVOKABLE void onUpdateAllPages(); Q_INVOKABLE void onUpdateAllPages();
@ -118,11 +123,11 @@ public:
Q_INVOKABLE void saveBinaryFile(const QString& desc, QString ext, const QString& data); Q_INVOKABLE void saveBinaryFile(const QString& desc, QString ext, const QString& data);
Q_INVOKABLE void copyToClipboard(const QString& text); 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); void shareTempFile(const QString &suggestedName, QString ext, const QString& data);
signals: signals:
void dialogConnectErrorTextChanged();
void goToPage(PageEnumNS::Page page, bool reset = true, bool slide = true); void goToPage(PageEnumNS::Page page, bool reset = true, bool slide = true);
void goToProtocolPage(Proto protocol, 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); void goToShareProtocolPage(Proto protocol, bool reset = true, bool slide = true);
@ -136,13 +141,15 @@ signals:
void hide(); void hide();
void raise(); void raise();
void toggleLogPanel(); void toggleLogPanel();
void showWarningMessage(QString message);
private slots: private slots:
// containers - INOUT arg // containers - INOUT arg
void installServer(QMap<DockerContainer, QJsonObject> &containers); void installServer(QPair<amnezia::DockerContainer, QJsonObject> &container);
private: private:
PageEnumNS::Page currentPage(); PageEnumNS::Page currentPage();
bool isContainerAlreadyAddedToGui(DockerContainer container);
public: public:
Q_INVOKABLE PageProtocolLogicBase *protocolLogic(Proto p); Q_INVOKABLE PageProtocolLogicBase *protocolLogic(Proto p);
@ -185,8 +192,8 @@ private:
NotificationHandler* m_notificationHandler; NotificationHandler* m_notificationHandler;
int selectedServerIndex = -1; // server index to use when proto settings page opened int m_selectedServerIndex = -1; // server index to use when proto settings page opened
DockerContainer selectedDockerContainer; // same DockerContainer m_selectedDockerContainer; // same
ServerCredentials installCredentials; // used to save cred between pages new_server and new_server_protocols and wizard ServerCredentials m_installCredentials; // used to save cred between pages new_server and new_server_protocols and wizard
}; };
#endif // UILOGIC_H #endif // UILOGIC_H

View file

@ -105,8 +105,8 @@ void VpnConnection::onConnectionStateChanged(VpnProtocol::VpnConnectionState sta
} }
else { else {
m_isIOSConnected = false; m_isIOSConnected = false;
m_receivedBytes = 0; // m_receivedBytes = 0;
m_sentBytes = 0; // m_sentBytes = 0;
} }
#endif #endif
emit connectionStateChanged(state); emit connectionStateChanged(state);