some fixes including adding double quotes

This commit is contained in:
arcan1s
2014-08-12 22:58:13 +04:00
parent b65f761520
commit 3b1701f8b5
15 changed files with 207 additions and 29 deletions

View File

@ -71,6 +71,7 @@ public:
* @param settings default settings. Needed keys are
* CTRL_DIR (path to ctrl_directory),
* CTRL_GROUP (group which is owner of CTRL_DIR),
* FORCE_SUDO (force to use sudo),
* PID_FILE (wpa_supplicant PID file),
* SUDO_PATH (path to sudo command),
* WPACLI_PATH (path to wpa_cli command),

View File

@ -97,10 +97,12 @@ bool Netctl::cmdCall(const bool sudo, const QString command, const QString comma
cmd = sudoCommand + QString(" ");
cmd += command + QString(" ") + commandLine;
if (argument != 0)
cmd += QString(" ") + argument;
cmd += QString(" \"") + argument + QString("\"");
if (debug) qDebug() << "[Netctl]" << "[cmdCall]" << ":" << "Run cmd" << cmd;
TaskResult process = runTask(cmd, (useSuid && sudo));
if (debug) qDebug() << "[Netctl]" << "[cmdCall]" << ":" << "Cmd returns" << process.exitCode;
if (process.exitCode != 0)
if (debug) qDebug() << "[Netctl]" << "[cmdCall]" << ":" << "Error" << process.error;
if (process.exitCode == 0)
return true;
@ -128,10 +130,12 @@ QString Netctl::getCmdOutput(const bool sudo, const QString command, const QStri
cmd = sudoCommand + QString(" ");
cmd += command + QString(" ") + commandLine;
if (argument != 0)
cmd += QString(" ") + argument;
cmd += QString(" \"") + argument + QString("\"");
if (debug) qDebug() << "[Netctl]" << "[getCmdOutput]" << ":" << "Run cmd" << cmd;
TaskResult process = runTask(cmd, (useSuid && sudo));
if (debug) qDebug() << "[Netctl]" << "[getCmdOutput]" << ":" << "Cmd returns" << process.exitCode;
if (process.exitCode != 0)
if (debug) qDebug() << "[Netctl]" << "[getCmdOutput]" << ":" << "Error" << process.error;
return process.output;
}

View File

@ -80,10 +80,12 @@ bool NetctlProfile::copyProfile(const QString oldPath)
}
QString newPath = profileDirectory->absolutePath() + QDir::separator() + QFileInfo(oldPath).fileName();
QString cmd = sudoCommand + QString(" /usr/bin/mv ") + oldPath + QString(" ") + newPath;
QString cmd = sudoCommand + QString(" /usr/bin/mv \"") + oldPath + QString("\" \"") + newPath + QString("\"");
if (debug) qDebug() << "[NetctlProfile]" << "[copyProfile]" << ":" << "Run cmd" << cmd;
TaskResult process = runTask(cmd, useSuid);
if (debug) qDebug() << "[NetctlProfile]" << "[copyProfile]" << ":" << "Cmd returns" << process.exitCode;
if (process.exitCode != 0)
if (debug) qDebug() << "[NetctlProfile]" << "[copyProfile]" << ":" << "Error" << process.error;
if (process.exitCode == 0)
return true;
@ -143,13 +145,13 @@ QMap<QString, QString> NetctlProfile::getSettingsFromProfile(const QString profi
// getting variables list
// system variables
QProcess shell;
QString cmd = QString("env -i bash -c \"set\"");
if (debug) qDebug() << "[NetctlProfile]" << "[getSettingsFromProfile]" << ":" << "Run cmd" << cmd;
shell.start(cmd);
shell.waitForFinished(-1);
if (debug) qDebug() << "[NetctlProfile]" << "[getSettingsFromProfile]" << ":" << "Cmd returns" << shell.exitCode();
QStringList output = QString(shell.readAllStandardOutput()).trimmed().split(QChar('\n'));
TaskResult process = runTask(cmd, false);
if (debug) qDebug() << "[NetctlProfile]" << "[getSettingsFromProfile]" << ":" << "Cmd returns" << process.exitCode;
if (process.exitCode != 0)
if (debug) qDebug() << "[NetctlProfile]" << "[getSettingsFromProfile]" << ":" << "Error" << process.error;
QStringList output = QString(process.output).trimmed().split(QChar('\n'));
QStringList systemVariables;
systemVariables.append(QString("PIPESTATUS"));
for (int i=0; i<output.count(); i++)
@ -157,12 +159,13 @@ QMap<QString, QString> NetctlProfile::getSettingsFromProfile(const QString profi
// profile variables
QMap<QString, QString> settings;
QString profileUrl = profileDirectory->absolutePath() + QDir::separator() + QFileInfo(profile).fileName();
cmd = QString("env -i bash -c \"source ") + profileUrl + QString("; set\"");
cmd = QString("env -i bash -c \"source '") + profileUrl + QString("'; set\"");
if (debug) qDebug() << "[NetctlProfile]" << "[getSettingsFromProfile]" << ":" << "Run cmd" << cmd;
shell.start(cmd);
shell.waitForFinished(-1);
if (debug) qDebug() << "[NetctlProfile]" << "[getSettingsFromProfile]" << ":" << "Cmd returns" << shell.exitCode();
output = QString(shell.readAllStandardOutput()).trimmed().split(QChar('\n'));
process = runTask(cmd, false);
if (debug) qDebug() << "[NetctlProfile]" << "[getSettingsFromProfile]" << ":" << "Cmd returns" << process.exitCode;
if (process.exitCode != 0)
if (debug) qDebug() << "[NetctlProfile]" << "[getSettingsFromProfile]" << ":" << "Error" << process.error;
output = QString(process.output).trimmed().split(QChar('\n'));
// gettings variables
QStringList keys;
@ -170,12 +173,11 @@ QMap<QString, QString> NetctlProfile::getSettingsFromProfile(const QString profi
if (!systemVariables.contains(output[i].split(QChar('='))[0]))
keys.append(output[i].split(QChar('='))[0]);
for (int i=0; i<keys.count(); i++){
cmd = QString("env -i bash -c \"source ") + profileUrl +
QString("; for i in ${!") + keys[i] + QString("[@]}; do echo ${") +
cmd = QString("env -i bash -c \"source '") + profileUrl +
QString("'; for i in ${!") + keys[i] + QString("[@]}; do echo ${") +
keys[i] + QString("[$i]}; done\"");
shell.start(cmd);
shell.waitForFinished(-1);
settings[keys[i]] = shell.readAllStandardOutput().trimmed();
process = runTask(cmd, false);
settings[keys[i]] = process.output.trimmed();
if (debug) qDebug() << "[NetctlProfile]" << "[getSettingsFromProfile]" << ":" << keys[i] << "=" << settings[keys[i]];
}
@ -197,7 +199,7 @@ QString NetctlProfile::getValueFromProfile(const QString profile, const QString
if (settings.contains(key))
return settings[key];
else
return QString("");
return QString();
}
@ -214,10 +216,12 @@ bool NetctlProfile::removeProfile(const QString profile)
}
QString profilePath = profileDirectory->absolutePath() + QDir::separator() + QFileInfo(profile).fileName();
QString cmd = sudoCommand + QString(" /usr/bin/rm ") + profilePath;
QString cmd = sudoCommand + QString(" /usr/bin/rm \"") + profilePath + QString("\"");
if (debug) qDebug() << "[NetctlProfile]" << "[removeProfile]" << ":" << "Run cmd" << cmd;
TaskResult process = runTask(cmd, useSuid);
if (debug) qDebug() << "[NetctlProfile]" << "[removeProfile]" << ":" << "Cmd returns" << process.exitCode;
if (process.exitCode != 0)
if (debug) qDebug() << "[NetctlProfile]" << "[removeProfile]" << ":" << "Error" << process.error;
if (process.exitCode == 0)
return true;

View File

@ -269,6 +269,8 @@ bool WpaSup::startWpaSupplicant()
TaskResult process = runTask(cmd, useSuid);
waitForProcess(1);
if (debug) qDebug() << "[WpaSup]" << "[startWpaSupplicant]" << ":" << "Cmd returns" << process.exitCode;
if (process.exitCode != 0)
if (debug) qDebug() << "[WpaSup]" << "[startWpaSupplicant]" << ":" << "Error" << process.error;
if (process.exitCode == 0)
return true;
@ -324,6 +326,8 @@ QString WpaSup::getWpaCliOutput(const QString commandLine)
if (debug) qDebug() << "[WpaSup]" << "[getWpaCliOutput]" << ":" << "Run cmd" << cmd;
TaskResult process = runTask(cmd);
if (debug) qDebug() << "[WpaSup]" << "[getWpaCliOutput]" << ":" << "Cmd returns" << process.exitCode;
if (process.exitCode != 0)
if (debug) qDebug() << "[WpaSup]" << "[getWpaCliOutput]" << ":" << "Error" << process.error;
return process.output;
}
@ -380,6 +384,8 @@ bool WpaSup::wpaCliCall(const QString commandLine)
TaskResult process = runTask(cmd);
waitForProcess(1);
if (debug) qDebug() << "[WpaSup]" << "[getWpaCliOutput]" << ":" << "Cmd returns" << process.exitCode;
if (process.exitCode != 0)
if (debug) qDebug() << "[NetctlProfile]" << "[getWpaCliOutput]" << ":" << "Error" << process.error;
if (process.exitCode == 0)
return true;