summaryrefslogtreecommitdiffstats
path: root/NetworkDiscovery
diff options
context:
space:
mode:
Diffstat (limited to 'NetworkDiscovery')
-rw-r--r--NetworkDiscovery/CMakeLists.txt2
-rw-r--r--NetworkDiscovery/html/js/networkDiscovery.js16
-rw-r--r--NetworkDiscovery/html/networkdiscovery.html2
-rw-r--r--NetworkDiscovery/ndgui.cpp36
-rw-r--r--NetworkDiscovery/ndgui.h5
-rw-r--r--NetworkDiscovery/networkdiscovery.cpp156
-rw-r--r--NetworkDiscovery/networkdiscovery.h88
7 files changed, 197 insertions, 108 deletions
diff --git a/NetworkDiscovery/CMakeLists.txt b/NetworkDiscovery/CMakeLists.txt
index a802c86..78af80b 100644
--- a/NetworkDiscovery/CMakeLists.txt
+++ b/NetworkDiscovery/CMakeLists.txt
@@ -3,6 +3,8 @@ cmake_minimum_required(VERSION 2.8)
project(NetworkDiscovery)
set(QT_MIN_VERSION "4.7.0")
+#set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
+
find_package(Qt4 REQUIRED)
if (QT4_FOUND)
message(STATUS "QT4 found.")
diff --git a/NetworkDiscovery/html/js/networkDiscovery.js b/NetworkDiscovery/html/js/networkDiscovery.js
index 2200d82..3fcde38 100644
--- a/NetworkDiscovery/html/js/networkDiscovery.js
+++ b/NetworkDiscovery/html/js/networkDiscovery.js
@@ -31,10 +31,11 @@ var checkRegexp = function ( o, regexp, n ) {
};
var showLog = function (t) {
- $("#nd_show_log_msg").val(t);
- $("#nd_show_log_msg").attr('readonly','readonly');
+ $("#nd_show_log_msg").html(t);
+ //$("#nd_show_log_msg").val(t);
+ //$("#nd_show_log_msg").attr('readonly','readonly');
$("#nd_show_log_dialog").dialog(
- { minWidth: 450,
+ { minWidth: 600,
modal: true,
resizable: false,
draggable: false
@@ -123,9 +124,11 @@ var abortBootDialog = function (m) {
"Restart": function() {fbgui.restartSystem();
$(this).dialog("close"); },
"Shut Down": function() { fbgui.shutDownSystem();
- $(this).dialog("close"); }
+ $(this).dialog("close"); },
+ "Try Again": function() {fbgui.tryAgain();
+ $(this).dialog("close"); }
} ,
- minWidth: 450,
+ minWidth: 600,
modal: true,
resizable: false,
draggable: false,
@@ -137,6 +140,7 @@ var chooseInterfaceDialog = function (i) {
var cb = "<label> Choose your interface: </label>"+
"<select id='nd_ifName_select'>";
jQuery.each(i, function() {
+ updateIfProgressBar(this, 100);
cb += " <option>"+ this +"</option>";
}
);
@@ -159,7 +163,7 @@ var chooseInterfaceDialog = function (i) {
$(this).dialog("close");
}
} ,
- minWidth: 550,
+ minWidth: 600,
modal: true,
resizable: false,
draggable: false,
diff --git a/NetworkDiscovery/html/networkdiscovery.html b/NetworkDiscovery/html/networkdiscovery.html
index 84e88b3..6c516f9 100644
--- a/NetworkDiscovery/html/networkdiscovery.html
+++ b/NetworkDiscovery/html/networkdiscovery.html
@@ -229,7 +229,7 @@ var addInterface = function (i){
<p>test</p>
<!-- anchor for the show log dialog -->
<div id="nd_show_log_dialog" title="Log File">
- <textarea id="nd_show_log_msg"></textarea>
+ <pre id="nd_show_log_msg"></pre>
</div>
<!-- anchor for the abort boot dialog -->
<div id="nd_abort_boot_dialog" title="Abort Boot">
diff --git a/NetworkDiscovery/ndgui.cpp b/NetworkDiscovery/ndgui.cpp
index c1da989..87fda02 100644
--- a/NetworkDiscovery/ndgui.cpp
+++ b/NetworkDiscovery/ndgui.cpp
@@ -7,6 +7,7 @@ ndgui::ndgui(QMainWindow *parent) :
_started = false;
_userChoice = false;
+ _tryAgain = false;
createAction();
@@ -91,8 +92,15 @@ void ndgui::startNetworkDiscovery(){
disconnect(_webView,SIGNAL(loadFinished(bool)), this, SLOT(startNetworkDiscovery()));
if(!_started) {
- _started = true;
- networkDiscovery.initAndRun("209.85.148.105", _userChoice, true, "/var/tmp/logfile","/var/tmp/qt_c_socket_custom");
+ if (!_tryAgain) {
+ _started = true;
+ QStringList l;
+ l << "-d";
+ networkDiscovery.initAndRun("209.85.148.105", _userChoice, true, "/var/tmp/logfile","/var/tmp/qt_c_socket_custom", DEFAULT_PATHTODHCPCDEXE, &l);
+ } else {
+ _tryAgain = false;
+ networkDiscovery.tryAgain();
+ }
}
else {
qDebug() << _tag << "NetworkDiscovery already started";
@@ -172,7 +180,11 @@ void ndgui::continueBoot(QString ifName, int userChoice) {
QString gateway = networkDiscovery.getGatewayForInterface(ifName);
networkDiscovery.ip4_replaceDefaultRoute(ifName,gateway,0);
}
- _webView->load(QUrl("qrc:html/continueBoot.html"));
+ if (networkDiscovery.checkConnectivityViaTcp()) {
+ _webView->load(QUrl("qrc:html/continueBoot.html"));
+ } else {
+ abortBoot("Interface was suddenly made unusable ");
+ }
}
@@ -181,12 +193,28 @@ void ndgui::continueBoot(QString ifName, int userChoice) {
* read the log file. Log File will be presented inside of a dialog.
*/
QString ndgui::readLogFile() {
- qDebug() << _tag << "show log";
+ qDebug() << _tag << " show log ";
return networkDiscovery.readLogFile();
}
+/**/
+void ndgui::tryAgain() {
+ qDebug() << _tag << " try again ";
+ _tryAgain = true;
+ _started = false;
+ _ifNameList.clear();
+ _manConfList.clear();
+ createAction();
+ _webView->load(QUrl("qrc:html/networkdiscovery_userchoice.html"));
+ _webView->show();
+
+ QTimer::singleShot(2000, this, SLOT(prepareNetworkDiscover()));
+}
+
+
+
/*test html gui version*/
/**
diff --git a/NetworkDiscovery/ndgui.h b/NetworkDiscovery/ndgui.h
index a3d40cc..6235e84 100644
--- a/NetworkDiscovery/ndgui.h
+++ b/NetworkDiscovery/ndgui.h
@@ -26,6 +26,7 @@ public slots:
void restartSystem();
void shutDownSystem();
void continueBoot(QString ifName, int userChoice);
+ void tryAgain();
void prepareNetworkDiscover();
@@ -53,6 +54,8 @@ private:
bool _started;
+ bool _tryAgain;
+
QWebView * _webView;
QAction * _allowUserChoice;
@@ -63,8 +66,6 @@ private:
QList<QString> _manConfList;
- QString _manualConfInterfaces;
-
};
diff --git a/NetworkDiscovery/networkdiscovery.cpp b/NetworkDiscovery/networkdiscovery.cpp
index da2cb1d..bac824a 100644
--- a/NetworkDiscovery/networkdiscovery.cpp
+++ b/NetworkDiscovery/networkdiscovery.cpp
@@ -1,3 +1,6 @@
+#include <sys/types.h>
+#include <signal.h>
+
#include "networkdiscovery.h"
#include "../common/fbgui.h"
@@ -63,52 +66,27 @@ void NetworkDiscovery::initAndRun(QString serverIp, bool userChoice, bool autoUp
_dhcpcdArguments.append("-q");
_dhcpcdArguments.append(serverPath);
}
- /* delete the file at serverPath. this is necessary since in case the application crashes, the file still
- * exists which leads to an error.
- */
-
- if(QFile::exists(serverPath)) {
- QFile::remove(serverPath);
- }
-
- if (!_server->listen(serverPath)) {
- // emit signal to the gui that a critial error occoured
- qDebug() << _tag << "Unable to start server: "
- << _server->errorString();
- emit
- abortBoot("Unable to start server: " + _server->errorString());
- return;
- }
-
- // check if the path to the customdhcpcd file is correct
- QFileInfo fInfo(_pathToDhcpcdExe);
- if (!fInfo.exists()) {
- qDebug() << _tag
- << "could not find customdhcpcd exe. Please check the path to this file.";
- emit abortBoot(
- "could not find customdhcpcd exe. Please check the path to this file.");
- return;
- }
-
- connect(_server, SIGNAL(newConnection()), this, SLOT(handleNewConnection()));
- connect(this, SIGNAL(readyForRun()), this, SLOT(slotReadyForRun()));
-
- if (args != NULL && !args->isEmpty()) {
+ if(QFile::exists(serverPath)){
+ QFile::remove(serverPath);
+ }
+ if(!_server->listen(serverPath)){
+ qDebug() << _tag << "Unable to start server: " << _server->errorString();
+ abortBoot("Unable to start server: " + _server->errorString());
+ return;
+ }
+ QFileInfo fInfo(_pathToDhcpcdExe);
+ if(!fInfo.exists()){
+ qDebug() << _tag << "could not find customdhcpcd exe. Please check the path to this file.";
+ emit emit emit emit abortBoot("could not find customdhcpcd exe. Please check the path to this file.");
+ return;
+ }
+ connect(_server, SIGNAL(newConnection()), this, SLOT(handleNewConnection()));
+ connect(this, SIGNAL(readyForRun()), this, SLOT(slotReadyForRun()));
+ if (args != NULL && !args->isEmpty()) {
qDebug() << _tag << "added additional args";
_dhcpcdArguments.append(*args);
}
-
- // start the main work:
- if (_autoUp) {
- getListOfNetworkInterfacesWithAutoUp();
- _timer = new QTimer(this);
- connect(_timer, SIGNAL(timeout()), this, SLOT(checkForIsRunning()));
- _timer->start(1000);
-
- } else {
- getListOfNetworkInterfaces();
- emit readyForRun();
- }
+ mainWork();
}
@@ -125,6 +103,7 @@ void NetworkDiscovery::slotReadyForRun() {
emit addInterface(i);
}
_numberOfProcesses = _ifUpList.size();
+ qDebug() << _tag << "number of processes:" << _numberOfProcesses ;
runDHCPCD( _ifUpList);
} else {
qDebug() << _tag << "list is empty. Have not found usable interface.";
@@ -269,6 +248,61 @@ QString NetworkDiscovery::readLogFile() {
+/*
+ *TODO: to be bug fixed
+ *TODO: do it with kill and not QProcess("killall cdhcpcd")
+ *TODO: still some bugs. if you press tryAgain it can happen that the app stops with the mainscreen.
+ *TODO: reproducible: start normal with user choice. plug out the cable. press continue. abort screen should appear.
+ *TODO: press tryAgain.
+ */
+void NetworkDiscovery::tryAgain() {
+ // kill all cdhcpcd processes
+ qDebug() << " kill cdhcpcd processes";
+ QProcess * p = new QProcess(this);
+ p->start("killall cdhcpcd");
+ p->waitForFinished();
+ qDebug() << _tag << "[tryAgain]" << p->errorString();
+ /*
+ foreach(Q_PID pid , _pidsList) {
+ if (kill(pid,SIGKILL) <= -1)
+ qDebug() << _tag << " error: trying to kill process: " << pid << " error: " << strerror(errno);
+ }
+ */
+ // reset everything
+ _clients.clear();
+ _clientProcessToIfNameMap.clear();
+ _ifNameToClient.clear();
+ _numberOfProcesses = 0;
+ _blocked = false;
+ _ifUpCountdown = 10;
+ _ifUpList.clear();
+ _ifDownList.clear();
+ _pidsList.clear();
+ _ifcMap.clear();
+
+ // start again
+ mainWork();
+
+ //SIGK
+ //kill();
+}
+
+
+/**/
+QVariantMap NetworkDiscovery::getInterfaceConfig(QString ifName) {
+ QList<QString> dns;
+ interfaceconfiguration * ifc = _ifcMap.value(ifName, NULL);
+ if (ifc != NULL) {
+ dns.clear();
+ dns = ifc->getDnsservers().trimmed().split(" ");
+
+ //ifc->getIpAddress(), ifc->getNetmask(), ifc->getBroadcast(),
+ //ifc->getGateway(), 0, AF_INET, "/etc/", dns);
+ }
+}
+
+
+
/**
* ================================================================================
********************************* Private Methods ********************************
@@ -276,6 +310,22 @@ QString NetworkDiscovery::readLogFile() {
**/
+/**/
+void NetworkDiscovery::mainWork()
+{
+ if (_autoUp) {
+ getListOfNetworkInterfacesWithAutoUp();
+ _timer = new QTimer(this);
+ connect(_timer, SIGNAL(timeout()), this, SLOT(checkForIsRunning()));
+ _timer->start(1000);
+
+ } else {
+ getListOfNetworkInterfaces();
+ emit readyForRun();
+ }
+}
+
+
/**
* searches for usable interfaces and puts them into a list.
@@ -478,6 +528,13 @@ bool NetworkDiscovery::checkConnectivity(QString ifName) {
+/**/
+bool NetworkDiscovery::checkConnectivityViaTcp() {
+ return checkConnectivityViaTcp(_serverIp);
+}
+
+
+
/**
* try to open a tcp connection to the server
*
@@ -567,8 +624,8 @@ void NetworkDiscovery::handleNewInput() {
QLocalSocket * client = _clients.value(socket);
QString data(client->read(DHCP_MESSAGE_SIZE));
- client->write("ACK", ACK_SIZE);
- client->waitForBytesWritten();
+ //client->write("ACK", ACK_SIZE);
+ //client->waitForBytesWritten();
data = data.trimmed();
//qDebug() << _tag << data;
QStringList lines = data.split("\n");
@@ -657,6 +714,7 @@ void NetworkDiscovery::handleNewInputLine(QLocalSocket * client, QString data) {
case DHCPCD_LOG:
default:
+ qDebug() << _tag << "default" << msg;
break;
}
break;
@@ -704,6 +762,7 @@ void NetworkDiscovery::handleProcessFinished(int exitCode,
QProcess* p = qobject_cast<QProcess *> (QObject::sender());
QString ifName = _clientProcessToIfNameMap.value(p, "ifName");
+ _numberOfProcesses = _numberOfProcesses - 1;
if (!_blocked) { //_blocked becomes true, if _userChoice is false and we already found a usable interface
if (ifName.compare("ifName") == 0) {
qDebug() << _tag << "--- \t [NetworkDiscovery::handleProcessFinished] haven't found process!";
@@ -725,8 +784,8 @@ void NetworkDiscovery::handleProcessFinished(int exitCode,
if (client != 0) {
handleNewInput(client);
}
- _numberOfProcesses = _numberOfProcesses - 1;
- if (_numberOfProcesses <= 0 && _userChoice) {
+ //_numberOfProcesses = _numberOfProcesses - 1; && _userChoice
+ if (_numberOfProcesses <= 0 ) {
emit allProcessesFinished();
}
}
@@ -747,7 +806,8 @@ void NetworkDiscovery::handleProcessFinished(int exitCode,
void NetworkDiscovery::handleProcessStarted() {
QProcess* p = qobject_cast<QProcess *> (QObject::sender());
QString ifName = _clientProcessToIfNameMap.value(p, "ifName");
- qDebug() << _tag << "process started for interface:" << ifName;
+ qDebug() << _tag << "process started for interface:" << ifName << "with pid:" << p->pid();
+ _pidsList.append(p->pid());
}
diff --git a/NetworkDiscovery/networkdiscovery.h b/NetworkDiscovery/networkdiscovery.h
index b4c4ef7..2291a7c 100644
--- a/NetworkDiscovery/networkdiscovery.h
+++ b/NetworkDiscovery/networkdiscovery.h
@@ -27,36 +27,31 @@ class NetworkDiscovery: public QObject {
Q_OBJECT
public:
- NetworkDiscovery(QObject *parent=0);
- ~NetworkDiscovery();
-
- void initAndRun(QString serverIp, bool userChoice,
- bool autoUp,
- QString pathToLogFile,
- QString serverPath = DEFAULT_QTSOCKETADDRESS,
- QString pathToExe = DEFAULT_PATHTODHCPCDEXE,
- QStringList* args = NULL);
- int ip4_replaceDefaultRoute(QString ifName, QString gateway, int mss);
- QString getGatewayForInterface(QString ifName);
-
- int ip4_setManualConfiguration(QVariantMap result);
- QString readLogFile();
+ NetworkDiscovery(QObject *parent = 0);
+ ~NetworkDiscovery();
+ void initAndRun(QString serverIp, bool userChoice, bool autoUp, QString pathToLogFile, QString serverPath = DEFAULT_QTSOCKETADDRESS, QString pathToExe = DEFAULT_PATHTODHCPCDEXE, QStringList *args = NULL);
+ int ip4_replaceDefaultRoute(QString ifName, QString gateway, int mss);
+ QString getGatewayForInterface(QString ifName);
+ int ip4_setManualConfiguration(QVariantMap result);
+ QString readLogFile();
+ void tryAgain();
+ bool checkConnectivityViaTcp();
+ bool checkConnectivityViaTcp(QString server);
+ QVariantMap getInterfaceConfig(QString ifName);
private slots:
- void handleNewConnection();
- void handleNewInput();
- void handleNewInputLine(QLocalSocket * client, QString data);
- void handleProcessFinished(int exitCode, QProcess::ExitStatus exitStatus);
- void handleProcessStarted();
- void handleClientDisconnect();
-
- void slotReadyForRun();
-
- void checkForIsRunning();
+ void handleNewConnection();
+ void handleNewInput();
+ void handleNewInputLine(QLocalSocket *client, QString data);
+ void handleProcessFinished(int exitCode, QProcess::ExitStatus exitStatus);
+ void handleProcessStarted();
+ void handleClientDisconnect();
+ void slotReadyForRun();
+ void checkForIsRunning();
signals:
- void addInterface(const QString &ifName);
+ void addInterface(const QString & ifName);
void changeProgressBarValue(const QString & ifName, const int $newValue);
void connectionEstablished(QString ifName);
void abortBoot(QString msg);
@@ -64,31 +59,31 @@ signals:
void allProcessesFinished();
void continueBoot(QString ifName, int userChoice);
void setManualConfInterfaces(QString jsonArr);
-
void readyForRun();
private:
QString _tag;
- QLocalServer *_server;
- QMap<QLocalSocket *, QLocalSocket *> _clients;
- QLocalSocket * _client;
- QMap<QString, QLocalSocket*> _ifNameToClient;
- QMap<QProcess*, QString> _clientProcessToIfNameMap;
- QString _pathToDhcpcdExe;
- QStringList _dhcpcdArguments;
- int _numberOfProcesses;
- NetworkManager _networkManager;
- bool _userChoice;
- bool _blocked;
- bool _autoUp;
- QString _serverIp;
- QString _pathToLogFile;
- QList<QString> _ifUpList;
- QList<QString> _ifDownList;
- int _ifUpCountdown;
- QTimer* _timer;
-
- QMap<QString, interfaceconfiguration*> _ifcMap;
+ QLocalServer *_server;
+ QMap<QLocalSocket*,QLocalSocket*> _clients;
+ QLocalSocket *_client;
+ QMap<QString,QLocalSocket*> _ifNameToClient;
+ QMap<QProcess*,QString> _clientProcessToIfNameMap;
+ QString _pathToDhcpcdExe;
+ QStringList _dhcpcdArguments;
+ int _numberOfProcesses;
+ NetworkManager _networkManager;
+ bool _userChoice;
+ bool _blocked;
+ bool _autoUp;
+ QString _serverIp;
+ QString _pathToLogFile;
+ QList<QString> _ifUpList;
+ QList<QString> _ifDownList;
+ int _ifUpCountdown;
+ QTimer *_timer;
+ QList<Q_PID> _pidsList;
+ QMap<QString,interfaceconfiguration*> _ifcMap;
+ void mainWork();
void handleNewInput(QLocalSocket * client);
@@ -97,7 +92,6 @@ private:
bool checkCarrierState(QString interface);
bool checkConnectivity(QString ifName);
- bool checkConnectivityViaTcp(QString server);
bool checkBlackList(QString i);
void getListOfNetworkInterfaces();