mirror of
https://github.com/arcan1s/netctl-gui.git
synced 2025-04-24 15:37:23 +00:00
refactoring of library part
This commit is contained in:
parent
53ff63b792
commit
8b33ec859b
@ -59,8 +59,7 @@ Netctl::Netctl(const bool debugCmd, const QMap<QString, QString> settings)
|
|||||||
if (settings.contains(QString("SYSTEMCTL_PATH")))
|
if (settings.contains(QString("SYSTEMCTL_PATH")))
|
||||||
systemctlCommand = settings[QString("SYSTEMCTL_PATH")];
|
systemctlCommand = settings[QString("SYSTEMCTL_PATH")];
|
||||||
if (settings.contains(QString("FORCE_SUDO")))
|
if (settings.contains(QString("FORCE_SUDO")))
|
||||||
if (settings[QString("FORCE_SUDO")] == QString("true"))
|
useSuid = (settings[QString("FORCE_SUDO")] != QString("true"));
|
||||||
useSuid = false;
|
|
||||||
|
|
||||||
if (useSuid)
|
if (useSuid)
|
||||||
sudoCommand = QString("");
|
sudoCommand = QString("");
|
||||||
@ -89,27 +88,24 @@ bool Netctl::cmdCall(const bool sudo, const QString command, const QString comma
|
|||||||
if (debug) qDebug() << PDEBUG << ":" << "Command" << command;
|
if (debug) qDebug() << PDEBUG << ":" << "Command" << command;
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Command line" << commandLine;
|
if (debug) qDebug() << PDEBUG << ":" << "Command line" << commandLine;
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Argument" << argument;
|
if (debug) qDebug() << PDEBUG << ":" << "Argument" << argument;
|
||||||
if (command == 0) {
|
if (command.isEmpty()) {
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Could not find command";
|
if (debug) qDebug() << PDEBUG << ":" << "Could not find command";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString cmd = QString("");
|
QString cmd = QString("");
|
||||||
if (sudo)
|
if (sudo)
|
||||||
cmd = sudoCommand + QString(" ");
|
cmd = QString("%1 ").arg(sudoCommand);
|
||||||
cmd += command + QString(" ") + commandLine;
|
cmd += QString("%1 %2").arg(command).arg(commandLine);
|
||||||
if (argument != 0)
|
if (!argument.isEmpty())
|
||||||
cmd += QString(" \"") + argument + QString("\"");
|
cmd += QString(" \"%1\"").arg(argument);
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd;
|
if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd;
|
||||||
TaskResult process = runTask(cmd, (useSuid && sudo));
|
TaskResult process = runTask(cmd, (useSuid && sudo));
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
|
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
|
||||||
if (process.exitCode != 0)
|
if (process.exitCode != 0)
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
|
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
|
||||||
|
|
||||||
if (process.exitCode == 0)
|
return (process.exitCode == 0);
|
||||||
return true;
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -122,17 +118,17 @@ QString Netctl::getCmdOutput(const bool sudo, const QString command, const QStri
|
|||||||
if (debug) qDebug() << PDEBUG << ":" << "Command" << command;
|
if (debug) qDebug() << PDEBUG << ":" << "Command" << command;
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Command line" << commandLine;
|
if (debug) qDebug() << PDEBUG << ":" << "Command line" << commandLine;
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Argument" << argument;
|
if (debug) qDebug() << PDEBUG << ":" << "Argument" << argument;
|
||||||
if (command == 0) {
|
if (command.isEmpty()) {
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Could not find command";
|
if (debug) qDebug() << PDEBUG << ":" << "Could not find command";
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString cmd = QString("");
|
QString cmd = QString("");
|
||||||
if (sudo)
|
if (sudo)
|
||||||
cmd = sudoCommand + QString(" ");
|
cmd = QString("%1 ").arg(sudoCommand);
|
||||||
cmd += command + QString(" ") + commandLine;
|
cmd += QString("%1 %2").arg(command).arg(commandLine);
|
||||||
if (argument != 0)
|
if (!argument.isEmpty())
|
||||||
cmd += QString(" \"") + argument + QString("\"");
|
cmd += QString(" \"%1\"").arg(argument);
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd;
|
if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd;
|
||||||
TaskResult process = runTask(cmd, (useSuid && sudo));
|
TaskResult process = runTask(cmd, (useSuid && sudo));
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
|
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
|
||||||
@ -194,10 +190,7 @@ QList<netctlProfileInfo> Netctl::getProfileList()
|
|||||||
netctlProfileInfo profileInfo;
|
netctlProfileInfo profileInfo;
|
||||||
profileInfo.name = output[i].mid(2, -1);
|
profileInfo.name = output[i].mid(2, -1);
|
||||||
profileInfo.description = getProfileDescription(profileInfo.name);
|
profileInfo.description = getProfileDescription(profileInfo.name);
|
||||||
if (output[i][0] == QChar('*'))
|
profileInfo.active = (output[i][0] == QChar('*'));
|
||||||
profileInfo.active = true;
|
|
||||||
else
|
|
||||||
profileInfo.active = false;
|
|
||||||
profileInfo.enabled = isProfileEnabled(profileInfo.name);
|
profileInfo.enabled = isProfileEnabled(profileInfo.name);
|
||||||
fullProfilesInfo.append(profileInfo);
|
fullProfilesInfo.append(profileInfo);
|
||||||
}
|
}
|
||||||
@ -220,12 +213,8 @@ QList<netctlProfileInfo> Netctl::getProfileListFromNetctlAuto()
|
|||||||
netctlProfileInfo profileInfo;
|
netctlProfileInfo profileInfo;
|
||||||
profileInfo.name = output[i].mid(2, -1);
|
profileInfo.name = output[i].mid(2, -1);
|
||||||
profileInfo.description = getProfileDescription(profileInfo.name);
|
profileInfo.description = getProfileDescription(profileInfo.name);
|
||||||
profileInfo.active = false;
|
profileInfo.active = (output[i][0] == QChar('*'));
|
||||||
profileInfo.enabled = true;
|
profileInfo.enabled = (output[i][0] != QChar('!'));
|
||||||
if (output[i][0] == QChar('*'))
|
|
||||||
profileInfo.active = true;
|
|
||||||
else if (output[i][0] == QChar('!'))
|
|
||||||
profileInfo.enabled = false;
|
|
||||||
fullProfilesInfo.append(profileInfo);
|
fullProfilesInfo.append(profileInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,12 +268,9 @@ bool Netctl::isProfileActive(const QString profile)
|
|||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
|
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
|
||||||
|
|
||||||
bool status = false;
|
|
||||||
QString output = getCmdOutput(false, netctlCommand, QString("status"), profile);
|
QString output = getCmdOutput(false, netctlCommand, QString("status"), profile);
|
||||||
if (output.contains(QString("Active: active")))
|
|
||||||
status = true;
|
|
||||||
|
|
||||||
return status;
|
return (output.contains(QString("Active: active")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -346,17 +332,17 @@ bool Netctl::autoIsProfileEnabled(const QString profile)
|
|||||||
bool Netctl::isNetctlAutoEnabled()
|
bool Netctl::isNetctlAutoEnabled()
|
||||||
{
|
{
|
||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
if (netctlAutoService == 0) {
|
if (netctlAutoService.isEmpty()) {
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Could not find service";
|
if (debug) qDebug() << PDEBUG << ":" << "Could not find service";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (getWirelessInterfaceList().isEmpty()) {
|
QStringList interfaces = getWirelessInterfaceList();
|
||||||
|
if (interfaces.isEmpty()) {
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Could not interface";
|
if (debug) qDebug() << PDEBUG << ":" << "Could not interface";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString interface = getWirelessInterfaceList()[0];
|
QString argument = QString("%1@%2.service").arg(netctlAutoService).arg(interfaces[0]);
|
||||||
QString argument = netctlAutoService + QString("@") + interface + QString(".service");
|
|
||||||
|
|
||||||
return cmdCall(false, systemctlCommand, QString("is-enabled"), argument);
|
return cmdCall(false, systemctlCommand, QString("is-enabled"), argument);
|
||||||
}
|
}
|
||||||
@ -368,7 +354,7 @@ bool Netctl::isNetctlAutoEnabled()
|
|||||||
bool Netctl::isNetctlAutoRunning()
|
bool Netctl::isNetctlAutoRunning()
|
||||||
{
|
{
|
||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
if (netctlAutoService == 0) {
|
if (netctlAutoService.isEmpty()) {
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Could not find service";
|
if (debug) qDebug() << PDEBUG << ":" << "Could not find service";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -378,8 +364,7 @@ bool Netctl::isNetctlAutoRunning()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString interface = interfaces[0];
|
QString argument = QString("%1@%2.service").arg(netctlAutoService).arg(interfaces[0]);
|
||||||
QString argument = netctlAutoService + QString("@") + interface + QString(".service");
|
|
||||||
|
|
||||||
return cmdCall(false, systemctlCommand, QString("is-active"), argument);
|
return cmdCall(false, systemctlCommand, QString("is-active"), argument);
|
||||||
}
|
}
|
||||||
@ -391,7 +376,6 @@ bool Netctl::isNetctlAutoRunning()
|
|||||||
QMap<QString, QString> Netctl::getRecommendedConfiguration()
|
QMap<QString, QString> Netctl::getRecommendedConfiguration()
|
||||||
{
|
{
|
||||||
QMap<QString, QString> settings;
|
QMap<QString, QString> settings;
|
||||||
QString cmd;
|
|
||||||
TaskResult process;
|
TaskResult process;
|
||||||
QStringList recommended;
|
QStringList recommended;
|
||||||
// force sudo
|
// force sudo
|
||||||
@ -401,8 +385,7 @@ QMap<QString, QString> Netctl::getRecommendedConfiguration()
|
|||||||
recommended.append(QString("netctlgui-helper"));
|
recommended.append(QString("netctlgui-helper"));
|
||||||
recommended.append(QString("netctlgui-helper-suid"));
|
recommended.append(QString("netctlgui-helper-suid"));
|
||||||
for (int i=0; i<recommended.count(); i++) {
|
for (int i=0; i<recommended.count(); i++) {
|
||||||
cmd = QString("which ") + recommended[i];
|
process = runTask(QString("which %1").arg(recommended[i]), false);
|
||||||
process = runTask(cmd, false);
|
|
||||||
if (process.exitCode == 0) {
|
if (process.exitCode == 0) {
|
||||||
settings[QString("FORCE_SUDO")] = QString("false");
|
settings[QString("FORCE_SUDO")] = QString("false");
|
||||||
break;
|
break;
|
||||||
@ -430,8 +413,7 @@ QMap<QString, QString> Netctl::getRecommendedConfiguration()
|
|||||||
recommended.clear();
|
recommended.clear();
|
||||||
recommended.append("netctl");
|
recommended.append("netctl");
|
||||||
for (int i=0; i<recommended.count(); i++) {
|
for (int i=0; i<recommended.count(); i++) {
|
||||||
cmd = QString("which ") + recommended[i];
|
process = runTask(QString("which %1").arg(recommended[i]), false);
|
||||||
process = runTask(cmd, false);
|
|
||||||
if (process.exitCode == 0) {
|
if (process.exitCode == 0) {
|
||||||
settings[QString("NETCTL_PATH")] = process.output.trimmed();
|
settings[QString("NETCTL_PATH")] = process.output.trimmed();
|
||||||
break;
|
break;
|
||||||
@ -443,8 +425,7 @@ QMap<QString, QString> Netctl::getRecommendedConfiguration()
|
|||||||
recommended.clear();
|
recommended.clear();
|
||||||
recommended.append("netctl-auto");
|
recommended.append("netctl-auto");
|
||||||
for (int i=0; i<recommended.count(); i++) {
|
for (int i=0; i<recommended.count(); i++) {
|
||||||
cmd = QString("which ") + recommended[i];
|
process = runTask(QString("which %1").arg(recommended[i]), false);
|
||||||
process = runTask(cmd, false);
|
|
||||||
if (process.exitCode == 0) {
|
if (process.exitCode == 0) {
|
||||||
settings[QString("NETCTLAUTO_PATH")] = process.output.trimmed();
|
settings[QString("NETCTLAUTO_PATH")] = process.output.trimmed();
|
||||||
break;
|
break;
|
||||||
@ -474,8 +455,7 @@ QMap<QString, QString> Netctl::getRecommendedConfiguration()
|
|||||||
recommended.append("kdesu");
|
recommended.append("kdesu");
|
||||||
recommended.append("gksu");
|
recommended.append("gksu");
|
||||||
for (int i=0; i<recommended.count(); i++) {
|
for (int i=0; i<recommended.count(); i++) {
|
||||||
cmd = QString("which ") + recommended[i];
|
process = runTask(QString("which %1").arg(recommended[i]), false);
|
||||||
process = runTask(cmd, false);
|
|
||||||
if (process.exitCode == 0) {
|
if (process.exitCode == 0) {
|
||||||
settings[QString("SUDO_PATH")] = process.output.trimmed();
|
settings[QString("SUDO_PATH")] = process.output.trimmed();
|
||||||
break;
|
break;
|
||||||
@ -487,8 +467,7 @@ QMap<QString, QString> Netctl::getRecommendedConfiguration()
|
|||||||
recommended.clear();
|
recommended.clear();
|
||||||
recommended.append("systemctl");
|
recommended.append("systemctl");
|
||||||
for (int i=0; i<recommended.count(); i++) {
|
for (int i=0; i<recommended.count(); i++) {
|
||||||
cmd = QString("which ") + recommended[i];
|
process = runTask(QString("which %1").arg(recommended[i]), false);
|
||||||
process = runTask(cmd, false);
|
|
||||||
if (process.exitCode == 0) {
|
if (process.exitCode == 0) {
|
||||||
settings[QString("SYSTEMCTL_PATH")] = process.output.trimmed();
|
settings[QString("SYSTEMCTL_PATH")] = process.output.trimmed();
|
||||||
break;
|
break;
|
||||||
@ -505,7 +484,7 @@ QMap<QString, QString> Netctl::getRecommendedConfiguration()
|
|||||||
QStringList Netctl::getWirelessInterfaceList()
|
QStringList Netctl::getWirelessInterfaceList()
|
||||||
{
|
{
|
||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
if (ifaceDirectory == 0) {
|
if (ifaceDirectory == nullptr) {
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Could not find directory";
|
if (debug) qDebug() << PDEBUG << ":" << "Could not find directory";
|
||||||
return QStringList();
|
return QStringList();
|
||||||
}
|
}
|
||||||
@ -515,10 +494,11 @@ QStringList Netctl::getWirelessInterfaceList()
|
|||||||
interfaces.append(mainInterface);
|
interfaces.append(mainInterface);
|
||||||
QStringList allInterfaces = ifaceDirectory->entryList(QDir::Dirs | QDir::NoDotAndDotDot);
|
QStringList allInterfaces = ifaceDirectory->entryList(QDir::Dirs | QDir::NoDotAndDotDot);
|
||||||
for (int i=0; i<allInterfaces.count(); i++) {
|
for (int i=0; i<allInterfaces.count(); i++) {
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Check directory"
|
QString dir = QString("%1%2%3%2wireless").arg(ifaceDirectory->path())
|
||||||
<< ifaceDirectory->path() + QDir::separator() + allInterfaces[i] + QDir::separator() + QString("wireless");
|
.arg(QDir::separator())
|
||||||
if (QDir(ifaceDirectory->path() + QDir::separator() + allInterfaces[i] +
|
.arg(allInterfaces[i]);
|
||||||
QDir::separator() + QString("wireless")).exists())
|
if (debug) qDebug() << PDEBUG << ":" << "Check directory" << dir;
|
||||||
|
if (QDir(dir).exists())
|
||||||
interfaces.append(allInterfaces[i]);
|
interfaces.append(allInterfaces[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -624,10 +604,8 @@ bool Netctl::switchToProfile(const QString profile)
|
|||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
|
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
|
||||||
|
|
||||||
if (isProfileActive(profile))
|
return ((isProfileActive(profile)) ||
|
||||||
return true;
|
(cmdCall(true, netctlCommand, QString("switch-to"), profile)));
|
||||||
else
|
|
||||||
return cmdCall(true, netctlCommand, QString("switch-to"), profile);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -676,10 +654,8 @@ bool Netctl::autoStartProfile(const QString profile)
|
|||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
|
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
|
||||||
|
|
||||||
if (autoIsProfileActive(profile))
|
return ((autoIsProfileActive(profile)) ||
|
||||||
return true;
|
(cmdCall(false, netctlAutoCommand, QString("switch-to"), profile)));
|
||||||
else
|
|
||||||
return cmdCall(false, netctlAutoCommand, QString("switch-to"), profile);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -689,7 +665,7 @@ bool Netctl::autoStartProfile(const QString profile)
|
|||||||
bool Netctl::autoEnableService()
|
bool Netctl::autoEnableService()
|
||||||
{
|
{
|
||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
if (netctlAutoService == 0) {
|
if (netctlAutoService.isEmpty()) {
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Could not find service";
|
if (debug) qDebug() << PDEBUG << ":" << "Could not find service";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -699,8 +675,7 @@ bool Netctl::autoEnableService()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString interface = interfaces[0];
|
QString argument = QString("%1@%2.service").arg(netctlAutoService).arg(interfaces[0]);
|
||||||
QString argument = netctlAutoService + QString("@") + interface + QString(".service");
|
|
||||||
|
|
||||||
if (isNetctlAutoEnabled())
|
if (isNetctlAutoEnabled())
|
||||||
return cmdCall(true, systemctlCommand, QString("disable"), argument);
|
return cmdCall(true, systemctlCommand, QString("disable"), argument);
|
||||||
@ -715,7 +690,7 @@ bool Netctl::autoEnableService()
|
|||||||
bool Netctl::autoRestartService()
|
bool Netctl::autoRestartService()
|
||||||
{
|
{
|
||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
if (netctlAutoService == 0) {
|
if (netctlAutoService.isEmpty()) {
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Could not find service";
|
if (debug) qDebug() << PDEBUG << ":" << "Could not find service";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -725,13 +700,10 @@ bool Netctl::autoRestartService()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString interface = interfaces[0];
|
QString argument = QString("%1@%2.service").arg(netctlAutoService).arg(interfaces[0]);
|
||||||
QString argument = netctlAutoService + QString("@") + interface + QString(".service");
|
|
||||||
|
|
||||||
if (isNetctlAutoRunning())
|
return ((!isNetctlAutoRunning()) ||
|
||||||
return cmdCall(true, systemctlCommand, QString("restart"), argument);
|
(cmdCall(true, systemctlCommand, QString("restart"), argument)));
|
||||||
else
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -741,7 +713,7 @@ bool Netctl::autoRestartService()
|
|||||||
bool Netctl::autoStartService()
|
bool Netctl::autoStartService()
|
||||||
{
|
{
|
||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
if (netctlAutoService == 0) {
|
if (netctlAutoService.isEmpty()) {
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Could not find service";
|
if (debug) qDebug() << PDEBUG << ":" << "Could not find service";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -751,8 +723,7 @@ bool Netctl::autoStartService()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString interface = interfaces[0];
|
QString argument = QString("%1@%2.service").arg(netctlAutoService).arg(interfaces[0]);
|
||||||
QString argument = netctlAutoService + QString("@") + interface + QString(".service");
|
|
||||||
|
|
||||||
if (isNetctlAutoRunning())
|
if (isNetctlAutoRunning())
|
||||||
return cmdCall(true, systemctlCommand, QString("stop"), argument);
|
return cmdCall(true, systemctlCommand, QString("stop"), argument);
|
||||||
|
@ -50,8 +50,7 @@ NetctlProfile::NetctlProfile(const bool debugCmd, const QMap<QString, QString> s
|
|||||||
if (settings.contains(QString("SUDO_PATH")))
|
if (settings.contains(QString("SUDO_PATH")))
|
||||||
sudoCommand = settings[QString("SUDO_PATH")];
|
sudoCommand = settings[QString("SUDO_PATH")];
|
||||||
if (settings.contains(QString("FORCE_SUDO")))
|
if (settings.contains(QString("FORCE_SUDO")))
|
||||||
if (settings[QString("FORCE_SUDO")] == QString("true"))
|
useSuid = (settings[QString("FORCE_SUDO")] != QString("true"));
|
||||||
useSuid = false;
|
|
||||||
|
|
||||||
if (useSuid)
|
if (useSuid)
|
||||||
sudoCommand = QString("");
|
sudoCommand = QString("");
|
||||||
@ -76,23 +75,24 @@ bool NetctlProfile::copyProfile(const QString oldPath)
|
|||||||
{
|
{
|
||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Path" << oldPath;
|
if (debug) qDebug() << PDEBUG << ":" << "Path" << oldPath;
|
||||||
if (profileDirectory == 0) {
|
if (profileDirectory == nullptr) {
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Could not find directory";
|
if (debug) qDebug() << PDEBUG << ":" << "Could not find directory";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString newPath = profileDirectory->absolutePath() + QDir::separator() + QFileInfo(oldPath).fileName();
|
QString newPath = QString("%1%2%3").arg(profileDirectory->absolutePath())
|
||||||
QString cmd = sudoCommand + QString(" /usr/bin/mv \"") + oldPath + QString("\" \"") + newPath + QString("\"");
|
.arg(QDir::separator())
|
||||||
|
.arg(QFileInfo(oldPath).fileName());
|
||||||
|
QString cmd = QString("%1 /usr/bin/mv \"%2\" \"%3\"").arg(sudoCommand)
|
||||||
|
.arg(oldPath)
|
||||||
|
.arg(newPath);
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd;
|
if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd;
|
||||||
TaskResult process = runTask(cmd, useSuid);
|
TaskResult process = runTask(cmd, useSuid);
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
|
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
|
||||||
if (process.exitCode != 0)
|
if (process.exitCode != 0)
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
|
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
|
||||||
|
|
||||||
if (process.exitCode == 0)
|
return (process.exitCode == 0);
|
||||||
return true;
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -104,7 +104,9 @@ QString NetctlProfile::createProfile(const QString profile, const QMap<QString,
|
|||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
|
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
|
||||||
|
|
||||||
QString profileTempName = QDir::tempPath() + QDir::separator() + QFileInfo(profile).fileName();
|
QString profileTempName = QString("%1%2%3").arg(QDir::tempPath())
|
||||||
|
.arg(QDir::separator())
|
||||||
|
.arg(QFileInfo(profile).fileName());
|
||||||
QFile profileFile(profileTempName);
|
QFile profileFile(profileTempName);
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Save to" << profileTempName;
|
if (debug) qDebug() << PDEBUG << ":" << "Save to" << profileTempName;
|
||||||
if (!profileFile.open(QIODevice::WriteOnly | QIODevice::Text))
|
if (!profileFile.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||||
@ -123,7 +125,7 @@ QString NetctlProfile::createProfile(const QString profile, const QMap<QString,
|
|||||||
(settings.keys()[i] == QString("DNSOptions")) ||
|
(settings.keys()[i] == QString("DNSOptions")) ||
|
||||||
(settings.keys()[i] == QString("ScanFrequencies")) ||
|
(settings.keys()[i] == QString("ScanFrequencies")) ||
|
||||||
(settings.keys()[i] == QString("WPAConfigSection")))
|
(settings.keys()[i] == QString("WPAConfigSection")))
|
||||||
out << QString("(") + settings[settings.keys()[i]] << QString(")") << endl;
|
out << QString("(%1)").arg(settings[settings.keys()[i]]) << endl;
|
||||||
else
|
else
|
||||||
out << settings[settings.keys()[i]] << endl;
|
out << settings[settings.keys()[i]] << endl;
|
||||||
}
|
}
|
||||||
@ -139,7 +141,6 @@ QString NetctlProfile::createProfile(const QString profile, const QMap<QString,
|
|||||||
QMap<QString, QString> NetctlProfile::getRecommendedConfiguration()
|
QMap<QString, QString> NetctlProfile::getRecommendedConfiguration()
|
||||||
{
|
{
|
||||||
QMap<QString, QString> settings;
|
QMap<QString, QString> settings;
|
||||||
QString cmd;
|
|
||||||
TaskResult process;
|
TaskResult process;
|
||||||
QStringList recommended;
|
QStringList recommended;
|
||||||
// force sudo
|
// force sudo
|
||||||
@ -149,8 +150,7 @@ QMap<QString, QString> NetctlProfile::getRecommendedConfiguration()
|
|||||||
recommended.append(QString("netctlgui-helper"));
|
recommended.append(QString("netctlgui-helper"));
|
||||||
recommended.append(QString("netctlgui-helper-suid"));
|
recommended.append(QString("netctlgui-helper-suid"));
|
||||||
for (int i=0; i<recommended.count(); i++) {
|
for (int i=0; i<recommended.count(); i++) {
|
||||||
cmd = QString("which ") + recommended[i];
|
process = runTask(QString("which %1").arg(recommended[i]), false);
|
||||||
process = runTask(cmd, false);
|
|
||||||
if (process.exitCode == 0) {
|
if (process.exitCode == 0) {
|
||||||
settings[QString("FORCE_SUDO")] = QString("false");
|
settings[QString("FORCE_SUDO")] = QString("false");
|
||||||
break;
|
break;
|
||||||
@ -177,8 +177,7 @@ QMap<QString, QString> NetctlProfile::getRecommendedConfiguration()
|
|||||||
recommended.append("kdesu");
|
recommended.append("kdesu");
|
||||||
recommended.append("gksu");
|
recommended.append("gksu");
|
||||||
for (int i=0; i<recommended.count(); i++) {
|
for (int i=0; i<recommended.count(); i++) {
|
||||||
cmd = QString("which ") + recommended[i];
|
process = runTask(QString("which %1").arg(recommended[i]), false);
|
||||||
process = runTask(cmd, false);
|
|
||||||
if (process.exitCode == 0) {
|
if (process.exitCode == 0) {
|
||||||
settings[QString("SUDO_PATH")] = process.output.trimmed();
|
settings[QString("SUDO_PATH")] = process.output.trimmed();
|
||||||
break;
|
break;
|
||||||
@ -196,7 +195,7 @@ QMap<QString, QString> NetctlProfile::getSettingsFromProfile(const QString profi
|
|||||||
{
|
{
|
||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
|
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
|
||||||
if (profileDirectory == 0) {
|
if (profileDirectory == nullptr) {
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Could not find directory";
|
if (debug) qDebug() << PDEBUG << ":" << "Could not find directory";
|
||||||
return QMap<QString, QString>();
|
return QMap<QString, QString>();
|
||||||
}
|
}
|
||||||
@ -216,8 +215,10 @@ QMap<QString, QString> NetctlProfile::getSettingsFromProfile(const QString profi
|
|||||||
systemVariables.append(output[i].split(QChar('='))[0]);
|
systemVariables.append(output[i].split(QChar('='))[0]);
|
||||||
// profile variables
|
// profile variables
|
||||||
QMap<QString, QString> settings;
|
QMap<QString, QString> settings;
|
||||||
QString profileUrl = profileDirectory->absolutePath() + QDir::separator() + QFileInfo(profile).fileName();
|
QString profileUrl = QString("%1%2%3").arg(profileDirectory->absolutePath())
|
||||||
cmd = QString("env -i bash -c \"source '") + profileUrl + QString("'; set\"");
|
.arg(QDir::separator())
|
||||||
|
.arg(QFileInfo(profile).fileName());
|
||||||
|
cmd = QString("env -i bash -c \"source '%1'; set\"").arg(profileUrl);
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd;
|
if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd;
|
||||||
process = runTask(cmd, false);
|
process = runTask(cmd, false);
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
|
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
|
||||||
@ -231,9 +232,7 @@ QMap<QString, QString> NetctlProfile::getSettingsFromProfile(const QString profi
|
|||||||
if (!systemVariables.contains(output[i].split(QChar('='))[0]))
|
if (!systemVariables.contains(output[i].split(QChar('='))[0]))
|
||||||
keys.append(output[i].split(QChar('='))[0]);
|
keys.append(output[i].split(QChar('='))[0]);
|
||||||
for (int i=0; i<keys.count(); i++){
|
for (int i=0; i<keys.count(); i++){
|
||||||
cmd = QString("env -i bash -c \"source '") + profileUrl +
|
cmd = QString("env -i bash -c \"source '%1'; for i in ${!%2[@]}; do echo ${%2[$i]}; done\"").arg(profileUrl).arg(keys[i]);
|
||||||
QString("'; for i in ${!") + keys[i] + QString("[@]}; do echo ${") +
|
|
||||||
keys[i] + QString("[$i]}; done\"");
|
|
||||||
process = runTask(cmd, false);
|
process = runTask(cmd, false);
|
||||||
settings[keys[i]] = process.output.trimmed();
|
settings[keys[i]] = process.output.trimmed();
|
||||||
if (debug) qDebug() << PDEBUG << ":" << keys[i] << "=" << settings[keys[i]];
|
if (debug) qDebug() << PDEBUG << ":" << keys[i] << "=" << settings[keys[i]];
|
||||||
@ -254,10 +253,7 @@ QString NetctlProfile::getValueFromProfile(const QString profile, const QString
|
|||||||
|
|
||||||
QMap<QString, QString> settings = getSettingsFromProfile(profile);
|
QMap<QString, QString> settings = getSettingsFromProfile(profile);
|
||||||
|
|
||||||
if (settings.contains(key))
|
return settings[key];
|
||||||
return settings[key];
|
|
||||||
else
|
|
||||||
return QString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -268,21 +264,20 @@ bool NetctlProfile::removeProfile(const QString profile)
|
|||||||
{
|
{
|
||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
|
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
|
||||||
if (profileDirectory == 0) {
|
if (profileDirectory == nullptr) {
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Could not find directory";
|
if (debug) qDebug() << PDEBUG << ":" << "Could not find directory";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString profilePath = profileDirectory->absolutePath() + QDir::separator() + QFileInfo(profile).fileName();
|
QString profilePath = QString("%1%2%3").arg(profileDirectory->absolutePath())
|
||||||
QString cmd = sudoCommand + QString(" /usr/bin/rm \"") + profilePath + QString("\"");
|
.arg(QDir::separator())
|
||||||
|
.arg(QFileInfo(profile).fileName());
|
||||||
|
QString cmd = QString("%1 /usr/bin/rm \"%2\"").arg(sudoCommand).arg(profilePath);
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd;
|
if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd;
|
||||||
TaskResult process = runTask(cmd, useSuid);
|
TaskResult process = runTask(cmd, useSuid);
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
|
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
|
||||||
if (process.exitCode != 0)
|
if (process.exitCode != 0)
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
|
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
|
||||||
|
|
||||||
if (process.exitCode == 0)
|
return (process.exitCode == 0);
|
||||||
return true;
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
@ -58,8 +58,7 @@ WpaSup::WpaSup(const bool debugCmd, const QMap<QString, QString> settings)
|
|||||||
if (settings.contains(QString("WPASUP_PATH")))
|
if (settings.contains(QString("WPASUP_PATH")))
|
||||||
wpaSupPath = settings[QString("WPASUP_PATH")];
|
wpaSupPath = settings[QString("WPASUP_PATH")];
|
||||||
if (settings.contains(QString("FORCE_SUDO")))
|
if (settings.contains(QString("FORCE_SUDO")))
|
||||||
if (settings[QString("FORCE_SUDO")] == QString("true"))
|
useSuid = (settings[QString("FORCE_SUDO")] != QString("true"));
|
||||||
useSuid = false;
|
|
||||||
|
|
||||||
if (useSuid)
|
if (useSuid)
|
||||||
sudoCommand = QString("");
|
sudoCommand = QString("");
|
||||||
@ -86,11 +85,11 @@ QString WpaSup::existentProfile(const QString essid)
|
|||||||
{
|
{
|
||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "ESSID" << essid;
|
if (debug) qDebug() << PDEBUG << ":" << "ESSID" << essid;
|
||||||
if (netctlCommand == 0) {
|
if (netctlCommand == nullptr) {
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Could not find library";
|
if (debug) qDebug() << PDEBUG << ":" << "Could not find library";
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
if (netctlProfile == 0) {
|
if (netctlProfile == nullptr) {
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Could not find library";
|
if (debug) qDebug() << PDEBUG << ":" << "Could not find library";
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
@ -112,7 +111,6 @@ QMap<QString, QString> WpaSup::getRecommendedConfiguration()
|
|||||||
{
|
{
|
||||||
QMap<QString, QString> settings;
|
QMap<QString, QString> settings;
|
||||||
int size = 99;
|
int size = 99;
|
||||||
QString cmd;
|
|
||||||
TaskResult process;
|
TaskResult process;
|
||||||
QStringList recommended;
|
QStringList recommended;
|
||||||
// ctrl directory
|
// ctrl directory
|
||||||
@ -142,8 +140,7 @@ QMap<QString, QString> WpaSup::getRecommendedConfiguration()
|
|||||||
recommended.append(QString("netctlgui-helper"));
|
recommended.append(QString("netctlgui-helper"));
|
||||||
recommended.append(QString("netctlgui-helper-suid"));
|
recommended.append(QString("netctlgui-helper-suid"));
|
||||||
for (int i=0; i<recommended.count(); i++) {
|
for (int i=0; i<recommended.count(); i++) {
|
||||||
cmd = QString("which ") + recommended[i];
|
process = runTask(QString("which %1").arg(recommended[i]), false);
|
||||||
process = runTask(cmd, false);
|
|
||||||
if (process.exitCode == 0) {
|
if (process.exitCode == 0) {
|
||||||
settings[QString("FORCE_SUDO")] = QString("false");
|
settings[QString("FORCE_SUDO")] = QString("false");
|
||||||
break;
|
break;
|
||||||
@ -160,8 +157,7 @@ QMap<QString, QString> WpaSup::getRecommendedConfiguration()
|
|||||||
recommended.append("kdesu");
|
recommended.append("kdesu");
|
||||||
recommended.append("gksu");
|
recommended.append("gksu");
|
||||||
for (int i=0; i<recommended.count(); i++) {
|
for (int i=0; i<recommended.count(); i++) {
|
||||||
cmd = QString("which ") + recommended[i];
|
process = runTask(QString("which %1").arg(recommended[i]), false);
|
||||||
process = runTask(cmd, false);
|
|
||||||
if (process.exitCode == 0) {
|
if (process.exitCode == 0) {
|
||||||
settings[QString("SUDO_PATH")] = process.output.trimmed();
|
settings[QString("SUDO_PATH")] = process.output.trimmed();
|
||||||
break;
|
break;
|
||||||
@ -173,8 +169,7 @@ QMap<QString, QString> WpaSup::getRecommendedConfiguration()
|
|||||||
recommended.clear();
|
recommended.clear();
|
||||||
recommended.append("wpa_cli");
|
recommended.append("wpa_cli");
|
||||||
for (int i=0; i<recommended.count(); i++) {
|
for (int i=0; i<recommended.count(); i++) {
|
||||||
cmd = QString("which ") + recommended[i];
|
process = runTask(QString("which %1").arg(recommended[i]), false);
|
||||||
process = runTask(cmd, false);
|
|
||||||
if (process.exitCode == 0) {
|
if (process.exitCode == 0) {
|
||||||
settings[QString("WPACLI_PATH")] = process.output.trimmed();
|
settings[QString("WPACLI_PATH")] = process.output.trimmed();
|
||||||
break;
|
break;
|
||||||
@ -189,8 +184,7 @@ QMap<QString, QString> WpaSup::getRecommendedConfiguration()
|
|||||||
recommended.clear();
|
recommended.clear();
|
||||||
recommended.append("wpa_supplicant");
|
recommended.append("wpa_supplicant");
|
||||||
for (int i=0; i<recommended.count(); i++) {
|
for (int i=0; i<recommended.count(); i++) {
|
||||||
cmd = QString("which ") + recommended[i];
|
process = runTask(QString("which %1").arg(recommended[i]), false);
|
||||||
process = runTask(cmd, false);
|
|
||||||
if (process.exitCode == 0) {
|
if (process.exitCode == 0) {
|
||||||
settings[QString("WPASUP_PATH")] = process.output.trimmed();
|
settings[QString("WPASUP_PATH")] = process.output.trimmed();
|
||||||
break;
|
break;
|
||||||
@ -208,11 +202,11 @@ bool WpaSup::isProfileActive(const QString essid)
|
|||||||
{
|
{
|
||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "ESSID" << essid;
|
if (debug) qDebug() << PDEBUG << ":" << "ESSID" << essid;
|
||||||
if (netctlCommand == 0) {
|
if (netctlCommand == nullptr) {
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Could not find library";
|
if (debug) qDebug() << PDEBUG << ":" << "Could not find library";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (netctlProfile == 0) {
|
if (netctlProfile == nullptr) {
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Could not find library";
|
if (debug) qDebug() << PDEBUG << ":" << "Could not find library";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -236,11 +230,11 @@ bool WpaSup::isProfileExists(const QString essid)
|
|||||||
{
|
{
|
||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "ESSID" << essid;
|
if (debug) qDebug() << PDEBUG << ":" << "ESSID" << essid;
|
||||||
if (netctlCommand == 0) {
|
if (netctlCommand == nullptr) {
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Could not find library";
|
if (debug) qDebug() << PDEBUG << ":" << "Could not find library";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (netctlProfile == 0) {
|
if (netctlProfile == nullptr) {
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Could not find library";
|
if (debug) qDebug() << PDEBUG << ":" << "Could not find library";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -269,8 +263,7 @@ QList<netctlWifiInfo> WpaSup::scanWifi()
|
|||||||
stopWpaSupplicant();
|
stopWpaSupplicant();
|
||||||
return scanResults;
|
return scanResults;
|
||||||
}
|
}
|
||||||
if (!wpaCliCall(QString("scan")))
|
if (!wpaCliCall(QString("scan"))) return scanResults;
|
||||||
return scanResults;
|
|
||||||
waitForProcess(3);
|
waitForProcess(3);
|
||||||
|
|
||||||
QStringList rawOutput = getWpaCliOutput(QString("scan_results")).split(QChar('\n'), QString::SkipEmptyParts);
|
QStringList rawOutput = getWpaCliOutput(QString("scan_results")).split(QChar('\n'), QString::SkipEmptyParts);
|
||||||
@ -278,22 +271,22 @@ QList<netctlWifiInfo> WpaSup::scanWifi()
|
|||||||
rawOutput.removeFirst();
|
rawOutput.removeFirst();
|
||||||
// remove duplicates
|
// remove duplicates
|
||||||
QStringList rawList;
|
QStringList rawList;
|
||||||
|
QStringList names;
|
||||||
for (int i=0; i<rawOutput.count(); i++) {
|
for (int i=0; i<rawOutput.count(); i++) {
|
||||||
bool exist = false;
|
if (rawOutput[i].split(QChar('\t'), QString::SkipEmptyParts).count() == 4) {
|
||||||
if (rawOutput[i].split(QChar('\t'), QString::SkipEmptyParts).count() > 4)
|
|
||||||
for (int j=0; j<rawList.count(); j++)
|
|
||||||
if (rawList[j].split(QChar('\t'), QString::SkipEmptyParts).count() > 4)
|
|
||||||
if (rawOutput[i].split(QChar('\t'), QString::SkipEmptyParts)[4] ==
|
|
||||||
rawList[j].split(QChar('\t'), QString::SkipEmptyParts)[4])
|
|
||||||
exist = true;
|
|
||||||
if (!exist)
|
|
||||||
rawList.append(rawOutput[i]);
|
rawList.append(rawOutput[i]);
|
||||||
|
continue;
|
||||||
|
} else if (rawOutput[i].split(QChar('\t'), QString::SkipEmptyParts).count() == 5) {
|
||||||
|
if (names.contains(rawOutput[i].split(QChar('\t'), QString::SkipEmptyParts)[4])) continue;
|
||||||
|
names.append(rawOutput[i].split(QChar('\t'), QString::SkipEmptyParts)[4]);
|
||||||
|
rawList.append(rawOutput[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i=0; i<rawList.count(); i++) {
|
for (int i=0; i<rawList.count(); i++) {
|
||||||
netctlWifiInfo wifiPoint;
|
netctlWifiInfo wifiPoint;
|
||||||
// point name
|
// point name
|
||||||
if (rawList[i].split(QChar('\t'), QString::SkipEmptyParts).count() > 4)
|
if (rawList[i].split(QChar('\t'), QString::SkipEmptyParts).count() == 5)
|
||||||
wifiPoint.name = rawList[i].split(QChar('\t'), QString::SkipEmptyParts)[4];
|
wifiPoint.name = rawList[i].split(QChar('\t'), QString::SkipEmptyParts)[4];
|
||||||
else
|
else
|
||||||
wifiPoint.name = QString("<hidden>");
|
wifiPoint.name = QString("<hidden>");
|
||||||
@ -327,27 +320,27 @@ QList<netctlWifiInfo> WpaSup::scanWifi()
|
|||||||
bool WpaSup::startWpaSupplicant()
|
bool WpaSup::startWpaSupplicant()
|
||||||
{
|
{
|
||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
if (ctrlDir == 0) {
|
if (ctrlDir.isEmpty()) {
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Could not find directory";
|
if (debug) qDebug() << PDEBUG << ":" << "Could not find directory";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (ctrlGroup == 0) {
|
if (ctrlGroup.isEmpty()) {
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Could not find group";
|
if (debug) qDebug() << PDEBUG << ":" << "Could not find group";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (pidFile == 0) {
|
if (pidFile.isEmpty()) {
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Could not find PID file";
|
if (debug) qDebug() << PDEBUG << ":" << "Could not find PID file";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (wpaDrivers == 0) {
|
if (wpaDrivers.isEmpty()) {
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Could not find drivers";
|
if (debug) qDebug() << PDEBUG << ":" << "Could not find drivers";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (wpaSupPath == 0) {
|
if (wpaSupPath.isEmpty()) {
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Could not find wpa_supplicant";
|
if (debug) qDebug() << PDEBUG << ":" << "Could not find wpa_supplicant";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (netctlCommand == 0) {
|
if (netctlCommand == nullptr) {
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Could not find library";
|
if (debug) qDebug() << PDEBUG << ":" << "Could not find library";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -357,12 +350,10 @@ bool WpaSup::startWpaSupplicant()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (QFile(pidFile).exists())
|
if (QFile(pidFile).exists()) return true;
|
||||||
return true;
|
QString cmd = QString("%1 %2 -B -P \"%3\" -i %4 -D %5 -C \"DIR=%6 GROUP=%7\"")
|
||||||
QString interface = interfaces[0];
|
.arg(sudoCommand).arg(wpaSupPath).arg(pidFile).arg(interfaces[0])
|
||||||
QString cmd = sudoCommand + QString(" ") + wpaSupPath + QString(" -B -P ") + pidFile +
|
.arg(wpaDrivers).arg(ctrlDir).arg(ctrlGroup);
|
||||||
QString(" -i ") + interface + QString(" -D ") + wpaDrivers +
|
|
||||||
QString(" -C \"DIR=") + ctrlDir + QString(" GROUP=") + ctrlGroup + QString("\"");
|
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd;
|
if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd;
|
||||||
TaskResult process = runTask(cmd, useSuid);
|
TaskResult process = runTask(cmd, useSuid);
|
||||||
waitForProcess(1);
|
waitForProcess(1);
|
||||||
@ -370,10 +361,7 @@ bool WpaSup::startWpaSupplicant()
|
|||||||
if (process.exitCode != 0)
|
if (process.exitCode != 0)
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
|
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
|
||||||
|
|
||||||
if (process.exitCode == 0)
|
return (process.exitCode == 0);
|
||||||
return true;
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -396,19 +384,19 @@ QString WpaSup::getWpaCliOutput(const QString commandLine)
|
|||||||
{
|
{
|
||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Command" << commandLine;
|
if (debug) qDebug() << PDEBUG << ":" << "Command" << commandLine;
|
||||||
if (ctrlDir == 0) {
|
if (ctrlDir.isEmpty()) {
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Could not find directory";
|
if (debug) qDebug() << PDEBUG << ":" << "Could not find directory";
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
if (pidFile == 0) {
|
if (pidFile.isEmpty()) {
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Could not find PID file";
|
if (debug) qDebug() << PDEBUG << ":" << "Could not find PID file";
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
if (wpaCliPath == 0) {
|
if (wpaCliPath.isEmpty()) {
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Could not find wpa_cli";
|
if (debug) qDebug() << PDEBUG << ":" << "Could not find wpa_cli";
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
if (netctlCommand == 0) {
|
if (netctlCommand == nullptr) {
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Could not find library";
|
if (debug) qDebug() << PDEBUG << ":" << "Could not find library";
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
@ -453,19 +441,19 @@ bool WpaSup::wpaCliCall(const QString commandLine)
|
|||||||
{
|
{
|
||||||
if (debug) qDebug() << PDEBUG;
|
if (debug) qDebug() << PDEBUG;
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Command" << commandLine;
|
if (debug) qDebug() << PDEBUG << ":" << "Command" << commandLine;
|
||||||
if (ctrlDir == 0) {
|
if (ctrlDir.isEmpty()) {
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Could not find directory";
|
if (debug) qDebug() << PDEBUG << ":" << "Could not find directory";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (pidFile == 0) {
|
if (pidFile.isEmpty()) {
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Could not find PID file";
|
if (debug) qDebug() << PDEBUG << ":" << "Could not find PID file";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (wpaCliPath == 0) {
|
if (wpaCliPath.isEmpty()) {
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Could not find wpa_cli";
|
if (debug) qDebug() << PDEBUG << ":" << "Could not find wpa_cli";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (netctlCommand == 0) {
|
if (netctlCommand == nullptr) {
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Could not find library";
|
if (debug) qDebug() << PDEBUG << ":" << "Could not find library";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -485,8 +473,5 @@ bool WpaSup::wpaCliCall(const QString commandLine)
|
|||||||
if (process.exitCode != 0)
|
if (process.exitCode != 0)
|
||||||
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
|
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
|
||||||
|
|
||||||
if (process.exitCode == 0)
|
return (process.exitCode == 0);
|
||||||
return true;
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user