2021-01-06 17:12:24 +03:00
|
|
|
#ifndef DEFS_H
|
|
|
|
|
#define DEFS_H
|
|
|
|
|
|
2021-04-20 02:09:47 +03:00
|
|
|
#include <QMetaEnum>
|
2021-01-06 17:12:24 +03:00
|
|
|
#include <QObject>
|
|
|
|
|
|
|
|
|
|
namespace amnezia {
|
2021-04-20 02:09:47 +03:00
|
|
|
Q_NAMESPACE
|
2021-01-06 17:12:24 +03:00
|
|
|
|
|
|
|
|
enum class Protocol {
|
|
|
|
|
Any,
|
|
|
|
|
OpenVpn,
|
2021-04-26 23:19:19 +03:00
|
|
|
ShadowSocks,
|
|
|
|
|
Cloak,
|
2021-01-06 17:12:24 +03:00
|
|
|
WireGuard
|
|
|
|
|
};
|
2021-04-20 02:09:47 +03:00
|
|
|
Q_ENUM_NS(Protocol)
|
|
|
|
|
|
|
|
|
|
inline Protocol protoFromString(QString proto){
|
|
|
|
|
auto&& metaEnum = QMetaEnum::fromType<Protocol>();
|
|
|
|
|
return static_cast<Protocol>(metaEnum.keyToValue(proto.toStdString().c_str()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline QString protoToString(Protocol proto){
|
|
|
|
|
return QVariant::fromValue(proto).toString();
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-06 17:12:24 +03:00
|
|
|
|
2021-01-15 23:36:35 +03:00
|
|
|
enum class DockerContainer {
|
2021-04-04 23:12:36 +03:00
|
|
|
None,
|
2021-01-15 23:36:35 +03:00
|
|
|
OpenVpn,
|
2021-04-20 02:09:47 +03:00
|
|
|
ShadowSocksOverOpenVpn,
|
2021-04-04 23:12:36 +03:00
|
|
|
OpenVpnOverCloak,
|
2021-01-15 23:36:35 +03:00
|
|
|
WireGuard
|
|
|
|
|
};
|
2021-04-20 02:09:47 +03:00
|
|
|
Q_ENUM_NS(DockerContainer)
|
|
|
|
|
|
|
|
|
|
inline DockerContainer containerFromString(QString container){
|
|
|
|
|
auto&& metaEnum = QMetaEnum::fromType<DockerContainer>();
|
|
|
|
|
return static_cast<DockerContainer>(metaEnum.keyToValue(container.toStdString().c_str()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline QString containerToString(DockerContainer container){
|
|
|
|
|
return QVariant::fromValue(container).toString();
|
|
|
|
|
}
|
2021-01-15 23:36:35 +03:00
|
|
|
|
2021-04-26 23:19:19 +03:00
|
|
|
//static DockerContainer containerForProto(Protocol proto)
|
|
|
|
|
//{
|
|
|
|
|
// Q_ASSERT(proto != Protocol::Any);
|
|
|
|
|
|
|
|
|
|
// switch (proto) {
|
|
|
|
|
// case Protocol::OpenVpn: return DockerContainer::OpenVpn;
|
|
|
|
|
// case Protocol::OpenVpnOverCloak: return DockerContainer::OpenVpnOverCloak;
|
|
|
|
|
// case Protocol::ShadowSocksOverOpenVpn: return DockerContainer::ShadowSocksOverOpenVpn;
|
|
|
|
|
// case Protocol::WireGuard: return DockerContainer::WireGuard;
|
|
|
|
|
// case Protocol::Any: return DockerContainer::None;
|
|
|
|
|
// }
|
|
|
|
|
//}
|
2021-04-04 23:12:36 +03:00
|
|
|
|
2021-01-06 17:12:24 +03:00
|
|
|
struct ServerCredentials
|
|
|
|
|
{
|
|
|
|
|
QString hostName;
|
|
|
|
|
QString userName;
|
|
|
|
|
QString password;
|
|
|
|
|
int port = 22;
|
2021-03-14 21:19:11 +03:00
|
|
|
|
|
|
|
|
bool isValid() { return !hostName.isEmpty() && !userName.isEmpty() && !password.isEmpty() && port > 0; }
|
2021-01-06 17:12:24 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum ErrorCode
|
|
|
|
|
{
|
|
|
|
|
// General error codes
|
|
|
|
|
NoError = 0,
|
|
|
|
|
UnknownError,
|
|
|
|
|
InternalError,
|
|
|
|
|
NotImplementedError,
|
|
|
|
|
|
2021-02-18 15:00:41 +03:00
|
|
|
// Server errors
|
2021-01-06 17:12:24 +03:00
|
|
|
ServerCheckFailed,
|
2021-02-18 15:00:41 +03:00
|
|
|
ServerPortAlreadyAllocatedError,
|
2021-01-06 17:12:24 +03:00
|
|
|
|
|
|
|
|
// Ssh connection errors
|
|
|
|
|
SshSocketError, SshTimeoutError, SshProtocolError,
|
|
|
|
|
SshHostKeyError, SshKeyFileError, SshAuthenticationError,
|
|
|
|
|
SshClosedByServerError, SshInternalError,
|
|
|
|
|
|
|
|
|
|
// Ssh remote process errors
|
|
|
|
|
SshRemoteProcessCreationError,
|
|
|
|
|
FailedToStartRemoteProcessError, RemoteProcessCrashError,
|
2021-04-04 23:12:36 +03:00
|
|
|
SshSftpError,
|
2021-01-06 17:12:24 +03:00
|
|
|
|
|
|
|
|
// Local errors
|
|
|
|
|
FailedToSaveConfigData,
|
|
|
|
|
OpenVpnConfigMissing,
|
|
|
|
|
OpenVpnManagementServerError,
|
2021-01-07 20:53:42 +03:00
|
|
|
EasyRsaError,
|
2021-01-06 17:12:24 +03:00
|
|
|
|
|
|
|
|
// Distro errors
|
|
|
|
|
OpenVpnExecutableMissing,
|
2021-01-08 16:51:58 +03:00
|
|
|
EasyRsaExecutableMissing,
|
2021-02-21 09:44:53 -08:00
|
|
|
ShadowSocksExecutableMissing,
|
2021-04-04 23:12:36 +03:00
|
|
|
CloakExecutableMissing,
|
2021-01-08 16:51:58 +03:00
|
|
|
AmneziaServiceConnectionFailed,
|
|
|
|
|
|
|
|
|
|
// VPN errors
|
|
|
|
|
OpenVpnAdaptersInUseError,
|
2021-03-18 18:45:08 +03:00
|
|
|
OpenVpnUnknownError,
|
|
|
|
|
|
|
|
|
|
// 3rd party utils errors
|
|
|
|
|
OpenVpnExecutableCrashed,
|
2021-04-04 23:12:36 +03:00
|
|
|
ShadowSocksExecutableCrashed,
|
|
|
|
|
CloakExecutableCrashed
|
2021-01-06 17:12:24 +03:00
|
|
|
};
|
|
|
|
|
|
2021-02-18 15:00:41 +03:00
|
|
|
namespace config {
|
|
|
|
|
// config keys
|
2021-04-20 02:09:47 +03:00
|
|
|
const char key_openvpn_config_data[] = "openvpn_config_data";
|
|
|
|
|
const char key_openvpn_config_path[] = "openvpn_config_path";
|
|
|
|
|
const char key_shadowsocks_config_data[] = "shadowsocks_config_data";
|
|
|
|
|
const char key_cloak_config_data[] = "cloak_config_data";
|
2021-02-18 15:00:41 +03:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-06 17:12:24 +03:00
|
|
|
} // namespace amnezia
|
|
|
|
|
|
|
|
|
|
#endif // DEFS_H
|