diff --git a/sources/CMakeLists.txt b/sources/CMakeLists.txt index 53f625e..59330d4 100644 --- a/sources/CMakeLists.txt +++ b/sources/CMakeLists.txt @@ -19,6 +19,7 @@ option (WITH_DEBUG_MODE "Build with debug mode" OFF) option (BUILD_GUI "Build GUI" ON) option (BUILD_DATAENGINE "Build data engine" ON) option (BUILD_PLASMOID "Build plasmoid" ON) +option (BUILD_SCRIPTS "Build special scripts" ON) # verbose set (CMAKE_VERBOSE_MAKEFILE ON) @@ -50,3 +51,6 @@ endif () if (BUILD_PLASMOID) add_subdirectory (plasmoid) endif () +if (BUILD_SCRIPTS) + add_subdirectory (scripts) +endif() diff --git a/sources/gui/CMakeLists.txt b/sources/gui/CMakeLists.txt index 059cda6..e5fe024 100644 --- a/sources/gui/CMakeLists.txt +++ b/sources/gui/CMakeLists.txt @@ -15,5 +15,3 @@ set (HEADERS "") add_subdirectory (${SUBPROJECT_SOURCE_DIR}) install (FILES ${SUBPROJECT}.desktop DESTINATION share/applications/) -install (FILES ${SUBPROJECT}-logo.png DESTINATION share/pixmaps/) -install (FILES ${SUBPROJECT}.png DESTINATION share/icons/hicolor/32x32/apps/) diff --git a/sources/gui/netctl-gui.desktop b/sources/gui/netctl-gui.desktop new file mode 100755 index 0000000..d30b0ef --- /dev/null +++ b/sources/gui/netctl-gui.desktop @@ -0,0 +1,10 @@ +#!/usr/bin/env xdg-open +[Desktop Entry] +Name=Netctl GUI +Comment=GUI written on Qt4 for netctl +Exec=netctl-gui +Icon=netctl-gui.png +Terminal=false +Encoding=UTF-8 +Type=Application +Categories=Network diff --git a/sources/gui/src/mainwindow.cpp b/sources/gui/src/mainwindow.cpp index a12646c..85dc194 100644 --- a/sources/gui/src/mainwindow.cpp +++ b/sources/gui/src/mainwindow.cpp @@ -18,6 +18,8 @@ #include "mainwindow.h" #include "ui_mainwindow.h" +#include + #include "netctlinteract.h" #include "wpasupinteract.h" #include @@ -37,15 +39,16 @@ MainWindow::MainWindow(QWidget *parent) // temporary block netctlPath = QString("/usr/bin/netctl"); profileDir = QString("/etc/netctl"); - sudoPath = QString("/usr/bin/kdesu"); + sudoPath = QString("/usr/bin/sudo"); wpaConfig.append(QString("/usr/bin/wpa_cli")); wpaConfig.append(QString("/usr/bin/wpa_supplicant")); ifaceDir = QString("/sys/class/net/"); - preferedInterface = QString("wifi0"); + preferedInterface = QString(""); // additional settings wpaConfig.append(QString("/run/wpa_supplicant_netctl-gui.pid")); wpaConfig.append(QString("nl80211,wext")); wpaConfig.append(QString("/run/wpa_supplicant_netctl-gui")); + wpaConfig.append(QString("users")); netctlCommand = new Netctl(this, netctlPath, profileDir, sudoPath); wpaCommand = new WpaSup(this, wpaConfig, sudoPath, ifaceDir, preferedInterface); @@ -54,6 +57,7 @@ MainWindow::MainWindow(QWidget *parent) updateMainTab(); } + MainWindow::~MainWindow() { delete netctlCommand; @@ -62,6 +66,21 @@ MainWindow::~MainWindow() } +bool MainWindow::checkExternalApps() +{ + QProcess command; + command.start(QString("which ") + netctlPath + + QString(" ") + sudoPath + + QString(" ") + wpaConfig[0] + + QString(" ") + wpaConfig[1]); + command.waitForFinished(-1); + if (command.exitCode() != 0) + return false; + else + return true; +} + + // window signals void MainWindow::createActions() { @@ -89,11 +108,13 @@ void MainWindow::updateTabs(const int tab) void MainWindow::updateMainTab() { + if (!checkExternalApps()) + return; + QStringList profiles = netctlCommand->getProfileList(); QStringList descriptions = netctlCommand->getProfileDescriptions(profiles); QStringList statuses = netctlCommand->getProfileStatuses(profiles); - ui->tableWidget_main->setRowCount(profiles.count()); ui->tableWidget_main->sortByColumn(0, Qt::AscendingOrder); @@ -113,15 +134,19 @@ void MainWindow::updateMainTab() void MainWindow::updateWifiTab() { + if (!checkExternalApps()) + return; + QList scanResults = wpaCommand->scanWifi(); - for (int i=0; itableWidget_main->setDisabled(true); QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text(); netctlCommand->enableProfile(profile); @@ -144,6 +169,9 @@ void MainWindow::mainTabEnableProfile() void MainWindow::mainTabRestartProfile() { + if (!checkExternalApps()) + return; + ui->tableWidget_main->setDisabled(true); QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text(); netctlCommand->restartProfile(profile); @@ -158,6 +186,9 @@ void MainWindow::mainTabRestartProfile() void MainWindow::mainTabStartProfile() { + if (!checkExternalApps()) + return; + ui->tableWidget_main->setDisabled(true); QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text(); netctlCommand->startProfile(profile); @@ -181,12 +212,11 @@ void MainWindow::mainTabStartProfile() void MainWindow::mainTabRefreshButtons(QTableWidgetItem *current, QTableWidgetItem *previous) { Q_UNUSED(previous); + if (!checkExternalApps()) + return; QString profile = ui->tableWidget_main->item(current->row(), 0)->text(); - bool isActive = netctlCommand->isProfileActive(profile); - bool isEnable = netctlCommand->isProfileEnabled(profile); - - if (isActive) { + if (netctlCommand->isProfileActive(profile)) { ui->pushButton_mainRestart->setEnabled(true); ui->pushButton_mainStart->setText(QApplication::translate("MainWindow", "Stop")); } @@ -194,7 +224,7 @@ void MainWindow::mainTabRefreshButtons(QTableWidgetItem *current, QTableWidgetIt ui->pushButton_mainRestart->setDisabled(true); ui->pushButton_mainStart->setText(QApplication::translate("MainWindow", "Start")); } - if (isEnable) + if (netctlCommand->isProfileEnabled(profile)) ui->pushButton_mainEnable->setText(QApplication::translate("MainWindow", "Disable")); else ui->pushButton_mainEnable->setText(QApplication::translate("MainWindow", "Enable")); diff --git a/sources/gui/src/mainwindow.h b/sources/gui/src/mainwindow.h index 1ee9772..c07059f 100644 --- a/sources/gui/src/mainwindow.h +++ b/sources/gui/src/mainwindow.h @@ -43,8 +43,10 @@ public: wpaSupplicantPath = 1, wpaPidPath = 2, wpadSupDrivers = 3, - wpaConfDir = 4 + wpaConfDir = 4, + wpaConfGroup = 5 }; + bool checkExternalApps(); private slots: void updateTabs(const int tab); diff --git a/sources/gui/src/wpasupinteract.cpp b/sources/gui/src/wpasupinteract.cpp index 9fd9200..0d3706c 100644 --- a/sources/gui/src/wpasupinteract.cpp +++ b/sources/gui/src/wpasupinteract.cpp @@ -31,9 +31,10 @@ WpaSup::WpaSup(MainWindow *wid, QStringList wpaConfig, QString sudoPath, QString ifaceDirectory(new QDir(ifaceDir)), mainInterface(preferedInterface) { - if (QFile(wpaConf[2]).exists()) { + // remove old files if they exist + if (QFile(wpaConf[2]).exists() || QDir(wpaConf[4]).exists()) { QProcess command; - command.start(sudoCommand + QString(" /usr/bin/rm -f ") + wpaConf[2]); + command.start(sudoCommand + QString(" /usr/bin/rm -f ") + wpaConf[2] + QString(" ") + wpaConf[4]); command.waitForFinished(-1); } } @@ -70,8 +71,8 @@ bool WpaSup::wpaCliCall(QString commandLine) { QString interface = getInterfaceList()[0]; QProcess command; - command.start(sudoCommand + QString(" ") + wpaConf[0] + QString(" -i ") + interface + - QString(" -p ") + wpaConf[4] + QString(" ") + commandLine); + command.start(wpaConf[0] + QString(" -i ") + interface + QString(" -p ") + wpaConf[4] + + QString(" ") + commandLine); command.waitForFinished(-1); SleepThread::sleep(1); if (command.exitCode() == 0) @@ -85,8 +86,8 @@ QString WpaSup::getWpaCliOutput(QString commandLine) { QString interface = getInterfaceList()[0]; QProcess command; - command.start(sudoCommand + QString(" ") + wpaConf[0] + QString(" -i ") + interface + - QString(" -p ") + wpaConf[4] + QString(" ") + commandLine); + command.start(wpaConf[0] + QString(" -i ") + interface + QString(" -p ") + wpaConf[4] + + QString(" ") + commandLine); command.waitForFinished(-1); return command.readAllStandardOutput(); } @@ -98,7 +99,8 @@ bool WpaSup::startWpaSupplicant() QString interface = getInterfaceList()[0]; QProcess command; command.start(sudoCommand + QString(" ") + wpaConf[1] + QString(" -B -P ") + wpaConf[2] + - QString(" -i ") + interface + QString(" -D ") + wpaConf[3] + QString(" -C ") + wpaConf[4]); + QString(" -i ") + interface + QString(" -D ") + wpaConf[3] + + QString(" -C \"DIR=") + wpaConf[4] + QString(" GROUP=") + wpaConf[5]); command.waitForFinished(-1); SleepThread::sleep(1); if (command.exitCode() != 0) @@ -124,6 +126,7 @@ QList WpaSup::scanWifi() QStringList rawOutput = getWpaCliOutput(QString("scan_results")).split(QString("\n")); rawOutput.removeFirst(); + rawOutput.removeLast(); for (int i=0; i 4) for (int j=i+1; j WpaSup::scanWifi() for (int i=0; i 4) - wifiPoint.append(rawOutput[i].split(QString(" "), QString::SkipEmptyParts)[4]); + // point name + if (rawOutput[i].split(QString("\t"), QString::SkipEmptyParts).count() > 4) + wifiPoint.append(rawOutput[i].split(QString("\t"), QString::SkipEmptyParts)[4]); else wifiPoint.append(QString("")); - wifiPoint.append(rawOutput[i].split(QString(" "), QString::SkipEmptyParts)[2]); - wifiPoint.append(rawOutput[i].split(QString(" "), QString::SkipEmptyParts)[1]); - wifiPoint.append(rawOutput[i].split(QString(" "), QString::SkipEmptyParts)[0]); + // point signal + wifiPoint.append(rawOutput[i].split(QString("\t"), QString::SkipEmptyParts)[2]); + // point security + QString security = rawOutput[i].split(QString("\t"), QString::SkipEmptyParts)[3]; + if (security.indexOf(QString("WPA2"))) + security = QString("WPA2"); + else if (security.indexOf(QString("WPA"))) + security = QString("WPA"); + else if (security.indexOf(QString("WEP"))) + security = QString("WEP"); + else + security = QString("none"); + wifiPoint.append(security); + // point bssid + wifiPoint.append(rawOutput[i].split(QString("\t"), QString::SkipEmptyParts)[0]); + // profile existance scanResults.append(wifiPoint); } diff --git a/sources/scripts/CMakeLists.txt b/sources/scripts/CMakeLists.txt new file mode 100644 index 0000000..efdecf2 --- /dev/null +++ b/sources/scripts/CMakeLists.txt @@ -0,0 +1,8 @@ +# set project name +set (SUBPROJECT netctl-gui-scripts) +message (STATUS "Subproject ${SUBPROJECT}") + +install (FILES netctl-gui-netctl DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) +install (FILES netctl-gui-wpa_supplicant DESTINATION bin + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) diff --git a/sources/scripts/netctl-gui-netctl b/sources/scripts/netctl-gui-netctl new file mode 100755 index 0000000..7a4b73a --- /dev/null +++ b/sources/scripts/netctl-gui-netctl @@ -0,0 +1,4 @@ +#!/bin/bash + +/usr/bin/netctl $@ + diff --git a/sources/scripts/netctl-gui-wpa_supplicant b/sources/scripts/netctl-gui-wpa_supplicant new file mode 100755 index 0000000..bce05f0 --- /dev/null +++ b/sources/scripts/netctl-gui-wpa_supplicant @@ -0,0 +1,4 @@ +#!/bin/bash + +wpa_supplicant $@ +