SFTP fixes for Macos

This commit is contained in:
pokamest 2022-01-24 14:29:37 -08:00
parent 8e26da1759
commit 1a144da36d
4 changed files with 71 additions and 28 deletions

View file

@ -200,6 +200,7 @@ linux:!android {
} }
win32|macx|linux:!android { win32|macx|linux:!android {
DEFINES += AMNEZIA_DESKTOP
HEADERS += \ HEADERS += \
ui/systemtray_notificationhandler.h \ ui/systemtray_notificationhandler.h \

View file

@ -2,6 +2,7 @@
#include <QTimer> #include <QTimer>
#include <QProcess> #include <QProcess>
#include <QStorageInfo> #include <QStorageInfo>
#include <QStandardPaths>
#include "OtherProtocolsLogic.h" #include "OtherProtocolsLogic.h"
#include "core/servercontroller.h" #include "core/servercontroller.h"
@ -41,17 +42,12 @@ void OtherProtocolsLogic::updateProtocolPage(const QJsonObject &config, DockerCo
set_labelTftpPortText(config.value(config_key::port).toString()); set_labelTftpPortText(config.value(config_key::port).toString());
set_labelTorWebSiteAddressText(config.value(config_key::site).toString()); set_labelTorWebSiteAddressText(config.value(config_key::site).toString());
set_pushButtonSftpMountEnabled(true);
} }
//QJsonObject OtherProtocolsLogic::getProtocolConfigFromPage(QJsonObject oldConfig)
//{
//}
void OtherProtocolsLogic::onPushButtonSftpMountDriveClicked()
{
#ifdef Q_OS_WINDOWS #ifdef Q_OS_WINDOWS
QString OtherProtocolsLogic::getNextDriverLetter() const
{
QProcess drivesProc; QProcess drivesProc;
drivesProc.start("wmic logicaldisk get caption"); drivesProc.start("wmic logicaldisk get caption");
drivesProc.waitForFinished(); drivesProc.waitForFinished();
@ -68,53 +64,93 @@ void OtherProtocolsLogic::onPushButtonSftpMountDriveClicked()
if (letter == "C:") { if (letter == "C:") {
// set err info // set err info
qDebug() << "Can't find free drive letter"; qDebug() << "Can't find free drive letter";
return; return "";
}
return letter;
}
#endif
//QJsonObject OtherProtocolsLogic::getProtocolConfigFromPage(QJsonObject oldConfig)
//{
//}
void OtherProtocolsLogic::onPushButtonSftpMountDriveClicked()
{
QString mountPath;
QString cmd;
QString host = m_settings.serverCredentials(uiLogic()->selectedServerIndex).hostName;
#ifdef Q_OS_WINDOWS
mountPath = getNextDriverLetter() + ":";
// QString cmd = QString("net use \\\\sshfs\\%1@x.x.x.x!%2 /USER:%1 %3")
// .arg(labelTftpUserNameText())
// .arg(labelTftpPortText())
// .arg(labelTftpPasswordText());
cmd = "C:\\Program Files\\SSHFS-Win\\bin\\sshfs.exe";
#elif defined AMNEZIA_DESKTOP
mountPath = QString("%1/sftp:%2:%3")
.arg(QStandardPaths::writableLocation(QStandardPaths::HomeLocation))
.arg(host)
.arg(labelTftpPortText());
QDir dir(mountPath);
if (!dir.exists()){
dir.mkpath(mountPath);
} }
cmd = "/usr/local/bin/sshfs";
#endif
#ifdef AMNEZIA_DESKTOP
set_pushButtonSftpMountEnabled(false); set_pushButtonSftpMountEnabled(false);
QProcess *p = new QProcess; QProcess *p = new QProcess;
m_sftpMountProcesses.append(p); m_sftpMountProcesses.append(p);
p->setProcessChannelMode(QProcess::MergedChannels); p->setProcessChannelMode(QProcess::MergedChannels);
connect(p, &QProcess::readyRead, this, [this, p, letter](){ connect(p, &QProcess::readyRead, this, [this, p, mountPath](){
QString s = p->readAll(); QString s = p->readAll();
if (s.contains("The service sshfs has been started")) { if (s.contains("The service sshfs has been started")) {
QDesktopServices::openUrl(QUrl("file:///" + letter + ":")); QDesktopServices::openUrl(QUrl("file:///" + mountPath));
set_pushButtonSftpMountEnabled(true); set_pushButtonSftpMountEnabled(true);
} }
qDebug() << s;
}); });
// QString cmd = QString("net use \\\\sshfs\\%1@x.x.x.x!%2 /USER:%1 %3")
// .arg(labelTftpUserNameText())
// .arg(labelTftpPortText())
// .arg(labelTftpPasswordText());
p->setProgram("C:\\Program Files\\SSHFS-Win\\bin\\sshfs.exe");
QString host = m_settings.serverCredentials(uiLogic()->selectedServerIndex).hostName; p->setProgram(cmd);
QString args = QString( QString args = QString(
"%1@%2:/ %3: " "%1@%2:/ %3 "
"-o port=%4 " "-o port=%4 "
"-f " "-f "
"-o reconnect" "-o reconnect "
"-orellinks " "-o rellinks "
"-ofstypename=SSHFS " "-o fstypename=SSHFS "
"-o ssh_command=/usr/bin/ssh.exe " "-o ssh_command=/usr/bin/ssh.exe "
"-oUserKnownHostsFile=/dev/null " "-o UserKnownHostsFile=/dev/null "
"-oStrictHostKeyChecking=no " "-o StrictHostKeyChecking=no "
"-o password_stdin") "-o password_stdin")
.arg(labelTftpUserNameText()) .arg(labelTftpUserNameText())
.arg(host) .arg(host)
.arg(letter) .arg(mountPath)
.arg(labelTftpPortText()); .arg(labelTftpPortText());
p->setNativeArguments(args); // args.replace("\n", " ");
// args.replace("\r", " ");
//#ifndef Q_OS_WIN
// args.replace("reconnect-orellinks", "");
//#endif
p->setArguments(args.split(" ", QString::SkipEmptyParts));
p->start(); p->start();
p->waitForStarted(50); p->waitForStarted(50);
if (p->state() != QProcess::Running) { if (p->state() != QProcess::Running) {
qDebug() << "onPushButtonSftpMountDriveClicked process not started"; qDebug() << "onPushButtonSftpMountDriveClicked process not started";
qDebug() << args;
} }
else { else {
p->write((labelTftpPasswordText() + "\n").toUtf8()); p->write((labelTftpPasswordText() + "\n").toUtf8());
@ -123,7 +159,6 @@ void OtherProtocolsLogic::onPushButtonSftpMountDriveClicked()
//qDebug().noquote() << "onPushButtonSftpMountDriveClicked" << args; //qDebug().noquote() << "onPushButtonSftpMountDriveClicked" << args;
set_pushButtonSftpMountEnabled(true); set_pushButtonSftpMountEnabled(true);
#endif #endif
} }

View file

@ -34,9 +34,13 @@ private:
Settings m_settings; Settings m_settings;
UiLogic *m_uiLogic; UiLogic *m_uiLogic;
#ifdef Q_OS_WINDOWS #ifdef AMNEZIA_DESKTOP
QList <QProcess *> m_sftpMountProcesses; QList <QProcess *> m_sftpMountProcesses;
#endif #endif
#ifdef Q_OS_WINDOWS
QString getNextDriverLetter() const;
#endif
}; };
#endif // OTHER_PROTOCOLS_LOGIC_H #endif // OTHER_PROTOCOLS_LOGIC_H

View file

@ -16,7 +16,7 @@ PageProtocolBase {
Caption { Caption {
id: caption id: caption
text: qsTr("SFTF settings") text: qsTr("SFTP settings")
} }
Rectangle { Rectangle {
@ -105,6 +105,7 @@ PageProtocolBase {
readonly property string macos_text: "In order to mount remote SFTP folder as local folder, perform following steps: readonly property string macos_text: "In order to mount remote SFTP folder as local folder, perform following steps:
<ul> <ul>
<li>Install the latest version of <a href=\"https://osxfuse.github.io/\">macFUSE</a>.</li> <li>Install the latest version of <a href=\"https://osxfuse.github.io/\">macFUSE</a>.</li>
<li>Install the latest version of <a href=\"https://osxfuse.github.io/\">SSHFS</a>.</li>
</ul>" </ul>"
text: { text: {
@ -117,6 +118,7 @@ PageProtocolBase {
CheckBoxType { CheckBoxType {
id: check_persist id: check_persist
visible: false
anchors.bottom: pb_mount.top anchors.bottom: pb_mount.top
anchors.bottomMargin: 10 anchors.bottomMargin: 10
x: 30 x: 30
@ -134,6 +136,7 @@ PageProtocolBase {
BlueButtonType { BlueButtonType {
id: pb_mount id: pb_mount
visible: GC.isDesktop()
enabled: logic.pushButtonSftpMountEnabled enabled: logic.pushButtonSftpMountEnabled
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
anchors.bottom: parent.bottom anchors.bottom: parent.bottom