mirror of
https://github.com/arcan1s/netctl-gui.git
synced 2025-04-24 15:37:23 +00:00
small commit
This commit is contained in:
parent
fc43861ba6
commit
4a2a27176f
4
sources/gui/show_scripts
Executable file
4
sources/gui/show_scripts
Executable file
@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
kate /usr/lib/network/wpa /usr/lib/network/globals /usr/bin/wifi-menu &> /dev/null
|
||||||
|
|
@ -37,12 +37,18 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
// temporary block
|
// temporary block
|
||||||
netctlPath = QString("/usr/bin/netctl");
|
netctlPath = QString("/usr/bin/netctl");
|
||||||
profileDir = QString("/etc/netctl");
|
profileDir = QString("/etc/netctl");
|
||||||
sudoPath = QString("/usr/bin/kdesu -c");
|
sudoPath = QString("/usr/bin/kdesu");
|
||||||
wpaCliPath = QString("/usr/bin/wpa_cli");
|
wpaConfig.append(QString("/usr/bin/wpa_cli"));
|
||||||
|
wpaConfig.append(QString("/usr/bin/wpa_supplicant"));
|
||||||
ifaceDir = QString("/sys/class/net/");
|
ifaceDir = QString("/sys/class/net/");
|
||||||
|
preferedInterface = QString("wifi0");
|
||||||
|
// additional settings
|
||||||
|
wpaConfig.append(QString("/run/wpa_supplicant_netctl-gui.pid"));
|
||||||
|
wpaConfig.append(QString("nl80211,wext"));
|
||||||
|
wpaConfig.append(QString("/run/wpa_supplicant_netctl-gui"));
|
||||||
|
|
||||||
netctlCommand = new Netctl(this, netctlPath, profileDir, sudoPath);
|
netctlCommand = new Netctl(this, netctlPath, profileDir, sudoPath);
|
||||||
wpaCliCommand = new WpaSup(this, wpaCliPath, ifaceDir);
|
wpaCommand = new WpaSup(this, wpaConfig, sudoPath, ifaceDir, preferedInterface);
|
||||||
|
|
||||||
createActions();
|
createActions();
|
||||||
updateMainTab();
|
updateMainTab();
|
||||||
@ -51,6 +57,7 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
{
|
{
|
||||||
delete netctlCommand;
|
delete netctlCommand;
|
||||||
|
delete wpaCommand;
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,7 +113,9 @@ void MainWindow::updateMainTab()
|
|||||||
|
|
||||||
void MainWindow::updateWifiTab()
|
void MainWindow::updateWifiTab()
|
||||||
{
|
{
|
||||||
|
QList<QStringList> scanResults = wpaCommand->scanWifi();
|
||||||
|
for (int i=0; i<scanResults.count(); i++)
|
||||||
|
printf("%s\n", scanResults[i][0].toUtf8().data());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -38,6 +38,13 @@ class MainWindow : public QMainWindow
|
|||||||
public:
|
public:
|
||||||
explicit MainWindow(QWidget *parent = 0);
|
explicit MainWindow(QWidget *parent = 0);
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
|
enum wpaConfigIndex {
|
||||||
|
wpaCliPath = 0,
|
||||||
|
wpaSupplicantPath = 1,
|
||||||
|
wpaPidPath = 2,
|
||||||
|
wpadSupDrivers = 3,
|
||||||
|
wpaConfDir = 4
|
||||||
|
};
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void updateTabs(const int tab);
|
void updateTabs(const int tab);
|
||||||
@ -51,15 +58,16 @@ private slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Netctl *netctlCommand;
|
Netctl *netctlCommand;
|
||||||
WpaSup *wpaCliCommand;
|
WpaSup *wpaCommand;
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
void createActions();
|
void createActions();
|
||||||
// configuration
|
// configuration
|
||||||
QString netctlPath;
|
QString netctlPath;
|
||||||
QString profileDir;
|
QString profileDir;
|
||||||
QString sudoPath;
|
QString sudoPath;
|
||||||
QString wpaCliPath;
|
QStringList wpaConfig;
|
||||||
QString ifaceDir;
|
QString ifaceDir;
|
||||||
|
QString preferedInterface;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -66,6 +66,9 @@
|
|||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Refresh</string>
|
<string>Refresh</string>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string>Ctrl+R</string>
|
||||||
|
</property>
|
||||||
<property name="autoDefault">
|
<property name="autoDefault">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
@ -181,6 +184,9 @@
|
|||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Refresh</string>
|
<string>Refresh</string>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string>Ctrl+R</string>
|
||||||
|
</property>
|
||||||
<property name="autoDefault">
|
<property name="autoDefault">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
|
@ -37,6 +37,8 @@ public:
|
|||||||
QStringList getProfileStatuses(QStringList profileList);
|
QStringList getProfileStatuses(QStringList profileList);
|
||||||
bool isProfileActive(QString profile);
|
bool isProfileActive(QString profile);
|
||||||
bool isProfileEnabled(QString profile);
|
bool isProfileEnabled(QString profile);
|
||||||
|
|
||||||
|
public slots:
|
||||||
// functions
|
// functions
|
||||||
bool enableProfile(QString profile);
|
bool enableProfile(QString profile);
|
||||||
bool restartProfile(QString profile);
|
bool restartProfile(QString profile);
|
||||||
|
46
sources/gui/src/sleepthread.h
Normal file
46
sources/gui/src/sleepthread.h
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* This file is part of netctl-plasmoid *
|
||||||
|
* *
|
||||||
|
* netctl-plasmoid is free software: you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU General Public License as *
|
||||||
|
* published by the Free Software Foundation, either version 3 of the *
|
||||||
|
* License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* netctl-plasmoid is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
* GNU General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU General Public License *
|
||||||
|
* along with netctl-plasmoid. If not, see http://www.gnu.org/licenses/ *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#ifndef SLEEPTHREAD_H
|
||||||
|
#define SLEEPTHREAD_H
|
||||||
|
|
||||||
|
#include <QThread>
|
||||||
|
|
||||||
|
|
||||||
|
// class for sleeping function
|
||||||
|
class SleepThread : public QThread
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
// private run
|
||||||
|
void run () {}
|
||||||
|
|
||||||
|
public :
|
||||||
|
static void usleep(long iSleepTime)
|
||||||
|
{
|
||||||
|
QThread::usleep(iSleepTime);
|
||||||
|
}
|
||||||
|
static void sleep(long iSleepTime)
|
||||||
|
{
|
||||||
|
QThread::sleep(iSleepTime);
|
||||||
|
}
|
||||||
|
static void msleep(long iSleepTime)
|
||||||
|
{
|
||||||
|
QThread::msleep(iSleepTime);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* SLEEPTHREAD_H */
|
@ -17,16 +17,25 @@
|
|||||||
|
|
||||||
#include "wpasupinteract.h"
|
#include "wpasupinteract.h"
|
||||||
|
|
||||||
|
#include <QProcess>
|
||||||
|
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
#include "sleepthread.h"
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
|
|
||||||
WpaSup::WpaSup(MainWindow *wid, QString wpaCliPath, QString ifaceDir)
|
WpaSup::WpaSup(MainWindow *wid, QStringList wpaConfig, QString sudoPath, QString ifaceDir, QString preferedInterface)
|
||||||
: parent(wid),
|
: parent(wid),
|
||||||
wpaCliCommand(wpaCliPath),
|
wpaConf(wpaConfig),
|
||||||
ifaceDirectory(new QDir(ifaceDir))
|
sudoCommand(sudoPath),
|
||||||
|
ifaceDirectory(new QDir(ifaceDir)),
|
||||||
|
mainInterface(preferedInterface)
|
||||||
{
|
{
|
||||||
|
if (QFile(wpaConf[2]).exists()) {
|
||||||
|
QProcess command;
|
||||||
|
command.start(sudoCommand + QString(" /usr/bin/rm -f ") + wpaConf[2]);
|
||||||
|
command.waitForFinished(-1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -40,13 +49,103 @@ WpaSup::~WpaSup()
|
|||||||
QStringList WpaSup::getInterfaceList()
|
QStringList WpaSup::getInterfaceList()
|
||||||
{
|
{
|
||||||
QStringList interfaces;
|
QStringList interfaces;
|
||||||
QStringList allInterfaces;
|
|
||||||
|
|
||||||
allInterfaces = ifaceDirectory->entryList(QDir::Dirs | QDir::NoDotAndDotDot);
|
if (mainInterface.isEmpty()) {
|
||||||
for (int i=0; i<allInterfaces.count(); i++)
|
QStringList allInterfaces;
|
||||||
if (QDir(ifaceDirectory->path() + QDir::separator() + allInterfaces[i] +
|
allInterfaces = ifaceDirectory->entryList(QDir::Dirs | QDir::NoDotAndDotDot);
|
||||||
QDir::separator() + QString("wireless")).exists())
|
for (int i=0; i<allInterfaces.count(); i++)
|
||||||
interfaces.append(allInterfaces[i]);
|
if (QDir(ifaceDirectory->path() + QDir::separator() + allInterfaces[i] +
|
||||||
|
QDir::separator() + QString("wireless")).exists())
|
||||||
|
interfaces.append(allInterfaces[i]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
interfaces.append(mainInterface);
|
||||||
|
|
||||||
return interfaces;
|
return interfaces;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// functions
|
||||||
|
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.waitForFinished(-1);
|
||||||
|
SleepThread::sleep(1);
|
||||||
|
if (command.exitCode() == 0)
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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.waitForFinished(-1);
|
||||||
|
return command.readAllStandardOutput();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool WpaSup::startWpaSupplicant()
|
||||||
|
{
|
||||||
|
if (!QFile(wpaConf[2]).exists()) {
|
||||||
|
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]);
|
||||||
|
command.waitForFinished(-1);
|
||||||
|
SleepThread::sleep(1);
|
||||||
|
if (command.exitCode() != 0)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool WpaSup::stopWpaSupplicant()
|
||||||
|
{
|
||||||
|
return wpaCliCall(QString("terminate"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QList<QStringList> WpaSup::scanWifi()
|
||||||
|
{
|
||||||
|
QList<QStringList> scanResults;
|
||||||
|
startWpaSupplicant();
|
||||||
|
if (!wpaCliCall(QString("scan")))
|
||||||
|
return scanResults;
|
||||||
|
SleepThread::sleep(3);
|
||||||
|
|
||||||
|
QStringList rawOutput = getWpaCliOutput(QString("scan_results")).split(QString("\n"));
|
||||||
|
rawOutput.removeFirst();
|
||||||
|
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++)
|
||||||
|
if (rawOutput[j].split(QString(" "), QString::SkipEmptyParts).count() > 4)
|
||||||
|
if (rawOutput[i].split(QString(" "), QString::SkipEmptyParts)[4] ==
|
||||||
|
rawOutput[j].split(QString(" "), QString::SkipEmptyParts)[4])
|
||||||
|
rawOutput.removeAt(j);
|
||||||
|
|
||||||
|
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]);
|
||||||
|
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]);
|
||||||
|
|
||||||
|
scanResults.append(wifiPoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
stopWpaSupplicant();
|
||||||
|
return scanResults;
|
||||||
|
}
|
||||||
|
@ -29,15 +29,26 @@ class WpaSup : public QWidget
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
WpaSup(MainWindow *wid, QString wpaCliPath, QString ifaceDir);
|
WpaSup(MainWindow *wid, QStringList wpaConfig, QString sudoPath, QString ifaceDir, QString preferedInterface);
|
||||||
~WpaSup();
|
~WpaSup();
|
||||||
// general information
|
// general information
|
||||||
QStringList getInterfaceList();
|
QStringList getInterfaceList();
|
||||||
|
// functions
|
||||||
|
bool wpaCliCall(QString commandLine);
|
||||||
|
QString getWpaCliOutput(QString commandLine);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
// functions
|
||||||
|
bool startWpaSupplicant();
|
||||||
|
bool stopWpaSupplicant();
|
||||||
|
QList<QStringList> scanWifi();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MainWindow *parent;
|
MainWindow *parent;
|
||||||
QString wpaCliCommand;
|
QStringList wpaConf;
|
||||||
|
QString sudoCommand;
|
||||||
QDir *ifaceDirectory;
|
QDir *ifaceDirectory;
|
||||||
|
QString mainInterface;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user