bool RunCommandPlugin::receivePackage(const NetworkPackage& np) { if (np.get<bool>("requestCommandList", false)) { sendConfig(); return true; } if (np.has("key")) { QJsonDocument commandsDocument = QJsonDocument::fromJson(config()->get<QByteArray>("commands", "{}")); QJsonObject commands = commandsDocument.object(); QString key = np.get<QString>("key"); QJsonValue value = commands[key]; if (value == QJsonValue::Undefined) { qCWarning(KDECONNECT_PLUGIN_RUNCOMMAND) << key << "is not a configured command"; } const QJsonObject command = value.toObject(); QString name = command["name"].toString(); QStringList commandLine = KShell::splitArgs(command["command"].toString()); QProcess::startDetached(commandLine.at(0), commandLine.mid(1)); return true; } return false; }
void Mounter::onPakcageReceived(const NetworkPackage& np) { if (np.get<bool>("stop", false)) { qCDebug(KDECONNECT_PLUGIN_SFTP) << "SFTP server stopped"; unmount(); return; } //This is the previous code, to access sftp server using KIO. Now we are //using the external binary sshfs, and accessing it as a local filesystem. /* * QUrl url; * url.setScheme("sftp"); * url.setHost(np.get<QString>("ip")); * url.setPort(np.get<QString>("port").toInt()); * url.setUserName(np.get<QString>("user")); * url.setPassword(np.get<QString>("password")); * url.setPath(np.get<QString>("path")); * new KRun(url, 0); * Q_EMIT mounted(); */ unmount(); m_proc = new KProcess(this); m_proc->setOutputChannelMode(KProcess::MergedChannels); connect(m_proc, SIGNAL(started()), SLOT(onStarted())); connect(m_proc, SIGNAL(error(QProcess::ProcessError)), SLOT(onError(QProcess::ProcessError))); connect(m_proc, SIGNAL(finished(int,QProcess::ExitStatus)), SLOT(onFinished(int,QProcess::ExitStatus))); QDir().mkpath(m_mountPoint); const QString program = "sshfs"; QString path; if (np.has("multiPaths")) path = '/'; else path = np.get<QString>("path"); const QStringList arguments = QStringList() << QString("%1@%2:%3") .arg(np.get<QString>("user")) .arg(np.get<QString>("ip")) .arg(path) << m_mountPoint << "-p" << np.get<QString>("port") << "-f" << "-o" << "IdentityFile=" + KdeConnectConfig::instance()->privateKeyPath() << "-o" << "StrictHostKeyChecking=no" //Do not ask for confirmation because it is not a known host << "-o" << "UserKnownHostsFile=/dev/null" //Prevent storing as a known host << "-o" << "HostKeyAlgorithms=ssh-dss" //https://bugs.kde.org/show_bug.cgi?id=351725 << "-o" << "password_stdin" ; m_proc->setProgram(program, arguments); qCDebug(KDECONNECT_PLUGIN_SFTP) << "Starting process: " << m_proc->program().join(" "); m_proc->start(); //qCDebug(KDECONNECT_PLUGIN_SFTP) << "Passing password: "******"password").toLatin1(); m_proc->write(np.get<QString>("password").toLatin1()); m_proc->write("\n"); }
bool SharePlugin::receivePackage(const NetworkPackage& np) { /* //TODO: Write a test like this if (np.type() == PACKAGE_TYPE_PING) { qCDebug(KDECONNECT_PLUGIN_SHARE) << "sending file" << (QDesktopServices::storageLocation(QDesktopServices::HomeLocation) + "/.bashrc"); NetworkPackage out(PACKAGE_TYPE_SHARE_REQUEST); out.set("filename", mDestinationDir + "itworks.txt"); AutoClosingQFile* file = new AutoClosingQFile(QDesktopServices::storageLocation(QDesktopServices::HomeLocation) + "/.bashrc"); //Test file to transfer out.setPayload(file, file->size()); device()->sendPackage(out); return true; } */ qCDebug(KDECONNECT_PLUGIN_SHARE) << "File transfer"; if (np.hasPayload()) { //qCDebug(KDECONNECT_PLUGIN_SHARE) << "receiving file"; const QString filename = np.get<QString>(QStringLiteral("filename"), QString::number(QDateTime::currentMSecsSinceEpoch())); const QUrl dir = destinationDir().adjusted(QUrl::StripTrailingSlash); QUrl destination(dir.toString() + '/' + filename); if (destination.isLocalFile() && QFile::exists(destination.toLocalFile())) { destination = QUrl(dir.toString() + '/' + KIO::suggestName(dir, filename)); } FileTransferJob* job = np.createPayloadTransferJob(destination); job->setOriginName(device()->name() + ": " + filename); connect(job, &KJob::result, this, &SharePlugin::finished); KIO::getJobTracker()->registerJob(job); job->start(); } else if (np.has(QStringLiteral("text"))) { QString text = np.get<QString>(QStringLiteral("text")); if (!QStandardPaths::findExecutable(QStringLiteral("kate")).isEmpty()) { QProcess* proc = new QProcess(); connect(proc, SIGNAL(finished(int)), proc, SLOT(deleteLater())); proc->start(QStringLiteral("kate"), QStringList(QStringLiteral("--stdin"))); proc->write(text.toUtf8()); proc->closeWriteChannel(); } else { QTemporaryFile tmpFile; tmpFile.setAutoRemove(false); tmpFile.open(); tmpFile.write(text.toUtf8()); tmpFile.close(); const QUrl url = QUrl::fromLocalFile(tmpFile.fileName()); Q_EMIT shareReceived(url); QDesktopServices::openUrl(url); } } else if (np.has(QStringLiteral("url"))) { QUrl url = QUrl::fromEncoded(np.get<QByteArray>(QStringLiteral("url"))); QDesktopServices::openUrl(url); Q_EMIT shareReceived(url); } else { qCDebug(KDECONNECT_PLUGIN_SHARE) << "Error: Nothing attached!"; } return true; }