Compare commits
17 commits
refactorin
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1909d3c94e | ||
|
|
10a107716c | ||
|
|
5445e6637b | ||
|
|
2380cd5cfb | ||
|
|
42661618dc | ||
|
|
8a7e901d7a | ||
|
|
f8bea71716 | ||
|
|
efcc0b7efc | ||
|
|
4d17e913b5 | ||
|
|
b341934863 | ||
|
|
127f8ed3bb | ||
|
|
9dca80de18 | ||
|
|
b0a6bcc055 | ||
|
|
f0626e2eca | ||
|
|
979ab42c5a | ||
|
|
e152e84ddc | ||
|
|
2605978889 |
114 changed files with 2633 additions and 2953 deletions
18
.github/workflows/deploy.yml
vendored
18
.github/workflows/deploy.yml
vendored
|
|
@ -255,7 +255,6 @@ jobs:
|
||||||
env:
|
env:
|
||||||
# Keep compat with MacOS 10.15 aka Catalina by Qt 6.4
|
# Keep compat with MacOS 10.15 aka Catalina by Qt 6.4
|
||||||
QT_VERSION: 6.4.3
|
QT_VERSION: 6.4.3
|
||||||
QIF_VERSION: 4.6
|
|
||||||
PROD_AGW_PUBLIC_KEY: ${{ secrets.PROD_AGW_PUBLIC_KEY }}
|
PROD_AGW_PUBLIC_KEY: ${{ secrets.PROD_AGW_PUBLIC_KEY }}
|
||||||
PROD_S3_ENDPOINT: ${{ secrets.PROD_S3_ENDPOINT }}
|
PROD_S3_ENDPOINT: ${{ secrets.PROD_S3_ENDPOINT }}
|
||||||
DEV_AGW_PUBLIC_KEY: ${{ secrets.DEV_AGW_PUBLIC_KEY }}
|
DEV_AGW_PUBLIC_KEY: ${{ secrets.DEV_AGW_PUBLIC_KEY }}
|
||||||
|
|
@ -283,11 +282,6 @@ jobs:
|
||||||
set-env: 'true'
|
set-env: 'true'
|
||||||
extra: '--external 7z --base ${{ env.QT_MIRROR }}'
|
extra: '--external 7z --base ${{ env.QT_MIRROR }}'
|
||||||
|
|
||||||
- name: 'Install Qt Installer Framework ${{ env.QIF_VERSION }}'
|
|
||||||
run: |
|
|
||||||
mkdir -pv ${{ runner.temp }}/Qt/Tools/QtInstallerFramework
|
|
||||||
wget https://qt.amzsvc.com/tools/ifw/${{ env.QIF_VERSION }}.zip
|
|
||||||
unzip ${{ env.QIF_VERSION }}.zip -d ${{ runner.temp }}/Qt/Tools/QtInstallerFramework/
|
|
||||||
|
|
||||||
- name: 'Get sources'
|
- name: 'Get sources'
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
@ -301,14 +295,13 @@ jobs:
|
||||||
- name: 'Build project'
|
- name: 'Build project'
|
||||||
run: |
|
run: |
|
||||||
export QT_BIN_DIR="${{ runner.temp }}/Qt/${{ env.QT_VERSION }}/macos/bin"
|
export QT_BIN_DIR="${{ runner.temp }}/Qt/${{ env.QT_VERSION }}/macos/bin"
|
||||||
export QIF_BIN_DIR="${{ runner.temp }}/Qt/Tools/QtInstallerFramework/${{ env.QIF_VERSION }}/bin"
|
|
||||||
bash deploy/build_macos.sh
|
bash deploy/build_macos.sh
|
||||||
|
|
||||||
- name: 'Upload installer artifact'
|
- name: 'Upload installer artifact'
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: AmneziaVPN_MacOS_old_installer
|
name: AmneziaVPN_MacOS_old_installer
|
||||||
path: AmneziaVPN.dmg
|
path: deploy/build/pkg/AmneziaVPN.pkg
|
||||||
retention-days: 7
|
retention-days: 7
|
||||||
|
|
||||||
- name: 'Upload unpacked artifact'
|
- name: 'Upload unpacked artifact'
|
||||||
|
|
@ -325,7 +318,6 @@ jobs:
|
||||||
|
|
||||||
env:
|
env:
|
||||||
QT_VERSION: 6.8.0
|
QT_VERSION: 6.8.0
|
||||||
QIF_VERSION: 4.8.1
|
|
||||||
PROD_AGW_PUBLIC_KEY: ${{ secrets.PROD_AGW_PUBLIC_KEY }}
|
PROD_AGW_PUBLIC_KEY: ${{ secrets.PROD_AGW_PUBLIC_KEY }}
|
||||||
PROD_S3_ENDPOINT: ${{ secrets.PROD_S3_ENDPOINT }}
|
PROD_S3_ENDPOINT: ${{ secrets.PROD_S3_ENDPOINT }}
|
||||||
DEV_AGW_PUBLIC_KEY: ${{ secrets.DEV_AGW_PUBLIC_KEY }}
|
DEV_AGW_PUBLIC_KEY: ${{ secrets.DEV_AGW_PUBLIC_KEY }}
|
||||||
|
|
@ -353,11 +345,6 @@ jobs:
|
||||||
set-env: 'true'
|
set-env: 'true'
|
||||||
extra: '--external 7z --base ${{ env.QT_MIRROR }}'
|
extra: '--external 7z --base ${{ env.QT_MIRROR }}'
|
||||||
|
|
||||||
- name: 'Install Qt Installer Framework ${{ env.QIF_VERSION }}'
|
|
||||||
run: |
|
|
||||||
mkdir -pv ${{ runner.temp }}/Qt/Tools/QtInstallerFramework
|
|
||||||
wget https://qt.amzsvc.com/tools/ifw/${{ env.QIF_VERSION }}.zip
|
|
||||||
unzip ${{ env.QIF_VERSION }}.zip -d ${{ runner.temp }}/Qt/Tools/QtInstallerFramework/
|
|
||||||
|
|
||||||
- name: 'Get sources'
|
- name: 'Get sources'
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
@ -371,14 +358,13 @@ jobs:
|
||||||
- name: 'Build project'
|
- name: 'Build project'
|
||||||
run: |
|
run: |
|
||||||
export QT_BIN_DIR="${{ runner.temp }}/Qt/${{ env.QT_VERSION }}/macos/bin"
|
export QT_BIN_DIR="${{ runner.temp }}/Qt/${{ env.QT_VERSION }}/macos/bin"
|
||||||
export QIF_BIN_DIR="${{ runner.temp }}/Qt/Tools/QtInstallerFramework/${{ env.QIF_VERSION }}/bin"
|
|
||||||
bash deploy/build_macos.sh
|
bash deploy/build_macos.sh
|
||||||
|
|
||||||
- name: 'Upload installer artifact'
|
- name: 'Upload installer artifact'
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: AmneziaVPN_MacOS_installer
|
name: AmneziaVPN_MacOS_installer
|
||||||
path: AmneziaVPN.dmg
|
path: deploy/build/pkg/AmneziaVPN.pkg
|
||||||
retention-days: 7
|
retention-days: 7
|
||||||
|
|
||||||
- name: 'Upload unpacked artifact'
|
- name: 'Upload unpacked artifact'
|
||||||
|
|
|
||||||
1
.gitmodules
vendored
1
.gitmodules
vendored
|
|
@ -7,6 +7,7 @@
|
||||||
[submodule "client/3rd-prebuilt"]
|
[submodule "client/3rd-prebuilt"]
|
||||||
path = client/3rd-prebuilt
|
path = client/3rd-prebuilt
|
||||||
url = https://github.com/amnezia-vpn/3rd-prebuilt
|
url = https://github.com/amnezia-vpn/3rd-prebuilt
|
||||||
|
branch = feature/special-handshake
|
||||||
[submodule "client/3rd/amneziawg-apple"]
|
[submodule "client/3rd/amneziawg-apple"]
|
||||||
path = client/3rd/amneziawg-apple
|
path = client/3rd/amneziawg-apple
|
||||||
url = https://github.com/amnezia-vpn/amneziawg-apple
|
url = https://github.com/amnezia-vpn/amneziawg-apple
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.25.0 FATAL_ERROR)
|
||||||
|
|
||||||
set(PROJECT AmneziaVPN)
|
set(PROJECT AmneziaVPN)
|
||||||
|
|
||||||
project(${PROJECT} VERSION 4.8.7.2
|
project(${PROJECT} VERSION 4.8.8.1
|
||||||
DESCRIPTION "AmneziaVPN"
|
DESCRIPTION "AmneziaVPN"
|
||||||
HOMEPAGE_URL "https://amnezia.org/"
|
HOMEPAGE_URL "https://amnezia.org/"
|
||||||
)
|
)
|
||||||
|
|
@ -11,7 +11,7 @@ string(TIMESTAMP CURRENT_DATE "%Y-%m-%d")
|
||||||
set(RELEASE_DATE "${CURRENT_DATE}")
|
set(RELEASE_DATE "${CURRENT_DATE}")
|
||||||
|
|
||||||
set(APP_MAJOR_VERSION ${CMAKE_PROJECT_VERSION_MAJOR}.${CMAKE_PROJECT_VERSION_MINOR}.${CMAKE_PROJECT_VERSION_PATCH})
|
set(APP_MAJOR_VERSION ${CMAKE_PROJECT_VERSION_MAJOR}.${CMAKE_PROJECT_VERSION_MINOR}.${CMAKE_PROJECT_VERSION_PATCH})
|
||||||
set(APP_ANDROID_VERSION_CODE 2086)
|
set(APP_ANDROID_VERSION_CODE 2087)
|
||||||
|
|
||||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
|
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
|
||||||
set(MZ_PLATFORM_NAME "linux")
|
set(MZ_PLATFORM_NAME "linux")
|
||||||
|
|
@ -28,7 +28,7 @@ elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Emscripten")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(QT_BUILD_TOOLS_WHEN_CROSS_COMPILING ON)
|
set(QT_BUILD_TOOLS_WHEN_CROSS_COMPILING ON)
|
||||||
set(CMAKE_CXX_STANDARD 20)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
if(APPLE AND NOT IOS)
|
if(APPLE AND NOT IOS)
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit 0f3748efd7cc04e0c914304b68931f925bed1259
|
Subproject commit 840b7b070e6ac8b90dda2fac6e98859b23727c0c
|
||||||
2
client/3rd/amneziawg-apple
vendored
2
client/3rd/amneziawg-apple
vendored
|
|
@ -1 +1 @@
|
||||||
Subproject commit 76e7db556a6d7e2582f9481df91db188a46c009c
|
Subproject commit 811af0a83b3faeade89a9093a588595666d32066
|
||||||
|
|
@ -120,10 +120,21 @@ open class Wireguard : Protocol() {
|
||||||
configData.optStringOrNull("Jmax")?.let { setJmax(it.toInt()) }
|
configData.optStringOrNull("Jmax")?.let { setJmax(it.toInt()) }
|
||||||
configData.optStringOrNull("S1")?.let { setS1(it.toInt()) }
|
configData.optStringOrNull("S1")?.let { setS1(it.toInt()) }
|
||||||
configData.optStringOrNull("S2")?.let { setS2(it.toInt()) }
|
configData.optStringOrNull("S2")?.let { setS2(it.toInt()) }
|
||||||
|
configData.optStringOrNull("S3")?.let { setS3(it.toInt()) }
|
||||||
|
configData.optStringOrNull("S4")?.let { setS4(it.toInt()) }
|
||||||
configData.optStringOrNull("H1")?.let { setH1(it.toLong()) }
|
configData.optStringOrNull("H1")?.let { setH1(it.toLong()) }
|
||||||
configData.optStringOrNull("H2")?.let { setH2(it.toLong()) }
|
configData.optStringOrNull("H2")?.let { setH2(it.toLong()) }
|
||||||
configData.optStringOrNull("H3")?.let { setH3(it.toLong()) }
|
configData.optStringOrNull("H3")?.let { setH3(it.toLong()) }
|
||||||
configData.optStringOrNull("H4")?.let { setH4(it.toLong()) }
|
configData.optStringOrNull("H4")?.let { setH4(it.toLong()) }
|
||||||
|
configData.optStringOrNull("I1")?.let { setI1(it) }
|
||||||
|
configData.optStringOrNull("I2")?.let { setI2(it) }
|
||||||
|
configData.optStringOrNull("I3")?.let { setI3(it) }
|
||||||
|
configData.optStringOrNull("I4")?.let { setI4(it) }
|
||||||
|
configData.optStringOrNull("I5")?.let { setI5(it) }
|
||||||
|
configData.optStringOrNull("J1")?.let { setJ1(it) }
|
||||||
|
configData.optStringOrNull("J2")?.let { setJ2(it) }
|
||||||
|
configData.optStringOrNull("J3")?.let { setJ3(it) }
|
||||||
|
configData.optStringOrNull("Itime")?.let { setItime(it.toInt()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun start(config: WireguardConfig, vpnBuilder: Builder, protect: (Int) -> Boolean) {
|
private fun start(config: WireguardConfig, vpnBuilder: Builder, protect: (Int) -> Boolean) {
|
||||||
|
|
|
||||||
|
|
@ -20,10 +20,21 @@ open class WireguardConfig protected constructor(
|
||||||
val jmax: Int?,
|
val jmax: Int?,
|
||||||
val s1: Int?,
|
val s1: Int?,
|
||||||
val s2: Int?,
|
val s2: Int?,
|
||||||
|
val s3: Int?,
|
||||||
|
val s4: Int?,
|
||||||
val h1: Long?,
|
val h1: Long?,
|
||||||
val h2: Long?,
|
val h2: Long?,
|
||||||
val h3: Long?,
|
val h3: Long?,
|
||||||
val h4: Long?
|
val h4: Long?,
|
||||||
|
var i1: String?,
|
||||||
|
var i2: String?,
|
||||||
|
var i3: String?,
|
||||||
|
var i4: String?,
|
||||||
|
var i5: String?,
|
||||||
|
var j1: String?,
|
||||||
|
var j2: String?,
|
||||||
|
var j3: String?,
|
||||||
|
var itime: Int?
|
||||||
) : ProtocolConfig(protocolConfigBuilder) {
|
) : ProtocolConfig(protocolConfigBuilder) {
|
||||||
|
|
||||||
protected constructor(builder: Builder) : this(
|
protected constructor(builder: Builder) : this(
|
||||||
|
|
@ -39,10 +50,21 @@ open class WireguardConfig protected constructor(
|
||||||
builder.jmax,
|
builder.jmax,
|
||||||
builder.s1,
|
builder.s1,
|
||||||
builder.s2,
|
builder.s2,
|
||||||
|
builder.s3,
|
||||||
|
builder.s4,
|
||||||
builder.h1,
|
builder.h1,
|
||||||
builder.h2,
|
builder.h2,
|
||||||
builder.h3,
|
builder.h3,
|
||||||
builder.h4
|
builder.h4,
|
||||||
|
builder.i1,
|
||||||
|
builder.i2,
|
||||||
|
builder.i3,
|
||||||
|
builder.i4,
|
||||||
|
builder.i5,
|
||||||
|
builder.j1,
|
||||||
|
builder.j2,
|
||||||
|
builder.j3,
|
||||||
|
builder.itime
|
||||||
)
|
)
|
||||||
|
|
||||||
fun toWgUserspaceString(): String = with(StringBuilder()) {
|
fun toWgUserspaceString(): String = with(StringBuilder()) {
|
||||||
|
|
@ -61,10 +83,21 @@ open class WireguardConfig protected constructor(
|
||||||
appendLine("jmax=$jmax")
|
appendLine("jmax=$jmax")
|
||||||
appendLine("s1=$s1")
|
appendLine("s1=$s1")
|
||||||
appendLine("s2=$s2")
|
appendLine("s2=$s2")
|
||||||
|
s3?.let { appendLine("s3=$it") }
|
||||||
|
s4?.let { appendLine("s4=$it") }
|
||||||
appendLine("h1=$h1")
|
appendLine("h1=$h1")
|
||||||
appendLine("h2=$h2")
|
appendLine("h2=$h2")
|
||||||
appendLine("h3=$h3")
|
appendLine("h3=$h3")
|
||||||
appendLine("h4=$h4")
|
appendLine("h4=$h4")
|
||||||
|
i1?.let { appendLine("i1=$it") }
|
||||||
|
i2?.let { appendLine("i2=$it") }
|
||||||
|
i3?.let { appendLine("i3=$it") }
|
||||||
|
i4?.let { appendLine("i4=$it") }
|
||||||
|
i5?.let { appendLine("i5=$it") }
|
||||||
|
j1?.let { appendLine("j1=$it") }
|
||||||
|
j2?.let { appendLine("j2=$it") }
|
||||||
|
j3?.let { appendLine("j3=$it") }
|
||||||
|
itime?.let { appendLine("itime=$it") }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -117,10 +150,21 @@ open class WireguardConfig protected constructor(
|
||||||
internal var jmax: Int? = null
|
internal var jmax: Int? = null
|
||||||
internal var s1: Int? = null
|
internal var s1: Int? = null
|
||||||
internal var s2: Int? = null
|
internal var s2: Int? = null
|
||||||
|
internal var s3: Int? = null
|
||||||
|
internal var s4: Int? = null
|
||||||
internal var h1: Long? = null
|
internal var h1: Long? = null
|
||||||
internal var h2: Long? = null
|
internal var h2: Long? = null
|
||||||
internal var h3: Long? = null
|
internal var h3: Long? = null
|
||||||
internal var h4: Long? = null
|
internal var h4: Long? = null
|
||||||
|
internal var i1: String? = null
|
||||||
|
internal var i2: String? = null
|
||||||
|
internal var i3: String? = null
|
||||||
|
internal var i4: String? = null
|
||||||
|
internal var i5: String? = null
|
||||||
|
internal var j1: String? = null
|
||||||
|
internal var j2: String? = null
|
||||||
|
internal var j3: String? = null
|
||||||
|
internal var itime: Int? = null
|
||||||
|
|
||||||
fun setEndpoint(endpoint: InetEndpoint) = apply { this.endpoint = endpoint }
|
fun setEndpoint(endpoint: InetEndpoint) = apply { this.endpoint = endpoint }
|
||||||
|
|
||||||
|
|
@ -139,10 +183,21 @@ open class WireguardConfig protected constructor(
|
||||||
fun setJmax(jmax: Int) = apply { this.jmax = jmax }
|
fun setJmax(jmax: Int) = apply { this.jmax = jmax }
|
||||||
fun setS1(s1: Int) = apply { this.s1 = s1 }
|
fun setS1(s1: Int) = apply { this.s1 = s1 }
|
||||||
fun setS2(s2: Int) = apply { this.s2 = s2 }
|
fun setS2(s2: Int) = apply { this.s2 = s2 }
|
||||||
|
fun setS3(s3: Int) = apply { this.s3 = s3 }
|
||||||
|
fun setS4(s4: Int) = apply { this.s4 = s4 }
|
||||||
fun setH1(h1: Long) = apply { this.h1 = h1 }
|
fun setH1(h1: Long) = apply { this.h1 = h1 }
|
||||||
fun setH2(h2: Long) = apply { this.h2 = h2 }
|
fun setH2(h2: Long) = apply { this.h2 = h2 }
|
||||||
fun setH3(h3: Long) = apply { this.h3 = h3 }
|
fun setH3(h3: Long) = apply { this.h3 = h3 }
|
||||||
fun setH4(h4: Long) = apply { this.h4 = h4 }
|
fun setH4(h4: Long) = apply { this.h4 = h4 }
|
||||||
|
fun setI1(i1: String) = apply { this.i1 = i1 }
|
||||||
|
fun setI2(i2: String) = apply { this.i2 = i2 }
|
||||||
|
fun setI3(i3: String) = apply { this.i3 = i3 }
|
||||||
|
fun setI4(i4: String) = apply { this.i4 = i4 }
|
||||||
|
fun setI5(i5: String) = apply { this.i5 = i5 }
|
||||||
|
fun setJ1(j1: String) = apply { this.j1 = j1 }
|
||||||
|
fun setJ2(j2: String) = apply { this.j2 = j2 }
|
||||||
|
fun setJ3(j3: String) = apply { this.j3 = j3 }
|
||||||
|
fun setItime(itime: Int) = apply { this.itime = itime }
|
||||||
|
|
||||||
override fun build(): WireguardConfig = configBuild().run { WireguardConfig(this@Builder) }
|
override fun build(): WireguardConfig = configBuild().run { WireguardConfig(this@Builder) }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -116,7 +116,6 @@ file(GLOB UI_MODELS_H CONFIGURE_DEPENDS
|
||||||
${CLIENT_ROOT_DIR}/ui/models/services/*.h
|
${CLIENT_ROOT_DIR}/ui/models/services/*.h
|
||||||
${CLIENT_ROOT_DIR}/ui/models/api/*.h
|
${CLIENT_ROOT_DIR}/ui/models/api/*.h
|
||||||
)
|
)
|
||||||
|
|
||||||
file(GLOB UI_MODELS_CPP CONFIGURE_DEPENDS
|
file(GLOB UI_MODELS_CPP CONFIGURE_DEPENDS
|
||||||
${CLIENT_ROOT_DIR}/ui/models/*.cpp
|
${CLIENT_ROOT_DIR}/ui/models/*.cpp
|
||||||
${CLIENT_ROOT_DIR}/ui/models/protocols/*.cpp
|
${CLIENT_ROOT_DIR}/ui/models/protocols/*.cpp
|
||||||
|
|
@ -128,33 +127,17 @@ file(GLOB UI_CONTROLLERS_H CONFIGURE_DEPENDS
|
||||||
${CLIENT_ROOT_DIR}/ui/controllers/*.h
|
${CLIENT_ROOT_DIR}/ui/controllers/*.h
|
||||||
${CLIENT_ROOT_DIR}/ui/controllers/api/*.h
|
${CLIENT_ROOT_DIR}/ui/controllers/api/*.h
|
||||||
)
|
)
|
||||||
|
|
||||||
file(GLOB UI_CONTROLLERS_CPP CONFIGURE_DEPENDS
|
file(GLOB UI_CONTROLLERS_CPP CONFIGURE_DEPENDS
|
||||||
${CLIENT_ROOT_DIR}/ui/controllers/*.cpp
|
${CLIENT_ROOT_DIR}/ui/controllers/*.cpp
|
||||||
${CLIENT_ROOT_DIR}/ui/controllers/api/*.cpp
|
${CLIENT_ROOT_DIR}/ui/controllers/api/*.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
file(GLOB CORE_MODELS_H CONFIGURE_DEPENDS
|
|
||||||
${CLIENT_ROOT_DIR}/core/models/*.h
|
|
||||||
${CLIENT_ROOT_DIR}/core/models/containers/*.h
|
|
||||||
${CLIENT_ROOT_DIR}/core/models/protocols/*.h
|
|
||||||
${CLIENT_ROOT_DIR}/core/models/servers/*.h
|
|
||||||
)
|
|
||||||
|
|
||||||
file(GLOB CORE_MODELS_CPP CONFIGURE_DEPENDS
|
|
||||||
${CLIENT_ROOT_DIR}/core/models/*.cpp
|
|
||||||
${CLIENT_ROOT_DIR}/core/models/containers/*.cpp
|
|
||||||
${CLIENT_ROOT_DIR}/core/models/protocols/*.cpp
|
|
||||||
${CLIENT_ROOT_DIR}/core/models/servers/*.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
set(HEADERS ${HEADERS}
|
set(HEADERS ${HEADERS}
|
||||||
${COMMON_FILES_H}
|
${COMMON_FILES_H}
|
||||||
${PAGE_LOGIC_H}
|
${PAGE_LOGIC_H}
|
||||||
${CONFIGURATORS_H}
|
${CONFIGURATORS_H}
|
||||||
${UI_MODELS_H}
|
${UI_MODELS_H}
|
||||||
${UI_CONTROLLERS_H}
|
${UI_CONTROLLERS_H}
|
||||||
${CORE_MODELS_H}
|
|
||||||
)
|
)
|
||||||
set(SOURCES ${SOURCES}
|
set(SOURCES ${SOURCES}
|
||||||
${COMMON_FILES_CPP}
|
${COMMON_FILES_CPP}
|
||||||
|
|
@ -162,7 +145,6 @@ set(SOURCES ${SOURCES}
|
||||||
${CONFIGURATORS_CPP}
|
${CONFIGURATORS_CPP}
|
||||||
${UI_MODELS_CPP}
|
${UI_MODELS_CPP}
|
||||||
${UI_CONTROLLERS_CPP}
|
${UI_CONTROLLERS_CPP}
|
||||||
${CORE_MODELS_CPP}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
#include "awg_configurator.h"
|
#include "awg_configurator.h"
|
||||||
|
#include "protocols/protocols_defs.h"
|
||||||
|
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
|
|
@ -39,6 +40,20 @@ QString AwgConfigurator::createConfig(const ServerCredentials &credentials, Dock
|
||||||
jsonConfig[config_key::responsePacketMagicHeader] = configMap.value(config_key::responsePacketMagicHeader);
|
jsonConfig[config_key::responsePacketMagicHeader] = configMap.value(config_key::responsePacketMagicHeader);
|
||||||
jsonConfig[config_key::underloadPacketMagicHeader] = configMap.value(config_key::underloadPacketMagicHeader);
|
jsonConfig[config_key::underloadPacketMagicHeader] = configMap.value(config_key::underloadPacketMagicHeader);
|
||||||
jsonConfig[config_key::transportPacketMagicHeader] = configMap.value(config_key::transportPacketMagicHeader);
|
jsonConfig[config_key::transportPacketMagicHeader] = configMap.value(config_key::transportPacketMagicHeader);
|
||||||
|
|
||||||
|
// jsonConfig[config_key::cookieReplyPacketJunkSize] = configMap.value(config_key::cookieReplyPacketJunkSize);
|
||||||
|
// jsonConfig[config_key::transportPacketJunkSize] = configMap.value(config_key::transportPacketJunkSize);
|
||||||
|
|
||||||
|
// jsonConfig[config_key::specialJunk1] = configMap.value(amnezia::config_key::specialJunk1);
|
||||||
|
// jsonConfig[config_key::specialJunk2] = configMap.value(amnezia::config_key::specialJunk2);
|
||||||
|
// jsonConfig[config_key::specialJunk3] = configMap.value(amnezia::config_key::specialJunk3);
|
||||||
|
// jsonConfig[config_key::specialJunk4] = configMap.value(amnezia::config_key::specialJunk4);
|
||||||
|
// jsonConfig[config_key::specialJunk5] = configMap.value(amnezia::config_key::specialJunk5);
|
||||||
|
// jsonConfig[config_key::controlledJunk1] = configMap.value(amnezia::config_key::controlledJunk1);
|
||||||
|
// jsonConfig[config_key::controlledJunk2] = configMap.value(amnezia::config_key::controlledJunk2);
|
||||||
|
// jsonConfig[config_key::controlledJunk3] = configMap.value(amnezia::config_key::controlledJunk3);
|
||||||
|
// jsonConfig[config_key::specialHandshakeTimeout] = configMap.value(amnezia::config_key::specialHandshakeTimeout);
|
||||||
|
|
||||||
jsonConfig[config_key::mtu] =
|
jsonConfig[config_key::mtu] =
|
||||||
containerConfig.value(ProtocolProps::protoToString(Proto::Awg)).toObject().value(config_key::mtu).toString(protocols::awg::defaultMtu);
|
containerConfig.value(ProtocolProps::protoToString(Proto::Awg)).toObject().value(config_key::mtu).toString(protocols::awg::defaultMtu);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -118,6 +118,12 @@ QString OpenVpnConfigurator::processConfigWithLocalSettings(const QPair<QString,
|
||||||
QRegularExpression regex("redirect-gateway.*");
|
QRegularExpression regex("redirect-gateway.*");
|
||||||
config.replace(regex, "");
|
config.replace(regex, "");
|
||||||
|
|
||||||
|
// We don't use secondary DNS if primary DNS is AmneziaDNS
|
||||||
|
if (dns.first.contains(protocols::dns::amneziaDnsIp)) {
|
||||||
|
QRegularExpression dnsRegex("dhcp-option DNS " + dns.second);
|
||||||
|
config.replace(dnsRegex, "");
|
||||||
|
}
|
||||||
|
|
||||||
if (!m_settings->isSitesSplitTunnelingEnabled()) {
|
if (!m_settings->isSitesSplitTunnelingEnabled()) {
|
||||||
config.append("\nredirect-gateway def1 ipv6 bypass-dhcp\n");
|
config.append("\nredirect-gateway def1 ipv6 bypass-dhcp\n");
|
||||||
config.append("block-ipv6\n");
|
config.append("block-ipv6\n");
|
||||||
|
|
@ -161,6 +167,12 @@ QString OpenVpnConfigurator::processConfigWithExportSettings(const QPair<QString
|
||||||
QRegularExpression regex("redirect-gateway.*");
|
QRegularExpression regex("redirect-gateway.*");
|
||||||
config.replace(regex, "");
|
config.replace(regex, "");
|
||||||
|
|
||||||
|
// We don't use secondary DNS if primary DNS is AmneziaDNS
|
||||||
|
if (dns.first.contains(protocols::dns::amneziaDnsIp)) {
|
||||||
|
QRegularExpression dnsRegex("dhcp-option DNS " + dns.second);
|
||||||
|
config.replace(dnsRegex, "");
|
||||||
|
}
|
||||||
|
|
||||||
config.append("\nredirect-gateway def1 ipv6 bypass-dhcp\n");
|
config.append("\nredirect-gateway def1 ipv6 bypass-dhcp\n");
|
||||||
|
|
||||||
// Prevent ipv6 leak
|
// Prevent ipv6 leak
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,11 @@ namespace apiDefs
|
||||||
ExternalPremium
|
ExternalPremium
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum ConfigSource {
|
||||||
|
Telegram = 1,
|
||||||
|
AmneziaGateway
|
||||||
|
};
|
||||||
|
|
||||||
namespace key
|
namespace key
|
||||||
{
|
{
|
||||||
constexpr QLatin1String configVersion("config_version");
|
constexpr QLatin1String configVersion("config_version");
|
||||||
|
|
@ -27,6 +32,7 @@ namespace apiDefs
|
||||||
constexpr QLatin1String stackType("stack_type");
|
constexpr QLatin1String stackType("stack_type");
|
||||||
constexpr QLatin1String serviceType("service_type");
|
constexpr QLatin1String serviceType("service_type");
|
||||||
constexpr QLatin1String cliVersion("cli_version");
|
constexpr QLatin1String cliVersion("cli_version");
|
||||||
|
constexpr QLatin1String supportedProtocols("supported_protocols");
|
||||||
|
|
||||||
constexpr QLatin1String vpnKey("vpn_key");
|
constexpr QLatin1String vpnKey("vpn_key");
|
||||||
constexpr QLatin1String config("config");
|
constexpr QLatin1String config("config");
|
||||||
|
|
|
||||||
|
|
@ -32,8 +32,8 @@ bool apiUtils::isServerFromApi(const QJsonObject &serverConfigObject)
|
||||||
{
|
{
|
||||||
auto configVersion = serverConfigObject.value(apiDefs::key::configVersion).toInt();
|
auto configVersion = serverConfigObject.value(apiDefs::key::configVersion).toInt();
|
||||||
switch (configVersion) {
|
switch (configVersion) {
|
||||||
case amnezia::ServerConfigType::ApiV1: return true;
|
case apiDefs::ConfigSource::Telegram: return true;
|
||||||
case amnezia::ServerConfigType::ApiV2: return true;
|
case apiDefs::ConfigSource::AmneziaGateway: return true;
|
||||||
default: return false;
|
default: return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -43,7 +43,7 @@ apiDefs::ConfigType apiUtils::getConfigType(const QJsonObject &serverConfigObjec
|
||||||
auto configVersion = serverConfigObject.value(apiDefs::key::configVersion).toInt();
|
auto configVersion = serverConfigObject.value(apiDefs::key::configVersion).toInt();
|
||||||
|
|
||||||
switch (configVersion) {
|
switch (configVersion) {
|
||||||
case amnezia::ServerConfigType::ApiV1: {
|
case apiDefs::ConfigSource::Telegram: {
|
||||||
constexpr QLatin1String freeV2Endpoint(FREE_V2_ENDPOINT);
|
constexpr QLatin1String freeV2Endpoint(FREE_V2_ENDPOINT);
|
||||||
constexpr QLatin1String premiumV1Endpoint(PREM_V1_ENDPOINT);
|
constexpr QLatin1String premiumV1Endpoint(PREM_V1_ENDPOINT);
|
||||||
|
|
||||||
|
|
@ -55,7 +55,7 @@ apiDefs::ConfigType apiUtils::getConfigType(const QJsonObject &serverConfigObjec
|
||||||
return apiDefs::ConfigType::AmneziaFreeV2;
|
return apiDefs::ConfigType::AmneziaFreeV2;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
case amnezia::ServerConfigType::ApiV2: {
|
case apiDefs::ConfigSource::AmneziaGateway: {
|
||||||
constexpr QLatin1String servicePremium("amnezia-premium");
|
constexpr QLatin1String servicePremium("amnezia-premium");
|
||||||
constexpr QLatin1String serviceFree("amnezia-free");
|
constexpr QLatin1String serviceFree("amnezia-free");
|
||||||
constexpr QLatin1String serviceExternalPremium("external-premium");
|
constexpr QLatin1String serviceExternalPremium("external-premium");
|
||||||
|
|
@ -77,9 +77,9 @@ apiDefs::ConfigType apiUtils::getConfigType(const QJsonObject &serverConfigObjec
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
amnezia::ServerConfigType apiUtils::getConfigSource(const QJsonObject &serverConfigObject)
|
apiDefs::ConfigSource apiUtils::getConfigSource(const QJsonObject &serverConfigObject)
|
||||||
{
|
{
|
||||||
return static_cast<amnezia::ServerConfigType>(serverConfigObject.value(apiDefs::key::configVersion).toInt());
|
return static_cast<apiDefs::ConfigSource>(serverConfigObject.value(apiDefs::key::configVersion).toInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
amnezia::ErrorCode apiUtils::checkNetworkReplyErrors(const QList<QSslError> &sslErrors, QNetworkReply *reply)
|
amnezia::ErrorCode apiUtils::checkNetworkReplyErrors(const QList<QSslError> &sslErrors, QNetworkReply *reply)
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ namespace apiUtils
|
||||||
bool isPremiumServer(const QJsonObject &serverConfigObject);
|
bool isPremiumServer(const QJsonObject &serverConfigObject);
|
||||||
|
|
||||||
apiDefs::ConfigType getConfigType(const QJsonObject &serverConfigObject);
|
apiDefs::ConfigType getConfigType(const QJsonObject &serverConfigObject);
|
||||||
amnezia::ServerConfigType getConfigSource(const QJsonObject &serverConfigObject);
|
apiDefs::ConfigSource getConfigSource(const QJsonObject &serverConfigObject);
|
||||||
|
|
||||||
amnezia::ErrorCode checkNetworkReplyErrors(const QList<QSslError> &sslErrors, QNetworkReply *reply);
|
amnezia::ErrorCode checkNetworkReplyErrors(const QList<QSslError> &sslErrors, QNetworkReply *reply);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,43 +54,38 @@ void CoreController::initModels()
|
||||||
m_appSplitTunnelingModel.reset(new AppSplitTunnelingModel(m_settings, this));
|
m_appSplitTunnelingModel.reset(new AppSplitTunnelingModel(m_settings, this));
|
||||||
m_engine->rootContext()->setContextProperty("AppSplitTunnelingModel", m_appSplitTunnelingModel.get());
|
m_engine->rootContext()->setContextProperty("AppSplitTunnelingModel", m_appSplitTunnelingModel.get());
|
||||||
|
|
||||||
m_openVpnConfigModel = QSharedPointer<OpenVpnConfigModel>::create(this);
|
m_protocolsModel.reset(new ProtocolsModel(m_settings, this));
|
||||||
|
m_engine->rootContext()->setContextProperty("ProtocolsModel", m_protocolsModel.get());
|
||||||
|
|
||||||
|
m_openVpnConfigModel.reset(new OpenVpnConfigModel(this));
|
||||||
m_engine->rootContext()->setContextProperty("OpenVpnConfigModel", m_openVpnConfigModel.get());
|
m_engine->rootContext()->setContextProperty("OpenVpnConfigModel", m_openVpnConfigModel.get());
|
||||||
|
|
||||||
m_shadowSocksConfigModel = QSharedPointer<ShadowSocksConfigModel>::create(this);
|
m_shadowSocksConfigModel.reset(new ShadowSocksConfigModel(this));
|
||||||
m_engine->rootContext()->setContextProperty("ShadowSocksConfigModel", m_shadowSocksConfigModel.get());
|
m_engine->rootContext()->setContextProperty("ShadowSocksConfigModel", m_shadowSocksConfigModel.get());
|
||||||
|
|
||||||
m_cloakConfigModel = QSharedPointer<CloakConfigModel>::create(this);
|
m_cloakConfigModel.reset(new CloakConfigModel(this));
|
||||||
m_engine->rootContext()->setContextProperty("CloakConfigModel", m_cloakConfigModel.get());
|
m_engine->rootContext()->setContextProperty("CloakConfigModel", m_cloakConfigModel.get());
|
||||||
|
|
||||||
m_wireGuardConfigModel = QSharedPointer<WireGuardConfigModel>::create(this);
|
m_wireGuardConfigModel.reset(new WireGuardConfigModel(this));
|
||||||
m_engine->rootContext()->setContextProperty("WireGuardConfigModel", m_wireGuardConfigModel.get());
|
m_engine->rootContext()->setContextProperty("WireGuardConfigModel", m_wireGuardConfigModel.get());
|
||||||
|
|
||||||
m_awgConfigModel = QSharedPointer<AwgConfigModel>::create(this);
|
m_awgConfigModel.reset(new AwgConfigModel(this));
|
||||||
m_engine->rootContext()->setContextProperty("AwgConfigModel", m_awgConfigModel.get());
|
m_engine->rootContext()->setContextProperty("AwgConfigModel", m_awgConfigModel.get());
|
||||||
|
|
||||||
m_xrayConfigModel = QSharedPointer<XrayConfigModel>::create(this);
|
m_xrayConfigModel.reset(new XrayConfigModel(this));
|
||||||
m_engine->rootContext()->setContextProperty("XrayConfigModel", m_xrayConfigModel.get());
|
m_engine->rootContext()->setContextProperty("XrayConfigModel", m_xrayConfigModel.get());
|
||||||
|
|
||||||
#ifdef Q_OS_WINDOWS
|
#ifdef Q_OS_WINDOWS
|
||||||
m_ikev2ConfigModel = QSharedPointer<Ikev2ConfigModel>::create(this);
|
m_ikev2ConfigModel.reset(new Ikev2ConfigModel(this));
|
||||||
m_engine->rootContext()->setContextProperty("Ikev2ConfigModel", m_ikev2ConfigModel.get());
|
m_engine->rootContext()->setContextProperty("Ikev2ConfigModel", m_ikev2ConfigModel.get());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
m_sftpConfigModel = QSharedPointer<SftpConfigModel>::create(this);
|
m_sftpConfigModel.reset(new SftpConfigModel(this));
|
||||||
m_engine->rootContext()->setContextProperty("SftpConfigModel", m_sftpConfigModel.get());
|
m_engine->rootContext()->setContextProperty("SftpConfigModel", m_sftpConfigModel.get());
|
||||||
|
|
||||||
m_socks5ConfigModel = QSharedPointer<Socks5ProxyConfigModel>::create(this);
|
m_socks5ConfigModel.reset(new Socks5ProxyConfigModel(this));
|
||||||
m_engine->rootContext()->setContextProperty("Socks5ProxyConfigModel", m_socks5ConfigModel.get());
|
m_engine->rootContext()->setContextProperty("Socks5ProxyConfigModel", m_socks5ConfigModel.get());
|
||||||
|
|
||||||
m_protocolsModel.reset(new ProtocolsModel(m_openVpnConfigModel, m_shadowSocksConfigModel, m_cloakConfigModel, m_wireGuardConfigModel,
|
|
||||||
m_awgConfigModel, m_xrayConfigModel,
|
|
||||||
#ifdef Q_OS_WINDOWS
|
|
||||||
m_ikev2ConfigModel,
|
|
||||||
#endif
|
|
||||||
m_sftpConfigModel, m_socks5ConfigModel, this));
|
|
||||||
m_engine->rootContext()->setContextProperty("ProtocolsModel", m_protocolsModel.get());
|
|
||||||
|
|
||||||
m_clientManagementModel.reset(new ClientManagementModel(m_settings, this));
|
m_clientManagementModel.reset(new ClientManagementModel(m_settings, this));
|
||||||
m_engine->rootContext()->setContextProperty("ClientManagementModel", m_clientManagementModel.get());
|
m_engine->rootContext()->setContextProperty("ClientManagementModel", m_clientManagementModel.get());
|
||||||
|
|
||||||
|
|
@ -304,10 +299,13 @@ void CoreController::setQmlRoot()
|
||||||
|
|
||||||
void CoreController::initApiCountryModelUpdateHandler()
|
void CoreController::initApiCountryModelUpdateHandler()
|
||||||
{
|
{
|
||||||
|
// TODO
|
||||||
connect(m_serversModel.get(), &ServersModel::updateApiCountryModel, this, [this]() {
|
connect(m_serversModel.get(), &ServersModel::updateApiCountryModel, this, [this]() {
|
||||||
m_apiCountryModel->updateModel(m_serversModel->getProcessedServerData("apiAvailableCountries").toJsonArray(),
|
m_apiCountryModel->updateModel(m_serversModel->getProcessedServerData("apiAvailableCountries").toJsonArray(),
|
||||||
m_serversModel->getProcessedServerData("apiServerCountryCode").toString());
|
m_serversModel->getProcessedServerData("apiServerCountryCode").toString());
|
||||||
});
|
});
|
||||||
|
connect(m_serversModel.get(), &ServersModel::updateApiServicesModel, this,
|
||||||
|
[this]() { m_apiServicesModel->updateModel(m_serversModel->getProcessedServerData("apiConfig").toJsonObject()); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoreController::initContainerModelUpdateHandler()
|
void CoreController::initContainerModelUpdateHandler()
|
||||||
|
|
|
||||||
|
|
@ -129,17 +129,17 @@ private:
|
||||||
QSharedPointer<ApiAccountInfoModel> m_apiAccountInfoModel;
|
QSharedPointer<ApiAccountInfoModel> m_apiAccountInfoModel;
|
||||||
QSharedPointer<ApiDevicesModel> m_apiDevicesModel;
|
QSharedPointer<ApiDevicesModel> m_apiDevicesModel;
|
||||||
|
|
||||||
QSharedPointer<OpenVpnConfigModel> m_openVpnConfigModel;
|
QScopedPointer<OpenVpnConfigModel> m_openVpnConfigModel;
|
||||||
QSharedPointer<ShadowSocksConfigModel> m_shadowSocksConfigModel;
|
QScopedPointer<ShadowSocksConfigModel> m_shadowSocksConfigModel;
|
||||||
QSharedPointer<CloakConfigModel> m_cloakConfigModel;
|
QScopedPointer<CloakConfigModel> m_cloakConfigModel;
|
||||||
QSharedPointer<XrayConfigModel> m_xrayConfigModel;
|
QScopedPointer<XrayConfigModel> m_xrayConfigModel;
|
||||||
QSharedPointer<WireGuardConfigModel> m_wireGuardConfigModel;
|
QScopedPointer<WireGuardConfigModel> m_wireGuardConfigModel;
|
||||||
QSharedPointer<AwgConfigModel> m_awgConfigModel;
|
QScopedPointer<AwgConfigModel> m_awgConfigModel;
|
||||||
#ifdef Q_OS_WINDOWS
|
#ifdef Q_OS_WINDOWS
|
||||||
QSharedPointer<Ikev2ConfigModel> m_ikev2ConfigModel;
|
QScopedPointer<Ikev2ConfigModel> m_ikev2ConfigModel;
|
||||||
#endif
|
#endif
|
||||||
QSharedPointer<SftpConfigModel> m_sftpConfigModel;
|
QScopedPointer<SftpConfigModel> m_sftpConfigModel;
|
||||||
QSharedPointer<Socks5ProxyConfigModel> m_socks5ConfigModel;
|
QScopedPointer<Socks5ProxyConfigModel> m_socks5ConfigModel;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CORECONTROLLER_H
|
#endif // CORECONTROLLER_H
|
||||||
|
|
|
||||||
|
|
@ -349,7 +349,7 @@ bool ServerController::isReinstallContainerRequired(DockerContainer container, c
|
||||||
if ((oldProtoConfig.value(config_key::subnet_address).toString(protocols::wireguard::defaultSubnetAddress)
|
if ((oldProtoConfig.value(config_key::subnet_address).toString(protocols::wireguard::defaultSubnetAddress)
|
||||||
!= newProtoConfig.value(config_key::subnet_address).toString(protocols::wireguard::defaultSubnetAddress))
|
!= newProtoConfig.value(config_key::subnet_address).toString(protocols::wireguard::defaultSubnetAddress))
|
||||||
|| (oldProtoConfig.value(config_key::port).toString(protocols::awg::defaultPort)
|
|| (oldProtoConfig.value(config_key::port).toString(protocols::awg::defaultPort)
|
||||||
!= newProtoConfig.value(config_key::port).toString(protocols::awg::defaultPort))
|
!= newProtoConfig.value(config_key::port).toString(protocols::awg::defaultPort))
|
||||||
|| (oldProtoConfig.value(config_key::junkPacketCount).toString(protocols::awg::defaultJunkPacketCount)
|
|| (oldProtoConfig.value(config_key::junkPacketCount).toString(protocols::awg::defaultJunkPacketCount)
|
||||||
!= newProtoConfig.value(config_key::junkPacketCount).toString(protocols::awg::defaultJunkPacketCount))
|
!= newProtoConfig.value(config_key::junkPacketCount).toString(protocols::awg::defaultJunkPacketCount))
|
||||||
|| (oldProtoConfig.value(config_key::junkPacketMinSize).toString(protocols::awg::defaultJunkPacketMinSize)
|
|| (oldProtoConfig.value(config_key::junkPacketMinSize).toString(protocols::awg::defaultJunkPacketMinSize)
|
||||||
|
|
@ -366,8 +366,13 @@ bool ServerController::isReinstallContainerRequired(DockerContainer container, c
|
||||||
!= newProtoConfig.value(config_key::responsePacketMagicHeader).toString(protocols::awg::defaultResponsePacketMagicHeader))
|
!= newProtoConfig.value(config_key::responsePacketMagicHeader).toString(protocols::awg::defaultResponsePacketMagicHeader))
|
||||||
|| (oldProtoConfig.value(config_key::underloadPacketMagicHeader).toString(protocols::awg::defaultUnderloadPacketMagicHeader)
|
|| (oldProtoConfig.value(config_key::underloadPacketMagicHeader).toString(protocols::awg::defaultUnderloadPacketMagicHeader)
|
||||||
!= newProtoConfig.value(config_key::underloadPacketMagicHeader).toString(protocols::awg::defaultUnderloadPacketMagicHeader))
|
!= newProtoConfig.value(config_key::underloadPacketMagicHeader).toString(protocols::awg::defaultUnderloadPacketMagicHeader))
|
||||||
|| (oldProtoConfig.value(config_key::transportPacketMagicHeader).toString(protocols::awg::defaultTransportPacketMagicHeader)
|
|| (oldProtoConfig.value(config_key::transportPacketMagicHeader).toString(protocols::awg::defaultTransportPacketMagicHeader))
|
||||||
!= newProtoConfig.value(config_key::transportPacketMagicHeader).toString(protocols::awg::defaultTransportPacketMagicHeader)))
|
!= newProtoConfig.value(config_key::transportPacketMagicHeader).toString(protocols::awg::defaultTransportPacketMagicHeader))
|
||||||
|
// || (oldProtoConfig.value(config_key::cookieReplyPacketJunkSize).toString(protocols::awg::defaultCookieReplyPacketJunkSize)
|
||||||
|
// != newProtoConfig.value(config_key::cookieReplyPacketJunkSize).toString(protocols::awg::defaultCookieReplyPacketJunkSize))
|
||||||
|
// || (oldProtoConfig.value(config_key::transportPacketJunkSize).toString(protocols::awg::defaultTransportPacketJunkSize)
|
||||||
|
// != newProtoConfig.value(config_key::transportPacketJunkSize).toString(protocols::awg::defaultTransportPacketJunkSize))
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -375,7 +380,7 @@ bool ServerController::isReinstallContainerRequired(DockerContainer container, c
|
||||||
if ((oldProtoConfig.value(config_key::subnet_address).toString(protocols::wireguard::defaultSubnetAddress)
|
if ((oldProtoConfig.value(config_key::subnet_address).toString(protocols::wireguard::defaultSubnetAddress)
|
||||||
!= newProtoConfig.value(config_key::subnet_address).toString(protocols::wireguard::defaultSubnetAddress))
|
!= newProtoConfig.value(config_key::subnet_address).toString(protocols::wireguard::defaultSubnetAddress))
|
||||||
|| (oldProtoConfig.value(config_key::port).toString(protocols::wireguard::defaultPort)
|
|| (oldProtoConfig.value(config_key::port).toString(protocols::wireguard::defaultPort)
|
||||||
!= newProtoConfig.value(config_key::port).toString(protocols::wireguard::defaultPort)))
|
!= newProtoConfig.value(config_key::port).toString(protocols::wireguard::defaultPort)))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -460,6 +465,8 @@ ErrorCode ServerController::buildContainerWorker(const ServerCredentials &creden
|
||||||
return ErrorCode::ServerDockerOnCgroupsV2;
|
return ErrorCode::ServerDockerOnCgroupsV2;
|
||||||
if (stdOut.contains("cgroup mountpoint does not exist"))
|
if (stdOut.contains("cgroup mountpoint does not exist"))
|
||||||
return ErrorCode::ServerCgroupMountpoint;
|
return ErrorCode::ServerCgroupMountpoint;
|
||||||
|
if (stdOut.contains("have reached") && stdOut.contains("pull rate limit"))
|
||||||
|
return ErrorCode::DockerPullRateLimit;
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
@ -639,6 +646,9 @@ ServerController::Vars ServerController::genVarsForScript(const ServerCredential
|
||||||
vars.append({ { "$UNDERLOAD_PACKET_MAGIC_HEADER", amneziaWireguarConfig.value(config_key::underloadPacketMagicHeader).toString() } });
|
vars.append({ { "$UNDERLOAD_PACKET_MAGIC_HEADER", amneziaWireguarConfig.value(config_key::underloadPacketMagicHeader).toString() } });
|
||||||
vars.append({ { "$TRANSPORT_PACKET_MAGIC_HEADER", amneziaWireguarConfig.value(config_key::transportPacketMagicHeader).toString() } });
|
vars.append({ { "$TRANSPORT_PACKET_MAGIC_HEADER", amneziaWireguarConfig.value(config_key::transportPacketMagicHeader).toString() } });
|
||||||
|
|
||||||
|
vars.append({ { "$COOKIE_REPLY_PACKET_JUNK_SIZE", amneziaWireguarConfig.value(config_key::cookieReplyPacketJunkSize).toString() } });
|
||||||
|
vars.append({ { "$TRANSPORT_PACKET_JUNK_SIZE", amneziaWireguarConfig.value(config_key::transportPacketJunkSize).toString() } });
|
||||||
|
|
||||||
// Socks5 proxy vars
|
// Socks5 proxy vars
|
||||||
vars.append({ { "$SOCKS5_PROXY_PORT", socks5ProxyConfig.value(config_key::port).toString(protocols::socks5Proxy::defaultPort) } });
|
vars.append({ { "$SOCKS5_PROXY_PORT", socks5ProxyConfig.value(config_key::port).toString(protocols::socks5Proxy::defaultPort) } });
|
||||||
auto username = socks5ProxyConfig.value(config_key::userName).toString();
|
auto username = socks5ProxyConfig.value(config_key::userName).toString();
|
||||||
|
|
@ -825,7 +835,7 @@ ErrorCode ServerController::isServerDpkgBusy(const ServerCredentials &credential
|
||||||
|
|
||||||
if (stdOut.contains("Packet manager not found"))
|
if (stdOut.contains("Packet manager not found"))
|
||||||
return ErrorCode::ServerPacketManagerError;
|
return ErrorCode::ServerPacketManagerError;
|
||||||
if (stdOut.contains("fuser not installed"))
|
if (stdOut.contains("fuser not installed") || stdOut.contains("cat not installed"))
|
||||||
return ErrorCode::NoError;
|
return ErrorCode::NoError;
|
||||||
|
|
||||||
if (stdOut.isEmpty()) {
|
if (stdOut.isEmpty()) {
|
||||||
|
|
|
||||||
|
|
@ -19,13 +19,6 @@ namespace amnezia
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
enum ServerConfigType
|
|
||||||
{
|
|
||||||
SelfHosted,
|
|
||||||
ApiV1,
|
|
||||||
ApiV2
|
|
||||||
};
|
|
||||||
|
|
||||||
struct InstalledAppInfo {
|
struct InstalledAppInfo {
|
||||||
QString appName;
|
QString appName;
|
||||||
QString packageName;
|
QString packageName;
|
||||||
|
|
@ -67,6 +60,7 @@ namespace amnezia
|
||||||
ServerUserPasswordRequired = 210,
|
ServerUserPasswordRequired = 210,
|
||||||
ServerDockerOnCgroupsV2 = 211,
|
ServerDockerOnCgroupsV2 = 211,
|
||||||
ServerCgroupMountpoint = 212,
|
ServerCgroupMountpoint = 212,
|
||||||
|
DockerPullRateLimit = 213,
|
||||||
|
|
||||||
// Ssh connection errors
|
// Ssh connection errors
|
||||||
SshRequestDeniedError = 300,
|
SshRequestDeniedError = 300,
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ QString errorString(ErrorCode code) {
|
||||||
case(ErrorCode::ServerUserPasswordRequired): errorMessage = QObject::tr("The user's password is required"); break;
|
case(ErrorCode::ServerUserPasswordRequired): errorMessage = QObject::tr("The user's password is required"); break;
|
||||||
case(ErrorCode::ServerDockerOnCgroupsV2): errorMessage = QObject::tr("Docker error: runc doesn't work on cgroups v2"); break;
|
case(ErrorCode::ServerDockerOnCgroupsV2): errorMessage = QObject::tr("Docker error: runc doesn't work on cgroups v2"); break;
|
||||||
case(ErrorCode::ServerCgroupMountpoint): errorMessage = QObject::tr("Server error: cgroup mountpoint does not exist"); break;
|
case(ErrorCode::ServerCgroupMountpoint): errorMessage = QObject::tr("Server error: cgroup mountpoint does not exist"); break;
|
||||||
|
case(ErrorCode::DockerPullRateLimit): errorMessage = QObject::tr("Docker error: The pull rate limit has been reached"); break;
|
||||||
|
|
||||||
// Libssh errors
|
// Libssh errors
|
||||||
case(ErrorCode::SshRequestDeniedError): errorMessage = QObject::tr("SSH request was denied"); break;
|
case(ErrorCode::SshRequestDeniedError): errorMessage = QObject::tr("SSH request was denied"); break;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
#include "containerConfig.h"
|
|
||||||
|
|
||||||
ContainerConfig::ContainerConfig()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
#ifndef CONTAINERCONFIG_H
|
|
||||||
#define CONTAINERCONFIG_H
|
|
||||||
|
|
||||||
#include <QMap>
|
|
||||||
#include <QSharedPointer>
|
|
||||||
#include <QString>
|
|
||||||
|
|
||||||
#include "core/models/protocols/protocolConfig.h"
|
|
||||||
|
|
||||||
class ContainerConfig
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
ContainerConfig();
|
|
||||||
|
|
||||||
QString containerName;
|
|
||||||
QMap<QString, QSharedPointer<ProtocolConfig>> protocolConfigs;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // CONTAINERCONFIG_H
|
|
||||||
|
|
@ -1,242 +0,0 @@
|
||||||
#include "awgProtocolConfig.h"
|
|
||||||
|
|
||||||
#include <QJsonArray>
|
|
||||||
#include <QJsonDocument>
|
|
||||||
|
|
||||||
#include "protocols/protocols_defs.h"
|
|
||||||
|
|
||||||
using namespace amnezia;
|
|
||||||
|
|
||||||
AwgProtocolConfig::AwgProtocolConfig(const QString &protocolName) : ProtocolConfig(protocolName)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
AwgProtocolConfig::AwgProtocolConfig(const QJsonObject &protocolConfigObject, const QString &protocolName) : ProtocolConfig(protocolName)
|
|
||||||
{
|
|
||||||
serverProtocolConfig.port = protocolConfigObject.value(config_key::port).toString();
|
|
||||||
serverProtocolConfig.transportProto = protocolConfigObject.value(config_key::transport_proto).toString();
|
|
||||||
serverProtocolConfig.subnetAddress = protocolConfigObject.value(config_key::subnet_address).toString();
|
|
||||||
|
|
||||||
serverProtocolConfig.awgData.junkPacketCount = protocolConfigObject.value(config_key::junkPacketCount).toString();
|
|
||||||
serverProtocolConfig.awgData.junkPacketMinSize = protocolConfigObject.value(config_key::junkPacketMinSize).toString();
|
|
||||||
serverProtocolConfig.awgData.junkPacketMaxSize = protocolConfigObject.value(config_key::junkPacketMaxSize).toString();
|
|
||||||
serverProtocolConfig.awgData.initPacketJunkSize = protocolConfigObject.value(config_key::initPacketJunkSize).toString();
|
|
||||||
serverProtocolConfig.awgData.responsePacketJunkSize = protocolConfigObject.value(config_key::responsePacketJunkSize).toString();
|
|
||||||
serverProtocolConfig.awgData.initPacketMagicHeader = protocolConfigObject.value(config_key::initPacketMagicHeader).toString();
|
|
||||||
serverProtocolConfig.awgData.responsePacketMagicHeader = protocolConfigObject.value(config_key::responsePacketMagicHeader).toString();
|
|
||||||
serverProtocolConfig.awgData.underloadPacketMagicHeader = protocolConfigObject.value(config_key::underloadPacketMagicHeader).toString();
|
|
||||||
serverProtocolConfig.awgData.transportPacketMagicHeader = protocolConfigObject.value(config_key::transportPacketMagicHeader).toString();
|
|
||||||
|
|
||||||
auto clientProtocolString = protocolConfigObject.value(config_key::last_config).toString();
|
|
||||||
if (!clientProtocolString.isEmpty()) {
|
|
||||||
clientProtocolConfig.isEmpty = false;
|
|
||||||
|
|
||||||
QJsonObject clientProtocolConfigObject = QJsonDocument::fromJson(clientProtocolString.toUtf8()).object();
|
|
||||||
|
|
||||||
clientProtocolConfig.awgData.junkPacketCount = clientProtocolConfigObject.value(config_key::junkPacketCount).toString();
|
|
||||||
clientProtocolConfig.awgData.junkPacketMinSize = clientProtocolConfigObject.value(config_key::junkPacketMinSize).toString();
|
|
||||||
clientProtocolConfig.awgData.junkPacketMaxSize = clientProtocolConfigObject.value(config_key::junkPacketMaxSize).toString();
|
|
||||||
clientProtocolConfig.awgData.initPacketJunkSize = clientProtocolConfigObject.value(config_key::initPacketJunkSize).toString();
|
|
||||||
clientProtocolConfig.awgData.responsePacketJunkSize = clientProtocolConfigObject.value(config_key::responsePacketJunkSize).toString();
|
|
||||||
clientProtocolConfig.awgData.initPacketMagicHeader = clientProtocolConfigObject.value(config_key::initPacketMagicHeader).toString();
|
|
||||||
clientProtocolConfig.awgData.responsePacketMagicHeader =
|
|
||||||
clientProtocolConfigObject.value(config_key::responsePacketMagicHeader).toString();
|
|
||||||
clientProtocolConfig.awgData.underloadPacketMagicHeader =
|
|
||||||
clientProtocolConfigObject.value(config_key::underloadPacketMagicHeader).toString();
|
|
||||||
clientProtocolConfig.awgData.transportPacketMagicHeader =
|
|
||||||
clientProtocolConfigObject.value(config_key::transportPacketMagicHeader).toString();
|
|
||||||
|
|
||||||
clientProtocolConfig.clientId = clientProtocolConfigObject.value(config_key::clientId).toString();
|
|
||||||
|
|
||||||
clientProtocolConfig.wireGuardData.clientIp = clientProtocolConfigObject.value(config_key::client_ip).toString();
|
|
||||||
clientProtocolConfig.wireGuardData.clientPrivateKey = clientProtocolConfigObject.value(config_key::client_priv_key).toString();
|
|
||||||
clientProtocolConfig.wireGuardData.clientPublicKey = clientProtocolConfigObject.value(config_key::client_pub_key).toString();
|
|
||||||
clientProtocolConfig.wireGuardData.persistentKeepAlive =
|
|
||||||
clientProtocolConfigObject.value(config_key::persistent_keep_alive).toString();
|
|
||||||
clientProtocolConfig.wireGuardData.pskKey = clientProtocolConfigObject.value(config_key::psk_key).toString();
|
|
||||||
clientProtocolConfig.wireGuardData.serverPubKey = clientProtocolConfigObject.value(config_key::server_pub_key).toString();
|
|
||||||
clientProtocolConfig.wireGuardData.mtu = clientProtocolConfigObject.value(config_key::mtu).toString();
|
|
||||||
|
|
||||||
clientProtocolConfig.hostname = clientProtocolConfigObject.value(config_key::hostName).toString();
|
|
||||||
clientProtocolConfig.port = clientProtocolConfigObject.value(config_key::port).toInt(0);
|
|
||||||
|
|
||||||
clientProtocolConfig.nativeConfig = clientProtocolConfigObject.value(config_key::config).toString();
|
|
||||||
|
|
||||||
if (clientProtocolConfigObject.contains(config_key::allowed_ips)
|
|
||||||
&& clientProtocolConfigObject.value(config_key::allowed_ips).isArray()) {
|
|
||||||
auto allowedIpsArray = clientProtocolConfigObject.value(config_key::allowed_ips).toArray();
|
|
||||||
for (const auto &ip : allowedIpsArray) {
|
|
||||||
clientProtocolConfig.wireGuardData.allowedIps.append(ip.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
AwgProtocolConfig::AwgProtocolConfig(const AwgProtocolConfig &other) : ProtocolConfig(other.protocolName)
|
|
||||||
{
|
|
||||||
serverProtocolConfig = other.serverProtocolConfig;
|
|
||||||
clientProtocolConfig = other.clientProtocolConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
QJsonObject AwgProtocolConfig::toJson() const
|
|
||||||
{
|
|
||||||
QJsonObject json;
|
|
||||||
|
|
||||||
if (!serverProtocolConfig.port.isEmpty()) {
|
|
||||||
json[config_key::port] = serverProtocolConfig.port;
|
|
||||||
}
|
|
||||||
if (!serverProtocolConfig.transportProto.isEmpty()) {
|
|
||||||
json[config_key::transport_proto] = serverProtocolConfig.transportProto;
|
|
||||||
}
|
|
||||||
if (!serverProtocolConfig.subnetAddress.isEmpty()) {
|
|
||||||
json[config_key::subnet_address] = serverProtocolConfig.subnetAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!serverProtocolConfig.awgData.junkPacketCount.isEmpty()) {
|
|
||||||
json[config_key::junkPacketCount] = serverProtocolConfig.awgData.junkPacketCount;
|
|
||||||
}
|
|
||||||
if (!serverProtocolConfig.awgData.junkPacketMinSize.isEmpty()) {
|
|
||||||
json[config_key::junkPacketMinSize] = serverProtocolConfig.awgData.junkPacketMinSize;
|
|
||||||
}
|
|
||||||
if (!serverProtocolConfig.awgData.junkPacketMaxSize.isEmpty()) {
|
|
||||||
json[config_key::junkPacketMaxSize] = serverProtocolConfig.awgData.junkPacketMaxSize;
|
|
||||||
}
|
|
||||||
if (!serverProtocolConfig.awgData.initPacketJunkSize.isEmpty()) {
|
|
||||||
json[config_key::initPacketJunkSize] = serverProtocolConfig.awgData.initPacketJunkSize;
|
|
||||||
}
|
|
||||||
if (!serverProtocolConfig.awgData.responsePacketJunkSize.isEmpty()) {
|
|
||||||
json[config_key::responsePacketJunkSize] = serverProtocolConfig.awgData.responsePacketJunkSize;
|
|
||||||
}
|
|
||||||
if (!serverProtocolConfig.awgData.initPacketMagicHeader.isEmpty()) {
|
|
||||||
json[config_key::initPacketMagicHeader] = serverProtocolConfig.awgData.initPacketMagicHeader;
|
|
||||||
}
|
|
||||||
if (!serverProtocolConfig.awgData.responsePacketMagicHeader.isEmpty()) {
|
|
||||||
json[config_key::responsePacketMagicHeader] = serverProtocolConfig.awgData.responsePacketMagicHeader;
|
|
||||||
}
|
|
||||||
if (!serverProtocolConfig.awgData.underloadPacketMagicHeader.isEmpty()) {
|
|
||||||
json[config_key::underloadPacketMagicHeader] = serverProtocolConfig.awgData.underloadPacketMagicHeader;
|
|
||||||
}
|
|
||||||
if (!serverProtocolConfig.awgData.transportPacketMagicHeader.isEmpty()) {
|
|
||||||
json[config_key::transportPacketMagicHeader] = serverProtocolConfig.awgData.transportPacketMagicHeader;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!clientProtocolConfig.isEmpty) {
|
|
||||||
QJsonObject clientConfigJson;
|
|
||||||
|
|
||||||
if (!clientProtocolConfig.clientId.isEmpty()) {
|
|
||||||
clientConfigJson[config_key::clientId] = clientProtocolConfig.clientId;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!clientProtocolConfig.awgData.junkPacketCount.isEmpty()) {
|
|
||||||
clientConfigJson[config_key::junkPacketCount] = clientProtocolConfig.awgData.junkPacketCount;
|
|
||||||
}
|
|
||||||
if (!clientProtocolConfig.awgData.junkPacketMinSize.isEmpty()) {
|
|
||||||
clientConfigJson[config_key::junkPacketMinSize] = clientProtocolConfig.awgData.junkPacketMinSize;
|
|
||||||
}
|
|
||||||
if (!clientProtocolConfig.awgData.junkPacketMaxSize.isEmpty()) {
|
|
||||||
clientConfigJson[config_key::junkPacketMaxSize] = clientProtocolConfig.awgData.junkPacketMaxSize;
|
|
||||||
}
|
|
||||||
if (!clientProtocolConfig.awgData.initPacketJunkSize.isEmpty()) {
|
|
||||||
clientConfigJson[config_key::initPacketJunkSize] = clientProtocolConfig.awgData.initPacketJunkSize;
|
|
||||||
}
|
|
||||||
if (!clientProtocolConfig.awgData.responsePacketJunkSize.isEmpty()) {
|
|
||||||
clientConfigJson[config_key::responsePacketJunkSize] = clientProtocolConfig.awgData.responsePacketJunkSize;
|
|
||||||
}
|
|
||||||
if (!clientProtocolConfig.awgData.initPacketMagicHeader.isEmpty()) {
|
|
||||||
clientConfigJson[config_key::initPacketMagicHeader] = clientProtocolConfig.awgData.initPacketMagicHeader;
|
|
||||||
}
|
|
||||||
if (!clientProtocolConfig.awgData.responsePacketMagicHeader.isEmpty()) {
|
|
||||||
clientConfigJson[config_key::responsePacketMagicHeader] = clientProtocolConfig.awgData.responsePacketMagicHeader;
|
|
||||||
}
|
|
||||||
if (!clientProtocolConfig.awgData.underloadPacketMagicHeader.isEmpty()) {
|
|
||||||
clientConfigJson[config_key::underloadPacketMagicHeader] = clientProtocolConfig.awgData.underloadPacketMagicHeader;
|
|
||||||
}
|
|
||||||
if (!clientProtocolConfig.awgData.transportPacketMagicHeader.isEmpty()) {
|
|
||||||
clientConfigJson[config_key::transportPacketMagicHeader] = clientProtocolConfig.awgData.transportPacketMagicHeader;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!clientProtocolConfig.wireGuardData.clientIp.isEmpty()) {
|
|
||||||
clientConfigJson[config_key::client_ip] = clientProtocolConfig.wireGuardData.clientIp;
|
|
||||||
}
|
|
||||||
if (!clientProtocolConfig.wireGuardData.clientPrivateKey.isEmpty()) {
|
|
||||||
clientConfigJson[config_key::client_priv_key] = clientProtocolConfig.wireGuardData.clientPrivateKey;
|
|
||||||
}
|
|
||||||
if (!clientProtocolConfig.wireGuardData.clientPublicKey.isEmpty()) {
|
|
||||||
clientConfigJson[config_key::client_pub_key] = clientProtocolConfig.wireGuardData.clientPublicKey;
|
|
||||||
}
|
|
||||||
if (!clientProtocolConfig.wireGuardData.persistentKeepAlive.isEmpty()) {
|
|
||||||
clientConfigJson[config_key::persistent_keep_alive] = clientProtocolConfig.wireGuardData.persistentKeepAlive;
|
|
||||||
}
|
|
||||||
if (!clientProtocolConfig.wireGuardData.pskKey.isEmpty()) {
|
|
||||||
clientConfigJson[config_key::psk_key] = clientProtocolConfig.wireGuardData.pskKey;
|
|
||||||
}
|
|
||||||
if (!clientProtocolConfig.wireGuardData.serverPubKey.isEmpty()) {
|
|
||||||
clientConfigJson[config_key::server_pub_key] = clientProtocolConfig.wireGuardData.serverPubKey;
|
|
||||||
}
|
|
||||||
if (!clientProtocolConfig.wireGuardData.mtu.isEmpty()) {
|
|
||||||
clientConfigJson[config_key::mtu] = clientProtocolConfig.wireGuardData.mtu;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!clientProtocolConfig.wireGuardData.allowedIps.isEmpty()) {
|
|
||||||
QJsonArray allowedIpsArray;
|
|
||||||
for (const auto &ip : clientProtocolConfig.wireGuardData.allowedIps) {
|
|
||||||
if (!ip.isEmpty()) {
|
|
||||||
allowedIpsArray.append(ip);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!allowedIpsArray.isEmpty()) {
|
|
||||||
clientConfigJson[config_key::allowed_ips] = allowedIpsArray;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!clientProtocolConfig.hostname.isEmpty()) {
|
|
||||||
clientConfigJson[config_key::hostName] = clientProtocolConfig.hostname;
|
|
||||||
}
|
|
||||||
if (clientProtocolConfig.port) {
|
|
||||||
clientConfigJson[config_key::port] = clientProtocolConfig.port;
|
|
||||||
}
|
|
||||||
if (!clientProtocolConfig.nativeConfig.isEmpty()) {
|
|
||||||
clientConfigJson[config_key::config] = clientProtocolConfig.nativeConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!clientConfigJson.isEmpty()) {
|
|
||||||
json[config_key::last_config] = QString(QJsonDocument(clientConfigJson).toJson(QJsonDocument::Compact));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool AwgProtocolConfig::hasEqualServerSettings(const AwgProtocolConfig &other) const
|
|
||||||
{
|
|
||||||
if (serverProtocolConfig.subnetAddress != other.serverProtocolConfig.subnetAddress
|
|
||||||
|| serverProtocolConfig.port != other.serverProtocolConfig.port
|
|
||||||
|| serverProtocolConfig.awgData.junkPacketCount != other.serverProtocolConfig.awgData.junkPacketCount
|
|
||||||
|| serverProtocolConfig.awgData.junkPacketMinSize != other.serverProtocolConfig.awgData.junkPacketMinSize
|
|
||||||
|| serverProtocolConfig.awgData.junkPacketMaxSize != other.serverProtocolConfig.awgData.junkPacketMaxSize
|
|
||||||
|| serverProtocolConfig.awgData.initPacketJunkSize != other.serverProtocolConfig.awgData.initPacketJunkSize
|
|
||||||
|| serverProtocolConfig.awgData.responsePacketJunkSize != other.serverProtocolConfig.awgData.responsePacketJunkSize
|
|
||||||
|| serverProtocolConfig.awgData.initPacketMagicHeader != other.serverProtocolConfig.awgData.initPacketMagicHeader
|
|
||||||
|| serverProtocolConfig.awgData.responsePacketMagicHeader != other.serverProtocolConfig.awgData.responsePacketMagicHeader
|
|
||||||
|| serverProtocolConfig.awgData.underloadPacketMagicHeader != other.serverProtocolConfig.awgData.underloadPacketMagicHeader
|
|
||||||
|| serverProtocolConfig.awgData.transportPacketMagicHeader != other.serverProtocolConfig.awgData.transportPacketMagicHeader) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool AwgProtocolConfig::hasEqualClientSettings(const AwgProtocolConfig &other) const
|
|
||||||
{
|
|
||||||
if (clientProtocolConfig.wireGuardData.mtu != other.clientProtocolConfig.wireGuardData.mtu
|
|
||||||
|| clientProtocolConfig.awgData.junkPacketCount != other.clientProtocolConfig.awgData.junkPacketCount
|
|
||||||
|| clientProtocolConfig.awgData.junkPacketMinSize != other.clientProtocolConfig.awgData.junkPacketMinSize
|
|
||||||
|| clientProtocolConfig.awgData.junkPacketMaxSize != other.clientProtocolConfig.awgData.junkPacketMaxSize) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AwgProtocolConfig::clearClientSettings()
|
|
||||||
{
|
|
||||||
clientProtocolConfig = awg::ClientProtocolConfig();
|
|
||||||
}
|
|
||||||
|
|
@ -1,74 +0,0 @@
|
||||||
#ifndef AWGPROTOCOLCONFIG_H
|
|
||||||
#define AWGPROTOCOLCONFIG_H
|
|
||||||
|
|
||||||
#include <QJsonObject>
|
|
||||||
#include <QStringList>
|
|
||||||
|
|
||||||
#include "protocolConfig.h"
|
|
||||||
#include "wireguardProtocolConfig.h"
|
|
||||||
|
|
||||||
namespace awg
|
|
||||||
{
|
|
||||||
struct AwgData
|
|
||||||
{
|
|
||||||
QString junkPacketCount;
|
|
||||||
QString junkPacketMinSize;
|
|
||||||
QString junkPacketMaxSize;
|
|
||||||
|
|
||||||
QString initPacketJunkSize;
|
|
||||||
QString responsePacketJunkSize;
|
|
||||||
|
|
||||||
QString initPacketMagicHeader;
|
|
||||||
QString responsePacketMagicHeader;
|
|
||||||
QString underloadPacketMagicHeader;
|
|
||||||
QString transportPacketMagicHeader;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ServerProtocolConfig
|
|
||||||
{
|
|
||||||
QString port;
|
|
||||||
QString transportProto;
|
|
||||||
|
|
||||||
QString subnetAddress;
|
|
||||||
|
|
||||||
AwgData awgData;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ClientProtocolConfig
|
|
||||||
{
|
|
||||||
bool isEmpty = true;
|
|
||||||
|
|
||||||
QString clientId;
|
|
||||||
|
|
||||||
wireguard::WireGuardData wireGuardData;
|
|
||||||
|
|
||||||
AwgData awgData;
|
|
||||||
|
|
||||||
QString hostname;
|
|
||||||
int port;
|
|
||||||
|
|
||||||
QString nativeConfig;
|
|
||||||
};
|
|
||||||
|
|
||||||
const int messageInitiationSize = 148;
|
|
||||||
const int messageResponseSize = 92;
|
|
||||||
}
|
|
||||||
|
|
||||||
class AwgProtocolConfig : public ProtocolConfig
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
AwgProtocolConfig(const QString &protocolName);
|
|
||||||
AwgProtocolConfig(const QJsonObject &protocolConfigObject, const QString &protocolName);
|
|
||||||
AwgProtocolConfig(const AwgProtocolConfig &other);
|
|
||||||
|
|
||||||
QJsonObject toJson() const override;
|
|
||||||
|
|
||||||
bool hasEqualServerSettings(const AwgProtocolConfig &other) const;
|
|
||||||
bool hasEqualClientSettings(const AwgProtocolConfig &other) const;
|
|
||||||
void clearClientSettings();
|
|
||||||
|
|
||||||
awg::ServerProtocolConfig serverProtocolConfig;
|
|
||||||
awg::ClientProtocolConfig clientProtocolConfig;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // AWGPROTOCOLCONFIG_H
|
|
||||||
|
|
@ -1,58 +0,0 @@
|
||||||
#include "cloakProtocolConfig.h"
|
|
||||||
|
|
||||||
#include <QJsonArray>
|
|
||||||
#include <QJsonDocument>
|
|
||||||
#include "protocols/protocols_defs.h"
|
|
||||||
|
|
||||||
using namespace amnezia;
|
|
||||||
|
|
||||||
CloakProtocolConfig::CloakProtocolConfig(const QJsonObject &protocolConfigObject, const QString &protocolName) : ProtocolConfig(protocolName)
|
|
||||||
{
|
|
||||||
serverProtocolConfig.port = protocolConfigObject.value(config_key::port).toString();
|
|
||||||
serverProtocolConfig.cipher = protocolConfigObject.value(config_key::cipher).toString();
|
|
||||||
serverProtocolConfig.site = protocolConfigObject.value(config_key::site).toString();
|
|
||||||
|
|
||||||
auto clientProtocolString = protocolConfigObject.value(config_key::last_config).toString();
|
|
||||||
if (!clientProtocolString.isEmpty()) {
|
|
||||||
clientProtocolConfig.isEmpty = false;
|
|
||||||
|
|
||||||
QJsonObject clientProtocolConfigObject = QJsonDocument::fromJson(clientProtocolString.toUtf8()).object();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QJsonObject CloakProtocolConfig::toJson() const
|
|
||||||
{
|
|
||||||
QJsonObject json;
|
|
||||||
|
|
||||||
if (!serverProtocolConfig.port.isEmpty()) {
|
|
||||||
json[config_key::port] = serverProtocolConfig.port;
|
|
||||||
}
|
|
||||||
if (!serverProtocolConfig.cipher.isEmpty()) {
|
|
||||||
json[config_key::cipher] = serverProtocolConfig.cipher;
|
|
||||||
}
|
|
||||||
if (!serverProtocolConfig.site.isEmpty()) {
|
|
||||||
json[config_key::site] = serverProtocolConfig.site;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!clientProtocolConfig.isEmpty) {
|
|
||||||
QJsonObject clientConfigJson;
|
|
||||||
json[config_key::last_config] = QString(QJsonDocument(clientConfigJson).toJson());
|
|
||||||
}
|
|
||||||
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CloakProtocolConfig::hasEqualServerSettings(const CloakProtocolConfig &other) const
|
|
||||||
{
|
|
||||||
if (serverProtocolConfig.port != other.serverProtocolConfig.port ||
|
|
||||||
serverProtocolConfig.cipher != other.serverProtocolConfig.cipher ||
|
|
||||||
serverProtocolConfig.site != other.serverProtocolConfig.site) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CloakProtocolConfig::clearClientSettings()
|
|
||||||
{
|
|
||||||
clientProtocolConfig = cloak::ClientProtocolConfig();
|
|
||||||
}
|
|
||||||
|
|
@ -1,38 +0,0 @@
|
||||||
#ifndef CLOAKPROTOCOLCONFIG_H
|
|
||||||
#define CLOAKPROTOCOLCONFIG_H
|
|
||||||
|
|
||||||
#include <QJsonObject>
|
|
||||||
#include <QString>
|
|
||||||
|
|
||||||
#include "protocolConfig.h"
|
|
||||||
|
|
||||||
namespace cloak
|
|
||||||
{
|
|
||||||
struct ServerProtocolConfig
|
|
||||||
{
|
|
||||||
QString port;
|
|
||||||
QString cipher;
|
|
||||||
QString site;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ClientProtocolConfig
|
|
||||||
{
|
|
||||||
bool isEmpty = true;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
class CloakProtocolConfig : public ProtocolConfig
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
CloakProtocolConfig(const QJsonObject &protocolConfigObject, const QString &protocolName);
|
|
||||||
|
|
||||||
QJsonObject toJson() const override;
|
|
||||||
|
|
||||||
bool hasEqualServerSettings(const CloakProtocolConfig &other) const;
|
|
||||||
void clearClientSettings();
|
|
||||||
|
|
||||||
cloak::ServerProtocolConfig serverProtocolConfig;
|
|
||||||
cloak::ClientProtocolConfig clientProtocolConfig;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // CLOAKPROTOCOLCONFIG_H
|
|
||||||
|
|
@ -1,100 +0,0 @@
|
||||||
#include "openvpnProtocolConfig.h"
|
|
||||||
|
|
||||||
#include "protocols/protocols_defs.h"
|
|
||||||
#include <QJsonDocument>
|
|
||||||
|
|
||||||
using namespace amnezia;
|
|
||||||
|
|
||||||
OpenVpnProtocolConfig::OpenVpnProtocolConfig(const QJsonObject &protocolConfigObject, const QString &protocolName)
|
|
||||||
: ProtocolConfig(protocolName)
|
|
||||||
{
|
|
||||||
serverProtocolConfig.subnetAddress = protocolConfigObject.value(config_key::subnet_address).toString();
|
|
||||||
serverProtocolConfig.transportProto = protocolConfigObject.value(config_key::transport_proto).toString();
|
|
||||||
serverProtocolConfig.port = protocolConfigObject.value(config_key::port).toString();
|
|
||||||
serverProtocolConfig.ncpDisable = protocolConfigObject.value(config_key::ncp_disable).toBool(protocols::openvpn::defaultNcpDisable);
|
|
||||||
serverProtocolConfig.hash = protocolConfigObject.value(config_key::hash).toString();
|
|
||||||
serverProtocolConfig.cipher = protocolConfigObject.value(config_key::cipher).toString();
|
|
||||||
serverProtocolConfig.tlsAuth = protocolConfigObject.value(config_key::tls_auth).toBool(protocols::openvpn::defaultTlsAuth);
|
|
||||||
serverProtocolConfig.blockOutsideDns =
|
|
||||||
protocolConfigObject.value(config_key::block_outside_dns).toBool(protocols::openvpn::defaultBlockOutsideDns);
|
|
||||||
serverProtocolConfig.additionalClientConfig = protocolConfigObject.value(config_key::additional_client_config).toString();
|
|
||||||
serverProtocolConfig.additionalServerConfig = protocolConfigObject.value(config_key::additional_server_config).toString();
|
|
||||||
|
|
||||||
auto clientProtocolString = protocolConfigObject.value(config_key::last_config).toString();
|
|
||||||
if (!clientProtocolString.isEmpty()) {
|
|
||||||
clientProtocolConfig.isEmpty = false;
|
|
||||||
|
|
||||||
QJsonObject clientProtocolConfigObject = QJsonDocument::fromJson(clientProtocolString.toUtf8()).object();
|
|
||||||
|
|
||||||
clientProtocolConfig.clientId = clientProtocolConfigObject.value(config_key::clientId).toString();
|
|
||||||
clientProtocolConfig.nativeConfig = clientProtocolConfigObject.value(config_key::config).toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QJsonObject OpenVpnProtocolConfig::toJson() const
|
|
||||||
{
|
|
||||||
QJsonObject json;
|
|
||||||
|
|
||||||
if (!serverProtocolConfig.subnetAddress.isEmpty()) {
|
|
||||||
json[config_key::subnet_address] = serverProtocolConfig.subnetAddress;
|
|
||||||
}
|
|
||||||
if (!serverProtocolConfig.transportProto.isEmpty()) {
|
|
||||||
json[config_key::transport_proto] = serverProtocolConfig.transportProto;
|
|
||||||
}
|
|
||||||
if (!serverProtocolConfig.port.isEmpty()) {
|
|
||||||
json[config_key::port] = serverProtocolConfig.port;
|
|
||||||
}
|
|
||||||
json[config_key::ncp_disable] = serverProtocolConfig.ncpDisable;
|
|
||||||
if (!serverProtocolConfig.hash.isEmpty()) {
|
|
||||||
json[config_key::hash] = serverProtocolConfig.hash;
|
|
||||||
}
|
|
||||||
if (!serverProtocolConfig.cipher.isEmpty()) {
|
|
||||||
json[config_key::cipher] = serverProtocolConfig.cipher;
|
|
||||||
}
|
|
||||||
json[config_key::tls_auth] = serverProtocolConfig.tlsAuth;
|
|
||||||
json[config_key::block_outside_dns] = serverProtocolConfig.blockOutsideDns;
|
|
||||||
if (!serverProtocolConfig.additionalClientConfig.isEmpty()) {
|
|
||||||
json[config_key::additional_client_config] = serverProtocolConfig.additionalClientConfig;
|
|
||||||
}
|
|
||||||
if (!serverProtocolConfig.additionalServerConfig.isEmpty()) {
|
|
||||||
json[config_key::additional_server_config] = serverProtocolConfig.additionalServerConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!clientProtocolConfig.isEmpty) {
|
|
||||||
QJsonObject clientConfigJson;
|
|
||||||
|
|
||||||
if (!clientProtocolConfig.clientId.isEmpty()) {
|
|
||||||
clientConfigJson[config_key::clientId] = clientProtocolConfig.clientId;
|
|
||||||
}
|
|
||||||
if (!clientProtocolConfig.nativeConfig.isEmpty()) {
|
|
||||||
clientConfigJson[config_key::config] = clientProtocolConfig.nativeConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!clientConfigJson.isEmpty()) {
|
|
||||||
json[config_key::last_config] = QString(QJsonDocument(clientConfigJson).toJson());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool OpenVpnProtocolConfig::hasEqualServerSettings(const OpenVpnProtocolConfig &other) const
|
|
||||||
{
|
|
||||||
if (serverProtocolConfig.subnetAddress != other.serverProtocolConfig.subnetAddress
|
|
||||||
|| serverProtocolConfig.transportProto != other.serverProtocolConfig.transportProto
|
|
||||||
|| serverProtocolConfig.port != other.serverProtocolConfig.port
|
|
||||||
|| serverProtocolConfig.ncpDisable != other.serverProtocolConfig.ncpDisable
|
|
||||||
|| serverProtocolConfig.hash != other.serverProtocolConfig.hash || serverProtocolConfig.cipher != other.serverProtocolConfig.cipher
|
|
||||||
|| serverProtocolConfig.tlsAuth != other.serverProtocolConfig.tlsAuth
|
|
||||||
|| serverProtocolConfig.blockOutsideDns != other.serverProtocolConfig.blockOutsideDns
|
|
||||||
|| serverProtocolConfig.additionalClientConfig != other.serverProtocolConfig.additionalClientConfig
|
|
||||||
|| serverProtocolConfig.additionalServerConfig != other.serverProtocolConfig.additionalServerConfig) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void OpenVpnProtocolConfig::clearClientSettings()
|
|
||||||
{
|
|
||||||
clientProtocolConfig = openvpn::ClientProtocolConfig();
|
|
||||||
}
|
|
||||||
|
|
@ -1,49 +0,0 @@
|
||||||
#ifndef OPENVPNPROTOCOLCONFIG_H
|
|
||||||
#define OPENVPNPROTOCOLCONFIG_H
|
|
||||||
|
|
||||||
#include <QJsonObject>
|
|
||||||
#include <QString>
|
|
||||||
|
|
||||||
#include "protocolConfig.h"
|
|
||||||
|
|
||||||
namespace openvpn
|
|
||||||
{
|
|
||||||
struct ServerProtocolConfig
|
|
||||||
{
|
|
||||||
QString subnetAddress;
|
|
||||||
QString transportProto;
|
|
||||||
QString port;
|
|
||||||
bool ncpDisable;
|
|
||||||
QString hash;
|
|
||||||
QString cipher;
|
|
||||||
bool tlsAuth;
|
|
||||||
bool blockOutsideDns;
|
|
||||||
QString additionalClientConfig;
|
|
||||||
QString additionalServerConfig;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ClientProtocolConfig
|
|
||||||
{
|
|
||||||
bool isEmpty = true;
|
|
||||||
|
|
||||||
QString clientId;
|
|
||||||
|
|
||||||
QString nativeConfig;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
class OpenVpnProtocolConfig : public ProtocolConfig
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
OpenVpnProtocolConfig(const QJsonObject &protocolConfigObject, const QString &protocolName);
|
|
||||||
|
|
||||||
QJsonObject toJson() const override;
|
|
||||||
|
|
||||||
bool hasEqualServerSettings(const OpenVpnProtocolConfig &other) const;
|
|
||||||
void clearClientSettings();
|
|
||||||
|
|
||||||
openvpn::ServerProtocolConfig serverProtocolConfig;
|
|
||||||
openvpn::ClientProtocolConfig clientProtocolConfig;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // OPENVPNPROTOCOLCONFIG_H
|
|
||||||
|
|
@ -1,76 +0,0 @@
|
||||||
#include "protocolConfig.h"
|
|
||||||
|
|
||||||
#include "core/models/protocols/awgProtocolConfig.h"
|
|
||||||
#include "core/models/protocols/cloakProtocolConfig.h"
|
|
||||||
#include "core/models/protocols/openvpnProtocolConfig.h"
|
|
||||||
#include "core/models/protocols/protocolConfig.h"
|
|
||||||
#include "core/models/protocols/shadowsocksProtocolConfig.h"
|
|
||||||
#include "core/models/protocols/wireguardProtocolConfig.h"
|
|
||||||
#include "core/models/protocols/xrayProtocolConfig.h"
|
|
||||||
#include "protocols/protocols_defs.h"
|
|
||||||
|
|
||||||
using namespace amnezia;
|
|
||||||
|
|
||||||
ProtocolConfig::ProtocolConfig(const QString &protocolName) : protocolName(protocolName)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
ProtocolConfigVariant ProtocolConfig::getProtocolConfigVariant(const QSharedPointer<ProtocolConfig> &protocolConfig)
|
|
||||||
{
|
|
||||||
ProtocolConfigVariant variant;
|
|
||||||
auto proto = ProtocolProps::protoFromString(protocolConfig->protocolName);
|
|
||||||
switch (proto) {
|
|
||||||
case Proto::OpenVpn: variant = qSharedPointerCast<OpenVpnProtocolConfig>(protocolConfig); break;
|
|
||||||
case Proto::WireGuard: variant = qSharedPointerCast<WireGuardProtocolConfig>(protocolConfig); break;
|
|
||||||
case Proto::ShadowSocks: variant = qSharedPointerCast<ShadowsocksProtocolConfig>(protocolConfig); break;
|
|
||||||
case Proto::Cloak: variant = qSharedPointerCast<CloakProtocolConfig>(protocolConfig); break;
|
|
||||||
case Proto::Xray: variant = qSharedPointerCast<XrayProtocolConfig>(protocolConfig); break;
|
|
||||||
case Proto::Awg: variant = qSharedPointerCast<AwgProtocolConfig>(protocolConfig); break;
|
|
||||||
default: break;
|
|
||||||
}
|
|
||||||
return variant;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ProtocolConfig::isServerSettingsEqual(const QSharedPointer<ProtocolConfig> &other)
|
|
||||||
{
|
|
||||||
auto proto = ProtocolProps::protoFromString(protocolName);
|
|
||||||
|
|
||||||
switch (proto) {
|
|
||||||
case Proto::OpenVpn: {
|
|
||||||
auto thisConfig = qSharedPointerCast<OpenVpnProtocolConfig>(QSharedPointer<ProtocolConfig>(this));
|
|
||||||
auto otherConfig = qSharedPointerCast<OpenVpnProtocolConfig>(other);
|
|
||||||
return thisConfig->hasEqualServerSettings(*otherConfig.data());
|
|
||||||
}
|
|
||||||
case Proto::WireGuard: {
|
|
||||||
auto thisConfig = qSharedPointerCast<WireGuardProtocolConfig>(QSharedPointer<ProtocolConfig>(this));
|
|
||||||
auto otherConfig = qSharedPointerCast<WireGuardProtocolConfig>(other);
|
|
||||||
return thisConfig->hasEqualServerSettings(*otherConfig.data());
|
|
||||||
}
|
|
||||||
case Proto::ShadowSocks: {
|
|
||||||
auto thisConfig = qSharedPointerCast<ShadowsocksProtocolConfig>(QSharedPointer<ProtocolConfig>(this));
|
|
||||||
auto otherConfig = qSharedPointerCast<ShadowsocksProtocolConfig>(other);
|
|
||||||
return thisConfig->hasEqualServerSettings(*otherConfig.data());
|
|
||||||
}
|
|
||||||
case Proto::Cloak: {
|
|
||||||
auto thisConfig = qSharedPointerCast<CloakProtocolConfig>(QSharedPointer<ProtocolConfig>(this));
|
|
||||||
auto otherConfig = qSharedPointerCast<CloakProtocolConfig>(other);
|
|
||||||
return thisConfig->hasEqualServerSettings(*otherConfig.data());
|
|
||||||
}
|
|
||||||
case Proto::Xray: {
|
|
||||||
auto thisConfig = qSharedPointerCast<XrayProtocolConfig>(QSharedPointer<ProtocolConfig>(this));
|
|
||||||
auto otherConfig = qSharedPointerCast<XrayProtocolConfig>(other);
|
|
||||||
return thisConfig->hasEqualServerSettings(*otherConfig.data());
|
|
||||||
}
|
|
||||||
case Proto::Awg: {
|
|
||||||
auto thisConfig = qSharedPointerCast<AwgProtocolConfig>(QSharedPointer<ProtocolConfig>(this));
|
|
||||||
auto otherConfig = qSharedPointerCast<AwgProtocolConfig>(other);
|
|
||||||
return thisConfig->hasEqualServerSettings(*otherConfig.data());
|
|
||||||
}
|
|
||||||
default: return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QJsonObject ProtocolConfig::toJson() const
|
|
||||||
{
|
|
||||||
return QJsonObject();
|
|
||||||
}
|
|
||||||
|
|
@ -1,31 +0,0 @@
|
||||||
#ifndef PROTOCOLCONFIG_H
|
|
||||||
#define PROTOCOLCONFIG_H
|
|
||||||
|
|
||||||
#include <QJsonObject>
|
|
||||||
#include <QSharedPointer>
|
|
||||||
#include <variant>
|
|
||||||
|
|
||||||
class OpenVpnProtocolConfig;
|
|
||||||
class WireGuardProtocolConfig;
|
|
||||||
class ShadowsocksProtocolConfig;
|
|
||||||
class CloakProtocolConfig;
|
|
||||||
class XrayProtocolConfig;
|
|
||||||
class AwgProtocolConfig;
|
|
||||||
|
|
||||||
using ProtocolConfigVariant =
|
|
||||||
std::variant<QSharedPointer<OpenVpnProtocolConfig>, QSharedPointer<WireGuardProtocolConfig>, QSharedPointer<ShadowsocksProtocolConfig>,
|
|
||||||
QSharedPointer<CloakProtocolConfig>, QSharedPointer<XrayProtocolConfig>, QSharedPointer<AwgProtocolConfig> >;
|
|
||||||
|
|
||||||
class ProtocolConfig
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
ProtocolConfig(const QString &protocolName);
|
|
||||||
virtual QJsonObject toJson() const;
|
|
||||||
|
|
||||||
static ProtocolConfigVariant getProtocolConfigVariant(const QSharedPointer<ProtocolConfig> &protocolConfig);
|
|
||||||
bool isServerSettingsEqual(const QSharedPointer<ProtocolConfig> &protocolConfig);
|
|
||||||
|
|
||||||
QString protocolName;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // PROTOCOLCONFIG_H
|
|
||||||
|
|
@ -1,53 +0,0 @@
|
||||||
#include "shadowsocksProtocolConfig.h"
|
|
||||||
|
|
||||||
#include <QJsonArray>
|
|
||||||
#include <QJsonDocument>
|
|
||||||
#include "protocols/protocols_defs.h"
|
|
||||||
|
|
||||||
using namespace amnezia;
|
|
||||||
|
|
||||||
ShadowsocksProtocolConfig::ShadowsocksProtocolConfig(const QJsonObject &protocolConfigObject, const QString &protocolName) : ProtocolConfig(protocolName)
|
|
||||||
{
|
|
||||||
serverProtocolConfig.port = protocolConfigObject.value(config_key::port).toString();
|
|
||||||
serverProtocolConfig.cipher = protocolConfigObject.value(config_key::cipher).toString();
|
|
||||||
|
|
||||||
auto clientProtocolString = protocolConfigObject.value(config_key::last_config).toString();
|
|
||||||
if (!clientProtocolString.isEmpty()) {
|
|
||||||
clientProtocolConfig.isEmpty = false;
|
|
||||||
|
|
||||||
QJsonObject clientProtocolConfigObject = QJsonDocument::fromJson(clientProtocolString.toUtf8()).object();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QJsonObject ShadowsocksProtocolConfig::toJson() const
|
|
||||||
{
|
|
||||||
QJsonObject json;
|
|
||||||
|
|
||||||
if (!serverProtocolConfig.port.isEmpty()) {
|
|
||||||
json[config_key::port] = serverProtocolConfig.port;
|
|
||||||
}
|
|
||||||
if (!serverProtocolConfig.cipher.isEmpty()) {
|
|
||||||
json[config_key::cipher] = serverProtocolConfig.cipher;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!clientProtocolConfig.isEmpty) {
|
|
||||||
QJsonObject clientConfigJson;
|
|
||||||
json[config_key::last_config] = QString(QJsonDocument(clientConfigJson).toJson());
|
|
||||||
}
|
|
||||||
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ShadowsocksProtocolConfig::hasEqualServerSettings(const ShadowsocksProtocolConfig &other) const
|
|
||||||
{
|
|
||||||
if (serverProtocolConfig.port != other.serverProtocolConfig.port ||
|
|
||||||
serverProtocolConfig.cipher != other.serverProtocolConfig.cipher) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ShadowsocksProtocolConfig::clearClientSettings()
|
|
||||||
{
|
|
||||||
clientProtocolConfig = shadowsocks::ClientProtocolConfig();
|
|
||||||
}
|
|
||||||
|
|
@ -1,37 +0,0 @@
|
||||||
#ifndef SHADOWSOCKSPROTOCOLCONFIG_H
|
|
||||||
#define SHADOWSOCKSPROTOCOLCONFIG_H
|
|
||||||
|
|
||||||
#include <QJsonObject>
|
|
||||||
#include <QString>
|
|
||||||
|
|
||||||
#include "protocolConfig.h"
|
|
||||||
|
|
||||||
namespace shadowsocks
|
|
||||||
{
|
|
||||||
struct ServerProtocolConfig
|
|
||||||
{
|
|
||||||
QString port;
|
|
||||||
QString cipher;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ClientProtocolConfig
|
|
||||||
{
|
|
||||||
bool isEmpty = true;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
class ShadowsocksProtocolConfig : public ProtocolConfig
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
ShadowsocksProtocolConfig(const QJsonObject &protocolConfigObject, const QString &protocolName);
|
|
||||||
|
|
||||||
QJsonObject toJson() const override;
|
|
||||||
|
|
||||||
bool hasEqualServerSettings(const ShadowsocksProtocolConfig &other) const;
|
|
||||||
void clearClientSettings();
|
|
||||||
|
|
||||||
shadowsocks::ServerProtocolConfig serverProtocolConfig;
|
|
||||||
shadowsocks::ClientProtocolConfig clientProtocolConfig;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // SHADOWSOCKSPROTOCOLCONFIG_H
|
|
||||||
|
|
@ -1,134 +0,0 @@
|
||||||
#include "wireguardProtocolConfig.h"
|
|
||||||
|
|
||||||
#include <QJsonArray>
|
|
||||||
#include <QJsonDocument>
|
|
||||||
|
|
||||||
#include "protocols/protocols_defs.h"
|
|
||||||
|
|
||||||
using namespace amnezia;
|
|
||||||
|
|
||||||
WireGuardProtocolConfig::WireGuardProtocolConfig(const QJsonObject &protocolConfigObject, const QString &protocolName)
|
|
||||||
: ProtocolConfig(protocolName)
|
|
||||||
{
|
|
||||||
serverProtocolConfig.port = protocolConfigObject.value(config_key::port).toString();
|
|
||||||
serverProtocolConfig.transportProto = protocolConfigObject.value(config_key::transport_proto).toString();
|
|
||||||
serverProtocolConfig.subnetAddress = protocolConfigObject.value(config_key::subnet_address).toString();
|
|
||||||
|
|
||||||
auto clientProtocolString = protocolConfigObject.value(config_key::last_config).toString();
|
|
||||||
if (!clientProtocolString.isEmpty()) {
|
|
||||||
clientProtocolConfig.isEmpty = false;
|
|
||||||
|
|
||||||
QJsonObject clientProtocolConfigObject = QJsonDocument::fromJson(clientProtocolString.toUtf8()).object();
|
|
||||||
|
|
||||||
clientProtocolConfig.clientId = clientProtocolConfigObject.value(config_key::clientId).toString();
|
|
||||||
|
|
||||||
clientProtocolConfig.wireGuardData.clientIp = clientProtocolConfigObject.value(config_key::client_ip).toString();
|
|
||||||
clientProtocolConfig.wireGuardData.clientPrivateKey = clientProtocolConfigObject.value(config_key::client_priv_key).toString();
|
|
||||||
clientProtocolConfig.wireGuardData.clientPublicKey = clientProtocolConfigObject.value(config_key::client_pub_key).toString();
|
|
||||||
clientProtocolConfig.wireGuardData.persistentKeepAlive =
|
|
||||||
clientProtocolConfigObject.value(config_key::persistent_keep_alive).toString();
|
|
||||||
clientProtocolConfig.wireGuardData.pskKey = clientProtocolConfigObject.value(config_key::psk_key).toString();
|
|
||||||
clientProtocolConfig.wireGuardData.serverPubKey = clientProtocolConfigObject.value(config_key::server_pub_key).toString();
|
|
||||||
clientProtocolConfig.wireGuardData.mtu = clientProtocolConfigObject.value(config_key::mtu).toString();
|
|
||||||
|
|
||||||
clientProtocolConfig.hostname = clientProtocolConfigObject.value(config_key::hostName).toString();
|
|
||||||
clientProtocolConfig.port = clientProtocolConfigObject.value(config_key::port).toInt(0);
|
|
||||||
|
|
||||||
clientProtocolConfig.nativeConfig = clientProtocolConfigObject.value(config_key::config).toString();
|
|
||||||
|
|
||||||
if (clientProtocolConfigObject.contains(config_key::allowed_ips)
|
|
||||||
&& clientProtocolConfigObject.value(config_key::allowed_ips).isArray()) {
|
|
||||||
auto allowedIpsArray = clientProtocolConfigObject.value(config_key::allowed_ips).toArray();
|
|
||||||
for (const auto &ip : allowedIpsArray) {
|
|
||||||
clientProtocolConfig.wireGuardData.allowedIps.append(ip.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QJsonObject WireGuardProtocolConfig::toJson() const
|
|
||||||
{
|
|
||||||
QJsonObject json;
|
|
||||||
|
|
||||||
if (!serverProtocolConfig.port.isEmpty()) {
|
|
||||||
json[config_key::port] = serverProtocolConfig.port;
|
|
||||||
}
|
|
||||||
if (!serverProtocolConfig.transportProto.isEmpty()) {
|
|
||||||
json[config_key::transport_proto] = serverProtocolConfig.transportProto;
|
|
||||||
}
|
|
||||||
if (!serverProtocolConfig.subnetAddress.isEmpty()) {
|
|
||||||
json[config_key::subnet_address] = serverProtocolConfig.subnetAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!clientProtocolConfig.isEmpty) {
|
|
||||||
QJsonObject clientConfigJson;
|
|
||||||
|
|
||||||
if (!clientProtocolConfig.clientId.isEmpty()) {
|
|
||||||
clientConfigJson[config_key::clientId] = clientProtocolConfig.clientId;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!clientProtocolConfig.wireGuardData.clientIp.isEmpty()) {
|
|
||||||
clientConfigJson[config_key::client_ip] = clientProtocolConfig.wireGuardData.clientIp;
|
|
||||||
}
|
|
||||||
if (!clientProtocolConfig.wireGuardData.clientPrivateKey.isEmpty()) {
|
|
||||||
clientConfigJson[config_key::client_priv_key] = clientProtocolConfig.wireGuardData.clientPrivateKey;
|
|
||||||
}
|
|
||||||
if (!clientProtocolConfig.wireGuardData.clientPublicKey.isEmpty()) {
|
|
||||||
clientConfigJson[config_key::client_pub_key] = clientProtocolConfig.wireGuardData.clientPublicKey;
|
|
||||||
}
|
|
||||||
if (!clientProtocolConfig.wireGuardData.persistentKeepAlive.isEmpty()) {
|
|
||||||
clientConfigJson[config_key::persistent_keep_alive] = clientProtocolConfig.wireGuardData.persistentKeepAlive;
|
|
||||||
}
|
|
||||||
if (!clientProtocolConfig.wireGuardData.pskKey.isEmpty()) {
|
|
||||||
clientConfigJson[config_key::psk_key] = clientProtocolConfig.wireGuardData.pskKey;
|
|
||||||
}
|
|
||||||
if (!clientProtocolConfig.wireGuardData.serverPubKey.isEmpty()) {
|
|
||||||
clientConfigJson[config_key::server_pub_key] = clientProtocolConfig.wireGuardData.serverPubKey;
|
|
||||||
}
|
|
||||||
if (!clientProtocolConfig.wireGuardData.mtu.isEmpty()) {
|
|
||||||
clientConfigJson[config_key::mtu] = clientProtocolConfig.wireGuardData.mtu;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!clientProtocolConfig.wireGuardData.allowedIps.isEmpty()) {
|
|
||||||
QJsonArray allowedIpsArray;
|
|
||||||
for (const auto &ip : clientProtocolConfig.wireGuardData.allowedIps) {
|
|
||||||
if (!ip.isEmpty()) {
|
|
||||||
allowedIpsArray.append(ip);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!allowedIpsArray.isEmpty()) {
|
|
||||||
clientConfigJson[config_key::allowed_ips] = allowedIpsArray;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!clientProtocolConfig.hostname.isEmpty()) {
|
|
||||||
clientConfigJson[config_key::hostName] = clientProtocolConfig.hostname;
|
|
||||||
}
|
|
||||||
if (clientProtocolConfig.port) {
|
|
||||||
clientConfigJson[config_key::port] = clientProtocolConfig.port;
|
|
||||||
}
|
|
||||||
if (!clientProtocolConfig.nativeConfig.isEmpty()) {
|
|
||||||
clientConfigJson[config_key::config] = clientProtocolConfig.nativeConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!clientConfigJson.isEmpty()) {
|
|
||||||
json[config_key::last_config] = QString(QJsonDocument(clientConfigJson).toJson());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool WireGuardProtocolConfig::hasEqualServerSettings(const WireGuardProtocolConfig &other) const
|
|
||||||
{
|
|
||||||
if (serverProtocolConfig.subnetAddress != other.serverProtocolConfig.subnetAddress ||
|
|
||||||
serverProtocolConfig.port != other.serverProtocolConfig.port) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void WireGuardProtocolConfig::clearClientSettings()
|
|
||||||
{
|
|
||||||
clientProtocolConfig = wireguard::ClientProtocolConfig();
|
|
||||||
}
|
|
||||||
|
|
@ -1,61 +0,0 @@
|
||||||
#ifndef WIREGUARDPROTOCOLCONFIG_H
|
|
||||||
#define WIREGUARDPROTOCOLCONFIG_H
|
|
||||||
|
|
||||||
#include <QJsonObject>
|
|
||||||
#include <QStringList>
|
|
||||||
|
|
||||||
#include "protocolConfig.h"
|
|
||||||
|
|
||||||
namespace wireguard
|
|
||||||
{
|
|
||||||
struct WireGuardData
|
|
||||||
{
|
|
||||||
QStringList allowedIps;
|
|
||||||
|
|
||||||
QString clientIp;
|
|
||||||
QString clientPrivateKey;
|
|
||||||
QString clientPublicKey;
|
|
||||||
QString mtu;
|
|
||||||
QString persistentKeepAlive;
|
|
||||||
QString pskKey;
|
|
||||||
QString serverPubKey;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ServerProtocolConfig
|
|
||||||
{
|
|
||||||
QString port;
|
|
||||||
QString transportProto;
|
|
||||||
|
|
||||||
QString subnetAddress;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ClientProtocolConfig
|
|
||||||
{
|
|
||||||
bool isEmpty = true;
|
|
||||||
|
|
||||||
QString clientId;
|
|
||||||
|
|
||||||
WireGuardData wireGuardData;
|
|
||||||
|
|
||||||
QString hostname;
|
|
||||||
int port;
|
|
||||||
|
|
||||||
QString nativeConfig;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
class WireGuardProtocolConfig : public ProtocolConfig
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
WireGuardProtocolConfig(const QJsonObject &protocolConfigObject, const QString &protocolName);
|
|
||||||
|
|
||||||
QJsonObject toJson() const override;
|
|
||||||
|
|
||||||
bool hasEqualServerSettings(const WireGuardProtocolConfig &other) const;
|
|
||||||
void clearClientSettings();
|
|
||||||
|
|
||||||
wireguard::ServerProtocolConfig serverProtocolConfig;
|
|
||||||
wireguard::ClientProtocolConfig clientProtocolConfig;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // WIREGUARDPROTOCOLCONFIG_H
|
|
||||||
|
|
@ -1,58 +0,0 @@
|
||||||
#include "xrayProtocolConfig.h"
|
|
||||||
|
|
||||||
#include <QJsonArray>
|
|
||||||
#include <QJsonDocument>
|
|
||||||
#include "protocols/protocols_defs.h"
|
|
||||||
|
|
||||||
using namespace amnezia;
|
|
||||||
|
|
||||||
XrayProtocolConfig::XrayProtocolConfig(const QJsonObject &protocolConfigObject, const QString &protocolName) : ProtocolConfig(protocolName)
|
|
||||||
{
|
|
||||||
serverProtocolConfig.site = protocolConfigObject.value(config_key::site).toString();
|
|
||||||
serverProtocolConfig.port = protocolConfigObject.value(config_key::port).toString();
|
|
||||||
serverProtocolConfig.transportProto = protocolConfigObject.value(config_key::transport_proto).toString();
|
|
||||||
|
|
||||||
auto clientProtocolString = protocolConfigObject.value(config_key::last_config).toString();
|
|
||||||
if (!clientProtocolString.isEmpty()) {
|
|
||||||
clientProtocolConfig.isEmpty = false;
|
|
||||||
|
|
||||||
QJsonObject clientProtocolConfigObject = QJsonDocument::fromJson(clientProtocolString.toUtf8()).object();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QJsonObject XrayProtocolConfig::toJson() const
|
|
||||||
{
|
|
||||||
QJsonObject json;
|
|
||||||
|
|
||||||
if (!serverProtocolConfig.site.isEmpty()) {
|
|
||||||
json[config_key::site] = serverProtocolConfig.site;
|
|
||||||
}
|
|
||||||
if (!serverProtocolConfig.port.isEmpty()) {
|
|
||||||
json[config_key::port] = serverProtocolConfig.port;
|
|
||||||
}
|
|
||||||
if (!serverProtocolConfig.transportProto.isEmpty()) {
|
|
||||||
json[config_key::transport_proto] = serverProtocolConfig.transportProto;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!clientProtocolConfig.isEmpty) {
|
|
||||||
QJsonObject clientConfigJson;
|
|
||||||
json[config_key::last_config] = QString(QJsonDocument(clientConfigJson).toJson());
|
|
||||||
}
|
|
||||||
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool XrayProtocolConfig::hasEqualServerSettings(const XrayProtocolConfig &other) const
|
|
||||||
{
|
|
||||||
if (serverProtocolConfig.site != other.serverProtocolConfig.site ||
|
|
||||||
serverProtocolConfig.port != other.serverProtocolConfig.port ||
|
|
||||||
serverProtocolConfig.transportProto != other.serverProtocolConfig.transportProto) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void XrayProtocolConfig::clearClientSettings()
|
|
||||||
{
|
|
||||||
clientProtocolConfig = xray::ClientProtocolConfig();
|
|
||||||
}
|
|
||||||
|
|
@ -1,38 +0,0 @@
|
||||||
#ifndef XRAYPROTOCOLCONFIG_H
|
|
||||||
#define XRAYPROTOCOLCONFIG_H
|
|
||||||
|
|
||||||
#include <QJsonObject>
|
|
||||||
#include <QString>
|
|
||||||
|
|
||||||
#include "protocolConfig.h"
|
|
||||||
|
|
||||||
namespace xray
|
|
||||||
{
|
|
||||||
struct ServerProtocolConfig
|
|
||||||
{
|
|
||||||
QString site;
|
|
||||||
QString port;
|
|
||||||
QString transportProto;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ClientProtocolConfig
|
|
||||||
{
|
|
||||||
bool isEmpty = true;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
class XrayProtocolConfig : public ProtocolConfig
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
XrayProtocolConfig(const QJsonObject &protocolConfigObject, const QString &protocolName);
|
|
||||||
|
|
||||||
QJsonObject toJson() const override;
|
|
||||||
|
|
||||||
bool hasEqualServerSettings(const XrayProtocolConfig &other) const;
|
|
||||||
void clearClientSettings();
|
|
||||||
|
|
||||||
xray::ServerProtocolConfig serverProtocolConfig;
|
|
||||||
xray::ClientProtocolConfig clientProtocolConfig;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // XRAYPROTOCOLCONFIG_H
|
|
||||||
|
|
@ -1,28 +0,0 @@
|
||||||
#include "apiV1ServerConfig.h"
|
|
||||||
|
|
||||||
#include <QJsonArray>
|
|
||||||
#include <QJsonDocument>
|
|
||||||
|
|
||||||
#include "protocols/protocols_defs.h"
|
|
||||||
|
|
||||||
using namespace amnezia;
|
|
||||||
|
|
||||||
ApiV1ServerConfig::ApiV1ServerConfig(const QJsonObject &serverConfigObject) : ServerConfig(serverConfigObject)
|
|
||||||
{
|
|
||||||
name = serverConfigObject.value(config_key::name).toString();
|
|
||||||
description = serverConfigObject.value(config_key::description).toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
QJsonObject ApiV1ServerConfig::toJson() const
|
|
||||||
{
|
|
||||||
QJsonObject json = ServerConfig::toJson();
|
|
||||||
|
|
||||||
if (!name.isEmpty()) {
|
|
||||||
json[config_key::name] = name;
|
|
||||||
}
|
|
||||||
if (!description.isEmpty()) {
|
|
||||||
json[config_key::description] = description;
|
|
||||||
}
|
|
||||||
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
#ifndef APIV1SERVERCONFIG_H
|
|
||||||
#define APIV1SERVERCONFIG_H
|
|
||||||
|
|
||||||
#include "serverConfig.h"
|
|
||||||
|
|
||||||
class ApiV1ServerConfig : public ServerConfig
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
ApiV1ServerConfig(const QJsonObject &serverConfigObject);
|
|
||||||
|
|
||||||
QJsonObject toJson() const override;
|
|
||||||
|
|
||||||
QString name;
|
|
||||||
QString description;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // APIV1SERVERCONFIG_H
|
|
||||||
|
|
@ -1,125 +0,0 @@
|
||||||
#include "apiV2ServerConfig.h"
|
|
||||||
|
|
||||||
#include <QJsonArray>
|
|
||||||
#include <QJsonDocument>
|
|
||||||
|
|
||||||
#include "protocols/protocols_defs.h"
|
|
||||||
|
|
||||||
using namespace amnezia;
|
|
||||||
|
|
||||||
ApiV2ServerConfig::ApiV2ServerConfig(const QJsonObject &serverConfigObject) : ServerConfig(serverConfigObject)
|
|
||||||
{
|
|
||||||
name = serverConfigObject.value(config_key::name).toString();
|
|
||||||
description = serverConfigObject.value(config_key::description).toString();
|
|
||||||
|
|
||||||
auto apiConfigObject = serverConfigObject.value("api_config").toObject();
|
|
||||||
|
|
||||||
auto availableCountriesArray = apiConfigObject.value("available_countries").toArray();
|
|
||||||
for (const auto &countryValue : availableCountriesArray) {
|
|
||||||
auto countryObject = countryValue.toObject();
|
|
||||||
apiv2::Country country;
|
|
||||||
country.code = countryObject.value("server_country_code").toString();
|
|
||||||
country.name = countryObject.value("server_country_name").toString();
|
|
||||||
apiConfig.availableCountries.append(country);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto subscriptionObject = apiConfigObject.value("subscription").toObject();
|
|
||||||
apiConfig.subscription.end_date = subscriptionObject.value("end_date").toString();
|
|
||||||
|
|
||||||
auto publicKeyObject = apiConfigObject.value("public_key").toObject();
|
|
||||||
apiConfig.publicKey.expiresAt = publicKeyObject.value("expires_at").toString();
|
|
||||||
|
|
||||||
apiConfig.serverCountryCode = apiConfigObject.value("server_country_code").toString();
|
|
||||||
apiConfig.serverCountryName = apiConfigObject.value("server_country_name").toString();
|
|
||||||
|
|
||||||
apiConfig.serviceProtocol = apiConfigObject.value("service_protocol").toString();
|
|
||||||
apiConfig.serviceType = apiConfigObject.value("service_type").toString();
|
|
||||||
|
|
||||||
apiConfig.userCountryCode = apiConfigObject.value("user_country_code").toString();
|
|
||||||
|
|
||||||
apiConfig.vpnKey = apiConfigObject.value("vpn_key").toString();
|
|
||||||
|
|
||||||
auto authDataObject = serverConfigObject.value("auth_data").toObject();
|
|
||||||
apiConfig.authData.apiKey = authDataObject.value("api_key").toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
QJsonObject ApiV2ServerConfig::toJson() const
|
|
||||||
{
|
|
||||||
QJsonObject json = ServerConfig::toJson();
|
|
||||||
|
|
||||||
if (!name.isEmpty()) {
|
|
||||||
json[config_key::name] = name;
|
|
||||||
}
|
|
||||||
if (!description.isEmpty()) {
|
|
||||||
json[config_key::description] = description;
|
|
||||||
}
|
|
||||||
|
|
||||||
QJsonObject apiConfigJson;
|
|
||||||
|
|
||||||
if (!apiConfig.availableCountries.isEmpty()) {
|
|
||||||
QJsonArray availableCountriesArray;
|
|
||||||
for (const auto &country : apiConfig.availableCountries) {
|
|
||||||
QJsonObject countryObject;
|
|
||||||
if (!country.code.isEmpty()) {
|
|
||||||
countryObject["server_country_code"] = country.code;
|
|
||||||
}
|
|
||||||
if (!country.name.isEmpty()) {
|
|
||||||
countryObject["server_country_name"] = country.name;
|
|
||||||
}
|
|
||||||
if (!countryObject.isEmpty()) {
|
|
||||||
availableCountriesArray.append(countryObject);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!availableCountriesArray.isEmpty()) {
|
|
||||||
apiConfigJson["available_countries"] = availableCountriesArray;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!apiConfig.subscription.end_date.isEmpty()) {
|
|
||||||
QJsonObject subscriptionObject;
|
|
||||||
subscriptionObject["end_date"] = apiConfig.subscription.end_date;
|
|
||||||
apiConfigJson["subscription"] = subscriptionObject;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!apiConfig.publicKey.expiresAt.isEmpty()) {
|
|
||||||
QJsonObject publicKeyObject;
|
|
||||||
publicKeyObject["expires_at"] = apiConfig.publicKey.expiresAt;
|
|
||||||
apiConfigJson["public_key"] = publicKeyObject;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!apiConfig.serverCountryCode.isEmpty()) {
|
|
||||||
apiConfigJson["server_country_code"] = apiConfig.serverCountryCode;
|
|
||||||
}
|
|
||||||
if (!apiConfig.serverCountryName.isEmpty()) {
|
|
||||||
apiConfigJson["server_country_name"] = apiConfig.serverCountryName;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!apiConfig.serviceProtocol.isEmpty()) {
|
|
||||||
apiConfigJson["service_protocol"] = apiConfig.serviceProtocol;
|
|
||||||
}
|
|
||||||
if (!apiConfig.serviceType.isEmpty()) {
|
|
||||||
apiConfigJson["service_type"] = apiConfig.serviceType;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!apiConfig.userCountryCode.isEmpty()) {
|
|
||||||
apiConfigJson["user_country_code"] = apiConfig.userCountryCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!apiConfig.vpnKey.isEmpty()) {
|
|
||||||
apiConfigJson["vpn_key"] = apiConfig.vpnKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
QJsonObject authDataJson;
|
|
||||||
if (!apiConfig.authData.apiKey.isEmpty()) {
|
|
||||||
authDataJson["api_key"] = apiConfig.authData.apiKey;
|
|
||||||
}
|
|
||||||
if (!authDataJson.isEmpty()) {
|
|
||||||
apiConfigJson["auth_data"] = authDataJson;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!apiConfigJson.isEmpty()) {
|
|
||||||
json["api_config"] = apiConfigJson;
|
|
||||||
}
|
|
||||||
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
|
|
@ -1,61 +0,0 @@
|
||||||
#ifndef APIV2SERVERCONFIG_H
|
|
||||||
#define APIV2SERVERCONFIG_H
|
|
||||||
|
|
||||||
#include "serverConfig.h"
|
|
||||||
|
|
||||||
namespace apiv2
|
|
||||||
{
|
|
||||||
struct Country {
|
|
||||||
QString code;
|
|
||||||
QString name;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct PublicKey
|
|
||||||
{
|
|
||||||
QString expiresAt;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Subscription
|
|
||||||
{
|
|
||||||
QString end_date;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct AuthData
|
|
||||||
{
|
|
||||||
QString apiKey;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ApiConfig {
|
|
||||||
QVector<Country> availableCountries;
|
|
||||||
|
|
||||||
Subscription subscription;
|
|
||||||
PublicKey publicKey;
|
|
||||||
|
|
||||||
AuthData authData;
|
|
||||||
|
|
||||||
QString serverCountryCode;
|
|
||||||
QString serverCountryName;
|
|
||||||
|
|
||||||
QString serviceProtocol;
|
|
||||||
QString serviceType;
|
|
||||||
|
|
||||||
QString userCountryCode;
|
|
||||||
|
|
||||||
QString vpnKey;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
class ApiV2ServerConfig : public ServerConfig
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
ApiV2ServerConfig(const QJsonObject &serverConfigObject);
|
|
||||||
|
|
||||||
QJsonObject toJson() const override;
|
|
||||||
|
|
||||||
QString name;
|
|
||||||
QString description;
|
|
||||||
|
|
||||||
apiv2::ApiConfig apiConfig;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // APIV2SERVERCONFIG_H
|
|
||||||
|
|
@ -1,48 +0,0 @@
|
||||||
#include "selfHostedServerConfig.h"
|
|
||||||
|
|
||||||
#include <QJsonArray>
|
|
||||||
#include <QJsonDocument>
|
|
||||||
|
|
||||||
#include "protocols/protocols_defs.h"
|
|
||||||
|
|
||||||
using namespace amnezia;
|
|
||||||
|
|
||||||
SelfHostedServerConfig::SelfHostedServerConfig(const QJsonObject &serverConfigObject) : ServerConfig(serverConfigObject)
|
|
||||||
{
|
|
||||||
name = serverConfigObject.value(config_key::description).toString();
|
|
||||||
if (name.isEmpty()) {
|
|
||||||
name = serverConfigObject.value(config_key::hostName).toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
serverCredentials.hostName = serverConfigObject.value(config_key::hostName).toString();
|
|
||||||
serverCredentials.userName = serverConfigObject.value(config_key::userName).toString();
|
|
||||||
serverCredentials.secretData = serverConfigObject.value(config_key::password).toString();
|
|
||||||
serverCredentials.port = serverConfigObject.value(config_key::port).toInt(22);
|
|
||||||
}
|
|
||||||
|
|
||||||
QJsonObject SelfHostedServerConfig::toJson() const
|
|
||||||
{
|
|
||||||
// Сначала вызываем родительскую функцию для сериализации базовых полей
|
|
||||||
QJsonObject json = ServerConfig::toJson();
|
|
||||||
|
|
||||||
// Добавляем имя только если оно не пустое
|
|
||||||
if (!name.isEmpty()) {
|
|
||||||
json[config_key::description] = name; // Используем description как в конструкторе
|
|
||||||
}
|
|
||||||
|
|
||||||
// Добавляем credentials только если они не пустые
|
|
||||||
if (!serverCredentials.hostName.isEmpty()) {
|
|
||||||
json[config_key::hostName] = serverCredentials.hostName;
|
|
||||||
}
|
|
||||||
if (!serverCredentials.userName.isEmpty()) {
|
|
||||||
json[config_key::userName] = serverCredentials.userName;
|
|
||||||
}
|
|
||||||
if (!serverCredentials.secretData.isEmpty()) {
|
|
||||||
json[config_key::password] = serverCredentials.secretData;
|
|
||||||
}
|
|
||||||
if (serverCredentials.port != 22) { // Добавляем порт только если не дефолтный
|
|
||||||
json[config_key::port] = serverCredentials.port;
|
|
||||||
}
|
|
||||||
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
#ifndef SELFHOSTEDSERVERCONFIG_H
|
|
||||||
#define SELFHOSTEDSERVERCONFIG_H
|
|
||||||
|
|
||||||
#include "core/defs.h"
|
|
||||||
#include "serverConfig.h"
|
|
||||||
|
|
||||||
class SelfHostedServerConfig : public ServerConfig
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
SelfHostedServerConfig(const QJsonObject &serverConfigObject);
|
|
||||||
|
|
||||||
QJsonObject toJson() const override;
|
|
||||||
|
|
||||||
QString name;
|
|
||||||
|
|
||||||
amnezia::ServerCredentials serverCredentials;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // SELFHOSTEDSERVERCONFIG_H
|
|
||||||
|
|
@ -1,167 +0,0 @@
|
||||||
#include "serverConfig.h"
|
|
||||||
|
|
||||||
#include <QJsonArray>
|
|
||||||
|
|
||||||
#include "apiV1ServerConfig.h"
|
|
||||||
#include "apiV2ServerConfig.h"
|
|
||||||
#include "containers/containers_defs.h"
|
|
||||||
#include "core/models/protocols/awgProtocolConfig.h"
|
|
||||||
#include "core/models/protocols/cloakProtocolConfig.h"
|
|
||||||
#include "core/models/protocols/openvpnProtocolConfig.h"
|
|
||||||
#include "core/models/protocols/protocolConfig.h"
|
|
||||||
#include "core/models/protocols/shadowsocksProtocolConfig.h"
|
|
||||||
#include "core/models/protocols/xrayProtocolConfig.h"
|
|
||||||
#include "protocols/protocols_defs.h"
|
|
||||||
#include "selfHostedServerConfig.h"
|
|
||||||
|
|
||||||
using namespace amnezia;
|
|
||||||
|
|
||||||
ServerConfig::ServerConfig(const QJsonObject &serverConfigObject)
|
|
||||||
{
|
|
||||||
type = static_cast<ServerConfigType>(serverConfigObject.value(config_key::configVersion).toInt(0));
|
|
||||||
|
|
||||||
hostName = serverConfigObject.value(config_key::hostName).toString();
|
|
||||||
|
|
||||||
dns1 = serverConfigObject.value(config_key::dns1).toString();
|
|
||||||
dns2 = serverConfigObject.value(config_key::dns2).toString();
|
|
||||||
|
|
||||||
defaultContainer = serverConfigObject.value(config_key::defaultContainer).toString();
|
|
||||||
|
|
||||||
crc = serverConfigObject.value(config_key::crc).toInt(0);
|
|
||||||
nameOverriddenByUser = serverConfigObject.value(config_key::nameOverriddenByUser).toBool(false);
|
|
||||||
|
|
||||||
auto containers = serverConfigObject.value(config_key::containers).toArray();
|
|
||||||
for (const auto &container : std::as_const(containers)) {
|
|
||||||
auto containerObject = container.toObject();
|
|
||||||
|
|
||||||
auto containerName = containerObject.value(config_key::container).toString();
|
|
||||||
|
|
||||||
ContainerConfig containerConfig;
|
|
||||||
containerConfig.containerName = containerName;
|
|
||||||
|
|
||||||
auto protocols = ContainerProps::protocolsForContainer(ContainerProps::containerFromString(containerName));
|
|
||||||
for (const auto &protocol : protocols) {
|
|
||||||
auto protocolName = ProtocolProps::protoToString(protocol);
|
|
||||||
auto protocolConfigObject = containerObject.value(protocolName).toObject();
|
|
||||||
|
|
||||||
switch (protocol) {
|
|
||||||
case Proto::OpenVpn: {
|
|
||||||
containerConfig.protocolConfigs.insert(protocolName,
|
|
||||||
QSharedPointer<OpenVpnProtocolConfig>::create(protocolConfigObject, protocolName));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case Proto::ShadowSocks: {
|
|
||||||
containerConfig.protocolConfigs.insert(
|
|
||||||
protocolName, QSharedPointer<ShadowsocksProtocolConfig>::create(protocolConfigObject, protocolName));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case Proto::Cloak: {
|
|
||||||
containerConfig.protocolConfigs.insert(protocolName,
|
|
||||||
QSharedPointer<CloakProtocolConfig>::create(protocolConfigObject, protocolName));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case Proto::WireGuard: {
|
|
||||||
containerConfig.protocolConfigs.insert(protocolName,
|
|
||||||
QSharedPointer<WireGuardProtocolConfig>::create(protocolConfigObject, protocolName));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case Proto::Awg: {
|
|
||||||
containerConfig.protocolConfigs.insert(protocolName,
|
|
||||||
QSharedPointer<AwgProtocolConfig>::create(protocolConfigObject, protocolName));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case Proto::Xray: {
|
|
||||||
containerConfig.protocolConfigs.insert(protocolName,
|
|
||||||
QSharedPointer<XrayProtocolConfig>::create(protocolConfigObject, protocolName));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case Proto::Ikev2: break;
|
|
||||||
case Proto::L2tp: break;
|
|
||||||
case Proto::SSXray: break;
|
|
||||||
case Proto::TorWebSite: break;
|
|
||||||
case Proto::Dns: break;
|
|
||||||
case Proto::Sftp: break;
|
|
||||||
case Proto::Socks5Proxy: break;
|
|
||||||
default: break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
containerConfigs.insert(containerName, containerConfig);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QSharedPointer<ServerConfig> ServerConfig::createServerConfig(const QJsonObject &serverConfigObject)
|
|
||||||
{
|
|
||||||
auto type = static_cast<ServerConfigType>(serverConfigObject.value(config_key::configVersion).toInt(0));
|
|
||||||
|
|
||||||
switch (type) {
|
|
||||||
case ServerConfigType::SelfHosted: return QSharedPointer<SelfHostedServerConfig>::create(serverConfigObject);
|
|
||||||
case ServerConfigType::ApiV1: return QSharedPointer<ApiV1ServerConfig>::create(serverConfigObject);
|
|
||||||
case ServerConfigType::ApiV2: return QSharedPointer<ApiV2ServerConfig>::create(serverConfigObject);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ServerConfigVariant ServerConfig::getServerConfigVariant(const QSharedPointer<ServerConfig> &serverConfig)
|
|
||||||
{
|
|
||||||
ServerConfigVariant variant;
|
|
||||||
switch (serverConfig->type) {
|
|
||||||
case amnezia::ServerConfigType::SelfHosted: variant = qSharedPointerCast<SelfHostedServerConfig>(serverConfig); break;
|
|
||||||
case amnezia::ServerConfigType::ApiV1: variant = qSharedPointerCast<ApiV1ServerConfig>(serverConfig); break;
|
|
||||||
case amnezia::ServerConfigType::ApiV2: variant = qSharedPointerCast<ApiV2ServerConfig>(serverConfig); break;
|
|
||||||
}
|
|
||||||
return variant;
|
|
||||||
}
|
|
||||||
|
|
||||||
QJsonObject ServerConfig::toJson() const
|
|
||||||
{
|
|
||||||
QJsonObject json;
|
|
||||||
|
|
||||||
if (type != ServerConfigType::SelfHosted) {
|
|
||||||
json[config_key::configVersion] = static_cast<int>(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!hostName.isEmpty()) {
|
|
||||||
json[config_key::hostName] = hostName;
|
|
||||||
}
|
|
||||||
if (!dns1.isEmpty()) {
|
|
||||||
json[config_key::dns1] = dns1;
|
|
||||||
}
|
|
||||||
if (!dns2.isEmpty()) {
|
|
||||||
json[config_key::dns2] = dns2;
|
|
||||||
}
|
|
||||||
if (!defaultContainer.isEmpty()) {
|
|
||||||
json[config_key::defaultContainer] = defaultContainer;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!containerConfigs.isEmpty()) {
|
|
||||||
QJsonArray containersArray;
|
|
||||||
for (const auto &containerConfig : containerConfigs) {
|
|
||||||
QJsonObject containerObject;
|
|
||||||
containerObject[config_key::container] = containerConfig.containerName;
|
|
||||||
|
|
||||||
if (!containerConfig.protocolConfigs.isEmpty()) {
|
|
||||||
for (const auto &protocolConfig : containerConfig.protocolConfigs) {
|
|
||||||
QJsonObject protocolJson = protocolConfig->toJson();
|
|
||||||
if (!protocolJson.isEmpty()) {
|
|
||||||
containerObject[protocolConfig->protocolName] = protocolJson;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
containersArray.append(containerObject);
|
|
||||||
}
|
|
||||||
if (!containersArray.isEmpty()) {
|
|
||||||
json[config_key::containers] = containersArray;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ServerConfig::updateProtocolConfig(const QString &containerName, const QMap<QString, QSharedPointer<ProtocolConfig>> &protocolConfigs)
|
|
||||||
{
|
|
||||||
if (containerConfigs.contains(containerName)) {
|
|
||||||
ContainerConfig &containerConfig = containerConfigs[containerName];
|
|
||||||
containerConfig.protocolConfigs = protocolConfigs;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,45 +0,0 @@
|
||||||
#ifndef SERVERCONFIG_H
|
|
||||||
#define SERVERCONFIG_H
|
|
||||||
|
|
||||||
#include <QJsonObject>
|
|
||||||
#include <QSharedPointer>
|
|
||||||
#include <QString>
|
|
||||||
|
|
||||||
#include "core/defs.h"
|
|
||||||
#include "core/models/containers/containerConfig.h"
|
|
||||||
|
|
||||||
class SelfHostedServerConfig;
|
|
||||||
class ApiV1ServerConfig;
|
|
||||||
class ApiV2ServerConfig;
|
|
||||||
|
|
||||||
using ServerConfigVariant =
|
|
||||||
std::variant<QSharedPointer<SelfHostedServerConfig>, QSharedPointer<ApiV1ServerConfig>, QSharedPointer<ApiV2ServerConfig> >;
|
|
||||||
|
|
||||||
class ServerConfig
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
ServerConfig(const QJsonObject &serverConfigObject);
|
|
||||||
|
|
||||||
virtual QJsonObject toJson() const;
|
|
||||||
|
|
||||||
static QSharedPointer<ServerConfig> createServerConfig(const QJsonObject &serverConfigObject);
|
|
||||||
static ServerConfigVariant getServerConfigVariant(const QSharedPointer<ServerConfig> &serverConfig);
|
|
||||||
|
|
||||||
void updateProtocolConfig(const QString &containerName, const QMap<QString, QSharedPointer<ProtocolConfig>> &protocolConfigs);
|
|
||||||
|
|
||||||
amnezia::ServerConfigType type;
|
|
||||||
|
|
||||||
QString hostName;
|
|
||||||
|
|
||||||
QString dns1;
|
|
||||||
QString dns2;
|
|
||||||
|
|
||||||
QString defaultContainer;
|
|
||||||
|
|
||||||
bool nameOverriddenByUser;
|
|
||||||
int crc; // TODO it makes sense to add for all server types or move it to the api
|
|
||||||
|
|
||||||
QMap<QString, ContainerConfig> containerConfigs;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // SERVERCONFIG_H
|
|
||||||
|
|
@ -169,11 +169,14 @@ bool Daemon::maybeUpdateResolvers(const InterfaceConfig& config) {
|
||||||
if ((config.m_hopType == InterfaceConfig::MultiHopExit) ||
|
if ((config.m_hopType == InterfaceConfig::MultiHopExit) ||
|
||||||
(config.m_hopType == InterfaceConfig::SingleHop)) {
|
(config.m_hopType == InterfaceConfig::SingleHop)) {
|
||||||
QList<QHostAddress> resolvers;
|
QList<QHostAddress> resolvers;
|
||||||
resolvers.append(QHostAddress(config.m_dnsServer));
|
resolvers.append(QHostAddress(config.m_primaryDnsServer));
|
||||||
|
if (!config.m_secondaryDnsServer.isEmpty()) {
|
||||||
|
resolvers.append(QHostAddress(config.m_secondaryDnsServer));
|
||||||
|
}
|
||||||
|
|
||||||
// If the DNS is not the Gateway, it's a user defined DNS
|
// If the DNS is not the Gateway, it's a user defined DNS
|
||||||
// thus, not add any other :)
|
// thus, not add any other :)
|
||||||
if (config.m_dnsServer == config.m_serverIpv4Gateway) {
|
if (config.m_primaryDnsServer == config.m_serverIpv4Gateway) {
|
||||||
resolvers.append(QHostAddress(config.m_serverIpv6Gateway));
|
resolvers.append(QHostAddress(config.m_serverIpv6Gateway));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -279,15 +282,26 @@ bool Daemon::parseConfig(const QJsonObject& obj, InterfaceConfig& config) {
|
||||||
config.m_serverIpv4Gateway = obj.value("serverIpv4Gateway").toString();
|
config.m_serverIpv4Gateway = obj.value("serverIpv4Gateway").toString();
|
||||||
config.m_serverIpv6Gateway = obj.value("serverIpv6Gateway").toString();
|
config.m_serverIpv6Gateway = obj.value("serverIpv6Gateway").toString();
|
||||||
|
|
||||||
if (!obj.contains("dnsServer")) {
|
if (!obj.contains("primaryDnsServer")) {
|
||||||
config.m_dnsServer = QString();
|
config.m_primaryDnsServer = QString();
|
||||||
} else {
|
} else {
|
||||||
QJsonValue value = obj.value("dnsServer");
|
QJsonValue value = obj.value("primaryDnsServer");
|
||||||
if (!value.isString()) {
|
if (!value.isString()) {
|
||||||
logger.error() << "dnsServer is not a string";
|
logger.error() << "dnsServer is not a string";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
config.m_dnsServer = value.toString();
|
config.m_primaryDnsServer = value.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!obj.contains("secondaryDnsServer")) {
|
||||||
|
config.m_secondaryDnsServer = QString();
|
||||||
|
} else {
|
||||||
|
QJsonValue value = obj.value("secondaryDnsServer");
|
||||||
|
if (!value.isString()) {
|
||||||
|
logger.error() << "dnsServer is not a string";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
config.m_secondaryDnsServer = value.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!obj.contains("hopType")) {
|
if (!obj.contains("hopType")) {
|
||||||
|
|
@ -391,6 +405,13 @@ bool Daemon::parseConfig(const QJsonObject& obj, InterfaceConfig& config) {
|
||||||
if (!obj.value("S2").isNull()) {
|
if (!obj.value("S2").isNull()) {
|
||||||
config.m_responsePacketJunkSize = obj.value("S2").toString();
|
config.m_responsePacketJunkSize = obj.value("S2").toString();
|
||||||
}
|
}
|
||||||
|
if (!obj.value("S3").isNull()) {
|
||||||
|
config.m_cookieReplyPacketJunkSize = obj.value("S3").toString();
|
||||||
|
}
|
||||||
|
if (!obj.value("S4").isNull()) {
|
||||||
|
config.m_transportPacketJunkSize = obj.value("S4").toString();
|
||||||
|
}
|
||||||
|
|
||||||
if (!obj.value("H1").isNull()) {
|
if (!obj.value("H1").isNull()) {
|
||||||
config.m_initPacketMagicHeader = obj.value("H1").toString();
|
config.m_initPacketMagicHeader = obj.value("H1").toString();
|
||||||
}
|
}
|
||||||
|
|
@ -404,6 +425,34 @@ bool Daemon::parseConfig(const QJsonObject& obj, InterfaceConfig& config) {
|
||||||
config.m_transportPacketMagicHeader = obj.value("H4").toString();
|
config.m_transportPacketMagicHeader = obj.value("H4").toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!obj.value("I1").isNull()) {
|
||||||
|
config.m_specialJunk["I1"] = obj.value("I1").toString();
|
||||||
|
}
|
||||||
|
if (!obj.value("I2").isNull()) {
|
||||||
|
config.m_specialJunk["I2"] = obj.value("I2").toString();
|
||||||
|
}
|
||||||
|
if (!obj.value("I3").isNull()) {
|
||||||
|
config.m_specialJunk["I3"] = obj.value("I3").toString();
|
||||||
|
}
|
||||||
|
if (!obj.value("I4").isNull()) {
|
||||||
|
config.m_specialJunk["I4"] = obj.value("I4").toString();
|
||||||
|
}
|
||||||
|
if (!obj.value("I5").isNull()) {
|
||||||
|
config.m_specialJunk["I5"] = obj.value("I5").toString();
|
||||||
|
}
|
||||||
|
if (!obj.value("J1").isNull()) {
|
||||||
|
config.m_controlledJunk["J1"] = obj.value("J1").toString();
|
||||||
|
}
|
||||||
|
if (!obj.value("J2").isNull()) {
|
||||||
|
config.m_controlledJunk["J2"] = obj.value("J2").toString();
|
||||||
|
}
|
||||||
|
if (!obj.value("J3").isNull()) {
|
||||||
|
config.m_controlledJunk["J3"] = obj.value("J3").toString();
|
||||||
|
}
|
||||||
|
if (!obj.value("Itime").isNull()) {
|
||||||
|
config.m_specialHandshakeTimeout = obj.value("Itime").toString();
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,8 @@ QJsonObject InterfaceConfig::toJson() const {
|
||||||
(m_hopType == InterfaceConfig::SingleHop)) {
|
(m_hopType == InterfaceConfig::SingleHop)) {
|
||||||
json.insert("serverIpv4Gateway", QJsonValue(m_serverIpv4Gateway));
|
json.insert("serverIpv4Gateway", QJsonValue(m_serverIpv4Gateway));
|
||||||
json.insert("serverIpv6Gateway", QJsonValue(m_serverIpv6Gateway));
|
json.insert("serverIpv6Gateway", QJsonValue(m_serverIpv6Gateway));
|
||||||
json.insert("dnsServer", QJsonValue(m_dnsServer));
|
json.insert("primaryDnsServer", QJsonValue(m_primaryDnsServer));
|
||||||
|
json.insert("secondaryDnsServer", QJsonValue(m_secondaryDnsServer));
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonArray allowedIPAddesses;
|
QJsonArray allowedIPAddesses;
|
||||||
|
|
@ -100,11 +101,15 @@ QString InterfaceConfig::toWgConf(const QMap<QString, QString>& extra) const {
|
||||||
out << "MTU = " << m_deviceMTU << "\n";
|
out << "MTU = " << m_deviceMTU << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_dnsServer.isNull()) {
|
if (!m_primaryDnsServer.isNull()) {
|
||||||
QStringList dnsServers(m_dnsServer);
|
QStringList dnsServers;
|
||||||
|
dnsServers.append(m_primaryDnsServer);
|
||||||
|
if (!m_secondaryDnsServer.isNull()) {
|
||||||
|
dnsServers.append(m_secondaryDnsServer);
|
||||||
|
}
|
||||||
// If the DNS is not the Gateway, it's a user defined DNS
|
// If the DNS is not the Gateway, it's a user defined DNS
|
||||||
// thus, not add any other :)
|
// thus, not add any other :)
|
||||||
if (m_dnsServer == m_serverIpv4Gateway) {
|
if (m_primaryDnsServer == m_serverIpv4Gateway) {
|
||||||
dnsServers.append(m_serverIpv6Gateway);
|
dnsServers.append(m_serverIpv6Gateway);
|
||||||
}
|
}
|
||||||
out << "DNS = " << dnsServers.join(", ") << "\n";
|
out << "DNS = " << dnsServers.join(", ") << "\n";
|
||||||
|
|
@ -125,6 +130,12 @@ QString InterfaceConfig::toWgConf(const QMap<QString, QString>& extra) const {
|
||||||
if (!m_responsePacketJunkSize.isNull()) {
|
if (!m_responsePacketJunkSize.isNull()) {
|
||||||
out << "S2 = " << m_responsePacketJunkSize << "\n";
|
out << "S2 = " << m_responsePacketJunkSize << "\n";
|
||||||
}
|
}
|
||||||
|
if (!m_cookieReplyPacketJunkSize.isNull()) {
|
||||||
|
out << "S3 = " << m_cookieReplyPacketJunkSize << "\n";
|
||||||
|
}
|
||||||
|
if (!m_transportPacketJunkSize.isNull()) {
|
||||||
|
out << "S4 = " << m_transportPacketJunkSize << "\n";
|
||||||
|
}
|
||||||
if (!m_initPacketMagicHeader.isNull()) {
|
if (!m_initPacketMagicHeader.isNull()) {
|
||||||
out << "H1 = " << m_initPacketMagicHeader << "\n";
|
out << "H1 = " << m_initPacketMagicHeader << "\n";
|
||||||
}
|
}
|
||||||
|
|
@ -138,6 +149,16 @@ QString InterfaceConfig::toWgConf(const QMap<QString, QString>& extra) const {
|
||||||
out << "H4 = " << m_transportPacketMagicHeader << "\n";
|
out << "H4 = " << m_transportPacketMagicHeader << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const QString& key : m_specialJunk.keys()) {
|
||||||
|
out << key << " = " << m_specialJunk[key] << "\n";
|
||||||
|
}
|
||||||
|
for (const QString& key : m_controlledJunk.keys()) {
|
||||||
|
out << key << " = " << m_controlledJunk[key] << "\n";
|
||||||
|
}
|
||||||
|
if (!m_specialHandshakeTimeout.isNull()) {
|
||||||
|
out << "Itime = " << m_specialHandshakeTimeout << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
// If any extra config was provided, append it now.
|
// If any extra config was provided, append it now.
|
||||||
for (const QString& key : extra.keys()) {
|
for (const QString& key : extra.keys()) {
|
||||||
out << key << " = " << extra[key] << "\n";
|
out << key << " = " << extra[key] << "\n";
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,8 @@ class InterfaceConfig {
|
||||||
QString m_serverIpv4AddrIn;
|
QString m_serverIpv4AddrIn;
|
||||||
QString m_serverPskKey;
|
QString m_serverPskKey;
|
||||||
QString m_serverIpv6AddrIn;
|
QString m_serverIpv6AddrIn;
|
||||||
QString m_dnsServer;
|
QString m_primaryDnsServer;
|
||||||
|
QString m_secondaryDnsServer;
|
||||||
int m_serverPort = 0;
|
int m_serverPort = 0;
|
||||||
int m_deviceMTU = 1420;
|
int m_deviceMTU = 1420;
|
||||||
QList<IPAddress> m_allowedIPAddressRanges;
|
QList<IPAddress> m_allowedIPAddressRanges;
|
||||||
|
|
@ -49,10 +50,15 @@ class InterfaceConfig {
|
||||||
QString m_junkPacketMaxSize;
|
QString m_junkPacketMaxSize;
|
||||||
QString m_initPacketJunkSize;
|
QString m_initPacketJunkSize;
|
||||||
QString m_responsePacketJunkSize;
|
QString m_responsePacketJunkSize;
|
||||||
|
QString m_cookieReplyPacketJunkSize;
|
||||||
|
QString m_transportPacketJunkSize;
|
||||||
QString m_initPacketMagicHeader;
|
QString m_initPacketMagicHeader;
|
||||||
QString m_responsePacketMagicHeader;
|
QString m_responsePacketMagicHeader;
|
||||||
QString m_underloadPacketMagicHeader;
|
QString m_underloadPacketMagicHeader;
|
||||||
QString m_transportPacketMagicHeader;
|
QString m_transportPacketMagicHeader;
|
||||||
|
QMap<QString, QString> m_specialJunk;
|
||||||
|
QMap<QString, QString> m_controlledJunk;
|
||||||
|
QString m_specialHandshakeTimeout;
|
||||||
|
|
||||||
QJsonObject toJson() const;
|
QJsonObject toJson() const;
|
||||||
QString toWgConf(
|
QString toWgConf(
|
||||||
|
|
|
||||||
|
|
@ -149,7 +149,14 @@ void LocalSocketController::activate(const QJsonObject &rawConfig) {
|
||||||
json.insert("serverPort", wgConfig.value(amnezia::config_key::port).toInt());
|
json.insert("serverPort", wgConfig.value(amnezia::config_key::port).toInt());
|
||||||
json.insert("serverIpv4Gateway", wgConfig.value(amnezia::config_key::hostName));
|
json.insert("serverIpv4Gateway", wgConfig.value(amnezia::config_key::hostName));
|
||||||
// json.insert("serverIpv6Gateway", QJsonValue(hop.m_server.ipv6Gateway()));
|
// json.insert("serverIpv6Gateway", QJsonValue(hop.m_server.ipv6Gateway()));
|
||||||
json.insert("dnsServer", rawConfig.value(amnezia::config_key::dns1));
|
|
||||||
|
json.insert("primaryDnsServer", rawConfig.value(amnezia::config_key::dns1));
|
||||||
|
|
||||||
|
// We don't use secondary DNS if primary DNS is AmneziaDNS
|
||||||
|
if (!rawConfig.value(amnezia::config_key::dns1).toString().
|
||||||
|
contains(amnezia::protocols::dns::amneziaDnsIp)) {
|
||||||
|
json.insert("secondaryDnsServer", rawConfig.value(amnezia::config_key::dns2));
|
||||||
|
}
|
||||||
|
|
||||||
QJsonArray jsAllowedIPAddesses;
|
QJsonArray jsAllowedIPAddesses;
|
||||||
|
|
||||||
|
|
@ -237,28 +244,61 @@ void LocalSocketController::activate(const QJsonObject &rawConfig) {
|
||||||
json.insert(amnezia::config_key::junkPacketMaxSize, wgConfig.value(amnezia::config_key::junkPacketMaxSize));
|
json.insert(amnezia::config_key::junkPacketMaxSize, wgConfig.value(amnezia::config_key::junkPacketMaxSize));
|
||||||
json.insert(amnezia::config_key::initPacketJunkSize, wgConfig.value(amnezia::config_key::initPacketJunkSize));
|
json.insert(amnezia::config_key::initPacketJunkSize, wgConfig.value(amnezia::config_key::initPacketJunkSize));
|
||||||
json.insert(amnezia::config_key::responsePacketJunkSize, wgConfig.value(amnezia::config_key::responsePacketJunkSize));
|
json.insert(amnezia::config_key::responsePacketJunkSize, wgConfig.value(amnezia::config_key::responsePacketJunkSize));
|
||||||
|
json.insert(amnezia::config_key::cookieReplyPacketJunkSize, wgConfig.value(amnezia::config_key::cookieReplyPacketJunkSize));
|
||||||
|
json.insert(amnezia::config_key::transportPacketJunkSize, wgConfig.value(amnezia::config_key::transportPacketJunkSize));
|
||||||
json.insert(amnezia::config_key::initPacketMagicHeader, wgConfig.value(amnezia::config_key::initPacketMagicHeader));
|
json.insert(amnezia::config_key::initPacketMagicHeader, wgConfig.value(amnezia::config_key::initPacketMagicHeader));
|
||||||
json.insert(amnezia::config_key::responsePacketMagicHeader, wgConfig.value(amnezia::config_key::responsePacketMagicHeader));
|
json.insert(amnezia::config_key::responsePacketMagicHeader, wgConfig.value(amnezia::config_key::responsePacketMagicHeader));
|
||||||
json.insert(amnezia::config_key::underloadPacketMagicHeader, wgConfig.value(amnezia::config_key::underloadPacketMagicHeader));
|
json.insert(amnezia::config_key::underloadPacketMagicHeader, wgConfig.value(amnezia::config_key::underloadPacketMagicHeader));
|
||||||
json.insert(amnezia::config_key::transportPacketMagicHeader, wgConfig.value(amnezia::config_key::transportPacketMagicHeader));
|
json.insert(amnezia::config_key::transportPacketMagicHeader, wgConfig.value(amnezia::config_key::transportPacketMagicHeader));
|
||||||
|
json.insert(amnezia::config_key::specialJunk1, wgConfig.value(amnezia::config_key::specialJunk1));
|
||||||
|
json.insert(amnezia::config_key::specialJunk2, wgConfig.value(amnezia::config_key::specialJunk2));
|
||||||
|
json.insert(amnezia::config_key::specialJunk3, wgConfig.value(amnezia::config_key::specialJunk3));
|
||||||
|
json.insert(amnezia::config_key::specialJunk4, wgConfig.value(amnezia::config_key::specialJunk4));
|
||||||
|
json.insert(amnezia::config_key::specialJunk5, wgConfig.value(amnezia::config_key::specialJunk5));
|
||||||
|
json.insert(amnezia::config_key::controlledJunk1, wgConfig.value(amnezia::config_key::controlledJunk1));
|
||||||
|
json.insert(amnezia::config_key::controlledJunk2, wgConfig.value(amnezia::config_key::controlledJunk2));
|
||||||
|
json.insert(amnezia::config_key::controlledJunk3, wgConfig.value(amnezia::config_key::controlledJunk3));
|
||||||
|
json.insert(amnezia::config_key::specialHandshakeTimeout, wgConfig.value(amnezia::config_key::specialHandshakeTimeout));
|
||||||
} else if (!wgConfig.value(amnezia::config_key::junkPacketCount).isUndefined()
|
} else if (!wgConfig.value(amnezia::config_key::junkPacketCount).isUndefined()
|
||||||
&& !wgConfig.value(amnezia::config_key::junkPacketMinSize).isUndefined()
|
&& !wgConfig.value(amnezia::config_key::junkPacketMinSize).isUndefined()
|
||||||
&& !wgConfig.value(amnezia::config_key::junkPacketMaxSize).isUndefined()
|
&& !wgConfig.value(amnezia::config_key::junkPacketMaxSize).isUndefined()
|
||||||
&& !wgConfig.value(amnezia::config_key::initPacketJunkSize).isUndefined()
|
&& !wgConfig.value(amnezia::config_key::initPacketJunkSize).isUndefined()
|
||||||
&& !wgConfig.value(amnezia::config_key::responsePacketJunkSize).isUndefined()
|
&& !wgConfig.value(amnezia::config_key::responsePacketJunkSize).isUndefined()
|
||||||
|
&& !wgConfig.value(amnezia::config_key::cookieReplyPacketJunkSize).isUndefined()
|
||||||
|
&& !wgConfig.value(amnezia::config_key::transportPacketJunkSize).isUndefined()
|
||||||
&& !wgConfig.value(amnezia::config_key::initPacketMagicHeader).isUndefined()
|
&& !wgConfig.value(amnezia::config_key::initPacketMagicHeader).isUndefined()
|
||||||
&& !wgConfig.value(amnezia::config_key::responsePacketMagicHeader).isUndefined()
|
&& !wgConfig.value(amnezia::config_key::responsePacketMagicHeader).isUndefined()
|
||||||
&& !wgConfig.value(amnezia::config_key::underloadPacketMagicHeader).isUndefined()
|
&& !wgConfig.value(amnezia::config_key::underloadPacketMagicHeader).isUndefined()
|
||||||
&& !wgConfig.value(amnezia::config_key::transportPacketMagicHeader).isUndefined()) {
|
&& !wgConfig.value(amnezia::config_key::transportPacketMagicHeader).isUndefined()
|
||||||
|
&& !wgConfig.value(amnezia::config_key::specialJunk1).isUndefined()
|
||||||
|
&& !wgConfig.value(amnezia::config_key::specialJunk2).isUndefined()
|
||||||
|
&& !wgConfig.value(amnezia::config_key::specialJunk3).isUndefined()
|
||||||
|
&& !wgConfig.value(amnezia::config_key::specialJunk4).isUndefined()
|
||||||
|
&& !wgConfig.value(amnezia::config_key::specialJunk5).isUndefined()
|
||||||
|
&& !wgConfig.value(amnezia::config_key::controlledJunk1).isUndefined()
|
||||||
|
&& !wgConfig.value(amnezia::config_key::controlledJunk2).isUndefined()
|
||||||
|
&& !wgConfig.value(amnezia::config_key::controlledJunk3).isUndefined()
|
||||||
|
&& !wgConfig.value(amnezia::config_key::specialHandshakeTimeout).isUndefined()) {
|
||||||
json.insert(amnezia::config_key::junkPacketCount, wgConfig.value(amnezia::config_key::junkPacketCount));
|
json.insert(amnezia::config_key::junkPacketCount, wgConfig.value(amnezia::config_key::junkPacketCount));
|
||||||
json.insert(amnezia::config_key::junkPacketMinSize, wgConfig.value(amnezia::config_key::junkPacketMinSize));
|
json.insert(amnezia::config_key::junkPacketMinSize, wgConfig.value(amnezia::config_key::junkPacketMinSize));
|
||||||
json.insert(amnezia::config_key::junkPacketMaxSize, wgConfig.value(amnezia::config_key::junkPacketMaxSize));
|
json.insert(amnezia::config_key::junkPacketMaxSize, wgConfig.value(amnezia::config_key::junkPacketMaxSize));
|
||||||
json.insert(amnezia::config_key::initPacketJunkSize, wgConfig.value(amnezia::config_key::initPacketJunkSize));
|
json.insert(amnezia::config_key::initPacketJunkSize, wgConfig.value(amnezia::config_key::initPacketJunkSize));
|
||||||
json.insert(amnezia::config_key::responsePacketJunkSize, wgConfig.value(amnezia::config_key::responsePacketJunkSize));
|
json.insert(amnezia::config_key::responsePacketJunkSize, wgConfig.value(amnezia::config_key::responsePacketJunkSize));
|
||||||
|
json.insert(amnezia::config_key::cookieReplyPacketJunkSize, wgConfig.value(amnezia::config_key::cookieReplyPacketJunkSize));
|
||||||
|
json.insert(amnezia::config_key::transportPacketJunkSize, wgConfig.value(amnezia::config_key::transportPacketJunkSize));
|
||||||
json.insert(amnezia::config_key::initPacketMagicHeader, wgConfig.value(amnezia::config_key::initPacketMagicHeader));
|
json.insert(amnezia::config_key::initPacketMagicHeader, wgConfig.value(amnezia::config_key::initPacketMagicHeader));
|
||||||
json.insert(amnezia::config_key::responsePacketMagicHeader, wgConfig.value(amnezia::config_key::responsePacketMagicHeader));
|
json.insert(amnezia::config_key::responsePacketMagicHeader, wgConfig.value(amnezia::config_key::responsePacketMagicHeader));
|
||||||
json.insert(amnezia::config_key::underloadPacketMagicHeader, wgConfig.value(amnezia::config_key::underloadPacketMagicHeader));
|
json.insert(amnezia::config_key::underloadPacketMagicHeader, wgConfig.value(amnezia::config_key::underloadPacketMagicHeader));
|
||||||
json.insert(amnezia::config_key::transportPacketMagicHeader, wgConfig.value(amnezia::config_key::transportPacketMagicHeader));
|
json.insert(amnezia::config_key::transportPacketMagicHeader, wgConfig.value(amnezia::config_key::transportPacketMagicHeader));
|
||||||
|
json.insert(amnezia::config_key::specialJunk1, wgConfig.value(amnezia::config_key::specialJunk1));
|
||||||
|
json.insert(amnezia::config_key::specialJunk2, wgConfig.value(amnezia::config_key::specialJunk2));
|
||||||
|
json.insert(amnezia::config_key::specialJunk3, wgConfig.value(amnezia::config_key::specialJunk3));
|
||||||
|
json.insert(amnezia::config_key::specialJunk4, wgConfig.value(amnezia::config_key::specialJunk4));
|
||||||
|
json.insert(amnezia::config_key::specialJunk5, wgConfig.value(amnezia::config_key::specialJunk5));
|
||||||
|
json.insert(amnezia::config_key::controlledJunk1, wgConfig.value(amnezia::config_key::controlledJunk1));
|
||||||
|
json.insert(amnezia::config_key::controlledJunk2, wgConfig.value(amnezia::config_key::controlledJunk2));
|
||||||
|
json.insert(amnezia::config_key::controlledJunk3, wgConfig.value(amnezia::config_key::controlledJunk3));
|
||||||
|
json.insert(amnezia::config_key::specialHandshakeTimeout, wgConfig.value(amnezia::config_key::specialHandshakeTimeout));
|
||||||
}
|
}
|
||||||
|
|
||||||
write(json);
|
write(json);
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,10 @@ struct WGConfig: Decodable {
|
||||||
let initPacketMagicHeader, responsePacketMagicHeader: String?
|
let initPacketMagicHeader, responsePacketMagicHeader: String?
|
||||||
let underloadPacketMagicHeader, transportPacketMagicHeader: String?
|
let underloadPacketMagicHeader, transportPacketMagicHeader: String?
|
||||||
let junkPacketCount, junkPacketMinSize, junkPacketMaxSize: String?
|
let junkPacketCount, junkPacketMinSize, junkPacketMaxSize: String?
|
||||||
let initPacketJunkSize, responsePacketJunkSize: String?
|
let initPacketJunkSize, responsePacketJunkSize, cookieReplyPacketJunkSize, transportPacketJunkSize: String?
|
||||||
|
let specialJunk1, specialJunk2, specialJunk3, specialJunk4, specialJunk5: String?
|
||||||
|
let controlledJunk1, controlledJunk2, controlledJunk3: String?
|
||||||
|
let specialHandshakeTimeout: String?
|
||||||
let dns1: String
|
let dns1: String
|
||||||
let dns2: String
|
let dns2: String
|
||||||
let mtu: String
|
let mtu: String
|
||||||
|
|
@ -23,7 +26,10 @@ struct WGConfig: Decodable {
|
||||||
case initPacketMagicHeader = "H1", responsePacketMagicHeader = "H2"
|
case initPacketMagicHeader = "H1", responsePacketMagicHeader = "H2"
|
||||||
case underloadPacketMagicHeader = "H3", transportPacketMagicHeader = "H4"
|
case underloadPacketMagicHeader = "H3", transportPacketMagicHeader = "H4"
|
||||||
case junkPacketCount = "Jc", junkPacketMinSize = "Jmin", junkPacketMaxSize = "Jmax"
|
case junkPacketCount = "Jc", junkPacketMinSize = "Jmin", junkPacketMaxSize = "Jmax"
|
||||||
case initPacketJunkSize = "S1", responsePacketJunkSize = "S2"
|
case initPacketJunkSize = "S1", responsePacketJunkSize = "S2", cookieReplyPacketJunkSize = "S3", transportPacketJunkSize = "S4"
|
||||||
|
case specialJunk1 = "I1", specialJunk2 = "I2", specialJunk3 = "I3", specialJunk4 = "I4", specialJunk5 = "I5"
|
||||||
|
case controlledJunk1 = "J1", controlledJunk2 = "J2", controlledJunk3 = "J3"
|
||||||
|
case specialHandshakeTimeout = "Itime"
|
||||||
case dns1
|
case dns1
|
||||||
case dns2
|
case dns2
|
||||||
case mtu
|
case mtu
|
||||||
|
|
@ -40,19 +46,59 @@ struct WGConfig: Decodable {
|
||||||
}
|
}
|
||||||
|
|
||||||
var settings: String {
|
var settings: String {
|
||||||
junkPacketCount == nil ? "" :
|
guard junkPacketCount != nil else { return "" }
|
||||||
"""
|
|
||||||
Jc = \(junkPacketCount!)
|
|
||||||
Jmin = \(junkPacketMinSize!)
|
|
||||||
Jmax = \(junkPacketMaxSize!)
|
|
||||||
S1 = \(initPacketJunkSize!)
|
|
||||||
S2 = \(responsePacketJunkSize!)
|
|
||||||
H1 = \(initPacketMagicHeader!)
|
|
||||||
H2 = \(responsePacketMagicHeader!)
|
|
||||||
H3 = \(underloadPacketMagicHeader!)
|
|
||||||
H4 = \(transportPacketMagicHeader!)
|
|
||||||
|
|
||||||
"""
|
var settingsLines: [String] = []
|
||||||
|
|
||||||
|
// Required parameters when junkPacketCount is present
|
||||||
|
settingsLines.append("Jc = \(junkPacketCount!)")
|
||||||
|
settingsLines.append("Jmin = \(junkPacketMinSize!)")
|
||||||
|
settingsLines.append("Jmax = \(junkPacketMaxSize!)")
|
||||||
|
settingsLines.append("S1 = \(initPacketJunkSize!)")
|
||||||
|
settingsLines.append("S2 = \(responsePacketJunkSize!)")
|
||||||
|
|
||||||
|
settingsLines.append("H1 = \(initPacketMagicHeader!)")
|
||||||
|
settingsLines.append("H2 = \(responsePacketMagicHeader!)")
|
||||||
|
settingsLines.append("H3 = \(underloadPacketMagicHeader!)")
|
||||||
|
settingsLines.append("H4 = \(transportPacketMagicHeader!)")
|
||||||
|
|
||||||
|
// Optional parameters - only add if not nil and not empty
|
||||||
|
if let s3 = cookieReplyPacketJunkSize, !s3.isEmpty {
|
||||||
|
settingsLines.append("S3 = \(s3)")
|
||||||
|
}
|
||||||
|
if let s4 = transportPacketJunkSize, !s4.isEmpty {
|
||||||
|
settingsLines.append("S4 = \(s4)")
|
||||||
|
}
|
||||||
|
|
||||||
|
if let i1 = specialJunk1, !i1.isEmpty {
|
||||||
|
settingsLines.append("I1 = \(i1)")
|
||||||
|
}
|
||||||
|
if let i2 = specialJunk2, !i2.isEmpty {
|
||||||
|
settingsLines.append("I2 = \(i2)")
|
||||||
|
}
|
||||||
|
if let i3 = specialJunk3, !i3.isEmpty {
|
||||||
|
settingsLines.append("I3 = \(i3)")
|
||||||
|
}
|
||||||
|
if let i4 = specialJunk4, !i4.isEmpty {
|
||||||
|
settingsLines.append("I4 = \(i4)")
|
||||||
|
}
|
||||||
|
if let i5 = specialJunk5, !i5.isEmpty {
|
||||||
|
settingsLines.append("I5 = \(i5)")
|
||||||
|
}
|
||||||
|
if let j1 = controlledJunk1, !j1.isEmpty {
|
||||||
|
settingsLines.append("J1 = \(j1)")
|
||||||
|
}
|
||||||
|
if let j2 = controlledJunk2, !j2.isEmpty {
|
||||||
|
settingsLines.append("J2 = \(j2)")
|
||||||
|
}
|
||||||
|
if let j3 = controlledJunk3, !j3.isEmpty {
|
||||||
|
settingsLines.append("J3 = \(j3)")
|
||||||
|
}
|
||||||
|
if let itime = specialHandshakeTimeout, !itime.isEmpty {
|
||||||
|
settingsLines.append("Itime = \(itime)")
|
||||||
|
}
|
||||||
|
|
||||||
|
return settingsLines.joined(separator: "\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
var str: String {
|
var str: String {
|
||||||
|
|
|
||||||
|
|
@ -507,6 +507,8 @@ bool IosController::setupWireGuard()
|
||||||
|
|
||||||
wgConfig.insert(config_key::initPacketJunkSize, config[config_key::initPacketJunkSize]);
|
wgConfig.insert(config_key::initPacketJunkSize, config[config_key::initPacketJunkSize]);
|
||||||
wgConfig.insert(config_key::responsePacketJunkSize, config[config_key::responsePacketJunkSize]);
|
wgConfig.insert(config_key::responsePacketJunkSize, config[config_key::responsePacketJunkSize]);
|
||||||
|
wgConfig.insert(config_key::cookieReplyPacketJunkSize, config[config_key::cookieReplyPacketJunkSize]);
|
||||||
|
wgConfig.insert(config_key::transportPacketJunkSize, config[config_key::transportPacketJunkSize]);
|
||||||
|
|
||||||
wgConfig.insert(config_key::junkPacketCount, config[config_key::junkPacketCount]);
|
wgConfig.insert(config_key::junkPacketCount, config[config_key::junkPacketCount]);
|
||||||
wgConfig.insert(config_key::junkPacketMinSize, config[config_key::junkPacketMinSize]);
|
wgConfig.insert(config_key::junkPacketMinSize, config[config_key::junkPacketMinSize]);
|
||||||
|
|
@ -605,11 +607,23 @@ bool IosController::setupAwg()
|
||||||
|
|
||||||
wgConfig.insert(config_key::initPacketJunkSize, config[config_key::initPacketJunkSize]);
|
wgConfig.insert(config_key::initPacketJunkSize, config[config_key::initPacketJunkSize]);
|
||||||
wgConfig.insert(config_key::responsePacketJunkSize, config[config_key::responsePacketJunkSize]);
|
wgConfig.insert(config_key::responsePacketJunkSize, config[config_key::responsePacketJunkSize]);
|
||||||
|
wgConfig.insert(config_key::cookieReplyPacketJunkSize, config[config_key::cookieReplyPacketJunkSize]);
|
||||||
|
wgConfig.insert(config_key::transportPacketJunkSize, config[config_key::transportPacketJunkSize]);
|
||||||
|
|
||||||
wgConfig.insert(config_key::junkPacketCount, config[config_key::junkPacketCount]);
|
wgConfig.insert(config_key::junkPacketCount, config[config_key::junkPacketCount]);
|
||||||
wgConfig.insert(config_key::junkPacketMinSize, config[config_key::junkPacketMinSize]);
|
wgConfig.insert(config_key::junkPacketMinSize, config[config_key::junkPacketMinSize]);
|
||||||
wgConfig.insert(config_key::junkPacketMaxSize, config[config_key::junkPacketMaxSize]);
|
wgConfig.insert(config_key::junkPacketMaxSize, config[config_key::junkPacketMaxSize]);
|
||||||
|
|
||||||
|
wgConfig.insert(config_key::specialJunk1, config[config_key::specialJunk1]);
|
||||||
|
wgConfig.insert(config_key::specialJunk2, config[config_key::specialJunk2]);
|
||||||
|
wgConfig.insert(config_key::specialJunk3, config[config_key::specialJunk3]);
|
||||||
|
wgConfig.insert(config_key::specialJunk4, config[config_key::specialJunk4]);
|
||||||
|
wgConfig.insert(config_key::specialJunk5, config[config_key::specialJunk5]);
|
||||||
|
wgConfig.insert(config_key::controlledJunk1, config[config_key::controlledJunk1]);
|
||||||
|
wgConfig.insert(config_key::controlledJunk2, config[config_key::controlledJunk2]);
|
||||||
|
wgConfig.insert(config_key::controlledJunk3, config[config_key::controlledJunk3]);
|
||||||
|
wgConfig.insert(config_key::specialHandshakeTimeout, config[config_key::specialHandshakeTimeout]);
|
||||||
|
|
||||||
QJsonDocument wgConfigDoc(wgConfig);
|
QJsonDocument wgConfigDoc(wgConfig);
|
||||||
QString wgConfigDocStr(wgConfigDoc.toJson(QJsonDocument::Compact));
|
QString wgConfigDocStr(wgConfigDoc.toJson(QJsonDocument::Compact));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -121,6 +121,12 @@ bool WireguardUtilsLinux::addInterface(const InterfaceConfig& config) {
|
||||||
if (!config.m_responsePacketJunkSize.isEmpty()) {
|
if (!config.m_responsePacketJunkSize.isEmpty()) {
|
||||||
out << "s2=" << config.m_responsePacketJunkSize << "\n";
|
out << "s2=" << config.m_responsePacketJunkSize << "\n";
|
||||||
}
|
}
|
||||||
|
if (!config.m_cookieReplyPacketJunkSize.isEmpty()) {
|
||||||
|
out << "s3=" << config.m_cookieReplyPacketJunkSize << "\n";
|
||||||
|
}
|
||||||
|
if (!config.m_transportPacketJunkSize.isEmpty()) {
|
||||||
|
out << "s4=" << config.m_transportPacketJunkSize << "\n";
|
||||||
|
}
|
||||||
if (!config.m_initPacketMagicHeader.isEmpty()) {
|
if (!config.m_initPacketMagicHeader.isEmpty()) {
|
||||||
out << "h1=" << config.m_initPacketMagicHeader << "\n";
|
out << "h1=" << config.m_initPacketMagicHeader << "\n";
|
||||||
}
|
}
|
||||||
|
|
@ -134,13 +140,26 @@ bool WireguardUtilsLinux::addInterface(const InterfaceConfig& config) {
|
||||||
out << "h4=" << config.m_transportPacketMagicHeader << "\n";
|
out << "h4=" << config.m_transportPacketMagicHeader << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const QString& key : config.m_specialJunk.keys()) {
|
||||||
|
out << key.toLower() << "=" << config.m_specialJunk.value(key) << "\n";
|
||||||
|
}
|
||||||
|
for (const QString& key : config.m_controlledJunk.keys()) {
|
||||||
|
out << key.toLower() << "=" << config.m_controlledJunk.value(key) << "\n";
|
||||||
|
}
|
||||||
|
if (!config.m_specialHandshakeTimeout.isEmpty()) {
|
||||||
|
out << "itime=" << config.m_specialHandshakeTimeout << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
int err = uapiErrno(uapiCommand(message));
|
int err = uapiErrno(uapiCommand(message));
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
logger.error() << "Interface configuration failed:" << strerror(err);
|
logger.error() << "Interface configuration failed:" << strerror(err);
|
||||||
} else {
|
} else {
|
||||||
if (config.m_killSwitchEnabled) {
|
if (config.m_killSwitchEnabled) {
|
||||||
FirewallParams params { };
|
FirewallParams params { };
|
||||||
params.dnsServers.append(config.m_dnsServer);
|
params.dnsServers.append(config.m_primaryDnsServer);
|
||||||
|
if (!config.m_secondaryDnsServer.isEmpty()) {
|
||||||
|
params.dnsServers.append(config.m_secondaryDnsServer);
|
||||||
|
}
|
||||||
if (config.m_allowedIPAddressRanges.contains(IPAddress("0.0.0.0/0"))) {
|
if (config.m_allowedIPAddressRanges.contains(IPAddress("0.0.0.0/0"))) {
|
||||||
params.blockAll = true;
|
params.blockAll = true;
|
||||||
if (config.m_excludedAddresses.size()) {
|
if (config.m_excludedAddresses.size()) {
|
||||||
|
|
|
||||||
|
|
@ -43,8 +43,16 @@ namespace {
|
||||||
|
|
||||||
#include "macosfirewall.h"
|
#include "macosfirewall.h"
|
||||||
|
|
||||||
#define ResourceDir qApp->applicationDirPath() + "/pf"
|
#include <QDir>
|
||||||
#define DaemonDataDir qApp->applicationDirPath() + "/pf"
|
#include <QStandardPaths>
|
||||||
|
|
||||||
|
// Read-only rules bundled with the application.
|
||||||
|
#define ResourceDir (qApp->applicationDirPath() + "/pf")
|
||||||
|
|
||||||
|
// Writable location that does NOT live inside the signed bundle. Using a
|
||||||
|
// constant path under /Library/Application Support keeps the signature intact
|
||||||
|
// and is accessible to the root helper.
|
||||||
|
#define DaemonDataDir QStringLiteral("/Library/Application Support/AmneziaVPN/pf")
|
||||||
|
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
|
|
||||||
|
|
@ -121,6 +129,8 @@ void MacOSFirewall::install()
|
||||||
logger.info() << "Installing PF root anchor";
|
logger.info() << "Installing PF root anchor";
|
||||||
|
|
||||||
installRootAnchors();
|
installRootAnchors();
|
||||||
|
// Ensure writable directory exists, then store the token there.
|
||||||
|
QDir().mkpath(DaemonDataDir);
|
||||||
execute(QStringLiteral("pfctl -E 2>&1 | grep -F 'Token : ' | cut -c9- > '%1/pf.token'").arg(DaemonDataDir));
|
execute(QStringLiteral("pfctl -E 2>&1 | grep -F 'Token : ' | cut -c9- > '%1/pf.token'").arg(DaemonDataDir));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -119,6 +119,12 @@ bool WireguardUtilsMacos::addInterface(const InterfaceConfig& config) {
|
||||||
if (!config.m_responsePacketJunkSize.isEmpty()) {
|
if (!config.m_responsePacketJunkSize.isEmpty()) {
|
||||||
out << "s2=" << config.m_responsePacketJunkSize << "\n";
|
out << "s2=" << config.m_responsePacketJunkSize << "\n";
|
||||||
}
|
}
|
||||||
|
if (!config.m_cookieReplyPacketJunkSize.isEmpty()) {
|
||||||
|
out << "s3=" << config.m_cookieReplyPacketJunkSize << "\n";
|
||||||
|
}
|
||||||
|
if (!config.m_transportPacketJunkSize.isEmpty()) {
|
||||||
|
out << "s4=" << config.m_transportPacketJunkSize << "\n";
|
||||||
|
}
|
||||||
if (!config.m_initPacketMagicHeader.isEmpty()) {
|
if (!config.m_initPacketMagicHeader.isEmpty()) {
|
||||||
out << "h1=" << config.m_initPacketMagicHeader << "\n";
|
out << "h1=" << config.m_initPacketMagicHeader << "\n";
|
||||||
}
|
}
|
||||||
|
|
@ -132,30 +138,43 @@ bool WireguardUtilsMacos::addInterface(const InterfaceConfig& config) {
|
||||||
out << "h4=" << config.m_transportPacketMagicHeader << "\n";
|
out << "h4=" << config.m_transportPacketMagicHeader << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const QString& key : config.m_specialJunk.keys()) {
|
||||||
|
out << key.toLower() << "=" << config.m_specialJunk.value(key) << "\n";
|
||||||
|
}
|
||||||
|
for (const QString& key : config.m_controlledJunk.keys()) {
|
||||||
|
out << key.toLower() << "=" << config.m_controlledJunk.value(key) << "\n";
|
||||||
|
}
|
||||||
|
if (!config.m_specialHandshakeTimeout.isEmpty()) {
|
||||||
|
out << "itime=" << config.m_specialHandshakeTimeout << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
int err = uapiErrno(uapiCommand(message));
|
int err = uapiErrno(uapiCommand(message));
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
logger.error() << "Interface configuration failed:" << strerror(err);
|
logger.error() << "Interface configuration failed:" << strerror(err);
|
||||||
} else {
|
} else {
|
||||||
if (config.m_killSwitchEnabled) {
|
if (config.m_killSwitchEnabled) {
|
||||||
FirewallParams params { };
|
FirewallParams params { };
|
||||||
params.dnsServers.append(config.m_dnsServer);
|
params.dnsServers.append(config.m_primaryDnsServer);
|
||||||
|
if (!config.m_secondaryDnsServer.isEmpty()) {
|
||||||
|
params.dnsServers.append(config.m_secondaryDnsServer);
|
||||||
|
}
|
||||||
|
|
||||||
if (config.m_allowedIPAddressRanges.contains(IPAddress("0.0.0.0/0"))) {
|
if (config.m_allowedIPAddressRanges.contains(IPAddress("0.0.0.0/0"))) {
|
||||||
params.blockAll = true;
|
params.blockAll = true;
|
||||||
if (config.m_excludedAddresses.size()) {
|
if (config.m_excludedAddresses.size()) {
|
||||||
params.allowNets = true;
|
params.allowNets = true;
|
||||||
foreach (auto net, config.m_excludedAddresses) {
|
foreach (auto net, config.m_excludedAddresses) {
|
||||||
params.allowAddrs.append(net.toUtf8());
|
params.allowAddrs.append(net.toUtf8());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
params.blockNets = true;
|
params.blockNets = true;
|
||||||
foreach (auto net, config.m_allowedIPAddressRanges) {
|
foreach (auto net, config.m_allowedIPAddressRanges) {
|
||||||
params.blockAddrs.append(net.toString());
|
params.blockAddrs.append(net.toString());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
applyFirewallRules(params);
|
|
||||||
}
|
}
|
||||||
|
applyFirewallRules(params);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return (err == 0);
|
return (err == 0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -291,15 +291,32 @@ bool WindowsFirewall::enablePeerTraffic(const InterfaceConfig& config) {
|
||||||
"Block Internet", config.m_serverPublicKey)) {
|
"Block Internet", config.m_serverPublicKey)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!config.m_dnsServer.isEmpty()) {
|
if (!config.m_primaryDnsServer.isEmpty()) {
|
||||||
if (!allowTrafficTo(QHostAddress(config.m_dnsServer), 53, HIGH_WEIGHT,
|
if (!allowTrafficTo(QHostAddress(config.m_primaryDnsServer), 53, HIGH_WEIGHT,
|
||||||
"Allow DNS-Server", config.m_serverPublicKey)) {
|
"Allow DNS-Server", config.m_serverPublicKey)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// In some cases, we might configure a 2nd DNS server for IPv6, however
|
// In some cases, we might configure a 2nd DNS server for IPv6, however
|
||||||
// this should probably be cleaned up by converting m_dnsServer into
|
// this should probably be cleaned up by converting m_dnsServer into
|
||||||
// a QStringList instead.
|
// a QStringList instead.
|
||||||
if (config.m_dnsServer == config.m_serverIpv4Gateway) {
|
if (config.m_primaryDnsServer == config.m_serverIpv4Gateway) {
|
||||||
|
if (!allowTrafficTo(QHostAddress(config.m_serverIpv6Gateway), 53,
|
||||||
|
HIGH_WEIGHT, "Allow extra IPv6 DNS-Server",
|
||||||
|
config.m_serverPublicKey)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!config.m_secondaryDnsServer.isEmpty()) {
|
||||||
|
if (!allowTrafficTo(QHostAddress(config.m_secondaryDnsServer), 53, HIGH_WEIGHT,
|
||||||
|
"Allow DNS-Server", config.m_serverPublicKey)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// In some cases, we might configure a 2nd DNS server for IPv6, however
|
||||||
|
// this should probably be cleaned up by converting m_dnsServer into
|
||||||
|
// a QStringList instead.
|
||||||
|
if (config.m_secondaryDnsServer == config.m_serverIpv4Gateway) {
|
||||||
if (!allowTrafficTo(QHostAddress(config.m_serverIpv6Gateway), 53,
|
if (!allowTrafficTo(QHostAddress(config.m_serverIpv6Gateway), 53,
|
||||||
HIGH_WEIGHT, "Allow extra IPv6 DNS-Server",
|
HIGH_WEIGHT, "Allow extra IPv6 DNS-Server",
|
||||||
config.m_serverPublicKey)) {
|
config.m_serverPublicKey)) {
|
||||||
|
|
|
||||||
|
|
@ -130,6 +130,7 @@ bool WireguardUtilsWindows::addInterface(const InterfaceConfig& config) {
|
||||||
// Enable the windows firewall
|
// Enable the windows firewall
|
||||||
NET_IFINDEX ifindex;
|
NET_IFINDEX ifindex;
|
||||||
ConvertInterfaceLuidToIndex(&luid, &ifindex);
|
ConvertInterfaceLuidToIndex(&luid, &ifindex);
|
||||||
|
m_firewall->allowAllTraffic();
|
||||||
m_firewall->enableInterface(ifindex);
|
m_firewall->enableInterface(ifindex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -343,7 +343,7 @@ void OpenVpnProtocol::updateVpnGateway(const QString &line)
|
||||||
// killSwitch toggle
|
// killSwitch toggle
|
||||||
if (m_vpnLocalAddress == netInterfaces.at(i).addressEntries().at(j).ip().toString()) {
|
if (m_vpnLocalAddress == netInterfaces.at(i).addressEntries().at(j).ip().toString()) {
|
||||||
if (QVariant(m_configData.value(config_key::killSwitchOption).toString()).toBool()) {
|
if (QVariant(m_configData.value(config_key::killSwitchOption).toString()).toBool()) {
|
||||||
IpcClient::Interface()->enableKillSwitch(QJsonObject(), netInterfaces.at(i).index());
|
IpcClient::Interface()->enableKillSwitch(m_configData, netInterfaces.at(i).index());
|
||||||
}
|
}
|
||||||
m_configData.insert("vpnAdapterIndex", netInterfaces.at(i).index());
|
m_configData.insert("vpnAdapterIndex", netInterfaces.at(i).index());
|
||||||
m_configData.insert("vpnGateway", m_vpnGateway);
|
m_configData.insert("vpnGateway", m_vpnGateway);
|
||||||
|
|
|
||||||
|
|
@ -72,10 +72,21 @@ namespace amnezia
|
||||||
constexpr char junkPacketMaxSize[] = "Jmax";
|
constexpr char junkPacketMaxSize[] = "Jmax";
|
||||||
constexpr char initPacketJunkSize[] = "S1";
|
constexpr char initPacketJunkSize[] = "S1";
|
||||||
constexpr char responsePacketJunkSize[] = "S2";
|
constexpr char responsePacketJunkSize[] = "S2";
|
||||||
|
constexpr char cookieReplyPacketJunkSize[] = "S3";
|
||||||
|
constexpr char transportPacketJunkSize[] = "S4";
|
||||||
constexpr char initPacketMagicHeader[] = "H1";
|
constexpr char initPacketMagicHeader[] = "H1";
|
||||||
constexpr char responsePacketMagicHeader[] = "H2";
|
constexpr char responsePacketMagicHeader[] = "H2";
|
||||||
constexpr char underloadPacketMagicHeader[] = "H3";
|
constexpr char underloadPacketMagicHeader[] = "H3";
|
||||||
constexpr char transportPacketMagicHeader[] = "H4";
|
constexpr char transportPacketMagicHeader[] = "H4";
|
||||||
|
constexpr char specialJunk1[] = "I1";
|
||||||
|
constexpr char specialJunk2[] = "I2";
|
||||||
|
constexpr char specialJunk3[] = "I3";
|
||||||
|
constexpr char specialJunk4[] = "I4";
|
||||||
|
constexpr char specialJunk5[] = "I5";
|
||||||
|
constexpr char controlledJunk1[] = "J1";
|
||||||
|
constexpr char controlledJunk2[] = "J2";
|
||||||
|
constexpr char controlledJunk3[] = "J3";
|
||||||
|
constexpr char specialHandshakeTimeout[] = "Itime";
|
||||||
|
|
||||||
constexpr char openvpn[] = "openvpn";
|
constexpr char openvpn[] = "openvpn";
|
||||||
constexpr char wireguard[] = "wireguard";
|
constexpr char wireguard[] = "wireguard";
|
||||||
|
|
@ -216,10 +227,22 @@ namespace amnezia
|
||||||
constexpr char defaultJunkPacketMaxSize[] = "30";
|
constexpr char defaultJunkPacketMaxSize[] = "30";
|
||||||
constexpr char defaultInitPacketJunkSize[] = "15";
|
constexpr char defaultInitPacketJunkSize[] = "15";
|
||||||
constexpr char defaultResponsePacketJunkSize[] = "18";
|
constexpr char defaultResponsePacketJunkSize[] = "18";
|
||||||
|
constexpr char defaultCookieReplyPacketJunkSize[] = "20";
|
||||||
|
constexpr char defaultTransportPacketJunkSize[] = "23";
|
||||||
|
|
||||||
constexpr char defaultInitPacketMagicHeader[] = "1020325451";
|
constexpr char defaultInitPacketMagicHeader[] = "1020325451";
|
||||||
constexpr char defaultResponsePacketMagicHeader[] = "3288052141";
|
constexpr char defaultResponsePacketMagicHeader[] = "3288052141";
|
||||||
constexpr char defaultTransportPacketMagicHeader[] = "2528465083";
|
constexpr char defaultTransportPacketMagicHeader[] = "2528465083";
|
||||||
constexpr char defaultUnderloadPacketMagicHeader[] = "1766607858";
|
constexpr char defaultUnderloadPacketMagicHeader[] = "1766607858";
|
||||||
|
constexpr char defaultSpecialJunk1[] = "";
|
||||||
|
constexpr char defaultSpecialJunk2[] = "";
|
||||||
|
constexpr char defaultSpecialJunk3[] = "";
|
||||||
|
constexpr char defaultSpecialJunk4[] = "";
|
||||||
|
constexpr char defaultSpecialJunk5[] = "";
|
||||||
|
constexpr char defaultControlledJunk1[] = "";
|
||||||
|
constexpr char defaultControlledJunk2[] = "";
|
||||||
|
constexpr char defaultControlledJunk3[] = "";
|
||||||
|
constexpr char defaultSpecialHandshakeTimeout[] = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace socks5Proxy
|
namespace socks5Proxy
|
||||||
|
|
|
||||||
|
|
@ -98,8 +98,13 @@ ErrorCode XrayProtocol::startTun2Sock()
|
||||||
if (vpnState == Vpn::ConnectionState::Connected) {
|
if (vpnState == Vpn::ConnectionState::Connected) {
|
||||||
setConnectionState(Vpn::ConnectionState::Connecting);
|
setConnectionState(Vpn::ConnectionState::Connecting);
|
||||||
QList<QHostAddress> dnsAddr;
|
QList<QHostAddress> dnsAddr;
|
||||||
|
|
||||||
dnsAddr.push_back(QHostAddress(m_configData.value(config_key::dns1).toString()));
|
dnsAddr.push_back(QHostAddress(m_configData.value(config_key::dns1).toString()));
|
||||||
dnsAddr.push_back(QHostAddress(m_configData.value(config_key::dns2).toString()));
|
// We don't use secondary DNS if primary DNS is AmneziaDNS
|
||||||
|
if (!m_configData.value(amnezia::config_key::dns1).toString().
|
||||||
|
contains(amnezia::protocols::dns::amneziaDnsIp)) {
|
||||||
|
dnsAddr.push_back(QHostAddress(m_configData.value(config_key::dns2).toString()));
|
||||||
|
}
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
QThread::msleep(8000);
|
QThread::msleep(8000);
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -134,7 +139,7 @@ ErrorCode XrayProtocol::startTun2Sock()
|
||||||
// killSwitch toggle
|
// killSwitch toggle
|
||||||
if (m_vpnLocalAddress == netInterfaces.at(i).addressEntries().at(j).ip().toString()) {
|
if (m_vpnLocalAddress == netInterfaces.at(i).addressEntries().at(j).ip().toString()) {
|
||||||
if (QVariant(m_configData.value(config_key::killSwitchOption).toString()).toBool()) {
|
if (QVariant(m_configData.value(config_key::killSwitchOption).toString()).toBool()) {
|
||||||
IpcClient::Interface()->enableKillSwitch(QJsonObject(), netInterfaces.at(i).index());
|
IpcClient::Interface()->enableKillSwitch(m_configData, netInterfaces.at(i).index());
|
||||||
}
|
}
|
||||||
m_configData.insert("vpnAdapterIndex", netInterfaces.at(i).index());
|
m_configData.insert("vpnAdapterIndex", netInterfaces.at(i).index());
|
||||||
m_configData.insert("vpnGateway", m_vpnGateway);
|
m_configData.insert("vpnGateway", m_vpnGateway);
|
||||||
|
|
|
||||||
|
|
@ -239,6 +239,7 @@
|
||||||
<file>ui/qml/Components/ApiPremV1MigrationDrawer.qml</file>
|
<file>ui/qml/Components/ApiPremV1MigrationDrawer.qml</file>
|
||||||
<file>ui/qml/Components/ApiPremV1SubListDrawer.qml</file>
|
<file>ui/qml/Components/ApiPremV1SubListDrawer.qml</file>
|
||||||
<file>ui/qml/Components/OtpCodeDrawer.qml</file>
|
<file>ui/qml/Components/OtpCodeDrawer.qml</file>
|
||||||
|
<file>ui/qml/Components/AwgTextField.qml</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
<qresource prefix="/countriesFlags">
|
<qresource prefix="/countriesFlags">
|
||||||
<file>images/flagKit/ZW.svg</file>
|
<file>images/flagKit/ZW.svg</file>
|
||||||
|
|
|
||||||
|
|
@ -44,3 +44,4 @@ RUN echo -e " \n\
|
||||||
|
|
||||||
ENTRYPOINT [ "dumb-init", "/opt/amnezia/start.sh" ]
|
ENTRYPOINT [ "dumb-init", "/opt/amnezia/start.sh" ]
|
||||||
CMD [ "" ]
|
CMD [ "" ]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,4 +23,5 @@ H1 = $INIT_PACKET_MAGIC_HEADER
|
||||||
H2 = $RESPONSE_PACKET_MAGIC_HEADER
|
H2 = $RESPONSE_PACKET_MAGIC_HEADER
|
||||||
H3 = $UNDERLOAD_PACKET_MAGIC_HEADER
|
H3 = $UNDERLOAD_PACKET_MAGIC_HEADER
|
||||||
H4 = $TRANSPORT_PACKET_MAGIC_HEADER
|
H4 = $TRANSPORT_PACKET_MAGIC_HEADER
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
if which apt-get > /dev/null 2>&1; then LOCK_FILE="/var/lib/dpkg/lock-frontend";\
|
if which apt-get > /dev/null 2>&1; then LOCK_CMD="fuser"; LOCK_FILE="/var/lib/dpkg/lock-frontend";\
|
||||||
elif which dnf > /dev/null 2>&1; then LOCK_FILE="/var/run/dnf.pid";\
|
elif which dnf > /dev/null 2>&1; then LOCK_CMD="fuser"; LOCK_FILE="/var/cache/dnf/* /var/run/dnf/* /var/lib/dnf/* /var/lib/rpm/*";\
|
||||||
elif which yum > /dev/null 2>&1; then LOCK_FILE="/var/run/yum.pid";\
|
elif which yum > /dev/null 2>&1; then LOCK_CMD="cat"; LOCK_FILE="/var/run/yum.pid";\
|
||||||
elif which pacman > /dev/null 2>&1; then LOCK_FILE="/var/lib/pacman/db.lck";\
|
elif which zypper > /dev/null 2>&1; then LOCK_CMD="cat"; LOCK_FILE="/var/run/zypp.pid";\
|
||||||
|
elif which pacman > /dev/null 2>&1; then LOCK_CMD="fuser"; LOCK_FILE="/var/lib/pacman/db.lck";\
|
||||||
else echo "Packet manager not found"; echo "Internal error"; exit 1; fi;\
|
else echo "Packet manager not found"; echo "Internal error"; exit 1; fi;\
|
||||||
if command -v fuser > /dev/null 2>&1; then sudo fuser $LOCK_FILE 2>/dev/null; else echo "fuser not installed"; fi
|
if command -v $LOCK_CMD > /dev/null 2>&1; then sudo $LOCK_CMD $LOCK_FILE 2>/dev/null; else echo "$LOCK_CMD not installed"; fi
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
if which apt-get > /dev/null 2>&1; then pm=$(which apt-get); opt="--version";\
|
if which apt-get > /dev/null 2>&1; then pm=$(which apt-get); opt="--version";\
|
||||||
elif which dnf > /dev/null 2>&1; then pm=$(which dnf); opt="--version";\
|
elif which dnf > /dev/null 2>&1; then pm=$(which dnf); opt="--version";\
|
||||||
elif which yum > /dev/null 2>&1; then pm=$(which yum); opt="--version";\
|
elif which yum > /dev/null 2>&1; then pm=$(which yum); opt="--version";\
|
||||||
|
elif which zypper > /dev/null 2>&1; then pm=$(which zypper); opt="--version";\
|
||||||
elif which pacman > /dev/null 2>&1; then pm=$(which pacman); opt="--version";\
|
elif which pacman > /dev/null 2>&1; then pm=$(which pacman); opt="--version";\
|
||||||
else pm="uname"; opt="-a";\
|
else pm="uname"; opt="-a";\
|
||||||
fi;\
|
fi;\
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
if which apt-get > /dev/null 2>&1; then pm=$(which apt-get); silent_inst="-yq install"; check_pkgs="-yq update"; docker_pkg="docker.io"; dist="debian";\
|
if which apt-get > /dev/null 2>&1; then pm=$(which apt-get); silent_inst="-yq install"; check_pkgs="-yq update"; docker_pkg="docker.io"; dist="debian";\
|
||||||
elif which dnf > /dev/null 2>&1; then pm=$(which dnf); silent_inst="-yq install"; check_pkgs="-yq check-update"; docker_pkg="docker"; dist="fedora";\
|
elif which dnf > /dev/null 2>&1; then pm=$(which dnf); silent_inst="-yq install"; check_pkgs="-yq check-update"; docker_pkg="docker"; dist="fedora";\
|
||||||
elif which yum > /dev/null 2>&1; then pm=$(which yum); silent_inst="-y -q install"; check_pkgs="-y -q check-update"; docker_pkg="docker"; dist="centos";\
|
elif which yum > /dev/null 2>&1; then pm=$(which yum); silent_inst="-y -q install"; check_pkgs="-y -q check-update"; docker_pkg="docker"; dist="centos";\
|
||||||
|
elif which zypper > /dev/null 2>&1; then pm=$(which zypper); silent_inst="-nq install"; check_pkgs="-nq refresh"; docker_pkg="docker"; dist="opensuse";\
|
||||||
elif which pacman > /dev/null 2>&1; then pm=$(which pacman); silent_inst="-S --noconfirm --noprogressbar --quiet"; check_pkgs="-Sup"; docker_pkg="docker"; dist="archlinux";\
|
elif which pacman > /dev/null 2>&1; then pm=$(which pacman); silent_inst="-S --noconfirm --noprogressbar --quiet"; check_pkgs="-Sup"; docker_pkg="docker"; dist="archlinux";\
|
||||||
else echo "Packet manager not found"; exit 1; fi;\
|
else echo "Packet manager not found"; exit 1; fi;\
|
||||||
echo "Dist: $dist, Packet manager: $pm, Install command: $silent_inst, Check pkgs command: $check_pkgs, Docker pkg: $docker_pkg";\
|
echo "Dist: $dist, Packet manager: $pm, Install command: $silent_inst, Check pkgs command: $check_pkgs, Docker pkg: $docker_pkg";\
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ namespace
|
||||||
{
|
{
|
||||||
constexpr char cloak[] = "cloak";
|
constexpr char cloak[] = "cloak";
|
||||||
constexpr char awg[] = "awg";
|
constexpr char awg[] = "awg";
|
||||||
|
constexpr char vless[] = "vless";
|
||||||
|
|
||||||
constexpr char apiEndpoint[] = "api_endpoint";
|
constexpr char apiEndpoint[] = "api_endpoint";
|
||||||
constexpr char accessToken[] = "api_key";
|
constexpr char accessToken[] = "api_key";
|
||||||
|
|
@ -35,10 +36,6 @@ namespace
|
||||||
constexpr char serviceInfo[] = "service_info";
|
constexpr char serviceInfo[] = "service_info";
|
||||||
constexpr char serviceProtocol[] = "service_protocol";
|
constexpr char serviceProtocol[] = "service_protocol";
|
||||||
|
|
||||||
constexpr char aesKey[] = "aes_key";
|
|
||||||
constexpr char aesIv[] = "aes_iv";
|
|
||||||
constexpr char aesSalt[] = "aes_salt";
|
|
||||||
|
|
||||||
constexpr char apiPayload[] = "api_payload";
|
constexpr char apiPayload[] = "api_payload";
|
||||||
constexpr char keyPayload[] = "key_payload";
|
constexpr char keyPayload[] = "key_payload";
|
||||||
|
|
||||||
|
|
@ -47,6 +44,185 @@ namespace
|
||||||
|
|
||||||
constexpr char config[] = "config";
|
constexpr char config[] = "config";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct ProtocolData
|
||||||
|
{
|
||||||
|
OpenVpnConfigurator::ConnectionData certRequest;
|
||||||
|
|
||||||
|
QString wireGuardClientPrivKey;
|
||||||
|
QString wireGuardClientPubKey;
|
||||||
|
|
||||||
|
QString xrayUuid;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct GatewayRequestData
|
||||||
|
{
|
||||||
|
QString osVersion;
|
||||||
|
QString appVersion;
|
||||||
|
|
||||||
|
QString installationUuid;
|
||||||
|
|
||||||
|
QString userCountryCode;
|
||||||
|
QString serverCountryCode;
|
||||||
|
QString serviceType;
|
||||||
|
QString serviceProtocol;
|
||||||
|
|
||||||
|
QJsonObject authData;
|
||||||
|
|
||||||
|
QJsonObject toJsonObject() const
|
||||||
|
{
|
||||||
|
QJsonObject obj;
|
||||||
|
if (!osVersion.isEmpty()) {
|
||||||
|
obj[configKey::osVersion] = osVersion;
|
||||||
|
}
|
||||||
|
if (!appVersion.isEmpty()) {
|
||||||
|
obj[configKey::appVersion] = appVersion;
|
||||||
|
}
|
||||||
|
if (!installationUuid.isEmpty()) {
|
||||||
|
obj[configKey::uuid] = installationUuid;
|
||||||
|
}
|
||||||
|
if (!userCountryCode.isEmpty()) {
|
||||||
|
obj[configKey::userCountryCode] = userCountryCode;
|
||||||
|
}
|
||||||
|
if (!serverCountryCode.isEmpty()) {
|
||||||
|
obj[configKey::serverCountryCode] = serverCountryCode;
|
||||||
|
}
|
||||||
|
if (!serviceType.isEmpty()) {
|
||||||
|
obj[configKey::serviceType] = serviceType;
|
||||||
|
}
|
||||||
|
if (!serviceProtocol.isEmpty()) {
|
||||||
|
obj[configKey::serviceProtocol] = serviceProtocol;
|
||||||
|
}
|
||||||
|
if (!authData.isEmpty()) {
|
||||||
|
obj[configKey::authData] = authData;
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ProtocolData generateProtocolData(const QString &protocol)
|
||||||
|
{
|
||||||
|
ProtocolData protocolData;
|
||||||
|
if (protocol == configKey::cloak) {
|
||||||
|
protocolData.certRequest = OpenVpnConfigurator::createCertRequest();
|
||||||
|
} else if (protocol == configKey::awg) {
|
||||||
|
auto connData = WireguardConfigurator::genClientKeys();
|
||||||
|
protocolData.wireGuardClientPubKey = connData.clientPubKey;
|
||||||
|
protocolData.wireGuardClientPrivKey = connData.clientPrivKey;
|
||||||
|
} else if (protocol == configKey::vless) {
|
||||||
|
protocolData.xrayUuid = QUuid::createUuid().toString(QUuid::WithoutBraces);
|
||||||
|
}
|
||||||
|
|
||||||
|
return protocolData;
|
||||||
|
}
|
||||||
|
|
||||||
|
void appendProtocolDataToApiPayload(const QString &protocol, const ProtocolData &protocolData, QJsonObject &apiPayload)
|
||||||
|
{
|
||||||
|
if (protocol == configKey::cloak) {
|
||||||
|
apiPayload[configKey::certificate] = protocolData.certRequest.request;
|
||||||
|
} else if (protocol == configKey::awg) {
|
||||||
|
apiPayload[configKey::publicKey] = protocolData.wireGuardClientPubKey;
|
||||||
|
} else if (protocol == configKey::vless) {
|
||||||
|
apiPayload[configKey::publicKey] = protocolData.xrayUuid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ErrorCode fillServerConfig(const QString &protocol, const ProtocolData &apiPayloadData, const QByteArray &apiResponseBody,
|
||||||
|
QJsonObject &serverConfig)
|
||||||
|
{
|
||||||
|
QString data = QJsonDocument::fromJson(apiResponseBody).object().value(config_key::config).toString();
|
||||||
|
|
||||||
|
data.replace("vpn://", "");
|
||||||
|
QByteArray ba = QByteArray::fromBase64(data.toUtf8(), QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals);
|
||||||
|
|
||||||
|
if (ba.isEmpty()) {
|
||||||
|
qDebug() << "empty vpn key";
|
||||||
|
return ErrorCode::ApiConfigEmptyError;
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray ba_uncompressed = qUncompress(ba);
|
||||||
|
if (!ba_uncompressed.isEmpty()) {
|
||||||
|
ba = ba_uncompressed;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString configStr = ba;
|
||||||
|
if (protocol == configKey::cloak) {
|
||||||
|
configStr.replace("<key>", "<key>\n");
|
||||||
|
configStr.replace("$OPENVPN_PRIV_KEY", apiPayloadData.certRequest.privKey);
|
||||||
|
} else if (protocol == configKey::awg) {
|
||||||
|
configStr.replace("$WIREGUARD_CLIENT_PRIVATE_KEY", apiPayloadData.wireGuardClientPrivKey);
|
||||||
|
auto newServerConfig = QJsonDocument::fromJson(configStr.toUtf8()).object();
|
||||||
|
auto containers = newServerConfig.value(config_key::containers).toArray();
|
||||||
|
if (containers.isEmpty()) {
|
||||||
|
qDebug() << "missing containers field";
|
||||||
|
return ErrorCode::ApiConfigEmptyError;
|
||||||
|
}
|
||||||
|
auto container = containers.at(0).toObject();
|
||||||
|
QString containerName = ContainerProps::containerTypeToString(DockerContainer::Awg);
|
||||||
|
auto serverProtocolConfig = container.value(containerName).toObject();
|
||||||
|
auto clientProtocolConfig =
|
||||||
|
QJsonDocument::fromJson(serverProtocolConfig.value(config_key::last_config).toString().toUtf8()).object();
|
||||||
|
|
||||||
|
//TODO looks like this block can be removed after v1 configs EOL
|
||||||
|
|
||||||
|
serverProtocolConfig[config_key::junkPacketCount] = clientProtocolConfig.value(config_key::junkPacketCount);
|
||||||
|
serverProtocolConfig[config_key::junkPacketMinSize] = clientProtocolConfig.value(config_key::junkPacketMinSize);
|
||||||
|
serverProtocolConfig[config_key::junkPacketMaxSize] = clientProtocolConfig.value(config_key::junkPacketMaxSize);
|
||||||
|
serverProtocolConfig[config_key::initPacketJunkSize] = clientProtocolConfig.value(config_key::initPacketJunkSize);
|
||||||
|
serverProtocolConfig[config_key::responsePacketJunkSize] = clientProtocolConfig.value(config_key::responsePacketJunkSize);
|
||||||
|
serverProtocolConfig[config_key::initPacketMagicHeader] = clientProtocolConfig.value(config_key::initPacketMagicHeader);
|
||||||
|
serverProtocolConfig[config_key::responsePacketMagicHeader] = clientProtocolConfig.value(config_key::responsePacketMagicHeader);
|
||||||
|
serverProtocolConfig[config_key::underloadPacketMagicHeader] = clientProtocolConfig.value(config_key::underloadPacketMagicHeader);
|
||||||
|
serverProtocolConfig[config_key::transportPacketMagicHeader] = clientProtocolConfig.value(config_key::transportPacketMagicHeader);
|
||||||
|
|
||||||
|
serverProtocolConfig[config_key::cookieReplyPacketJunkSize] = clientProtocolConfig.value(config_key::cookieReplyPacketJunkSize);
|
||||||
|
serverProtocolConfig[config_key::transportPacketJunkSize] = clientProtocolConfig.value(config_key::transportPacketJunkSize);
|
||||||
|
serverProtocolConfig[config_key::specialJunk1] = clientProtocolConfig.value(config_key::specialJunk1);
|
||||||
|
serverProtocolConfig[config_key::specialJunk2] = clientProtocolConfig.value(config_key::specialJunk2);
|
||||||
|
serverProtocolConfig[config_key::specialJunk3] = clientProtocolConfig.value(config_key::specialJunk3);
|
||||||
|
serverProtocolConfig[config_key::specialJunk4] = clientProtocolConfig.value(config_key::specialJunk4);
|
||||||
|
serverProtocolConfig[config_key::specialJunk5] = clientProtocolConfig.value(config_key::specialJunk5);
|
||||||
|
serverProtocolConfig[config_key::controlledJunk1] = clientProtocolConfig.value(config_key::controlledJunk1);
|
||||||
|
serverProtocolConfig[config_key::controlledJunk2] = clientProtocolConfig.value(config_key::controlledJunk2);
|
||||||
|
serverProtocolConfig[config_key::controlledJunk3] = clientProtocolConfig.value(config_key::controlledJunk3);
|
||||||
|
serverProtocolConfig[config_key::specialHandshakeTimeout] = clientProtocolConfig.value(config_key::specialHandshakeTimeout);
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
container[containerName] = serverProtocolConfig;
|
||||||
|
containers.replace(0, container);
|
||||||
|
newServerConfig[config_key::containers] = containers;
|
||||||
|
configStr = QString(QJsonDocument(newServerConfig).toJson());
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonObject newServerConfig = QJsonDocument::fromJson(configStr.toUtf8()).object();
|
||||||
|
serverConfig[config_key::dns1] = newServerConfig.value(config_key::dns1);
|
||||||
|
serverConfig[config_key::dns2] = newServerConfig.value(config_key::dns2);
|
||||||
|
serverConfig[config_key::containers] = newServerConfig.value(config_key::containers);
|
||||||
|
serverConfig[config_key::hostName] = newServerConfig.value(config_key::hostName);
|
||||||
|
|
||||||
|
if (newServerConfig.value(config_key::configVersion).toInt() == apiDefs::ConfigSource::AmneziaGateway) {
|
||||||
|
serverConfig[config_key::configVersion] = newServerConfig.value(config_key::configVersion);
|
||||||
|
serverConfig[config_key::description] = newServerConfig.value(config_key::description);
|
||||||
|
serverConfig[config_key::name] = newServerConfig.value(config_key::name);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto defaultContainer = newServerConfig.value(config_key::defaultContainer).toString();
|
||||||
|
serverConfig[config_key::defaultContainer] = defaultContainer;
|
||||||
|
|
||||||
|
QVariantMap map = serverConfig.value(configKey::apiConfig).toObject().toVariantMap();
|
||||||
|
map.insert(newServerConfig.value(configKey::apiConfig).toObject().toVariantMap());
|
||||||
|
auto apiConfig = QJsonObject::fromVariantMap(map);
|
||||||
|
|
||||||
|
if (newServerConfig.value(config_key::configVersion).toInt() == apiDefs::ConfigSource::AmneziaGateway) {
|
||||||
|
apiConfig.insert(apiDefs::key::supportedProtocols,
|
||||||
|
QJsonDocument::fromJson(apiResponseBody).object().value(apiDefs::key::supportedProtocols).toArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
serverConfig[configKey::apiConfig] = apiConfig;
|
||||||
|
|
||||||
|
return ErrorCode::NoError;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ApiConfigsController::ApiConfigsController(const QSharedPointer<ServersModel> &serversModel,
|
ApiConfigsController::ApiConfigsController(const QSharedPointer<ServersModel> &serversModel,
|
||||||
|
|
@ -63,24 +239,26 @@ bool ApiConfigsController::exportNativeConfig(const QString &serverCountryCode,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
GatewayController gatewayController(m_settings->getGatewayEndpoint(), m_settings->isDevGatewayEnv(), apiDefs::requestTimeoutMsecs,
|
|
||||||
m_settings->isStrictKillSwitchEnabled());
|
|
||||||
|
|
||||||
auto serverConfigObject = m_serversModel->getServerConfig(m_serversModel->getProcessedServerIndex());
|
auto serverConfigObject = m_serversModel->getServerConfig(m_serversModel->getProcessedServerIndex());
|
||||||
auto apiConfigObject = serverConfigObject.value(configKey::apiConfig).toObject();
|
auto apiConfigObject = serverConfigObject.value(configKey::apiConfig).toObject();
|
||||||
|
|
||||||
QString protocol = apiConfigObject.value(configKey::serviceProtocol).toString();
|
GatewayRequestData gatewayRequestData { QSysInfo::productType(),
|
||||||
ApiPayloadData apiPayloadData = generateApiPayloadData(protocol);
|
QString(APP_VERSION),
|
||||||
|
m_settings->getInstallationUuid(true),
|
||||||
|
apiConfigObject.value(configKey::userCountryCode).toString(),
|
||||||
|
serverCountryCode,
|
||||||
|
apiConfigObject.value(configKey::serviceType).toString(),
|
||||||
|
m_apiServicesModel->getSelectedServiceProtocol(),
|
||||||
|
serverConfigObject.value(configKey::authData).toObject() };
|
||||||
|
|
||||||
QJsonObject apiPayload = fillApiPayload(protocol, apiPayloadData);
|
QString protocol = apiConfigObject.value(configKey::serviceProtocol).toString();
|
||||||
apiPayload[configKey::userCountryCode] = apiConfigObject.value(configKey::userCountryCode);
|
ProtocolData protocolData = generateProtocolData(protocol);
|
||||||
apiPayload[configKey::serverCountryCode] = serverCountryCode;
|
|
||||||
apiPayload[configKey::serviceType] = apiConfigObject.value(configKey::serviceType);
|
QJsonObject apiPayload = gatewayRequestData.toJsonObject();
|
||||||
apiPayload[configKey::authData] = serverConfigObject.value(configKey::authData);
|
appendProtocolDataToApiPayload(gatewayRequestData.serviceProtocol, protocolData, apiPayload);
|
||||||
apiPayload[apiDefs::key::cliVersion] = QString(APP_VERSION);
|
|
||||||
|
|
||||||
QByteArray responseBody;
|
QByteArray responseBody;
|
||||||
ErrorCode errorCode = gatewayController.post(QString("%1v1/native_config"), apiPayload, responseBody);
|
ErrorCode errorCode = executeRequest(QString("%1v1/native_config"), apiPayload, responseBody);
|
||||||
if (errorCode != ErrorCode::NoError) {
|
if (errorCode != ErrorCode::NoError) {
|
||||||
emit errorOccurred(errorCode);
|
emit errorOccurred(errorCode);
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -88,7 +266,7 @@ bool ApiConfigsController::exportNativeConfig(const QString &serverCountryCode,
|
||||||
|
|
||||||
QJsonObject jsonConfig = QJsonDocument::fromJson(responseBody).object();
|
QJsonObject jsonConfig = QJsonDocument::fromJson(responseBody).object();
|
||||||
QString nativeConfig = jsonConfig.value(configKey::config).toString();
|
QString nativeConfig = jsonConfig.value(configKey::config).toString();
|
||||||
nativeConfig.replace("$WIREGUARD_CLIENT_PRIVATE_KEY", apiPayloadData.wireGuardClientPrivKey);
|
nativeConfig.replace("$WIREGUARD_CLIENT_PRIVATE_KEY", protocolData.wireGuardClientPrivKey);
|
||||||
|
|
||||||
SystemController::saveFile(fileName, nativeConfig);
|
SystemController::saveFile(fileName, nativeConfig);
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -96,24 +274,22 @@ bool ApiConfigsController::exportNativeConfig(const QString &serverCountryCode,
|
||||||
|
|
||||||
bool ApiConfigsController::revokeNativeConfig(const QString &serverCountryCode)
|
bool ApiConfigsController::revokeNativeConfig(const QString &serverCountryCode)
|
||||||
{
|
{
|
||||||
GatewayController gatewayController(m_settings->getGatewayEndpoint(), m_settings->isDevGatewayEnv(), apiDefs::requestTimeoutMsecs,
|
|
||||||
m_settings->isStrictKillSwitchEnabled());
|
|
||||||
|
|
||||||
auto serverConfigObject = m_serversModel->getServerConfig(m_serversModel->getProcessedServerIndex());
|
auto serverConfigObject = m_serversModel->getServerConfig(m_serversModel->getProcessedServerIndex());
|
||||||
auto apiConfigObject = serverConfigObject.value(configKey::apiConfig).toObject();
|
auto apiConfigObject = serverConfigObject.value(configKey::apiConfig).toObject();
|
||||||
|
|
||||||
QString protocol = apiConfigObject.value(configKey::serviceProtocol).toString();
|
GatewayRequestData gatewayRequestData { QSysInfo::productType(),
|
||||||
ApiPayloadData apiPayloadData = generateApiPayloadData(protocol);
|
QString(APP_VERSION),
|
||||||
|
m_settings->getInstallationUuid(true),
|
||||||
|
apiConfigObject.value(configKey::userCountryCode).toString(),
|
||||||
|
serverCountryCode,
|
||||||
|
apiConfigObject.value(configKey::serviceType).toString(),
|
||||||
|
m_apiServicesModel->getSelectedServiceProtocol(),
|
||||||
|
serverConfigObject.value(configKey::authData).toObject() };
|
||||||
|
|
||||||
QJsonObject apiPayload = fillApiPayload(protocol, apiPayloadData);
|
QJsonObject apiPayload = gatewayRequestData.toJsonObject();
|
||||||
apiPayload[configKey::userCountryCode] = apiConfigObject.value(configKey::userCountryCode);
|
|
||||||
apiPayload[configKey::serverCountryCode] = serverCountryCode;
|
|
||||||
apiPayload[configKey::serviceType] = apiConfigObject.value(configKey::serviceType);
|
|
||||||
apiPayload[configKey::authData] = serverConfigObject.value(configKey::authData);
|
|
||||||
apiPayload[apiDefs::key::cliVersion] = QString(APP_VERSION);
|
|
||||||
|
|
||||||
QByteArray responseBody;
|
QByteArray responseBody;
|
||||||
ErrorCode errorCode = gatewayController.post(QString("%1v1/revoke_native_config"), apiPayload, responseBody);
|
ErrorCode errorCode = executeRequest(QString("%1v1/revoke_native_config"), apiPayload, responseBody);
|
||||||
if (errorCode != ErrorCode::NoError && errorCode != ErrorCode::ApiNotFoundError) {
|
if (errorCode != ErrorCode::NoError && errorCode != ErrorCode::ApiNotFoundError) {
|
||||||
emit errorOccurred(errorCode);
|
emit errorOccurred(errorCode);
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -144,14 +320,11 @@ void ApiConfigsController::copyVpnKeyToClipboard()
|
||||||
|
|
||||||
bool ApiConfigsController::fillAvailableServices()
|
bool ApiConfigsController::fillAvailableServices()
|
||||||
{
|
{
|
||||||
GatewayController gatewayController(m_settings->getGatewayEndpoint(), m_settings->isDevGatewayEnv(), apiDefs::requestTimeoutMsecs,
|
|
||||||
m_settings->isStrictKillSwitchEnabled());
|
|
||||||
|
|
||||||
QJsonObject apiPayload;
|
QJsonObject apiPayload;
|
||||||
apiPayload[configKey::osVersion] = QSysInfo::productType();
|
apiPayload[configKey::osVersion] = QSysInfo::productType();
|
||||||
|
|
||||||
QByteArray responseBody;
|
QByteArray responseBody;
|
||||||
ErrorCode errorCode = gatewayController.post(QString("%1v1/services"), apiPayload, responseBody);
|
ErrorCode errorCode = executeRequest(QString("%1v1/services"), apiPayload, responseBody);
|
||||||
if (errorCode == ErrorCode::NoError) {
|
if (errorCode == ErrorCode::NoError) {
|
||||||
if (!responseBody.contains("services")) {
|
if (!responseBody.contains("services")) {
|
||||||
errorCode = ErrorCode::ApiServicesMissingError;
|
errorCode = ErrorCode::ApiServicesMissingError;
|
||||||
|
|
@ -170,34 +343,36 @@ bool ApiConfigsController::fillAvailableServices()
|
||||||
|
|
||||||
bool ApiConfigsController::importServiceFromGateway()
|
bool ApiConfigsController::importServiceFromGateway()
|
||||||
{
|
{
|
||||||
if (m_serversModel->isServerFromApiAlreadyExists(m_apiServicesModel->getCountryCode(), m_apiServicesModel->getSelectedServiceType(),
|
GatewayRequestData gatewayRequestData { QSysInfo::productType(),
|
||||||
m_apiServicesModel->getSelectedServiceProtocol())) {
|
QString(APP_VERSION),
|
||||||
|
m_settings->getInstallationUuid(true),
|
||||||
|
m_apiServicesModel->getCountryCode(),
|
||||||
|
"",
|
||||||
|
m_apiServicesModel->getSelectedServiceType(),
|
||||||
|
m_apiServicesModel->getSelectedServiceProtocol(),
|
||||||
|
QJsonObject() };
|
||||||
|
|
||||||
|
if (m_serversModel->isServerFromApiAlreadyExists(gatewayRequestData.userCountryCode, gatewayRequestData.serviceType,
|
||||||
|
gatewayRequestData.serviceProtocol)) {
|
||||||
emit errorOccurred(ErrorCode::ApiConfigAlreadyAdded);
|
emit errorOccurred(ErrorCode::ApiConfigAlreadyAdded);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
GatewayController gatewayController(m_settings->getGatewayEndpoint(), m_settings->isDevGatewayEnv(), apiDefs::requestTimeoutMsecs,
|
ProtocolData protocolData = generateProtocolData(gatewayRequestData.serviceProtocol);
|
||||||
m_settings->isStrictKillSwitchEnabled());
|
|
||||||
|
|
||||||
auto installationUuid = m_settings->getInstallationUuid(true);
|
QJsonObject apiPayload = gatewayRequestData.toJsonObject();
|
||||||
auto userCountryCode = m_apiServicesModel->getCountryCode();
|
appendProtocolDataToApiPayload(gatewayRequestData.serviceProtocol, protocolData, apiPayload);
|
||||||
auto serviceType = m_apiServicesModel->getSelectedServiceType();
|
|
||||||
auto serviceProtocol = m_apiServicesModel->getSelectedServiceProtocol();
|
|
||||||
|
|
||||||
ApiPayloadData apiPayloadData = generateApiPayloadData(serviceProtocol);
|
|
||||||
|
|
||||||
QJsonObject apiPayload = fillApiPayload(serviceProtocol, apiPayloadData);
|
|
||||||
apiPayload[configKey::userCountryCode] = userCountryCode;
|
|
||||||
apiPayload[configKey::serviceType] = serviceType;
|
|
||||||
apiPayload[configKey::uuid] = installationUuid;
|
|
||||||
apiPayload[apiDefs::key::cliVersion] = QString(APP_VERSION);
|
|
||||||
|
|
||||||
QByteArray responseBody;
|
QByteArray responseBody;
|
||||||
ErrorCode errorCode = gatewayController.post(QString("%1v1/config"), apiPayload, responseBody);
|
ErrorCode errorCode = executeRequest(QString("%1v1/config"), apiPayload, responseBody);
|
||||||
|
|
||||||
QJsonObject serverConfig;
|
QJsonObject serverConfig;
|
||||||
if (errorCode == ErrorCode::NoError) {
|
if (errorCode == ErrorCode::NoError) {
|
||||||
fillServerConfig(serviceProtocol, apiPayloadData, responseBody, serverConfig);
|
errorCode = fillServerConfig(gatewayRequestData.serviceProtocol, protocolData, responseBody, serverConfig);
|
||||||
|
if (errorCode != ErrorCode::NoError) {
|
||||||
|
emit errorOccurred(errorCode);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
QJsonObject apiConfig = serverConfig.value(configKey::apiConfig).toObject();
|
QJsonObject apiConfig = serverConfig.value(configKey::apiConfig).toObject();
|
||||||
apiConfig.insert(configKey::userCountryCode, m_apiServicesModel->getCountryCode());
|
apiConfig.insert(configKey::userCountryCode, m_apiServicesModel->getCountryCode());
|
||||||
|
|
@ -218,39 +393,33 @@ bool ApiConfigsController::importServiceFromGateway()
|
||||||
bool ApiConfigsController::updateServiceFromGateway(const int serverIndex, const QString &newCountryCode, const QString &newCountryName,
|
bool ApiConfigsController::updateServiceFromGateway(const int serverIndex, const QString &newCountryCode, const QString &newCountryName,
|
||||||
bool reloadServiceConfig)
|
bool reloadServiceConfig)
|
||||||
{
|
{
|
||||||
GatewayController gatewayController(m_settings->getGatewayEndpoint(), m_settings->isDevGatewayEnv(), apiDefs::requestTimeoutMsecs,
|
|
||||||
m_settings->isStrictKillSwitchEnabled());
|
|
||||||
|
|
||||||
auto serverConfig = m_serversModel->getServerConfig(serverIndex);
|
auto serverConfig = m_serversModel->getServerConfig(serverIndex);
|
||||||
auto apiConfig = serverConfig.value(configKey::apiConfig).toObject();
|
auto apiConfig = serverConfig.value(configKey::apiConfig).toObject();
|
||||||
auto authData = serverConfig.value(configKey::authData).toObject();
|
|
||||||
|
|
||||||
auto installationUuid = m_settings->getInstallationUuid(true);
|
GatewayRequestData gatewayRequestData { QSysInfo::productType(),
|
||||||
auto userCountryCode = apiConfig.value(configKey::userCountryCode).toString();
|
QString(APP_VERSION),
|
||||||
auto serviceType = apiConfig.value(configKey::serviceType).toString();
|
m_settings->getInstallationUuid(true),
|
||||||
auto serviceProtocol = apiConfig.value(configKey::serviceProtocol).toString();
|
apiConfig.value(configKey::userCountryCode).toString(),
|
||||||
|
newCountryCode,
|
||||||
|
apiConfig.value(configKey::serviceType).toString(),
|
||||||
|
apiConfig.value(configKey::serviceProtocol).toString(),
|
||||||
|
serverConfig.value(configKey::authData).toObject() };
|
||||||
|
|
||||||
ApiPayloadData apiPayloadData = generateApiPayloadData(serviceProtocol);
|
ProtocolData protocolData = generateProtocolData(gatewayRequestData.serviceProtocol);
|
||||||
|
|
||||||
QJsonObject apiPayload = fillApiPayload(serviceProtocol, apiPayloadData);
|
QJsonObject apiPayload = gatewayRequestData.toJsonObject();
|
||||||
apiPayload[configKey::userCountryCode] = userCountryCode;
|
appendProtocolDataToApiPayload(gatewayRequestData.serviceProtocol, protocolData, apiPayload);
|
||||||
apiPayload[configKey::serviceType] = serviceType;
|
|
||||||
apiPayload[configKey::uuid] = installationUuid;
|
|
||||||
apiPayload[apiDefs::key::cliVersion] = QString(APP_VERSION);
|
|
||||||
|
|
||||||
if (!newCountryCode.isEmpty()) {
|
|
||||||
apiPayload[configKey::serverCountryCode] = newCountryCode;
|
|
||||||
}
|
|
||||||
if (!authData.isEmpty()) {
|
|
||||||
apiPayload[configKey::authData] = authData;
|
|
||||||
}
|
|
||||||
|
|
||||||
QByteArray responseBody;
|
QByteArray responseBody;
|
||||||
ErrorCode errorCode = gatewayController.post(QString("%1v1/config"), apiPayload, responseBody);
|
ErrorCode errorCode = executeRequest(QString("%1v1/config"), apiPayload, responseBody);
|
||||||
|
|
||||||
QJsonObject newServerConfig;
|
QJsonObject newServerConfig;
|
||||||
if (errorCode == ErrorCode::NoError) {
|
if (errorCode == ErrorCode::NoError) {
|
||||||
fillServerConfig(serviceProtocol, apiPayloadData, responseBody, newServerConfig);
|
errorCode = fillServerConfig(gatewayRequestData.serviceProtocol, protocolData, responseBody, newServerConfig);
|
||||||
|
if (errorCode != ErrorCode::NoError) {
|
||||||
|
emit errorOccurred(errorCode);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
QJsonObject newApiConfig = newServerConfig.value(configKey::apiConfig).toObject();
|
QJsonObject newApiConfig = newServerConfig.value(configKey::apiConfig).toObject();
|
||||||
newApiConfig.insert(configKey::userCountryCode, apiConfig.value(configKey::userCountryCode));
|
newApiConfig.insert(configKey::userCountryCode, apiConfig.value(configKey::userCountryCode));
|
||||||
|
|
@ -259,7 +428,7 @@ bool ApiConfigsController::updateServiceFromGateway(const int serverIndex, const
|
||||||
newApiConfig.insert(apiDefs::key::vpnKey, apiConfig.value(apiDefs::key::vpnKey));
|
newApiConfig.insert(apiDefs::key::vpnKey, apiConfig.value(apiDefs::key::vpnKey));
|
||||||
|
|
||||||
newServerConfig.insert(configKey::apiConfig, newApiConfig);
|
newServerConfig.insert(configKey::apiConfig, newApiConfig);
|
||||||
newServerConfig.insert(configKey::authData, authData);
|
newServerConfig.insert(configKey::authData, gatewayRequestData.authData);
|
||||||
|
|
||||||
if (serverConfig.value(config_key::nameOverriddenByUser).toBool()) {
|
if (serverConfig.value(config_key::nameOverriddenByUser).toBool()) {
|
||||||
newServerConfig.insert(config_key::name, serverConfig.value(config_key::name));
|
newServerConfig.insert(config_key::name, serverConfig.value(config_key::name));
|
||||||
|
|
@ -294,10 +463,13 @@ bool ApiConfigsController::updateServiceFromTelegram(const int serverIndex)
|
||||||
auto installationUuid = m_settings->getInstallationUuid(true);
|
auto installationUuid = m_settings->getInstallationUuid(true);
|
||||||
|
|
||||||
QString serviceProtocol = serverConfig.value(configKey::protocol).toString();
|
QString serviceProtocol = serverConfig.value(configKey::protocol).toString();
|
||||||
ApiPayloadData apiPayloadData = generateApiPayloadData(serviceProtocol);
|
ProtocolData protocolData = generateProtocolData(serviceProtocol);
|
||||||
|
|
||||||
QJsonObject apiPayload = fillApiPayload(serviceProtocol, apiPayloadData);
|
QJsonObject apiPayload;
|
||||||
|
appendProtocolDataToApiPayload(serviceProtocol, protocolData, apiPayload);
|
||||||
apiPayload[configKey::uuid] = installationUuid;
|
apiPayload[configKey::uuid] = installationUuid;
|
||||||
|
apiPayload[configKey::osVersion] = QSysInfo::productType();
|
||||||
|
apiPayload[configKey::appVersion] = QString(APP_VERSION);
|
||||||
apiPayload[configKey::accessToken] = serverConfig.value(configKey::accessToken).toString();
|
apiPayload[configKey::accessToken] = serverConfig.value(configKey::accessToken).toString();
|
||||||
apiPayload[configKey::apiEndpoint] = serverConfig.value(configKey::apiEndpoint).toString();
|
apiPayload[configKey::apiEndpoint] = serverConfig.value(configKey::apiEndpoint).toString();
|
||||||
|
|
||||||
|
|
@ -305,7 +477,11 @@ bool ApiConfigsController::updateServiceFromTelegram(const int serverIndex)
|
||||||
ErrorCode errorCode = gatewayController.post(QString("%1v1/proxy_config"), apiPayload, responseBody);
|
ErrorCode errorCode = gatewayController.post(QString("%1v1/proxy_config"), apiPayload, responseBody);
|
||||||
|
|
||||||
if (errorCode == ErrorCode::NoError) {
|
if (errorCode == ErrorCode::NoError) {
|
||||||
fillServerConfig(serviceProtocol, apiPayloadData, responseBody, serverConfig);
|
errorCode = fillServerConfig(serviceProtocol, protocolData, responseBody, serverConfig);
|
||||||
|
if (errorCode != ErrorCode::NoError) {
|
||||||
|
emit errorOccurred(errorCode);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
m_serversModel->editServer(serverConfig, serverIndex);
|
m_serversModel->editServer(serverConfig, serverIndex);
|
||||||
emit updateServerFromApiFinished();
|
emit updateServerFromApiFinished();
|
||||||
|
|
@ -318,9 +494,6 @@ bool ApiConfigsController::updateServiceFromTelegram(const int serverIndex)
|
||||||
|
|
||||||
bool ApiConfigsController::deactivateDevice()
|
bool ApiConfigsController::deactivateDevice()
|
||||||
{
|
{
|
||||||
GatewayController gatewayController(m_settings->getGatewayEndpoint(), m_settings->isDevGatewayEnv(), apiDefs::requestTimeoutMsecs,
|
|
||||||
m_settings->isStrictKillSwitchEnabled());
|
|
||||||
|
|
||||||
auto serverIndex = m_serversModel->getProcessedServerIndex();
|
auto serverIndex = m_serversModel->getProcessedServerIndex();
|
||||||
auto serverConfigObject = m_serversModel->getServerConfig(serverIndex);
|
auto serverConfigObject = m_serversModel->getServerConfig(serverIndex);
|
||||||
auto apiConfigObject = serverConfigObject.value(configKey::apiConfig).toObject();
|
auto apiConfigObject = serverConfigObject.value(configKey::apiConfig).toObject();
|
||||||
|
|
@ -329,19 +502,19 @@ bool ApiConfigsController::deactivateDevice()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString protocol = apiConfigObject.value(configKey::serviceProtocol).toString();
|
GatewayRequestData gatewayRequestData { QSysInfo::productType(),
|
||||||
ApiPayloadData apiPayloadData = generateApiPayloadData(protocol);
|
QString(APP_VERSION),
|
||||||
|
m_settings->getInstallationUuid(true),
|
||||||
|
apiConfigObject.value(configKey::userCountryCode).toString(),
|
||||||
|
apiConfigObject.value(configKey::serverCountryCode).toString(),
|
||||||
|
apiConfigObject.value(configKey::serviceType).toString(),
|
||||||
|
"",
|
||||||
|
serverConfigObject.value(configKey::authData).toObject() };
|
||||||
|
|
||||||
QJsonObject apiPayload = fillApiPayload(protocol, apiPayloadData);
|
QJsonObject apiPayload = gatewayRequestData.toJsonObject();
|
||||||
apiPayload[configKey::userCountryCode] = apiConfigObject.value(configKey::userCountryCode);
|
|
||||||
apiPayload[configKey::serverCountryCode] = apiConfigObject.value(configKey::serverCountryCode);
|
|
||||||
apiPayload[configKey::serviceType] = apiConfigObject.value(configKey::serviceType);
|
|
||||||
apiPayload[configKey::authData] = serverConfigObject.value(configKey::authData);
|
|
||||||
apiPayload[configKey::uuid] = m_settings->getInstallationUuid(true);
|
|
||||||
apiPayload[apiDefs::key::cliVersion] = QString(APP_VERSION);
|
|
||||||
|
|
||||||
QByteArray responseBody;
|
QByteArray responseBody;
|
||||||
ErrorCode errorCode = gatewayController.post(QString("%1v1/revoke_config"), apiPayload, responseBody);
|
ErrorCode errorCode = executeRequest(QString("%1v1/revoke_config"), apiPayload, responseBody);
|
||||||
if (errorCode != ErrorCode::NoError && errorCode != ErrorCode::ApiNotFoundError) {
|
if (errorCode != ErrorCode::NoError && errorCode != ErrorCode::ApiNotFoundError) {
|
||||||
emit errorOccurred(errorCode);
|
emit errorOccurred(errorCode);
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -355,9 +528,6 @@ bool ApiConfigsController::deactivateDevice()
|
||||||
|
|
||||||
bool ApiConfigsController::deactivateExternalDevice(const QString &uuid, const QString &serverCountryCode)
|
bool ApiConfigsController::deactivateExternalDevice(const QString &uuid, const QString &serverCountryCode)
|
||||||
{
|
{
|
||||||
GatewayController gatewayController(m_settings->getGatewayEndpoint(), m_settings->isDevGatewayEnv(), apiDefs::requestTimeoutMsecs,
|
|
||||||
m_settings->isStrictKillSwitchEnabled());
|
|
||||||
|
|
||||||
auto serverIndex = m_serversModel->getProcessedServerIndex();
|
auto serverIndex = m_serversModel->getProcessedServerIndex();
|
||||||
auto serverConfigObject = m_serversModel->getServerConfig(serverIndex);
|
auto serverConfigObject = m_serversModel->getServerConfig(serverIndex);
|
||||||
auto apiConfigObject = serverConfigObject.value(configKey::apiConfig).toObject();
|
auto apiConfigObject = serverConfigObject.value(configKey::apiConfig).toObject();
|
||||||
|
|
@ -366,19 +536,19 @@ bool ApiConfigsController::deactivateExternalDevice(const QString &uuid, const Q
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString protocol = apiConfigObject.value(configKey::serviceProtocol).toString();
|
GatewayRequestData gatewayRequestData { QSysInfo::productType(),
|
||||||
ApiPayloadData apiPayloadData = generateApiPayloadData(protocol);
|
QString(APP_VERSION),
|
||||||
|
uuid,
|
||||||
|
apiConfigObject.value(configKey::userCountryCode).toString(),
|
||||||
|
serverCountryCode,
|
||||||
|
apiConfigObject.value(configKey::serviceType).toString(),
|
||||||
|
"",
|
||||||
|
serverConfigObject.value(configKey::authData).toObject() };
|
||||||
|
|
||||||
QJsonObject apiPayload = fillApiPayload(protocol, apiPayloadData);
|
QJsonObject apiPayload = gatewayRequestData.toJsonObject();
|
||||||
apiPayload[configKey::userCountryCode] = apiConfigObject.value(configKey::userCountryCode);
|
|
||||||
apiPayload[configKey::serverCountryCode] = serverCountryCode;
|
|
||||||
apiPayload[configKey::serviceType] = apiConfigObject.value(configKey::serviceType);
|
|
||||||
apiPayload[configKey::authData] = serverConfigObject.value(configKey::authData);
|
|
||||||
apiPayload[configKey::uuid] = uuid;
|
|
||||||
apiPayload[apiDefs::key::cliVersion] = QString(APP_VERSION);
|
|
||||||
|
|
||||||
QByteArray responseBody;
|
QByteArray responseBody;
|
||||||
ErrorCode errorCode = gatewayController.post(QString("%1v1/revoke_config"), apiPayload, responseBody);
|
ErrorCode errorCode = executeRequest(QString("%1v1/revoke_config"), apiPayload, responseBody);
|
||||||
if (errorCode != ErrorCode::NoError && errorCode != ErrorCode::ApiNotFoundError) {
|
if (errorCode != ErrorCode::NoError && errorCode != ErrorCode::ApiNotFoundError) {
|
||||||
emit errorOccurred(errorCode);
|
emit errorOccurred(errorCode);
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -398,16 +568,16 @@ bool ApiConfigsController::isConfigValid()
|
||||||
QJsonObject serverConfigObject = m_serversModel->getServerConfig(serverIndex);
|
QJsonObject serverConfigObject = m_serversModel->getServerConfig(serverIndex);
|
||||||
auto configSource = apiUtils::getConfigSource(serverConfigObject);
|
auto configSource = apiUtils::getConfigSource(serverConfigObject);
|
||||||
|
|
||||||
if (configSource == amnezia::ServerConfigType::ApiV1
|
if (configSource == apiDefs::ConfigSource::Telegram
|
||||||
&& !m_serversModel->data(serverIndex, ServersModel::Roles::HasInstalledContainers).toBool()) {
|
&& !m_serversModel->data(serverIndex, ServersModel::Roles::HasInstalledContainers).toBool()) {
|
||||||
m_serversModel->removeApiConfig(serverIndex);
|
m_serversModel->removeApiConfig(serverIndex);
|
||||||
return updateServiceFromTelegram(serverIndex);
|
return updateServiceFromTelegram(serverIndex);
|
||||||
} else if (configSource == amnezia::ServerConfigType::ApiV2
|
} else if (configSource == apiDefs::ConfigSource::AmneziaGateway
|
||||||
&& !m_serversModel->data(serverIndex, ServersModel::Roles::HasInstalledContainers).toBool()) {
|
&& !m_serversModel->data(serverIndex, ServersModel::Roles::HasInstalledContainers).toBool()) {
|
||||||
return updateServiceFromGateway(serverIndex, "", "");
|
return updateServiceFromGateway(serverIndex, "", "");
|
||||||
} else if (configSource && m_serversModel->isApiKeyExpired(serverIndex)) {
|
} else if (configSource && m_serversModel->isApiKeyExpired(serverIndex)) {
|
||||||
qDebug() << "attempt to update api config by expires_at event";
|
qDebug() << "attempt to update api config by expires_at event";
|
||||||
if (configSource == amnezia::ServerConfigType::ApiV2) {
|
if (configSource == apiDefs::ConfigSource::AmneziaGateway) {
|
||||||
return updateServiceFromGateway(serverIndex, "", "");
|
return updateServiceFromGateway(serverIndex, "", "");
|
||||||
} else {
|
} else {
|
||||||
m_serversModel->removeApiConfig(serverIndex);
|
m_serversModel->removeApiConfig(serverIndex);
|
||||||
|
|
@ -417,108 +587,29 @@ bool ApiConfigsController::isConfigValid()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ApiConfigsController::ApiPayloadData ApiConfigsController::generateApiPayloadData(const QString &protocol)
|
void ApiConfigsController::setCurrentProtocol(const QString &protocolName)
|
||||||
{
|
{
|
||||||
ApiConfigsController::ApiPayloadData apiPayload;
|
auto serverIndex = m_serversModel->getProcessedServerIndex();
|
||||||
if (protocol == configKey::cloak) {
|
auto serverConfigObject = m_serversModel->getServerConfig(serverIndex);
|
||||||
apiPayload.certRequest = OpenVpnConfigurator::createCertRequest();
|
auto apiConfigObject = serverConfigObject.value(configKey::apiConfig).toObject();
|
||||||
} else if (protocol == configKey::awg) {
|
|
||||||
auto connData = WireguardConfigurator::genClientKeys();
|
apiConfigObject[configKey::serviceProtocol] = protocolName;
|
||||||
apiPayload.wireGuardClientPubKey = connData.clientPubKey;
|
|
||||||
apiPayload.wireGuardClientPrivKey = connData.clientPrivKey;
|
serverConfigObject.insert(configKey::apiConfig, apiConfigObject);
|
||||||
}
|
|
||||||
return apiPayload;
|
m_serversModel->editServer(serverConfigObject, serverIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonObject ApiConfigsController::fillApiPayload(const QString &protocol, const ApiPayloadData &apiPayloadData)
|
bool ApiConfigsController::isVlessProtocol()
|
||||||
{
|
{
|
||||||
QJsonObject obj;
|
auto serverIndex = m_serversModel->getProcessedServerIndex();
|
||||||
if (protocol == configKey::cloak) {
|
auto serverConfigObject = m_serversModel->getServerConfig(serverIndex);
|
||||||
obj[configKey::certificate] = apiPayloadData.certRequest.request;
|
auto apiConfigObject = serverConfigObject.value(configKey::apiConfig).toObject();
|
||||||
} else if (protocol == configKey::awg) {
|
|
||||||
obj[configKey::publicKey] = apiPayloadData.wireGuardClientPubKey;
|
if (apiConfigObject[configKey::serviceProtocol].toString() == "vless") {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
obj[configKey::osVersion] = QSysInfo::productType();
|
|
||||||
obj[configKey::appVersion] = QString(APP_VERSION);
|
|
||||||
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ApiConfigsController::fillServerConfig(const QString &protocol, const ApiPayloadData &apiPayloadData,
|
|
||||||
const QByteArray &apiResponseBody, QJsonObject &serverConfig)
|
|
||||||
{
|
|
||||||
QString data = QJsonDocument::fromJson(apiResponseBody).object().value(config_key::config).toString();
|
|
||||||
|
|
||||||
data.replace("vpn://", "");
|
|
||||||
QByteArray ba = QByteArray::fromBase64(data.toUtf8(), QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals);
|
|
||||||
|
|
||||||
if (ba.isEmpty()) {
|
|
||||||
emit errorOccurred(ErrorCode::ApiConfigEmptyError);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QByteArray ba_uncompressed = qUncompress(ba);
|
|
||||||
if (!ba_uncompressed.isEmpty()) {
|
|
||||||
ba = ba_uncompressed;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString configStr = ba;
|
|
||||||
if (protocol == configKey::cloak) {
|
|
||||||
configStr.replace("<key>", "<key>\n");
|
|
||||||
configStr.replace("$OPENVPN_PRIV_KEY", apiPayloadData.certRequest.privKey);
|
|
||||||
} else if (protocol == configKey::awg) {
|
|
||||||
configStr.replace("$WIREGUARD_CLIENT_PRIVATE_KEY", apiPayloadData.wireGuardClientPrivKey);
|
|
||||||
auto newServerConfig = QJsonDocument::fromJson(configStr.toUtf8()).object();
|
|
||||||
auto containers = newServerConfig.value(config_key::containers).toArray();
|
|
||||||
if (containers.isEmpty()) {
|
|
||||||
return; // todo process error
|
|
||||||
}
|
|
||||||
auto container = containers.at(0).toObject();
|
|
||||||
QString containerName = ContainerProps::containerTypeToString(DockerContainer::Awg);
|
|
||||||
auto containerConfig = container.value(containerName).toObject();
|
|
||||||
auto protocolConfig = QJsonDocument::fromJson(containerConfig.value(config_key::last_config).toString().toUtf8()).object();
|
|
||||||
containerConfig[config_key::junkPacketCount] = protocolConfig.value(config_key::junkPacketCount);
|
|
||||||
containerConfig[config_key::junkPacketMinSize] = protocolConfig.value(config_key::junkPacketMinSize);
|
|
||||||
containerConfig[config_key::junkPacketMaxSize] = protocolConfig.value(config_key::junkPacketMaxSize);
|
|
||||||
containerConfig[config_key::initPacketJunkSize] = protocolConfig.value(config_key::initPacketJunkSize);
|
|
||||||
containerConfig[config_key::responsePacketJunkSize] = protocolConfig.value(config_key::responsePacketJunkSize);
|
|
||||||
containerConfig[config_key::initPacketMagicHeader] = protocolConfig.value(config_key::initPacketMagicHeader);
|
|
||||||
containerConfig[config_key::responsePacketMagicHeader] = protocolConfig.value(config_key::responsePacketMagicHeader);
|
|
||||||
containerConfig[config_key::underloadPacketMagicHeader] = protocolConfig.value(config_key::underloadPacketMagicHeader);
|
|
||||||
containerConfig[config_key::transportPacketMagicHeader] = protocolConfig.value(config_key::transportPacketMagicHeader);
|
|
||||||
container[containerName] = containerConfig;
|
|
||||||
containers.replace(0, container);
|
|
||||||
newServerConfig[config_key::containers] = containers;
|
|
||||||
configStr = QString(QJsonDocument(newServerConfig).toJson());
|
|
||||||
}
|
|
||||||
|
|
||||||
QJsonObject newServerConfig = QJsonDocument::fromJson(configStr.toUtf8()).object();
|
|
||||||
serverConfig[config_key::dns1] = newServerConfig.value(config_key::dns1);
|
|
||||||
serverConfig[config_key::dns2] = newServerConfig.value(config_key::dns2);
|
|
||||||
serverConfig[config_key::containers] = newServerConfig.value(config_key::containers);
|
|
||||||
serverConfig[config_key::hostName] = newServerConfig.value(config_key::hostName);
|
|
||||||
|
|
||||||
if (newServerConfig.value(config_key::configVersion).toInt() == amnezia::ServerConfigType::ApiV2) {
|
|
||||||
serverConfig[config_key::configVersion] = newServerConfig.value(config_key::configVersion);
|
|
||||||
serverConfig[config_key::description] = newServerConfig.value(config_key::description);
|
|
||||||
serverConfig[config_key::name] = newServerConfig.value(config_key::name);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto defaultContainer = newServerConfig.value(config_key::defaultContainer).toString();
|
|
||||||
serverConfig[config_key::defaultContainer] = defaultContainer;
|
|
||||||
|
|
||||||
QVariantMap map = serverConfig.value(configKey::apiConfig).toObject().toVariantMap();
|
|
||||||
map.insert(newServerConfig.value(configKey::apiConfig).toObject().toVariantMap());
|
|
||||||
auto apiConfig = QJsonObject::fromVariantMap(map);
|
|
||||||
|
|
||||||
if (newServerConfig.value(config_key::configVersion).toInt() == amnezia::ServerConfigType::ApiV2) {
|
|
||||||
apiConfig.insert(configKey::serviceInfo, QJsonDocument::fromJson(apiResponseBody).object().value(configKey::serviceInfo).toObject());
|
|
||||||
}
|
|
||||||
|
|
||||||
serverConfig[configKey::apiConfig] = apiConfig;
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QString> ApiConfigsController::getQrCodes()
|
QList<QString> ApiConfigsController::getQrCodes()
|
||||||
|
|
@ -535,3 +626,10 @@ QString ApiConfigsController::getVpnKey()
|
||||||
{
|
{
|
||||||
return m_vpnKey;
|
return m_vpnKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ErrorCode ApiConfigsController::executeRequest(const QString &endpoint, const QJsonObject &apiPayload, QByteArray &responseBody)
|
||||||
|
{
|
||||||
|
GatewayController gatewayController(m_settings->getGatewayEndpoint(), m_settings->isDevGatewayEnv(), apiDefs::requestTimeoutMsecs,
|
||||||
|
m_settings->isStrictKillSwitchEnabled());
|
||||||
|
return gatewayController.post(endpoint, apiPayload, responseBody);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,9 @@ public slots:
|
||||||
|
|
||||||
bool isConfigValid();
|
bool isConfigValid();
|
||||||
|
|
||||||
|
void setCurrentProtocol(const QString &protocolName);
|
||||||
|
bool isVlessProtocol();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void errorOccurred(ErrorCode errorCode);
|
void errorOccurred(ErrorCode errorCode);
|
||||||
|
|
||||||
|
|
@ -46,23 +49,12 @@ signals:
|
||||||
void vpnKeyExportReady();
|
void vpnKeyExportReady();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct ApiPayloadData
|
|
||||||
{
|
|
||||||
OpenVpnConfigurator::ConnectionData certRequest;
|
|
||||||
|
|
||||||
QString wireGuardClientPrivKey;
|
|
||||||
QString wireGuardClientPubKey;
|
|
||||||
};
|
|
||||||
|
|
||||||
ApiPayloadData generateApiPayloadData(const QString &protocol);
|
|
||||||
QJsonObject fillApiPayload(const QString &protocol, const ApiPayloadData &apiPayloadData);
|
|
||||||
void fillServerConfig(const QString &protocol, const ApiPayloadData &apiPayloadData, const QByteArray &apiResponseBody,
|
|
||||||
QJsonObject &serverConfig);
|
|
||||||
|
|
||||||
QList<QString> getQrCodes();
|
QList<QString> getQrCodes();
|
||||||
int getQrCodesCount();
|
int getQrCodesCount();
|
||||||
QString getVpnKey();
|
QString getVpnKey();
|
||||||
|
|
||||||
|
ErrorCode executeRequest(const QString &endpoint, const QJsonObject &apiPayload, QByteArray &responseBody);
|
||||||
|
|
||||||
QList<QString> m_qrCodes;
|
QList<QString> m_qrCodes;
|
||||||
QString m_vpnKey;
|
QString m_vpnKey;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@
|
||||||
#include "core/errorstrings.h"
|
#include "core/errorstrings.h"
|
||||||
#include "core/qrCodeUtils.h"
|
#include "core/qrCodeUtils.h"
|
||||||
#include "core/serialization/serialization.h"
|
#include "core/serialization/serialization.h"
|
||||||
|
#include "protocols/protocols_defs.h"
|
||||||
#include "systemController.h"
|
#include "systemController.h"
|
||||||
#include "utilities.h"
|
#include "utilities.h"
|
||||||
|
|
||||||
|
|
@ -286,6 +287,19 @@ void ImportController::processNativeWireGuardConfig()
|
||||||
clientProtocolConfig[config_key::underloadPacketMagicHeader] = "3";
|
clientProtocolConfig[config_key::underloadPacketMagicHeader] = "3";
|
||||||
clientProtocolConfig[config_key::transportPacketMagicHeader] = "4";
|
clientProtocolConfig[config_key::transportPacketMagicHeader] = "4";
|
||||||
|
|
||||||
|
// clientProtocolConfig[config_key::cookieReplyPacketJunkSize] = "0";
|
||||||
|
// clientProtocolConfig[config_key::transportPacketJunkSize] = "0";
|
||||||
|
|
||||||
|
// clientProtocolConfig[config_key::specialJunk1] = "";
|
||||||
|
// clientProtocolConfig[config_key::specialJunk2] = "";
|
||||||
|
// clientProtocolConfig[config_key::specialJunk3] = "";
|
||||||
|
// clientProtocolConfig[config_key::specialJunk4] = "";
|
||||||
|
// clientProtocolConfig[config_key::specialJunk5] = "";
|
||||||
|
// clientProtocolConfig[config_key::controlledJunk1] = "";
|
||||||
|
// clientProtocolConfig[config_key::controlledJunk2] = "";
|
||||||
|
// clientProtocolConfig[config_key::controlledJunk3] = "";
|
||||||
|
// clientProtocolConfig[config_key::specialHandshakeTimeout] = "0";
|
||||||
|
|
||||||
clientProtocolConfig[config_key::isObfuscationEnabled] = true;
|
clientProtocolConfig[config_key::isObfuscationEnabled] = true;
|
||||||
|
|
||||||
serverProtocolConfig[config_key::last_config] = QString(QJsonDocument(clientProtocolConfig).toJson());
|
serverProtocolConfig[config_key::last_config] = QString(QJsonDocument(clientProtocolConfig).toJson());
|
||||||
|
|
@ -438,21 +452,33 @@ QJsonObject ImportController::extractWireGuardConfig(const QString &data)
|
||||||
lastConfig[config_key::allowed_ips] = allowedIpsJsonArray;
|
lastConfig[config_key::allowed_ips] = allowedIpsJsonArray;
|
||||||
|
|
||||||
QString protocolName = "wireguard";
|
QString protocolName = "wireguard";
|
||||||
if (!configMap.value(config_key::junkPacketCount).isEmpty() && !configMap.value(config_key::junkPacketMinSize).isEmpty()
|
|
||||||
&& !configMap.value(config_key::junkPacketMaxSize).isEmpty() && !configMap.value(config_key::initPacketJunkSize).isEmpty()
|
const QStringList requiredJunkFields = { config_key::junkPacketCount, config_key::junkPacketMinSize,
|
||||||
&& !configMap.value(config_key::responsePacketJunkSize).isEmpty() && !configMap.value(config_key::initPacketMagicHeader).isEmpty()
|
config_key::junkPacketMaxSize, config_key::initPacketJunkSize,
|
||||||
&& !configMap.value(config_key::responsePacketMagicHeader).isEmpty()
|
config_key::responsePacketJunkSize, config_key::initPacketMagicHeader,
|
||||||
&& !configMap.value(config_key::underloadPacketMagicHeader).isEmpty()
|
config_key::responsePacketMagicHeader, config_key::underloadPacketMagicHeader,
|
||||||
&& !configMap.value(config_key::transportPacketMagicHeader).isEmpty()) {
|
config_key::transportPacketMagicHeader };
|
||||||
lastConfig[config_key::junkPacketCount] = configMap.value(config_key::junkPacketCount);
|
|
||||||
lastConfig[config_key::junkPacketMinSize] = configMap.value(config_key::junkPacketMinSize);
|
const QStringList optionalJunkFields = { // config_key::cookieReplyPacketJunkSize,
|
||||||
lastConfig[config_key::junkPacketMaxSize] = configMap.value(config_key::junkPacketMaxSize);
|
// config_key::transportPacketJunkSize,
|
||||||
lastConfig[config_key::initPacketJunkSize] = configMap.value(config_key::initPacketJunkSize);
|
config_key::specialJunk1, config_key::specialJunk2, config_key::specialJunk3,
|
||||||
lastConfig[config_key::responsePacketJunkSize] = configMap.value(config_key::responsePacketJunkSize);
|
config_key::specialJunk4, config_key::specialJunk5, config_key::controlledJunk1,
|
||||||
lastConfig[config_key::initPacketMagicHeader] = configMap.value(config_key::initPacketMagicHeader);
|
config_key::controlledJunk2, config_key::controlledJunk3, config_key::specialHandshakeTimeout
|
||||||
lastConfig[config_key::responsePacketMagicHeader] = configMap.value(config_key::responsePacketMagicHeader);
|
};
|
||||||
lastConfig[config_key::underloadPacketMagicHeader] = configMap.value(config_key::underloadPacketMagicHeader);
|
|
||||||
lastConfig[config_key::transportPacketMagicHeader] = configMap.value(config_key::transportPacketMagicHeader);
|
bool hasAllRequiredFields = std::all_of(requiredJunkFields.begin(), requiredJunkFields.end(),
|
||||||
|
[&configMap](const QString &field) { return !configMap.value(field).isEmpty(); });
|
||||||
|
if (hasAllRequiredFields) {
|
||||||
|
for (const QString &field : requiredJunkFields) {
|
||||||
|
lastConfig[field] = configMap.value(field);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const QString &field : optionalJunkFields) {
|
||||||
|
if (!configMap.value(field).isEmpty()) {
|
||||||
|
lastConfig[field] = configMap.value(field);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protocolName = "awg";
|
protocolName = "awg";
|
||||||
m_configType = ConfigTypes::Awg;
|
m_configType = ConfigTypes::Awg;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@
|
||||||
#include "core/api/apiUtils.h"
|
#include "core/api/apiUtils.h"
|
||||||
#include "core/controllers/serverController.h"
|
#include "core/controllers/serverController.h"
|
||||||
#include "core/controllers/vpnConfigurationController.h"
|
#include "core/controllers/vpnConfigurationController.h"
|
||||||
#include "core/models/servers/selfHostedServerConfig.h"
|
|
||||||
#include "core/networkUtilities.h"
|
#include "core/networkUtilities.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "ui/models/protocols/awgConfigModel.h"
|
#include "ui/models/protocols/awgConfigModel.h"
|
||||||
|
|
@ -80,12 +79,36 @@ void InstallController::install(DockerContainer container, int port, TransportPr
|
||||||
|
|
||||||
int s1 = QRandomGenerator::global()->bounded(15, 150);
|
int s1 = QRandomGenerator::global()->bounded(15, 150);
|
||||||
int s2 = QRandomGenerator::global()->bounded(15, 150);
|
int s2 = QRandomGenerator::global()->bounded(15, 150);
|
||||||
while (s1 + awg::messageInitiationSize == s2 + awg::messageResponseSize) {
|
// int s3 = QRandomGenerator::global()->bounded(15, 150);
|
||||||
|
// int s4 = QRandomGenerator::global()->bounded(15, 150);
|
||||||
|
|
||||||
|
// Ensure all values are unique and don't create equal packet sizes
|
||||||
|
QSet<int> usedValues;
|
||||||
|
usedValues.insert(s1);
|
||||||
|
|
||||||
|
while (usedValues.contains(s2) || s1 + AwgConstant::messageInitiationSize == s2 + AwgConstant::messageResponseSize) {
|
||||||
s2 = QRandomGenerator::global()->bounded(15, 150);
|
s2 = QRandomGenerator::global()->bounded(15, 150);
|
||||||
}
|
}
|
||||||
|
usedValues.insert(s2);
|
||||||
|
|
||||||
|
// while (usedValues.contains(s3)
|
||||||
|
// || s1 + AwgConstant::messageInitiationSize == s3 + AwgConstant::messageCookieReplySize
|
||||||
|
// || s2 + AwgConstant::messageResponseSize == s3 + AwgConstant::messageCookieReplySize) {
|
||||||
|
// s3 = QRandomGenerator::global()->bounded(15, 150);
|
||||||
|
// }
|
||||||
|
// usedValues.insert(s3);
|
||||||
|
|
||||||
|
// while (usedValues.contains(s4)
|
||||||
|
// || s1 + AwgConstant::messageInitiationSize == s4 + AwgConstant::messageTransportSize
|
||||||
|
// || s2 + AwgConstant::messageResponseSize == s4 + AwgConstant::messageTransportSize
|
||||||
|
// || s3 + AwgConstant::messageCookieReplySize == s4 + AwgConstant::messageTransportSize) {
|
||||||
|
// s4 = QRandomGenerator::global()->bounded(15, 150);
|
||||||
|
// }
|
||||||
|
|
||||||
QString initPacketJunkSize = QString::number(s1);
|
QString initPacketJunkSize = QString::number(s1);
|
||||||
QString responsePacketJunkSize = QString::number(s2);
|
QString responsePacketJunkSize = QString::number(s2);
|
||||||
|
// QString cookieReplyPacketJunkSize = QString::number(s3);
|
||||||
|
// QString transportPacketJunkSize = QString::number(s4);
|
||||||
|
|
||||||
QSet<QString> headersValue;
|
QSet<QString> headersValue;
|
||||||
while (headersValue.size() != 4) {
|
while (headersValue.size() != 4) {
|
||||||
|
|
@ -109,6 +132,21 @@ void InstallController::install(DockerContainer container, int port, TransportPr
|
||||||
containerConfig[config_key::responsePacketMagicHeader] = responsePacketMagicHeader;
|
containerConfig[config_key::responsePacketMagicHeader] = responsePacketMagicHeader;
|
||||||
containerConfig[config_key::underloadPacketMagicHeader] = underloadPacketMagicHeader;
|
containerConfig[config_key::underloadPacketMagicHeader] = underloadPacketMagicHeader;
|
||||||
containerConfig[config_key::transportPacketMagicHeader] = transportPacketMagicHeader;
|
containerConfig[config_key::transportPacketMagicHeader] = transportPacketMagicHeader;
|
||||||
|
|
||||||
|
// TODO:
|
||||||
|
// containerConfig[config_key::cookieReplyPacketJunkSize] = cookieReplyPacketJunkSize;
|
||||||
|
// containerConfig[config_key::transportPacketJunkSize] = transportPacketJunkSize;
|
||||||
|
|
||||||
|
// containerConfig[config_key::specialJunk1] = specialJunk1;
|
||||||
|
// containerConfig[config_key::specialJunk2] = specialJunk2;
|
||||||
|
// containerConfig[config_key::specialJunk3] = specialJunk3;
|
||||||
|
// containerConfig[config_key::specialJunk4] = specialJunk4;
|
||||||
|
// containerConfig[config_key::specialJunk5] = specialJunk5;
|
||||||
|
// containerConfig[config_key::controlledJunk1] = controlledJunk1;
|
||||||
|
// containerConfig[config_key::controlledJunk2] = controlledJunk2;
|
||||||
|
// containerConfig[config_key::controlledJunk3] = controlledJunk3;
|
||||||
|
// containerConfig[config_key::specialHandshakeTimeout] = specialHandshakeTimeout;
|
||||||
|
|
||||||
} else if (container == DockerContainer::Sftp) {
|
} else if (container == DockerContainer::Sftp) {
|
||||||
containerConfig.insert(config_key::userName, protocols::sftp::defaultUserName);
|
containerConfig.insert(config_key::userName, protocols::sftp::defaultUserName);
|
||||||
containerConfig.insert(config_key::password, Utils::getRandomString(16));
|
containerConfig.insert(config_key::password, Utils::getRandomString(16));
|
||||||
|
|
@ -402,6 +440,19 @@ ErrorCode InstallController::getAlreadyInstalledContainers(const ServerCredentia
|
||||||
containerConfig[config_key::transportPacketMagicHeader] =
|
containerConfig[config_key::transportPacketMagicHeader] =
|
||||||
serverConfigMap.value(config_key::transportPacketMagicHeader);
|
serverConfigMap.value(config_key::transportPacketMagicHeader);
|
||||||
|
|
||||||
|
// containerConfig[config_key::cookieReplyPacketJunkSize] = serverConfigMap.value(config_key::cookieReplyPacketJunkSize);
|
||||||
|
// containerConfig[config_key::transportPacketJunkSize] = serverConfigMap.value(config_key::transportPacketJunkSize);
|
||||||
|
|
||||||
|
// containerConfig[config_key::specialJunk1] = serverConfigMap.value(config_key::specialJunk1);
|
||||||
|
// containerConfig[config_key::specialJunk2] = serverConfigMap.value(config_key::specialJunk2);
|
||||||
|
// containerConfig[config_key::specialJunk3] = serverConfigMap.value(config_key::specialJunk3);
|
||||||
|
// containerConfig[config_key::specialJunk4] = serverConfigMap.value(config_key::specialJunk4);
|
||||||
|
// containerConfig[config_key::specialJunk5] = serverConfigMap.value(config_key::specialJunk5);
|
||||||
|
// containerConfig[config_key::controlledJunk1] = serverConfigMap.value(config_key::controlledJunk1);
|
||||||
|
// containerConfig[config_key::controlledJunk2] = serverConfigMap.value(config_key::controlledJunk2);
|
||||||
|
// containerConfig[config_key::controlledJunk3] = serverConfigMap.value(config_key::controlledJunk3);
|
||||||
|
// containerConfig[config_key::specialHandshakeTimeout] = serverConfigMap.value(config_key::specialHandshakeTimeout);
|
||||||
|
|
||||||
} else if (protocol == Proto::WireGuard) {
|
} else if (protocol == Proto::WireGuard) {
|
||||||
QString serverConfig = serverController->getTextFileFromContainer(container, credentials,
|
QString serverConfig = serverController->getTextFileFromContainer(container, credentials,
|
||||||
protocols::wireguard::serverConfigPath, errorCode);
|
protocols::wireguard::serverConfigPath, errorCode);
|
||||||
|
|
@ -553,34 +604,28 @@ ErrorCode InstallController::getAlreadyInstalledContainers(const ServerCredentia
|
||||||
return ErrorCode::NoError;
|
return ErrorCode::NoError;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InstallController::updateContainer()
|
void InstallController::updateContainer(QJsonObject config)
|
||||||
{
|
{
|
||||||
int serverIndex = m_serversModel->getProcessedServerIndex();
|
int serverIndex = m_serversModel->getProcessedServerIndex();
|
||||||
auto oldServerConfig = m_serversModel->getServerConfig(serverIndex);
|
ServerCredentials serverCredentials =
|
||||||
auto newServerConfig = QSharedPointer<SelfHostedServerConfig>::create(oldServerConfig);
|
qvariant_cast<ServerCredentials>(m_serversModel->data(serverIndex, ServersModel::Roles::CredentialsRole));
|
||||||
|
|
||||||
const DockerContainer container = static_cast<DockerContainer>(m_containersModel->getProcessedContainerIndex());
|
|
||||||
const QString containerName = m_containersModel->getProcessedContainerName();
|
|
||||||
auto protocolConfigs = m_protocolModel->getProtocolConfigs();
|
|
||||||
newServerConfig->updateProtocolConfig(containerName, protocolConfigs);
|
|
||||||
|
|
||||||
auto oldProtocolConfigs = oldServerConfig->containerConfigs[containerName].protocolConfigs;
|
|
||||||
auto newProtocolConfigs = newServerConfig->containerConfigs[containerName].protocolConfigs;
|
|
||||||
|
|
||||||
|
const DockerContainer container = ContainerProps::containerFromString(config.value(config_key::container).toString());
|
||||||
|
QJsonObject oldContainerConfig = m_containersModel->getContainerConfig(container);
|
||||||
ErrorCode errorCode = ErrorCode::NoError;
|
ErrorCode errorCode = ErrorCode::NoError;
|
||||||
|
|
||||||
if (isUpdateDockerContainerRequired(container, oldProtocolConfigs, newProtocolConfigs)) {
|
if (isUpdateDockerContainerRequired(container, oldContainerConfig, config)) {
|
||||||
QSharedPointer<ServerController> serverController(new ServerController(m_settings));
|
QSharedPointer<ServerController> serverController(new ServerController(m_settings));
|
||||||
connect(serverController.get(), &ServerController::serverIsBusy, this, &InstallController::serverIsBusy);
|
connect(serverController.get(), &ServerController::serverIsBusy, this, &InstallController::serverIsBusy);
|
||||||
connect(this, &InstallController::cancelInstallation, serverController.get(), &ServerController::cancelInstallation);
|
connect(this, &InstallController::cancelInstallation, serverController.get(), &ServerController::cancelInstallation);
|
||||||
|
|
||||||
errorCode = serverController->updateContainer(newServerConfig->serverCredentials, container, oldContainerConfig, config);
|
errorCode = serverController->updateContainer(serverCredentials, container, oldContainerConfig, config);
|
||||||
clearCachedProfile(serverController);
|
clearCachedProfile(serverController);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (errorCode == ErrorCode::NoError) {
|
if (errorCode == ErrorCode::NoError) {
|
||||||
m_serversModel->editServer(newServerConfig, serverIndex);
|
m_serversModel->updateContainerConfig(container, config);
|
||||||
m_protocolModel->updateModel(protocolConfigs);
|
m_protocolModel->updateModel(config);
|
||||||
|
|
||||||
auto defaultContainer = qvariant_cast<DockerContainer>(m_serversModel->data(serverIndex, ServersModel::Roles::DefaultContainerRole));
|
auto defaultContainer = qvariant_cast<DockerContainer>(m_serversModel->data(serverIndex, ServersModel::Roles::DefaultContainerRole));
|
||||||
if ((serverIndex == m_serversModel->getDefaultServerIndex()) && (container == defaultContainer)) {
|
if ((serverIndex == m_serversModel->getDefaultServerIndex()) && (container == defaultContainer)) {
|
||||||
|
|
@ -614,7 +659,7 @@ void InstallController::removeProcessedServer()
|
||||||
int serverIndex = m_serversModel->getProcessedServerIndex();
|
int serverIndex = m_serversModel->getProcessedServerIndex();
|
||||||
QString serverName = m_serversModel->data(serverIndex, ServersModel::Roles::NameRole).toString();
|
QString serverName = m_serversModel->data(serverIndex, ServersModel::Roles::NameRole).toString();
|
||||||
|
|
||||||
m_serversModel->removeProcessedServer();
|
m_serversModel->removeServer();
|
||||||
emit removeProcessedServerFinished(tr("Server '%1' was removed").arg(serverName));
|
emit removeProcessedServerFinished(tr("Server '%1' was removed").arg(serverName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -920,26 +965,29 @@ bool InstallController::isConfigValid()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InstallController::isUpdateDockerContainerRequired(const DockerContainer container,
|
bool InstallController::isUpdateDockerContainerRequired(const DockerContainer container, const QJsonObject &oldConfig,
|
||||||
const QMap<QString, QSharedPointer<ProtocolConfig>> &oldProtocolConfigs,
|
const QJsonObject &newConfig)
|
||||||
const QMap<QString, QSharedPointer<ProtocolConfig>> &newProtocolConfigs)
|
|
||||||
{
|
{
|
||||||
Proto mainProto = ContainerProps::defaultProtocol(container);
|
Proto mainProto = ContainerProps::defaultProtocol(container);
|
||||||
|
|
||||||
const auto oldProtoConfig = oldProtocolConfigs.value(ProtocolProps::protoToString(mainProto));
|
const QJsonObject &oldProtoConfig = oldConfig.value(ProtocolProps::protoToString(mainProto)).toObject();
|
||||||
const auto newProtoConfig = newProtocolConfigs.value(ProtocolProps::protoToString(mainProto));
|
const QJsonObject &newProtoConfig = newConfig.value(ProtocolProps::protoToString(mainProto)).toObject();
|
||||||
|
|
||||||
switch (mainProto) {
|
if (container == DockerContainer::Awg) {
|
||||||
case Proto::Awg: {
|
const AwgConfig oldConfig(oldProtoConfig);
|
||||||
auto newConfig = qSharedPointerCast<AwgProtocolConfig>(oldProtoConfig);
|
const AwgConfig newConfig(newProtoConfig);
|
||||||
auto oldConfig = qSharedPointerCast<AwgProtocolConfig>(newProtoConfig);
|
|
||||||
return !newConfig->hasEqualServerSettings(*oldConfig.data());
|
if (oldConfig.hasEqualServerSettings(newConfig)) {
|
||||||
}
|
return false;
|
||||||
case Proto::WireGuard: {
|
}
|
||||||
auto newConfig = qSharedPointerCast<WireGuardProtocolConfig>(oldProtoConfig);
|
} else if (container == DockerContainer::WireGuard) {
|
||||||
auto oldConfig = qSharedPointerCast<WireGuardProtocolConfig>(newProtoConfig);
|
const WgConfig oldConfig(oldProtoConfig);
|
||||||
return !newConfig->hasEqualServerSettings(*oldConfig.data());
|
const WgConfig newConfig(newProtoConfig);
|
||||||
}
|
|
||||||
default: return true;
|
if (oldConfig.hasEqualServerSettings(newConfig)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ public slots:
|
||||||
|
|
||||||
void scanServerForInstalledContainers();
|
void scanServerForInstalledContainers();
|
||||||
|
|
||||||
void updateContainer();
|
void updateContainer(QJsonObject config);
|
||||||
|
|
||||||
void removeProcessedServer();
|
void removeProcessedServer();
|
||||||
void rebootProcessedServer();
|
void rebootProcessedServer();
|
||||||
|
|
@ -94,9 +94,7 @@ private:
|
||||||
|
|
||||||
ErrorCode getAlreadyInstalledContainers(const ServerCredentials &credentials, const QSharedPointer<ServerController> &serverController,
|
ErrorCode getAlreadyInstalledContainers(const ServerCredentials &credentials, const QSharedPointer<ServerController> &serverController,
|
||||||
QMap<DockerContainer, QJsonObject> &installedContainers);
|
QMap<DockerContainer, QJsonObject> &installedContainers);
|
||||||
bool isUpdateDockerContainerRequired(const DockerContainer container,
|
bool isUpdateDockerContainerRequired(const DockerContainer container, const QJsonObject &oldConfig, const QJsonObject &newConfig);
|
||||||
const QMap<QString, QSharedPointer<ProtocolConfig>> &oldProtocolConfigs,
|
|
||||||
const QMap<QString, QSharedPointer<ProtocolConfig>> &newProtocolConfigs);
|
|
||||||
|
|
||||||
QSharedPointer<ServersModel> m_serversModel;
|
QSharedPointer<ServersModel> m_serversModel;
|
||||||
QSharedPointer<ContainersModel> m_containersModel;
|
QSharedPointer<ContainersModel> m_containersModel;
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,12 @@ QVariant ApiAccountInfoModel::data(const QModelIndex &index, int role) const
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
case IsProtocolSelectionSupportedRole: {
|
||||||
|
if (m_accountInfoData.supportedProtocols.size() > 1) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
@ -95,6 +101,10 @@ void ApiAccountInfoModel::updateModel(const QJsonObject &accountInfoObject, cons
|
||||||
|
|
||||||
accountInfoData.configType = apiUtils::getConfigType(serverConfig);
|
accountInfoData.configType = apiUtils::getConfigType(serverConfig);
|
||||||
|
|
||||||
|
for (const auto &protocol : accountInfoObject.value(apiDefs::key::supportedProtocols).toArray()) {
|
||||||
|
accountInfoData.supportedProtocols.push_back(protocol.toString());
|
||||||
|
}
|
||||||
|
|
||||||
m_accountInfoData = accountInfoData;
|
m_accountInfoData = accountInfoData;
|
||||||
|
|
||||||
m_supportInfo = accountInfoObject.value(apiDefs::key::supportInfo).toObject();
|
m_supportInfo = accountInfoObject.value(apiDefs::key::supportInfo).toObject();
|
||||||
|
|
@ -159,6 +169,7 @@ QHash<int, QByteArray> ApiAccountInfoModel::roleNames() const
|
||||||
roles[ServiceDescriptionRole] = "serviceDescription";
|
roles[ServiceDescriptionRole] = "serviceDescription";
|
||||||
roles[IsComponentVisibleRole] = "isComponentVisible";
|
roles[IsComponentVisibleRole] = "isComponentVisible";
|
||||||
roles[HasExpiredWorkerRole] = "hasExpiredWorker";
|
roles[HasExpiredWorkerRole] = "hasExpiredWorker";
|
||||||
|
roles[IsProtocolSelectionSupportedRole] = "isProtocolSelectionSupported";
|
||||||
|
|
||||||
return roles;
|
return roles;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,8 @@ public:
|
||||||
ServiceDescriptionRole,
|
ServiceDescriptionRole,
|
||||||
EndDateRole,
|
EndDateRole,
|
||||||
IsComponentVisibleRole,
|
IsComponentVisibleRole,
|
||||||
HasExpiredWorkerRole
|
HasExpiredWorkerRole,
|
||||||
|
IsProtocolSelectionSupportedRole
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit ApiAccountInfoModel(QObject *parent = nullptr);
|
explicit ApiAccountInfoModel(QObject *parent = nullptr);
|
||||||
|
|
@ -51,6 +52,8 @@ private:
|
||||||
int maxDeviceCount;
|
int maxDeviceCount;
|
||||||
|
|
||||||
apiDefs::ConfigType configType;
|
apiDefs::ConfigType configType;
|
||||||
|
|
||||||
|
QStringList supportedProtocols;
|
||||||
};
|
};
|
||||||
|
|
||||||
AccountInfoData m_accountInfoData;
|
AccountInfoData m_accountInfoData;
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@
|
||||||
|
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
|
|
||||||
ContainersModel::ContainersModel(QObject *parent) : QAbstractListModel(parent)
|
ContainersModel::ContainersModel(QObject *parent)
|
||||||
|
: QAbstractListModel(parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -24,13 +25,19 @@ QVariant ContainersModel::data(const QModelIndex &index, int role) const
|
||||||
case NameRole: return ContainerProps::containerHumanNames().value(container);
|
case NameRole: return ContainerProps::containerHumanNames().value(container);
|
||||||
case DescriptionRole: return ContainerProps::containerDescriptions().value(container);
|
case DescriptionRole: return ContainerProps::containerDescriptions().value(container);
|
||||||
case DetailedDescriptionRole: return ContainerProps::containerDetailedDescriptions().value(container);
|
case DetailedDescriptionRole: return ContainerProps::containerDetailedDescriptions().value(container);
|
||||||
|
case ConfigRole: {
|
||||||
|
if (container == DockerContainer::None) {
|
||||||
|
return QJsonObject();
|
||||||
|
}
|
||||||
|
return m_containers.value(container);
|
||||||
|
}
|
||||||
case ServiceTypeRole: return ContainerProps::containerService(container);
|
case ServiceTypeRole: return ContainerProps::containerService(container);
|
||||||
case DockerContainerRole: return container;
|
case DockerContainerRole: return container;
|
||||||
case IsEasySetupContainerRole: return ContainerProps::isEasySetupContainer(container);
|
case IsEasySetupContainerRole: return ContainerProps::isEasySetupContainer(container);
|
||||||
case EasySetupHeaderRole: return ContainerProps::easySetupHeader(container);
|
case EasySetupHeaderRole: return ContainerProps::easySetupHeader(container);
|
||||||
case EasySetupDescriptionRole: return ContainerProps::easySetupDescription(container);
|
case EasySetupDescriptionRole: return ContainerProps::easySetupDescription(container);
|
||||||
case EasySetupOrderRole: return ContainerProps::easySetupOrder(container);
|
case EasySetupOrderRole: return ContainerProps::easySetupOrder(container);
|
||||||
case IsInstalledRole: return m_containerConfigs.contains(ContainerProps::containerToString(container));
|
case IsInstalledRole: return m_containers.contains(container);
|
||||||
case IsCurrentlyProcessedRole: return container == static_cast<DockerContainer>(m_processedContainerIndex);
|
case IsCurrentlyProcessedRole: return container == static_cast<DockerContainer>(m_processedContainerIndex);
|
||||||
case IsSupportedRole: return ContainerProps::isSupportedByCurrentPlatform(container);
|
case IsSupportedRole: return ContainerProps::isSupportedByCurrentPlatform(container);
|
||||||
case IsShareableRole: return ContainerProps::isShareable(container);
|
case IsShareableRole: return ContainerProps::isShareable(container);
|
||||||
|
|
@ -46,10 +53,14 @@ QVariant ContainersModel::data(const int index, int role) const
|
||||||
return data(modelIndex, role);
|
return data(modelIndex, role);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContainersModel::updateModel(const QMap<QString, ContainerConfig> &containerConfigs)
|
void ContainersModel::updateModel(const QJsonArray &containers)
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
m_containerConfigs = containerConfigs;
|
m_containers.clear();
|
||||||
|
for (const QJsonValue &val : containers) {
|
||||||
|
m_containers.insert(ContainerProps::containerFromString(val.toObject().value(config_key::container).toString()),
|
||||||
|
val.toObject());
|
||||||
|
}
|
||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -68,6 +79,11 @@ QString ContainersModel::getProcessedContainerName()
|
||||||
return ContainerProps::containerHumanNames().value(static_cast<DockerContainer>(m_processedContainerIndex));
|
return ContainerProps::containerHumanNames().value(static_cast<DockerContainer>(m_processedContainerIndex));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QJsonObject ContainersModel::getContainerConfig(const int containerIndex)
|
||||||
|
{
|
||||||
|
return qvariant_cast<QJsonObject>(data(index(containerIndex), ConfigRole));
|
||||||
|
}
|
||||||
|
|
||||||
bool ContainersModel::isSupportedByCurrentPlatform(const int containerIndex)
|
bool ContainersModel::isSupportedByCurrentPlatform(const int containerIndex)
|
||||||
{
|
{
|
||||||
return qvariant_cast<bool>(data(index(containerIndex), IsSupportedRole));
|
return qvariant_cast<bool>(data(index(containerIndex), IsSupportedRole));
|
||||||
|
|
@ -80,8 +96,8 @@ bool ContainersModel::isServiceContainer(const int containerIndex)
|
||||||
|
|
||||||
bool ContainersModel::hasInstalledServices()
|
bool ContainersModel::hasInstalledServices()
|
||||||
{
|
{
|
||||||
for (const auto &containerName : m_containerConfigs.keys()) {
|
for (const auto &container : m_containers.keys()) {
|
||||||
if (ContainerProps::containerService(ContainerProps::containerFromString(containerName)) == ServiceType::Other) {
|
if (ContainerProps::containerService(container) == ServiceType::Other) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -90,8 +106,8 @@ bool ContainersModel::hasInstalledServices()
|
||||||
|
|
||||||
bool ContainersModel::hasInstalledProtocols()
|
bool ContainersModel::hasInstalledProtocols()
|
||||||
{
|
{
|
||||||
for (const auto &containerName : m_containerConfigs.keys()) {
|
for (const auto &container : m_containers.keys()) {
|
||||||
if (ContainerProps::containerService(ContainerProps::containerFromString(containerName)) == ServiceType::Vpn) {
|
if (ContainerProps::containerService(container) == ServiceType::Vpn) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -106,6 +122,7 @@ QHash<int, QByteArray> ContainersModel::roleNames() const
|
||||||
roles[DetailedDescriptionRole] = "detailedDescription";
|
roles[DetailedDescriptionRole] = "detailedDescription";
|
||||||
roles[ServiceTypeRole] = "serviceType";
|
roles[ServiceTypeRole] = "serviceType";
|
||||||
roles[DockerContainerRole] = "dockerContainer";
|
roles[DockerContainerRole] = "dockerContainer";
|
||||||
|
roles[ConfigRole] = "config";
|
||||||
|
|
||||||
roles[IsEasySetupContainerRole] = "isEasySetupContainer";
|
roles[IsEasySetupContainerRole] = "isEasySetupContainer";
|
||||||
roles[EasySetupHeaderRole] = "easySetupHeader";
|
roles[EasySetupHeaderRole] = "easySetupHeader";
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,10 @@
|
||||||
|
|
||||||
#include <QAbstractListModel>
|
#include <QAbstractListModel>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "containers/containers_defs.h"
|
#include "containers/containers_defs.h"
|
||||||
#include "core/models/containers/containerConfig.h"
|
|
||||||
|
|
||||||
class ContainersModel : public QAbstractListModel
|
class ContainersModel : public QAbstractListModel
|
||||||
{
|
{
|
||||||
|
|
@ -18,6 +19,7 @@ public:
|
||||||
DescriptionRole,
|
DescriptionRole,
|
||||||
DetailedDescriptionRole,
|
DetailedDescriptionRole,
|
||||||
ServiceTypeRole,
|
ServiceTypeRole,
|
||||||
|
ConfigRole,
|
||||||
DockerContainerRole,
|
DockerContainerRole,
|
||||||
|
|
||||||
IsEasySetupContainerRole,
|
IsEasySetupContainerRole,
|
||||||
|
|
@ -40,13 +42,15 @@ public:
|
||||||
QVariant data(const int index, int role) const;
|
QVariant data(const int index, int role) const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updateModel(const QMap<QString, ContainerConfig> &containerConfigs);
|
void updateModel(const QJsonArray &containers);
|
||||||
|
|
||||||
void setProcessedContainerIndex(int containerIndex);
|
void setProcessedContainerIndex(int containerIndex);
|
||||||
int getProcessedContainerIndex();
|
int getProcessedContainerIndex();
|
||||||
|
|
||||||
QString getProcessedContainerName();
|
QString getProcessedContainerName();
|
||||||
|
|
||||||
|
QJsonObject getContainerConfig(const int containerIndex);
|
||||||
|
|
||||||
bool isSupportedByCurrentPlatform(const int containerIndex);
|
bool isSupportedByCurrentPlatform(const int containerIndex);
|
||||||
bool isServiceContainer(const int containerIndex);
|
bool isServiceContainer(const int containerIndex);
|
||||||
|
|
||||||
|
|
@ -60,7 +64,7 @@ signals:
|
||||||
void containersModelUpdated();
|
void containersModelUpdated();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QMap<QString, ContainerConfig> m_containerConfigs;
|
QMap<DockerContainer, QJsonObject> m_containers;
|
||||||
|
|
||||||
int m_processedContainerIndex;
|
int m_processedContainerIndex;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,7 @@
|
||||||
|
|
||||||
#include "protocols/protocols_defs.h"
|
#include "protocols/protocols_defs.h"
|
||||||
|
|
||||||
AwgConfigModel::AwgConfigModel(QObject *parent)
|
AwgConfigModel::AwgConfigModel(QObject *parent) : QAbstractListModel(parent)
|
||||||
: QAbstractListModel(parent),
|
|
||||||
m_newAwgProtocolConfig(ProtocolProps::protoToString(Proto::Awg)),
|
|
||||||
m_oldAwgProtocolConfig(ProtocolProps::protoToString(Proto::Awg))
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -24,42 +21,46 @@ bool AwgConfigModel::setData(const QModelIndex &index, const QVariant &value, in
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Roles::SubnetAddressRole: m_newAwgProtocolConfig.serverProtocolConfig.subnetAddress = value.toString(); break;
|
case Roles::SubnetAddressRole: m_serverProtocolConfig.insert(config_key::subnet_address, value.toString()); break;
|
||||||
case Roles::PortRole: m_newAwgProtocolConfig.serverProtocolConfig.port = value.toString(); break;
|
case Roles::PortRole: m_serverProtocolConfig.insert(config_key::port, value.toString()); break;
|
||||||
|
|
||||||
case Roles::ClientMtuRole: m_newAwgProtocolConfig.clientProtocolConfig.wireGuardData.mtu = value.toString(); break;
|
case Roles::ClientMtuRole: m_clientProtocolConfig.insert(config_key::mtu, value.toString()); break;
|
||||||
case Roles::ClientJunkPacketCountRole: m_newAwgProtocolConfig.clientProtocolConfig.awgData.junkPacketCount = value.toString(); break;
|
case Roles::ClientJunkPacketCountRole: m_clientProtocolConfig.insert(config_key::junkPacketCount, value.toString()); break;
|
||||||
case Roles::ClientJunkPacketMinSizeRole:
|
case Roles::ClientJunkPacketMinSizeRole: m_clientProtocolConfig.insert(config_key::junkPacketMinSize, value.toString()); break;
|
||||||
m_newAwgProtocolConfig.clientProtocolConfig.awgData.junkPacketMinSize = value.toString();
|
case Roles::ClientJunkPacketMaxSizeRole: m_clientProtocolConfig.insert(config_key::junkPacketMaxSize, value.toString()); break;
|
||||||
break;
|
case Roles::ClientSpecialJunk1Role: m_clientProtocolConfig.insert(config_key::specialJunk1, value.toString()); break;
|
||||||
case Roles::ClientJunkPacketMaxSizeRole:
|
case Roles::ClientSpecialJunk2Role: m_clientProtocolConfig.insert(config_key::specialJunk2, value.toString()); break;
|
||||||
m_newAwgProtocolConfig.clientProtocolConfig.awgData.junkPacketMaxSize = value.toString();
|
case Roles::ClientSpecialJunk3Role: m_clientProtocolConfig.insert(config_key::specialJunk3, value.toString()); break;
|
||||||
break;
|
case Roles::ClientSpecialJunk4Role: m_clientProtocolConfig.insert(config_key::specialJunk4, value.toString()); break;
|
||||||
|
case Roles::ClientSpecialJunk5Role: m_clientProtocolConfig.insert(config_key::specialJunk5, value.toString()); break;
|
||||||
case Roles::ServerJunkPacketCountRole: m_newAwgProtocolConfig.serverProtocolConfig.awgData.junkPacketCount = value.toString(); break;
|
case Roles::ClientControlledJunk1Role: m_clientProtocolConfig.insert(config_key::controlledJunk1, value.toString()); break;
|
||||||
case Roles::ServerJunkPacketMinSizeRole:
|
case Roles::ClientControlledJunk2Role: m_clientProtocolConfig.insert(config_key::controlledJunk2, value.toString()); break;
|
||||||
m_newAwgProtocolConfig.serverProtocolConfig.awgData.junkPacketMinSize = value.toString();
|
case Roles::ClientControlledJunk3Role: m_clientProtocolConfig.insert(config_key::controlledJunk3, value.toString()); break;
|
||||||
break;
|
case Roles::ClientSpecialHandshakeTimeoutRole:
|
||||||
case Roles::ServerJunkPacketMaxSizeRole:
|
m_clientProtocolConfig.insert(config_key::specialHandshakeTimeout, value.toString());
|
||||||
m_newAwgProtocolConfig.serverProtocolConfig.awgData.junkPacketMaxSize = value.toString();
|
|
||||||
break;
|
|
||||||
case Roles::ServerInitPacketJunkSizeRole:
|
|
||||||
m_newAwgProtocolConfig.serverProtocolConfig.awgData.initPacketJunkSize = value.toString();
|
|
||||||
break;
|
break;
|
||||||
|
case Roles::ServerJunkPacketCountRole: m_serverProtocolConfig.insert(config_key::junkPacketCount, value.toString()); break;
|
||||||
|
case Roles::ServerJunkPacketMinSizeRole: m_serverProtocolConfig.insert(config_key::junkPacketMinSize, value.toString()); break;
|
||||||
|
case Roles::ServerJunkPacketMaxSizeRole: m_serverProtocolConfig.insert(config_key::junkPacketMaxSize, value.toString()); break;
|
||||||
|
case Roles::ServerInitPacketJunkSizeRole: m_serverProtocolConfig.insert(config_key::initPacketJunkSize, value.toString()); break;
|
||||||
case Roles::ServerResponsePacketJunkSizeRole:
|
case Roles::ServerResponsePacketJunkSizeRole:
|
||||||
m_newAwgProtocolConfig.serverProtocolConfig.awgData.responsePacketJunkSize = value.toString();
|
m_serverProtocolConfig.insert(config_key::responsePacketJunkSize, value.toString());
|
||||||
break;
|
|
||||||
case Roles::ServerInitPacketMagicHeaderRole:
|
|
||||||
m_newAwgProtocolConfig.serverProtocolConfig.awgData.initPacketMagicHeader = value.toString();
|
|
||||||
break;
|
break;
|
||||||
|
// case Roles::ServerCookieReplyPacketJunkSizeRole:
|
||||||
|
// m_serverProtocolConfig.insert(config_key::cookieReplyPacketJunkSize, value.toString());
|
||||||
|
// break;
|
||||||
|
// case Roles::ServerTransportPacketJunkSizeRole:
|
||||||
|
// m_serverProtocolConfig.insert(config_key::transportPacketJunkSize, value.toString());
|
||||||
|
// break;
|
||||||
|
case Roles::ServerInitPacketMagicHeaderRole: m_serverProtocolConfig.insert(config_key::initPacketMagicHeader, value.toString()); break;
|
||||||
case Roles::ServerResponsePacketMagicHeaderRole:
|
case Roles::ServerResponsePacketMagicHeaderRole:
|
||||||
m_newAwgProtocolConfig.serverProtocolConfig.awgData.responsePacketMagicHeader = value.toString();
|
m_serverProtocolConfig.insert(config_key::responsePacketMagicHeader, value.toString());
|
||||||
break;
|
break;
|
||||||
case Roles::ServerUnderloadPacketMagicHeaderRole:
|
case Roles::ServerUnderloadPacketMagicHeaderRole:
|
||||||
m_newAwgProtocolConfig.serverProtocolConfig.awgData.underloadPacketMagicHeader = value.toString();
|
m_serverProtocolConfig.insert(config_key::underloadPacketMagicHeader, value.toString());
|
||||||
break;
|
break;
|
||||||
case Roles::ServerTransportPacketMagicHeaderRole:
|
case Roles::ServerTransportPacketMagicHeaderRole:
|
||||||
m_newAwgProtocolConfig.serverProtocolConfig.awgData.transportPacketMagicHeader = value.toString();
|
m_serverProtocolConfig.insert(config_key::transportPacketMagicHeader, value.toString());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -74,42 +75,137 @@ QVariant AwgConfigModel::data(const QModelIndex &index, int role) const
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Roles::SubnetAddressRole: return m_newAwgProtocolConfig.serverProtocolConfig.subnetAddress;
|
case Roles::SubnetAddressRole: return m_serverProtocolConfig.value(config_key::subnet_address).toString();
|
||||||
case Roles::PortRole: return m_newAwgProtocolConfig.serverProtocolConfig.port;
|
case Roles::PortRole: return m_serverProtocolConfig.value(config_key::port).toString();
|
||||||
|
|
||||||
case Roles::ClientMtuRole: return m_newAwgProtocolConfig.clientProtocolConfig.wireGuardData.mtu;
|
case Roles::ClientMtuRole: return m_clientProtocolConfig.value(config_key::mtu);
|
||||||
case Roles::ClientJunkPacketCountRole: return m_newAwgProtocolConfig.clientProtocolConfig.awgData.junkPacketCount;
|
case Roles::ClientJunkPacketCountRole: return m_clientProtocolConfig.value(config_key::junkPacketCount);
|
||||||
case Roles::ClientJunkPacketMinSizeRole: return m_newAwgProtocolConfig.clientProtocolConfig.awgData.junkPacketMinSize;
|
case Roles::ClientJunkPacketMinSizeRole: return m_clientProtocolConfig.value(config_key::junkPacketMinSize);
|
||||||
case Roles::ClientJunkPacketMaxSizeRole: return m_newAwgProtocolConfig.clientProtocolConfig.awgData.junkPacketMaxSize;
|
case Roles::ClientJunkPacketMaxSizeRole: return m_clientProtocolConfig.value(config_key::junkPacketMaxSize);
|
||||||
|
case Roles::ClientSpecialJunk1Role: return m_clientProtocolConfig.value(config_key::specialJunk1);
|
||||||
|
case Roles::ClientSpecialJunk2Role: return m_clientProtocolConfig.value(config_key::specialJunk2);
|
||||||
|
case Roles::ClientSpecialJunk3Role: return m_clientProtocolConfig.value(config_key::specialJunk3);
|
||||||
|
case Roles::ClientSpecialJunk4Role: return m_clientProtocolConfig.value(config_key::specialJunk4);
|
||||||
|
case Roles::ClientSpecialJunk5Role: return m_clientProtocolConfig.value(config_key::specialJunk5);
|
||||||
|
case Roles::ClientControlledJunk1Role: return m_clientProtocolConfig.value(config_key::controlledJunk1);
|
||||||
|
case Roles::ClientControlledJunk2Role: return m_clientProtocolConfig.value(config_key::controlledJunk2);
|
||||||
|
case Roles::ClientControlledJunk3Role: return m_clientProtocolConfig.value(config_key::controlledJunk3);
|
||||||
|
case Roles::ClientSpecialHandshakeTimeoutRole: return m_clientProtocolConfig.value(config_key::specialHandshakeTimeout);
|
||||||
|
|
||||||
case Roles::ServerJunkPacketCountRole: return m_newAwgProtocolConfig.serverProtocolConfig.awgData.junkPacketCount;
|
case Roles::ServerJunkPacketCountRole: return m_serverProtocolConfig.value(config_key::junkPacketCount);
|
||||||
case Roles::ServerJunkPacketMinSizeRole: return m_newAwgProtocolConfig.serverProtocolConfig.awgData.junkPacketMinSize;
|
case Roles::ServerJunkPacketMinSizeRole: return m_serverProtocolConfig.value(config_key::junkPacketMinSize);
|
||||||
case Roles::ServerJunkPacketMaxSizeRole: return m_newAwgProtocolConfig.serverProtocolConfig.awgData.junkPacketMaxSize;
|
case Roles::ServerJunkPacketMaxSizeRole: return m_serverProtocolConfig.value(config_key::junkPacketMaxSize);
|
||||||
case Roles::ServerInitPacketJunkSizeRole: return m_newAwgProtocolConfig.serverProtocolConfig.awgData.initPacketJunkSize;
|
case Roles::ServerInitPacketJunkSizeRole: return m_serverProtocolConfig.value(config_key::initPacketJunkSize);
|
||||||
case Roles::ServerResponsePacketJunkSizeRole: return m_newAwgProtocolConfig.serverProtocolConfig.awgData.responsePacketJunkSize;
|
case Roles::ServerResponsePacketJunkSizeRole: return m_serverProtocolConfig.value(config_key::responsePacketJunkSize);
|
||||||
case Roles::ServerInitPacketMagicHeaderRole: return m_newAwgProtocolConfig.serverProtocolConfig.awgData.initPacketMagicHeader;
|
// case Roles::ServerCookieReplyPacketJunkSizeRole: return m_serverProtocolConfig.value(config_key::cookieReplyPacketJunkSize);
|
||||||
case Roles::ServerResponsePacketMagicHeaderRole: return m_newAwgProtocolConfig.serverProtocolConfig.awgData.responsePacketMagicHeader;
|
// case Roles::ServerTransportPacketJunkSizeRole: return m_serverProtocolConfig.value(config_key::transportPacketJunkSize);
|
||||||
case Roles::ServerUnderloadPacketMagicHeaderRole: return m_newAwgProtocolConfig.serverProtocolConfig.awgData.underloadPacketMagicHeader;
|
case Roles::ServerInitPacketMagicHeaderRole: return m_serverProtocolConfig.value(config_key::initPacketMagicHeader);
|
||||||
case Roles::ServerTransportPacketMagicHeaderRole: return m_newAwgProtocolConfig.serverProtocolConfig.awgData.transportPacketMagicHeader;
|
case Roles::ServerResponsePacketMagicHeaderRole: return m_serverProtocolConfig.value(config_key::responsePacketMagicHeader);
|
||||||
|
case Roles::ServerUnderloadPacketMagicHeaderRole: return m_serverProtocolConfig.value(config_key::underloadPacketMagicHeader);
|
||||||
|
case Roles::ServerTransportPacketMagicHeaderRole: return m_serverProtocolConfig.value(config_key::transportPacketMagicHeader);
|
||||||
}
|
}
|
||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AwgConfigModel::updateModel(const AwgProtocolConfig awgProtocolConfig)
|
void AwgConfigModel::updateModel(const QJsonObject &config)
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
m_newAwgProtocolConfig = awgProtocolConfig;
|
m_container = ContainerProps::containerFromString(config.value(config_key::container).toString());
|
||||||
m_oldAwgProtocolConfig = awgProtocolConfig;
|
|
||||||
|
m_fullConfig = config;
|
||||||
|
|
||||||
|
QJsonObject serverProtocolConfig = config.value(config_key::awg).toObject();
|
||||||
|
|
||||||
|
auto defaultTransportProto = ProtocolProps::transportProtoToString(ProtocolProps::defaultTransportProto(Proto::Awg), Proto::Awg);
|
||||||
|
m_serverProtocolConfig.insert(config_key::transport_proto,
|
||||||
|
serverProtocolConfig.value(config_key::transport_proto).toString(defaultTransportProto));
|
||||||
|
m_serverProtocolConfig[config_key::last_config] = serverProtocolConfig.value(config_key::last_config);
|
||||||
|
m_serverProtocolConfig[config_key::subnet_address] =
|
||||||
|
serverProtocolConfig.value(config_key::subnet_address).toString(protocols::wireguard::defaultSubnetAddress);
|
||||||
|
m_serverProtocolConfig[config_key::port] = serverProtocolConfig.value(config_key::port).toString(protocols::awg::defaultPort);
|
||||||
|
m_serverProtocolConfig[config_key::junkPacketCount] =
|
||||||
|
serverProtocolConfig.value(config_key::junkPacketCount).toString(protocols::awg::defaultJunkPacketCount);
|
||||||
|
m_serverProtocolConfig[config_key::junkPacketMinSize] =
|
||||||
|
serverProtocolConfig.value(config_key::junkPacketMinSize).toString(protocols::awg::defaultJunkPacketMinSize);
|
||||||
|
m_serverProtocolConfig[config_key::junkPacketMaxSize] =
|
||||||
|
serverProtocolConfig.value(config_key::junkPacketMaxSize).toString(protocols::awg::defaultJunkPacketMaxSize);
|
||||||
|
m_serverProtocolConfig[config_key::initPacketJunkSize] =
|
||||||
|
serverProtocolConfig.value(config_key::initPacketJunkSize).toString(protocols::awg::defaultInitPacketJunkSize);
|
||||||
|
m_serverProtocolConfig[config_key::responsePacketJunkSize] =
|
||||||
|
serverProtocolConfig.value(config_key::responsePacketJunkSize).toString(protocols::awg::defaultResponsePacketJunkSize);
|
||||||
|
// m_serverProtocolConfig[config_key::cookieReplyPacketJunkSize] =
|
||||||
|
// serverProtocolConfig.value(config_key::cookieReplyPacketJunkSize).toString(protocols::awg::defaultCookieReplyPacketJunkSize);
|
||||||
|
// m_serverProtocolConfig[config_key::transportPacketJunkSize] =
|
||||||
|
// serverProtocolConfig.value(config_key::transportPacketJunkSize).toString(protocols::awg::defaultTransportPacketJunkSize);
|
||||||
|
m_serverProtocolConfig[config_key::initPacketMagicHeader] =
|
||||||
|
serverProtocolConfig.value(config_key::initPacketMagicHeader).toString(protocols::awg::defaultInitPacketMagicHeader);
|
||||||
|
m_serverProtocolConfig[config_key::responsePacketMagicHeader] =
|
||||||
|
serverProtocolConfig.value(config_key::responsePacketMagicHeader).toString(protocols::awg::defaultResponsePacketMagicHeader);
|
||||||
|
m_serverProtocolConfig[config_key::underloadPacketMagicHeader] =
|
||||||
|
serverProtocolConfig.value(config_key::underloadPacketMagicHeader).toString(protocols::awg::defaultUnderloadPacketMagicHeader);
|
||||||
|
m_serverProtocolConfig[config_key::transportPacketMagicHeader] =
|
||||||
|
serverProtocolConfig.value(config_key::transportPacketMagicHeader).toString(protocols::awg::defaultTransportPacketMagicHeader);
|
||||||
|
|
||||||
|
auto lastConfig = m_serverProtocolConfig.value(config_key::last_config).toString();
|
||||||
|
QJsonObject clientProtocolConfig = QJsonDocument::fromJson(lastConfig.toUtf8()).object();
|
||||||
|
m_clientProtocolConfig[config_key::mtu] = clientProtocolConfig[config_key::mtu].toString(protocols::awg::defaultMtu);
|
||||||
|
m_clientProtocolConfig[config_key::junkPacketCount] =
|
||||||
|
clientProtocolConfig.value(config_key::junkPacketCount).toString(m_serverProtocolConfig[config_key::junkPacketCount].toString());
|
||||||
|
m_clientProtocolConfig[config_key::junkPacketMinSize] =
|
||||||
|
clientProtocolConfig.value(config_key::junkPacketMinSize).toString(m_serverProtocolConfig[config_key::junkPacketMinSize].toString());
|
||||||
|
m_clientProtocolConfig[config_key::junkPacketMaxSize] =
|
||||||
|
clientProtocolConfig.value(config_key::junkPacketMaxSize).toString(m_serverProtocolConfig[config_key::junkPacketMaxSize].toString());
|
||||||
|
m_clientProtocolConfig[config_key::specialJunk1] =
|
||||||
|
clientProtocolConfig.value(config_key::specialJunk1).toString(protocols::awg::defaultSpecialJunk1);
|
||||||
|
m_clientProtocolConfig[config_key::specialJunk2] =
|
||||||
|
clientProtocolConfig.value(config_key::specialJunk2).toString(protocols::awg::defaultSpecialJunk2);
|
||||||
|
m_clientProtocolConfig[config_key::specialJunk3] =
|
||||||
|
clientProtocolConfig.value(config_key::specialJunk3).toString(protocols::awg::defaultSpecialJunk3);
|
||||||
|
m_clientProtocolConfig[config_key::specialJunk4] =
|
||||||
|
clientProtocolConfig.value(config_key::specialJunk4).toString(protocols::awg::defaultSpecialJunk4);
|
||||||
|
m_clientProtocolConfig[config_key::specialJunk5] =
|
||||||
|
clientProtocolConfig.value(config_key::specialJunk5).toString(protocols::awg::defaultSpecialJunk5);
|
||||||
|
m_clientProtocolConfig[config_key::controlledJunk1] =
|
||||||
|
clientProtocolConfig.value(config_key::controlledJunk1).toString(protocols::awg::defaultControlledJunk1);
|
||||||
|
m_clientProtocolConfig[config_key::controlledJunk2] =
|
||||||
|
clientProtocolConfig.value(config_key::controlledJunk2).toString(protocols::awg::defaultControlledJunk2);
|
||||||
|
m_clientProtocolConfig[config_key::controlledJunk3] =
|
||||||
|
clientProtocolConfig.value(config_key::controlledJunk3).toString(protocols::awg::defaultControlledJunk3);
|
||||||
|
m_clientProtocolConfig[config_key::specialHandshakeTimeout] =
|
||||||
|
clientProtocolConfig.value(config_key::specialHandshakeTimeout).toString(protocols::awg::defaultSpecialHandshakeTimeout);
|
||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
QSharedPointer<ProtocolConfig> AwgConfigModel::getConfig()
|
QJsonObject AwgConfigModel::getConfig()
|
||||||
{
|
{
|
||||||
if (m_oldAwgProtocolConfig.hasEqualServerSettings(m_newAwgProtocolConfig)) {
|
const AwgConfig oldConfig(m_fullConfig.value(config_key::awg).toObject());
|
||||||
m_newAwgProtocolConfig.clearClientSettings();
|
const AwgConfig newConfig(m_serverProtocolConfig);
|
||||||
|
|
||||||
|
if (!oldConfig.hasEqualServerSettings(newConfig)) {
|
||||||
|
m_serverProtocolConfig.remove(config_key::last_config);
|
||||||
|
} else {
|
||||||
|
auto lastConfig = m_serverProtocolConfig.value(config_key::last_config).toString();
|
||||||
|
QJsonObject jsonConfig = QJsonDocument::fromJson(lastConfig.toUtf8()).object();
|
||||||
|
jsonConfig[config_key::mtu] = m_clientProtocolConfig[config_key::mtu];
|
||||||
|
jsonConfig[config_key::junkPacketCount] = m_clientProtocolConfig[config_key::junkPacketCount];
|
||||||
|
jsonConfig[config_key::junkPacketMinSize] = m_clientProtocolConfig[config_key::junkPacketMinSize];
|
||||||
|
jsonConfig[config_key::junkPacketMaxSize] = m_clientProtocolConfig[config_key::junkPacketMaxSize];
|
||||||
|
jsonConfig[config_key::specialJunk1] = m_clientProtocolConfig[config_key::specialJunk1];
|
||||||
|
jsonConfig[config_key::specialJunk2] = m_clientProtocolConfig[config_key::specialJunk2];
|
||||||
|
jsonConfig[config_key::specialJunk3] = m_clientProtocolConfig[config_key::specialJunk3];
|
||||||
|
jsonConfig[config_key::specialJunk4] = m_clientProtocolConfig[config_key::specialJunk4];
|
||||||
|
jsonConfig[config_key::specialJunk5] = m_clientProtocolConfig[config_key::specialJunk5];
|
||||||
|
jsonConfig[config_key::controlledJunk1] = m_clientProtocolConfig[config_key::controlledJunk1];
|
||||||
|
jsonConfig[config_key::controlledJunk2] = m_clientProtocolConfig[config_key::controlledJunk2];
|
||||||
|
jsonConfig[config_key::controlledJunk3] = m_clientProtocolConfig[config_key::controlledJunk3];
|
||||||
|
jsonConfig[config_key::specialHandshakeTimeout] = m_clientProtocolConfig[config_key::specialHandshakeTimeout];
|
||||||
|
|
||||||
|
m_serverProtocolConfig[config_key::last_config] = QString(QJsonDocument(jsonConfig).toJson());
|
||||||
}
|
}
|
||||||
return QSharedPointer<AwgProtocolConfig>::create(m_newAwgProtocolConfig);
|
|
||||||
|
m_fullConfig.insert(config_key::awg, m_serverProtocolConfig);
|
||||||
|
return m_fullConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AwgConfigModel::isHeadersEqual(const QString &h1, const QString &h2, const QString &h3, const QString &h4)
|
bool AwgConfigModel::isHeadersEqual(const QString &h1, const QString &h2, const QString &h3, const QString &h4)
|
||||||
|
|
@ -119,12 +215,26 @@ bool AwgConfigModel::isHeadersEqual(const QString &h1, const QString &h2, const
|
||||||
|
|
||||||
bool AwgConfigModel::isPacketSizeEqual(const int s1, const int s2)
|
bool AwgConfigModel::isPacketSizeEqual(const int s1, const int s2)
|
||||||
{
|
{
|
||||||
return (awg::messageInitiationSize + s1 == awg::messageResponseSize + s2);
|
return (AwgConstant::messageInitiationSize + s1 == AwgConstant::messageResponseSize + s2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// bool AwgConfigModel::isPacketSizeEqual(const int s1, const int s2, const int s3, const int s4)
|
||||||
|
// {
|
||||||
|
// int initSize = AwgConstant::messageInitiationSize + s1;
|
||||||
|
// int responseSize = AwgConstant::messageResponseSize + s2;
|
||||||
|
// int cookieSize = AwgConstant::messageCookieReplySize + s3;
|
||||||
|
// int transportSize = AwgConstant::messageTransportSize + s4;
|
||||||
|
|
||||||
|
// return (initSize == responseSize || initSize == cookieSize || initSize == transportSize || responseSize == cookieSize
|
||||||
|
// || responseSize == transportSize || cookieSize == transportSize);
|
||||||
|
// }
|
||||||
|
|
||||||
bool AwgConfigModel::isServerSettingsEqual()
|
bool AwgConfigModel::isServerSettingsEqual()
|
||||||
{
|
{
|
||||||
return m_oldAwgProtocolConfig.hasEqualServerSettings(m_newAwgProtocolConfig);
|
const AwgConfig oldConfig(m_fullConfig.value(config_key::awg).toObject());
|
||||||
|
const AwgConfig newConfig(m_serverProtocolConfig);
|
||||||
|
|
||||||
|
return oldConfig.hasEqualServerSettings(newConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
QHash<int, QByteArray> AwgConfigModel::roleNames() const
|
QHash<int, QByteArray> AwgConfigModel::roleNames() const
|
||||||
|
|
@ -138,12 +248,24 @@ QHash<int, QByteArray> AwgConfigModel::roleNames() const
|
||||||
roles[ClientJunkPacketCountRole] = "clientJunkPacketCount";
|
roles[ClientJunkPacketCountRole] = "clientJunkPacketCount";
|
||||||
roles[ClientJunkPacketMinSizeRole] = "clientJunkPacketMinSize";
|
roles[ClientJunkPacketMinSizeRole] = "clientJunkPacketMinSize";
|
||||||
roles[ClientJunkPacketMaxSizeRole] = "clientJunkPacketMaxSize";
|
roles[ClientJunkPacketMaxSizeRole] = "clientJunkPacketMaxSize";
|
||||||
|
roles[ClientSpecialJunk1Role] = "clientSpecialJunk1";
|
||||||
|
roles[ClientSpecialJunk2Role] = "clientSpecialJunk2";
|
||||||
|
roles[ClientSpecialJunk3Role] = "clientSpecialJunk3";
|
||||||
|
roles[ClientSpecialJunk4Role] = "clientSpecialJunk4";
|
||||||
|
roles[ClientSpecialJunk5Role] = "clientSpecialJunk5";
|
||||||
|
roles[ClientControlledJunk1Role] = "clientControlledJunk1";
|
||||||
|
roles[ClientControlledJunk2Role] = "clientControlledJunk2";
|
||||||
|
roles[ClientControlledJunk3Role] = "clientControlledJunk3";
|
||||||
|
roles[ClientSpecialHandshakeTimeoutRole] = "clientSpecialHandshakeTimeout";
|
||||||
|
|
||||||
roles[ServerJunkPacketCountRole] = "serverJunkPacketCount";
|
roles[ServerJunkPacketCountRole] = "serverJunkPacketCount";
|
||||||
roles[ServerJunkPacketMinSizeRole] = "serverJunkPacketMinSize";
|
roles[ServerJunkPacketMinSizeRole] = "serverJunkPacketMinSize";
|
||||||
roles[ServerJunkPacketMaxSizeRole] = "serverJunkPacketMaxSize";
|
roles[ServerJunkPacketMaxSizeRole] = "serverJunkPacketMaxSize";
|
||||||
roles[ServerInitPacketJunkSizeRole] = "serverInitPacketJunkSize";
|
roles[ServerInitPacketJunkSizeRole] = "serverInitPacketJunkSize";
|
||||||
roles[ServerResponsePacketJunkSizeRole] = "serverResponsePacketJunkSize";
|
roles[ServerResponsePacketJunkSizeRole] = "serverResponsePacketJunkSize";
|
||||||
|
roles[ServerCookieReplyPacketJunkSizeRole] = "serverCookieReplyPacketJunkSize";
|
||||||
|
roles[ServerTransportPacketJunkSizeRole] = "serverTransportPacketJunkSize";
|
||||||
|
|
||||||
roles[ServerInitPacketMagicHeaderRole] = "serverInitPacketMagicHeader";
|
roles[ServerInitPacketMagicHeaderRole] = "serverInitPacketMagicHeader";
|
||||||
roles[ServerResponsePacketMagicHeaderRole] = "serverResponsePacketMagicHeader";
|
roles[ServerResponsePacketMagicHeaderRole] = "serverResponsePacketMagicHeader";
|
||||||
roles[ServerUnderloadPacketMagicHeaderRole] = "serverUnderloadPacketMagicHeader";
|
roles[ServerUnderloadPacketMagicHeaderRole] = "serverUnderloadPacketMagicHeader";
|
||||||
|
|
@ -151,3 +273,74 @@ QHash<int, QByteArray> AwgConfigModel::roleNames() const
|
||||||
|
|
||||||
return roles;
|
return roles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AwgConfig::AwgConfig(const QJsonObject &serverProtocolConfig)
|
||||||
|
{
|
||||||
|
auto lastConfig = serverProtocolConfig.value(config_key::last_config).toString();
|
||||||
|
QJsonObject clientProtocolConfig = QJsonDocument::fromJson(lastConfig.toUtf8()).object();
|
||||||
|
clientMtu = clientProtocolConfig[config_key::mtu].toString(protocols::awg::defaultMtu);
|
||||||
|
clientJunkPacketCount = clientProtocolConfig.value(config_key::junkPacketCount).toString(protocols::awg::defaultJunkPacketCount);
|
||||||
|
clientJunkPacketMinSize = clientProtocolConfig.value(config_key::junkPacketMinSize).toString(protocols::awg::defaultJunkPacketMinSize);
|
||||||
|
clientJunkPacketMaxSize = clientProtocolConfig.value(config_key::junkPacketMaxSize).toString(protocols::awg::defaultJunkPacketMaxSize);
|
||||||
|
clientSpecialJunk1 = clientProtocolConfig.value(config_key::specialJunk1).toString(protocols::awg::defaultSpecialJunk1);
|
||||||
|
clientSpecialJunk2 = clientProtocolConfig.value(config_key::specialJunk2).toString(protocols::awg::defaultSpecialJunk2);
|
||||||
|
clientSpecialJunk3 = clientProtocolConfig.value(config_key::specialJunk3).toString(protocols::awg::defaultSpecialJunk3);
|
||||||
|
clientSpecialJunk4 = clientProtocolConfig.value(config_key::specialJunk4).toString(protocols::awg::defaultSpecialJunk4);
|
||||||
|
clientSpecialJunk5 = clientProtocolConfig.value(config_key::specialJunk5).toString(protocols::awg::defaultSpecialJunk5);
|
||||||
|
clientControlledJunk1 = clientProtocolConfig.value(config_key::controlledJunk1).toString(protocols::awg::defaultControlledJunk1);
|
||||||
|
clientControlledJunk2 = clientProtocolConfig.value(config_key::controlledJunk2).toString(protocols::awg::defaultControlledJunk2);
|
||||||
|
clientControlledJunk3 = clientProtocolConfig.value(config_key::controlledJunk3).toString(protocols::awg::defaultControlledJunk3);
|
||||||
|
clientSpecialHandshakeTimeout =
|
||||||
|
clientProtocolConfig.value(config_key::specialHandshakeTimeout).toString(protocols::awg::defaultSpecialHandshakeTimeout);
|
||||||
|
|
||||||
|
subnetAddress = serverProtocolConfig.value(config_key::subnet_address).toString(protocols::wireguard::defaultSubnetAddress);
|
||||||
|
port = serverProtocolConfig.value(config_key::port).toString(protocols::awg::defaultPort);
|
||||||
|
serverJunkPacketCount = serverProtocolConfig.value(config_key::junkPacketCount).toString(protocols::awg::defaultJunkPacketCount);
|
||||||
|
serverJunkPacketMinSize = serverProtocolConfig.value(config_key::junkPacketMinSize).toString(protocols::awg::defaultJunkPacketMinSize);
|
||||||
|
serverJunkPacketMaxSize = serverProtocolConfig.value(config_key::junkPacketMaxSize).toString(protocols::awg::defaultJunkPacketMaxSize);
|
||||||
|
serverInitPacketJunkSize = serverProtocolConfig.value(config_key::initPacketJunkSize).toString(protocols::awg::defaultInitPacketJunkSize);
|
||||||
|
serverResponsePacketJunkSize =
|
||||||
|
serverProtocolConfig.value(config_key::responsePacketJunkSize).toString(protocols::awg::defaultResponsePacketJunkSize);
|
||||||
|
// serverCookieReplyPacketJunkSize =
|
||||||
|
// serverProtocolConfig.value(config_key::cookieReplyPacketJunkSize).toString(protocols::awg::defaultCookieReplyPacketJunkSize);
|
||||||
|
// serverTransportPacketJunkSize =
|
||||||
|
// serverProtocolConfig.value(config_key::transportPacketJunkSize).toString(protocols::awg::defaultTransportPacketJunkSize);
|
||||||
|
serverInitPacketMagicHeader =
|
||||||
|
serverProtocolConfig.value(config_key::initPacketMagicHeader).toString(protocols::awg::defaultInitPacketMagicHeader);
|
||||||
|
serverResponsePacketMagicHeader =
|
||||||
|
serverProtocolConfig.value(config_key::responsePacketMagicHeader).toString(protocols::awg::defaultResponsePacketMagicHeader);
|
||||||
|
serverUnderloadPacketMagicHeader =
|
||||||
|
serverProtocolConfig.value(config_key::underloadPacketMagicHeader).toString(protocols::awg::defaultUnderloadPacketMagicHeader);
|
||||||
|
serverTransportPacketMagicHeader =
|
||||||
|
serverProtocolConfig.value(config_key::transportPacketMagicHeader).toString(protocols::awg::defaultTransportPacketMagicHeader);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AwgConfig::hasEqualServerSettings(const AwgConfig &other) const
|
||||||
|
{
|
||||||
|
if (subnetAddress != other.subnetAddress || port != other.port || serverJunkPacketCount != other.serverJunkPacketCount
|
||||||
|
|| serverJunkPacketMinSize != other.serverJunkPacketMinSize || serverJunkPacketMaxSize != other.serverJunkPacketMaxSize
|
||||||
|
|| serverInitPacketJunkSize != other.serverInitPacketJunkSize || serverResponsePacketJunkSize != other.serverResponsePacketJunkSize
|
||||||
|
// || serverCookieReplyPacketJunkSize != other.serverCookieReplyPacketJunkSize
|
||||||
|
// || serverTransportPacketJunkSize != other.serverTransportPacketJunkSize
|
||||||
|
|| serverInitPacketMagicHeader != other.serverInitPacketMagicHeader
|
||||||
|
|| serverResponsePacketMagicHeader != other.serverResponsePacketMagicHeader
|
||||||
|
|| serverUnderloadPacketMagicHeader != other.serverUnderloadPacketMagicHeader
|
||||||
|
|| serverTransportPacketMagicHeader != other.serverTransportPacketMagicHeader) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AwgConfig::hasEqualClientSettings(const AwgConfig &other) const
|
||||||
|
{
|
||||||
|
if (clientMtu != other.clientMtu || clientJunkPacketCount != other.clientJunkPacketCount
|
||||||
|
|| clientJunkPacketMinSize != other.clientJunkPacketMinSize || clientJunkPacketMaxSize != other.clientJunkPacketMaxSize
|
||||||
|
|| clientSpecialJunk1 != other.clientSpecialJunk1 || clientSpecialJunk2 != other.clientSpecialJunk2
|
||||||
|
|| clientSpecialJunk3 != other.clientSpecialJunk3 || clientSpecialJunk4 != other.clientSpecialJunk4
|
||||||
|
|| clientSpecialJunk5 != other.clientSpecialJunk5 || clientControlledJunk1 != other.clientControlledJunk1
|
||||||
|
|| clientControlledJunk2 != other.clientControlledJunk2 || clientControlledJunk3 != other.clientControlledJunk3
|
||||||
|
|| clientSpecialHandshakeTimeout != other.clientSpecialHandshakeTimeout) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,51 @@
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
|
|
||||||
#include "containers/containers_defs.h"
|
#include "containers/containers_defs.h"
|
||||||
#include "core/models/protocols/awgProtocolConfig.h"
|
|
||||||
|
namespace AwgConstant
|
||||||
|
{
|
||||||
|
const int messageInitiationSize = 148;
|
||||||
|
const int messageResponseSize = 92;
|
||||||
|
const int messageCookieReplySize = 64;
|
||||||
|
const int messageTransportSize = 32;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct AwgConfig
|
||||||
|
{
|
||||||
|
AwgConfig(const QJsonObject &jsonConfig);
|
||||||
|
|
||||||
|
QString subnetAddress;
|
||||||
|
QString port;
|
||||||
|
|
||||||
|
QString clientMtu;
|
||||||
|
QString clientJunkPacketCount;
|
||||||
|
QString clientJunkPacketMinSize;
|
||||||
|
QString clientJunkPacketMaxSize;
|
||||||
|
QString clientSpecialJunk1;
|
||||||
|
QString clientSpecialJunk2;
|
||||||
|
QString clientSpecialJunk3;
|
||||||
|
QString clientSpecialJunk4;
|
||||||
|
QString clientSpecialJunk5;
|
||||||
|
QString clientControlledJunk1;
|
||||||
|
QString clientControlledJunk2;
|
||||||
|
QString clientControlledJunk3;
|
||||||
|
QString clientSpecialHandshakeTimeout;
|
||||||
|
|
||||||
|
QString serverJunkPacketCount;
|
||||||
|
QString serverJunkPacketMinSize;
|
||||||
|
QString serverJunkPacketMaxSize;
|
||||||
|
QString serverInitPacketJunkSize;
|
||||||
|
QString serverResponsePacketJunkSize;
|
||||||
|
QString serverCookieReplyPacketJunkSize;
|
||||||
|
QString serverTransportPacketJunkSize;
|
||||||
|
QString serverInitPacketMagicHeader;
|
||||||
|
QString serverResponsePacketMagicHeader;
|
||||||
|
QString serverUnderloadPacketMagicHeader;
|
||||||
|
QString serverTransportPacketMagicHeader;
|
||||||
|
|
||||||
|
bool hasEqualServerSettings(const AwgConfig &other) const;
|
||||||
|
bool hasEqualClientSettings(const AwgConfig &other) const;
|
||||||
|
};
|
||||||
|
|
||||||
class AwgConfigModel : public QAbstractListModel
|
class AwgConfigModel : public QAbstractListModel
|
||||||
{
|
{
|
||||||
|
|
@ -20,16 +64,28 @@ public:
|
||||||
ClientJunkPacketCountRole,
|
ClientJunkPacketCountRole,
|
||||||
ClientJunkPacketMinSizeRole,
|
ClientJunkPacketMinSizeRole,
|
||||||
ClientJunkPacketMaxSizeRole,
|
ClientJunkPacketMaxSizeRole,
|
||||||
|
ClientSpecialJunk1Role,
|
||||||
|
ClientSpecialJunk2Role,
|
||||||
|
ClientSpecialJunk3Role,
|
||||||
|
ClientSpecialJunk4Role,
|
||||||
|
ClientSpecialJunk5Role,
|
||||||
|
ClientControlledJunk1Role,
|
||||||
|
ClientControlledJunk2Role,
|
||||||
|
ClientControlledJunk3Role,
|
||||||
|
ClientSpecialHandshakeTimeoutRole,
|
||||||
|
|
||||||
ServerJunkPacketCountRole,
|
ServerJunkPacketCountRole,
|
||||||
ServerJunkPacketMinSizeRole,
|
ServerJunkPacketMinSizeRole,
|
||||||
ServerJunkPacketMaxSizeRole,
|
ServerJunkPacketMaxSizeRole,
|
||||||
ServerInitPacketJunkSizeRole,
|
ServerInitPacketJunkSizeRole,
|
||||||
ServerResponsePacketJunkSizeRole,
|
ServerResponsePacketJunkSizeRole,
|
||||||
|
ServerCookieReplyPacketJunkSizeRole,
|
||||||
|
ServerTransportPacketJunkSizeRole,
|
||||||
|
|
||||||
ServerInitPacketMagicHeaderRole,
|
ServerInitPacketMagicHeaderRole,
|
||||||
ServerResponsePacketMagicHeaderRole,
|
ServerResponsePacketMagicHeaderRole,
|
||||||
ServerUnderloadPacketMagicHeaderRole,
|
ServerUnderloadPacketMagicHeaderRole,
|
||||||
ServerTransportPacketMagicHeaderRole
|
ServerTransportPacketMagicHeaderRole,
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit AwgConfigModel(QObject *parent = nullptr);
|
explicit AwgConfigModel(QObject *parent = nullptr);
|
||||||
|
|
@ -40,11 +96,11 @@ public:
|
||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updateModel(const AwgProtocolConfig awgProtocolConfig);
|
void updateModel(const QJsonObject &config);
|
||||||
QSharedPointer<ProtocolConfig> getConfig();
|
QJsonObject getConfig();
|
||||||
|
|
||||||
bool isHeadersEqual(const QString &h1, const QString &h2, const QString &h3, const QString &h4);
|
bool isHeadersEqual(const QString &h1, const QString &h2, const QString &h3, const QString &h4);
|
||||||
bool isPacketSizeEqual(const int s1, const int s2);
|
bool isPacketSizeEqual(const int s1, const int s2/*, const int s3, const int s4*/);
|
||||||
|
|
||||||
bool isServerSettingsEqual();
|
bool isServerSettingsEqual();
|
||||||
|
|
||||||
|
|
@ -52,8 +108,10 @@ protected:
|
||||||
QHash<int, QByteArray> roleNames() const override;
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AwgProtocolConfig m_newAwgProtocolConfig;
|
DockerContainer m_container;
|
||||||
AwgProtocolConfig m_oldAwgProtocolConfig;
|
QJsonObject m_serverProtocolConfig;
|
||||||
|
QJsonObject m_clientProtocolConfig;
|
||||||
|
QJsonObject m_fullConfig;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // AWGCONFIGMODEL_H
|
#endif // AWGCONFIGMODEL_H
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,7 @@
|
||||||
|
|
||||||
#include "protocols/protocols_defs.h"
|
#include "protocols/protocols_defs.h"
|
||||||
|
|
||||||
CloakConfigModel::CloakConfigModel(QObject *parent)
|
CloakConfigModel::CloakConfigModel(QObject *parent) : QAbstractListModel(parent)
|
||||||
: QAbstractListModel(parent),
|
|
||||||
m_newCloakProtocolConfig(QJsonObject(), ProtocolProps::protoToString(Proto::Cloak)),
|
|
||||||
m_oldCloakProtocolConfig(QJsonObject(), ProtocolProps::protoToString(Proto::Cloak))
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -22,9 +19,9 @@ bool CloakConfigModel::setData(const QModelIndex &index, const QVariant &value,
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Roles::PortRole: m_newCloakProtocolConfig.serverProtocolConfig.port = value.toString(); break;
|
case Roles::PortRole: m_protocolConfig.insert(config_key::port, value.toString()); break;
|
||||||
case Roles::CipherRole: m_newCloakProtocolConfig.serverProtocolConfig.cipher = value.toString(); break;
|
case Roles::CipherRole: m_protocolConfig.insert(config_key::cipher, value.toString()); break;
|
||||||
case Roles::SiteRole: m_newCloakProtocolConfig.serverProtocolConfig.site = value.toString(); break;
|
case Roles::SiteRole: m_protocolConfig.insert(config_key::site, value.toString()); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
emit dataChanged(index, index, QList { role });
|
emit dataChanged(index, index, QList { role });
|
||||||
|
|
@ -38,33 +35,35 @@ QVariant CloakConfigModel::data(const QModelIndex &index, int role) const
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Roles::PortRole: return m_newCloakProtocolConfig.serverProtocolConfig.port;
|
case Roles::PortRole: return m_protocolConfig.value(config_key::port).toString(protocols::cloak::defaultPort);
|
||||||
case Roles::CipherRole: return m_newCloakProtocolConfig.serverProtocolConfig.cipher;
|
case Roles::CipherRole: return m_protocolConfig.value(config_key::cipher).toString(protocols::cloak::defaultCipher);
|
||||||
case Roles::SiteRole: return m_newCloakProtocolConfig.serverProtocolConfig.site;
|
case Roles::SiteRole: return m_protocolConfig.value(config_key::site).toString(protocols::cloak::defaultRedirSite);
|
||||||
}
|
}
|
||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CloakConfigModel::updateModel(const CloakProtocolConfig cloakProtocolConfig)
|
void CloakConfigModel::updateModel(const QJsonObject &config)
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
m_newCloakProtocolConfig = cloakProtocolConfig;
|
m_container = ContainerProps::containerFromString(config.value(config_key::container).toString());
|
||||||
m_oldCloakProtocolConfig = cloakProtocolConfig;
|
|
||||||
|
m_fullConfig = config;
|
||||||
|
QJsonObject protocolConfig = config.value(config_key::cloak).toObject();
|
||||||
|
|
||||||
|
auto defaultTransportProto = ProtocolProps::transportProtoToString(ProtocolProps::defaultTransportProto(Proto::Cloak), Proto::Cloak);
|
||||||
|
m_protocolConfig.insert(config_key::transport_proto, protocolConfig.value(config_key::transport_proto).toString(defaultTransportProto));
|
||||||
|
m_protocolConfig.insert(config_key::cipher, protocolConfig.value(config_key::cipher).toString(protocols::cloak::defaultCipher));
|
||||||
|
m_protocolConfig.insert(config_key::port, protocolConfig.value(config_key::port).toString(protocols::cloak::defaultPort));
|
||||||
|
m_protocolConfig.insert(config_key::site, protocolConfig.value(config_key::site).toString(protocols::cloak::defaultRedirSite));
|
||||||
|
|
||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
QSharedPointer<ProtocolConfig> CloakConfigModel::getConfig()
|
QJsonObject CloakConfigModel::getConfig()
|
||||||
{
|
{
|
||||||
if (m_oldCloakProtocolConfig.hasEqualServerSettings(m_newCloakProtocolConfig)) {
|
m_fullConfig.insert(config_key::cloak, m_protocolConfig);
|
||||||
m_newCloakProtocolConfig.clearClientSettings();
|
return m_fullConfig;
|
||||||
}
|
|
||||||
return QSharedPointer<CloakProtocolConfig>::create(m_newCloakProtocolConfig);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CloakConfigModel::isServerSettingsEqual()
|
|
||||||
{
|
|
||||||
return m_oldCloakProtocolConfig.hasEqualServerSettings(m_newCloakProtocolConfig);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QHash<int, QByteArray> CloakConfigModel::roleNames() const
|
QHash<int, QByteArray> CloakConfigModel::roleNames() const
|
||||||
|
|
@ -77,4 +76,3 @@ QHash<int, QByteArray> CloakConfigModel::roleNames() const
|
||||||
|
|
||||||
return roles;
|
return roles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
|
|
||||||
#include "containers/containers_defs.h"
|
#include "containers/containers_defs.h"
|
||||||
#include "core/models/protocols/cloakProtocolConfig.h"
|
|
||||||
|
|
||||||
class CloakConfigModel : public QAbstractListModel
|
class CloakConfigModel : public QAbstractListModel
|
||||||
{
|
{
|
||||||
|
|
@ -26,17 +25,16 @@ public:
|
||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updateModel(const CloakProtocolConfig cloakProtocolConfig);
|
void updateModel(const QJsonObject &config);
|
||||||
QSharedPointer<ProtocolConfig> getConfig();
|
QJsonObject getConfig();
|
||||||
|
|
||||||
bool isServerSettingsEqual();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QHash<int, QByteArray> roleNames() const override;
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CloakProtocolConfig m_newCloakProtocolConfig;
|
DockerContainer m_container;
|
||||||
CloakProtocolConfig m_oldCloakProtocolConfig;
|
QJsonObject m_protocolConfig;
|
||||||
|
QJsonObject m_fullConfig;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CLOAKCONFIGMODEL_H
|
#endif // CLOAKCONFIGMODEL_H
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,7 @@
|
||||||
|
|
||||||
#include "protocols/protocols_defs.h"
|
#include "protocols/protocols_defs.h"
|
||||||
|
|
||||||
OpenVpnConfigModel::OpenVpnConfigModel(QObject *parent)
|
OpenVpnConfigModel::OpenVpnConfigModel(QObject *parent) : QAbstractListModel(parent)
|
||||||
: QAbstractListModel(parent),
|
|
||||||
m_newOpenVpnProtocolConfig(QJsonObject(), ProtocolProps::protoToString(Proto::OpenVpn)),
|
|
||||||
m_oldOpenVpnProtocolConfig(QJsonObject(), ProtocolProps::protoToString(Proto::OpenVpn))
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -22,16 +19,16 @@ bool OpenVpnConfigModel::setData(const QModelIndex &index, const QVariant &value
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Roles::SubnetAddressRole: m_newOpenVpnProtocolConfig.serverProtocolConfig.subnetAddress = value.toString(); break;
|
case Roles::SubnetAddressRole: m_protocolConfig.insert(amnezia::config_key::subnet_address, value.toString()); break;
|
||||||
case Roles::TransportProtoRole: m_newOpenVpnProtocolConfig.serverProtocolConfig.transportProto = value.toString(); break;
|
case Roles::TransportProtoRole: m_protocolConfig.insert(config_key::transport_proto, value.toString()); break;
|
||||||
case Roles::PortRole: m_newOpenVpnProtocolConfig.serverProtocolConfig.port = value.toString(); break;
|
case Roles::PortRole: m_protocolConfig.insert(config_key::port, value.toString()); break;
|
||||||
case Roles::AutoNegotiateEncryprionRole: m_newOpenVpnProtocolConfig.serverProtocolConfig.ncpDisable = !value.toBool(); break;
|
case Roles::AutoNegotiateEncryprionRole: m_protocolConfig.insert(config_key::ncp_disable, !value.toBool()); break;
|
||||||
case Roles::HashRole: m_newOpenVpnProtocolConfig.serverProtocolConfig.hash = value.toString(); break;
|
case Roles::HashRole: m_protocolConfig.insert(config_key::hash, value.toString()); break;
|
||||||
case Roles::CipherRole: m_newOpenVpnProtocolConfig.serverProtocolConfig.cipher = value.toString(); break;
|
case Roles::CipherRole: m_protocolConfig.insert(config_key::cipher, value.toString()); break;
|
||||||
case Roles::TlsAuthRole: m_newOpenVpnProtocolConfig.serverProtocolConfig.tlsAuth = value.toBool(); break;
|
case Roles::TlsAuthRole: m_protocolConfig.insert(config_key::tls_auth, value.toBool()); break;
|
||||||
case Roles::BlockDnsRole: m_newOpenVpnProtocolConfig.serverProtocolConfig.blockOutsideDns = value.toBool(); break;
|
case Roles::BlockDnsRole: m_protocolConfig.insert(config_key::block_outside_dns, value.toBool()); break;
|
||||||
case Roles::AdditionalClientCommandsRole: m_newOpenVpnProtocolConfig.serverProtocolConfig.additionalClientConfig = value.toString(); break;
|
case Roles::AdditionalClientCommandsRole: m_protocolConfig.insert(config_key::additional_client_config, value.toString()); break;
|
||||||
case Roles::AdditionalServerCommandsRole: m_newOpenVpnProtocolConfig.serverProtocolConfig.additionalServerConfig = value.toString(); break;
|
case Roles::AdditionalServerCommandsRole: m_protocolConfig.insert(config_key::additional_server_config, value.toString()); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
emit dataChanged(index, index, QList { role });
|
emit dataChanged(index, index, QList { role });
|
||||||
|
|
@ -45,42 +42,72 @@ QVariant OpenVpnConfigModel::data(const QModelIndex &index, int role) const
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Roles::SubnetAddressRole: return m_newOpenVpnProtocolConfig.serverProtocolConfig.subnetAddress;
|
case Roles::SubnetAddressRole:
|
||||||
case Roles::TransportProtoRole: return m_newOpenVpnProtocolConfig.serverProtocolConfig.transportProto;
|
return m_protocolConfig.value(amnezia::config_key::subnet_address).toString(amnezia::protocols::openvpn::defaultSubnetAddress);
|
||||||
case Roles::PortRole: return m_newOpenVpnProtocolConfig.serverProtocolConfig.port;
|
case Roles::TransportProtoRole:
|
||||||
case Roles::AutoNegotiateEncryprionRole: return !m_newOpenVpnProtocolConfig.serverProtocolConfig.ncpDisable;
|
return m_protocolConfig.value(config_key::transport_proto).toString(protocols::openvpn::defaultTransportProto);
|
||||||
case Roles::HashRole: return m_newOpenVpnProtocolConfig.serverProtocolConfig.hash;
|
case Roles::PortRole: return m_protocolConfig.value(config_key::port).toString(protocols::openvpn::defaultPort);
|
||||||
case Roles::CipherRole: return m_newOpenVpnProtocolConfig.serverProtocolConfig.cipher;
|
case Roles::AutoNegotiateEncryprionRole:
|
||||||
case Roles::TlsAuthRole: return m_newOpenVpnProtocolConfig.serverProtocolConfig.tlsAuth;
|
return !m_protocolConfig.value(config_key::ncp_disable).toBool(protocols::openvpn::defaultNcpDisable);
|
||||||
case Roles::BlockDnsRole: return m_newOpenVpnProtocolConfig.serverProtocolConfig.blockOutsideDns;
|
case Roles::HashRole: return m_protocolConfig.value(config_key::hash).toString(protocols::openvpn::defaultHash);
|
||||||
case Roles::AdditionalClientCommandsRole: return m_newOpenVpnProtocolConfig.serverProtocolConfig.additionalClientConfig;
|
case Roles::CipherRole: return m_protocolConfig.value(config_key::cipher).toString(protocols::openvpn::defaultCipher);
|
||||||
case Roles::AdditionalServerCommandsRole: return m_newOpenVpnProtocolConfig.serverProtocolConfig.additionalServerConfig;
|
case Roles::TlsAuthRole: return m_protocolConfig.value(config_key::tls_auth).toBool(protocols::openvpn::defaultTlsAuth);
|
||||||
case Roles::IsPortEditable: return true; // TODO: implement container check if needed
|
case Roles::BlockDnsRole:
|
||||||
case Roles::IsTransportProtoEditable: return true; // TODO: implement container check if needed
|
return m_protocolConfig.value(config_key::block_outside_dns).toBool(protocols::openvpn::defaultBlockOutsideDns);
|
||||||
case Roles::HasRemoveButton: return true; // TODO: implement container check if needed
|
case Roles::AdditionalClientCommandsRole:
|
||||||
|
return m_protocolConfig.value(config_key::additional_client_config).toString(protocols::openvpn::defaultAdditionalClientConfig);
|
||||||
|
case Roles::AdditionalServerCommandsRole:
|
||||||
|
return m_protocolConfig.value(config_key::additional_server_config).toString(protocols::openvpn::defaultAdditionalServerConfig);
|
||||||
|
case Roles::IsPortEditable: return m_container == DockerContainer::OpenVpn ? true : false;
|
||||||
|
case Roles::IsTransportProtoEditable: return m_container == DockerContainer::OpenVpn ? true : false;
|
||||||
|
case Roles::HasRemoveButton: return m_container == DockerContainer::OpenVpn ? true : false;
|
||||||
}
|
}
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenVpnConfigModel::updateModel(const OpenVpnProtocolConfig openVpnProtocolConfig)
|
void OpenVpnConfigModel::updateModel(const QJsonObject &config)
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
m_newOpenVpnProtocolConfig = openVpnProtocolConfig;
|
m_container = ContainerProps::containerFromString(config.value(config_key::container).toString());
|
||||||
m_oldOpenVpnProtocolConfig = openVpnProtocolConfig;
|
|
||||||
|
m_fullConfig = config;
|
||||||
|
QJsonObject protocolConfig = config.value(config_key::openvpn).toObject();
|
||||||
|
|
||||||
|
m_protocolConfig.insert(
|
||||||
|
config_key::subnet_address,
|
||||||
|
protocolConfig.value(amnezia::config_key::subnet_address).toString(amnezia::protocols::openvpn::defaultSubnetAddress));
|
||||||
|
|
||||||
|
QString transportProto;
|
||||||
|
if (m_container == DockerContainer::OpenVpn) {
|
||||||
|
transportProto = protocolConfig.value(config_key::transport_proto).toString(protocols::openvpn::defaultTransportProto);
|
||||||
|
} else {
|
||||||
|
transportProto = "tcp";
|
||||||
|
}
|
||||||
|
|
||||||
|
m_protocolConfig.insert(config_key::transport_proto, transportProto);
|
||||||
|
|
||||||
|
m_protocolConfig.insert(config_key::ncp_disable,
|
||||||
|
protocolConfig.value(config_key::ncp_disable).toBool(protocols::openvpn::defaultNcpDisable));
|
||||||
|
m_protocolConfig.insert(config_key::cipher, protocolConfig.value(config_key::cipher).toString(protocols::openvpn::defaultCipher));
|
||||||
|
m_protocolConfig.insert(config_key::hash, protocolConfig.value(config_key::hash).toString(protocols::openvpn::defaultHash));
|
||||||
|
m_protocolConfig.insert(config_key::block_outside_dns,
|
||||||
|
protocolConfig.value(config_key::block_outside_dns).toBool(protocols::openvpn::defaultBlockOutsideDns));
|
||||||
|
m_protocolConfig.insert(config_key::port, protocolConfig.value(config_key::port).toString(protocols::openvpn::defaultPort));
|
||||||
|
m_protocolConfig.insert(config_key::tls_auth, protocolConfig.value(config_key::tls_auth).toBool(protocols::openvpn::defaultTlsAuth));
|
||||||
|
m_protocolConfig.insert(
|
||||||
|
config_key::additional_client_config,
|
||||||
|
protocolConfig.value(config_key::additional_client_config).toString(protocols::openvpn::defaultAdditionalClientConfig));
|
||||||
|
m_protocolConfig.insert(
|
||||||
|
config_key::additional_server_config,
|
||||||
|
protocolConfig.value(config_key::additional_server_config).toString(protocols::openvpn::defaultAdditionalServerConfig));
|
||||||
|
|
||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
QSharedPointer<ProtocolConfig> OpenVpnConfigModel::getConfig()
|
QJsonObject OpenVpnConfigModel::getConfig()
|
||||||
{
|
{
|
||||||
if (m_oldOpenVpnProtocolConfig.hasEqualServerSettings(m_newOpenVpnProtocolConfig)) {
|
m_fullConfig.insert(config_key::openvpn, m_protocolConfig);
|
||||||
m_newOpenVpnProtocolConfig.clearClientSettings();
|
return m_fullConfig;
|
||||||
}
|
|
||||||
return QSharedPointer<OpenVpnProtocolConfig>::create(m_newOpenVpnProtocolConfig);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool OpenVpnConfigModel::isServerSettingsEqual()
|
|
||||||
{
|
|
||||||
return m_oldOpenVpnProtocolConfig.hasEqualServerSettings(m_newOpenVpnProtocolConfig);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QHash<int, QByteArray> OpenVpnConfigModel::roleNames() const
|
QHash<int, QByteArray> OpenVpnConfigModel::roleNames() const
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
|
|
||||||
#include "containers/containers_defs.h"
|
#include "containers/containers_defs.h"
|
||||||
#include "core/models/protocols/openvpnProtocolConfig.h"
|
|
||||||
|
|
||||||
class OpenVpnConfigModel : public QAbstractListModel
|
class OpenVpnConfigModel : public QAbstractListModel
|
||||||
{
|
{
|
||||||
|
|
@ -38,17 +37,16 @@ public:
|
||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updateModel(const OpenVpnProtocolConfig openVpnProtocolConfig);
|
void updateModel(const QJsonObject &config);
|
||||||
QSharedPointer<ProtocolConfig> getConfig();
|
QJsonObject getConfig();
|
||||||
|
|
||||||
bool isServerSettingsEqual();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QHash<int, QByteArray> roleNames() const override;
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
OpenVpnProtocolConfig m_newOpenVpnProtocolConfig;
|
DockerContainer m_container;
|
||||||
OpenVpnProtocolConfig m_oldOpenVpnProtocolConfig;
|
QJsonObject m_protocolConfig;
|
||||||
|
QJsonObject m_fullConfig;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // OPENVPNCONFIGMODEL_H
|
#endif // OPENVPNCONFIGMODEL_H
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,7 @@
|
||||||
|
|
||||||
#include "protocols/protocols_defs.h"
|
#include "protocols/protocols_defs.h"
|
||||||
|
|
||||||
ShadowSocksConfigModel::ShadowSocksConfigModel(QObject *parent)
|
ShadowSocksConfigModel::ShadowSocksConfigModel(QObject *parent) : QAbstractListModel(parent)
|
||||||
: QAbstractListModel(parent),
|
|
||||||
m_newShadowsocksProtocolConfig(QJsonObject(), ProtocolProps::protoToString(Proto::ShadowSocks)),
|
|
||||||
m_oldShadowsocksProtocolConfig(QJsonObject(), ProtocolProps::protoToString(Proto::ShadowSocks))
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -22,8 +19,8 @@ bool ShadowSocksConfigModel::setData(const QModelIndex &index, const QVariant &v
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Roles::PortRole: m_newShadowsocksProtocolConfig.serverProtocolConfig.port = value.toString(); break;
|
case Roles::PortRole: m_protocolConfig.insert(config_key::port, value.toString()); break;
|
||||||
case Roles::CipherRole: m_newShadowsocksProtocolConfig.serverProtocolConfig.cipher = value.toString(); break;
|
case Roles::CipherRole: m_protocolConfig.insert(config_key::cipher, value.toString()); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
emit dataChanged(index, index, QList { role });
|
emit dataChanged(index, index, QList { role });
|
||||||
|
|
@ -37,34 +34,36 @@ QVariant ShadowSocksConfigModel::data(const QModelIndex &index, int role) const
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Roles::PortRole: return m_newShadowsocksProtocolConfig.serverProtocolConfig.port;
|
case Roles::PortRole: return m_protocolConfig.value(config_key::port).toString(protocols::shadowsocks::defaultPort);
|
||||||
case Roles::CipherRole: return m_newShadowsocksProtocolConfig.serverProtocolConfig.cipher;
|
case Roles::CipherRole: return m_protocolConfig.value(config_key::cipher).toString(protocols::shadowsocks::defaultCipher);
|
||||||
case Roles::IsPortEditableRole: return true; // TODO: implement container check if needed
|
case Roles::IsPortEditableRole: return m_container == DockerContainer::ShadowSocks ? true : false;
|
||||||
case Roles::IsCipherEditableRole: return true; // TODO: implement container check if needed
|
case Roles::IsCipherEditableRole: return m_container == DockerContainer::ShadowSocks ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShadowSocksConfigModel::updateModel(const ShadowsocksProtocolConfig shadowsocksProtocolConfig)
|
void ShadowSocksConfigModel::updateModel(const QJsonObject &config)
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
m_newShadowsocksProtocolConfig = shadowsocksProtocolConfig;
|
m_container = ContainerProps::containerFromString(config.value(config_key::container).toString());
|
||||||
m_oldShadowsocksProtocolConfig = shadowsocksProtocolConfig;
|
|
||||||
|
m_fullConfig = config;
|
||||||
|
QJsonObject protocolConfig = config.value(config_key::shadowsocks).toObject();
|
||||||
|
|
||||||
|
auto defaultTransportProto = ProtocolProps::transportProtoToString(ProtocolProps::defaultTransportProto(Proto::ShadowSocks), Proto::ShadowSocks);
|
||||||
|
m_protocolConfig.insert(config_key::transport_proto,
|
||||||
|
protocolConfig.value(config_key::transport_proto).toString(defaultTransportProto));
|
||||||
|
m_protocolConfig.insert(config_key::cipher, protocolConfig.value(config_key::cipher).toString(protocols::shadowsocks::defaultCipher));
|
||||||
|
m_protocolConfig.insert(config_key::port, protocolConfig.value(config_key::port).toString(protocols::shadowsocks::defaultPort));
|
||||||
|
|
||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
QSharedPointer<ProtocolConfig> ShadowSocksConfigModel::getConfig()
|
QJsonObject ShadowSocksConfigModel::getConfig()
|
||||||
{
|
{
|
||||||
if (m_oldShadowsocksProtocolConfig.hasEqualServerSettings(m_newShadowsocksProtocolConfig)) {
|
m_fullConfig.insert(config_key::shadowsocks, m_protocolConfig);
|
||||||
m_newShadowsocksProtocolConfig.clearClientSettings();
|
return m_fullConfig;
|
||||||
}
|
|
||||||
return QSharedPointer<ShadowsocksProtocolConfig>::create(m_newShadowsocksProtocolConfig);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ShadowSocksConfigModel::isServerSettingsEqual()
|
|
||||||
{
|
|
||||||
return m_oldShadowsocksProtocolConfig.hasEqualServerSettings(m_newShadowsocksProtocolConfig);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QHash<int, QByteArray> ShadowSocksConfigModel::roleNames() const
|
QHash<int, QByteArray> ShadowSocksConfigModel::roleNames() const
|
||||||
|
|
@ -78,4 +77,3 @@ QHash<int, QByteArray> ShadowSocksConfigModel::roleNames() const
|
||||||
|
|
||||||
return roles;
|
return roles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
|
|
||||||
#include "containers/containers_defs.h"
|
#include "containers/containers_defs.h"
|
||||||
#include "core/models/protocols/shadowsocksProtocolConfig.h"
|
|
||||||
|
|
||||||
class ShadowSocksConfigModel : public QAbstractListModel
|
class ShadowSocksConfigModel : public QAbstractListModel
|
||||||
{
|
{
|
||||||
|
|
@ -27,17 +26,16 @@ public:
|
||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updateModel(const ShadowsocksProtocolConfig shadowsocksProtocolConfig);
|
void updateModel(const QJsonObject &config);
|
||||||
QSharedPointer<ProtocolConfig> getConfig();
|
QJsonObject getConfig();
|
||||||
|
|
||||||
bool isServerSettingsEqual();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QHash<int, QByteArray> roleNames() const override;
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ShadowsocksProtocolConfig m_newShadowsocksProtocolConfig;
|
DockerContainer m_container;
|
||||||
ShadowsocksProtocolConfig m_oldShadowsocksProtocolConfig;
|
QJsonObject m_protocolConfig;
|
||||||
|
QJsonObject m_fullConfig;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SHADOWSOCKSCONFIGMODEL_H
|
#endif // SHADOWSOCKSCONFIGMODEL_H
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,7 @@
|
||||||
|
|
||||||
#include "protocols/protocols_defs.h"
|
#include "protocols/protocols_defs.h"
|
||||||
|
|
||||||
WireGuardConfigModel::WireGuardConfigModel(QObject *parent)
|
WireGuardConfigModel::WireGuardConfigModel(QObject *parent) : QAbstractListModel(parent)
|
||||||
: QAbstractListModel(parent),
|
|
||||||
m_newWireGuardProtocolConfig(QJsonObject(), ProtocolProps::protoToString(Proto::WireGuard)),
|
|
||||||
m_oldWireGuardProtocolConfig(QJsonObject(), ProtocolProps::protoToString(Proto::WireGuard))
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -24,9 +21,9 @@ bool WireGuardConfigModel::setData(const QModelIndex &index, const QVariant &val
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Roles::SubnetAddressRole: m_newWireGuardProtocolConfig.serverProtocolConfig.subnetAddress = value.toString(); break;
|
case Roles::SubnetAddressRole: m_serverProtocolConfig.insert(config_key::subnet_address, value.toString()); break;
|
||||||
case Roles::PortRole: m_newWireGuardProtocolConfig.serverProtocolConfig.port = value.toString(); break;
|
case Roles::PortRole: m_serverProtocolConfig.insert(config_key::port, value.toString()); break;
|
||||||
case Roles::ClientMtuRole: m_newWireGuardProtocolConfig.clientProtocolConfig.wireGuardData.mtu = value.toString(); break;
|
case Roles::ClientMtuRole: m_clientProtocolConfig.insert(config_key::mtu, value.toString()); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
emit dataChanged(index, index, QList { role });
|
emit dataChanged(index, index, QList { role });
|
||||||
|
|
@ -40,33 +37,62 @@ QVariant WireGuardConfigModel::data(const QModelIndex &index, int role) const
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Roles::SubnetAddressRole: return m_newWireGuardProtocolConfig.serverProtocolConfig.subnetAddress;
|
case Roles::SubnetAddressRole: return m_serverProtocolConfig.value(config_key::subnet_address).toString();
|
||||||
case Roles::PortRole: return m_newWireGuardProtocolConfig.serverProtocolConfig.port;
|
case Roles::PortRole: return m_serverProtocolConfig.value(config_key::port).toString();
|
||||||
case Roles::ClientMtuRole: return m_newWireGuardProtocolConfig.clientProtocolConfig.wireGuardData.mtu;
|
case Roles::ClientMtuRole: return m_clientProtocolConfig.value(config_key::mtu);
|
||||||
}
|
}
|
||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WireGuardConfigModel::updateModel(const WireGuardProtocolConfig wireGuardProtocolConfig)
|
void WireGuardConfigModel::updateModel(const QJsonObject &config)
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
m_newWireGuardProtocolConfig = wireGuardProtocolConfig;
|
m_container = ContainerProps::containerFromString(config.value(config_key::container).toString());
|
||||||
m_oldWireGuardProtocolConfig = wireGuardProtocolConfig;
|
|
||||||
|
m_fullConfig = config;
|
||||||
|
QJsonObject serverProtocolConfig = config.value(config_key::wireguard).toObject();
|
||||||
|
|
||||||
|
auto defaultTransportProto =
|
||||||
|
ProtocolProps::transportProtoToString(ProtocolProps::defaultTransportProto(Proto::WireGuard), Proto::WireGuard);
|
||||||
|
m_serverProtocolConfig.insert(config_key::transport_proto,
|
||||||
|
serverProtocolConfig.value(config_key::transport_proto).toString(defaultTransportProto));
|
||||||
|
m_serverProtocolConfig[config_key::last_config] = serverProtocolConfig.value(config_key::last_config);
|
||||||
|
m_serverProtocolConfig[config_key::subnet_address] = serverProtocolConfig.value(config_key::subnet_address).toString(protocols::wireguard::defaultSubnetAddress);
|
||||||
|
m_serverProtocolConfig[config_key::port] = serverProtocolConfig.value(config_key::port).toString(protocols::wireguard::defaultPort);
|
||||||
|
|
||||||
|
auto lastConfig = m_serverProtocolConfig.value(config_key::last_config).toString();
|
||||||
|
QJsonObject clientProtocolConfig = QJsonDocument::fromJson(lastConfig.toUtf8()).object();
|
||||||
|
m_clientProtocolConfig[config_key::mtu] = clientProtocolConfig[config_key::mtu].toString(protocols::wireguard::defaultMtu);
|
||||||
|
|
||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
QSharedPointer<ProtocolConfig> WireGuardConfigModel::getConfig()
|
QJsonObject WireGuardConfigModel::getConfig()
|
||||||
{
|
{
|
||||||
if (m_oldWireGuardProtocolConfig.hasEqualServerSettings(m_newWireGuardProtocolConfig)) {
|
const WgConfig oldConfig(m_fullConfig.value(config_key::wireguard).toObject());
|
||||||
m_newWireGuardProtocolConfig.clearClientSettings();
|
const WgConfig newConfig(m_serverProtocolConfig);
|
||||||
|
|
||||||
|
if (!oldConfig.hasEqualServerSettings(newConfig)) {
|
||||||
|
m_serverProtocolConfig.remove(config_key::last_config);
|
||||||
|
} else {
|
||||||
|
auto lastConfig = m_serverProtocolConfig.value(config_key::last_config).toString();
|
||||||
|
QJsonObject jsonConfig = QJsonDocument::fromJson(lastConfig.toUtf8()).object();
|
||||||
|
jsonConfig[config_key::mtu] = m_clientProtocolConfig[config_key::mtu];
|
||||||
|
|
||||||
|
m_serverProtocolConfig[config_key::last_config] = QString(QJsonDocument(jsonConfig).toJson());
|
||||||
}
|
}
|
||||||
return QSharedPointer<WireGuardProtocolConfig>::create(m_newWireGuardProtocolConfig);
|
|
||||||
|
m_fullConfig.insert(config_key::wireguard, m_serverProtocolConfig);
|
||||||
|
return m_fullConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WireGuardConfigModel::isServerSettingsEqual()
|
bool WireGuardConfigModel::isServerSettingsEqual()
|
||||||
{
|
{
|
||||||
return m_oldWireGuardProtocolConfig.hasEqualServerSettings(m_newWireGuardProtocolConfig);
|
const WgConfig oldConfig(m_fullConfig.value(config_key::wireguard).toObject());
|
||||||
|
const WgConfig newConfig(m_serverProtocolConfig);
|
||||||
|
|
||||||
|
return oldConfig.hasEqualServerSettings(newConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
QHash<int, QByteArray> WireGuardConfigModel::roleNames() const
|
QHash<int, QByteArray> WireGuardConfigModel::roleNames() const
|
||||||
|
|
@ -79,3 +105,29 @@ QHash<int, QByteArray> WireGuardConfigModel::roleNames() const
|
||||||
|
|
||||||
return roles;
|
return roles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WgConfig::WgConfig(const QJsonObject &serverProtocolConfig)
|
||||||
|
{
|
||||||
|
auto lastConfig = serverProtocolConfig.value(config_key::last_config).toString();
|
||||||
|
QJsonObject clientProtocolConfig = QJsonDocument::fromJson(lastConfig.toUtf8()).object();
|
||||||
|
clientMtu = clientProtocolConfig[config_key::mtu].toString(protocols::wireguard::defaultMtu);
|
||||||
|
|
||||||
|
subnetAddress = serverProtocolConfig.value(config_key::subnet_address).toString(protocols::wireguard::defaultSubnetAddress);
|
||||||
|
port = serverProtocolConfig.value(config_key::port).toString(protocols::wireguard::defaultPort);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool WgConfig::hasEqualServerSettings(const WgConfig &other) const
|
||||||
|
{
|
||||||
|
if (subnetAddress != other.subnetAddress || port != other.port) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool WgConfig::hasEqualClientSettings(const WgConfig &other) const
|
||||||
|
{
|
||||||
|
if (clientMtu != other.clientMtu) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,19 @@
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
|
|
||||||
#include "containers/containers_defs.h"
|
#include "containers/containers_defs.h"
|
||||||
#include "core/models/protocols/wireguardProtocolConfig.h"
|
|
||||||
|
struct WgConfig
|
||||||
|
{
|
||||||
|
WgConfig(const QJsonObject &jsonConfig);
|
||||||
|
|
||||||
|
QString subnetAddress;
|
||||||
|
QString port;
|
||||||
|
QString clientMtu;
|
||||||
|
|
||||||
|
bool hasEqualServerSettings(const WgConfig &other) const;
|
||||||
|
bool hasEqualClientSettings(const WgConfig &other) const;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
class WireGuardConfigModel : public QAbstractListModel
|
class WireGuardConfigModel : public QAbstractListModel
|
||||||
{
|
{
|
||||||
|
|
@ -26,8 +38,8 @@ public:
|
||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updateModel(const WireGuardProtocolConfig wireGuardProtocolConfig);
|
void updateModel(const QJsonObject &config);
|
||||||
QSharedPointer<ProtocolConfig> getConfig();
|
QJsonObject getConfig();
|
||||||
|
|
||||||
bool isServerSettingsEqual();
|
bool isServerSettingsEqual();
|
||||||
|
|
||||||
|
|
@ -35,8 +47,10 @@ protected:
|
||||||
QHash<int, QByteArray> roleNames() const override;
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
WireGuardProtocolConfig m_newWireGuardProtocolConfig;
|
DockerContainer m_container;
|
||||||
WireGuardProtocolConfig m_oldWireGuardProtocolConfig;
|
QJsonObject m_serverProtocolConfig;
|
||||||
|
QJsonObject m_clientProtocolConfig;
|
||||||
|
QJsonObject m_fullConfig;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // WIREGUARDCONFIGMODEL_H
|
#endif // WIREGUARDCONFIGMODEL_H
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,7 @@
|
||||||
|
|
||||||
#include "protocols/protocols_defs.h"
|
#include "protocols/protocols_defs.h"
|
||||||
|
|
||||||
XrayConfigModel::XrayConfigModel(QObject *parent)
|
XrayConfigModel::XrayConfigModel(QObject *parent) : QAbstractListModel(parent)
|
||||||
: QAbstractListModel(parent),
|
|
||||||
m_newXrayProtocolConfig(QJsonObject(), ProtocolProps::protoToString(Proto::Xray)),
|
|
||||||
m_oldXrayProtocolConfig(QJsonObject(), ProtocolProps::protoToString(Proto::Xray))
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -22,8 +19,8 @@ bool XrayConfigModel::setData(const QModelIndex &index, const QVariant &value, i
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Roles::SiteRole: m_newXrayProtocolConfig.serverProtocolConfig.site = value.toString(); break;
|
case Roles::SiteRole: m_protocolConfig.insert(config_key::site, value.toString()); break;
|
||||||
case Roles::PortRole: m_newXrayProtocolConfig.serverProtocolConfig.port = value.toString(); break;
|
case Roles::PortRole: m_protocolConfig.insert(config_key::port, value.toString()); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
emit dataChanged(index, index, QList { role });
|
emit dataChanged(index, index, QList { role });
|
||||||
|
|
@ -37,32 +34,34 @@ QVariant XrayConfigModel::data(const QModelIndex &index, int role) const
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Roles::SiteRole: return m_newXrayProtocolConfig.serverProtocolConfig.site;
|
case Roles::SiteRole: return m_protocolConfig.value(config_key::site).toString(protocols::xray::defaultSite);
|
||||||
case Roles::PortRole: return m_newXrayProtocolConfig.serverProtocolConfig.port;
|
case Roles::PortRole: return m_protocolConfig.value(config_key::port).toString(protocols::xray::defaultPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
void XrayConfigModel::updateModel(const XrayProtocolConfig xrayProtocolConfig)
|
void XrayConfigModel::updateModel(const QJsonObject &config)
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
m_newXrayProtocolConfig = xrayProtocolConfig;
|
m_container = ContainerProps::containerFromString(config.value(config_key::container).toString());
|
||||||
m_oldXrayProtocolConfig = xrayProtocolConfig;
|
|
||||||
|
m_fullConfig = config;
|
||||||
|
QJsonObject protocolConfig = config.value(config_key::xray).toObject();
|
||||||
|
|
||||||
|
auto defaultTransportProto = ProtocolProps::transportProtoToString(ProtocolProps::defaultTransportProto(Proto::Xray), Proto::Xray);
|
||||||
|
m_protocolConfig.insert(config_key::transport_proto,
|
||||||
|
protocolConfig.value(config_key::transport_proto).toString(defaultTransportProto));
|
||||||
|
m_protocolConfig.insert(config_key::port, protocolConfig.value(config_key::port).toString(protocols::xray::defaultPort));
|
||||||
|
m_protocolConfig.insert(config_key::site, protocolConfig.value(config_key::site).toString(protocols::xray::defaultSite));
|
||||||
|
|
||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
QSharedPointer<ProtocolConfig> XrayConfigModel::getConfig()
|
QJsonObject XrayConfigModel::getConfig()
|
||||||
{
|
{
|
||||||
if (m_oldXrayProtocolConfig.hasEqualServerSettings(m_newXrayProtocolConfig)) {
|
m_fullConfig.insert(config_key::xray, m_protocolConfig);
|
||||||
m_newXrayProtocolConfig.clearClientSettings();
|
return m_fullConfig;
|
||||||
}
|
|
||||||
return QSharedPointer<XrayProtocolConfig>::create(m_newXrayProtocolConfig);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool XrayConfigModel::isServerSettingsEqual()
|
|
||||||
{
|
|
||||||
return m_oldXrayProtocolConfig.hasEqualServerSettings(m_newXrayProtocolConfig);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QHash<int, QByteArray> XrayConfigModel::roleNames() const
|
QHash<int, QByteArray> XrayConfigModel::roleNames() const
|
||||||
|
|
@ -74,4 +73,3 @@ QHash<int, QByteArray> XrayConfigModel::roleNames() const
|
||||||
|
|
||||||
return roles;
|
return roles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
|
|
||||||
#include "containers/containers_defs.h"
|
#include "containers/containers_defs.h"
|
||||||
#include "core/models/protocols/xrayProtocolConfig.h"
|
|
||||||
|
|
||||||
class XrayConfigModel : public QAbstractListModel
|
class XrayConfigModel : public QAbstractListModel
|
||||||
{
|
{
|
||||||
|
|
@ -25,17 +24,16 @@ public:
|
||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updateModel(const XrayProtocolConfig xrayProtocolConfig);
|
void updateModel(const QJsonObject &config);
|
||||||
QSharedPointer<ProtocolConfig> getConfig();
|
QJsonObject getConfig();
|
||||||
|
|
||||||
bool isServerSettingsEqual();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QHash<int, QByteArray> roleNames() const override;
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
XrayProtocolConfig m_newXrayProtocolConfig;
|
DockerContainer m_container;
|
||||||
XrayProtocolConfig m_oldXrayProtocolConfig;
|
QJsonObject m_protocolConfig;
|
||||||
|
QJsonObject m_fullConfig;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // XRAYCONFIGMODEL_H
|
#endif // XRAYCONFIGMODEL_H
|
||||||
|
|
|
||||||
|
|
@ -1,45 +1,14 @@
|
||||||
#include "protocols_model.h"
|
#include "protocols_model.h"
|
||||||
|
|
||||||
#include "core/models/protocols/awgProtocolConfig.h"
|
ProtocolsModel::ProtocolsModel(std::shared_ptr<Settings> settings, QObject *parent)
|
||||||
#include "core/models/protocols/cloakProtocolConfig.h"
|
: m_settings(settings), QAbstractListModel(parent)
|
||||||
#include "core/models/protocols/openvpnProtocolConfig.h"
|
|
||||||
#include "core/models/protocols/shadowsocksProtocolConfig.h"
|
|
||||||
#include "core/models/protocols/wireguardProtocolConfig.h"
|
|
||||||
#include "core/models/protocols/xrayProtocolConfig.h"
|
|
||||||
|
|
||||||
ProtocolsModel::ProtocolsModel(QObject *parent) : QAbstractListModel(parent)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
ProtocolsModel::ProtocolsModel(const QSharedPointer<OpenVpnConfigModel> &openVpnConfigModel,
|
|
||||||
const QSharedPointer<ShadowSocksConfigModel> &shadowSocksConfigModel,
|
|
||||||
const QSharedPointer<CloakConfigModel> &cloakConfigModel,
|
|
||||||
const QSharedPointer<WireGuardConfigModel> &wireGuardConfigModel,
|
|
||||||
const QSharedPointer<AwgConfigModel> &awgConfigModel, const QSharedPointer<XrayConfigModel> &xrayConfigModel,
|
|
||||||
#ifdef Q_OS_WINDOWS
|
|
||||||
const QSharedPointer<Ikev2ConfigModel> &ikev2ConfigModel,
|
|
||||||
#endif
|
|
||||||
const QSharedPointer<SftpConfigModel> &sftpConfigModel,
|
|
||||||
const QSharedPointer<Socks5ProxyConfigModel> &socks5ProxyConfigModel, QObject *parent)
|
|
||||||
: QAbstractListModel(parent),
|
|
||||||
m_openVpnConfigModel(openVpnConfigModel),
|
|
||||||
m_shadowSocksConfigModel(shadowSocksConfigModel),
|
|
||||||
m_cloakConfigModel(cloakConfigModel),
|
|
||||||
m_wireGuardConfigModel(wireGuardConfigModel),
|
|
||||||
m_awgConfigModel(awgConfigModel),
|
|
||||||
m_xrayConfigModel(xrayConfigModel),
|
|
||||||
#ifdef Q_OS_WINDOWS
|
|
||||||
m_ikev2ConfigModel(ikev2ConfigModel),
|
|
||||||
#endif
|
|
||||||
m_sftpConfigModel(sftpConfigModel),
|
|
||||||
m_socks5ProxyConfigModel(socks5ProxyConfigModel)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int ProtocolsModel::rowCount(const QModelIndex &parent) const
|
int ProtocolsModel::rowCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(parent);
|
Q_UNUSED(parent);
|
||||||
return m_protocolConfigs.size();
|
return m_content.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
QHash<int, QByteArray> ProtocolsModel::roleNames() const
|
QHash<int, QByteArray> ProtocolsModel::roleNames() const
|
||||||
|
|
@ -58,102 +27,60 @@ QHash<int, QByteArray> ProtocolsModel::roleNames() const
|
||||||
|
|
||||||
QVariant ProtocolsModel::data(const QModelIndex &index, int role) const
|
QVariant ProtocolsModel::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
if (!index.isValid() || index.row() < 0 || index.row() >= m_protocolConfigs.size()) {
|
if (!index.isValid() || index.row() < 0 || index.row() >= m_content.size()) {
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto protocolConfig = m_protocolConfigs.at(index.row());
|
|
||||||
amnezia::Proto protocol = ProtocolProps::protoFromString(protocolConfig->protocolName);
|
|
||||||
|
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case ProtocolNameRole: {
|
case ProtocolNameRole: {
|
||||||
return ProtocolProps::protocolHumanNames().value(protocol);
|
amnezia::Proto proto = ProtocolProps::protoFromString(m_content.keys().at(index.row()));
|
||||||
|
return ProtocolProps::protocolHumanNames().value(proto);
|
||||||
}
|
}
|
||||||
case ServerProtocolPageRole: return static_cast<int>(serverProtocolPage(protocol));
|
case ServerProtocolPageRole:
|
||||||
case ClientProtocolPageRole: return static_cast<int>(clientProtocolPage(protocol));
|
return static_cast<int>(serverProtocolPage(ProtocolProps::protoFromString(m_content.keys().at(index.row()))));
|
||||||
case ProtocolIndexRole: return protocol;
|
case ClientProtocolPageRole:
|
||||||
// case RawConfigRole: {
|
return static_cast<int>(clientProtocolPage(ProtocolProps::protoFromString(m_content.keys().at(index.row()))));
|
||||||
// auto protocolConfig = m_content.value(ContainerProps::containerTypeToString(m_container)).toObject();
|
case ProtocolIndexRole: return ProtocolProps::protoFromString(m_content.keys().at(index.row()));
|
||||||
// auto lastConfigJsonDoc = QJsonDocument::fromJson(protocolConfig.value(config_key::last_config).toString().toUtf8());
|
case RawConfigRole: {
|
||||||
// auto lastConfigJson = lastConfigJsonDoc.object();
|
auto protocolConfig = m_content.value(ContainerProps::containerTypeToString(m_container)).toObject();
|
||||||
|
auto lastConfigJsonDoc =
|
||||||
|
QJsonDocument::fromJson(protocolConfig.value(config_key::last_config).toString().toUtf8());
|
||||||
|
auto lastConfigJson = lastConfigJsonDoc.object();
|
||||||
|
|
||||||
// QString rawConfig;
|
QString rawConfig;
|
||||||
// QStringList lines = lastConfigJson.value(config_key::config).toString().replace("\r", "").split("\n");
|
QStringList lines = lastConfigJson.value(config_key::config).toString().replace("\r", "").split("\n");
|
||||||
// for (const QString &l : lines) {
|
for (const QString &l : lines) {
|
||||||
// rawConfig.append(l + "\n");
|
rawConfig.append(l + "\n");
|
||||||
// }
|
}
|
||||||
// return rawConfig;
|
return rawConfig;
|
||||||
// }
|
}
|
||||||
case IsClientProtocolExistsRole: {
|
case IsClientProtocolExistsRole: {
|
||||||
auto protocolVariant = ProtocolConfig::getProtocolConfigVariant(protocolConfig);
|
auto protocolConfig = m_content.value(ContainerProps::containerTypeToString(m_container)).toObject();
|
||||||
return std::visit([](const auto &ptr) -> bool { return ptr->clientProtocolConfig.isEmpty; }, protocolVariant);
|
auto lastConfigJsonDoc =
|
||||||
|
QJsonDocument::fromJson(protocolConfig.value(config_key::last_config).toString().toUtf8());
|
||||||
|
auto lastConfigJson = lastConfigJsonDoc.object();
|
||||||
|
|
||||||
|
auto configString = lastConfigJson.value(config_key::config).toString();
|
||||||
|
return !configString.isEmpty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProtocolsModel::updateModel(const QMap<QString, QSharedPointer<ProtocolConfig>> &protocolConfigs)
|
void ProtocolsModel::updateModel(const QJsonObject &content)
|
||||||
{
|
{
|
||||||
beginResetModel();
|
m_container = ContainerProps::containerFromString(content.value(config_key::container).toString());
|
||||||
m_protocolConfigs.clear();
|
|
||||||
for (const auto &protocolConfig : protocolConfigs) {
|
m_content = content;
|
||||||
m_protocolConfigs.push_back(protocolConfig);
|
m_content.remove(config_key::container);
|
||||||
}
|
|
||||||
endResetModel();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProtocolsModel::updateProtocolModel(amnezia::Proto protocol)
|
QJsonObject ProtocolsModel::getConfig()
|
||||||
{
|
{
|
||||||
QSharedPointer<ProtocolConfig> protocolConfig;
|
QJsonObject config = m_content;
|
||||||
|
config.insert(config_key::container, ContainerProps::containerToString(m_container));
|
||||||
for (const auto &config : m_protocolConfigs) {
|
return config;
|
||||||
if (ProtocolProps::protoFromString(config->protocolName) == protocol) {
|
|
||||||
protocolConfig = config;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (protocol) {
|
|
||||||
case Proto::OpenVpn: m_openVpnConfigModel->updateModel(*qSharedPointerCast<OpenVpnProtocolConfig>(protocolConfig).data()); break;
|
|
||||||
case Proto::ShadowSocks: m_shadowSocksConfigModel->updateModel(*qSharedPointerCast<ShadowsocksProtocolConfig>(protocolConfig).data()); break;
|
|
||||||
case Proto::Cloak: m_cloakConfigModel->updateModel(*qSharedPointerCast<CloakProtocolConfig>(protocolConfig).data()); break;
|
|
||||||
case Proto::WireGuard: m_wireGuardConfigModel->updateModel(*qSharedPointerCast<WireGuardProtocolConfig>(protocolConfig).data()); break;
|
|
||||||
case Proto::Awg: m_awgConfigModel->updateModel(*qSharedPointerCast<AwgProtocolConfig>(protocolConfig).data()); break;
|
|
||||||
case Proto::Xray: m_xrayConfigModel->updateModel(*qSharedPointerCast<XrayProtocolConfig>(protocolConfig).data()); break;
|
|
||||||
#ifdef Q_OS_WINDOWS
|
|
||||||
case Proto::Ikev2:
|
|
||||||
case Proto::L2tp: m_ikev2ConfigModel->updateModel(*qSharedPointerCast<AwgProtocolConfig>(protocolConfig).data()); break;
|
|
||||||
#endif
|
|
||||||
// case Proto::Sftp: m_sftpConfigModel->updateModel(*qSharedPointerCast<SftpConfigModel>(protocolConfig).data()); break;
|
|
||||||
// case Proto::Socks5Proxy: m_socks5ProxyConfigModel->updateModel(*qSharedPointerCast<Socks>(protocolConfig).data()); break;
|
|
||||||
default: break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QMap<QString, QSharedPointer<ProtocolConfig>> ProtocolsModel::getProtocolConfigs()
|
|
||||||
{
|
|
||||||
QMap<QString, QSharedPointer<ProtocolConfig>> protocolConfigs;
|
|
||||||
|
|
||||||
for (const auto &config : m_protocolConfigs) {
|
|
||||||
switch (ProtocolProps::protoFromString(config->protocolName)) {
|
|
||||||
case Proto::OpenVpn: protocolConfigs.insert(config->protocolName, m_openVpnConfigModel->getConfig()); break;
|
|
||||||
case Proto::ShadowSocks: protocolConfigs.insert(config->protocolName, m_shadowSocksConfigModel->getConfig()); break;
|
|
||||||
case Proto::Cloak: protocolConfigs.insert(config->protocolName, m_cloakConfigModel->getConfig()); break;
|
|
||||||
case Proto::WireGuard: protocolConfigs.insert(config->protocolName, m_wireGuardConfigModel->getConfig()); break;
|
|
||||||
case Proto::Awg: protocolConfigs.insert(config->protocolName, m_awgConfigModel->getConfig()); break;
|
|
||||||
case Proto::Xray: protocolConfigs.insert(config->protocolName, m_xrayConfigModel->getConfig()); break;
|
|
||||||
#ifdef Q_OS_WINDOWS
|
|
||||||
case Proto::Ikev2:
|
|
||||||
case Proto::L2tp: protocolConfigs.insert(config->protocolName, m_awgConfigModel->getConfig()); break;
|
|
||||||
#endif
|
|
||||||
// case Proto::Sftp: protocolConfigs.insert(config->protocolName, m_awgConfigModel->getConfig()); break;
|
|
||||||
// case Proto::Socks5Proxy: protocolConfigs.insert(config->protocolName, m_awgConfigModel->getConfig()); break;
|
|
||||||
default: break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return protocolConfigs;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PageLoader::PageEnum ProtocolsModel::serverProtocolPage(Proto protocol) const
|
PageLoader::PageEnum ProtocolsModel::serverProtocolPage(Proto protocol) const
|
||||||
|
|
|
||||||
|
|
@ -4,19 +4,8 @@
|
||||||
#include <QAbstractListModel>
|
#include <QAbstractListModel>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
|
|
||||||
#include "core/models/protocols/protocolConfig.h"
|
#include "../controllers/pageController.h"
|
||||||
#include "ui/controllers/pageController.h"
|
#include "settings.h"
|
||||||
#include "ui/models/protocols/awgConfigModel.h"
|
|
||||||
#include "ui/models/protocols/cloakConfigModel.h"
|
|
||||||
#include "ui/models/protocols/openvpnConfigModel.h"
|
|
||||||
#include "ui/models/protocols/shadowsocksConfigModel.h"
|
|
||||||
#include "ui/models/protocols/wireguardConfigModel.h"
|
|
||||||
#include "ui/models/protocols/xrayConfigModel.h"
|
|
||||||
#ifdef Q_OS_WINDOWS
|
|
||||||
#include "ui/models/protocols/ikev2ConfigModel.h"
|
|
||||||
#endif
|
|
||||||
#include "ui/models/services/sftpConfigModel.h"
|
|
||||||
#include "ui/models/services/socks5ProxyConfigModel.h"
|
|
||||||
|
|
||||||
class ProtocolsModel : public QAbstractListModel
|
class ProtocolsModel : public QAbstractListModel
|
||||||
{
|
{
|
||||||
|
|
@ -31,26 +20,16 @@ public:
|
||||||
IsClientProtocolExistsRole
|
IsClientProtocolExistsRole
|
||||||
};
|
};
|
||||||
|
|
||||||
ProtocolsModel(QObject *parent = nullptr);
|
ProtocolsModel(std::shared_ptr<Settings> settings, QObject *parent = nullptr);
|
||||||
ProtocolsModel(const QSharedPointer<OpenVpnConfigModel> &openVpnConfigModel,
|
|
||||||
const QSharedPointer<ShadowSocksConfigModel> &shadowSocksConfigModel,
|
|
||||||
const QSharedPointer<CloakConfigModel> &cloakConfigModel, const QSharedPointer<WireGuardConfigModel> &wireGuardConfigModel,
|
|
||||||
const QSharedPointer<AwgConfigModel> &awgConfigModel, const QSharedPointer<XrayConfigModel> &xrayConfigModel,
|
|
||||||
#ifdef Q_OS_WINDOWS
|
|
||||||
const QSharedPointer<Ikev2ConfigModel> &ikev2ConfigModel,
|
|
||||||
#endif
|
|
||||||
const QSharedPointer<SftpConfigModel> &sftpConfigModel,
|
|
||||||
const QSharedPointer<Socks5ProxyConfigModel> &socks5ProxyConfigModel, QObject *parent = nullptr);
|
|
||||||
|
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
|
|
||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updateModel(const QMap<QString, QSharedPointer<ProtocolConfig>> &protocolConfigs);
|
void updateModel(const QJsonObject &content);
|
||||||
void updateProtocolModel(amnezia::Proto protocol);
|
|
||||||
|
|
||||||
QMap<QString, QSharedPointer<ProtocolConfig>> getProtocolConfigs();
|
QJsonObject getConfig();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QHash<int, QByteArray> roleNames() const override;
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
|
|
@ -59,19 +38,10 @@ private:
|
||||||
PageLoader::PageEnum serverProtocolPage(Proto protocol) const;
|
PageLoader::PageEnum serverProtocolPage(Proto protocol) const;
|
||||||
PageLoader::PageEnum clientProtocolPage(Proto protocol) const;
|
PageLoader::PageEnum clientProtocolPage(Proto protocol) const;
|
||||||
|
|
||||||
QVector<QSharedPointer<ProtocolConfig>> m_protocolConfigs;
|
std::shared_ptr<Settings> m_settings;
|
||||||
|
|
||||||
QSharedPointer<OpenVpnConfigModel> m_openVpnConfigModel;
|
DockerContainer m_container;
|
||||||
QSharedPointer<ShadowSocksConfigModel> m_shadowSocksConfigModel;
|
QJsonObject m_content;
|
||||||
QSharedPointer<CloakConfigModel> m_cloakConfigModel;
|
|
||||||
QSharedPointer<WireGuardConfigModel> m_wireGuardConfigModel;
|
|
||||||
QSharedPointer<AwgConfigModel> m_awgConfigModel;
|
|
||||||
QSharedPointer<XrayConfigModel> m_xrayConfigModel;
|
|
||||||
#ifdef Q_OS_WINDOWS
|
|
||||||
QSharedPointer<Ikev2ConfigModel> m_ikev2ConfigModel;
|
|
||||||
#endif
|
|
||||||
QSharedPointer<SftpConfigModel> m_sftpConfigModel;
|
|
||||||
QSharedPointer<Socks5ProxyConfigModel> m_socks5ProxyConfigModel;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PROTOCOLS_MODEL_H
|
#endif // PROTOCOLS_MODEL_H
|
||||||
|
|
|
||||||
|
|
@ -2,16 +2,14 @@
|
||||||
|
|
||||||
#include "core/api/apiDefs.h"
|
#include "core/api/apiDefs.h"
|
||||||
#include "core/controllers/serverController.h"
|
#include "core/controllers/serverController.h"
|
||||||
#include "core/models/servers/apiV1ServerConfig.h"
|
|
||||||
#include "core/models/servers/apiV2ServerConfig.h"
|
|
||||||
#include "core/models/servers/selfHostedServerConfig.h"
|
|
||||||
#include "core/models/servers/serverConfig.h"
|
|
||||||
#include "core/networkUtilities.h"
|
#include "core/networkUtilities.h"
|
||||||
|
|
||||||
#ifdef Q_OS_IOS
|
#ifdef Q_OS_IOS
|
||||||
#include <AmneziaVPN-Swift.h>
|
#include <AmneziaVPN-Swift.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "core/api/apiUtils.h"
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
namespace configKey
|
namespace configKey
|
||||||
|
|
@ -37,7 +35,8 @@ ServersModel::ServersModel(std::shared_ptr<Settings> settings, QObject *parent)
|
||||||
connect(this, &ServersModel::defaultServerIndexChanged, this, &ServersModel::defaultServerNameChanged);
|
connect(this, &ServersModel::defaultServerIndexChanged, this, &ServersModel::defaultServerNameChanged);
|
||||||
|
|
||||||
connect(this, &ServersModel::defaultServerIndexChanged, this, [this](const int serverIndex) {
|
connect(this, &ServersModel::defaultServerIndexChanged, this, [this](const int serverIndex) {
|
||||||
auto defaultContainer = ContainerProps::containerFromString(m_servers1.at(serverIndex)->defaultContainer);
|
auto defaultContainer =
|
||||||
|
ContainerProps::containerFromString(m_servers.at(serverIndex).toObject().value(config_key::defaultContainer).toString());
|
||||||
emit ServersModel::defaultServerDefaultContainerChanged(defaultContainer);
|
emit ServersModel::defaultServerDefaultContainerChanged(defaultContainer);
|
||||||
emit ServersModel::defaultServerNameChanged();
|
emit ServersModel::defaultServerNameChanged();
|
||||||
updateDefaultServerContainersModel();
|
updateDefaultServerContainersModel();
|
||||||
|
|
@ -50,25 +49,28 @@ ServersModel::ServersModel(std::shared_ptr<Settings> settings, QObject *parent)
|
||||||
int ServersModel::rowCount(const QModelIndex &parent) const
|
int ServersModel::rowCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(parent);
|
Q_UNUSED(parent);
|
||||||
return static_cast<int>(m_servers1.size());
|
return static_cast<int>(m_servers.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ServersModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
bool ServersModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||||
{
|
{
|
||||||
if (!index.isValid() || index.row() < 0 || index.row() >= static_cast<int>(m_servers1.size())) {
|
if (!index.isValid() || index.row() < 0 || index.row() >= static_cast<int>(m_servers.size())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QSharedPointer<ServerConfig> serverConfig = m_servers1.at(index.row());
|
QJsonObject server = m_servers.at(index.row()).toObject();
|
||||||
ServerConfigVariant variant = ServerConfig::getServerConfigVariant(serverConfig);
|
const auto configVersion = server.value(config_key::configVersion).toInt();
|
||||||
|
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case NameRole: {
|
case NameRole: {
|
||||||
std::visit([&value](const auto &ptr) -> void { ptr->name = value.toString(); }, variant);
|
if (configVersion) {
|
||||||
serverConfig->nameOverriddenByUser = true;
|
server.insert(config_key::name, value.toString());
|
||||||
|
} else {
|
||||||
m_settings->editServer(index.row(), serverConfig->toJson());
|
server.insert(config_key::description, value.toString());
|
||||||
m_servers1.replace(index.row(), serverConfig);
|
}
|
||||||
|
server.insert(config_key::nameOverriddenByUser, true);
|
||||||
|
m_settings->editServer(index.row(), server);
|
||||||
|
m_servers.replace(index.row(), server);
|
||||||
if (index.row() == m_defaultServerIndex) {
|
if (index.row() == m_defaultServerIndex) {
|
||||||
emit defaultServerNameChanged();
|
emit defaultServerNameChanged();
|
||||||
}
|
}
|
||||||
|
|
@ -91,21 +93,29 @@ bool ServersModel::setData(const int index, const QVariant &value, int role)
|
||||||
|
|
||||||
QVariant ServersModel::data(const QModelIndex &index, int role) const
|
QVariant ServersModel::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
if (!index.isValid() || index.row() < 0 || index.row() >= static_cast<int>(m_servers1.size())) {
|
if (!index.isValid() || index.row() < 0 || index.row() >= static_cast<int>(m_servers.size())) {
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
QSharedPointer<ServerConfig> serverConfig = m_servers1.at(index.row());
|
const QJsonObject server = m_servers.at(index.row()).toObject();
|
||||||
ServerConfigVariant variant = ServerConfig::getServerConfigVariant(serverConfig);
|
const auto apiConfig = server.value(configKey::apiConfig).toObject();
|
||||||
|
const auto configVersion = server.value(config_key::configVersion).toInt();
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case NameRole: {
|
case NameRole: {
|
||||||
return std::visit([](const auto &ptr) -> QString { return ptr->name; }, variant);
|
if (configVersion) {
|
||||||
|
return server.value(config_key::name).toString();
|
||||||
|
}
|
||||||
|
auto name = server.value(config_key::description).toString();
|
||||||
|
if (name.isEmpty()) {
|
||||||
|
return server.value(config_key::hostName).toString();
|
||||||
|
}
|
||||||
|
return name;
|
||||||
}
|
}
|
||||||
case ServerDescriptionRole: {
|
case ServerDescriptionRole: {
|
||||||
return getServerDescription(index.row());
|
auto description = getServerDescription(server, index.row());
|
||||||
|
return configVersion ? description : description + server.value(config_key::hostName).toString();
|
||||||
}
|
}
|
||||||
case HostNameRole: return serverConfig->hostName;
|
case HostNameRole: return server.value(config_key::hostName).toString();
|
||||||
case CredentialsRole: return QVariant::fromValue(serverCredentials(index.row()));
|
case CredentialsRole: return QVariant::fromValue(serverCredentials(index.row()));
|
||||||
case CredentialsLoginRole: return serverCredentials(index.row()).userName;
|
case CredentialsLoginRole: return serverCredentials(index.row()).userName;
|
||||||
case IsDefaultRole: return index.row() == m_defaultServerIndex;
|
case IsDefaultRole: return index.row() == m_defaultServerIndex;
|
||||||
|
|
@ -115,28 +125,36 @@ QVariant ServersModel::data(const QModelIndex &index, int role) const
|
||||||
return (!credentials.userName.isEmpty() && !credentials.secretData.isEmpty());
|
return (!credentials.userName.isEmpty() && !credentials.secretData.isEmpty());
|
||||||
}
|
}
|
||||||
case ContainsAmneziaDnsRole: {
|
case ContainsAmneziaDnsRole: {
|
||||||
return serverConfig->dns1 == protocols::dns::amneziaDnsIp;
|
QString primaryDns = server.value(config_key::dns1).toString();
|
||||||
|
return primaryDns == protocols::dns::amneziaDnsIp;
|
||||||
}
|
}
|
||||||
case DefaultContainerRole: {
|
case DefaultContainerRole: {
|
||||||
return ContainerProps::containerFromString(serverConfig->defaultContainer);
|
return ContainerProps::containerFromString(server.value(config_key::defaultContainer).toString());
|
||||||
}
|
}
|
||||||
case HasInstalledContainers: {
|
case HasInstalledContainers: {
|
||||||
return serverHasInstalledContainers(index.row());
|
return serverHasInstalledContainers(index.row());
|
||||||
}
|
}
|
||||||
case IsServerFromTelegramApiRole: {
|
case IsServerFromTelegramApiRole: {
|
||||||
return serverConfig->type == amnezia::ServerConfigType::ApiV1;
|
return server.value(config_key::configVersion).toInt() == apiDefs::ConfigSource::Telegram;
|
||||||
}
|
}
|
||||||
case IsServerFromGatewayApiRole: {
|
case IsServerFromGatewayApiRole: {
|
||||||
return serverConfig->type == amnezia::ServerConfigType::ApiV2;
|
return server.value(config_key::configVersion).toInt() == apiDefs::ConfigSource::AmneziaGateway;
|
||||||
|
}
|
||||||
|
case ApiConfigRole: {
|
||||||
|
return apiConfig;
|
||||||
}
|
}
|
||||||
case IsCountrySelectionAvailableRole: {
|
case IsCountrySelectionAvailableRole: {
|
||||||
return !qSharedPointerCast<ApiV2ServerConfig>(serverConfig)->apiConfig.availableCountries.isEmpty();
|
return !apiConfig.value(configKey::availableCountries).toArray().isEmpty();
|
||||||
}
|
}
|
||||||
case ApiAvailableCountriesRole: {
|
case ApiAvailableCountriesRole: {
|
||||||
return QVariant::fromValue(qSharedPointerCast<ApiV2ServerConfig>(serverConfig)->apiConfig.availableCountries);
|
return apiConfig.value(configKey::availableCountries).toArray();
|
||||||
}
|
}
|
||||||
case ApiServerCountryCodeRole: {
|
case ApiServerCountryCodeRole: {
|
||||||
return qSharedPointerCast<ApiV2ServerConfig>(serverConfig)->apiConfig.serverCountryCode;
|
return apiConfig.value(configKey::serverCountryCode).toString();
|
||||||
|
}
|
||||||
|
case HasAmneziaDns: {
|
||||||
|
QString primaryDns = server.value(config_key::dns1).toString();
|
||||||
|
return primaryDns == protocols::dns::amneziaDnsIp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -152,15 +170,9 @@ QVariant ServersModel::data(const int index, int role) const
|
||||||
void ServersModel::resetModel()
|
void ServersModel::resetModel()
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
auto servers = m_settings->serversArray();
|
m_servers = m_settings->serversArray();
|
||||||
m_defaultServerIndex = m_settings->defaultServerIndex();
|
m_defaultServerIndex = m_settings->defaultServerIndex();
|
||||||
m_processedServerIndex = m_defaultServerIndex;
|
m_processedServerIndex = m_defaultServerIndex;
|
||||||
|
|
||||||
for (auto server : servers) {
|
|
||||||
auto serverConfig = ServerConfig::createServerConfig(server.toObject());
|
|
||||||
m_servers1.push_back(serverConfig);
|
|
||||||
}
|
|
||||||
|
|
||||||
endResetModel();
|
endResetModel();
|
||||||
emit defaultServerIndexChanged(m_defaultServerIndex);
|
emit defaultServerIndexChanged(m_defaultServerIndex);
|
||||||
}
|
}
|
||||||
|
|
@ -182,64 +194,58 @@ const QString ServersModel::getDefaultServerName()
|
||||||
return qvariant_cast<QString>(data(m_defaultServerIndex, NameRole));
|
return qvariant_cast<QString>(data(m_defaultServerIndex, NameRole));
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ServersModel::getServerDescription(const int index) const
|
QString ServersModel::getServerDescription(const QJsonObject &server, const int index) const
|
||||||
{
|
{
|
||||||
auto serverConfig = m_servers1.at(index);
|
const auto configVersion = server.value(config_key::configVersion).toInt();
|
||||||
switch (serverConfig->type) {
|
const auto apiConfig = server.value(configKey::apiConfig).toObject();
|
||||||
case amnezia::ServerConfigType::ApiV1: return qSharedPointerCast<ApiV1ServerConfig>(serverConfig)->description;
|
|
||||||
case amnezia::ServerConfigType::ApiV2: {
|
QString description;
|
||||||
auto apiV2ServerConfig = qSharedPointerCast<ApiV2ServerConfig>(serverConfig);
|
|
||||||
if (apiV2ServerConfig->apiConfig.serverCountryCode.isEmpty()) {
|
if (configVersion && !apiConfig.value(configKey::serverCountryCode).toString().isEmpty()) {
|
||||||
return apiV2ServerConfig->description;
|
return apiConfig.value(configKey::serverCountryName).toString();
|
||||||
} else {
|
} else if (configVersion) {
|
||||||
return apiV2ServerConfig->apiConfig.serverCountryName;
|
return server.value(config_key::description).toString();
|
||||||
|
} else if (data(index, HasWriteAccessRole).toBool()) {
|
||||||
|
if (m_isAmneziaDnsEnabled && isAmneziaDnsContainerInstalled(index)) {
|
||||||
|
description += "Amnezia DNS | ";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (data(index, HasAmneziaDns).toBool()) {
|
||||||
|
description += "Amnezia DNS | ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case amnezia::ServerConfigType::SelfHosted: {
|
return description;
|
||||||
QString description;
|
|
||||||
if (data(index, HasWriteAccessRole).toBool()) {
|
|
||||||
if (m_isAmneziaDnsEnabled && isAmneziaDnsContainerInstalled(index)) {
|
|
||||||
description += "Amnezia DNS | " + serverConfig->hostName;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (data(index, ContainsAmneziaDnsRole).toBool()) {
|
|
||||||
description += "Amnezia DNS | " + serverConfig->hostName;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return description;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString ServersModel::getDefaultServerDescriptionCollapsed()
|
const QString ServersModel::getDefaultServerDescriptionCollapsed()
|
||||||
{
|
{
|
||||||
auto serverConfig = m_servers1.at(m_defaultServerIndex);
|
const QJsonObject server = m_servers.at(m_defaultServerIndex).toObject();
|
||||||
auto description = getServerDescription(m_defaultServerIndex);
|
const auto configVersion = server.value(config_key::configVersion).toInt();
|
||||||
auto containerName = ContainerProps::containerFromString(serverConfig->defaultContainer);
|
auto description = getServerDescription(server, m_defaultServerIndex);
|
||||||
|
if (configVersion) {
|
||||||
if (serverConfig->type != ServerConfigType::SelfHosted) {
|
|
||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
return description += ContainerProps::containerHumanNames().value(containerName) + " | " + serverConfig->hostName;
|
auto container = ContainerProps::containerFromString(server.value(config_key::defaultContainer).toString());
|
||||||
|
|
||||||
|
return description += ContainerProps::containerHumanNames().value(container) + " | " + server.value(config_key::hostName).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString ServersModel::getDefaultServerDescriptionExpanded()
|
const QString ServersModel::getDefaultServerDescriptionExpanded()
|
||||||
{
|
{
|
||||||
auto serverConfig = m_servers1.at(m_defaultServerIndex);
|
const QJsonObject server = m_servers.at(m_defaultServerIndex).toObject();
|
||||||
auto description = getServerDescription(m_defaultServerIndex);
|
const auto configVersion = server.value(config_key::configVersion).toInt();
|
||||||
auto containerName = ContainerProps::containerFromString(serverConfig->defaultContainer);
|
auto description = getServerDescription(server, m_defaultServerIndex);
|
||||||
|
if (configVersion) {
|
||||||
if (serverConfig->type != ServerConfigType::SelfHosted) {
|
|
||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
return description += serverConfig->hostName;
|
return description += server.value(config_key::hostName).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
const int ServersModel::getServersCount()
|
const int ServersModel::getServersCount()
|
||||||
{
|
{
|
||||||
return m_servers1.count();
|
return m_servers.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ServersModel::hasServerWithWriteAccess()
|
bool ServersModel::hasServerWithWriteAccess()
|
||||||
|
|
@ -301,22 +307,18 @@ bool ServersModel::isDefaultServerHasWriteAccess()
|
||||||
return qvariant_cast<bool>(data(m_defaultServerIndex, HasWriteAccessRole));
|
return qvariant_cast<bool>(data(m_defaultServerIndex, HasWriteAccessRole));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServersModel::addServer(const QSharedPointer<ServerConfig> &serverConfig)
|
void ServersModel::addServer(const QJsonObject &server)
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
m_settings->addServer(serverConfig->toJson());
|
m_settings->addServer(server);
|
||||||
auto servers = m_settings->serversArray();
|
m_servers = m_settings->serversArray();
|
||||||
for (auto server : servers) {
|
|
||||||
auto serverConfig = ServerConfig::createServerConfig(server.toObject());
|
|
||||||
m_servers1.push_back(serverConfig);
|
|
||||||
}
|
|
||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServersModel::editServer(const QSharedPointer<ServerConfig> &serverConfig, const int serverIndex)
|
void ServersModel::editServer(const QJsonObject &server, const int serverIndex)
|
||||||
{
|
{
|
||||||
m_settings->editServer(serverIndex, serverConfig->toJson());
|
m_settings->editServer(serverIndex, server);
|
||||||
m_servers1[serverIndex] = serverConfig;
|
m_servers.replace(serverIndex, m_settings->serversArray().at(serverIndex));
|
||||||
emit dataChanged(index(serverIndex, 0), index(serverIndex, 0));
|
emit dataChanged(index(serverIndex, 0), index(serverIndex, 0));
|
||||||
|
|
||||||
if (serverIndex == m_defaultServerIndex) {
|
if (serverIndex == m_defaultServerIndex) {
|
||||||
|
|
@ -330,20 +332,30 @@ void ServersModel::editServer(const QSharedPointer<ServerConfig> &serverConfig,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServersModel::removeProcessedServer()
|
void ServersModel::removeServer()
|
||||||
{
|
{
|
||||||
removeServer(m_processedServerIndex);
|
beginResetModel();
|
||||||
|
m_settings->removeServer(m_processedServerIndex);
|
||||||
|
m_servers = m_settings->serversArray();
|
||||||
|
|
||||||
|
if (m_settings->defaultServerIndex() == m_processedServerIndex) {
|
||||||
|
setDefaultServerIndex(0);
|
||||||
|
} else if (m_settings->defaultServerIndex() > m_processedServerIndex) {
|
||||||
|
setDefaultServerIndex(m_settings->defaultServerIndex() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_settings->serversCount() == 0) {
|
||||||
|
setDefaultServerIndex(-1);
|
||||||
|
}
|
||||||
|
setProcessedServerIndex(m_defaultServerIndex);
|
||||||
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServersModel::removeServer(const int serverIndex)
|
void ServersModel::removeServer(const int serverIndex)
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
m_settings->removeServer(serverIndex);
|
m_settings->removeServer(serverIndex);
|
||||||
auto servers = m_settings->serversArray();
|
m_servers = m_settings->serversArray();
|
||||||
for (auto server : servers) {
|
|
||||||
auto serverConfig = ServerConfig::createServerConfig(server.toObject());
|
|
||||||
m_servers1.push_back(serverConfig);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_settings->defaultServerIndex() == serverIndex) {
|
if (m_settings->defaultServerIndex() == serverIndex) {
|
||||||
setDefaultServerIndex(0);
|
setDefaultServerIndex(0);
|
||||||
|
|
@ -385,6 +397,7 @@ QHash<int, QByteArray> ServersModel::roleNames() const
|
||||||
|
|
||||||
roles[IsServerFromTelegramApiRole] = "isServerFromTelegramApi";
|
roles[IsServerFromTelegramApiRole] = "isServerFromTelegramApi";
|
||||||
roles[IsServerFromGatewayApiRole] = "isServerFromGatewayApi";
|
roles[IsServerFromGatewayApiRole] = "isServerFromGatewayApi";
|
||||||
|
roles[ApiConfigRole] = "apiConfig";
|
||||||
roles[IsCountrySelectionAvailableRole] = "isCountrySelectionAvailable";
|
roles[IsCountrySelectionAvailableRole] = "isCountrySelectionAvailable";
|
||||||
roles[ApiAvailableCountriesRole] = "apiAvailableCountries";
|
roles[ApiAvailableCountriesRole] = "apiAvailableCountries";
|
||||||
roles[ApiServerCountryCodeRole] = "apiServerCountryCode";
|
roles[ApiServerCountryCodeRole] = "apiServerCountryCode";
|
||||||
|
|
@ -393,33 +406,97 @@ QHash<int, QByteArray> ServersModel::roleNames() const
|
||||||
|
|
||||||
ServerCredentials ServersModel::serverCredentials(int index) const
|
ServerCredentials ServersModel::serverCredentials(int index) const
|
||||||
{
|
{
|
||||||
const auto serverConfig = m_servers1.at(index);
|
const QJsonObject &s = m_servers.at(index).toObject();
|
||||||
return qSharedPointerCast<SelfHostedServerConfig>(serverConfig)->serverCredentials;
|
|
||||||
|
ServerCredentials credentials;
|
||||||
|
credentials.hostName = s.value(config_key::hostName).toString();
|
||||||
|
credentials.userName = s.value(config_key::userName).toString();
|
||||||
|
credentials.secretData = s.value(config_key::password).toString();
|
||||||
|
credentials.port = s.value(config_key::port).toInt();
|
||||||
|
|
||||||
|
return credentials;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServersModel::updateContainersModel()
|
void ServersModel::updateContainersModel()
|
||||||
{
|
{
|
||||||
auto containerConfigs = m_servers1.at(m_processedServerIndex)->containerConfigs;
|
auto containers = m_servers.at(m_processedServerIndex).toObject().value(config_key::containers).toArray();
|
||||||
emit containersUpdated(containerConfigs);
|
emit containersUpdated(containers);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServersModel::updateDefaultServerContainersModel()
|
void ServersModel::updateDefaultServerContainersModel()
|
||||||
{
|
{
|
||||||
auto containerConfigs = m_servers1.at(m_defaultServerIndex)->containerConfigs;
|
auto containers = m_servers.at(m_defaultServerIndex).toObject().value(config_key::containers).toArray();
|
||||||
emit defaultServerContainersUpdated(containerConfigs);
|
emit defaultServerContainersUpdated(containers);
|
||||||
}
|
}
|
||||||
|
|
||||||
QSharedPointer<const ServerConfig> ServersModel::getServerConfig(const int serverIndex)
|
QJsonObject ServersModel::getServerConfig(const int serverIndex) const
|
||||||
{
|
{
|
||||||
return m_servers1.at(serverIndex);
|
return m_servers.at(serverIndex).toObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServersModel::reloadDefaultServerContainerConfig()
|
||||||
|
{
|
||||||
|
QJsonObject server = m_servers.at(m_defaultServerIndex).toObject();
|
||||||
|
auto container = ContainerProps::containerFromString(server.value(config_key::defaultContainer).toString());
|
||||||
|
|
||||||
|
auto containers = server.value(config_key::containers).toArray();
|
||||||
|
|
||||||
|
auto config = m_settings->containerConfig(m_defaultServerIndex, container);
|
||||||
|
for (auto i = 0; i < containers.size(); i++) {
|
||||||
|
auto c = ContainerProps::containerFromString(containers.at(i).toObject().value(config_key::container).toString());
|
||||||
|
if (c == container) {
|
||||||
|
containers.replace(i, config);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
server.insert(config_key::containers, containers);
|
||||||
|
editServer(server, m_defaultServerIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServersModel::updateContainerConfig(const int containerIndex, const QJsonObject config)
|
||||||
|
{
|
||||||
|
auto container = static_cast<DockerContainer>(containerIndex);
|
||||||
|
QJsonObject server = m_servers.at(m_processedServerIndex).toObject();
|
||||||
|
|
||||||
|
auto containers = server.value(config_key::containers).toArray();
|
||||||
|
for (auto i = 0; i < containers.size(); i++) {
|
||||||
|
auto c = ContainerProps::containerFromString(containers.at(i).toObject().value(config_key::container).toString());
|
||||||
|
if (c == container) {
|
||||||
|
containers.replace(i, config);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
server.insert(config_key::containers, containers);
|
||||||
|
editServer(server, m_processedServerIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServersModel::addContainerConfig(const int containerIndex, const QJsonObject config)
|
||||||
|
{
|
||||||
|
auto container = static_cast<DockerContainer>(containerIndex);
|
||||||
|
QJsonObject server = m_servers.at(m_processedServerIndex).toObject();
|
||||||
|
|
||||||
|
auto containers = server.value(config_key::containers).toArray();
|
||||||
|
containers.push_back(config);
|
||||||
|
|
||||||
|
server.insert(config_key::containers, containers);
|
||||||
|
|
||||||
|
auto defaultContainer = server.value(config_key::defaultContainer).toString();
|
||||||
|
if (ContainerProps::containerFromString(defaultContainer) == DockerContainer::None
|
||||||
|
&& ContainerProps::containerService(container) != ServiceType::Other && ContainerProps::isSupportedByCurrentPlatform(container)) {
|
||||||
|
server.insert(config_key::defaultContainer, ContainerProps::containerToString(container));
|
||||||
|
}
|
||||||
|
|
||||||
|
editServer(server, m_processedServerIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServersModel::setDefaultContainer(const int serverIndex, const int containerIndex)
|
void ServersModel::setDefaultContainer(const int serverIndex, const int containerIndex)
|
||||||
{
|
{
|
||||||
auto container = static_cast<DockerContainer>(containerIndex);
|
auto container = static_cast<DockerContainer>(containerIndex);
|
||||||
auto serverConfig = m_servers1.at(serverIndex);
|
QJsonObject s = m_servers.at(serverIndex).toObject();
|
||||||
serverConfig->defaultContainer = ContainerProps::containerToString(container);
|
s.insert(config_key::defaultContainer, ContainerProps::containerToString(container));
|
||||||
editServer(serverConfig, serverIndex);
|
editServer(s, serverIndex); // check
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString ServersModel::getDefaultServerDefaultContainerName()
|
const QString ServersModel::getDefaultServerDefaultContainerName()
|
||||||
|
|
@ -430,19 +507,25 @@ const QString ServersModel::getDefaultServerDefaultContainerName()
|
||||||
|
|
||||||
ErrorCode ServersModel::removeAllContainers(const QSharedPointer<ServerController> &serverController)
|
ErrorCode ServersModel::removeAllContainers(const QSharedPointer<ServerController> &serverController)
|
||||||
{
|
{
|
||||||
|
|
||||||
ErrorCode errorCode = serverController->removeAllContainers(m_settings->serverCredentials(m_processedServerIndex));
|
ErrorCode errorCode = serverController->removeAllContainers(m_settings->serverCredentials(m_processedServerIndex));
|
||||||
|
|
||||||
if (errorCode == ErrorCode::NoError) {
|
if (errorCode == ErrorCode::NoError) {
|
||||||
auto serverConfig = m_servers1.at(m_processedServerIndex);
|
QJsonObject s = m_servers.at(m_processedServerIndex).toObject();
|
||||||
serverConfig->containerConfigs.clear();
|
s.insert(config_key::containers, {});
|
||||||
editServer(serverConfig, m_processedServerIndex);
|
s.insert(config_key::defaultContainer, ContainerProps::containerToString(DockerContainer::None));
|
||||||
|
|
||||||
|
editServer(s, m_processedServerIndex);
|
||||||
}
|
}
|
||||||
return errorCode;
|
return errorCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorCode ServersModel::rebootServer(const QSharedPointer<ServerController> &serverController)
|
ErrorCode ServersModel::rebootServer(const QSharedPointer<ServerController> &serverController)
|
||||||
{
|
{
|
||||||
ErrorCode errorCode = serverController->rebootServer(m_settings->serverCredentials(m_processedServerIndex));
|
|
||||||
|
auto credentials = m_settings->serverCredentials(m_processedServerIndex);
|
||||||
|
|
||||||
|
ErrorCode errorCode = serverController->rebootServer(credentials);
|
||||||
return errorCode;
|
return errorCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -455,19 +538,30 @@ ErrorCode ServersModel::removeContainer(const QSharedPointer<ServerController> &
|
||||||
ErrorCode errorCode = serverController->removeContainer(credentials, dockerContainer);
|
ErrorCode errorCode = serverController->removeContainer(credentials, dockerContainer);
|
||||||
|
|
||||||
if (errorCode == ErrorCode::NoError) {
|
if (errorCode == ErrorCode::NoError) {
|
||||||
auto serverConfig = m_servers1.at(m_processedServerIndex);
|
QJsonObject server = m_servers.at(m_processedServerIndex).toObject();
|
||||||
serverConfig->containerConfigs.remove(ContainerProps::containerToString(dockerContainer));
|
|
||||||
|
|
||||||
auto defaultContainer = ContainerProps::containerFromString(serverConfig->defaultContainer);
|
auto containers = server.value(config_key::containers).toArray();
|
||||||
if (defaultContainer == containerIndex) {
|
for (auto it = containers.begin(); it != containers.end(); it++) {
|
||||||
if (serverConfig->containerConfigs.empty()) {
|
if (it->toObject().value(config_key::container).toString() == ContainerProps::containerToString(dockerContainer)) {
|
||||||
serverConfig->defaultContainer = ContainerProps::containerToString(DockerContainer::None);
|
containers.erase(it);
|
||||||
} else {
|
break;
|
||||||
serverConfig->defaultContainer = serverConfig->containerConfigs.begin()->containerName;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
editServer(serverConfig, m_processedServerIndex);
|
server.insert(config_key::containers, containers);
|
||||||
|
|
||||||
|
auto defaultContainer = ContainerProps::containerFromString(server.value(config_key::defaultContainer).toString());
|
||||||
|
if (defaultContainer == containerIndex) {
|
||||||
|
if (containers.empty()) {
|
||||||
|
defaultContainer = DockerContainer::None;
|
||||||
|
} else {
|
||||||
|
defaultContainer =
|
||||||
|
ContainerProps::containerFromString(containers.begin()->toObject().value(config_key::container).toString());
|
||||||
|
}
|
||||||
|
server.insert(config_key::defaultContainer, ContainerProps::containerToString(defaultContainer));
|
||||||
|
}
|
||||||
|
|
||||||
|
editServer(server, m_processedServerIndex);
|
||||||
}
|
}
|
||||||
return errorCode;
|
return errorCode;
|
||||||
}
|
}
|
||||||
|
|
@ -475,9 +569,7 @@ ErrorCode ServersModel::removeContainer(const QSharedPointer<ServerController> &
|
||||||
void ServersModel::clearCachedProfile(const DockerContainer container)
|
void ServersModel::clearCachedProfile(const DockerContainer container)
|
||||||
{
|
{
|
||||||
m_settings->clearLastConnectionConfig(m_processedServerIndex, container);
|
m_settings->clearLastConnectionConfig(m_processedServerIndex, container);
|
||||||
auto serverConfig = ServerConfig::createServerConfig(m_settings->server(m_processedServerIndex));
|
m_servers.replace(m_processedServerIndex, m_settings->server(m_processedServerIndex));
|
||||||
|
|
||||||
m_servers1.replace(m_processedServerIndex, serverConfig);
|
|
||||||
if (m_processedServerIndex == m_defaultServerIndex) {
|
if (m_processedServerIndex == m_defaultServerIndex) {
|
||||||
updateDefaultServerContainersModel();
|
updateDefaultServerContainersModel();
|
||||||
}
|
}
|
||||||
|
|
@ -486,9 +578,10 @@ void ServersModel::clearCachedProfile(const DockerContainer container)
|
||||||
|
|
||||||
bool ServersModel::isAmneziaDnsContainerInstalled(const int serverIndex) const
|
bool ServersModel::isAmneziaDnsContainerInstalled(const int serverIndex) const
|
||||||
{
|
{
|
||||||
auto serverConfig = m_servers1.at(serverIndex);
|
QJsonObject server = m_servers.at(serverIndex).toObject();
|
||||||
for (const auto &container : serverConfig->containerConfigs) {
|
auto containers = server.value(config_key::containers).toArray();
|
||||||
if (container.containerName == ContainerProps::containerToString(DockerContainer::Dns)) {
|
for (auto it = containers.begin(); it != containers.end(); it++) {
|
||||||
|
if (it->toObject().value(config_key::container).toString() == ContainerProps::containerToString(DockerContainer::Dns)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -499,16 +592,17 @@ QPair<QString, QString> ServersModel::getDnsPair(int serverIndex)
|
||||||
{
|
{
|
||||||
QPair<QString, QString> dns;
|
QPair<QString, QString> dns;
|
||||||
|
|
||||||
auto serverConfig = m_servers1.at(serverIndex);
|
const QJsonObject &server = m_servers.at(m_processedServerIndex).toObject();
|
||||||
|
const auto containers = server.value(config_key::containers).toArray();
|
||||||
bool isDnsContainerInstalled = false;
|
bool isDnsContainerInstalled = false;
|
||||||
for (const auto &container : serverConfig->containerConfigs) {
|
for (const QJsonValue &container : containers) {
|
||||||
if (container.containerName == ContainerProps::containerToString(DockerContainer::Dns)) {
|
if (ContainerProps::containerFromString(container.toObject().value(config_key::container).toString()) == DockerContainer::Dns) {
|
||||||
isDnsContainerInstalled = true;
|
isDnsContainerInstalled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dns.first = serverConfig->dns1;
|
dns.first = server.value(config_key::dns1).toString();
|
||||||
dns.second = serverConfig->dns2;
|
dns.second = server.value(config_key::dns2).toString();
|
||||||
|
|
||||||
if (dns.first.isEmpty() || !NetworkUtilities::checkIPv4Format(dns.first)) {
|
if (dns.first.isEmpty() || !NetworkUtilities::checkIPv4Format(dns.first)) {
|
||||||
if (m_isAmneziaDnsEnabled && isDnsContainerInstalled) {
|
if (m_isAmneziaDnsEnabled && isDnsContainerInstalled) {
|
||||||
|
|
@ -527,17 +621,18 @@ QPair<QString, QString> ServersModel::getDnsPair(int serverIndex)
|
||||||
QStringList ServersModel::getAllInstalledServicesName(const int serverIndex)
|
QStringList ServersModel::getAllInstalledServicesName(const int serverIndex)
|
||||||
{
|
{
|
||||||
QStringList servicesName;
|
QStringList servicesName;
|
||||||
auto serverConfig = m_servers1.at(serverIndex);
|
QJsonObject server = m_servers.at(serverIndex).toObject();
|
||||||
for (const auto &container : serverConfig->containerConfigs) {
|
const auto containers = server.value(config_key::containers).toArray();
|
||||||
auto containerType = ContainerProps::containerFromString(container.containerName);
|
for (auto it = containers.begin(); it != containers.end(); it++) {
|
||||||
if (ContainerProps::containerService(containerType) == ServiceType::Other) {
|
auto container = ContainerProps::containerFromString(it->toObject().value(config_key::container).toString());
|
||||||
if (containerType == DockerContainer::Dns) {
|
if (ContainerProps::containerService(container) == ServiceType::Other) {
|
||||||
|
if (container == DockerContainer::Dns) {
|
||||||
servicesName.append("DNS");
|
servicesName.append("DNS");
|
||||||
} else if (containerType == DockerContainer::Sftp) {
|
} else if (container == DockerContainer::Sftp) {
|
||||||
servicesName.append("SFTP");
|
servicesName.append("SFTP");
|
||||||
} else if (containerType == DockerContainer::TorWebSite) {
|
} else if (container == DockerContainer::TorWebSite) {
|
||||||
servicesName.append("TOR");
|
servicesName.append("TOR");
|
||||||
} else if (containerType == DockerContainer::Socks5Proxy) {
|
} else if (container == DockerContainer::Socks5Proxy) {
|
||||||
servicesName.append("SOCKS5");
|
servicesName.append("SOCKS5");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -554,8 +649,8 @@ void ServersModel::toggleAmneziaDns(bool enabled)
|
||||||
|
|
||||||
bool ServersModel::isServerFromApiAlreadyExists(const quint16 crc)
|
bool ServersModel::isServerFromApiAlreadyExists(const quint16 crc)
|
||||||
{
|
{
|
||||||
for (const auto &server : std::as_const(m_servers1)) {
|
for (const auto &server : std::as_const(m_servers)) {
|
||||||
if (static_cast<quint16>(server->crc) == crc) {
|
if (static_cast<quint16>(server.toObject().value(config_key::crc).toInt()) == crc) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -564,10 +659,11 @@ bool ServersModel::isServerFromApiAlreadyExists(const quint16 crc)
|
||||||
|
|
||||||
bool ServersModel::isServerFromApiAlreadyExists(const QString &userCountryCode, const QString &serviceType, const QString &serviceProtocol)
|
bool ServersModel::isServerFromApiAlreadyExists(const QString &userCountryCode, const QString &serviceType, const QString &serviceProtocol)
|
||||||
{
|
{
|
||||||
for (const auto &serverConfig : std::as_const(m_servers1)) {
|
for (const auto &server : std::as_const(m_servers)) {
|
||||||
const auto apiV2ServerConfig = qSharedPointerCast<ApiV2ServerConfig>(serverConfig);
|
const auto apiConfig = server.toObject().value(configKey::apiConfig).toObject();
|
||||||
if (apiV2ServerConfig->apiConfig.userCountryCode == userCountryCode && apiV2ServerConfig->apiConfig.serviceType == serviceType
|
if (apiConfig.value(configKey::userCountryCode).toString() == userCountryCode
|
||||||
&& apiV2ServerConfig->apiConfig.serviceProtocol == serviceProtocol) {
|
&& apiConfig.value(configKey::serviceType).toString() == serviceType
|
||||||
|
&& apiConfig.value(configKey::serviceProtocol).toString() == serviceProtocol) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -576,14 +672,14 @@ bool ServersModel::isServerFromApiAlreadyExists(const QString &userCountryCode,
|
||||||
|
|
||||||
bool ServersModel::serverHasInstalledContainers(const int serverIndex) const
|
bool ServersModel::serverHasInstalledContainers(const int serverIndex) const
|
||||||
{
|
{
|
||||||
auto server = m_servers1.at(serverIndex);
|
QJsonObject server = m_servers.at(serverIndex).toObject();
|
||||||
const auto containers = server->containerConfigs;
|
const auto containers = server.value(config_key::containers).toArray();
|
||||||
for (const auto &container : containers) {
|
for (auto it = containers.begin(); it != containers.end(); it++) {
|
||||||
auto dockerContainer = ContainerProps::containerFromString(container.containerName);
|
auto container = ContainerProps::containerFromString(it->toObject().value(config_key::container).toString());
|
||||||
if (ContainerProps::containerService(dockerContainer) == ServiceType::Vpn) {
|
if (ContainerProps::containerService(container) == ServiceType::Vpn) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (dockerContainer == DockerContainer::SSXray) {
|
if (container == DockerContainer::SSXray) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -628,46 +724,27 @@ bool ServersModel::setProcessedServerData(const QString &roleString, const QVari
|
||||||
|
|
||||||
bool ServersModel::isDefaultServerDefaultContainerHasSplitTunneling()
|
bool ServersModel::isDefaultServerDefaultContainerHasSplitTunneling()
|
||||||
{
|
{
|
||||||
auto serverConfig = m_servers1.at(m_defaultServerIndex);
|
auto server = m_servers.at(m_defaultServerIndex).toObject();
|
||||||
auto defaultContainer = ContainerProps::containerFromString(serverConfig->defaultContainer);
|
auto defaultContainer = ContainerProps::containerFromString(server.value(config_key::defaultContainer).toString());
|
||||||
|
|
||||||
for (const auto &container : serverConfig->containerConfigs) {
|
auto containers = server.value(config_key::containers).toArray();
|
||||||
if (container.containerName != serverConfig->defaultContainer) {
|
for (auto i = 0; i < containers.size(); i++) {
|
||||||
|
auto container = containers.at(i).toObject();
|
||||||
|
if (container.value(config_key::container).toString() != ContainerProps::containerToString(defaultContainer)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (defaultContainer == DockerContainer::Awg || defaultContainer == DockerContainer::WireGuard) {
|
if (defaultContainer == DockerContainer::Awg || defaultContainer == DockerContainer::WireGuard) {
|
||||||
auto protocolConfigVariant = ProtocolConfig::getProtocolConfigVariant(container.protocolConfigs[serverConfig->defaultContainer]);
|
QJsonObject serverProtocolConfig = container.value(ContainerProps::containerTypeToString(defaultContainer)).toObject();
|
||||||
return std::visit(
|
QString clientProtocolConfigString = serverProtocolConfig.value(config_key::last_config).toString();
|
||||||
[](const auto &ptr) -> bool {
|
QJsonObject clientProtocolConfig = QJsonDocument::fromJson(clientProtocolConfigString.toUtf8()).object();
|
||||||
if constexpr (requires {
|
return (clientProtocolConfigString.contains("AllowedIPs") && !clientProtocolConfigString.contains("AllowedIPs = 0.0.0.0/0, ::/0"))
|
||||||
ptr->clientProtocolConfig;
|
|| (!clientProtocolConfig.value(config_key::allowed_ips).toArray().isEmpty()
|
||||||
ptr->clientProtocolConfig.wireGuardData;
|
&& !clientProtocolConfig.value(config_key::allowed_ips).toArray().contains("0.0.0.0/0"));
|
||||||
}) {
|
|
||||||
const auto nativeConfig = ptr->clientProtocolConfig.nativeConfig;
|
|
||||||
const auto allowedIps = ptr->clientProtocolConfig.wireGuardData.allowedIps;
|
|
||||||
|
|
||||||
return (nativeConfig.contains("AllowedIPs") && !nativeConfig.contains("AllowedIPs = 0.0.0.0/0, ::/0"))
|
|
||||||
|| (!allowedIps.isEmpty() && !allowedIps.contains("0.0.0.0/0"));
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
protocolConfigVariant);
|
|
||||||
} else if (defaultContainer == DockerContainer::Cloak || defaultContainer == DockerContainer::OpenVpn
|
} else if (defaultContainer == DockerContainer::Cloak || defaultContainer == DockerContainer::OpenVpn
|
||||||
|| defaultContainer == DockerContainer::ShadowSocks) {
|
|| defaultContainer == DockerContainer::ShadowSocks) {
|
||||||
auto protocolConfigVariant = ProtocolConfig::getProtocolConfigVariant(
|
auto serverProtocolConfig = container.value(ContainerProps::containerTypeToString(DockerContainer::OpenVpn)).toObject();
|
||||||
container.protocolConfigs[ContainerProps::containerTypeToString(DockerContainer::OpenVpn)]);
|
QString clientProtocolConfigString = serverProtocolConfig.value(config_key::last_config).toString();
|
||||||
return std::visit(
|
return !clientProtocolConfigString.isEmpty() && !clientProtocolConfigString.contains("redirect-gateway");
|
||||||
[](const auto &ptr) -> bool {
|
|
||||||
if constexpr (requires { ptr->clientProtocolConfig; }) {
|
|
||||||
const auto nativeConfig = ptr->clientProtocolConfig.nativeConfig;
|
|
||||||
|
|
||||||
return (!nativeConfig.isEmpty() && !nativeConfig.contains("redirect-gateway"));
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
protocolConfigVariant);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -680,62 +757,67 @@ bool ServersModel::isServerFromApi(const int serverIndex)
|
||||||
|
|
||||||
bool ServersModel::isApiKeyExpired(const int serverIndex)
|
bool ServersModel::isApiKeyExpired(const int serverIndex)
|
||||||
{
|
{
|
||||||
// auto serverConfig = m_servers1.at(serverIndex);
|
auto serverConfig = m_servers.at(serverIndex).toObject();
|
||||||
// auto apiConfig = serverConfig.value(configKey::apiConfig).toObject();
|
auto apiConfig = serverConfig.value(configKey::apiConfig).toObject();
|
||||||
|
|
||||||
// auto publicKeyInfo = apiConfig.value(configKey::publicKeyInfo).toObject();
|
auto publicKeyInfo = apiConfig.value(configKey::publicKeyInfo).toObject();
|
||||||
// const QString expiresAt = publicKeyInfo.value(configKey::expiresAt).toString();
|
const QString expiresAt = publicKeyInfo.value(configKey::expiresAt).toString();
|
||||||
// if (expiresAt.isEmpty()) {
|
if (expiresAt.isEmpty()) {
|
||||||
// publicKeyInfo.insert(configKey::expiresAt, QDateTime::currentDateTimeUtc().addDays(1).toString(Qt::ISODate));
|
publicKeyInfo.insert(configKey::expiresAt, QDateTime::currentDateTimeUtc().addDays(1).toString(Qt::ISODate));
|
||||||
// apiConfig.insert(configKey::publicKeyInfo, publicKeyInfo);
|
apiConfig.insert(configKey::publicKeyInfo, publicKeyInfo);
|
||||||
// serverConfig.insert(configKey::apiConfig, apiConfig);
|
serverConfig.insert(configKey::apiConfig, apiConfig);
|
||||||
// editServer(serverConfig, serverIndex);
|
editServer(serverConfig, serverIndex);
|
||||||
|
|
||||||
// return false;
|
return false;
|
||||||
// }
|
}
|
||||||
|
|
||||||
// auto expiresAtDateTime = QDateTime::fromString(expiresAt, Qt::ISODate).toUTC();
|
auto expiresAtDateTime = QDateTime::fromString(expiresAt, Qt::ISODate).toUTC();
|
||||||
// if (expiresAtDateTime < QDateTime::currentDateTimeUtc()) {
|
if (expiresAtDateTime < QDateTime::currentDateTimeUtc()) {
|
||||||
// return true;
|
return true;
|
||||||
// }
|
}
|
||||||
// return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServersModel::removeApiConfig(const int serverIndex)
|
void ServersModel::removeApiConfig(const int serverIndex)
|
||||||
{
|
{
|
||||||
// auto serverConfig = m_servers1.at(serverIndex);
|
auto serverConfig = getServerConfig(serverIndex);
|
||||||
|
|
||||||
// #ifdef Q_OS_IOS
|
#ifdef Q_OS_IOS
|
||||||
// QString vpncName = QString("%1 (%2) %3")
|
QString vpncName = QString("%1 (%2) %3")
|
||||||
// .arg(serverConfig[config_key::description].toString())
|
.arg(serverConfig[config_key::description].toString())
|
||||||
// .arg(serverConfig[config_key::hostName].toString())
|
.arg(serverConfig[config_key::hostName].toString())
|
||||||
// .arg(serverConfig[config_key::vpnproto].toString());
|
.arg(serverConfig[config_key::vpnproto].toString());
|
||||||
|
|
||||||
// AmneziaVPN::removeVPNC(vpncName.toStdString());
|
AmneziaVPN::removeVPNC(vpncName.toStdString());
|
||||||
// #endif
|
#endif
|
||||||
|
|
||||||
// serverConfig.remove(config_key::dns1);
|
serverConfig.remove(config_key::dns1);
|
||||||
// serverConfig.remove(config_key::dns2);
|
serverConfig.remove(config_key::dns2);
|
||||||
// serverConfig.remove(config_key::containers);
|
serverConfig.remove(config_key::containers);
|
||||||
// serverConfig.remove(config_key::hostName);
|
serverConfig.remove(config_key::hostName);
|
||||||
|
|
||||||
// auto apiConfig = serverConfig.value(configKey::apiConfig).toObject();
|
auto apiConfig = serverConfig.value(configKey::apiConfig).toObject();
|
||||||
// apiConfig.remove(configKey::publicKeyInfo);
|
apiConfig.remove(configKey::publicKeyInfo);
|
||||||
// serverConfig.insert(configKey::apiConfig, apiConfig);
|
serverConfig.insert(configKey::apiConfig, apiConfig);
|
||||||
|
|
||||||
// serverConfig.insert(config_key::defaultContainer, ContainerProps::containerToString(DockerContainer::None));
|
serverConfig.insert(config_key::defaultContainer, ContainerProps::containerToString(DockerContainer::None));
|
||||||
|
|
||||||
// editServer(serverConfig, serverIndex);
|
editServer(serverConfig, serverIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString ServersModel::getDefaultServerImagePathCollapsed()
|
const QString ServersModel::getDefaultServerImagePathCollapsed()
|
||||||
{
|
{
|
||||||
// const auto server = m_servers.at(m_defaultServerIndex).toObject();
|
const auto server = m_servers.at(m_defaultServerIndex).toObject();
|
||||||
// const auto apiConfig = server.value(configKey::apiConfig).toObject();
|
const auto apiConfig = server.value(configKey::apiConfig).toObject();
|
||||||
// const auto countryCode = apiConfig.value(configKey::serverCountryCode).toString();
|
const auto countryCode = apiConfig.value(configKey::serverCountryCode).toString();
|
||||||
|
|
||||||
// if (countryCode.isEmpty()) {
|
if (countryCode.isEmpty()) {
|
||||||
// return "";
|
return "";
|
||||||
// }
|
}
|
||||||
// return QString("qrc:/countriesFlags/images/flagKit/%1.svg").arg(countryCode.toUpper());
|
return QString("qrc:/countriesFlags/images/flagKit/%1.svg").arg(countryCode.toUpper());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ServersModel::processedServerIsPremium() const
|
||||||
|
{
|
||||||
|
return apiUtils::isPremiumServer(getServerConfig(m_processedServerIndex));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@
|
||||||
#include <QAbstractListModel>
|
#include <QAbstractListModel>
|
||||||
|
|
||||||
#include "core/controllers/serverController.h"
|
#include "core/controllers/serverController.h"
|
||||||
#include "core/models/servers/serverConfig.h"
|
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
|
||||||
class ServersModel : public QAbstractListModel
|
class ServersModel : public QAbstractListModel
|
||||||
|
|
@ -37,7 +36,9 @@ public:
|
||||||
ApiConfigRole,
|
ApiConfigRole,
|
||||||
IsCountrySelectionAvailableRole,
|
IsCountrySelectionAvailableRole,
|
||||||
ApiAvailableCountriesRole,
|
ApiAvailableCountriesRole,
|
||||||
ApiServerCountryCodeRole
|
ApiServerCountryCodeRole,
|
||||||
|
|
||||||
|
HasAmneziaDns
|
||||||
};
|
};
|
||||||
|
|
||||||
ServersModel(std::shared_ptr<Settings> settings, QObject *parent = nullptr);
|
ServersModel(std::shared_ptr<Settings> settings, QObject *parent = nullptr);
|
||||||
|
|
@ -62,6 +63,9 @@ public:
|
||||||
Q_PROPERTY(bool isDefaultServerFromApi READ isDefaultServerFromApi NOTIFY defaultServerIndexChanged)
|
Q_PROPERTY(bool isDefaultServerFromApi READ isDefaultServerFromApi NOTIFY defaultServerIndexChanged)
|
||||||
|
|
||||||
Q_PROPERTY(int processedIndex READ getProcessedServerIndex WRITE setProcessedServerIndex NOTIFY processedServerIndexChanged)
|
Q_PROPERTY(int processedIndex READ getProcessedServerIndex WRITE setProcessedServerIndex NOTIFY processedServerIndexChanged)
|
||||||
|
Q_PROPERTY(bool processedServerIsPremium READ processedServerIsPremium NOTIFY processedServerChanged)
|
||||||
|
|
||||||
|
bool processedServerIsPremium() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setDefaultServerIndex(const int index);
|
void setDefaultServerIndex(const int index);
|
||||||
|
|
@ -86,12 +90,16 @@ public slots:
|
||||||
const ServerCredentials getProcessedServerCredentials();
|
const ServerCredentials getProcessedServerCredentials();
|
||||||
const ServerCredentials getServerCredentials(const int index);
|
const ServerCredentials getServerCredentials(const int index);
|
||||||
|
|
||||||
void addServer(const QSharedPointer<ServerConfig> &serverConfig);
|
void addServer(const QJsonObject &server);
|
||||||
void editServer(const QSharedPointer<ServerConfig> &serverConfig, const int serverIndex);
|
void editServer(const QJsonObject &server, const int serverIndex);
|
||||||
void removeProcessedServer();
|
void removeServer();
|
||||||
void removeServer(const int serverIndex);
|
void removeServer(const int serverIndex);
|
||||||
|
|
||||||
QSharedPointer<const ServerConfig> getServerConfig(const int serverIndex);
|
QJsonObject getServerConfig(const int serverIndex) const;
|
||||||
|
|
||||||
|
void reloadDefaultServerContainerConfig();
|
||||||
|
void updateContainerConfig(const int containerIndex, const QJsonObject config);
|
||||||
|
void addContainerConfig(const int containerIndex, const QJsonObject config);
|
||||||
|
|
||||||
void clearCachedProfile(const DockerContainer container);
|
void clearCachedProfile(const DockerContainer container);
|
||||||
|
|
||||||
|
|
@ -132,8 +140,8 @@ signals:
|
||||||
void defaultServerNameChanged();
|
void defaultServerNameChanged();
|
||||||
void defaultServerDescriptionChanged();
|
void defaultServerDescriptionChanged();
|
||||||
|
|
||||||
void containersUpdated(const QMap<QString, ContainerConfig> &containerConfigs);
|
void containersUpdated(const QJsonArray &containers);
|
||||||
void defaultServerContainersUpdated(const QMap<QString, ContainerConfig> &containerConfigs);
|
void defaultServerContainersUpdated(const QJsonArray &containers);
|
||||||
void defaultServerDefaultContainerChanged(const int containerIndex);
|
void defaultServerDefaultContainerChanged(const int containerIndex);
|
||||||
|
|
||||||
void updateApiCountryModel();
|
void updateApiCountryModel();
|
||||||
|
|
@ -145,13 +153,13 @@ private:
|
||||||
void updateContainersModel();
|
void updateContainersModel();
|
||||||
void updateDefaultServerContainersModel();
|
void updateDefaultServerContainersModel();
|
||||||
|
|
||||||
QString getServerDescription(const int index) const;
|
QString getServerDescription(const QJsonObject &server, const int index) const;
|
||||||
|
|
||||||
bool isAmneziaDnsContainerInstalled(const int serverIndex) const;
|
bool isAmneziaDnsContainerInstalled(const int serverIndex) const;
|
||||||
|
|
||||||
bool serverHasInstalledContainers(const int serverIndex) const;
|
bool serverHasInstalledContainers(const int serverIndex) const;
|
||||||
|
|
||||||
QVector<QSharedPointer<ServerConfig>> m_servers1;
|
QJsonArray m_servers;
|
||||||
|
|
||||||
std::shared_ptr<Settings> m_settings;
|
std::shared_ptr<Settings> m_settings;
|
||||||
|
|
||||||
|
|
|
||||||
15
client/ui/qml/Components/AwgTextField.qml
Normal file
15
client/ui/qml/Components/AwgTextField.qml
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
pragma ComponentBehavior: Bound
|
||||||
|
|
||||||
|
import QtQuick
|
||||||
|
import QtQuick.Layouts
|
||||||
|
|
||||||
|
import "../Controls2"
|
||||||
|
|
||||||
|
TextFieldWithHeaderType {
|
||||||
|
Layout.fillWidth: true
|
||||||
|
Layout.topMargin: 16
|
||||||
|
|
||||||
|
textField.validator: IntValidator { bottom: 0 }
|
||||||
|
|
||||||
|
checkEmptyText: true
|
||||||
|
}
|
||||||
|
|
@ -115,14 +115,10 @@ PageType {
|
||||||
KeyNavigation.tab: junkPacketCountTextField.textField
|
KeyNavigation.tab: junkPacketCountTextField.textField
|
||||||
}
|
}
|
||||||
|
|
||||||
TextFieldWithHeaderType {
|
AwgTextField {
|
||||||
id: junkPacketCountTextField
|
id: junkPacketCountTextField
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.topMargin: 16
|
|
||||||
|
|
||||||
headerText: "Jc - Junk packet count"
|
headerText: "Jc - Junk packet count"
|
||||||
textField.text: clientJunkPacketCount
|
textField.text: clientJunkPacketCount
|
||||||
textField.validator: IntValidator { bottom: 0 }
|
|
||||||
|
|
||||||
textField.onEditingFinished: {
|
textField.onEditingFinished: {
|
||||||
if (textField.text !== clientJunkPacketCount) {
|
if (textField.text !== clientJunkPacketCount) {
|
||||||
|
|
@ -130,19 +126,13 @@ PageType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
checkEmptyText: true
|
|
||||||
|
|
||||||
KeyNavigation.tab: junkPacketMinSizeTextField.textField
|
KeyNavigation.tab: junkPacketMinSizeTextField.textField
|
||||||
}
|
}
|
||||||
|
|
||||||
TextFieldWithHeaderType {
|
AwgTextField {
|
||||||
id: junkPacketMinSizeTextField
|
id: junkPacketMinSizeTextField
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.topMargin: 16
|
|
||||||
|
|
||||||
headerText: "Jmin - Junk packet minimum size"
|
headerText: "Jmin - Junk packet minimum size"
|
||||||
textField.text: clientJunkPacketMinSize
|
textField.text: clientJunkPacketMinSize
|
||||||
textField.validator: IntValidator { bottom: 0 }
|
|
||||||
|
|
||||||
textField.onEditingFinished: {
|
textField.onEditingFinished: {
|
||||||
if (textField.text !== clientJunkPacketMinSize) {
|
if (textField.text !== clientJunkPacketMinSize) {
|
||||||
|
|
@ -150,28 +140,144 @@ PageType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
checkEmptyText: true
|
|
||||||
|
|
||||||
KeyNavigation.tab: junkPacketMaxSizeTextField.textField
|
KeyNavigation.tab: junkPacketMaxSizeTextField.textField
|
||||||
}
|
}
|
||||||
|
|
||||||
TextFieldWithHeaderType {
|
AwgTextField {
|
||||||
id: junkPacketMaxSizeTextField
|
id: junkPacketMaxSizeTextField
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.topMargin: 16
|
|
||||||
|
|
||||||
headerText: "Jmax - Junk packet maximum size"
|
headerText: "Jmax - Junk packet maximum size"
|
||||||
textField.text: clientJunkPacketMaxSize
|
textField.text: clientJunkPacketMaxSize
|
||||||
textField.validator: IntValidator { bottom: 0 }
|
|
||||||
|
|
||||||
textField.onEditingFinished: {
|
textField.onEditingFinished: {
|
||||||
if (textField.text !== clientJunkPacketMaxSize) {
|
if (textField.text !== clientJunkPacketMaxSize) {
|
||||||
clientJunkPacketMaxSize = textField.text
|
clientJunkPacketMaxSize = textField.text
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
checkEmptyText: true
|
AwgTextField {
|
||||||
|
id: specialJunk1TextField
|
||||||
|
headerText: qsTr("I1 - First special junk packet")
|
||||||
|
textField.text: clientSpecialJunk1
|
||||||
|
textField.validator: null
|
||||||
|
checkEmptyText: false
|
||||||
|
|
||||||
|
textField.onEditingFinished: {
|
||||||
|
if (textField.text !== clientSpecialJunk1) {
|
||||||
|
clientSpecialJunk1 = textField.text
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AwgTextField {
|
||||||
|
id: specialJunk2TextField
|
||||||
|
headerText: qsTr("I2 - Second special junk packet")
|
||||||
|
textField.text: clientSpecialJunk2
|
||||||
|
textField.validator: null
|
||||||
|
checkEmptyText: false
|
||||||
|
|
||||||
|
textField.onEditingFinished: {
|
||||||
|
if (textField.text !== clientSpecialJunk2) {
|
||||||
|
clientSpecialJunk2 = textField.text
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AwgTextField {
|
||||||
|
id: specialJunk3TextField
|
||||||
|
headerText: qsTr("I3 - Third special junk packet")
|
||||||
|
textField.text: clientSpecialJunk3
|
||||||
|
textField.validator: null
|
||||||
|
checkEmptyText: false
|
||||||
|
|
||||||
|
textField.onEditingFinished: {
|
||||||
|
if (textField.text !== clientSpecialJunk3) {
|
||||||
|
clientSpecialJunk3 = textField.text
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AwgTextField {
|
||||||
|
id: specialJunk4TextField
|
||||||
|
headerText: qsTr("I4 - Fourth special junk packet")
|
||||||
|
textField.text: clientSpecialJunk4
|
||||||
|
textField.validator: null
|
||||||
|
checkEmptyText: false
|
||||||
|
|
||||||
|
textField.onEditingFinished: {
|
||||||
|
if (textField.text !== clientSpecialJunk4) {
|
||||||
|
clientSpecialJunk4 = textField.text
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AwgTextField {
|
||||||
|
id: specialJunk5TextField
|
||||||
|
headerText: qsTr("I5 - Fifth special junk packet")
|
||||||
|
textField.text: clientSpecialJunk5
|
||||||
|
textField.validator: null
|
||||||
|
checkEmptyText: false
|
||||||
|
|
||||||
|
textField.onEditingFinished: {
|
||||||
|
if (textField.text !== clientSpecialJunk5 ) {
|
||||||
|
clientSpecialJunk5 = textField.text
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AwgTextField {
|
||||||
|
id: controlledJunk1TextField
|
||||||
|
headerText: qsTr("J1 - First controlled junk packet")
|
||||||
|
textField.text: clientControlledJunk1
|
||||||
|
textField.validator: null
|
||||||
|
checkEmptyText: false
|
||||||
|
|
||||||
|
textField.onEditingFinished: {
|
||||||
|
if (textField.text !== clientControlledJunk1) {
|
||||||
|
clientControlledJunk1 = textField.text
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AwgTextField {
|
||||||
|
id: controlledJunk2TextField
|
||||||
|
headerText: qsTr("J2 - Second controlled junk packet")
|
||||||
|
textField.text: clientControlledJunk2
|
||||||
|
textField.validator: null
|
||||||
|
checkEmptyText: false
|
||||||
|
|
||||||
|
textField.onEditingFinished: {
|
||||||
|
if (textField.text !== clientControlledJunk2) {
|
||||||
|
clientControlledJunk2 = textField.text
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AwgTextField {
|
||||||
|
id: controlledJunk3TextField
|
||||||
|
headerText: qsTr("J3 - Third controlled junk packet")
|
||||||
|
textField.text: clientControlledJunk3
|
||||||
|
textField.validator: null
|
||||||
|
checkEmptyText: false
|
||||||
|
|
||||||
|
textField.onEditingFinished: {
|
||||||
|
if (textField.text !== clientControlledJunk3) {
|
||||||
|
clientControlledJunk3 = textField.text
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AwgTextField {
|
||||||
|
id: iTimeTextField
|
||||||
|
headerText: qsTr("Itime - Special handshake timeout")
|
||||||
|
textField.text: clientSpecialHandshakeTimeout
|
||||||
|
checkEmptyText: false
|
||||||
|
|
||||||
|
textField.onEditingFinished: {
|
||||||
|
if (textField.text !== clientSpecialHandshakeTimeout) {
|
||||||
|
clientSpecialHandshakeTimeout = textField.text
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Header2TextType {
|
Header2TextType {
|
||||||
|
|
@ -181,82 +287,78 @@ PageType {
|
||||||
text: qsTr("Server settings")
|
text: qsTr("Server settings")
|
||||||
}
|
}
|
||||||
|
|
||||||
TextFieldWithHeaderType {
|
AwgTextField {
|
||||||
id: portTextField
|
id: portTextField
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.topMargin: 8
|
|
||||||
|
|
||||||
enabled: false
|
enabled: false
|
||||||
|
|
||||||
headerText: qsTr("Port")
|
headerText: qsTr("Port")
|
||||||
textField.text: port
|
textField.text: port
|
||||||
}
|
}
|
||||||
|
|
||||||
TextFieldWithHeaderType {
|
AwgTextField {
|
||||||
id: initPacketJunkSizeTextField
|
id: initPacketJunkSizeTextField
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.topMargin: 16
|
|
||||||
|
|
||||||
enabled: false
|
enabled: false
|
||||||
|
|
||||||
headerText: "S1 - Init packet junk size"
|
headerText: "S1 - Init packet junk size"
|
||||||
textField.text: serverInitPacketJunkSize
|
textField.text: serverInitPacketJunkSize
|
||||||
}
|
}
|
||||||
|
|
||||||
TextFieldWithHeaderType {
|
AwgTextField {
|
||||||
id: responsePacketJunkSizeTextField
|
id: responsePacketJunkSizeTextField
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.topMargin: 16
|
|
||||||
|
|
||||||
enabled: false
|
enabled: false
|
||||||
|
|
||||||
headerText: "S2 - Response packet junk size"
|
headerText: "S2 - Response packet junk size"
|
||||||
textField.text: serverResponsePacketJunkSize
|
textField.text: serverResponsePacketJunkSize
|
||||||
}
|
}
|
||||||
|
|
||||||
TextFieldWithHeaderType {
|
// AwgTextField {
|
||||||
id: initPacketMagicHeaderTextField
|
// id: cookieReplyPacketJunkSizeTextField
|
||||||
Layout.fillWidth: true
|
// enabled: false
|
||||||
Layout.topMargin: 16
|
|
||||||
|
|
||||||
|
// headerText: "S3 - Cookie Reply packet junk size"
|
||||||
|
// textField.text: serverCookieReplyPacketJunkSize
|
||||||
|
// }
|
||||||
|
|
||||||
|
// AwgTextField {
|
||||||
|
// id: transportPacketJunkSizeTextField
|
||||||
|
// enabled: false
|
||||||
|
|
||||||
|
// headerText: "S4 - Transport packet junk size"
|
||||||
|
// textField.text: serverTransportPacketJunkSize
|
||||||
|
// }
|
||||||
|
|
||||||
|
AwgTextField {
|
||||||
|
id: initPacketMagicHeaderTextField
|
||||||
enabled: false
|
enabled: false
|
||||||
|
|
||||||
headerText: "H1 - Init packet magic header"
|
headerText: "H1 - Init packet magic header"
|
||||||
textField.text: serverInitPacketMagicHeader
|
textField.text: serverInitPacketMagicHeader
|
||||||
}
|
}
|
||||||
|
|
||||||
TextFieldWithHeaderType {
|
AwgTextField {
|
||||||
id: responsePacketMagicHeaderTextField
|
id: responsePacketMagicHeaderTextField
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.topMargin: 16
|
|
||||||
|
|
||||||
enabled: false
|
enabled: false
|
||||||
|
|
||||||
headerText: "H2 - Response packet magic header"
|
headerText: "H2 - Response packet magic header"
|
||||||
textField.text: serverResponsePacketMagicHeader
|
textField.text: serverResponsePacketMagicHeader
|
||||||
}
|
}
|
||||||
|
|
||||||
TextFieldWithHeaderType {
|
AwgTextField {
|
||||||
id: underloadPacketMagicHeaderTextField
|
id: underloadPacketMagicHeaderTextField
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.topMargin: 16
|
|
||||||
|
|
||||||
enabled: false
|
enabled: false
|
||||||
|
|
||||||
headerText: "H3 - Underload packet magic header"
|
headerText: "H3 - Underload packet magic header"
|
||||||
textField.text: serverUnderloadPacketMagicHeader
|
textField.text: serverUnderloadPacketMagicHeader
|
||||||
}
|
}
|
||||||
|
|
||||||
TextFieldWithHeaderType {
|
AwgTextField {
|
||||||
id: transportPacketMagicHeaderTextField
|
id: transportPacketMagicHeaderTextField
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.topMargin: 16
|
|
||||||
|
|
||||||
enabled: false
|
enabled: false
|
||||||
|
|
||||||
headerText: "H4 - Transport packet magic header"
|
headerText: "H4 - Transport packet magic header"
|
||||||
textField.text: serverTransportPacketMagicHeader
|
textField.text: serverTransportPacketMagicHeader
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -138,184 +138,139 @@ PageType {
|
||||||
checkEmptyText: true
|
checkEmptyText: true
|
||||||
}
|
}
|
||||||
|
|
||||||
TextFieldWithHeaderType {
|
AwgTextField {
|
||||||
id: junkPacketCountTextField
|
id: junkPacketCountTextField
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.topMargin: 16
|
|
||||||
|
|
||||||
headerText: qsTr("Jc - Junk packet count")
|
headerText: qsTr("Jc - Junk packet count")
|
||||||
textField.text: serverJunkPacketCount
|
textField.text: serverJunkPacketCount
|
||||||
textField.validator: IntValidator { bottom: 0 }
|
|
||||||
|
|
||||||
textField.onEditingFinished: {
|
textField.onEditingFinished: {
|
||||||
if (textField.text === "") {
|
|
||||||
textField.text = "0"
|
|
||||||
}
|
|
||||||
|
|
||||||
if (textField.text !== serverJunkPacketCount) {
|
if (textField.text !== serverJunkPacketCount) {
|
||||||
serverJunkPacketCount = textField.text
|
serverJunkPacketCount = textField.text
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
checkEmptyText: true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TextFieldWithHeaderType {
|
AwgTextField {
|
||||||
id: junkPacketMinSizeTextField
|
id: junkPacketMinSizeTextField
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.topMargin: 16
|
|
||||||
|
|
||||||
headerText: qsTr("Jmin - Junk packet minimum size")
|
headerText: qsTr("Jmin - Junk packet minimum size")
|
||||||
textField.text: serverJunkPacketMinSize
|
textField.text: serverJunkPacketMinSize
|
||||||
textField.validator: IntValidator { bottom: 0 }
|
|
||||||
|
|
||||||
textField.onEditingFinished: {
|
textField.onEditingFinished: {
|
||||||
if (textField.text !== serverJunkPacketMinSize) {
|
if (textField.text !== serverJunkPacketMinSize) {
|
||||||
serverJunkPacketMinSize = textField.text
|
serverJunkPacketMinSize = textField.text
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
checkEmptyText: true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TextFieldWithHeaderType {
|
AwgTextField {
|
||||||
id: junkPacketMaxSizeTextField
|
id: junkPacketMaxSizeTextField
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.topMargin: 16
|
|
||||||
|
|
||||||
headerText: qsTr("Jmax - Junk packet maximum size")
|
headerText: qsTr("Jmax - Junk packet maximum size")
|
||||||
textField.text: serverJunkPacketMaxSize
|
textField.text: serverJunkPacketMaxSize
|
||||||
textField.validator: IntValidator { bottom: 0 }
|
|
||||||
|
|
||||||
textField.onEditingFinished: {
|
textField.onEditingFinished: {
|
||||||
if (textField.text !== serverJunkPacketMaxSize) {
|
if (textField.text !== serverJunkPacketMaxSize) {
|
||||||
serverJunkPacketMaxSize = textField.text
|
serverJunkPacketMaxSize = textField.text
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
checkEmptyText: true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TextFieldWithHeaderType {
|
AwgTextField {
|
||||||
id: initPacketJunkSizeTextField
|
id: initPacketJunkSizeTextField
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.topMargin: 16
|
|
||||||
|
|
||||||
headerText: qsTr("S1 - Init packet junk size")
|
headerText: qsTr("S1 - Init packet junk size")
|
||||||
textField.text: serverInitPacketJunkSize
|
textField.text: serverInitPacketJunkSize
|
||||||
textField.validator: IntValidator { bottom: 0 }
|
|
||||||
|
|
||||||
textField.onEditingFinished: {
|
textField.onEditingFinished: {
|
||||||
if (textField.text !== serverInitPacketJunkSize) {
|
if (textField.text !== serverInitPacketJunkSize) {
|
||||||
serverInitPacketJunkSize = textField.text
|
serverInitPacketJunkSize = textField.text
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
checkEmptyText: true
|
|
||||||
|
|
||||||
onActiveFocusChanged: {
|
|
||||||
if(activeFocus) {
|
|
||||||
listview.positionViewAtEnd()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TextFieldWithHeaderType {
|
AwgTextField {
|
||||||
id: responsePacketJunkSizeTextField
|
id: responsePacketJunkSizeTextField
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.topMargin: 16
|
|
||||||
|
|
||||||
headerText: qsTr("S2 - Response packet junk size")
|
headerText: qsTr("S2 - Response packet junk size")
|
||||||
textField.text: serverResponsePacketJunkSize
|
textField.text: serverResponsePacketJunkSize
|
||||||
textField.validator: IntValidator { bottom: 0 }
|
|
||||||
|
|
||||||
textField.onEditingFinished: {
|
textField.onEditingFinished: {
|
||||||
if (textField.text !== serverResponsePacketJunkSize) {
|
if (textField.text !== serverResponsePacketJunkSize) {
|
||||||
serverResponsePacketJunkSize = textField.text
|
serverResponsePacketJunkSize = textField.text
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
checkEmptyText: true
|
|
||||||
|
|
||||||
onActiveFocusChanged: {
|
|
||||||
if(activeFocus) {
|
|
||||||
listview.positionViewAtEnd()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TextFieldWithHeaderType {
|
// AwgTextField {
|
||||||
id: initPacketMagicHeaderTextField
|
// id: cookieReplyPacketJunkSizeTextField
|
||||||
Layout.fillWidth: true
|
// headerText: qsTr("S3 - Cookie reply packet junk size")
|
||||||
Layout.topMargin: 16
|
// textField.text: serverCookieReplyPacketJunkSize
|
||||||
|
|
||||||
|
// textField.onEditingFinished: {
|
||||||
|
// if (textField.text !== serverCookieReplyPacketJunkSize) {
|
||||||
|
// serverCookieReplyPacketJunkSize = textField.text
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// AwgTextField {
|
||||||
|
// id: transportPacketJunkSizeTextField
|
||||||
|
// headerText: qsTr("S4 - Transport packet junk size")
|
||||||
|
// textField.text: serverTransportPacketJunkSize
|
||||||
|
|
||||||
|
// textField.onEditingFinished: {
|
||||||
|
// if (textField.text !== serverTransportPacketJunkSize) {
|
||||||
|
// serverTransportPacketJunkSize = textField.text
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
AwgTextField {
|
||||||
|
id: initPacketMagicHeaderTextField
|
||||||
headerText: qsTr("H1 - Init packet magic header")
|
headerText: qsTr("H1 - Init packet magic header")
|
||||||
textField.text: serverInitPacketMagicHeader
|
textField.text: serverInitPacketMagicHeader
|
||||||
textField.validator: IntValidator { bottom: 0 }
|
|
||||||
|
|
||||||
textField.onEditingFinished: {
|
textField.onEditingFinished: {
|
||||||
if (textField.text !== serverInitPacketMagicHeader) {
|
if (textField.text !== serverInitPacketMagicHeader) {
|
||||||
serverInitPacketMagicHeader = textField.text
|
serverInitPacketMagicHeader = textField.text
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
checkEmptyText: true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TextFieldWithHeaderType {
|
AwgTextField {
|
||||||
id: responsePacketMagicHeaderTextField
|
id: responsePacketMagicHeaderTextField
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.topMargin: 16
|
|
||||||
|
|
||||||
headerText: qsTr("H2 - Response packet magic header")
|
headerText: qsTr("H2 - Response packet magic header")
|
||||||
textField.text: serverResponsePacketMagicHeader
|
textField.text: serverResponsePacketMagicHeader
|
||||||
textField.validator: IntValidator { bottom: 0 }
|
|
||||||
|
|
||||||
textField.onEditingFinished: {
|
textField.onEditingFinished: {
|
||||||
if (textField.text !== serverResponsePacketMagicHeader) {
|
if (textField.text !== serverResponsePacketMagicHeader) {
|
||||||
serverResponsePacketMagicHeader = textField.text
|
serverResponsePacketMagicHeader = textField.text
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
checkEmptyText: true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TextFieldWithHeaderType {
|
AwgTextField {
|
||||||
id: transportPacketMagicHeaderTextField
|
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.topMargin: 16
|
|
||||||
|
|
||||||
headerText: qsTr("H4 - Transport packet magic header")
|
|
||||||
textField.text: serverTransportPacketMagicHeader
|
|
||||||
textField.validator: IntValidator { bottom: 0 }
|
|
||||||
|
|
||||||
textField.onEditingFinished: {
|
|
||||||
if (textField.text !== serverTransportPacketMagicHeader) {
|
|
||||||
serverTransportPacketMagicHeader = textField.text
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
checkEmptyText: true
|
|
||||||
}
|
|
||||||
|
|
||||||
TextFieldWithHeaderType {
|
|
||||||
id: underloadPacketMagicHeaderTextField
|
id: underloadPacketMagicHeaderTextField
|
||||||
Layout.fillWidth: true
|
|
||||||
Layout.topMargin: 16
|
|
||||||
|
|
||||||
headerText: qsTr("H3 - Underload packet magic header")
|
headerText: qsTr("H3 - Underload packet magic header")
|
||||||
textField.text: serverUnderloadPacketMagicHeader
|
textField.text: serverUnderloadPacketMagicHeader
|
||||||
textField.validator: IntValidator { bottom: 0 }
|
|
||||||
|
|
||||||
textField.onEditingFinished: {
|
textField.onEditingFinished: {
|
||||||
if (textField.text !== serverUnderloadPacketMagicHeader) {
|
if (textField.text !== serverUnderloadPacketMagicHeader) {
|
||||||
serverUnderloadPacketMagicHeader = textField.text
|
serverUnderloadPacketMagicHeader = textField.text
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
checkEmptyText: true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AwgTextField {
|
||||||
|
id: transportPacketMagicHeaderTextField
|
||||||
|
headerText: qsTr("H4 - Transport packet magic header")
|
||||||
|
textField.text: serverTransportPacketMagicHeader
|
||||||
|
|
||||||
|
textField.onEditingFinished: {
|
||||||
|
if (textField.text !== serverTransportPacketMagicHeader) {
|
||||||
|
serverTransportPacketMagicHeader = textField.text
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
BasicButtonType {
|
BasicButtonType {
|
||||||
id: saveRestartButton
|
id: saveRestartButton
|
||||||
|
|
||||||
|
|
@ -328,6 +283,8 @@ PageType {
|
||||||
responsePacketMagicHeaderTextField.errorText === "" &&
|
responsePacketMagicHeaderTextField.errorText === "" &&
|
||||||
initPacketMagicHeaderTextField.errorText === "" &&
|
initPacketMagicHeaderTextField.errorText === "" &&
|
||||||
responsePacketJunkSizeTextField.errorText === "" &&
|
responsePacketJunkSizeTextField.errorText === "" &&
|
||||||
|
// cookieReplyHeaderJunkTextField.errorText === "" &&
|
||||||
|
// transportHeaderJunkTextField.errorText === "" &&
|
||||||
initPacketJunkSizeTextField.errorText === "" &&
|
initPacketJunkSizeTextField.errorText === "" &&
|
||||||
junkPacketMaxSizeTextField.errorText === "" &&
|
junkPacketMaxSizeTextField.errorText === "" &&
|
||||||
junkPacketMinSizeTextField.errorText === "" &&
|
junkPacketMinSizeTextField.errorText === "" &&
|
||||||
|
|
@ -360,6 +317,13 @@ PageType {
|
||||||
PageController.showErrorMessage(qsTr("The value of the field S1 + message initiation size (148) must not equal S2 + message response size (92)"))
|
PageController.showErrorMessage(qsTr("The value of the field S1 + message initiation size (148) must not equal S2 + message response size (92)"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// if (AwgConfigModel.isPacketSizeEqual(parseInt(initPacketJunkSizeTextField.textField.text),
|
||||||
|
// parseInt(responsePacketJunkSizeTextField.textField.text),
|
||||||
|
// parseInt(cookieReplyPacketJunkSizeTextField.textField.text),
|
||||||
|
// parseInt(transportPacketJunkSizeTextField.textField.text))) {
|
||||||
|
// PageController.showErrorMessage(qsTr("The value of the field S1 + message initiation size (148) must not equal S2 + message response size (92) + S3 + cookie reply size (64) + S4 + transport packet size (32)"))
|
||||||
|
// return
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
var headerText = qsTr("Save settings?")
|
var headerText = qsTr("Save settings?")
|
||||||
|
|
|
||||||
|
|
@ -59,10 +59,13 @@ PageType {
|
||||||
model: CloakConfigModel
|
model: CloakConfigModel
|
||||||
|
|
||||||
delegate: Item {
|
delegate: Item {
|
||||||
implicitWidth: listview.width
|
id: delegateItem
|
||||||
implicitHeight: col.implicitHeight
|
|
||||||
|
|
||||||
property alias trafficFromField: trafficFromField
|
property alias trafficFromField: trafficFromField
|
||||||
|
property bool isEnabled: ServersModel.isProcessedServerHasWriteAccess()
|
||||||
|
|
||||||
|
implicitWidth: listview.width
|
||||||
|
implicitHeight: col.implicitHeight
|
||||||
|
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
id: col
|
id: col
|
||||||
|
|
@ -78,7 +81,6 @@ PageType {
|
||||||
|
|
||||||
BaseHeaderType {
|
BaseHeaderType {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
|
|
||||||
headerText: qsTr("Cloak settings")
|
headerText: qsTr("Cloak settings")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -88,6 +90,8 @@ PageType {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.topMargin: 32
|
Layout.topMargin: 32
|
||||||
|
|
||||||
|
enabled: delegateItem.isEnabled
|
||||||
|
|
||||||
headerText: qsTr("Disguised as traffic from")
|
headerText: qsTr("Disguised as traffic from")
|
||||||
textField.text: site
|
textField.text: site
|
||||||
|
|
||||||
|
|
@ -104,6 +108,8 @@ PageType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkEmptyText: true
|
||||||
}
|
}
|
||||||
|
|
||||||
TextFieldWithHeaderType {
|
TextFieldWithHeaderType {
|
||||||
|
|
@ -112,6 +118,8 @@ PageType {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.topMargin: 16
|
Layout.topMargin: 16
|
||||||
|
|
||||||
|
enabled: delegateItem.isEnabled
|
||||||
|
|
||||||
headerText: qsTr("Port")
|
headerText: qsTr("Port")
|
||||||
textField.text: port
|
textField.text: port
|
||||||
textField.maximumLength: 5
|
textField.maximumLength: 5
|
||||||
|
|
@ -122,6 +130,8 @@ PageType {
|
||||||
port = textField.text
|
port = textField.text
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkEmptyText: true
|
||||||
}
|
}
|
||||||
|
|
||||||
DropDownType {
|
DropDownType {
|
||||||
|
|
@ -129,6 +139,8 @@ PageType {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.topMargin: 16
|
Layout.topMargin: 16
|
||||||
|
|
||||||
|
enabled: delegateItem.isEnabled
|
||||||
|
|
||||||
descriptionText: qsTr("Cipher")
|
descriptionText: qsTr("Cipher")
|
||||||
headerText: qsTr("Cipher")
|
headerText: qsTr("Cipher")
|
||||||
|
|
||||||
|
|
@ -166,25 +178,46 @@ PageType {
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicButtonType {
|
BasicButtonType {
|
||||||
id: saveRestartButton
|
id: saveButton
|
||||||
|
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.topMargin: 24
|
Layout.topMargin: 24
|
||||||
Layout.bottomMargin: 24
|
Layout.bottomMargin: 24
|
||||||
|
|
||||||
|
enabled: trafficFromField.errorText === "" &&
|
||||||
|
portTextField.errorText === ""
|
||||||
|
|
||||||
text: qsTr("Save")
|
text: qsTr("Save")
|
||||||
|
|
||||||
clickedFunc: function() {
|
clickedFunc: function() {
|
||||||
forceActiveFocus()
|
forceActiveFocus()
|
||||||
|
|
||||||
if (ConnectionController.isConnected && ServersModel.getDefaultServerData("defaultContainer") === ContainersModel.getProcessedContainerIndex()) {
|
var headerText = qsTr("Save settings?")
|
||||||
PageController.showNotificationMessage(qsTr("Unable change settings while there is an active connection"))
|
var descriptionText = qsTr("All users with whom you shared a connection with will no longer be able to connect to it.")
|
||||||
return
|
var yesButtonText = qsTr("Continue")
|
||||||
|
var noButtonText = qsTr("Cancel")
|
||||||
|
|
||||||
|
var yesButtonFunction = function() {
|
||||||
|
if (ConnectionController.isConnected && ServersModel.getDefaultServerData("defaultContainer") === ContainersModel.getProcessedContainerIndex()) {
|
||||||
|
PageController.showNotificationMessage(qsTr("Unable change settings while there is an active connection"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
PageController.goToPage(PageEnum.PageSetupWizardInstalling)
|
||||||
|
InstallController.updateContainer(CloakConfigModel.getConfig())
|
||||||
}
|
}
|
||||||
|
|
||||||
PageController.goToPage(PageEnum.PageSetupWizardInstalling);
|
var noButtonFunction = function() {
|
||||||
InstallController.updateContainer(CloakConfigModel.getConfig())
|
if (!GC.isMobile()) {
|
||||||
|
saveButton.forceActiveFocus()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
showQuestionDrawer(headerText, descriptionText, yesButtonText, noButtonText, yesButtonFunction, noButtonFunction)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Keys.onEnterPressed: saveButton.clicked()
|
||||||
|
Keys.onReturnPressed: saveButton.clicked()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -58,10 +58,13 @@ PageType {
|
||||||
model: OpenVpnConfigModel
|
model: OpenVpnConfigModel
|
||||||
|
|
||||||
delegate: Item {
|
delegate: Item {
|
||||||
implicitWidth: listview.width
|
id: delegateItem
|
||||||
implicitHeight: col.implicitHeight
|
|
||||||
|
|
||||||
property alias vpnAddressSubnetTextField: vpnAddressSubnetTextField
|
property alias vpnAddressSubnetTextField: vpnAddressSubnetTextField
|
||||||
|
property bool isEnabled: ServersModel.isProcessedServerHasWriteAccess()
|
||||||
|
|
||||||
|
implicitWidth: listview.width
|
||||||
|
implicitHeight: col.implicitHeight
|
||||||
|
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
id: col
|
id: col
|
||||||
|
|
@ -77,7 +80,6 @@ PageType {
|
||||||
|
|
||||||
BaseHeaderType {
|
BaseHeaderType {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
|
|
||||||
headerText: qsTr("OpenVPN settings")
|
headerText: qsTr("OpenVPN settings")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -87,6 +89,8 @@ PageType {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.topMargin: 32
|
Layout.topMargin: 32
|
||||||
|
|
||||||
|
enabled: delegateItem.isEnabled
|
||||||
|
|
||||||
headerText: qsTr("VPN address subnet")
|
headerText: qsTr("VPN address subnet")
|
||||||
textField.text: subnetAddress
|
textField.text: subnetAddress
|
||||||
|
|
||||||
|
|
@ -97,6 +101,8 @@ PageType {
|
||||||
subnetAddress = textField.text
|
subnetAddress = textField.text
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkEmptyText: true
|
||||||
}
|
}
|
||||||
|
|
||||||
ParagraphTextType {
|
ParagraphTextType {
|
||||||
|
|
@ -134,7 +140,7 @@ PageType {
|
||||||
Layout.topMargin: 40
|
Layout.topMargin: 40
|
||||||
parentFlickable: fl
|
parentFlickable: fl
|
||||||
|
|
||||||
enabled: isPortEditable
|
enabled: delegateItem.isEnabled
|
||||||
|
|
||||||
headerText: qsTr("Port")
|
headerText: qsTr("Port")
|
||||||
textField.text: port
|
textField.text: port
|
||||||
|
|
@ -146,6 +152,8 @@ PageType {
|
||||||
port = textField.text
|
port = textField.text
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkEmptyText: true
|
||||||
}
|
}
|
||||||
|
|
||||||
SwitcherType {
|
SwitcherType {
|
||||||
|
|
@ -388,26 +396,45 @@ PageType {
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicButtonType {
|
BasicButtonType {
|
||||||
id: saveRestartButton
|
id: saveButton
|
||||||
|
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.topMargin: 24
|
Layout.topMargin: 24
|
||||||
Layout.bottomMargin: 24
|
Layout.bottomMargin: 24
|
||||||
|
|
||||||
|
enabled: vpnAddressSubnetTextField.errorText === "" &&
|
||||||
|
portTextField.errorText === ""
|
||||||
|
|
||||||
text: qsTr("Save")
|
text: qsTr("Save")
|
||||||
parentFlickable: fl
|
parentFlickable: fl
|
||||||
|
|
||||||
clickedFunc: function() {
|
onClicked: function() {
|
||||||
forceActiveFocus()
|
forceActiveFocus()
|
||||||
|
|
||||||
if (ConnectionController.isConnected && ServersModel.getDefaultServerData("defaultContainer") === ContainersModel.getProcessedContainerIndex()) {
|
var headerText = qsTr("Save settings?")
|
||||||
PageController.showNotificationMessage(qsTr("Unable change settings while there is an active connection"))
|
var descriptionText = qsTr("All users with whom you shared a connection with will no longer be able to connect to it.")
|
||||||
return
|
var yesButtonText = qsTr("Continue")
|
||||||
}
|
var noButtonText = qsTr("Cancel")
|
||||||
|
|
||||||
PageController.goToPage(PageEnum.PageSetupWizardInstalling);
|
var yesButtonFunction = function() {
|
||||||
InstallController.updateContainer(OpenVpnConfigModel.getConfig())
|
if (ConnectionController.isConnected && ServersModel.getDefaultServerData("defaultContainer") === ContainersModel.getProcessedContainerIndex()) {
|
||||||
|
PageController.showNotificationMessage(qsTr("Unable change settings while there is an active connection"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
PageController.goToPage(PageEnum.PageSetupWizardInstalling);
|
||||||
|
InstallController.updateContainer(OpenVpnConfigModel.getConfig())
|
||||||
|
}
|
||||||
|
var noButtonFunction = function() {
|
||||||
|
if (!GC.isMobile()) {
|
||||||
|
saveButton.forceActiveFocus()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
showQuestionDrawer(headerText, descriptionText, yesButtonText, noButtonText, yesButtonFunction, noButtonFunction)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Keys.onEnterPressed: saveButton.clicked()
|
||||||
|
Keys.onReturnPressed: saveButton.clicked()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,15 +57,13 @@ PageType {
|
||||||
model: ShadowSocksConfigModel
|
model: ShadowSocksConfigModel
|
||||||
|
|
||||||
delegate: Item {
|
delegate: Item {
|
||||||
|
id: delegateItem
|
||||||
|
|
||||||
|
property bool isEnabled: ServersModel.isProcessedServerHasWriteAccess()
|
||||||
|
|
||||||
implicitWidth: listview.width
|
implicitWidth: listview.width
|
||||||
implicitHeight: col.implicitHeight
|
implicitHeight: col.implicitHeight
|
||||||
|
|
||||||
property var focusItemId: portTextField.enabled ?
|
|
||||||
portTextField :
|
|
||||||
cipherDropDown.enabled ?
|
|
||||||
cipherDropDown :
|
|
||||||
saveRestartButton
|
|
||||||
|
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
id: col
|
id: col
|
||||||
|
|
||||||
|
|
@ -80,7 +78,6 @@ PageType {
|
||||||
|
|
||||||
BaseHeaderType {
|
BaseHeaderType {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
|
|
||||||
headerText: qsTr("Shadowsocks settings")
|
headerText: qsTr("Shadowsocks settings")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -90,7 +87,7 @@ PageType {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.topMargin: 40
|
Layout.topMargin: 40
|
||||||
|
|
||||||
enabled: isPortEditable
|
enabled: delegateItem.isEnabled
|
||||||
|
|
||||||
headerText: qsTr("Port")
|
headerText: qsTr("Port")
|
||||||
textField.text: port
|
textField.text: port
|
||||||
|
|
@ -102,6 +99,8 @@ PageType {
|
||||||
port = textField.text
|
port = textField.text
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkEmptyText: true
|
||||||
}
|
}
|
||||||
|
|
||||||
DropDownType {
|
DropDownType {
|
||||||
|
|
@ -109,7 +108,7 @@ PageType {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.topMargin: 20
|
Layout.topMargin: 20
|
||||||
|
|
||||||
enabled: isCipherEditable
|
enabled: delegateItem.isEnabled
|
||||||
|
|
||||||
descriptionText: qsTr("Cipher")
|
descriptionText: qsTr("Cipher")
|
||||||
headerText: qsTr("Cipher")
|
headerText: qsTr("Cipher")
|
||||||
|
|
@ -149,27 +148,43 @@ PageType {
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicButtonType {
|
BasicButtonType {
|
||||||
id: saveRestartButton
|
id: saveButton
|
||||||
|
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.topMargin: 24
|
Layout.topMargin: 24
|
||||||
Layout.bottomMargin: 24
|
Layout.bottomMargin: 24
|
||||||
|
|
||||||
enabled: isPortEditable | isCipherEditable
|
enabled: portTextField.errorText === ""
|
||||||
|
|
||||||
text: qsTr("Save")
|
text: qsTr("Save")
|
||||||
|
|
||||||
clickedFunc: function() {
|
clickedFunc: function() {
|
||||||
forceActiveFocus()
|
forceActiveFocus()
|
||||||
|
|
||||||
if (ConnectionController.isConnected && ServersModel.getDefaultServerData("defaultContainer") === ContainersModel.getProcessedContainerIndex()) {
|
var headerText = qsTr("Save settings?")
|
||||||
PageController.showNotificationMessage(qsTr("Unable change settings while there is an active connection"))
|
var descriptionText = qsTr("All users with whom you shared a connection with will no longer be able to connect to it.")
|
||||||
return
|
var yesButtonText = qsTr("Continue")
|
||||||
}
|
var noButtonText = qsTr("Cancel")
|
||||||
|
|
||||||
PageController.goToPage(PageEnum.PageSetupWizardInstalling);
|
var yesButtonFunction = function() {
|
||||||
InstallController.updateContainer(ShadowSocksConfigModel.getConfig())
|
if (ConnectionController.isConnected && ServersModel.getDefaultServerData("defaultContainer") === ContainersModel.getProcessedContainerIndex()) {
|
||||||
|
PageController.showNotificationMessage(qsTr("Unable change settings while there is an active connection"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
PageController.goToPage(PageEnum.PageSetupWizardInstalling);
|
||||||
|
InstallController.updateContainer(ShadowSocksConfigModel.getConfig())
|
||||||
|
}
|
||||||
|
var noButtonFunction = function() {
|
||||||
|
if (!GC.isMobile()) {
|
||||||
|
saveButton.forceActiveFocus()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
showQuestionDrawer(headerText, descriptionText, yesButtonText, noButtonText, yesButtonFunction, noButtonFunction)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Keys.onEnterPressed: saveButton.clicked()
|
||||||
|
Keys.onReturnPressed: saveButton.clicked()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -152,7 +152,7 @@ PageType {
|
||||||
}
|
}
|
||||||
var noButtonFunction = function() {
|
var noButtonFunction = function() {
|
||||||
if (!GC.isMobile()) {
|
if (!GC.isMobile()) {
|
||||||
saveRestartButton.forceActiveFocus()
|
saveButton.forceActiveFocus()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
showQuestionDrawer(headerText, descriptionText, yesButtonText, noButtonText, yesButtonFunction, noButtonFunction)
|
showQuestionDrawer(headerText, descriptionText, yesButtonText, noButtonText, yesButtonFunction, noButtonFunction)
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,10 @@ PageType {
|
||||||
model: XrayConfigModel
|
model: XrayConfigModel
|
||||||
|
|
||||||
delegate: Item {
|
delegate: Item {
|
||||||
|
id: delegateItem
|
||||||
|
|
||||||
property alias focusItemId: textFieldWithHeaderType.textField
|
property alias focusItemId: textFieldWithHeaderType.textField
|
||||||
|
property bool isEnabled: ServersModel.isProcessedServerHasWriteAccess()
|
||||||
|
|
||||||
implicitWidth: listview.width
|
implicitWidth: listview.width
|
||||||
implicitHeight: col.implicitHeight
|
implicitHeight: col.implicitHeight
|
||||||
|
|
@ -85,6 +88,8 @@ PageType {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.topMargin: 32
|
Layout.topMargin: 32
|
||||||
|
|
||||||
|
enabled: delegateItem.isEnabled
|
||||||
|
|
||||||
headerText: qsTr("Disguised as traffic from")
|
headerText: qsTr("Disguised as traffic from")
|
||||||
textField.text: site
|
textField.text: site
|
||||||
|
|
||||||
|
|
@ -101,6 +106,8 @@ PageType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkEmptyText: true
|
||||||
}
|
}
|
||||||
|
|
||||||
TextFieldWithHeaderType {
|
TextFieldWithHeaderType {
|
||||||
|
|
@ -130,23 +137,38 @@ PageType {
|
||||||
Layout.topMargin: 24
|
Layout.topMargin: 24
|
||||||
Layout.bottomMargin: 24
|
Layout.bottomMargin: 24
|
||||||
|
|
||||||
|
enabled: portTextField.errorText === ""
|
||||||
|
|
||||||
text: qsTr("Save")
|
text: qsTr("Save")
|
||||||
|
|
||||||
onClicked: {
|
onClicked: function() {
|
||||||
forceActiveFocus()
|
forceActiveFocus()
|
||||||
|
|
||||||
if (ConnectionController.isConnected && ServersModel.getDefaultServerData("defaultContainer") === ContainersModel.getProcessedContainerIndex()) {
|
var headerText = qsTr("Save settings?")
|
||||||
PageController.showNotificationMessage(qsTr("Unable change settings while there is an active connection"))
|
var descriptionText = qsTr("All users with whom you shared a connection with will no longer be able to connect to it.")
|
||||||
return
|
var yesButtonText = qsTr("Continue")
|
||||||
}
|
var noButtonText = qsTr("Cancel")
|
||||||
|
|
||||||
PageController.goToPage(PageEnum.PageSetupWizardInstalling);
|
var yesButtonFunction = function() {
|
||||||
InstallController.updateContainer(XrayConfigModel.getConfig())
|
if (ConnectionController.isConnected && ServersModel.getDefaultServerData("defaultContainer") === ContainersModel.getProcessedContainerIndex()) {
|
||||||
focusItem.forceActiveFocus()
|
PageController.showNotificationMessage(qsTr("Unable change settings while there is an active connection"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
PageController.goToPage(PageEnum.PageSetupWizardInstalling);
|
||||||
|
InstallController.updateContainer(XrayConfigModel.getConfig())
|
||||||
|
//focusItem.forceActiveFocus()
|
||||||
|
}
|
||||||
|
var noButtonFunction = function() {
|
||||||
|
if (!GC.isMobile()) {
|
||||||
|
saveButton.forceActiveFocus()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
showQuestionDrawer(headerText, descriptionText, yesButtonText, noButtonText, yesButtonFunction, noButtonFunction)
|
||||||
}
|
}
|
||||||
|
|
||||||
Keys.onEnterPressed: basicButton.clicked()
|
Keys.onEnterPressed: saveButton.clicked()
|
||||||
Keys.onReturnPressed: basicButton.clicked()
|
Keys.onReturnPressed: saveButton.clicked()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -158,6 +158,32 @@ PageType {
|
||||||
|
|
||||||
readonly property bool isVisibleForAmneziaFree: ApiAccountInfoModel.data("isComponentVisible")
|
readonly property bool isVisibleForAmneziaFree: ApiAccountInfoModel.data("isComponentVisible")
|
||||||
|
|
||||||
|
SwitcherType {
|
||||||
|
id: switcher
|
||||||
|
|
||||||
|
readonly property bool isVlessProtocol: ApiConfigsController.isVlessProtocol()
|
||||||
|
|
||||||
|
Layout.fillWidth: true
|
||||||
|
Layout.topMargin: 24
|
||||||
|
Layout.rightMargin: 16
|
||||||
|
Layout.leftMargin: 16
|
||||||
|
|
||||||
|
visible: ApiAccountInfoModel.data("isProtocolSelectionSupported")
|
||||||
|
|
||||||
|
text: qsTr("Use VLESS protocol")
|
||||||
|
checked: switcher.isVlessProtocol
|
||||||
|
onToggled: function() {
|
||||||
|
if (ServersModel.isDefaultServerCurrentlyProcessed() && ConnectionController.isConnected) {
|
||||||
|
PageController.showNotificationMessage(qsTr("Cannot change protocol during active connection"))
|
||||||
|
} else {
|
||||||
|
PageController.showBusyIndicator(true)
|
||||||
|
ApiConfigsController.setCurrentProtocol(switcher.isVlessProtocol ? "awg" : "vless")
|
||||||
|
ApiConfigsController.updateServiceFromGateway(ServersModel.processedIndex, "", "", true)
|
||||||
|
PageController.showBusyIndicator(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
WarningType {
|
WarningType {
|
||||||
id: warning
|
id: warning
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,8 @@ PageType {
|
||||||
Layout.rightMargin: 16
|
Layout.rightMargin: 16
|
||||||
|
|
||||||
visible: false
|
visible: false
|
||||||
enabled: false //SettingsController.isKillSwitchEnabled && !ConnectionController.isConnected
|
enabled: false
|
||||||
|
// enabled: SettingsController.isKillSwitchEnabled && !ConnectionController.isConnected
|
||||||
checked: SettingsController.strictKillSwitchEnabled
|
checked: SettingsController.strictKillSwitchEnabled
|
||||||
|
|
||||||
text: qsTr("Strict KillSwitch")
|
text: qsTr("Strict KillSwitch")
|
||||||
|
|
|
||||||
|
|
@ -260,7 +260,7 @@ PageType {
|
||||||
|
|
||||||
LabelWithButtonType {
|
LabelWithButtonType {
|
||||||
id: labelWithButton6
|
id: labelWithButton6
|
||||||
visible: ServersModel.getProcessedServerData("isServerFromTelegramApi")
|
visible: ServersModel.getProcessedServerData("isServerFromTelegramApi") && ServersModel.processedServerIsPremium
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
|
|
||||||
text: qsTr("Switch to the new Amnezia Premium subscription")
|
text: qsTr("Switch to the new Amnezia Premium subscription")
|
||||||
|
|
@ -273,7 +273,7 @@ PageType {
|
||||||
}
|
}
|
||||||
|
|
||||||
DividerType {
|
DividerType {
|
||||||
visible: ServersModel.getProcessedServerData("isServerFromTelegramApi")
|
visible: ServersModel.getProcessedServerData("isServerFromTelegramApi") && ServersModel.processedServerIsPremium
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,10 @@ PageType {
|
||||||
|
|
||||||
clickedFunction: function() {
|
clickedFunction: function() {
|
||||||
if (isClientProtocolExists) {
|
if (isClientProtocolExists) {
|
||||||
ProtocolsModel.updateProtocolModel(protocolIndex)
|
switch (protocolIndex) {
|
||||||
|
case ProtocolEnum.WireGuard: WireGuardConfigModel.updateModel(ProtocolsModel.getConfig()); break;
|
||||||
|
case ProtocolEnum.Awg: AwgConfigModel.updateModel(ProtocolsModel.getConfig()); break;
|
||||||
|
}
|
||||||
PageController.goToPage(clientProtocolPage);
|
PageController.goToPage(clientProtocolPage);
|
||||||
} else {
|
} else {
|
||||||
PageController.showNotificationMessage(qsTr("Click the \"connect\" button to create a connection configuration"))
|
PageController.showNotificationMessage(qsTr("Click the \"connect\" button to create a connection configuration"))
|
||||||
|
|
@ -129,7 +132,17 @@ PageType {
|
||||||
visible: delegateContent.isServerSettingsVisible
|
visible: delegateContent.isServerSettingsVisible
|
||||||
|
|
||||||
clickedFunction: function() {
|
clickedFunction: function() {
|
||||||
ProtocolsModel.updateProtocolModel(protocolIndex)
|
switch (protocolIndex) {
|
||||||
|
case ProtocolEnum.OpenVpn: OpenVpnConfigModel.updateModel(ProtocolsModel.getConfig()); break;
|
||||||
|
case ProtocolEnum.ShadowSocks: ShadowSocksConfigModel.updateModel(ProtocolsModel.getConfig()); break;
|
||||||
|
case ProtocolEnum.Cloak: CloakConfigModel.updateModel(ProtocolsModel.getConfig()); break;
|
||||||
|
case ProtocolEnum.WireGuard: WireGuardConfigModel.updateModel(ProtocolsModel.getConfig()); break;
|
||||||
|
case ProtocolEnum.Awg: AwgConfigModel.updateModel(ProtocolsModel.getConfig()); break;
|
||||||
|
case ProtocolEnum.Xray: XrayConfigModel.updateModel(ProtocolsModel.getConfig()); break;
|
||||||
|
case ProtocolEnum.Sftp: SftpConfigModel.updateModel(ProtocolsModel.getConfig()); break;
|
||||||
|
case ProtocolEnum.Ipsec: Ikev2ConfigModel.updateModel(ProtocolsModel.getConfig()); break;
|
||||||
|
case ProtocolEnum.Socks5Proxy: Socks5ProxyConfigModel.updateModel(ProtocolsModel.getConfig()); break;
|
||||||
|
}
|
||||||
PageController.goToPage(serverProtocolPage);
|
PageController.goToPage(serverProtocolPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -429,6 +429,11 @@ PageType {
|
||||||
|
|
||||||
fillConnectionTypeModel()
|
fillConnectionTypeModel()
|
||||||
|
|
||||||
|
if (exportTypeSelector.currentIndex >= root.connectionTypesModel.length) {
|
||||||
|
exportTypeSelector.currentIndex = 0
|
||||||
|
exportTypeSelector.text = root.connectionTypesModel[0].name
|
||||||
|
}
|
||||||
|
|
||||||
if (accessTypeSelector.currentIndex === 1) {
|
if (accessTypeSelector.currentIndex === 1) {
|
||||||
PageController.showBusyIndicator(true)
|
PageController.showBusyIndicator(true)
|
||||||
ExportController.updateClientManagementModel(ContainersModel.getProcessedContainerIndex(),
|
ExportController.updateClientManagementModel(ContainersModel.getProcessedContainerIndex(),
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue