mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-06-23 02:00:20 +07:00
fixed secret & enum
This commit is contained in:
@@ -18,7 +18,7 @@ using namespace amnezia;
|
|||||||
namespace {
|
namespace {
|
||||||
constexpr QLatin1String kTelemtClientJsonPath("/data/amnezia-telemt-client.json");
|
constexpr QLatin1String kTelemtClientJsonPath("/data/amnezia-telemt-client.json");
|
||||||
constexpr QLatin1String kTelemtClientJsonUploadPath("data/amnezia-telemt-client.json");
|
constexpr QLatin1String kTelemtClientJsonUploadPath("data/amnezia-telemt-client.json");
|
||||||
constexpr QLatin1String kTelemtSecretPath("/data/.amnezia-secret");
|
constexpr QLatin1String kTelemtSecretPath("/data/secret");
|
||||||
}
|
}
|
||||||
|
|
||||||
TelemtInstaller::TelemtInstaller(QObject *parent) : InstallerBase(parent) {}
|
TelemtInstaller::TelemtInstaller(QObject *parent) : InstallerBase(parent) {}
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ mkdir -p /data/tlsfront
|
|||||||
# Secret: substituted $TELEMT_SECRET -> saved file -> openssl (same rules as MTProxy configure)
|
# Secret: substituted $TELEMT_SECRET -> saved file -> openssl (same rules as MTProxy configure)
|
||||||
if [ -n "$TELEMT_SECRET" ]; then
|
if [ -n "$TELEMT_SECRET" ]; then
|
||||||
SECRET="$TELEMT_SECRET"
|
SECRET="$TELEMT_SECRET"
|
||||||
|
elif [ -f /data/secret ]; then
|
||||||
|
SECRET=$(cat /data/secret)
|
||||||
elif [ -f /data/.amnezia-secret ]; then
|
elif [ -f /data/.amnezia-secret ]; then
|
||||||
SECRET=$(cat /data/.amnezia-secret)
|
SECRET=$(cat /data/.amnezia-secret)
|
||||||
else
|
else
|
||||||
@@ -61,8 +63,8 @@ rm -f /data/config.toml
|
|||||||
echo "$TELEMT_USER_NAME = \"$SECRET\""
|
echo "$TELEMT_USER_NAME = \"$SECRET\""
|
||||||
} > /data/config.toml
|
} > /data/config.toml
|
||||||
|
|
||||||
echo "$SECRET" > /data/.amnezia-secret
|
echo "$SECRET" > /data/secret
|
||||||
chmod 600 /data/.amnezia-secret 2>/dev/null || true
|
chmod 600 /data/secret 2>/dev/null || true
|
||||||
|
|
||||||
# Do not start telemt here: a long-lived process + curl loop inside `docker exec` can confuse SSH/Docker
|
# Do not start telemt here: a long-lived process + curl loop inside `docker exec` can confuse SSH/Docker
|
||||||
# timing and is unnecessary — start.sh runs telemt after configure. Links can be empty until the service
|
# timing and is unnecessary — start.sh runs telemt after configure. Links can be empty until the service
|
||||||
|
|||||||
@@ -330,6 +330,7 @@ void InstallUiController::setContainerEnabled(int serverIndex, int containerInde
|
|||||||
const ServerCredentials credentials = m_serversController->getServerCredentials(serverIndex);
|
const ServerCredentials credentials = m_serversController->getServerCredentials(serverIndex);
|
||||||
const QString containerName = ContainerUtils::containerToString(container);
|
const QString containerName = ContainerUtils::containerToString(container);
|
||||||
|
|
||||||
|
if (container == amnezia::ContainerEnumNS::MtProxy || container == amnezia::ContainerEnumNS::Telemt) {
|
||||||
emit serverIsBusy(true);
|
emit serverIsBusy(true);
|
||||||
SshSession sshSession(this);
|
SshSession sshSession(this);
|
||||||
const QString script = enabled
|
const QString script = enabled
|
||||||
@@ -354,6 +355,7 @@ void InstallUiController::setContainerEnabled(int serverIndex, int containerInde
|
|||||||
}
|
}
|
||||||
|
|
||||||
emit installationErrorOccurred(errorCode);
|
emit installationErrorOccurred(errorCode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InstallUiController::refreshContainerStatus(int serverIndex, int containerIndex) {
|
void InstallUiController::refreshContainerStatus(int serverIndex, int containerIndex) {
|
||||||
@@ -361,6 +363,7 @@ void InstallUiController::refreshContainerStatus(int serverIndex, int containerI
|
|||||||
const ServerCredentials credentials = m_serversController->getServerCredentials(serverIndex);
|
const ServerCredentials credentials = m_serversController->getServerCredentials(serverIndex);
|
||||||
const QString containerName = ContainerUtils::containerToString(container);
|
const QString containerName = ContainerUtils::containerToString(container);
|
||||||
|
|
||||||
|
if (container == amnezia::ContainerEnumNS::MtProxy || container == amnezia::ContainerEnumNS::Telemt) {
|
||||||
QString stdOut;
|
QString stdOut;
|
||||||
auto cbReadStdOut = [&](const QString &data, libssh::Client &) {
|
auto cbReadStdOut = [&](const QString &data, libssh::Client &) {
|
||||||
stdOut += data;
|
stdOut += data;
|
||||||
@@ -387,6 +390,7 @@ void InstallUiController::refreshContainerStatus(int serverIndex, int containerI
|
|||||||
} else {
|
} else {
|
||||||
emit containerStatusRefreshed(3);
|
emit containerStatusRefreshed(3);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InstallUiController::refreshContainerDiagnostics(int serverIndex, int containerIndex, int port) {
|
void InstallUiController::refreshContainerDiagnostics(int serverIndex, int containerIndex, int port) {
|
||||||
@@ -394,6 +398,7 @@ void InstallUiController::refreshContainerDiagnostics(int serverIndex, int conta
|
|||||||
const DockerContainer container = static_cast<DockerContainer>(containerIndex);
|
const DockerContainer container = static_cast<DockerContainer>(containerIndex);
|
||||||
const QString containerName = ContainerUtils::containerToString(container);
|
const QString containerName = ContainerUtils::containerToString(container);
|
||||||
|
|
||||||
|
if (container == amnezia::ContainerEnumNS::MtProxy || container == amnezia::ContainerEnumNS::Telemt) {
|
||||||
const QString script =
|
const QString script =
|
||||||
QString(
|
QString(
|
||||||
"PORT_OK=$(sudo docker exec %1 sh -c 'ss -tlnp 2>/dev/null | grep -q :%2 && echo yes || echo no' 2>/dev/null || echo no); "
|
"PORT_OK=$(sudo docker exec %1 sh -c 'ss -tlnp 2>/dev/null | grep -q :%2 && echo yes || echo no' 2>/dev/null || echo no); "
|
||||||
@@ -443,6 +448,7 @@ void InstallUiController::refreshContainerDiagnostics(int serverIndex, int conta
|
|||||||
|
|
||||||
emit containerDiagnosticsRefreshed(portReachable, upstreamReachable, clientsConnected, lastConfigRefresh,
|
emit containerDiagnosticsRefreshed(portReachable, upstreamReachable, clientsConnected, lastConfigRefresh,
|
||||||
statsEndpoint);
|
statsEndpoint);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InstallUiController::fetchContainerSecret(int serverIndex, int containerIndex) {
|
void InstallUiController::fetchContainerSecret(int serverIndex, int containerIndex) {
|
||||||
@@ -450,6 +456,7 @@ void InstallUiController::fetchContainerSecret(int serverIndex, int containerInd
|
|||||||
const DockerContainer container = static_cast<DockerContainer>(containerIndex);
|
const DockerContainer container = static_cast<DockerContainer>(containerIndex);
|
||||||
const QString containerName = ContainerUtils::containerToString(container);
|
const QString containerName = ContainerUtils::containerToString(container);
|
||||||
|
|
||||||
|
if (container == amnezia::ContainerEnumNS::MtProxy || container == amnezia::ContainerEnumNS::Telemt) {
|
||||||
QString stdOut;
|
QString stdOut;
|
||||||
auto cbReadStdOut = [&](const QString &data, libssh::Client &) {
|
auto cbReadStdOut = [&](const QString &data, libssh::Client &) {
|
||||||
stdOut += data;
|
stdOut += data;
|
||||||
@@ -457,8 +464,7 @@ void InstallUiController::fetchContainerSecret(int serverIndex, int containerInd
|
|||||||
};
|
};
|
||||||
|
|
||||||
SshSession sshSession(this);
|
SshSession sshSession(this);
|
||||||
const QString path = container == DockerContainer::Telemt ? QStringLiteral("/data/.amnezia-secret")
|
const QString path = QStringLiteral("/data/secret");
|
||||||
: QStringLiteral("/data/secret");
|
|
||||||
const QString cmd =
|
const QString cmd =
|
||||||
QStringLiteral("sudo docker exec %1 cat %2").arg(containerName, path);
|
QStringLiteral("sudo docker exec %1 cat %2").arg(containerName, path);
|
||||||
const ErrorCode errorCode = sshSession.runScript(credentials, cmd, cbReadStdOut);
|
const ErrorCode errorCode = sshSession.runScript(credentials, cmd, cbReadStdOut);
|
||||||
@@ -470,6 +476,7 @@ void InstallUiController::fetchContainerSecret(int serverIndex, int containerInd
|
|||||||
const QString secret = stdOut.trimmed();
|
const QString secret = stdOut.trimmed();
|
||||||
static const QRegularExpression hex32(QStringLiteral("^[0-9a-fA-F]{32}$"));
|
static const QRegularExpression hex32(QStringLiteral("^[0-9a-fA-F]{32}$"));
|
||||||
emit containerSecretFetched(hex32.match(secret).hasMatch() ? secret : QString());
|
emit containerSecretFetched(hex32.match(secret).hasMatch() ? secret : QString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InstallUiController::rebootServer(int serverIndex)
|
void InstallUiController::rebootServer(int serverIndex)
|
||||||
|
|||||||
Reference in New Issue
Block a user