Files
amnezia-client/client/utilities.h
T

79 lines
2.5 KiB
C++
Raw Normal View History

#ifndef UTILITIES_H
#define UTILITIES_H
2020-12-26 15:03:51 +03:00
2021-02-25 18:03:24 +03:00
#include <QRegExp>
#include <QRegularExpression>
#include <QString>
2020-12-26 15:03:51 +03:00
2021-03-18 18:45:08 +03:00
#ifdef Q_OS_WIN
2023-08-23 00:20:59 +05:00
#include "Windows.h"
2021-03-18 18:45:08 +03:00
#endif
2023-08-23 00:20:59 +05:00
class Utils : public QObject
{
Q_OBJECT
2020-12-26 15:03:51 +03:00
public:
2021-04-04 23:12:36 +03:00
static QString getRandomString(int len);
2023-08-23 00:20:59 +05:00
static QString executable(const QString &baseName, bool absPath);
static QString usrExecutable(const QString &baseName);
2020-12-26 15:03:51 +03:00
static QString systemLogPath();
2023-08-23 00:20:59 +05:00
static bool createEmptyFile(const QString &path);
static bool initializePath(const QString &path);
static QString getIPAddress(const QString &host);
static QString getStringBetween(const QString &s, const QString &a, const QString &b);
static bool checkIPv4Format(const QString &ip);
static bool checkIpSubnetFormat(const QString &ip);
static QRegularExpression ipAddressRegExp()
{
return QRegularExpression("^((25[0-5]|(2[0-4]|1[0-9]|[1-9]|)[0-9])(\\.(?!$)|$)){4}$");
}
static QRegularExpression ipAddressPortRegExp()
{
return QRegularExpression("^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\\.){3}"
"(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(\\:[0-9]{1,5}){0,1}$");
}
static QRegExp ipAddressWithSubnetRegExp()
{
return QRegExp("(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\\.){3}"
"(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(\\/[0-9]{1,2}){0,1}");
}
static QRegExp ipNetwork24RegExp()
{
return QRegExp("^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\\.){3}"
"0$");
}
static QRegExp ipPortRegExp()
{
return QRegExp("^()([1-9]|[1-5]?[0-9]{2,4}|6[1-4][0-9]{3}|65[1-4][0-9]{2}|655[1-2][0-9]|6553[1-5])$");
}
static QRegExp domainRegExp()
{
return QRegExp("(((?!\\-))(xn\\-\\-)?[a-z0-9\\-_]{0,61}[a-z0-9]{1,1}\\.)*(xn\\-\\-)?([a-z0-9\\-]{1,61}|[a-z0-"
"9\\-]{1,30})\\.[a-z]{2,}");
}
static bool processIsRunning(const QString &fileName);
2021-03-18 18:45:08 +03:00
static void killProcessByName(const QString &name);
2021-05-27 22:18:36 +03:00
static QString netMaskFromIpWithSubnet(const QString ip);
static QString ipAddressFromIpWithSubnet(const QString ip);
2021-06-01 18:18:09 +03:00
static QStringList summarizeRoutes(const QStringList &ips, const QString cidr);
2022-08-10 22:15:00 +03:00
static QString openVpnExecPath();
static QString wireguardExecPath();
static QString certUtilPath();
2021-03-18 18:45:08 +03:00
#ifdef Q_OS_WIN
static bool signalCtrl(DWORD dwProcessId, DWORD dwCtrlEvent);
#endif
2020-12-26 15:03:51 +03:00
};
#endif // UTILITIES_H