mirror of
https://github.com/arcan1s/netctl-gui.git
synced 2025-04-24 15:37:23 +00:00
edited wpa functions, added scripts
This commit is contained in:
parent
4a2a27176f
commit
d9571b76cf
@ -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()
|
||||
|
@ -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/)
|
||||
|
10
sources/gui/netctl-gui.desktop
Executable file
10
sources/gui/netctl-gui.desktop
Executable file
@ -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
|
@ -18,6 +18,8 @@
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
|
||||
#include <QProcess>
|
||||
|
||||
#include "netctlinteract.h"
|
||||
#include "wpasupinteract.h"
|
||||
#include <cstdio>
|
||||
@ -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<QStringList> scanResults = wpaCommand->scanWifi();
|
||||
for (int i=0; i<scanResults.count(); i++)
|
||||
printf("%s\n", scanResults[i][0].toUtf8().data());
|
||||
}
|
||||
|
||||
|
||||
// main tab slots
|
||||
void MainWindow::mainTabEnableProfile()
|
||||
{
|
||||
if (!checkExternalApps())
|
||||
return;
|
||||
|
||||
ui->tableWidget_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"));
|
||||
|
@ -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);
|
||||
|
@ -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<QStringList> WpaSup::scanWifi()
|
||||
|
||||
QStringList rawOutput = getWpaCliOutput(QString("scan_results")).split(QString("\n"));
|
||||
rawOutput.removeFirst();
|
||||
rawOutput.removeLast();
|
||||
for (int i=0; i<rawOutput.count()-1; i++)
|
||||
if (rawOutput[i].split(QString(" "), QString::SkipEmptyParts).count() > 4)
|
||||
for (int j=i+1; j<rawOutput.count(); j++)
|
||||
@ -135,13 +138,27 @@ QList<QStringList> WpaSup::scanWifi()
|
||||
for (int i=0; i<rawOutput.count(); i++) {
|
||||
QStringList wifiPoint;
|
||||
|
||||
if (rawOutput[i].split(QString(" "), QString::SkipEmptyParts).count() > 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("<hidden>"));
|
||||
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);
|
||||
}
|
||||
|
8
sources/scripts/CMakeLists.txt
Normal file
8
sources/scripts/CMakeLists.txt
Normal file
@ -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)
|
4
sources/scripts/netctl-gui-netctl
Executable file
4
sources/scripts/netctl-gui-netctl
Executable file
@ -0,0 +1,4 @@
|
||||
#!/bin/bash
|
||||
|
||||
/usr/bin/netctl $@
|
||||
|
4
sources/scripts/netctl-gui-wpa_supplicant
Executable file
4
sources/scripts/netctl-gui-wpa_supplicant
Executable file
@ -0,0 +1,4 @@
|
||||
#!/bin/bash
|
||||
|
||||
wpa_supplicant $@
|
||||
|
Loading…
Reference in New Issue
Block a user