refactor: refactor the application to the mvvm architecture (#2009)

* refactor: move business logic from servers model

* refactor: move containersModel initialization

* refactor: added protocol ui controller and removed settings class from protocols model

* refactor: moved cli management to separate controller

* refactor: moved app split to separate controller

* refactor: moved site split to separate controller

* refactor: moved allowed dns to separate controller

* refactor: moved language logic to separate ui controller

* refactor: removed Settings from devices model

* refactor: moved configs and services api logit to separate core controller

* refactor: added a layer with a repository between the storage and controllers

* refactor: use child parent system instead of smart pointers for controllers and models initialization

* refactor: moved install functions from server controller to install controller

* refactor: install controller refactoring

* chore: renamed exportController to exportUiController

* refactor: separate export controller

* refactor: removed VpnConfigurationsController

* chore: renamed ServerController to SshSession

* refactor: replaced ServerController to SshSession

* chore: moved qml controllers to separate folder

* chore: include fixes

* chore: moved utils from core root to core/utils

* chore: include fixes

* chore: rename core/utils files to camelCase foramt

* chore: include fixes

* chore: moved some utils to api and selfhosted folders

* chore: include fixes

* chore: remove unused file

* chore: moved serialization folder to core/utils

* chore: include fixes

* chore: moved some files from client root to core/utils

* chore: include fixes

* chore: moved ui utils to ui/utils folder

* chore: include fixes

* chore: move utils from root to ui/utils

* chore: include fixes

* chore: moved configurators to core/configurators

* chore: include fixes

* refactor: moved iap logic from ui controller to core

* refactor: moved remaining core logic from ApiConfigsController to SubscriptionController

* chore: rename apiNewsController to apiNewsUiController

* refactor: moved core logic from news ui controller to core

* chore: renamed apiConfigsController to subscriptionUiController

* chore: include fixes

* refactor: merge ApiSettingsController with SubscriptionUiController

* chore: moved ui selfhosted controllers to separate folder

* chore: include fixes

* chore: rename connectionController to connectiomUiController

* refactor: moved core logic from connectionUiController

* chore: rename settingsController to settingsUiController

* refactor: move core logic from settingsUiController

* refactor: moved core controller signal/slot connections to separate class

* fix: newsController fixes after refactoring

* chore: rename model to camelCase

* chore: include fixes

* chore: remove unused code

* chore: move selfhosted core to separate folder

* chore: include fixes

* chore: rename importController to importUiController

* refactor: move core logic from importUiController

* chore: minor fixes

* chore: remove prem v1 migration

* refactor: remove openvpn over cloak and openvpn over shadowsocks

* refactor: removed protocolsForContainer function

* refactor: add core models

* refactor: replace json with c++ structs for server config

* refactor: move getDnsPair to ServerConfigUtils

* feat: add admin selfhosted config export test

* feat: add multi import test

* refactor: use coreController for tests

* feat: add few simple tests

* chore: qrepos in all core controllers

* feat: add test for settings

* refactor: remove repo dependency from configurators

* chore: moved protocols to core folder

* chore: include fixes

* refactor: moved containersDefs, defs, apiDefs, protocolsDefs to different places

* chore: include fixes

* chore: build fixes

* chore: build fixes

* refactor: remove q repo and interface repo

* feat: add test for ui servers model and controller

* chore: renamed to camelCase

* chore: include fixes

* refactor: moved core logic from sites ui controller

* fix: fixed api config processing

* fix: fixed processed server index processing

* refactor: protocol models now use c++ structs instead of json configs

* refactor: servers model now use c++ struct instead of json config

* fix: fixed default server index processing

* fix: fix logs init

* fix: fix secure settings load keys

* chore: build fixes

* fix: fixed clear settings

* fix: fixed restore backup

* fix: sshSession usage

* fix: fixed export functions signatures

* fix: return missing part from buildContainerWorker

* fix: fixed server description on page home

* refactor: add container config helpers functions

* refactor: c++ structs instead of json

* chore: add dns protocol config struct

* refactor: move config utils functions to config structs

* feat: add test for selfhosted server setup

* refactor: separate resources.qrc

* fix: fixed server rename

* chore: return nameOverriddenByUser

* fix: build fixes

* fix: fixed models init

* refactor: cleanup models usage

* fix: fixed models init

* chore: cleanup connections and functions signatures

* chore: cleanup updateModel calls

* feat: added cache to servers repo

* chore: cleanup unused functions

* chore: ssxray processing

* chore: remove transportProtoWithDefault and portWithDefault functions

* chore: removed proto types any and l2tp

* refactor: moved some constants

* fix: fixed native configs export

* refactor: remove json from processConfigWith functions

* fix: fixed processed server index usage

* fix: qml warning fixes

* chore: merge fixes

* chore: update tests

* fix: fixed xray config processing

* fix: fixed split tunneling processing

* chore: rename sites controllers and model

* chore: rename fixes

* chore: minor fixes

* chore: remove ability to load backup from "file with connection settings" button

* fix: fixed api device revoke

* fix: remove full model update when renaming a user

* fix: fixed premium/free server rename

* fix: fixed selfhosted new server install

* fix: fixed updateContainer function

* fix: fixed revoke for external premium configs

* feat: add native configs qr processing

* chore: codestyle fixes

* fix: fixed admin config create

* chore: again remove ability to load backup from "file with connection settings" button

* chore: minor fixes

* fix: fixed variables initialization

* fix: fixed qml imports

* fix: minor fixes

* fix: fix vpnConnection function calls

* feat: add buckup error handling

* fix: fixed admin config revok

* fix: fixed selfhosted awg installation

* fix: ad visability

* feat: add empty check for primary dns

* chore: minor fixes
This commit is contained in:
vkamn
2026-04-30 14:53:03 +08:00
committed by GitHub
parent 2edd7de413
commit 847bb6923b
469 changed files with 25992 additions and 17154 deletions
@@ -0,0 +1,11 @@
#ifndef APICONSTANTS_H
#define APICONSTANTS_H
namespace apiDefs
{
const int requestTimeoutMsecs = 12 * 1000; // 12 secs
}
#endif // APICONSTANTS_H
+88
View File
@@ -0,0 +1,88 @@
#ifndef APIKEYS_H
#define APIKEYS_H
#include <QLatin1String>
#include "core/utils/api/apiEnums.h"
namespace apiDefs
{
namespace key
{
constexpr QLatin1String apiEndpoint("api_endpoint");
constexpr QLatin1String apiKey("api_key");
constexpr QLatin1String protocol("protocol");
constexpr QLatin1String apiConfig("api_config");
constexpr QLatin1String serviceType("service_type");
constexpr QLatin1String serviceInfo("service_info");
constexpr QLatin1String serviceProtocol("service_protocol");
constexpr QLatin1String vpnKey("vpn_key");
constexpr QLatin1String stackType("stack_type");
constexpr QLatin1String cliVersion("cli_version");
constexpr QLatin1String cliName("cli_name");
constexpr QLatin1String supportedProtocols("supported_protocols");
constexpr QLatin1String availableCountries("available_countries");
constexpr QLatin1String installationUuid("installation_uuid");
constexpr QLatin1String uuid("installation_uuid");
constexpr QLatin1String osVersion("os_version");
constexpr QLatin1String userCountryCode("user_country_code");
constexpr QLatin1String serverCountryCode("server_country_code");
constexpr QLatin1String serverCountryName("server_country_name");
constexpr QLatin1String appVersion("app_version");
constexpr QLatin1String authData("auth_data");
constexpr QLatin1String aesKey("aes_key");
constexpr QLatin1String aesIv("aes_iv");
constexpr QLatin1String aesSalt("aes_salt");
constexpr QLatin1String apiPayload("api_payload");
constexpr QLatin1String keyPayload("key_payload");
constexpr QLatin1String services("services");
constexpr QLatin1String workerLastUpdated("worker_last_updated");
constexpr QLatin1String lastDownloaded("last_downloaded");
constexpr QLatin1String sourceType("source_type");
constexpr QLatin1String appLanguage("app_language");
constexpr QLatin1String activeDeviceCount("active_device_count");
constexpr QLatin1String maxDeviceCount("max_device_count");
constexpr QLatin1String subscriptionEndDate("subscription_end_date");
constexpr QLatin1String subscriptionExpiredByServer("subscription_expired_by_server");
constexpr QLatin1String subscriptionStatus("subscription_status");
constexpr QLatin1String subscription("subscription");
constexpr QLatin1String endDate("end_date");
constexpr QLatin1String issuedConfigs("issued_configs");
constexpr QLatin1String subscriptionDescription("subscription_description");
constexpr QLatin1String termsOfUseUrl("terms_of_use_url");
constexpr QLatin1String privacyPolicyUrl("privacy_policy_url");
constexpr QLatin1String supportInfo("support_info");
constexpr QLatin1String email("email");
constexpr QLatin1String billingEmail("billing_email");
constexpr QLatin1String website("website");
constexpr QLatin1String websiteName("website_name");
constexpr QLatin1String telegram("telegram");
constexpr QLatin1String id("id");
constexpr QLatin1String orderId("order_id");
constexpr QLatin1String migrationCode("migration_code");
constexpr QLatin1String transactionId("transaction_id");
constexpr QLatin1String isTestPurchase("is_test_purchase");
constexpr QLatin1String isInAppPurchase("is_in_app_purchase");
constexpr QLatin1String config("config");
constexpr QLatin1String isAdVisible("is_ad_visible");
constexpr QLatin1String isRenewalAvailable("is_renewal_available");
constexpr QLatin1String adHeader("ad_header");
constexpr QLatin1String adDescription("ad_description");
constexpr QLatin1String adEndpoint("ad_endpoint");
constexpr QLatin1String configs("configs");
constexpr QLatin1String publicKeyInfo("public_key");
constexpr QLatin1String publicKey("public_key");
constexpr QLatin1String expiresAt("expires_at");
constexpr QLatin1String isConnectEvent("is_connect_event");
constexpr QLatin1String certificate("certificate");
}
}
#endif // APIKEYS_H
+127
View File
@@ -0,0 +1,127 @@
#ifndef CONFIGKEYS_H
#define CONFIGKEYS_H
#include <QLatin1String>
namespace amnezia
{
namespace configKey
{
constexpr QLatin1String hostName("hostName");
constexpr QLatin1String userName("userName");
constexpr QLatin1String password("password");
constexpr QLatin1String port("port");
constexpr QLatin1String localPort("local_port");
constexpr QLatin1String dns1("dns1");
constexpr QLatin1String dns2("dns2");
constexpr QLatin1String serverIndex("serverIndex");
constexpr QLatin1String description("description");
constexpr QLatin1String name("name");
constexpr QLatin1String cert("cert");
constexpr QLatin1String accessToken("api_key");
constexpr QLatin1String config("config");
constexpr QLatin1String configVersion("config_version");
constexpr QLatin1String containers("containers");
constexpr QLatin1String container("container");
constexpr QLatin1String defaultContainer("defaultContainer");
constexpr QLatin1String vpnProto("protocol");
constexpr QLatin1String protocol("protocol");
constexpr QLatin1String protocols("protocols");
constexpr QLatin1String remote("remote");
constexpr QLatin1String transportProto("transport_proto");
constexpr QLatin1String cipher("cipher");
constexpr QLatin1String hash("hash");
constexpr QLatin1String ncpDisable("ncp_disable");
constexpr QLatin1String tlsAuth("tls_auth");
constexpr QLatin1String clientPrivKey("client_priv_key");
constexpr QLatin1String clientPubKey("client_pub_key");
constexpr QLatin1String serverPrivKey("server_priv_key");
constexpr QLatin1String serverPubKey("server_pub_key");
constexpr QLatin1String pskKey("psk_key");
constexpr QLatin1String mtu("mtu");
constexpr QLatin1String allowedIps("allowed_ips");
constexpr QLatin1String persistentKeepAlive("persistent_keep_alive");
constexpr QLatin1String clientIp("client_ip");
constexpr QLatin1String site("site");
constexpr QLatin1String blockOutsideDns("block_outside_dns");
constexpr QLatin1String subnetAddress("subnet_address");
constexpr QLatin1String subnetMask("subnet_mask");
constexpr QLatin1String subnetCidr("subnet_cidr");
constexpr QLatin1String additionalClientConfig("additional_client_config");
constexpr QLatin1String additionalServerConfig("additional_server_config");
constexpr QLatin1String lastConfig("last_config");
constexpr QLatin1String isThirdPartyConfig("isThirdPartyConfig");
constexpr QLatin1String isObfuscationEnabled("isObfuscationEnabled");
constexpr QLatin1String junkPacketCount("Jc");
constexpr QLatin1String junkPacketMinSize("Jmin");
constexpr QLatin1String junkPacketMaxSize("Jmax");
constexpr QLatin1String initPacketJunkSize("S1");
constexpr QLatin1String responsePacketJunkSize("S2");
constexpr QLatin1String cookieReplyPacketJunkSize("S3");
constexpr QLatin1String transportPacketJunkSize("S4");
constexpr QLatin1String initPacketMagicHeader("H1");
constexpr QLatin1String responsePacketMagicHeader("H2");
constexpr QLatin1String underloadPacketMagicHeader("H3");
constexpr QLatin1String transportPacketMagicHeader("H4");
constexpr QLatin1String specialJunk1("I1");
constexpr QLatin1String specialJunk2("I2");
constexpr QLatin1String specialJunk3("I3");
constexpr QLatin1String specialJunk4("I4");
constexpr QLatin1String specialJunk5("I5");
constexpr QLatin1String protocolVersion("protocol_version");
constexpr QLatin1String openvpn("openvpn");
constexpr QLatin1String wireguard("wireguard");
constexpr QLatin1String sftp("sftp");
constexpr QLatin1String awg("awg");
constexpr QLatin1String vless("vless");
constexpr QLatin1String xray("xray");
constexpr QLatin1String ssxray("ssxray");
constexpr QLatin1String socks5proxy("socks5proxy");
constexpr QLatin1String splitTunnelSites("splitTunnelSites");
constexpr QLatin1String splitTunnelType("splitTunnelType");
constexpr QLatin1String splitTunnelApps("splitTunnelApps");
constexpr QLatin1String appSplitTunnelType("appSplitTunnelType");
constexpr QLatin1String allowedDnsServers("allowedDnsServers");
constexpr QLatin1String killSwitchOption("killSwitchOption");
constexpr QLatin1String crc("crc");
constexpr QLatin1String clientId("clientId");
constexpr QLatin1String nameOverriddenByUser("nameOverriddenByUser");
constexpr QLatin1String amneziaOpenvpn("amnezia-openvpn");
constexpr QLatin1String amneziaWireguard("amnezia-wireguard");
constexpr QLatin1String amneziaAwg("amnezia-awg");
constexpr QLatin1String amneziaXray("amnezia-xray");
constexpr QLatin1String amneziaSsxray("amnezia-ssxray");
constexpr QLatin1String clientName("clientName");
constexpr QLatin1String userData("userData");
constexpr QLatin1String creationDate("creationDate");
constexpr QLatin1String latestHandshake("latestHandshake");
constexpr QLatin1String dataReceived("dataReceived");
constexpr QLatin1String dataSent("dataSent");
}
}
#endif
@@ -0,0 +1,182 @@
#ifndef PROTOCOLCONSTANTS_H
#define PROTOCOLCONSTANTS_H
namespace amnezia
{
namespace protocols
{
namespace dns
{
constexpr char amneziaDnsIp[] = "172.29.172.254";
}
namespace openvpn
{
constexpr char defaultSubnetAddress[] = "10.8.0.0";
constexpr char defaultSubnetMask[] = "255.255.255.0";
constexpr char defaultSubnetCidr[] = "24";
constexpr char defaultMtu[] = "1500";
constexpr char serverConfigPath[] = "/opt/amnezia/openvpn/server.conf";
constexpr char caCertPath[] = "/opt/amnezia/openvpn/pki/ca.crt";
constexpr char clientCertPath[] = "/opt/amnezia/openvpn/pki/issued";
constexpr char taKeyPath[] = "/opt/amnezia/openvpn/ta.key";
constexpr char clientsDirPath[] = "/opt/amnezia/openvpn/clients";
constexpr char defaultPort[] = "1194";
constexpr char defaultTransportProto[] = "udp";
constexpr char defaultCipher[] = "AES-256-GCM";
constexpr char defaultHash[] = "SHA512";
constexpr bool defaultBlockOutsideDns = true;
constexpr bool defaultNcpDisable = false;
constexpr bool defaultTlsAuth = true;
constexpr char ncpDisableString[] = "ncp-disable";
constexpr char tlsAuthString[] = "tls-auth /opt/amnezia/openvpn/ta.key 0";
constexpr char defaultAdditionalClientConfig[] = "";
constexpr char defaultAdditionalServerConfig[] = "";
}
namespace shadowsocks
{
constexpr char ssKeyPath[] = "/opt/amnezia/shadowsocks/shadowsocks.key";
constexpr char defaultPort[] = "6789";
constexpr char defaultLocalProxyPort[] = "8585";
constexpr char defaultCipher[] = "chacha20-ietf-poly1305";
}
namespace xray
{
constexpr char serverConfigPath[] = "/opt/amnezia/xray/server.json";
constexpr char uuidPath[] = "/opt/amnezia/xray/xray_uuid.key";
constexpr char PublicKeyPath[] = "/opt/amnezia/xray/xray_public.key";
constexpr char PrivateKeyPath[] = "/opt/amnezia/xray/xray_private.key";
constexpr char shortidPath[] = "/opt/amnezia/xray/xray_short_id.key";
constexpr char defaultSite[] = "www.googletagmanager.com";
constexpr char defaultPort[] = "443";
constexpr char defaultLocalProxyPort[] = "10808";
constexpr char defaultLocalAddr[] = "10.33.0.2";
constexpr char outbounds[] = "outbounds";
constexpr char inbounds[] = "inbounds";
constexpr char settings[] = "settings";
constexpr char streamSettings[] = "streamSettings";
constexpr char vnext[] = "vnext";
constexpr char users[] = "users";
constexpr char servers[] = "servers";
constexpr char clients[] = "clients";
constexpr char id[] = "id";
constexpr char port[] = "port";
constexpr char address[] = "address";
constexpr char flow[] = "flow";
constexpr char encryption[] = "encryption";
constexpr char network[] = "network";
constexpr char security[] = "security";
constexpr char realitySettings[] = "realitySettings";
constexpr char serverNames[] = "serverNames";
constexpr char serverName[] = "serverName";
constexpr char publicKey[] = "publicKey";
constexpr char shortId[] = "shortId";
constexpr char fingerprint[] = "fingerprint";
constexpr char spiderX[] = "spiderX";
constexpr char user[] = "user";
constexpr char pass[] = "pass";
}
namespace cloak
{
constexpr char ckPublicKeyPath[] = "/opt/amnezia/cloak/cloak_public.key";
constexpr char ckBypassUidKeyPath[] = "/opt/amnezia/cloak/cloak_bypass_uid.key";
constexpr char ckAdminKeyPath[] = "/opt/amnezia/cloak/cloak_admin_uid.key";
constexpr char defaultPort[] = "443";
constexpr char defaultRedirSite[] = "tile.openstreetmap.org";
constexpr char defaultCipher[] = "chacha20-poly1305";
}
namespace wireguard
{
// Config file keys ([Interface] / [Peer] sections) - case-sensitive
constexpr char PrivateKey[] = "PrivateKey";
constexpr char Address[] = "Address";
constexpr char PublicKey[] = "PublicKey";
constexpr char PresharedKey[] = "PresharedKey";
constexpr char PreSharedKey[] = "PreSharedKey";
constexpr char AllowedIPs[] = "AllowedIPs";
constexpr char Endpoint[] = "Endpoint";
constexpr char PersistentKeepalive[] = "PersistentKeepalive";
constexpr char MTU[] = "MTU";
constexpr char defaultSubnetAddress[] = "10.8.1.0";
constexpr char defaultSubnetMask[] = "255.255.255.0";
constexpr char defaultSubnetCidr[] = "24";
constexpr char defaultPort[] = "51820";
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS) || defined(MACOS_NE)
constexpr char defaultMtu[] = "1280";
#else
constexpr char defaultMtu[] = "1376";
#endif
constexpr char serverConfigPath[] = "/opt/amnezia/wireguard/wg0.conf";
constexpr char serverPublicKeyPath[] = "/opt/amnezia/wireguard/wireguard_server_public_key.key";
constexpr char serverPskKeyPath[] = "/opt/amnezia/wireguard/wireguard_psk.key";
}
namespace sftp
{
constexpr char defaultUserName[] = "sftp_user";
} // namespace sftp
namespace awg
{
constexpr char defaultPort[] = "55424";
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS) || defined(MACOS_NE)
constexpr char defaultMtu[] = "1280";
#else
constexpr char defaultMtu[] = "1376";
#endif
constexpr char serverConfigPath[] = "/opt/amnezia/awg/awg0.conf";
constexpr char serverLegacyConfigPath[] = "/opt/amnezia/awg/wg0.conf";
constexpr char serverPublicKeyPath[] = "/opt/amnezia/awg/wireguard_server_public_key.key";
constexpr char serverPskKeyPath[] = "/opt/amnezia/awg/wireguard_psk.key";
constexpr char defaultJunkPacketCount[] = "3";
constexpr char defaultJunkPacketMinSize[] = "10";
constexpr char defaultJunkPacketMaxSize[] = "30";
constexpr char defaultInitPacketJunkSize[] = "15";
constexpr char defaultResponsePacketJunkSize[] = "18";
constexpr char defaultCookieReplyPacketJunkSize[] = "20";
constexpr char defaultTransportPacketJunkSize[] = "23";
constexpr char defaultInitPacketMagicHeader[] = "1020325451";
constexpr char defaultResponsePacketMagicHeader[] = "3288052141";
constexpr char defaultTransportPacketMagicHeader[] = "2528465083";
constexpr char defaultUnderloadPacketMagicHeader[] = "1766607858";
constexpr char defaultSpecialJunk1[] = "<r 2><b 0x858000010001000000000669636c6f756403636f6d0000010001c00c000100010000105a00044d583737>";
constexpr char defaultSpecialJunk2[] = "";
constexpr char defaultSpecialJunk3[] = "";
constexpr char defaultSpecialJunk4[] = "";
constexpr char defaultSpecialJunk5[] = "";
constexpr char awgV1_5[] = "1.5";
constexpr char awgV2[] = "2";
}
namespace socks5Proxy
{
constexpr char defaultUserName[] = "proxy_user";
constexpr char defaultPort[] = "38080";
constexpr char proxyConfigPath[] = "/usr/local/3proxy/conf/3proxy.cfg";
}
} // namespace protocols
}
#endif // PROTOCOLCONSTANTS_H