From 0216e9aadb7e794037d3cf553b05474de8322a74 Mon Sep 17 00:00:00 2001 From: Niklas Date: Fri, 23 Sep 2011 14:08:55 +0200 Subject: renamed the logreceiver to networkdiscovery and deleted the abortbootdialog and chooseinterfacedialog since this is now implemented via html/css/jquery --- LogReceiver/LogReceiver.pro | 16 +- LogReceiver/abortbootdialog.cpp | 98 ------- LogReceiver/abortbootdialog.h | 46 --- LogReceiver/chooseinterfacedialog.cpp | 98 ------- LogReceiver/chooseinterfacedialog.h | 44 --- LogReceiver/logreceiver.cpp | 518 ---------------------------------- LogReceiver/logreceiver.h | 98 ------- LogReceiver/ndgui.cpp | 16 +- LogReceiver/ndgui.h | 8 +- LogReceiver/networkdiscovery.cpp | 518 ++++++++++++++++++++++++++++++++++ LogReceiver/networkdiscovery.h | 98 +++++++ 11 files changed, 632 insertions(+), 926 deletions(-) delete mode 100644 LogReceiver/abortbootdialog.cpp delete mode 100644 LogReceiver/abortbootdialog.h delete mode 100644 LogReceiver/chooseinterfacedialog.cpp delete mode 100644 LogReceiver/chooseinterfacedialog.h delete mode 100644 LogReceiver/logreceiver.cpp delete mode 100644 LogReceiver/logreceiver.h create mode 100644 LogReceiver/networkdiscovery.cpp create mode 100644 LogReceiver/networkdiscovery.h diff --git a/LogReceiver/LogReceiver.pro b/LogReceiver/LogReceiver.pro index 2eea3bd..eaa7001 100644 --- a/LogReceiver/LogReceiver.pro +++ b/LogReceiver/LogReceiver.pro @@ -7,18 +7,14 @@ LIBS += -lsysfs \ -L/home/niklas/fbgui/customdhcpcd/src/build \ -llibcustomdhcpcd INCLUDEPATH += /home/niklas/fbgui/customdhcpcd/src -HEADERS += routemanager.h \ +HEADERS += networkdiscovery.h \ + routemanager.h \ interfaceconfiguration.h \ - ndgui.h \ - logreceiver.h \ - abortbootdialog.h \ - chooseinterfacedialog.h -SOURCES += routemanager.cpp \ + ndgui.h +SOURCES += networkdiscovery.cpp \ + routemanager.cpp \ interfaceconfiguration.cpp \ ndgui.cpp \ - main.cpp \ - logreceiver.cpp \ - abortbootdialog.cpp \ - chooseinterfacedialog.cpp + main.cpp FORMS += ndgui.ui RESOURCES += nd.qrc diff --git a/LogReceiver/abortbootdialog.cpp b/LogReceiver/abortbootdialog.cpp deleted file mode 100644 index 1614f6b..0000000 --- a/LogReceiver/abortbootdialog.cpp +++ /dev/null @@ -1,98 +0,0 @@ -#include - -#include "abortbootdialog.h" - -AbortBootDialog::AbortBootDialog(QWidget *parent) : - QDialog(parent) -{ - oneMinuteCountdown = 60; - - createContentGroupBox(); - createButtonGroupBox(); - - createTimer(); - - mainLayout = new QVBoxLayout; - mainLayout->addWidget(contentGroupBox); - mainLayout->addWidget(buttonGroupBox); - - setLayout(mainLayout); - setWindowTitle(tr("Abort Boot")); -} -void AbortBootDialog::createContentGroupBox() -{ - contentGroupBox = new QGroupBox; - timerLabel = new QLabel(QString::number(oneMinuteCountdown)); - QHBoxLayout *layout = new QHBoxLayout; - - - layout->addWidget(new QLabel(tr("test"))); - layout->addWidget(timerLabel); - contentGroupBox->setLayout(layout); -} - -void AbortBootDialog::createButtonGroupBox() -{ - buttonGroupBox = new QGroupBox; - QHBoxLayout *layout = new QHBoxLayout; - - QPushButton *shutDownButton = new QPushButton(tr("Shut Down")); - shutDownButton->setDefault(true); - QPushButton *restartButton = new QPushButton(tr("Restart")); - restartButton->setAutoDefault(false); - QPushButton *showLogButton = new QPushButton(tr("Show Log")); - showLogButton->setAutoDefault(false); - - connect(showLogButton, SIGNAL(clicked()),this, SLOT(showLogButtonClicked())); - connect(shutDownButton, SIGNAL(clicked()), this, SLOT(shutDownButtonClicked())); - connect(restartButton, SIGNAL(clicked()), this, SLOT(restartButtonClicked())); - - layout->addWidget(showLogButton); - layout->addWidget(restartButton); - layout->addWidget(shutDownButton); - buttonGroupBox->setLayout(layout); -} - -void AbortBootDialog::createTimer() -{ - timer = new QTimer(this); - connect(timer, SIGNAL(timeout()),this, SLOT(timerLabelUpdate())); - timer->start(1000); -} - -void AbortBootDialog::showLogButtonClicked() -{ - qDebug() << "show log button clicked"; - emit showLogSignal(); -} - -void AbortBootDialog::shutDownButtonClicked() -{ - qDebug() << "shut down button clicked"; - emit shutDownSignal(); -} - -void AbortBootDialog::restartButtonClicked() -{ - qDebug() << "restart button clicked"; - emit restartSignal(); -} - -void AbortBootDialog::timerLabelUpdate() -{ - oneMinuteCountdown = oneMinuteCountdown -1; - timerLabel->setText(QString::number(oneMinuteCountdown)); - if(oneMinuteCountdown <= 0) - { - timer->stop(); - emit shutDownSignal(); - } - -} - -void AbortBootDialog::closeDialog() -{ - this->hide(); - this->killTimer(timer->timerId()); - this->close(); -} diff --git a/LogReceiver/abortbootdialog.h b/LogReceiver/abortbootdialog.h deleted file mode 100644 index 157331b..0000000 --- a/LogReceiver/abortbootdialog.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef ABORTBOOTDIALOG_H -#define ABORTBOOTDIALOG_H - -#include -#include "qboxlayout.h" -#include "qgroupbox.h" -#include "qcombobox.h" -#include "qlabel.h" - - -class AbortBootDialog : public QDialog -{ - Q_OBJECT -public: - explicit AbortBootDialog(QWidget *parent = 0); - - void closeDialog(); -private slots: - void showLogButtonClicked(); - void shutDownButtonClicked(); - void restartButtonClicked(); - void timerLabelUpdate(); - -private: - QVBoxLayout *mainLayout; - QGroupBox *contentGroupBox; - QGroupBox *buttonGroupBox; - QLabel *timerLabel; - QTimer *timer; - int oneMinuteCountdown; - - void createContentGroupBox(); - void createButtonGroupBox(); - void createTimer(); - - -signals: - void showLogSignal(); - void shutDownSignal(); - void restartSignal(); - -public slots: - -}; - -#endif // ABORTBOOTDIALOG_H diff --git a/LogReceiver/chooseinterfacedialog.cpp b/LogReceiver/chooseinterfacedialog.cpp deleted file mode 100644 index b7a37e8..0000000 --- a/LogReceiver/chooseinterfacedialog.cpp +++ /dev/null @@ -1,98 +0,0 @@ -#include - -#include "chooseinterfacedialog.h" - -ChooseInterfaceDialog::ChooseInterfaceDialog(QStringList &interfaces, QWidget *parent) : - QDialog(parent) -{ - oneMinuteCountdown = 60; - - createContentGroupBox(interfaces); - createButtonGroupBox(); - - createTimer(); - - mainLayout = new QVBoxLayout; - mainLayout->addWidget(contentGroupBox); - mainLayout->addWidget(buttonGroupBox); - - setLayout(mainLayout); - setWindowTitle(tr("Choose Interface")); -} - -void ChooseInterfaceDialog::createContentGroupBox(QStringList &interfaces) -{ - contentGroupBox = new QGroupBox; - timerLabel = new QLabel(QString::number(oneMinuteCountdown)); - QVBoxLayout *groupBoxLayout = new QVBoxLayout; - QHBoxLayout *layout = new QHBoxLayout; - - comboBox = new QComboBox; - comboBox->addItems(interfaces); - - layout->addWidget(new QLabel(tr("test"))); - layout->addWidget(comboBox); - - groupBoxLayout->addWidget(timerLabel); - groupBoxLayout->addLayout(layout); - contentGroupBox->setLayout(groupBoxLayout); -} - -void ChooseInterfaceDialog::createButtonGroupBox() -{ - buttonGroupBox = new QGroupBox; - QHBoxLayout *layout = new QHBoxLayout; - - QPushButton *continueButton = new QPushButton(tr("Continue")); - continueButton->setDefault(true); - QPushButton *shutDownButton = new QPushButton(tr("Shut Down")); - shutDownButton->setAutoDefault(false); - QPushButton *restartButton = new QPushButton(tr("Restart")); - restartButton->setAutoDefault(false); - - connect(continueButton, SIGNAL(clicked()),this, SLOT(continueButtonClicked())); - connect(shutDownButton, SIGNAL(clicked()), this, SLOT(shutDownButtonClicked())); - connect(restartButton, SIGNAL(clicked()), this, SLOT(restartButtonClicked())); - - layout->addWidget(restartButton); - layout->addWidget(shutDownButton); - layout->addWidget(continueButton); - buttonGroupBox->setLayout(layout); -} - -void ChooseInterfaceDialog::createTimer() -{ - timer = new QTimer(this); - connect(timer, SIGNAL(timeout()),this, SLOT(timerLabelUpdate())); - timer->start(1000); -} - -void ChooseInterfaceDialog::continueButtonClicked() -{ - qDebug() << "continue button clicked"; - emit continueSignal(comboBox->currentText()); -} - -void ChooseInterfaceDialog::shutDownButtonClicked() -{ - qDebug() << "shut down button clicked"; - emit shutDownSignal(); -} - -void ChooseInterfaceDialog::restartButtonClicked() -{ - qDebug() << "restart button clicked"; - emit restartSignal(); -} - -void ChooseInterfaceDialog::timerLabelUpdate() -{ - oneMinuteCountdown = oneMinuteCountdown -1; - timerLabel->setText(QString::number(oneMinuteCountdown)); - if(oneMinuteCountdown <= 0) - { - timer->stop(); - emit continueSignal(comboBox->currentText()); - } - -} diff --git a/LogReceiver/chooseinterfacedialog.h b/LogReceiver/chooseinterfacedialog.h deleted file mode 100644 index 48ee038..0000000 --- a/LogReceiver/chooseinterfacedialog.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef CHOOSEINTERFACEDIALOG_H -#define CHOOSEINTERFACEDIALOG_H - -#include -#include "qboxlayout.h" -#include "qgroupbox.h" -#include "qcombobox.h" -#include "qlabel.h" - -class ChooseInterfaceDialog : public QDialog -{ - Q_OBJECT -public: - explicit ChooseInterfaceDialog(QStringList &interfaces, QWidget *parent = 0); -private slots: - void continueButtonClicked(); - void shutDownButtonClicked(); - void restartButtonClicked(); - void timerLabelUpdate(); - -private: - QVBoxLayout *mainLayout; - QGroupBox *contentGroupBox; - QGroupBox *buttonGroupBox; - QComboBox *comboBox; - QLabel *timerLabel; - QTimer *timer; - int oneMinuteCountdown; - - void createContentGroupBox(QStringList &interfaces); - void createButtonGroupBox(); - void createTimer(); - -signals: - void continueSignal(QString ifName); - void shutDownSignal(); - void restartSignal(); - - -public slots: - -}; - -#endif // CHOOSEINTERFACEDIALOG_H diff --git a/LogReceiver/logreceiver.cpp b/LogReceiver/logreceiver.cpp deleted file mode 100644 index 7f8c7f3..0000000 --- a/LogReceiver/logreceiver.cpp +++ /dev/null @@ -1,518 +0,0 @@ -#include "logreceiver.h" - -#include "../common/fbgui.h" - -LogReceiver::LogReceiver(QObject *parent) { - - server = new QLocalServer(this); -} - -LogReceiver::~LogReceiver() { - -} - -void LogReceiver::initAndRun(QString serverPath, QString pathToExe, - QStringList* args) { - - _userChoice = false; - _blocked = false; - - if (serverPath != DEFAULT_QTSOCKETADDRESS) { - dhcpcdArguments.append("-q"); - dhcpcdArguments.append(serverPath); - } - if (!server->listen(serverPath)) { - /* - QMessageBox::critical(this, tr("LogReceiver"), tr( - "Unable to start the server: %1.") .arg(server->errorString())); - close(); - */ - // emit signal to the gui that a critial error occoured - QString errorInfo("Unable to start server: "); - qDebug() << "--- \t [LogReceiver::initAndRun] " + errorInfo - << server->errorString(); - emit - abortBoot(errorInfo + server->errorString()); - return; - } - - connect(server, SIGNAL(newConnection()), this, SLOT(handleNewConnection())); - - pathToDhcpcdExe = pathToExe; - // check if the path to the customdhcpcd file is correct - QFileInfo fInfo(pathToDhcpcdExe); - if (!fInfo.exists()) { - qDebug() - << "couldn't find customdhcpcd exe. Please check the path to this file."; - emit - abortBoot( - "couldn't find customdhcpcd exe. Please check the path to this file."); - return; - } - - if (args != NULL && !args->isEmpty()) { - qDebug() << "--- \t [LogReceiver::initAndRun] added additional args"; - dhcpcdArguments.append(*args); - } - - numberOfProcesses = 0; - - // start the main work: - - QList list = getListOfNetworkInterfaces(); - - if (list.size() > 0) { - - //list = checkCarrierState(list); - - - //dhcpcdArguments.append("-d"); - QString ifName("eth0"); - numberOfProcesses = list.size(); - runDHCPCD(list); - } else { - qDebug() << "list is empty. Haven't found usable interface."; - emit - abortBoot("Haven't found usable interface"); - return; - } - -} - -int LogReceiver::replaceDefaultRoute(QString &ifName, QString &gateway, int af, int mss) { - rm.replaceDefaultRoute(ifName, gateway, mss, AF_INET); -} - -QList LogReceiver::getListOfNetworkInterfaces() { - QList nIList = QNetworkInterface::allInterfaces(); - QList result; - - if (nIList.size() > 0) { - foreach(QNetworkInterface nI, nIList) - { - if (((!(nI.flags() & QNetworkInterface::CanBroadcast) - || nI.flags() & QNetworkInterface::IsLoopBack) - || nI.flags() & QNetworkInterface::IsPointToPoint) - || checkBlackList(nI.humanReadableName())) { - continue; - } - if (!checkCarrierState(nI.humanReadableName())) { - continue; - } - result.append(nI.humanReadableName()); - emit addInterface(nI.humanReadableName()); - } - } else { - qDebug() << "no interfaces found!"; - } - return result; -} - -QList LogReceiver::checkCarrierState(QList &interfaces) { - QList result; - foreach(QString nI, interfaces) - { - if (checkCarrierState(nI)) { - // everything is fine, cable is plugged, - // go on with the next interface - //continue; - result.append(nI); - } - } - return result; -} - -bool LogReceiver::checkCarrierState(QString interface) { - - qDebug() << "check carrier state for interface " << interface; - QByteArray ba = interface.toAscii(); - const char * iface = ba.data(); - - struct sysfs_class_device *class_device = sysfs_open_class_device("net", - iface); - struct dlist *attrlist = sysfs_get_classdev_attributes(class_device); - if (attrlist != NULL) { - struct sysfs_attribute *attr = NULL; - dlist_for_each_data(attrlist, attr, struct sysfs_attribute) { - if (strcmp("carrier", attr->name) == 0) { - QString value(attr->value); - bool ok = false; - bool * pok = &ok; - int v = value.toInt(pok); - if (*pok) { - if (v == 1) { - qDebug() - << "carrier is 1. Cable is plugged. return true"; - return true; - } else { - qDebug() - << "carrier is 0. Cable is unplugged. return false"; - return false; - } - } else { - qDebug() << "conversion error"; - } - } - } - } else { - qDebug() << "attrlist is Null"; - } - sysfs_close_class_device(class_device); - - return true; -} - -void LogReceiver::runDHCPCD(QList &interfaces) { - foreach(QString nI, interfaces) - { - runDHCPCD(nI); - } -} - -void LogReceiver::runDHCPCD(QString interface) { - emit updateStatusLabel(interface, "start DHCP"); - dhcpcdArguments.append(interface); - QProcess * p = new QProcess(this); - - qDebug() << dhcpcdArguments; - - clientProcessToIfNameMap.insert(p, interface); - qDebug() << clientProcessToIfNameMap; - p->start(pathToDhcpcdExe, dhcpcdArguments); - connect(p, SIGNAL(started()), this, SLOT(handleProcessStarted())); - connect(p, SIGNAL(finished(int, QProcess::ExitStatus)), this, - SLOT(handleProcessFinished(int, QProcess::ExitStatus))); - dhcpcdArguments.removeLast(); -} - -bool LogReceiver::checkConnectivity(QString ifName) { - int metric = 0; - - // get gateway address - QString pathToGatewayFile(DEFAULT_GATEWAY_INFO_LOCATION); - pathToGatewayFile += ifName; - interfaceconfiguration ifConf; - ifConf.readConfigOutOfFile(pathToGatewayFile); - - // replace default route - qDebug() << rm.replaceDefaultRoute(ifName, ifConf.getGateway(), 0, AF_INET); - - // check connectivity via tcp connection - QTcpSocket *tcpSocket = new QTcpSocket(this); - tcpSocket->connectToHost(QString("209.85.148.105"), 80); - if (!tcpSocket->waitForConnected(500)) { - qDebug() << "no internet connection with interface" << ifName; - qDebug() << tcpSocket->errorString(); - emit - updateStatusLabel(ifName, "connection not possible"); - return false; - } else { - qDebug() << "internet: check passed! for interface" << ifName; - emit updateStatusLabel(ifName, "connection possible"); - if (!_userChoice) { - // blockiere jeden weiteren check - // emite continueBoot - _blocked = true; - emit continueBoot(ifName, _userChoice); - } else { - emit connectionEstablished(&ifConf); - } - return true; - } -} - -/** - * - */ -void LogReceiver::handleNewConnection() { - qDebug() << "New Connection arrived"; - - /*QLocalSocket **/ - client = server ->nextPendingConnection(); - clients.insert(client, client); - connect(client, SIGNAL(disconnected()), this, - SLOT(handleClientDisconnect())); - connect(client, SIGNAL(readyRead()), this, SLOT(handleNewInput())); -} - -/** - * - */ -void LogReceiver::handleClientDisconnect() { - QLocalSocket* socket = qobject_cast (QObject::sender()); - - QLocalSocket * client = clients.value(socket); - - qDebug() << "disconnect client"; - handleNewInput(client); - client->deleteLater(); -} - -/** - * - */ -void LogReceiver::handleNewInput(QLocalSocket * client) { - qDebug() << "last read before exit"; - while (client->canReadLine()) { - QString data(client->readLine()); - - data = data.trimmed(); - qDebug() << data; - QStringList lines = data.split("\n"); - - for (int i = 0; i < lines.length(); i++) { - handleNewInputLine(client, lines.at(i)); - } - } -} - -/** - * - * This method is connected to the readyRead Signal of the QLocalSocket - * client. - * send an ACK to the client with every received message. - */ -void LogReceiver::handleNewInput() { - QLocalSocket* socket = qobject_cast (QObject::sender()); - - QLocalSocket * client = clients.value(socket); - QString data(client->read(DHCP_MESSAGE_SIZE)); - client->write("ACK", ACK_SIZE); - client->waitForBytesWritten(); - data = data.trimmed(); - //qDebug() << data; - QStringList lines = data.split("\n"); - - for (int i = 0; i < lines.length(); i++) { - handleNewInputLine(client, lines.at(i)); - } -} - -/** - * This Method processes the send messages. - * - * This Method processes the send messages. It splits the line - * into several components. Those components are: - * interface: interface name ==> indicates the process who send the message - * s_state: is the number representation of syslog.h LOG levels - * s_subState: is the number representation of the dhcp.c DHCP states (1 - 8) plus - * the status. h states (9 - ..) - * msg: is a message which can contain additional informations - * - * According to the s_state and s_subState we emit the changeProgressBarValue() signal - * with different values. - * - * @param client - * the client who send the message - * - * @param data - * the message. (format ;;; ) - */ -void LogReceiver::handleNewInputLine(QLocalSocket * client, QString data) { - - QString logMsg(data); - QString interface = logMsg.section(";", 0, 0); - QString s_state = logMsg.section(";", 1, 1); - QString s_subState = logMsg.section(";", 2, 2); - QString msg = logMsg.section(";", 3, 3); - int st = s_state.trimmed().toInt(); - int sst = s_subState.trimmed().toInt(); - //qDebug() << logMsg; - - if (ifNameToClient.size() < numberOfProcesses && !ifNameToClient.contains( - interface)) { - ifNameToClient.insert(interface, client); - } - - switch (st) { - case LOG_INFO: - switch (sst) { - case DHCP_DISCOVER: - emit changeProgressBarValue(interface, 10); - break; - case DHCP_OFFER: - emit changeProgressBarValue(interface, 20); - break; - case DHCP_REQUEST: - emit changeProgressBarValue(interface, 30); - break; - case DHCP_ACK: - emit changeProgressBarValue(interface, 40); - break; - case DHCP_NAK: - emit changeProgressBarValue(interface, 40); - break; - case DHCPCD_ARP_TEST: - emit changeProgressBarValue(interface, 50); - break; - case DHCP_DECLINE: - emit changeProgressBarValue(interface, 60); - break; - case DHCP_RELEASE: - - break; - case DHCP_INFORM: - break; - case DHCPCD_CONFIGURE: - emit changeProgressBarValue(interface, 70); - break; - case DHCPCD_WRITE: - emit changeProgressBarValue(interface, 80); - break; - case DHCPCD_EXIT: - emit changeProgressBarValue(interface, 100); - break; - case DHCPCD_LOG: - - default: - break; - } - break; - case LOG_ERR: - qDebug() << "received error:" << msg; - break; - default: - //qDebug() << logMsg; - break; - } -} - -/** - * This Method is called when a process is finished. - * - * This Method is called when a process is finished. This slot is connected - * with the signal finished() of the QProcess class. - * If the process finishes, it will be checked if the process exited normal - * or if an unexpected error occurred. For this, we determine the sender (which is a - * QProcess), get the corresponding interface (which is stored in a map), and check - * the exitCode. Further actions are taken according to the exitCode check. - * Normal exit: - * emit changeProgressBar() to 100% - * emit updateStatusLabel() to check connection - * checkConnectivity() @see LogReceiver::checkConnectivity() - * Unexpected exit: - * emit updateStatusLabel() to process exited unexpected - * TODO:: the reason for the unexpected exit should be presented in the logfile. - * - * @param exitCode - * - * @param exitStatus - * - * @return bool - * returns true: if the interface name i starts with a letter in the blacklist. - * - * returns false: else - * - * @see LogReceiver::getListOfNetworkInterfaces() - */ -/* -void LogReceiver::handleProcessFinished(int exitCode, - QProcess::ExitStatus exitStatus) { - QProcess* p = qobject_cast (QObject::sender()); - QString ifName = clientProcessToIfNameMap.value(p, "ifName"); - - if (ifName.compare("ifName") == 0) { - qDebug() - << "--- \t [LogReceiver::handleProcessFinished] haven't found process!"; - } else { - qDebug() << "process for interface" << ifName << "finished" << exitCode - << exitStatus; - if (exitCode > 0) { - qDebug() << "process exited unexpected"; - emit updateStatusLabel(ifName, "process exited unexpected"); - } else { - qDebug() << "process normal exit"; - qDebug() << "check internet connection"; - emit - changeProgressBarValue(ifName, 100); - emit - updateStatusLabel(ifName, "check connectivity"); - checkConnectivity(ifName); - } - } - QLocalSocket *client = ifNameToClient.value(ifName, 0); - if (client != 0) { - handleNewInput(client); - } - numberOfProcesses = numberOfProcesses - 1; - if (numberOfProcesses <= 0) { - emit allProcessesFinished(); - } -} -*/ -void LogReceiver::handleProcessFinished(int exitCode, - QProcess::ExitStatus exitStatus) { - - QProcess* p = qobject_cast (QObject::sender()); - QString ifName = clientProcessToIfNameMap.value(p, "ifName"); - if (!_blocked) { //_blocked becomes true, if _userChoice is false and we found a usable interface - if (ifName.compare("ifName") == 0) { - qDebug() - << "--- \t [LogReceiver::handleProcessFinished] haven't found process!"; - } else { - qDebug() << "process for interface" << ifName << "finished" - << exitCode << exitStatus; - if (exitCode > 0) { - qDebug() << "process exited unexpected"; - emit updateStatusLabel(ifName, "process exited unexpected"); - } else { - qDebug() << "process normal exit"; - emit changeProgressBarValue(ifName, 100); - emit updateStatusLabel(ifName, "check connectivity"); - checkConnectivity(ifName); - } - } - if (!_blocked) { //_blocked becomes true, if _userChoice is false and we found a usable interface - QLocalSocket *client = ifNameToClient.value(ifName, 0); - if (client != 0) { - handleNewInput(client); - } - numberOfProcesses = numberOfProcesses - 1; - if (numberOfProcesses <= 0 && _userChoice) { - emit allProcessesFinished(); - } - } - } else { - qDebug() << "already blocked"; - emit updateStatusLabel(ifName, "finished DHCP"); - } -} -/** - * This Method is called when a process is started. - * - * This Method is called when a process is started. - * It prints the message: "process started for interface: ". - */ -void LogReceiver::handleProcessStarted() { - QProcess* p = qobject_cast (QObject::sender()); - QString ifName = clientProcessToIfNameMap.value(p, "ifName"); - qDebug() << "process started for interface:" << ifName; -} - -/** - * This Method implements a blacklist. - * - * This Method implements a blacklist. We check the fist character - * of the interface name. if this letter is in the list, we return true. - * True means, that this interface won't be put into the result list of - * getListOfNetworkInterfaces(). - * - * @param i - * is a interface name. - * - * @return bool - * returns true: if the interface name i starts with a letter in the blacklist. - * - * returns false: else - * - * @see LogReceiver::getListOfNetworkInterfaces() - */ -bool LogReceiver::checkBlackList(QString i) { - if (i.startsWith("v", Qt::CaseInsensitive)) { - return true; - } else if (i.startsWith("d", Qt::CaseInsensitive)) { - return true; - } else { - return false; - } -} diff --git a/LogReceiver/logreceiver.h b/LogReceiver/logreceiver.h deleted file mode 100644 index 7cd12d8..0000000 --- a/LogReceiver/logreceiver.h +++ /dev/null @@ -1,98 +0,0 @@ -#ifndef LOGRECEIVER_H -#define LOGRECEIVER_H - -//#include -#include -#include -//#include - -#include -#include -#include -#include -#include -#include - -#include "interfaceconfiguration.h" -#include "routemanager.h" -//#include -//#include -#include "status.h" -#include "dhcp.h" -#include "interface.h" - -//#include -//#include -//#include -//#include -//#include -#include -//#include -#include - - -#define DEFAULT_QTSOCKETADDRESS "/var/tmp/qt_c_socket_default" -#define DEFAULT_PATHTODHCPCDEXE "/home/niklas/fbgui/customdhcpcd/src/customdhcpcd" -#define DEFAULT_GATEWAY_INFO_LOCATION "/var/tmp/gateways_" -#define ACK_SIZE 4 - -class LogReceiver: public QObject { -Q_OBJECT - -public: - LogReceiver(QObject *parent=0); - ~LogReceiver(); - - void initAndRun(QString serverPath = DEFAULT_QTSOCKETADDRESS, - QString pathToExe = DEFAULT_PATHTODHCPCDEXE, - QStringList* args = NULL); - int replaceDefaultRoute(QString &ifName, QString &gateway, int af, int mss); - -private slots: - void handleNewConnection(); - void handleNewInput(); - void handleNewInputLine(QLocalSocket * client, QString data); - void handleProcessFinished(int exitCode, QProcess::ExitStatus exitStatus); - void handleProcessStarted(); - void handleClientDisconnect(); - -signals: - void addInterface(const QString &ifName); - void changeProgressBarValue(const QString & ifName, const int $newValue); - void connectionEstablished(interfaceconfiguration *ifConf); - void abortBoot(QString msg); - void updateStatusLabel(QString ifName, QString status); - void allProcessesFinished(); - void continueBoot(QString ifName, bool userChoice); - -private: - QLocalServer *server; - quint16 blockSize; - //QMap interfacesMap; - //QMap indexToIfaceNameMap; - QMap clients; - QLocalSocket * client; - QMap ifNameToClient; - QMap clientProcessToIfNameMap; - QString pathToDhcpcdExe; - QStringList dhcpcdArguments; - QNetworkConfigurationManager configurationManager; - QNetworkAccessManager *accessManager; - int numberOfProcesses; - routemanager rm; - bool _userChoice; - bool _blocked; - - void handleNewInput(QLocalSocket * client); - - void runDHCPCD(QList &interfaces); - void runDHCPCD(QString interface); - QListcheckCarrierState(QList &interfaces); - bool checkCarrierState(QString interface); - bool checkConnectivity(QString ifName); - QList getListOfNetworkInterfaces(); - bool checkBlackList(QString i); - -}; - -#endif // LOGRECEIVER_H diff --git a/LogReceiver/ndgui.cpp b/LogReceiver/ndgui.cpp index 0394926..624bbde 100644 --- a/LogReceiver/ndgui.cpp +++ b/LogReceiver/ndgui.cpp @@ -3,13 +3,13 @@ ndgui::ndgui(QMainWindow *parent) : QMainWindow(parent) { - connect(&logReceiver, SIGNAL(addInterface(const QString &)), this, SLOT(addInterface( const QString &))); - connect(&logReceiver, SIGNAL(changeProgressBarValue(const QString & , const int& )), this, SLOT(updateIfProgressBar(const QString & , const int&))); - //connect(&logReceiver, SIGNAL(connectionEstablished(interfaceconfiguration*)), this, SLOT(handleConnectionEstablished(interfaceconfiguration*))); - connect(&logReceiver, SIGNAL(abortBoot(QString)), this, SLOT(abortBoot(const QString))); - connect(&logReceiver, SIGNAL(updateStatusLabel(QString,QString)), this, SLOT(updateIfStatus(const QString &, const QString &))); - //connect(&logReceiver, SIGNAL(allProcessesFinished()), this, SLOT(handleAllProcessesFinished())); - connect(&logReceiver, SIGNAL(continueBoot(QString, bool)), this, SLOT(continueBoot(QString, bool))); + connect(&networkDiscovery, SIGNAL(addInterface(const QString &)), this, SLOT(addInterface( const QString &))); + connect(&networkDiscovery, SIGNAL(changeProgressBarValue(const QString & , const int& )), this, SLOT(updateIfProgressBar(const QString & , const int&))); + //connect(&networkDiscovery, SIGNAL(connectionEstablished(interfaceconfiguration*)), this, SLOT(handleConnectionEstablished(interfaceconfiguration*))); + connect(&networkDiscovery, SIGNAL(abortBoot(QString)), this, SLOT(abortBoot(const QString))); + connect(&networkDiscovery, SIGNAL(updateStatusLabel(QString,QString)), this, SLOT(updateIfStatus(const QString &, const QString &))); + //connect(&networkDiscovery, SIGNAL(allProcessesFinished()), this, SLOT(handleAllProcessesFinished())); + connect(&networkDiscovery, SIGNAL(continueBoot(QString, bool)), this, SLOT(continueBoot(QString, bool))); _started = false; @@ -37,7 +37,7 @@ ndgui::~ndgui() { void ndgui::startNetworkDiscovery(){ if(!_started) { _started = true; - logReceiver.initAndRun("/var/tmp/qt_c_socket_custom"); + networkDiscovery.initAndRun("/var/tmp/qt_c_socket_custom"); } else { qDebug() << "NetworkDiscovery already started"; diff --git a/LogReceiver/ndgui.h b/LogReceiver/ndgui.h index 7cbfb20..21217ec 100644 --- a/LogReceiver/ndgui.h +++ b/LogReceiver/ndgui.h @@ -8,9 +8,7 @@ #include #include -#include "logreceiver.h" -#include "chooseinterfacedialog.h" -#include "abortbootdialog.h" +#include "networkdiscovery.h" #include "ui_ndgui.h" @@ -50,12 +48,10 @@ private: QWebView * _webView; - LogReceiver logReceiver; + NetworkDiscovery networkDiscovery; QMap finalUsableIntefacesMap; // maps interfaceName to its gateway - ChooseInterfaceDialog *cID; - AbortBootDialog *aBD; }; diff --git a/LogReceiver/networkdiscovery.cpp b/LogReceiver/networkdiscovery.cpp new file mode 100644 index 0000000..cd77ee1 --- /dev/null +++ b/LogReceiver/networkdiscovery.cpp @@ -0,0 +1,518 @@ +#include "networkdiscovery.h" + +#include "../common/fbgui.h" + +NetworkDiscovery::NetworkDiscovery(QObject *parent) { + + server = new QLocalServer(this); +} + +NetworkDiscovery::~NetworkDiscovery() { + +} + +void NetworkDiscovery::initAndRun(QString serverPath, QString pathToExe, + QStringList* args) { + + _userChoice = false; + _blocked = false; + + if (serverPath != DEFAULT_QTSOCKETADDRESS) { + dhcpcdArguments.append("-q"); + dhcpcdArguments.append(serverPath); + } + if (!server->listen(serverPath)) { + /* + QMessageBox::critical(this, tr("NetworkDiscovery"), tr( + "Unable to start the server: %1.") .arg(server->errorString())); + close(); + */ + // emit signal to the gui that a critial error occoured + QString errorInfo("Unable to start server: "); + qDebug() << "--- \t [NetworkDiscovery::initAndRun] " + errorInfo + << server->errorString(); + emit + abortBoot(errorInfo + server->errorString()); + return; + } + + connect(server, SIGNAL(newConnection()), this, SLOT(handleNewConnection())); + + pathToDhcpcdExe = pathToExe; + // check if the path to the customdhcpcd file is correct + QFileInfo fInfo(pathToDhcpcdExe); + if (!fInfo.exists()) { + qDebug() + << "couldn't find customdhcpcd exe. Please check the path to this file."; + emit + abortBoot( + "couldn't find customdhcpcd exe. Please check the path to this file."); + return; + } + + if (args != NULL && !args->isEmpty()) { + qDebug() << "--- \t [NetworkDiscovery::initAndRun] added additional args"; + dhcpcdArguments.append(*args); + } + + numberOfProcesses = 0; + + // start the main work: + + QList list = getListOfNetworkInterfaces(); + + if (list.size() > 0) { + + //list = checkCarrierState(list); + + + //dhcpcdArguments.append("-d"); + QString ifName("eth0"); + numberOfProcesses = list.size(); + runDHCPCD(list); + } else { + qDebug() << "list is empty. Haven't found usable interface."; + emit + abortBoot("Haven't found usable interface"); + return; + } + +} + +int NetworkDiscovery::replaceDefaultRoute(QString &ifName, QString &gateway, int af, int mss) { + rm.replaceDefaultRoute(ifName, gateway, mss, AF_INET); +} + +QList NetworkDiscovery::getListOfNetworkInterfaces() { + QList nIList = QNetworkInterface::allInterfaces(); + QList result; + + if (nIList.size() > 0) { + foreach(QNetworkInterface nI, nIList) + { + if (((!(nI.flags() & QNetworkInterface::CanBroadcast) + || nI.flags() & QNetworkInterface::IsLoopBack) + || nI.flags() & QNetworkInterface::IsPointToPoint) + || checkBlackList(nI.humanReadableName())) { + continue; + } + if (!checkCarrierState(nI.humanReadableName())) { + continue; + } + result.append(nI.humanReadableName()); + emit addInterface(nI.humanReadableName()); + } + } else { + qDebug() << "no interfaces found!"; + } + return result; +} + +QList NetworkDiscovery::checkCarrierState(QList &interfaces) { + QList result; + foreach(QString nI, interfaces) + { + if (checkCarrierState(nI)) { + // everything is fine, cable is plugged, + // go on with the next interface + //continue; + result.append(nI); + } + } + return result; +} + +bool NetworkDiscovery::checkCarrierState(QString interface) { + + qDebug() << "check carrier state for interface " << interface; + QByteArray ba = interface.toAscii(); + const char * iface = ba.data(); + + struct sysfs_class_device *class_device = sysfs_open_class_device("net", + iface); + struct dlist *attrlist = sysfs_get_classdev_attributes(class_device); + if (attrlist != NULL) { + struct sysfs_attribute *attr = NULL; + dlist_for_each_data(attrlist, attr, struct sysfs_attribute) { + if (strcmp("carrier", attr->name) == 0) { + QString value(attr->value); + bool ok = false; + bool * pok = &ok; + int v = value.toInt(pok); + if (*pok) { + if (v == 1) { + qDebug() + << "carrier is 1. Cable is plugged. return true"; + return true; + } else { + qDebug() + << "carrier is 0. Cable is unplugged. return false"; + return false; + } + } else { + qDebug() << "conversion error"; + } + } + } + } else { + qDebug() << "attrlist is Null"; + } + sysfs_close_class_device(class_device); + + return true; +} + +void NetworkDiscovery::runDHCPCD(QList &interfaces) { + foreach(QString nI, interfaces) + { + runDHCPCD(nI); + } +} + +void NetworkDiscovery::runDHCPCD(QString interface) { + emit updateStatusLabel(interface, "start DHCP"); + dhcpcdArguments.append(interface); + QProcess * p = new QProcess(this); + + qDebug() << dhcpcdArguments; + + clientProcessToIfNameMap.insert(p, interface); + qDebug() << clientProcessToIfNameMap; + p->start(pathToDhcpcdExe, dhcpcdArguments); + connect(p, SIGNAL(started()), this, SLOT(handleProcessStarted())); + connect(p, SIGNAL(finished(int, QProcess::ExitStatus)), this, + SLOT(handleProcessFinished(int, QProcess::ExitStatus))); + dhcpcdArguments.removeLast(); +} + +bool NetworkDiscovery::checkConnectivity(QString ifName) { + int metric = 0; + + // get gateway address + QString pathToGatewayFile(DEFAULT_GATEWAY_INFO_LOCATION); + pathToGatewayFile += ifName; + interfaceconfiguration ifConf; + ifConf.readConfigOutOfFile(pathToGatewayFile); + + // replace default route + qDebug() << rm.replaceDefaultRoute(ifName, ifConf.getGateway(), 0, AF_INET); + + // check connectivity via tcp connection + QTcpSocket *tcpSocket = new QTcpSocket(this); + tcpSocket->connectToHost(QString("209.85.148.105"), 80); + if (!tcpSocket->waitForConnected(500)) { + qDebug() << "no internet connection with interface" << ifName; + qDebug() << tcpSocket->errorString(); + emit + updateStatusLabel(ifName, "connection not possible"); + return false; + } else { + qDebug() << "internet: check passed! for interface" << ifName; + emit updateStatusLabel(ifName, "connection possible"); + if (!_userChoice) { + // blockiere jeden weiteren check + // emite continueBoot + _blocked = true; + emit continueBoot(ifName, _userChoice); + } else { + emit connectionEstablished(&ifConf); + } + return true; + } +} + +/** + * + */ +void NetworkDiscovery::handleNewConnection() { + qDebug() << "New Connection arrived"; + + /*QLocalSocket **/ + client = server ->nextPendingConnection(); + clients.insert(client, client); + connect(client, SIGNAL(disconnected()), this, + SLOT(handleClientDisconnect())); + connect(client, SIGNAL(readyRead()), this, SLOT(handleNewInput())); +} + +/** + * + */ +void NetworkDiscovery::handleClientDisconnect() { + QLocalSocket* socket = qobject_cast (QObject::sender()); + + QLocalSocket * client = clients.value(socket); + + qDebug() << "disconnect client"; + handleNewInput(client); + client->deleteLater(); +} + +/** + * + */ +void NetworkDiscovery::handleNewInput(QLocalSocket * client) { + qDebug() << "last read before exit"; + while (client->canReadLine()) { + QString data(client->readLine()); + + data = data.trimmed(); + qDebug() << data; + QStringList lines = data.split("\n"); + + for (int i = 0; i < lines.length(); i++) { + handleNewInputLine(client, lines.at(i)); + } + } +} + +/** + * + * This method is connected to the readyRead Signal of the QLocalSocket + * client. + * send an ACK to the client with every received message. + */ +void NetworkDiscovery::handleNewInput() { + QLocalSocket* socket = qobject_cast (QObject::sender()); + + QLocalSocket * client = clients.value(socket); + QString data(client->read(DHCP_MESSAGE_SIZE)); + client->write("ACK", ACK_SIZE); + client->waitForBytesWritten(); + data = data.trimmed(); + //qDebug() << data; + QStringList lines = data.split("\n"); + + for (int i = 0; i < lines.length(); i++) { + handleNewInputLine(client, lines.at(i)); + } +} + +/** + * This Method processes the send messages. + * + * This Method processes the send messages. It splits the line + * into several components. Those components are: + * interface: interface name ==> indicates the process who send the message + * s_state: is the number representation of syslog.h LOG levels + * s_subState: is the number representation of the dhcp.c DHCP states (1 - 8) plus + * the status. h states (9 - ..) + * msg: is a message which can contain additional informations + * + * According to the s_state and s_subState we emit the changeProgressBarValue() signal + * with different values. + * + * @param client + * the client who send the message + * + * @param data + * the message. (format ;;; ) + */ +void NetworkDiscovery::handleNewInputLine(QLocalSocket * client, QString data) { + + QString logMsg(data); + QString interface = logMsg.section(";", 0, 0); + QString s_state = logMsg.section(";", 1, 1); + QString s_subState = logMsg.section(";", 2, 2); + QString msg = logMsg.section(";", 3, 3); + int st = s_state.trimmed().toInt(); + int sst = s_subState.trimmed().toInt(); + //qDebug() << logMsg; + + if (ifNameToClient.size() < numberOfProcesses && !ifNameToClient.contains( + interface)) { + ifNameToClient.insert(interface, client); + } + + switch (st) { + case LOG_INFO: + switch (sst) { + case DHCP_DISCOVER: + emit changeProgressBarValue(interface, 10); + break; + case DHCP_OFFER: + emit changeProgressBarValue(interface, 20); + break; + case DHCP_REQUEST: + emit changeProgressBarValue(interface, 30); + break; + case DHCP_ACK: + emit changeProgressBarValue(interface, 40); + break; + case DHCP_NAK: + emit changeProgressBarValue(interface, 40); + break; + case DHCPCD_ARP_TEST: + emit changeProgressBarValue(interface, 50); + break; + case DHCP_DECLINE: + emit changeProgressBarValue(interface, 60); + break; + case DHCP_RELEASE: + + break; + case DHCP_INFORM: + break; + case DHCPCD_CONFIGURE: + emit changeProgressBarValue(interface, 70); + break; + case DHCPCD_WRITE: + emit changeProgressBarValue(interface, 80); + break; + case DHCPCD_EXIT: + emit changeProgressBarValue(interface, 100); + break; + case DHCPCD_LOG: + + default: + break; + } + break; + case LOG_ERR: + qDebug() << "received error:" << msg; + break; + default: + //qDebug() << logMsg; + break; + } +} + +/** + * This Method is called when a process is finished. + * + * This Method is called when a process is finished. This slot is connected + * with the signal finished() of the QProcess class. + * If the process finishes, it will be checked if the process exited normal + * or if an unexpected error occurred. For this, we determine the sender (which is a + * QProcess), get the corresponding interface (which is stored in a map), and check + * the exitCode. Further actions are taken according to the exitCode check. + * Normal exit: + * emit changeProgressBar() to 100% + * emit updateStatusLabel() to check connection + * checkConnectivity() @see NetworkDiscovery::checkConnectivity() + * Unexpected exit: + * emit updateStatusLabel() to process exited unexpected + * TODO:: the reason for the unexpected exit should be presented in the logfile. + * + * @param exitCode + * + * @param exitStatus + * + * @return bool + * returns true: if the interface name i starts with a letter in the blacklist. + * + * returns false: else + * + * @see NetworkDiscovery::getListOfNetworkInterfaces() + */ +/* +void NetworkDiscovery::handleProcessFinished(int exitCode, + QProcess::ExitStatus exitStatus) { + QProcess* p = qobject_cast (QObject::sender()); + QString ifName = clientProcessToIfNameMap.value(p, "ifName"); + + if (ifName.compare("ifName") == 0) { + qDebug() + << "--- \t [NetworkDiscovery::handleProcessFinished] haven't found process!"; + } else { + qDebug() << "process for interface" << ifName << "finished" << exitCode + << exitStatus; + if (exitCode > 0) { + qDebug() << "process exited unexpected"; + emit updateStatusLabel(ifName, "process exited unexpected"); + } else { + qDebug() << "process normal exit"; + qDebug() << "check internet connection"; + emit + changeProgressBarValue(ifName, 100); + emit + updateStatusLabel(ifName, "check connectivity"); + checkConnectivity(ifName); + } + } + QLocalSocket *client = ifNameToClient.value(ifName, 0); + if (client != 0) { + handleNewInput(client); + } + numberOfProcesses = numberOfProcesses - 1; + if (numberOfProcesses <= 0) { + emit allProcessesFinished(); + } +} +*/ +void NetworkDiscovery::handleProcessFinished(int exitCode, + QProcess::ExitStatus exitStatus) { + + QProcess* p = qobject_cast (QObject::sender()); + QString ifName = clientProcessToIfNameMap.value(p, "ifName"); + if (!_blocked) { //_blocked becomes true, if _userChoice is false and we found a usable interface + if (ifName.compare("ifName") == 0) { + qDebug() + << "--- \t [NetworkDiscovery::handleProcessFinished] haven't found process!"; + } else { + qDebug() << "process for interface" << ifName << "finished" + << exitCode << exitStatus; + if (exitCode > 0) { + qDebug() << "process exited unexpected"; + emit updateStatusLabel(ifName, "process exited unexpected"); + } else { + qDebug() << "process normal exit"; + emit changeProgressBarValue(ifName, 100); + emit updateStatusLabel(ifName, "check connectivity"); + checkConnectivity(ifName); + } + } + if (!_blocked) { //_blocked becomes true, if _userChoice is false and we found a usable interface + QLocalSocket *client = ifNameToClient.value(ifName, 0); + if (client != 0) { + handleNewInput(client); + } + numberOfProcesses = numberOfProcesses - 1; + if (numberOfProcesses <= 0 && _userChoice) { + emit allProcessesFinished(); + } + } + } else { + qDebug() << "already blocked"; + emit updateStatusLabel(ifName, "finished DHCP"); + } +} +/** + * This Method is called when a process is started. + * + * This Method is called when a process is started. + * It prints the message: "process started for interface: ". + */ +void NetworkDiscovery::handleProcessStarted() { + QProcess* p = qobject_cast (QObject::sender()); + QString ifName = clientProcessToIfNameMap.value(p, "ifName"); + qDebug() << "process started for interface:" << ifName; +} + +/** + * This Method implements a blacklist. + * + * This Method implements a blacklist. We check the fist character + * of the interface name. if this letter is in the list, we return true. + * True means, that this interface won't be put into the result list of + * getListOfNetworkInterfaces(). + * + * @param i + * is a interface name. + * + * @return bool + * returns true: if the interface name i starts with a letter in the blacklist. + * + * returns false: else + * + * @see NetworkDiscovery::getListOfNetworkInterfaces() + */ +bool NetworkDiscovery::checkBlackList(QString i) { + if (i.startsWith("v", Qt::CaseInsensitive)) { + return true; + } else if (i.startsWith("d", Qt::CaseInsensitive)) { + return true; + } else { + return false; + } +} diff --git a/LogReceiver/networkdiscovery.h b/LogReceiver/networkdiscovery.h new file mode 100644 index 0000000..9a1441d --- /dev/null +++ b/LogReceiver/networkdiscovery.h @@ -0,0 +1,98 @@ +#ifndef NetworkDiscovery_H +#define NetworkDiscovery_H + +//#include +#include +#include +//#include + +#include +#include +#include +#include +#include +#include + +#include "interfaceconfiguration.h" +#include "routemanager.h" +//#include +//#include +#include "status.h" +#include "dhcp.h" +#include "interface.h" + +//#include +//#include +//#include +//#include +//#include +#include +//#include +#include + + +#define DEFAULT_QTSOCKETADDRESS "/var/tmp/qt_c_socket_default" +#define DEFAULT_PATHTODHCPCDEXE "/home/niklas/fbgui/customdhcpcd/src/customdhcpcd" +#define DEFAULT_GATEWAY_INFO_LOCATION "/var/tmp/gateways_" +#define ACK_SIZE 4 + +class NetworkDiscovery: public QObject { +Q_OBJECT + +public: + NetworkDiscovery(QObject *parent=0); + ~NetworkDiscovery(); + + void initAndRun(QString serverPath = DEFAULT_QTSOCKETADDRESS, + QString pathToExe = DEFAULT_PATHTODHCPCDEXE, + QStringList* args = NULL); + int replaceDefaultRoute(QString &ifName, QString &gateway, int af, int mss); + +private slots: + void handleNewConnection(); + void handleNewInput(); + void handleNewInputLine(QLocalSocket * client, QString data); + void handleProcessFinished(int exitCode, QProcess::ExitStatus exitStatus); + void handleProcessStarted(); + void handleClientDisconnect(); + +signals: + void addInterface(const QString &ifName); + void changeProgressBarValue(const QString & ifName, const int $newValue); + void connectionEstablished(interfaceconfiguration *ifConf); + void abortBoot(QString msg); + void updateStatusLabel(QString ifName, QString status); + void allProcessesFinished(); + void continueBoot(QString ifName, bool userChoice); + +private: + QLocalServer *server; + quint16 blockSize; + //QMap interfacesMap; + //QMap indexToIfaceNameMap; + QMap clients; + QLocalSocket * client; + QMap ifNameToClient; + QMap clientProcessToIfNameMap; + QString pathToDhcpcdExe; + QStringList dhcpcdArguments; + QNetworkConfigurationManager configurationManager; + QNetworkAccessManager *accessManager; + int numberOfProcesses; + routemanager rm; + bool _userChoice; + bool _blocked; + + void handleNewInput(QLocalSocket * client); + + void runDHCPCD(QList &interfaces); + void runDHCPCD(QString interface); + QListcheckCarrierState(QList &interfaces); + bool checkCarrierState(QString interface); + bool checkConnectivity(QString ifName); + QList getListOfNetworkInterfaces(); + bool checkBlackList(QString i); + +}; + +#endif // NetworkDiscovery_H -- cgit v1.2.3-55-g7522