Files
amnezia-client/client/protocols/protocols_defs.h
T

187 lines
5.2 KiB
C++
Raw Normal View History

2021-04-04 23:12:36 +03:00
#ifndef PROTOCOLS_DEFS_H
#define PROTOCOLS_DEFS_H
#include <QObject>
2021-05-10 02:33:31 +03:00
#include <QDebug>
2021-09-16 19:49:50 +03:00
#include <QQmlEngine>
2021-04-04 23:12:36 +03:00
namespace amnezia {
2021-04-26 22:54:31 +03:00
namespace config_key {
// Json config strings
2021-05-07 23:28:37 +03:00
constexpr char hostName[] = "hostName";
constexpr char userName[] = "userName";
constexpr char password[] = "password";
constexpr char port[] = "port";
constexpr char local_port[] = "local_port";
constexpr char description[] = "description";
2021-04-26 22:54:31 +03:00
2021-05-07 23:28:37 +03:00
constexpr char containers[] = "containers";
constexpr char container[] = "container";
constexpr char defaultContainer[] = "defaultContainer";
2021-04-26 22:54:31 +03:00
2021-05-07 23:28:37 +03:00
constexpr char protocols[] = "protocols";
//constexpr char protocol[] = "protocol";
2021-04-26 22:54:31 +03:00
2021-05-07 23:28:37 +03:00
constexpr char remote[] = "remote";
constexpr char transport_proto[] = "transport_proto";
constexpr char cipher[] = "cipher";
constexpr char hash[] = "hash";
constexpr char ncp_disable[] = "ncp_disable";
2021-05-18 15:50:52 +03:00
constexpr char tls_auth[] = "tls_auth";
2021-04-26 22:54:31 +03:00
2021-05-07 23:28:37 +03:00
constexpr char site[] = "site";
constexpr char block_outside_dns[] = "block_outside_dns";
2021-04-26 22:54:31 +03:00
2021-05-07 23:28:37 +03:00
constexpr char subnet_address[] = "subnet_address";
constexpr char subnet_mask[] = "subnet_mask";
2021-06-12 11:59:36 +03:00
constexpr char subnet_cidr[] = "subnet_cidr";
2021-04-26 22:54:31 +03:00
2021-05-07 23:28:37 +03:00
// proto config keys
constexpr char last_config[] = "last_config";
2021-04-26 22:54:31 +03:00
}
2021-04-04 23:12:36 +03:00
namespace protocols {
2021-06-12 11:59:36 +03:00
2021-05-07 23:28:37 +03:00
constexpr char UDP[] = "udp"; // case sens
constexpr char TCP[] = "tcp";
2021-04-26 22:54:31 +03:00
namespace openvpn {
2021-06-12 11:59:36 +03:00
constexpr char defaultSubnetAddress[] = "10.8.0.0";
constexpr char defaultSubnetMask[] = "255.255.255.0";
constexpr char defaultSubnetCidr[] = "24";
2021-05-07 23:28:37 +03:00
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";
2021-05-10 05:25:20 -07:00
constexpr char defaultTransportProto[] = "udp";
2021-05-07 23:28:37 +03:00
constexpr char defaultCipher[] = "AES-256-GCM";
constexpr char defaultHash[] = "SHA512";
constexpr bool defaultBlockOutsideDns = true;
constexpr bool defaultNcpDisable = false;
2021-05-18 15:50:52 +03:00
constexpr bool defaultTlsAuth = true;
2021-05-07 23:28:37 +03:00
constexpr char ncpDisableString[] = "ncp-disable";
2021-05-18 15:50:52 +03:00
constexpr char tlsAuthString[] = "tls-auth /opt/amnezia/openvpn/ta.key 0";
2021-05-07 23:28:37 +03:00
2021-04-04 23:12:36 +03:00
}
namespace shadowsocks {
2021-05-07 23:28:37 +03:00
constexpr char ssKeyPath[] = "/opt/amnezia/shadowsocks/shadowsocks.key";
constexpr char defaultPort[] = "6789";
constexpr char defaultLocalProxyPort[] = "8585";
constexpr char defaultCipher[] = "chacha20-ietf-poly1305";
2021-04-04 23:12:36 +03:00
}
namespace cloak {
2021-05-07 23:28:37 +03:00
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";
2021-06-19 16:38:35 +03:00
constexpr char defaultRedirSite[] = "tile.openstreetmap.org";
2021-05-10 02:33:31 +03:00
constexpr char defaultCipher[] = "chacha20-ietf-poly1305";
2021-04-04 23:12:36 +03:00
}
2021-06-12 11:59:36 +03:00
namespace wireguard {
constexpr char defaultSubnetAddress[] = "10.8.1.0";
constexpr char defaultSubnetMask[] = "255.255.255.0";
constexpr char defaultSubnetCidr[] = "24";
constexpr char defaultPort[] = "51820";
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";
}
2021-04-04 23:12:36 +03:00
} // namespace protocols
2021-05-07 23:28:37 +03:00
2021-09-16 19:49:50 +03:00
namespace ProtocolEnumNS {
2021-09-16 16:19:14 +03:00
Q_NAMESPACE
2021-09-20 21:51:28 +03:00
enum TransportProto {
Udp,
Tcp
};
Q_ENUM_NS(TransportProto)
enum Protocol {
Any = 0,
2021-05-07 23:28:37 +03:00
OpenVpn,
ShadowSocks,
Cloak,
2021-09-20 21:51:28 +03:00
WireGuard,
TorSite,
Dns,
FileShare
2021-05-07 23:28:37 +03:00
};
2021-09-16 16:19:14 +03:00
Q_ENUM_NS(Protocol)
2021-09-20 21:51:28 +03:00
enum ServiceType {
None = 0,
Vpn,
Other
};
Q_ENUM_NS(ServiceType)
2021-09-16 19:49:50 +03:00
} // namespace ProtocolEnumNS
using namespace ProtocolEnumNS;
2021-09-16 16:19:14 +03:00
2021-09-20 21:51:28 +03:00
class ProtocolProps : public QObject
{
Q_OBJECT
public:
Q_INVOKABLE static QList<Protocol> allProtocols();
// spelling may differ for various protocols - TCP for OpenVPN, tcp for others
Q_INVOKABLE static TransportProto transportProtoFromString(QString p);
Q_INVOKABLE static QString transportProtoToString(TransportProto proto, Protocol p = Protocol::Any);
Q_INVOKABLE static Protocol protoFromString(QString p);
Q_INVOKABLE static QString protoToString(Protocol p);
Q_INVOKABLE static QMap<Protocol, QString> protocolHumanNames();
Q_INVOKABLE static QMap<Protocol, QString> protocolDescriptions();
2021-05-07 23:28:37 +03:00
2021-09-20 21:51:28 +03:00
Q_INVOKABLE static ServiceType protocolService(Protocol p);
2021-05-07 23:28:37 +03:00
2021-09-20 21:51:28 +03:00
Q_INVOKABLE static int defaultPort(Protocol p);
Q_INVOKABLE static bool defaultPortChangeable(Protocol p);
Q_INVOKABLE static TransportProto defaultTransportProto(Protocol p);
Q_INVOKABLE static bool defaultTransportProtoChangeable(Protocol p);
};
2021-05-07 23:28:37 +03:00
2021-09-16 16:19:14 +03:00
static void declareQmlProtocolEnum() {
qmlRegisterUncreatableMetaObject(
2021-09-16 19:49:50 +03:00
ProtocolEnumNS::staticMetaObject,
2021-09-16 16:19:14 +03:00
"ProtocolEnum",
1, 0,
"ProtocolEnum",
"Error: only enums"
);
2021-09-20 21:51:28 +03:00
qmlRegisterUncreatableMetaObject(
ProtocolEnumNS::staticMetaObject,
"ProtocolEnum",
1, 0,
"TransportProto",
"Error: only enums"
);
2021-09-16 16:19:14 +03:00
}
2021-04-04 23:12:36 +03:00
} // namespace amnezia
2021-05-10 02:33:31 +03:00
QDebug operator<<(QDebug debug, const amnezia::Protocol &p);
2021-04-04 23:12:36 +03:00
#endif // PROTOCOLS_DEFS_H