Release 1.6 WIP
This commit is contained in:
parent
f9affb083b
commit
a5e9cea22f
29 changed files with 2046 additions and 136 deletions
|
@ -31,6 +31,7 @@ HEADERS += \
|
|||
ui/Controls/SlidingStackedWidget.h \
|
||||
ui/mainwindow.h \
|
||||
ui/qautostart.h \
|
||||
ui/server_widget.h \
|
||||
utils.h \
|
||||
vpnconnection.h \
|
||||
protocols/vpnprotocol.h \
|
||||
|
@ -52,12 +53,14 @@ SOURCES += \
|
|||
ui/Controls/SlidingStackedWidget.cpp \
|
||||
ui/mainwindow.cpp \
|
||||
ui/qautostart.cpp \
|
||||
ui/server_widget.cpp \
|
||||
utils.cpp \
|
||||
vpnconnection.cpp \
|
||||
protocols/vpnprotocol.cpp \
|
||||
protocols/openvpnprotocol.cpp \
|
||||
|
||||
FORMS += ui/mainwindow.ui
|
||||
FORMS += ui/mainwindow.ui \
|
||||
ui/server_widget.ui
|
||||
|
||||
RESOURCES += \
|
||||
resources.qrc
|
||||
|
|
|
@ -215,7 +215,7 @@ QString OpenVpnConfigurator::genOpenVpnConfig(const ServerCredentials &credentia
|
|||
|
||||
if (proto == Protocol::OpenVpn)
|
||||
config.replace("$PROTO", "udp");
|
||||
else if (proto == Protocol::ShadowSocks) {
|
||||
else if (proto == Protocol::ShadowSocksOverOpenVpn) {
|
||||
config.replace("$PROTO", "tcp");
|
||||
config.replace("$LOCAL_PROXY_PORT", QString::number(amnezia::protocols::shadowsocks::ssContainerPort()));
|
||||
}
|
||||
|
|
|
@ -1,25 +1,48 @@
|
|||
#ifndef DEFS_H
|
||||
#define DEFS_H
|
||||
|
||||
#include <QMetaEnum>
|
||||
#include <QObject>
|
||||
|
||||
namespace amnezia {
|
||||
Q_NAMESPACE
|
||||
|
||||
enum class Protocol {
|
||||
Any,
|
||||
OpenVpn,
|
||||
ShadowSocks,
|
||||
ShadowSocksOverOpenVpn,
|
||||
OpenVpnOverCloak,
|
||||
WireGuard
|
||||
};
|
||||
Q_ENUM_NS(Protocol)
|
||||
|
||||
inline Protocol protoFromString(QString proto){
|
||||
auto&& metaEnum = QMetaEnum::fromType<Protocol>();
|
||||
return static_cast<Protocol>(metaEnum.keyToValue(proto.toStdString().c_str()));
|
||||
}
|
||||
|
||||
inline QString protoToString(Protocol proto){
|
||||
return QVariant::fromValue(proto).toString();
|
||||
}
|
||||
|
||||
|
||||
enum class DockerContainer {
|
||||
None,
|
||||
OpenVpn,
|
||||
ShadowSocks,
|
||||
ShadowSocksOverOpenVpn,
|
||||
OpenVpnOverCloak,
|
||||
WireGuard
|
||||
};
|
||||
Q_ENUM_NS(DockerContainer)
|
||||
|
||||
inline DockerContainer containerFromString(QString container){
|
||||
auto&& metaEnum = QMetaEnum::fromType<DockerContainer>();
|
||||
return static_cast<DockerContainer>(metaEnum.keyToValue(container.toStdString().c_str()));
|
||||
}
|
||||
|
||||
inline QString containerToString(DockerContainer container){
|
||||
return QVariant::fromValue(container).toString();
|
||||
}
|
||||
|
||||
static DockerContainer containerForProto(Protocol proto)
|
||||
{
|
||||
|
@ -28,7 +51,7 @@ static DockerContainer containerForProto(Protocol proto)
|
|||
switch (proto) {
|
||||
case Protocol::OpenVpn: return DockerContainer::OpenVpn;
|
||||
case Protocol::OpenVpnOverCloak: return DockerContainer::OpenVpnOverCloak;
|
||||
case Protocol::ShadowSocks: return DockerContainer::ShadowSocks;
|
||||
case Protocol::ShadowSocksOverOpenVpn: return DockerContainer::ShadowSocksOverOpenVpn;
|
||||
case Protocol::WireGuard: return DockerContainer::WireGuard;
|
||||
case Protocol::Any: return DockerContainer::None;
|
||||
}
|
||||
|
@ -91,10 +114,10 @@ enum ErrorCode
|
|||
|
||||
namespace config {
|
||||
// config keys
|
||||
static QString key_openvpn_config_data() { return "openvpn_config_data"; }
|
||||
static QString key_openvpn_config_path() { return "openvpn_config_path"; }
|
||||
static QString key_shadowsocks_config_data() { return "shadowsocks_config_data"; }
|
||||
static QString key_cloak_config_data() { return "cloak_config_data"; }
|
||||
const char key_openvpn_config_data[] = "openvpn_config_data";
|
||||
const char key_openvpn_config_path[] = "openvpn_config_path";
|
||||
const char key_shadowsocks_config_data[] = "shadowsocks_config_data";
|
||||
const char key_cloak_config_data[] = "cloak_config_data";
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ QString amnezia::scriptFolder(amnezia::Protocol proto)
|
|||
switch (proto) {
|
||||
case Protocol::OpenVpn: return QLatin1String("openvpn");
|
||||
case Protocol::OpenVpnOverCloak: return QLatin1String("openvpn_cloak");
|
||||
case Protocol::ShadowSocks: return QLatin1String("openvpn_shadowsocks");
|
||||
case Protocol::ShadowSocksOverOpenVpn: return QLatin1String("openvpn_shadowsocks");
|
||||
case Protocol::WireGuard: return QLatin1String("wireguard");
|
||||
default: return "";
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ QString amnezia::server::getContainerName(amnezia::DockerContainer container)
|
|||
switch (container) {
|
||||
case(DockerContainer::OpenVpn): return "amnezia-openvpn";
|
||||
case(DockerContainer::OpenVpnOverCloak): return "amnezia-openvpn-cloak";
|
||||
case(DockerContainer::ShadowSocks): return "amnezia-shadowsocks";
|
||||
case(DockerContainer::ShadowSocksOverOpenVpn): return "amnezia-shadowsocks";
|
||||
default: return "";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,9 +9,9 @@ namespace server {
|
|||
QString getContainerName(amnezia::DockerContainer container);
|
||||
QString getDockerfileFolder(amnezia::DockerContainer container);
|
||||
|
||||
static QString vpnDefaultSubnetIp() { return "10.8.0.0"; }
|
||||
static QString vpnDefaultSubnetMask() { return "255.255.255.0"; }
|
||||
static QString vpnDefaultSubnetMaskVal() { return "24"; }
|
||||
const char vpnDefaultSubnetIp[] = "10.8.0.0";
|
||||
const char vpnDefaultSubnetMask[] = "255.255.255.0";
|
||||
const char vpnDefaultSubnetMaskVal[] = "24";
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -392,15 +392,15 @@ ErrorCode ServerController::removeServer(const ServerCredentials &credentials, P
|
|||
if (e) {
|
||||
return e;
|
||||
}
|
||||
return removeServer(credentials, Protocol::ShadowSocks);
|
||||
return removeServer(credentials, Protocol::ShadowSocksOverOpenVpn);
|
||||
}
|
||||
else if (proto == Protocol::OpenVpn) {
|
||||
scriptFileName = ":/server_scripts/remove_container.sh";
|
||||
container = DockerContainer::OpenVpn;
|
||||
}
|
||||
else if (proto == Protocol::ShadowSocks) {
|
||||
else if (proto == Protocol::ShadowSocksOverOpenVpn) {
|
||||
scriptFileName = ":/server_scripts/remove_container.sh";
|
||||
container = DockerContainer::ShadowSocks;
|
||||
container = DockerContainer::ShadowSocksOverOpenVpn;
|
||||
}
|
||||
else return ErrorCode::NotImplementedError;
|
||||
|
||||
|
@ -427,7 +427,7 @@ ErrorCode ServerController::setupServer(const ServerCredentials &credentials, Pr
|
|||
return ErrorCode::NoError;
|
||||
//return setupOpenVpnServer(credentials);
|
||||
}
|
||||
else if (proto == Protocol::ShadowSocks) {
|
||||
else if (proto == Protocol::ShadowSocksOverOpenVpn) {
|
||||
return setupShadowSocksServer(credentials);
|
||||
}
|
||||
else if (proto == Protocol::Any) {
|
||||
|
@ -586,9 +586,9 @@ ServerController::Vars ServerController::genVarsForScript(const ServerCredential
|
|||
{
|
||||
Vars vars;
|
||||
|
||||
vars.append(qMakePair<QString, QString>("$VPN_SUBNET_IP", amnezia::server::vpnDefaultSubnetIp()));
|
||||
vars.append(qMakePair<QString, QString>("$VPN_SUBNET_MASK_VAL", amnezia::server::vpnDefaultSubnetMaskVal()));
|
||||
vars.append(qMakePair<QString, QString>("$VPN_SUBNET_MASK", amnezia::server::vpnDefaultSubnetMask()));
|
||||
vars.append(qMakePair<QString, QString>("$VPN_SUBNET_IP", amnezia::server::vpnDefaultSubnetIp));
|
||||
vars.append(qMakePair<QString, QString>("$VPN_SUBNET_MASK_VAL", amnezia::server::vpnDefaultSubnetMaskVal));
|
||||
vars.append(qMakePair<QString, QString>("$VPN_SUBNET_MASK", amnezia::server::vpnDefaultSubnetMask));
|
||||
|
||||
vars.append(qMakePair<QString, QString>("$CONTAINER_NAME", amnezia::server::getContainerName(container)));
|
||||
vars.append(qMakePair<QString, QString>("$DOCKERFILE_FOLDER", "/opt/amnezia/" + amnezia::server::getContainerName(container)));
|
||||
|
@ -610,7 +610,7 @@ ServerController::Vars ServerController::genVarsForScript(const ServerCredential
|
|||
vars.append(qMakePair<QString, QString>("$SERVER_PORT", amnezia::protocols::cloak::ckDefaultPort()));
|
||||
vars.append(qMakePair<QString, QString>("$FAKE_WEB_SITE_ADDRESS", amnezia::protocols::cloak::ckDefaultRedirSite()));
|
||||
}
|
||||
else if (container == DockerContainer::ShadowSocks) {
|
||||
else if (container == DockerContainer::ShadowSocksOverOpenVpn) {
|
||||
vars.append(qMakePair<QString, QString>("$SERVER_PORT", "6789"));
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,6 @@
|
|||
#define APPLICATION_NAME "AmneziaVPN"
|
||||
#define SERVICE_NAME "AmneziaVPN-service"
|
||||
#define ORGANIZATION_NAME "AmneziaVPN.ORG"
|
||||
#define APP_VERSION "1.0.0.0"
|
||||
#define APP_VERSION "1.6.0.0"
|
||||
|
||||
#endif // DEFINES_H
|
||||
|
|
BIN
client/images/check.png
Normal file
BIN
client/images/check.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 13 KiB |
BIN
client/images/plus.png
Normal file
BIN
client/images/plus.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 215 B |
Binary file not shown.
Before Width: | Height: | Size: 871 B After Width: | Height: | Size: 846 B |
BIN
client/images/settings_grey.png
Normal file
BIN
client/images/settings_grey.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 871 B |
BIN
client/images/uncheck.png
Normal file
BIN
client/images/uncheck.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 10 KiB |
|
@ -101,5 +101,5 @@ QString OpenVpnOverCloakProtocol::cloakExecPath()
|
|||
|
||||
void OpenVpnOverCloakProtocol::readCloakConfiguration(const QJsonObject &configuration)
|
||||
{
|
||||
m_cloakConfig = configuration.value(config::key_cloak_config_data()).toObject();
|
||||
m_cloakConfig = configuration.value(config::key_cloak_config_data).toObject();
|
||||
}
|
||||
|
|
|
@ -68,16 +68,16 @@ void OpenVpnProtocol::killOpenVpnProcess()
|
|||
|
||||
void OpenVpnProtocol::readOpenVpnConfiguration(const QJsonObject &configuration)
|
||||
{
|
||||
if (configuration.contains(config::key_openvpn_config_data())) {
|
||||
if (configuration.contains(config::key_openvpn_config_data)) {
|
||||
m_configFile.open();
|
||||
m_configFile.write(configuration.value(config::key_openvpn_config_data()).toString().toUtf8());
|
||||
m_configFile.write(configuration.value(config::key_openvpn_config_data).toString().toUtf8());
|
||||
m_configFile.close();
|
||||
m_configFileName = m_configFile.fileName();
|
||||
|
||||
qDebug().noquote() << QString("Set config data") << m_configFileName;
|
||||
}
|
||||
else if (configuration.contains(config::key_openvpn_config_path())) {
|
||||
m_configFileName = configuration.value(config::key_openvpn_config_path()).toString();
|
||||
else if (configuration.contains(config::key_openvpn_config_path)) {
|
||||
m_configFileName = configuration.value(config::key_openvpn_config_path).toString();
|
||||
QFileInfo file(m_configFileName);
|
||||
|
||||
if (file.fileName().isEmpty()) {
|
||||
|
|
|
@ -110,5 +110,5 @@ QJsonObject ShadowSocksVpnProtocol::genShadowSocksConfig(const ServerCredentials
|
|||
|
||||
void ShadowSocksVpnProtocol::readShadowSocksConfiguration(const QJsonObject &configuration)
|
||||
{
|
||||
m_shadowSocksConfig = configuration.value(config::key_shadowsocks_config_data()).toObject();
|
||||
m_shadowSocksConfig = configuration.value(config::key_shadowsocks_config_data).toObject();
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ public:
|
|||
ErrorCode start() override;
|
||||
void stop() override;
|
||||
|
||||
static QJsonObject genShadowSocksConfig(const ServerCredentials &credentials, Protocol proto = Protocol::ShadowSocks);
|
||||
static QJsonObject genShadowSocksConfig(const ServerCredentials &credentials, Protocol proto = Protocol::ShadowSocksOverOpenVpn);
|
||||
|
||||
protected:
|
||||
void readShadowSocksConfiguration(const QJsonObject &configuration);
|
||||
|
|
|
@ -48,5 +48,9 @@
|
|||
<file>server_scripts/install_docker.sh</file>
|
||||
<file>server_scripts/build_container.sh</file>
|
||||
<file>server_scripts/prepare_host.sh</file>
|
||||
<file>images/check.png</file>
|
||||
<file>images/uncheck.png</file>
|
||||
<file>images/settings_grey.png</file>
|
||||
<file>images/plus.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
|
@ -1,33 +1,116 @@
|
|||
|
||||
#include "defines.h"
|
||||
#include "settings.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
Settings::Settings(QObject* parent) :
|
||||
QObject(parent),
|
||||
m_settings (ORGANIZATION_NAME, APPLICATION_NAME, this)
|
||||
{
|
||||
// Import old settings
|
||||
if (serversCount() == 0) {
|
||||
QString user = m_settings.value("Server/userName").toString();
|
||||
QString password = m_settings.value("Server/password").toString();
|
||||
QString serverName = m_settings.value("Server/serverName").toString();
|
||||
int port = m_settings.value("Server/serverPort").toInt();
|
||||
|
||||
if (!user.isEmpty() && !password.isEmpty() && !serverName.isEmpty()){
|
||||
QJsonObject server;
|
||||
server.insert(userNameString, user);
|
||||
server.insert(passwordString, password);
|
||||
server.insert(hostNameString, serverName);
|
||||
server.insert(portString, port);
|
||||
server.insert(descriptionString, tr("Server #1"));
|
||||
|
||||
addServer(server);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int Settings::serversCount() const
|
||||
{
|
||||
return serversArray().size();
|
||||
}
|
||||
|
||||
QJsonObject Settings::server(int index) const
|
||||
{
|
||||
const QJsonArray &servers = serversArray();
|
||||
if (index >= servers.size()) return QJsonObject();
|
||||
|
||||
return servers.at(index).toObject();
|
||||
}
|
||||
|
||||
void Settings::addServer(const QJsonObject &server)
|
||||
{
|
||||
QJsonArray servers = serversArray();
|
||||
servers.append(server);
|
||||
setServersArray(servers);
|
||||
}
|
||||
|
||||
void Settings::removeServer(int index)
|
||||
{
|
||||
QJsonArray servers = serversArray();
|
||||
if (index >= servers.size()) return;
|
||||
|
||||
servers.removeAt(index);
|
||||
setServersArray(servers);
|
||||
}
|
||||
|
||||
bool Settings::editServer(int index, const QJsonObject &server)
|
||||
{
|
||||
QJsonArray servers = serversArray();
|
||||
if (index >= servers.size()) return false;
|
||||
|
||||
servers.replace(index, server);
|
||||
setServersArray(servers);
|
||||
return true;
|
||||
}
|
||||
|
||||
void Settings::setDefaultContainer(int serverIndex, DockerContainer container)
|
||||
{
|
||||
QJsonObject s = server(serverIndex);
|
||||
s.insert(defaultContainerString, containerToString(container));
|
||||
editServer(serverIndex, s);
|
||||
}
|
||||
|
||||
DockerContainer Settings::defaultContainer(int serverIndex) const
|
||||
{
|
||||
return containerFromString(defaultContainerName(serverIndex));
|
||||
}
|
||||
|
||||
QString Settings::defaultContainerName(int serverIndex) const
|
||||
{
|
||||
QString name = server(serverIndex).value(defaultContainerString).toString();
|
||||
if (name.isEmpty()) {
|
||||
return containerToString(DockerContainer::OpenVpnOverCloak);
|
||||
}
|
||||
else return name;
|
||||
}
|
||||
|
||||
bool Settings::haveAuthData() const
|
||||
{
|
||||
return (!serverName().isEmpty() && !userName().isEmpty() && !password().isEmpty());
|
||||
ServerCredentials cred = defaultServerCredentials();
|
||||
|
||||
return (!cred.hostName.isEmpty() && !cred.userName.isEmpty() && !cred.password.isEmpty());
|
||||
}
|
||||
|
||||
void Settings::setServerCredentials(const ServerCredentials &credentials)
|
||||
{
|
||||
setServerName(credentials.hostName);
|
||||
setServerPort(credentials.port);
|
||||
setUserName(credentials.userName);
|
||||
setPassword(credentials.password);
|
||||
}
|
||||
//void Settings::setServerCredentials(const ServerCredentials &credentials)
|
||||
//{
|
||||
// setServerName(credentials.hostName);
|
||||
// setServerPort(credentials.port);
|
||||
// setUserName(credentials.userName);
|
||||
// setPassword(credentials.password);
|
||||
//}
|
||||
|
||||
ServerCredentials Settings::serverCredentials()
|
||||
ServerCredentials Settings::defaultServerCredentials() const
|
||||
{
|
||||
const QJsonObject &s = defaultServer();
|
||||
|
||||
ServerCredentials credentials;
|
||||
credentials.hostName = serverName();
|
||||
credentials.userName = userName();
|
||||
credentials.password = password();
|
||||
credentials.port = serverPort();
|
||||
credentials.hostName = s.value(hostNameString).toString();
|
||||
credentials.userName = s.value(userNameString).toString();
|
||||
credentials.password = s.value(passwordString).toString();
|
||||
credentials.port = s.value(portString).toInt();
|
||||
|
||||
return credentials;
|
||||
}
|
||||
|
|
|
@ -5,6 +5,10 @@
|
|||
#include <QString>
|
||||
#include <QSettings>
|
||||
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "core/defs.h"
|
||||
|
||||
using namespace amnezia;
|
||||
|
@ -18,22 +22,43 @@ class Settings : public QObject
|
|||
public:
|
||||
explicit Settings(QObject* parent = nullptr);
|
||||
|
||||
QString userName() const { return m_settings.value("Server/userName", QString()).toString(); }
|
||||
void setUserName(const QString& login) { m_settings.setValue("Server/userName", login); }
|
||||
|
||||
QString password() const { return m_settings.value("Server/password", QString()).toString(); }
|
||||
void setPassword(const QString& password) { m_settings.setValue("Server/password", password); }
|
||||
// QString userName() const { return m_settings.value("Server/userName", QString()).toString(); }
|
||||
// void setUserName(const QString& login) { m_settings.setValue("Server/userName", login); }
|
||||
|
||||
QString serverName() const { return m_settings.value("Server/serverName", QString()).toString(); }
|
||||
void setServerName(const QString& serverName) { m_settings.setValue("Server/serverName", serverName); }
|
||||
// QString password() const { return m_settings.value("Server/password", QString()).toString(); }
|
||||
// void setPassword(const QString& password) { m_settings.setValue("Server/password", password); }
|
||||
|
||||
int serverPort() const { return m_settings.value("Server/serverPort", 22).toInt(); }
|
||||
void setServerPort(int serverPort = 22) { m_settings.setValue("Server/serverPort", serverPort); }
|
||||
// QString serverName() const { return m_settings.value("Server/serverName", QString()).toString(); }
|
||||
// void setServerName(const QString& serverName) { m_settings.setValue("Server/serverName", serverName); }
|
||||
|
||||
// int serverPort() const { return m_settings.value("Server/serverPort", 22).toInt(); }
|
||||
// void setServerPort(int serverPort = 22) { m_settings.setValue("Server/serverPort", serverPort); }
|
||||
|
||||
ServerCredentials defaultServerCredentials() const;
|
||||
//void setServerCredentials(const ServerCredentials &credentials);
|
||||
|
||||
QJsonArray serversArray() const {return QJsonDocument::fromJson(m_settings.value("Servers/serversList").toByteArray()).array(); }
|
||||
void setServersArray(const QJsonArray &servers) { m_settings.setValue("Servers/serversList", QJsonDocument(servers).toJson()); }
|
||||
|
||||
// Servers section
|
||||
int serversCount() const;
|
||||
QJsonObject server(int index) const;
|
||||
void addServer(const QJsonObject &server);
|
||||
void removeServer(int index);
|
||||
bool editServer(int index, const QJsonObject &server);
|
||||
|
||||
int defaultServerIndex() const { return m_settings.value("Servers/defaultServerIndex", 0).toInt(); }
|
||||
void setDefaultServer(int index) { m_settings.setValue("Servers/defaultServerIndex", index); }
|
||||
QJsonObject defaultServer() const { return server(defaultServerIndex()); }
|
||||
|
||||
void setDefaultContainer(int serverIndex, DockerContainer container );
|
||||
DockerContainer defaultContainer(int serverIndex) const;
|
||||
QString defaultContainerName(int serverIndex) const;
|
||||
|
||||
ServerCredentials serverCredentials();
|
||||
void setServerCredentials(const ServerCredentials &credentials);
|
||||
bool haveAuthData() const;
|
||||
|
||||
// App settings section
|
||||
bool isAutoConnect() const { return m_settings.value("Conf/autoConnect", QString()).toBool(); }
|
||||
void setAutoConnect(bool enabled) { m_settings.setValue("Conf/autoConnect", enabled); }
|
||||
|
||||
|
@ -48,8 +73,8 @@ public:
|
|||
QStringList customIps() { return m_settings.value("Conf/customIps").toStringList(); }
|
||||
void setCustomIps(const QStringList &customIps) { m_settings.setValue("Conf/customIps", customIps); }
|
||||
|
||||
QString primaryDns() const { return m_settings.value("Conf/primaryDns", cloudFlareNs1()).toString(); }
|
||||
QString secondaryDns() const { return m_settings.value("Conf/secondaryDns", cloudFlareNs2()).toString(); }
|
||||
QString primaryDns() const { return m_settings.value("Conf/primaryDns", cloudFlareNs1).toString(); }
|
||||
QString secondaryDns() const { return m_settings.value("Conf/secondaryDns", cloudFlareNs2).toString(); }
|
||||
|
||||
//QString primaryDns() const { return m_primaryDns; }
|
||||
void setPrimaryDns(const QString &primaryDns) { m_settings.setValue("Conf/primaryDns", primaryDns); }
|
||||
|
@ -57,14 +82,29 @@ public:
|
|||
//QString secondaryDns() const { return m_secondaryDns; }
|
||||
void setSecondaryDns(const QString &secondaryDns) { m_settings.setValue("Conf/secondaryDns", secondaryDns); }
|
||||
|
||||
QString cloudFlareNs1() const { return "1.1.1.1"; }
|
||||
QString cloudFlareNs2() const { return "1.0.0.1"; }
|
||||
static constexpr char cloudFlareNs1[] = "1.1.1.1";
|
||||
static constexpr char cloudFlareNs2[] = "1.0.0.1";
|
||||
|
||||
static constexpr char openNicNs5[] = "94.103.153.176";
|
||||
static constexpr char openNicNs13[] = "144.76.103.143";
|
||||
|
||||
|
||||
public:
|
||||
// Json strings
|
||||
static constexpr char hostNameString[] = "hostName";
|
||||
static constexpr char userNameString[] = "userName";
|
||||
static constexpr char passwordString[] = "password";
|
||||
static constexpr char portString[] = "port";
|
||||
static constexpr char descriptionString[] = "description";
|
||||
|
||||
static constexpr char defaultContainerString[] = "defaultContainer";
|
||||
|
||||
QString openNicNs5() const { return "94.103.153.176"; }
|
||||
QString openNicNs13() const { return "144.76.103.143"; }
|
||||
|
||||
private:
|
||||
QSettings m_settings;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // SETTINGS_H
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include "SlidingStackedWidget.h"
|
||||
|
||||
#include <QEventLoop>
|
||||
|
||||
SlidingStackedWidget::SlidingStackedWidget(QWidget *parent)
|
||||
: QStackedWidget(parent)
|
||||
{
|
||||
|
@ -28,6 +30,14 @@ SlidingStackedWidget::SlidingStackedWidget(QWidget *parent)
|
|||
m_wrap = false;
|
||||
m_pnow = QPoint(0,0);
|
||||
m_active = false;
|
||||
|
||||
animnow = new QPropertyAnimation();
|
||||
animnext = new QPropertyAnimation();
|
||||
|
||||
animgroup = new QParallelAnimationGroup;
|
||||
|
||||
animgroup->addAnimation(animnow);
|
||||
animgroup->addAnimation(animnext);
|
||||
}
|
||||
|
||||
SlidingStackedWidget::~SlidingStackedWidget() {
|
||||
|
@ -90,6 +100,21 @@ void SlidingStackedWidget::slideInWidget(QWidget *widget, SlidingStackedWidget::
|
|||
#endif
|
||||
}
|
||||
|
||||
bool SlidingStackedWidget::isAnimationRunning()
|
||||
{
|
||||
return animgroup->state() == QAnimationGroup::Running;
|
||||
}
|
||||
|
||||
void SlidingStackedWidget::waitForAnimation()
|
||||
{
|
||||
if (!isAnimationRunning()) return;
|
||||
|
||||
qDebug() << "Wait for stacked widget animation";
|
||||
QEventLoop l;
|
||||
connect(animgroup, &QParallelAnimationGroup::finished, &l, &QEventLoop::quit);
|
||||
l.exec();
|
||||
}
|
||||
|
||||
void SlidingStackedWidget::slideInWgtImpl(QWidget * newwidget, enum t_direction direction) {
|
||||
if (m_active) {
|
||||
return;
|
||||
|
@ -149,22 +174,28 @@ void SlidingStackedWidget::slideInWgtImpl(QWidget * newwidget, enum t_direction
|
|||
widget(next)->raise();
|
||||
|
||||
// animate both, the now and next widget to the side, using animation framework
|
||||
QPropertyAnimation *animnow = new QPropertyAnimation(widget(now), "pos");
|
||||
//QPropertyAnimation *animnow = new QPropertyAnimation(widget(now), "pos");
|
||||
animnow->setTargetObject(widget(now));
|
||||
animnow->setPropertyName("pos");
|
||||
|
||||
|
||||
animnow->setDuration(m_speed);
|
||||
animnow->setEasingCurve(m_animationtype);
|
||||
animnow->setStartValue(QPoint(pnow.x(), pnow.y()));
|
||||
animnow->setEndValue(QPoint(offsetx + pnow.x(), offsety + pnow.y()));
|
||||
QPropertyAnimation *animnext = new QPropertyAnimation(widget(next), "pos");
|
||||
//QPropertyAnimation *animnext = new QPropertyAnimation(widget(next), "pos");
|
||||
animnext->setTargetObject(widget(next));
|
||||
animnext->setPropertyName("pos");
|
||||
|
||||
animnext->setDuration(m_speed);
|
||||
animnext->setEasingCurve(m_animationtype);
|
||||
animnext->setStartValue(QPoint(-offsetx + pnext.x(), offsety + pnext.y()));
|
||||
animnext->setEndValue(QPoint(pnext.x(), pnext.y()));
|
||||
|
||||
QParallelAnimationGroup *animgroup = new QParallelAnimationGroup;
|
||||
// QParallelAnimationGroup *animgroup = new QParallelAnimationGroup;
|
||||
|
||||
animgroup->addAnimation(animnow);
|
||||
animgroup->addAnimation(animnext);
|
||||
// animgroup->addAnimation(animnow);
|
||||
// animgroup->addAnimation(animnext);
|
||||
|
||||
QObject::connect(animgroup, SIGNAL(finished()),this,SLOT(animationDoneSlot()));
|
||||
m_next = next;
|
||||
|
|
|
@ -47,6 +47,8 @@ public slots:
|
|||
void slideInIdx(int idx, enum t_direction direction = AUTOMATIC);
|
||||
void slideInWidget(QWidget *widget, enum t_direction direction = AUTOMATIC);
|
||||
|
||||
bool isAnimationRunning();
|
||||
void waitForAnimation();
|
||||
signals:
|
||||
// this is used for internal purposes in the class engine
|
||||
void animationFinished(void);
|
||||
|
@ -71,6 +73,10 @@ protected:
|
|||
bool m_active;
|
||||
|
||||
QList<QWidget*> blockedPageList;
|
||||
|
||||
QPropertyAnimation *animnow;
|
||||
QPropertyAnimation *animnext;
|
||||
QParallelAnimationGroup *animgroup;
|
||||
};
|
||||
|
||||
#endif // SLIDINGSTACKEDWIDGET_H
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
#include "ui_mainwindow.h"
|
||||
#include "utils.h"
|
||||
#include "vpnconnection.h"
|
||||
#include "ui/server_widget.h"
|
||||
#include "ui_server_widget.h"
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
#include "ui/macos_util.h"
|
||||
|
@ -43,8 +45,10 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||
|
||||
setupTray();
|
||||
setupUiConnections();
|
||||
setupProtocolsPage();
|
||||
|
||||
ui->label_error_text->clear();
|
||||
installEventFilter(this);
|
||||
ui->widget_tittlebar->installEventFilter(this);
|
||||
|
||||
ui->stackedWidget_main->setSpeed(200);
|
||||
|
@ -67,11 +71,10 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||
}
|
||||
|
||||
// Post initialization
|
||||
goToPage(Page::Start, true, false);
|
||||
|
||||
if (m_settings.haveAuthData()) {
|
||||
goToPage(Page::Vpn, true, false);
|
||||
} else {
|
||||
goToPage(Page::Start, true, false);
|
||||
}
|
||||
|
||||
connect(ui->lineEdit_sites_add_custom, &QLineEdit::returnPressed, [&](){
|
||||
|
@ -137,6 +140,7 @@ MainWindow::~MainWindow()
|
|||
|
||||
void MainWindow::goToPage(Page page, bool reset, bool slide)
|
||||
{
|
||||
qDebug() << "goToPage" << page;
|
||||
if (reset) {
|
||||
if (page == Page::NewServer) {
|
||||
ui->label_new_server_wait_info->hide();
|
||||
|
@ -148,13 +152,13 @@ void MainWindow::goToPage(Page page, bool reset, bool slide)
|
|||
if (page == Page::ServerSettings) {
|
||||
ui->label_server_settings_wait_info->hide();
|
||||
ui->label_server_settings_wait_info->clear();
|
||||
ui->label_server_settings_server->setText(QString("%1@%2:%3")
|
||||
.arg(m_settings.userName())
|
||||
.arg(m_settings.serverName())
|
||||
.arg(m_settings.serverPort()));
|
||||
// ui->label_server_settings_server->setText(QString("%1@%2:%3")
|
||||
// .arg(m_settings.userName())
|
||||
// .arg(m_settings.serverName())
|
||||
// .arg(m_settings.serverPort()));
|
||||
}
|
||||
if (page == Page::ShareConnection) {
|
||||
QJsonObject ssConfig = ShadowSocksVpnProtocol::genShadowSocksConfig(m_settings.serverCredentials());
|
||||
QJsonObject ssConfig = ShadowSocksVpnProtocol::genShadowSocksConfig(m_settings.defaultServerCredentials());
|
||||
|
||||
QString ssString = QString("%1:%2@%3:%4")
|
||||
.arg(ssConfig.value("method").toString())
|
||||
|
@ -171,14 +175,29 @@ void MainWindow::goToPage(Page page, bool reset, bool slide)
|
|||
ui->label_share_ss_method->setText(ssConfig.value("method").toString());
|
||||
ui->label_share_ss_password->setText(ssConfig.value("password").toString());
|
||||
}
|
||||
if (page == Page::ServerSettings) {
|
||||
updateSettings();
|
||||
}
|
||||
if (page == Page::Start) {
|
||||
ui->pushButton_back_from_start->setVisible(!pagesStack.isEmpty());
|
||||
}
|
||||
|
||||
ui->pushButton_new_server_connect_key->setChecked(false);
|
||||
}
|
||||
|
||||
if (slide)
|
||||
ui->stackedWidget_main->slideInWidget(getPageWidget(page));
|
||||
ui->stackedWidget_main->slideInWidget(getPageWidget(page), SlidingStackedWidget::RIGHT2LEFT);
|
||||
else
|
||||
ui->stackedWidget_main->setCurrentWidget(getPageWidget(page));
|
||||
|
||||
pagesStack.push(page);
|
||||
}
|
||||
|
||||
void MainWindow::closePage()
|
||||
{
|
||||
Page prev = pagesStack.pop();
|
||||
qDebug() << "closePage" << prev << "Set page" << pagesStack.top();
|
||||
ui->stackedWidget_main->slideInWidget(getPageWidget(pagesStack.top()), SlidingStackedWidget::LEFT2RIGHT);
|
||||
}
|
||||
|
||||
QWidget *MainWindow::getPageWidget(MainWindow::Page page)
|
||||
|
@ -191,8 +210,13 @@ QWidget *MainWindow::getPageWidget(MainWindow::Page page)
|
|||
case(Page::AppSettings): return ui->page_app_settings;
|
||||
case(Page::NetworkSettings): return ui->page_network_settings;
|
||||
case(Page::ServerSettings): return ui->page_server_settings;
|
||||
case(Page::ServerVpnProtocols): return ui->page_server_protocols;
|
||||
case(Page::ServersList): return ui->page_servers;
|
||||
case(Page::ShareConnection): return ui->page_share_connection;
|
||||
case(Page::Sites): return ui->page_sites;
|
||||
case(Page::OpenVpnSettings): return ui->page_proto_openvpn;
|
||||
case(Page::ShadowSocksSettings): return ui->page_proto_shadowsocks;
|
||||
case(Page::CloakSettings): return ui->page_proto_cloak;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -224,6 +248,14 @@ bool MainWindow::eventFilter(QObject *obj, QEvent *event)
|
|||
return false;
|
||||
}
|
||||
}
|
||||
if (event->type() == QEvent::KeyPress) {
|
||||
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
|
||||
if (keyEvent->key() == Qt::Key_Escape && ! ui->stackedWidget_main->isAnimationRunning() ) {
|
||||
if (currentPage() != Page::Vpn && currentPage() != Page::Start) {
|
||||
closePage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return QMainWindow::eventFilter(obj, event);
|
||||
}
|
||||
|
@ -236,6 +268,8 @@ void MainWindow::keyPressEvent(QKeyEvent *event)
|
|||
QMessageBox::warning(this, APPLICATION_NAME, tr("Cannot open logs folder!"));
|
||||
}
|
||||
break;
|
||||
case Qt::Key_Q:
|
||||
qApp->quit();
|
||||
default:
|
||||
;
|
||||
}
|
||||
|
@ -326,7 +360,7 @@ void MainWindow::onPushButtonNewServerConnectWithNewData(bool)
|
|||
ui->label_new_server_wait_info);
|
||||
|
||||
if (ok) {
|
||||
m_settings.setServerCredentials(serverCredentials);
|
||||
//m_settings.setServerCredentials(serverCredentials);
|
||||
|
||||
goToPage(Page::Vpn);
|
||||
qApp->processEvents();
|
||||
|
@ -358,7 +392,7 @@ void MainWindow::onPushButtonNewServerConnectWithExistingCode(bool)
|
|||
return;
|
||||
}
|
||||
|
||||
m_settings.setServerCredentials(credentials);
|
||||
//m_settings.setServerCredentials(credentials);
|
||||
|
||||
goToPage(Page::Vpn);
|
||||
}
|
||||
|
@ -425,7 +459,7 @@ bool MainWindow::installServer(ServerCredentials credentials,
|
|||
void MainWindow::onPushButtonReinstallServer(bool)
|
||||
{
|
||||
onDisconnect();
|
||||
installServer(m_settings.serverCredentials(),
|
||||
installServer(m_settings.defaultServerCredentials(),
|
||||
ui->page_server_settings,
|
||||
ui->progressBar_server_settings_reinstall,
|
||||
ui->pushButton_server_settings_reinstall,
|
||||
|
@ -436,7 +470,7 @@ void MainWindow::onPushButtonClearServer(bool)
|
|||
{
|
||||
onDisconnect();
|
||||
|
||||
ErrorCode e = ServerController::removeServer(m_settings.serverCredentials(), Protocol::Any);
|
||||
ErrorCode e = ServerController::removeServer(m_settings.defaultServerCredentials(), Protocol::Any);
|
||||
if (e) {
|
||||
QMessageBox::warning(this, APPLICATION_NAME,
|
||||
tr("Error occurred while configuring server.") + "\n" +
|
||||
|
@ -455,10 +489,10 @@ void MainWindow::onPushButtonForgetServer(bool)
|
|||
{
|
||||
onDisconnect();
|
||||
|
||||
m_settings.setUserName("");
|
||||
m_settings.setPassword("");
|
||||
m_settings.setServerName("");
|
||||
m_settings.setServerPort();
|
||||
// m_settings.setUserName("");
|
||||
// m_settings.setPassword("");
|
||||
// m_settings.setServerName("");
|
||||
// m_settings.setServerPort();
|
||||
|
||||
goToPage(Page::Start);
|
||||
}
|
||||
|
@ -580,6 +614,8 @@ void MainWindow::setTrayIcon(const QString &iconPath)
|
|||
|
||||
MainWindow::Page MainWindow::currentPage()
|
||||
{
|
||||
ui->stackedWidget_main->waitForAnimation();
|
||||
|
||||
QWidget *currentPage = ui->stackedWidget_main->currentWidget();
|
||||
QMetaEnum e = QMetaEnum::fromType<MainWindow::Page>();
|
||||
|
||||
|
@ -616,6 +652,8 @@ void MainWindow::setupUiConnections()
|
|||
connect(ui->pushButton_app_settings, &QPushButton::clicked, this, [this](){ goToPage(Page::AppSettings); });
|
||||
connect(ui->pushButton_network_settings, &QPushButton::clicked, this, [this](){ goToPage(Page::NetworkSettings); });
|
||||
connect(ui->pushButton_server_settings, &QPushButton::clicked, this, [this](){ goToPage(Page::ServerSettings); });
|
||||
connect(ui->pushButton_server_settings_protocols, &QPushButton::clicked, this, [this](){ goToPage(Page::ServerVpnProtocols); });
|
||||
connect(ui->pushButton_servers_list, &QPushButton::clicked, this, [this](){ goToPage(Page::ServersList); });
|
||||
connect(ui->pushButton_share_connection, &QPushButton::clicked, this, [this](){
|
||||
goToPage(Page::ShareConnection);
|
||||
updateShareCode();
|
||||
|
@ -631,13 +669,35 @@ void MainWindow::setupUiConnections()
|
|||
});
|
||||
|
||||
|
||||
connect(ui->pushButton_back_from_sites, &QPushButton::clicked, this, [this](){ goToPage(Page::Vpn); });
|
||||
connect(ui->pushButton_back_from_settings, &QPushButton::clicked, this, [this](){ goToPage(Page::Vpn); });
|
||||
connect(ui->pushButton_back_from_new_server, &QPushButton::clicked, this, [this](){ goToPage(Page::Start); });
|
||||
connect(ui->pushButton_back_from_app_settings, &QPushButton::clicked, this, [this](){ goToPage(Page::GeneralSettings); });
|
||||
connect(ui->pushButton_back_from_network_settings, &QPushButton::clicked, this, [this](){ goToPage(Page::GeneralSettings); });
|
||||
connect(ui->pushButton_back_from_server_settings, &QPushButton::clicked, this, [this](){ goToPage(Page::GeneralSettings); });
|
||||
connect(ui->pushButton_back_from_share, &QPushButton::clicked, this, [this](){ goToPage(Page::GeneralSettings); });
|
||||
// connect(ui->pushButton_back_from_sites, &QPushButton::clicked, this, [this](){ goToPage(Page::Vpn); });
|
||||
// connect(ui->pushButton_back_from_settings, &QPushButton::clicked, this, [this](){ goToPage(Page::Vpn); });
|
||||
// connect(ui->pushButton_back_from_new_server, &QPushButton::clicked, this, [this](){ goToPage(Page::Start); });
|
||||
// connect(ui->pushButton_back_from_app_settings, &QPushButton::clicked, this, [this](){ goToPage(Page::GeneralSettings); });
|
||||
// connect(ui->pushButton_back_from_network_settings, &QPushButton::clicked, this, [this](){ goToPage(Page::GeneralSettings); });
|
||||
// connect(ui->pushButton_back_from_server_settings, &QPushButton::clicked, this, [this](){ goToPage(Page::GeneralSettings); });
|
||||
// connect(ui->pushButton_back_from_servers, &QPushButton::clicked, this, [this](){ goToPage(Page::GeneralSettings); });
|
||||
// connect(ui->pushButton_back_from_share, &QPushButton::clicked, this, [this](){ goToPage(Page::GeneralSettings); });
|
||||
// connect(ui->pushButton_back_from_server_vpn_protocols, &QPushButton::clicked, this, [this](){ goToPage(Page::ServerSettings); });
|
||||
|
||||
// connect(ui->pushButton_back_from_server_vpn_protocols, &QPushButton::clicked, this, [this](){ goToPage(Page::ServerSettings); });
|
||||
// connect(ui->pushButton_back_from_server_vpn_protocols, &QPushButton::clicked, this, [this](){ goToPage(Page::ServerSettings); });
|
||||
// connect(ui->pushButton_back_from_server_vpn_protocols, &QPushButton::clicked, this, [this](){ goToPage(Page::ServerSettings); });
|
||||
|
||||
connect(ui->pushButton_back_from_sites, &QPushButton::clicked, this, [this](){ closePage(); });
|
||||
connect(ui->pushButton_back_from_settings, &QPushButton::clicked, this, [this](){ closePage(); });
|
||||
connect(ui->pushButton_back_from_start, &QPushButton::clicked, this, [this](){ closePage(); });
|
||||
connect(ui->pushButton_back_from_new_server, &QPushButton::clicked, this, [this](){ closePage(); });
|
||||
connect(ui->pushButton_back_from_app_settings, &QPushButton::clicked, this, [this](){ closePage(); });
|
||||
connect(ui->pushButton_back_from_network_settings, &QPushButton::clicked, this, [this](){ closePage(); });
|
||||
connect(ui->pushButton_back_from_server_settings, &QPushButton::clicked, this, [this](){ closePage(); });
|
||||
connect(ui->pushButton_back_from_servers, &QPushButton::clicked, this, [this](){ closePage(); });
|
||||
connect(ui->pushButton_back_from_share, &QPushButton::clicked, this, [this](){ closePage(); });
|
||||
connect(ui->pushButton_back_from_server_vpn_protocols, &QPushButton::clicked, this, [this](){ closePage(); });
|
||||
|
||||
connect(ui->pushButton_back_from_openvpn_settings, &QPushButton::clicked, this, [this](){ closePage(); });
|
||||
connect(ui->pushButton_back_from_cloak_settings, &QPushButton::clicked, this, [this](){ closePage(); });
|
||||
connect(ui->pushButton_back_from_shadowsocks_settings, &QPushButton::clicked, this, [this](){ closePage(); });
|
||||
|
||||
|
||||
connect(ui->pushButton_sites_add_custom, &QPushButton::clicked, this, [this](){ onPushButtonAddCustomSitesClicked(); });
|
||||
|
||||
|
@ -659,11 +719,11 @@ void MainWindow::setupUiConnections()
|
|||
});
|
||||
|
||||
connect(ui->pushButton_network_settings_resetdns1, &QPushButton::clicked, this, [this](){
|
||||
m_settings.setPrimaryDns(m_settings.cloudFlareNs1());
|
||||
m_settings.setPrimaryDns(m_settings.cloudFlareNs1);
|
||||
updateSettings();
|
||||
});
|
||||
connect(ui->pushButton_network_settings_resetdns2, &QPushButton::clicked, this, [this](){
|
||||
m_settings.setSecondaryDns(m_settings.cloudFlareNs2());
|
||||
m_settings.setSecondaryDns(m_settings.cloudFlareNs2);
|
||||
updateSettings();
|
||||
});
|
||||
|
||||
|
@ -689,6 +749,36 @@ void MainWindow::setupUiConnections()
|
|||
QDesktopServices::openUrl(QUrl("https://github.com/amnezia-vpn/desktop-client/releases"));
|
||||
});
|
||||
|
||||
connect(ui->pushButton_servers_add_new, &QPushButton::clicked, this, [this](){ goToPage(Page::Start); });
|
||||
}
|
||||
|
||||
void MainWindow::setupProtocolsPage()
|
||||
{
|
||||
connect(ui->pushButton_proto_openvpn_cont_openvpn_config, &QPushButton::clicked, this, [this](){
|
||||
goToPage(Page::OpenVpnSettings);
|
||||
});
|
||||
connect(ui->pushButton_proto_ss_openvpn_cont_openvpn_config, &QPushButton::clicked, this, [this](){
|
||||
goToPage(Page::OpenVpnSettings);
|
||||
});
|
||||
connect(ui->pushButton_proto_cloak_openvpn_cont_openvpn_config, &QPushButton::clicked, this, [this](){
|
||||
goToPage(Page::OpenVpnSettings);
|
||||
});
|
||||
|
||||
connect(ui->pushButton_proto_cloak_openvpn_cont_default, &QPushButton::clicked, this, [this](){
|
||||
m_settings.setDefaultContainer(selectedServerIndex, DockerContainer::OpenVpnOverCloak);
|
||||
updateSettings();
|
||||
});
|
||||
|
||||
connect(ui->pushButton_proto_ss_openvpn_cont_default, &QPushButton::clicked, this, [this](){
|
||||
m_settings.setDefaultContainer(selectedServerIndex, DockerContainer::ShadowSocksOverOpenVpn);
|
||||
updateSettings();
|
||||
});
|
||||
|
||||
connect(ui->pushButton_proto_openvpn_cont_default, &QPushButton::clicked, this, [this](){
|
||||
m_settings.setDefaultContainer(selectedServerIndex, DockerContainer::OpenVpn);
|
||||
updateSettings();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::setTrayState(VpnProtocol::ConnectionState state)
|
||||
|
@ -753,7 +843,7 @@ void MainWindow::onConnect()
|
|||
qApp->processEvents();
|
||||
|
||||
// TODO: Call connectToVpn with restricted server account
|
||||
ServerCredentials credentials = m_settings.serverCredentials();
|
||||
ServerCredentials credentials = m_settings.defaultServerCredentials();
|
||||
|
||||
ErrorCode errorCode = m_vpnConnection->connectToVpn(credentials);
|
||||
if (errorCode) {
|
||||
|
@ -864,18 +954,36 @@ void MainWindow::updateSettings()
|
|||
for(const QString &site : m_settings.customSites()) {
|
||||
makeSitesListItem(ui->listWidget_sites, site);
|
||||
}
|
||||
|
||||
ui->listWidget_servers->clear();
|
||||
const QJsonArray &servers = m_settings.serversArray();
|
||||
int defaultServer = m_settings.defaultServerIndex();
|
||||
|
||||
for(int i = 0; i < servers.size(); i++) {
|
||||
makeServersListItem(ui->listWidget_servers, servers.at(i).toObject(), i == defaultServer, i);
|
||||
}
|
||||
|
||||
QJsonObject selectedServer = m_settings.server(selectedServerIndex);
|
||||
QString selectedContainerName = m_settings.defaultContainerName(selectedServerIndex);
|
||||
|
||||
ui->label_server_settings_current_vpn_protocol->setText(tr("Protocol: ") + selectedContainerName);
|
||||
|
||||
qDebug() << "DefaultContainer(selectedServerIndex)" << selectedServerIndex << m_settings.defaultContainer(selectedServerIndex);
|
||||
ui->pushButton_proto_cloak_openvpn_cont_default->setChecked(m_settings.defaultContainer(selectedServerIndex) == DockerContainer::OpenVpnOverCloak);
|
||||
ui->pushButton_proto_ss_openvpn_cont_default->setChecked(m_settings.defaultContainer(selectedServerIndex) == DockerContainer::ShadowSocksOverOpenVpn);
|
||||
ui->pushButton_proto_openvpn_cont_default->setChecked(m_settings.defaultContainer(selectedServerIndex) == DockerContainer::OpenVpn);
|
||||
}
|
||||
|
||||
void MainWindow::updateShareCode()
|
||||
{
|
||||
QJsonObject o;
|
||||
o.insert("h", m_settings.serverName());
|
||||
o.insert("p", m_settings.serverPort());
|
||||
o.insert("u", m_settings.userName());
|
||||
o.insert("w", m_settings.password());
|
||||
// QJsonObject o;
|
||||
// o.insert("h", m_settings.serverName());
|
||||
// o.insert("p", m_settings.serverPort());
|
||||
// o.insert("u", m_settings.userName());
|
||||
// o.insert("w", m_settings.password());
|
||||
|
||||
QByteArray ba = QJsonDocument(o).toJson().toBase64(QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals);
|
||||
ui->textEdit_sharing_code->setText(QString("vpn://%1").arg(QString(ba)));
|
||||
// QByteArray ba = QJsonDocument(o).toJson().toBase64(QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals);
|
||||
// ui->textEdit_sharing_code->setText(QString("vpn://%1").arg(QString(ba)));
|
||||
|
||||
//qDebug() << "Share code" << QJsonDocument(o).toJson();
|
||||
}
|
||||
|
@ -909,6 +1017,34 @@ void MainWindow::makeSitesListItem(QListWidget *listWidget, const QString &addre
|
|||
widget->setStyleSheet(styleSheet());
|
||||
}
|
||||
|
||||
void MainWindow::makeServersListItem(QListWidget *listWidget, const QJsonObject &server, bool isDefault, int index)
|
||||
{
|
||||
QSize size(310, 70);
|
||||
ServerWidget* widget = new ServerWidget(server, isDefault);
|
||||
widget->resize(size);
|
||||
|
||||
connect(widget->ui->pushButton_default, &QPushButton::clicked, this, [this, index](){
|
||||
m_settings.setDefaultServer(index);
|
||||
updateSettings();
|
||||
});
|
||||
|
||||
connect(widget->ui->pushButton_share, &QPushButton::clicked, this, [this, index](){
|
||||
goToPage(Page::ShareConnection);
|
||||
// update share page
|
||||
});
|
||||
|
||||
connect(widget->ui->pushButton_settings, &QPushButton::clicked, this, [this, index](){
|
||||
selectedServerIndex = index;
|
||||
goToPage(Page::ServerSettings);
|
||||
});
|
||||
|
||||
QListWidgetItem* item = new QListWidgetItem(listWidget);
|
||||
item->setSizeHint(size);
|
||||
listWidget->setItemWidget(item, widget);
|
||||
|
||||
widget->setStyleSheet(styleSheet());
|
||||
}
|
||||
|
||||
void MainWindow::updateQRCodeImage(const QString &text, QLabel *label)
|
||||
{
|
||||
int levelIndex = 1;
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <QProgressBar>
|
||||
#include <QPushButton>
|
||||
#include <QRegExpValidator>
|
||||
#include <QStack>
|
||||
#include <QStringListModel>
|
||||
#include <QSystemTrayIcon>
|
||||
|
||||
|
@ -39,7 +40,9 @@ public:
|
|||
explicit MainWindow(QWidget *parent = nullptr);
|
||||
~MainWindow();
|
||||
|
||||
enum Page {Start, NewServer, Vpn, GeneralSettings, AppSettings, NetworkSettings, ServerSettings, ShareConnection, Sites};
|
||||
enum Page {Start, NewServer, Vpn, GeneralSettings, AppSettings, NetworkSettings,
|
||||
ServerSettings, ServerVpnProtocols, ServersList, ShareConnection, Sites,
|
||||
OpenVpnSettings, ShadowSocksSettings, CloakSettings};
|
||||
Q_ENUM(Page)
|
||||
|
||||
private slots:
|
||||
|
@ -69,6 +72,8 @@ private slots:
|
|||
|
||||
private:
|
||||
void goToPage(Page page, bool reset = true, bool slide = true);
|
||||
void closePage();
|
||||
|
||||
QWidget *getPageWidget(Page page);
|
||||
Page currentPage();
|
||||
|
||||
|
@ -78,10 +83,13 @@ private:
|
|||
void setTrayIcon(const QString &iconPath);
|
||||
|
||||
void setupUiConnections();
|
||||
void setupProtocolsPage();
|
||||
|
||||
void updateSettings();
|
||||
|
||||
void updateShareCode();
|
||||
void makeSitesListItem(QListWidget* listWidget, const QString &address);
|
||||
void makeServersListItem(QListWidget* listWidget, const QJsonObject &server, bool isDefault, int index);
|
||||
|
||||
void updateQRCodeImage(const QString &text, QLabel *label);
|
||||
private:
|
||||
|
@ -111,6 +119,10 @@ private:
|
|||
const QString ConnectedTrayIconName = "active.png";
|
||||
const QString DisconnectedTrayIconName = "default.png";
|
||||
const QString ErrorTrayIconName = "error.png";
|
||||
|
||||
|
||||
QStack<Page> pagesStack;
|
||||
int selectedServerIndex = -1; // server index to use when proto settings page opened
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
|
File diff suppressed because it is too large
Load diff
30
client/ui/server_widget.cpp
Normal file
30
client/ui/server_widget.cpp
Normal file
|
@ -0,0 +1,30 @@
|
|||
#include "server_widget.h"
|
||||
#include "ui_server_widget.h"
|
||||
|
||||
#include "settings.h"
|
||||
|
||||
ServerWidget::ServerWidget(const QJsonObject &server, bool isDefault, QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::ServerWidget)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
QString desc = server.value(Settings::descriptionString).toString();
|
||||
QString address = server.value(Settings::hostNameString).toString();
|
||||
|
||||
ui->label_address->setText(address);
|
||||
|
||||
if (desc.isEmpty()) {
|
||||
ui->label_description->setText(address);
|
||||
}
|
||||
else {
|
||||
ui->label_description->setText(desc);
|
||||
}
|
||||
|
||||
ui->pushButton_default->setChecked(isDefault);
|
||||
ui->pushButton_default->setDisabled(isDefault);
|
||||
}
|
||||
|
||||
ServerWidget::~ServerWidget()
|
||||
{
|
||||
delete ui;
|
||||
}
|
22
client/ui/server_widget.h
Normal file
22
client/ui/server_widget.h
Normal file
|
@ -0,0 +1,22 @@
|
|||
#ifndef SERVER_WIDGET_H
|
||||
#define SERVER_WIDGET_H
|
||||
|
||||
#include <QJsonObject>
|
||||
#include <QWidget>
|
||||
|
||||
namespace Ui {
|
||||
class ServerWidget;
|
||||
}
|
||||
|
||||
class ServerWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ServerWidget(const QJsonObject &server, bool isDefault, QWidget *parent = nullptr);
|
||||
~ServerWidget();
|
||||
Ui::ServerWidget *ui;
|
||||
|
||||
};
|
||||
|
||||
#endif // SERVER_WIDGET_H
|
167
client/ui/server_widget.ui
Normal file
167
client/ui/server_widget.ui
Normal file
|
@ -0,0 +1,167 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ServerWidget</class>
|
||||
<widget class="QWidget" name="ServerWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>325</width>
|
||||
<height>70</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<widget class="QLabel" name="label_description">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>10</y>
|
||||
<width>181</width>
|
||||
<height>21</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">QLabel {
|
||||
font-size: 16px;
|
||||
|
||||
font-style: normal;
|
||||
font-weight: bold;
|
||||
color: #181922;
|
||||
}</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Description</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_address">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>40</y>
|
||||
<width>141</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Address</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="pushButton_default">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>300</x>
|
||||
<y>25</y>
|
||||
<width>24</width>
|
||||
<height>24</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="cursor">
|
||||
<cursorShape>PointingHandCursor</cursorShape>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Set as default</string>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">QPushButton:checked {
|
||||
image: url(:/images/check.png);
|
||||
}
|
||||
QPushButton:!checked {
|
||||
image: url(:/images/uncheck.png);
|
||||
}</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="pushButton_share">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>260</x>
|
||||
<y>25</y>
|
||||
<width>24</width>
|
||||
<height>24</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="cursor">
|
||||
<cursorShape>PointingHandCursor</cursorShape>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Share connection</string>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">image: url(:/images/share.png);</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="pushButton_connect">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>212</x>
|
||||
<y>25</y>
|
||||
<width>32</width>
|
||||
<height>24</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="cursor">
|
||||
<cursorShape>PointingHandCursor</cursorShape>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Connection</string>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">QPushButton:checked {
|
||||
image: url(:/images/connect_button_connected.png);
|
||||
}
|
||||
QPushButton:!checked {
|
||||
image: url(:/images/connect_button_disconnected.png);
|
||||
}</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="pushButton_settings">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>174</x>
|
||||
<y>25</y>
|
||||
<width>24</width>
|
||||
<height>24</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="cursor">
|
||||
<cursorShape>PointingHandCursor</cursorShape>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Server settings</string>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">image: url(:/images/settings.png);</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -83,9 +83,9 @@ ErrorCode VpnConnection::lastError() const
|
|||
ErrorCode VpnConnection::createVpnConfiguration(const ServerCredentials &credentials, Protocol protocol)
|
||||
{
|
||||
ErrorCode errorCode = ErrorCode::NoError;
|
||||
if (protocol == Protocol::OpenVpn || protocol == Protocol::ShadowSocks || protocol == Protocol::OpenVpnOverCloak) {
|
||||
if (protocol == Protocol::OpenVpn || protocol == Protocol::ShadowSocksOverOpenVpn || protocol == Protocol::OpenVpnOverCloak) {
|
||||
QString openVpnConfigData = OpenVpnConfigurator::genOpenVpnConfig(credentials, protocol, &errorCode);
|
||||
m_vpnConfiguration.insert(config::key_openvpn_config_data(), openVpnConfigData);
|
||||
m_vpnConfiguration.insert(config::key_openvpn_config_data, openVpnConfigData);
|
||||
if (errorCode) {
|
||||
return errorCode;
|
||||
}
|
||||
|
@ -101,14 +101,14 @@ ErrorCode VpnConnection::createVpnConfiguration(const ServerCredentials &credent
|
|||
}
|
||||
}
|
||||
|
||||
if (protocol == Protocol::ShadowSocks) {
|
||||
if (protocol == Protocol::ShadowSocksOverOpenVpn) {
|
||||
QJsonObject ssConfigData = ShadowSocksVpnProtocol::genShadowSocksConfig(credentials);
|
||||
m_vpnConfiguration.insert(config::key_shadowsocks_config_data(), ssConfigData);
|
||||
m_vpnConfiguration.insert(config::key_shadowsocks_config_data, ssConfigData);
|
||||
}
|
||||
|
||||
if (protocol == Protocol::OpenVpnOverCloak) {
|
||||
QJsonObject cloakConfigData = CloakConfigurator::genCloakConfig(credentials, Protocol::OpenVpnOverCloak, &errorCode);
|
||||
m_vpnConfiguration.insert(config::key_cloak_config_data(), cloakConfigData);
|
||||
m_vpnConfiguration.insert(config::key_cloak_config_data, cloakConfigData);
|
||||
}
|
||||
|
||||
//qDebug().noquote() << "VPN config" << QJsonDocument(m_vpnConfiguration).toJson();
|
||||
|
@ -152,8 +152,8 @@ ErrorCode VpnConnection::connectToVpn(const ServerCredentials &credentials, Prot
|
|||
return e;
|
||||
}
|
||||
}
|
||||
else if (protocol == Protocol::ShadowSocks) {
|
||||
ErrorCode e = createVpnConfiguration(credentials, Protocol::ShadowSocks);
|
||||
else if (protocol == Protocol::ShadowSocksOverOpenVpn) {
|
||||
ErrorCode e = createVpnConfiguration(credentials, Protocol::ShadowSocksOverOpenVpn);
|
||||
if (e) {
|
||||
emit connectionStateChanged(VpnProtocol::ConnectionState::Error);
|
||||
return e;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue