added display of "pure" config if it was imported in native format
- changed the method of passing the isThirdPartyConfig parameter to page logic - removed adding hostname to the server name when importing configs in native format - fixed display of the "$proto settings" button when clicking on the protocol on the "Installed services" page
This commit is contained in:
parent
22939a6707
commit
c6bb33fa84
17 changed files with 58 additions and 53 deletions
|
@ -312,10 +312,3 @@ ServerCredentials Settings::serverCredentials(int index) const
|
||||||
|
|
||||||
return credentials;
|
return credentials;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Settings::isThirdPartyConfig(int serverIndex) const
|
|
||||||
{
|
|
||||||
if (serverIndex < 0) return false;
|
|
||||||
const QJsonObject &s = server(serverIndex);
|
|
||||||
return s.value(config_key::isThirdPartyConfig).toBool();
|
|
||||||
}
|
|
||||||
|
|
|
@ -113,8 +113,6 @@ public:
|
||||||
QByteArray backupAppConfig() const { return m_settings.backupAppConfig(); }
|
QByteArray backupAppConfig() const { return m_settings.backupAppConfig(); }
|
||||||
bool restoreAppConfig(const QByteArray &cfg) { return m_settings.restoreAppConfig(cfg); }
|
bool restoreAppConfig(const QByteArray &cfg) { return m_settings.restoreAppConfig(cfg); }
|
||||||
|
|
||||||
bool isThirdPartyConfig(int serverIndex) const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SecureQSettings m_settings;
|
SecureQSettings m_settings;
|
||||||
|
|
||||||
|
|
|
@ -38,8 +38,7 @@ void ServerContainersLogic::onPushButtonProtoSettingsClicked(DockerContainer c,
|
||||||
uiLogic()->selectedDockerContainer = c;
|
uiLogic()->selectedDockerContainer = c;
|
||||||
uiLogic()->protocolLogic(p)->updateProtocolPage(m_settings->protocolConfig(uiLogic()->selectedServerIndex, uiLogic()->selectedDockerContainer, p),
|
uiLogic()->protocolLogic(p)->updateProtocolPage(m_settings->protocolConfig(uiLogic()->selectedServerIndex, uiLogic()->selectedDockerContainer, p),
|
||||||
uiLogic()->selectedDockerContainer,
|
uiLogic()->selectedDockerContainer,
|
||||||
m_settings->haveAuthData(uiLogic()->selectedServerIndex),
|
m_settings->haveAuthData(uiLogic()->selectedServerIndex));
|
||||||
m_settings->isThirdPartyConfig(uiLogic()->selectedServerIndex));
|
|
||||||
|
|
||||||
emit uiLogic()->goToProtocolPage(p);
|
emit uiLogic()->goToProtocolPage(p);
|
||||||
}
|
}
|
||||||
|
|
|
@ -250,6 +250,7 @@ bool StartPageLogic::importConnectionFromOpenVpnConfig(const QString &config)
|
||||||
|
|
||||||
QJsonObject lastConfig;
|
QJsonObject lastConfig;
|
||||||
lastConfig[config_key::last_config] = QString(QJsonDocument(openVpnConfig).toJson());
|
lastConfig[config_key::last_config] = QString(QJsonDocument(openVpnConfig).toJson());
|
||||||
|
lastConfig[config_key::isThirdPartyConfig] = true;
|
||||||
|
|
||||||
QJsonObject containers;
|
QJsonObject containers;
|
||||||
containers.insert(config_key::container, QJsonValue("amnezia-openvpn"));
|
containers.insert(config_key::container, QJsonValue("amnezia-openvpn"));
|
||||||
|
@ -268,7 +269,7 @@ bool StartPageLogic::importConnectionFromOpenVpnConfig(const QString &config)
|
||||||
QJsonObject o;
|
QJsonObject o;
|
||||||
o[config_key::containers] = arr;
|
o[config_key::containers] = arr;
|
||||||
o[config_key::defaultContainer] = "amnezia-openvpn";
|
o[config_key::defaultContainer] = "amnezia-openvpn";
|
||||||
o[config_key::description] = QString("OpenVpn server %1").arg(hostName);
|
o[config_key::description] = QString("OpenVpn server");
|
||||||
|
|
||||||
|
|
||||||
const static QRegularExpression dnsRegExp("dhcp-option DNS (\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\b)");
|
const static QRegularExpression dnsRegExp("dhcp-option DNS (\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\b)");
|
||||||
|
@ -282,8 +283,6 @@ bool StartPageLogic::importConnectionFromOpenVpnConfig(const QString &config)
|
||||||
|
|
||||||
o[config_key::hostName] = hostName;
|
o[config_key::hostName] = hostName;
|
||||||
|
|
||||||
o[config_key::isThirdPartyConfig] = true;
|
|
||||||
|
|
||||||
return importConnection(o);
|
return importConnection(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -302,7 +301,8 @@ bool StartPageLogic::importConnectionFromWireguardConfig(const QString &config)
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonObject wireguardConfig;
|
QJsonObject wireguardConfig;
|
||||||
wireguardConfig[config_key::last_config] = QString(QJsonDocument(lastConfig).toJson());;
|
wireguardConfig[config_key::last_config] = QString(QJsonDocument(lastConfig).toJson());
|
||||||
|
wireguardConfig[config_key::isThirdPartyConfig] = true;
|
||||||
wireguardConfig[config_key::port] = port;
|
wireguardConfig[config_key::port] = port;
|
||||||
wireguardConfig[config_key::transport_proto] = "udp";
|
wireguardConfig[config_key::transport_proto] = "udp";
|
||||||
|
|
||||||
|
@ -316,7 +316,7 @@ bool StartPageLogic::importConnectionFromWireguardConfig(const QString &config)
|
||||||
QJsonObject o;
|
QJsonObject o;
|
||||||
o[config_key::containers] = arr;
|
o[config_key::containers] = arr;
|
||||||
o[config_key::defaultContainer] = "amnezia-wireguard";
|
o[config_key::defaultContainer] = "amnezia-wireguard";
|
||||||
o[config_key::description] = QString("Wireguard server %1").arg(hostName);
|
o[config_key::description] = QString("Wireguard server");
|
||||||
|
|
||||||
const static QRegularExpression dnsRegExp("DNS = (\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\b).*(\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\b)");
|
const static QRegularExpression dnsRegExp("DNS = (\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\b).*(\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\b)");
|
||||||
QRegularExpressionMatch dnsMatch = dnsRegExp.match(config);
|
QRegularExpressionMatch dnsMatch = dnsRegExp.match(config);
|
||||||
|
@ -327,7 +327,5 @@ bool StartPageLogic::importConnectionFromWireguardConfig(const QString &config)
|
||||||
|
|
||||||
o[config_key::hostName] = hostName;
|
o[config_key::hostName] = hostName;
|
||||||
|
|
||||||
o[config_key::isThirdPartyConfig] = true;
|
|
||||||
|
|
||||||
return importConnection(o);
|
return importConnection(o);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,8 @@ void ViewConfigLogic::onUpdatePage()
|
||||||
{
|
{
|
||||||
set_configText(QJsonDocument(configJson()).toJson());
|
set_configText(QJsonDocument(configJson()).toJson());
|
||||||
|
|
||||||
|
auto s = configJson()[config_key::isThirdPartyConfig].toBool();
|
||||||
|
|
||||||
m_openVpnLastConfigs = m_openVpnMalStrings =
|
m_openVpnLastConfigs = m_openVpnMalStrings =
|
||||||
"<style> \
|
"<style> \
|
||||||
div { line-height: 0.5; } \
|
div { line-height: 0.5; } \
|
||||||
|
@ -24,15 +26,28 @@ void ViewConfigLogic::onUpdatePage()
|
||||||
const QJsonArray &containers = configJson()[config_key::containers].toArray();
|
const QJsonArray &containers = configJson()[config_key::containers].toArray();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (const QJsonValue &v: containers) {
|
for (const QJsonValue &v: containers) {
|
||||||
QString cfg_json = v.toObject()[ProtocolProps::protoToString(Proto::OpenVpn)]
|
auto containerName = v.toObject()[config_key::container].toString();
|
||||||
|
QJsonObject containerConfig = v.toObject()[containerName.replace("amnezia-", "")].toObject();
|
||||||
|
if (containerConfig[config_key::isThirdPartyConfig].toBool()) {
|
||||||
|
auto lastConfig = containerConfig.value(config_key::last_config).toString();
|
||||||
|
auto lastConfigJson = QJsonDocument::fromJson(lastConfig.toUtf8()).object();
|
||||||
|
QStringList lines = lastConfigJson.value(config_key::config).toString().replace("\r", "").split("\n");
|
||||||
|
QString lastConfigText;
|
||||||
|
for (const QString &l: lines) {
|
||||||
|
lastConfigText.append(l + "\n");
|
||||||
|
}
|
||||||
|
set_configText(lastConfigText);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (v.toObject()[config_key::container].toString() == "amnezia-openvpn") {
|
||||||
|
QString lastConfig = v.toObject()[ProtocolProps::protoToString(Proto::OpenVpn)]
|
||||||
.toObject()[config_key::last_config].toString();
|
.toObject()[config_key::last_config].toString();
|
||||||
|
|
||||||
QString openvpn_cfg = QJsonDocument::fromJson(cfg_json.toUtf8()).object()[config_key::config]
|
QString lastConfigJson = QJsonDocument::fromJson(lastConfig.toUtf8()).object()[config_key::config]
|
||||||
.toString();
|
.toString();
|
||||||
|
|
||||||
openvpn_cfg.replace("\r", "");
|
QStringList lines = lastConfigJson.replace("\r", "").split("\n");
|
||||||
|
|
||||||
QStringList lines = openvpn_cfg.split("\n");
|
|
||||||
for (const QString &l: lines) {
|
for (const QString &l: lines) {
|
||||||
i++;
|
i++;
|
||||||
QRegularExpressionMatch match = m_re.match(l);
|
QRegularExpressionMatch match = m_re.match(l);
|
||||||
|
@ -49,6 +64,7 @@ void ViewConfigLogic::onUpdatePage()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
emit openVpnLastConfigsChanged(m_openVpnLastConfigs);
|
emit openVpnLastConfigsChanged(m_openVpnLastConfigs);
|
||||||
emit openVpnMalStringsChanged(m_openVpnMalStrings);
|
emit openVpnMalStringsChanged(m_openVpnMalStrings);
|
||||||
|
|
|
@ -23,7 +23,7 @@ CloakLogic::CloakLogic(UiLogic *logic, QObject *parent):
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CloakLogic::updateProtocolPage(const QJsonObject &ckConfig, DockerContainer container, bool haveAuthData, bool isThirdPartyConfig)
|
void CloakLogic::updateProtocolPage(const QJsonObject &ckConfig, DockerContainer container, bool haveAuthData)
|
||||||
{
|
{
|
||||||
set_pageEnabled(haveAuthData);
|
set_pageEnabled(haveAuthData);
|
||||||
set_pushButtonSaveVisible(haveAuthData);
|
set_pushButtonSaveVisible(haveAuthData);
|
||||||
|
|
|
@ -28,7 +28,7 @@ public:
|
||||||
explicit CloakLogic(UiLogic *uiLogic, QObject *parent = nullptr);
|
explicit CloakLogic(UiLogic *uiLogic, QObject *parent = nullptr);
|
||||||
~CloakLogic() = default;
|
~CloakLogic() = default;
|
||||||
|
|
||||||
void updateProtocolPage(const QJsonObject &ckConfig, DockerContainer container, bool haveAuthData, bool isThirdPartyConfig) override;
|
void updateProtocolPage(const QJsonObject &ckConfig, DockerContainer container, bool haveAuthData) override;
|
||||||
QJsonObject getProtocolConfigFromPage(QJsonObject oldConfig) override;
|
QJsonObject getProtocolConfigFromPage(QJsonObject oldConfig) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -35,7 +35,7 @@ OpenVpnLogic::OpenVpnLogic(UiLogic *logic, QObject *parent):
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenVpnLogic::updateProtocolPage(const QJsonObject &openvpnConfig, DockerContainer container, bool haveAuthData, bool isThirdPartyConfig)
|
void OpenVpnLogic::updateProtocolPage(const QJsonObject &openvpnConfig, DockerContainer container, bool haveAuthData)
|
||||||
{
|
{
|
||||||
qDebug() << "OpenVpnLogic::updateProtocolPage";
|
qDebug() << "OpenVpnLogic::updateProtocolPage";
|
||||||
set_pageEnabled(haveAuthData);
|
set_pageEnabled(haveAuthData);
|
||||||
|
@ -96,8 +96,8 @@ void OpenVpnLogic::updateProtocolPage(const QJsonObject &openvpnConfig, DockerCo
|
||||||
openVpnLastConfigText.append(l + "\n");
|
openVpnLastConfigText.append(l + "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
set_openVpnLastConfigText(m_openVpnLastConfigText);
|
set_openVpnLastConfigText(openVpnLastConfigText);
|
||||||
set_isThirdPartyConfig(isThirdPartyConfig);
|
set_isThirdPartyConfig(openvpnConfig.value(config_key::isThirdPartyConfig).isBool());
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenVpnLogic::onPushButtonProtoOpenVpnSaveClicked()
|
void OpenVpnLogic::onPushButtonProtoOpenVpnSaveClicked()
|
||||||
|
|
|
@ -45,7 +45,7 @@ public:
|
||||||
explicit OpenVpnLogic(UiLogic *uiLogic, QObject *parent = nullptr);
|
explicit OpenVpnLogic(UiLogic *uiLogic, QObject *parent = nullptr);
|
||||||
~OpenVpnLogic() = default;
|
~OpenVpnLogic() = default;
|
||||||
|
|
||||||
void updateProtocolPage(const QJsonObject &openvpnConfig, DockerContainer container, bool haveAuthData, bool isThirdPartyConfig) override;
|
void updateProtocolPage(const QJsonObject &openvpnConfig, DockerContainer container, bool haveAuthData) override;
|
||||||
QJsonObject getProtocolConfigFromPage(QJsonObject oldConfig) override;
|
QJsonObject getProtocolConfigFromPage(QJsonObject oldConfig) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -36,7 +36,7 @@ OtherProtocolsLogic::~OtherProtocolsLogic()
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void OtherProtocolsLogic::updateProtocolPage(const QJsonObject &config, DockerContainer container, bool haveAuthData, bool isThirdPartyConfig)
|
void OtherProtocolsLogic::updateProtocolPage(const QJsonObject &config, DockerContainer container, bool haveAuthData)
|
||||||
{
|
{
|
||||||
set_labelTftpUserNameText(config.value(config_key::userName).toString());
|
set_labelTftpUserNameText(config.value(config_key::userName).toString());
|
||||||
set_labelTftpPasswordText(config.value(config_key::password).toString(protocols::sftp::defaultUserName));
|
set_labelTftpPasswordText(config.value(config_key::password).toString(protocols::sftp::defaultUserName));
|
||||||
|
|
|
@ -27,7 +27,7 @@ public:
|
||||||
explicit OtherProtocolsLogic(UiLogic *uiLogic, QObject *parent = nullptr);
|
explicit OtherProtocolsLogic(UiLogic *uiLogic, QObject *parent = nullptr);
|
||||||
~OtherProtocolsLogic();
|
~OtherProtocolsLogic();
|
||||||
|
|
||||||
void updateProtocolPage(const QJsonObject &config, DockerContainer container, bool haveAuthData, bool isThirdPartyConfig) override;
|
void updateProtocolPage(const QJsonObject &config, DockerContainer container, bool haveAuthData) override;
|
||||||
//QJsonObject getProtocolConfigFromPage(QJsonObject oldConfig) override;
|
//QJsonObject getProtocolConfigFromPage(QJsonObject oldConfig) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -17,7 +17,7 @@ public:
|
||||||
explicit PageProtocolLogicBase(UiLogic *uiLogic, QObject *parent = nullptr);
|
explicit PageProtocolLogicBase(UiLogic *uiLogic, QObject *parent = nullptr);
|
||||||
~PageProtocolLogicBase() = default;
|
~PageProtocolLogicBase() = default;
|
||||||
|
|
||||||
virtual void updateProtocolPage(const QJsonObject &config, DockerContainer container, bool haveAuthData, bool isThirdPartyConfig) {}
|
virtual void updateProtocolPage(const QJsonObject &config, DockerContainer container, bool haveAuthData) {}
|
||||||
virtual QJsonObject getProtocolConfigFromPage(QJsonObject oldConfig) { return QJsonObject(); }
|
virtual QJsonObject getProtocolConfigFromPage(QJsonObject oldConfig) { return QJsonObject(); }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -21,7 +21,7 @@ ShadowSocksLogic::ShadowSocksLogic(UiLogic *logic, QObject *parent):
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShadowSocksLogic::updateProtocolPage(const QJsonObject &ssConfig, DockerContainer container, bool haveAuthData, bool isThirdPartyConfig)
|
void ShadowSocksLogic::updateProtocolPage(const QJsonObject &ssConfig, DockerContainer container, bool haveAuthData)
|
||||||
{
|
{
|
||||||
set_pageEnabled(haveAuthData);
|
set_pageEnabled(haveAuthData);
|
||||||
set_pushButtonSaveVisible(haveAuthData);
|
set_pushButtonSaveVisible(haveAuthData);
|
||||||
|
|
|
@ -26,7 +26,7 @@ public:
|
||||||
explicit ShadowSocksLogic(UiLogic *uiLogic, QObject *parent = nullptr);
|
explicit ShadowSocksLogic(UiLogic *uiLogic, QObject *parent = nullptr);
|
||||||
~ShadowSocksLogic() = default;
|
~ShadowSocksLogic() = default;
|
||||||
|
|
||||||
void updateProtocolPage(const QJsonObject &ssConfig, DockerContainer container, bool haveAuthData, bool isThirdPartyConfig) override;
|
void updateProtocolPage(const QJsonObject &ssConfig, DockerContainer container, bool haveAuthData) override;
|
||||||
QJsonObject getProtocolConfigFromPage(QJsonObject oldConfig) override;
|
QJsonObject getProtocolConfigFromPage(QJsonObject oldConfig) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -12,7 +12,7 @@ WireGuardLogic::WireGuardLogic(UiLogic *logic, QObject *parent):
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WireGuardLogic::updateProtocolPage(const QJsonObject &wireGuardConfig, DockerContainer container, bool haveAuthData, bool isThirdPartyConfig)
|
void WireGuardLogic::updateProtocolPage(const QJsonObject &wireGuardConfig, DockerContainer container, bool haveAuthData)
|
||||||
{
|
{
|
||||||
qDebug() << "WireGuardLogic::updateProtocolPage";
|
qDebug() << "WireGuardLogic::updateProtocolPage";
|
||||||
|
|
||||||
|
@ -26,5 +26,5 @@ void WireGuardLogic::updateProtocolPage(const QJsonObject &wireGuardConfig, Dock
|
||||||
}
|
}
|
||||||
|
|
||||||
set_wireGuardLastConfigText(wireGuardLastConfigText);
|
set_wireGuardLastConfigText(wireGuardLastConfigText);
|
||||||
set_isThirdPartyConfig(isThirdPartyConfig);
|
set_isThirdPartyConfig(wireGuardConfig.value(config_key::isThirdPartyConfig).toBool());
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ public:
|
||||||
explicit WireGuardLogic(UiLogic *uiLogic, QObject *parent = nullptr);
|
explicit WireGuardLogic(UiLogic *uiLogic, QObject *parent = nullptr);
|
||||||
~WireGuardLogic() = default;
|
~WireGuardLogic() = default;
|
||||||
|
|
||||||
void updateProtocolPage(const QJsonObject &wireGuardConfig, DockerContainer container, bool haveAuthData, bool isThirdPartyConfig) override;
|
void updateProtocolPage(const QJsonObject &wireGuardConfig, DockerContainer container, bool haveAuthData) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
UiLogic *m_uiLogic;
|
UiLogic *m_uiLogic;
|
||||||
|
|
|
@ -32,6 +32,7 @@ PageBase {
|
||||||
|
|
||||||
BackButton {
|
BackButton {
|
||||||
id: back
|
id: back
|
||||||
|
onClicked: tb_c.currentIndex = -1
|
||||||
}
|
}
|
||||||
Caption {
|
Caption {
|
||||||
id: caption
|
id: caption
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue