summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNiklas2011-10-19 17:00:58 +0200
committerNiklas2011-10-19 17:00:58 +0200
commit54e31640362a7a995dd49f100eee9550d745e58f (patch)
tree04fbf5a34cf1d98c53a4a766da023e9f6843dcd6
parentsmall changes in the networkmanager. added some ipv6 methods for adding a rou... (diff)
downloadfbgui-54e31640362a7a995dd49f100eee9550d745e58f.tar.gz
fbgui-54e31640362a7a995dd49f100eee9550d745e58f.tar.xz
fbgui-54e31640362a7a995dd49f100eee9550d745e58f.zip
put the NetworkDiscovery code into the src folder of the fbgui. made some test, building a usb stick iso and running it on a maschine. did some bug fixes
-rw-r--r--CMakeLists.txt2
-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
-rwxr-xr-xUnixDomainSocketServer/Debug/UnixDomainSocketServerbin54133 -> 54333 bytes
-rw-r--r--customdhcpcd/src/dhcpcd.c3
-rw-r--r--customdhcpcd/src/logger.c86
-rw-r--r--customdhcpcd/src/logwriter.c9
-rw-r--r--src/fbgui.pro20
-rw-r--r--src/html/js/networkDiscovery.js19
-rw-r--r--src/html/networkdiscovery.css3
-rw-r--r--src/html/networkdiscovery.html8
-rw-r--r--src/main.cpp7
-rw-r--r--src/ndgui.cpp35
-rw-r--r--src/ndgui.h1
-rw-r--r--src/networkdiscovery.cpp135
-rw-r--r--src/networkdiscovery.h4
21 files changed, 413 insertions, 224 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f4a0c1f..78176a4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -36,7 +36,7 @@ include(${QT_USE_FILE})
add_definitions(${QT_DEFINITIONS})
link_directories(/usr/local/Qxt/lib /usr/lib
- /home/niklas/workspace/fbgui-ng/lib)
+ /usr/local/lib)
#add_library(
# /usr/local/Qxt/lib/libQxtCore.so
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();
diff --git a/UnixDomainSocketServer/Debug/UnixDomainSocketServer b/UnixDomainSocketServer/Debug/UnixDomainSocketServer
index bdab448..a7fbc06 100755
--- a/UnixDomainSocketServer/Debug/UnixDomainSocketServer
+++ b/UnixDomainSocketServer/Debug/UnixDomainSocketServer
Binary files differ
diff --git a/customdhcpcd/src/dhcpcd.c b/customdhcpcd/src/dhcpcd.c
index c200211..d0ad5e7 100644
--- a/customdhcpcd/src/dhcpcd.c
+++ b/customdhcpcd/src/dhcpcd.c
@@ -1,5 +1,4 @@
-/*
- * dhcpcd - DHCP client daemon
+ /* dhcpcd - DHCP client daemon
* Copyright 2006-2008 Roy Marples <roy@marples.name>
* All rights reserved
diff --git a/customdhcpcd/src/logger.c b/customdhcpcd/src/logger.c
index 91d6cc0..70c693a 100644
--- a/customdhcpcd/src/logger.c
+++ b/customdhcpcd/src/logger.c
@@ -80,47 +80,59 @@ void setlogprefix(const char *prefix) {
void logger(int level, const char *fmt, ...) {
va_list p;
va_list p2;
- FILE *f = stderr;
+// FILE *f = stderr;
+ FILE *f;
+ char* path = "/tmp/cdhcpcd.log";
+
+ f = fopen(path,"a");
va_start (p, fmt);
va_copy (p2, p);
- if (level <= LOG_ERR || level <= loglevel) {
-
- /* new function by Niklas Goby
- * send the log message also to our Qt programm.
- * implemented in logwriter.c
- * */
- logLoggerToQt(level, fmt, p);
-
- if (level == LOG_DEBUG || level == LOG_INFO)
- f = stdout;
- fprintf(f, "%s, %s", leveltolog(level), logprefix);
- vfprintf(f, fmt, p);
- fputc('\n', f);
-
- /* stdout, stderr may be re-directed to some kind of buffer.
- * So we always flush to ensure it's written. */
- fflush(f);
- }
-
- if (level < LOG_DEBUG || level <= loglevel) {
- size_t len = strlen(logprefix);
- size_t fmt2len = strlen(fmt) + len + 1;
- char *fmt2 = malloc(sizeof(char) * fmt2len);
- char *pf = fmt2;
- if (fmt2) {
- memcpy(pf, logprefix, len);
- pf += len;
- strlcpy(pf, fmt, fmt2len - len);
- vsyslog(level, fmt2, p2);
- free(fmt2);
- } else {
- vsyslog(level, fmt, p2);
- syslog(LOG_ERR, "logger: memory exhausted");
- exit(EXIT_FAILURE);
- }
- }
+ fprintf(f, "%s, %s", leveltolog(level), logprefix);
+ vfprintf(f, fmt, p);
+ fputc('\n', f);
+
+ /* stdout, stderr may be re-directed to some kind of buffer.
+ * So we always flush to ensure it's written. */
+ fflush(f);
+
+// //logLoggerToQt(level, fmt, p);
+// if (level <= LOG_ERR || level <= loglevel) {
+//
+// /* new function by Niklas Goby
+// * send the log message also to our Qt programm.
+// * implemented in logwriter.c
+// * */
+// //logLoggerToQt(level, fmt, p);
+//
+// if (level == LOG_DEBUG || level == LOG_INFO)
+// f = stdout;
+// fprintf(f, "%s, %s", leveltolog(level), logprefix);
+// vfprintf(f, fmt, p);
+// fputc('\n', f);
+//
+// /* stdout, stderr may be re-directed to some kind of buffer.
+// * So we always flush to ensure it's written. */
+// fflush(f);
+// }
+// if (level < LOG_DEBUG || level <= loglevel) {
+// size_t len = strlen(logprefix);
+// size_t fmt2len = strlen(fmt) + len + 1;
+// char *fmt2 = malloc(sizeof(char) * fmt2len);
+// char *pf = fmt2;
+// if (fmt2) {
+// memcpy(pf, logprefix, len);
+// pf += len;
+// strlcpy(pf, fmt, fmt2len - len);
+// vsyslog(level, fmt2, p2);
+// free(fmt2);
+// } else {
+// vsyslog(level, fmt, p2);
+// syslog(LOG_ERR, "logger: memory exhausted");
+// exit(EXIT_FAILURE);
+// }
+// }
va_end (p2);
va_end (p);
diff --git a/customdhcpcd/src/logwriter.c b/customdhcpcd/src/logwriter.c
index d8c3537..e407bc2 100644
--- a/customdhcpcd/src/logwriter.c
+++ b/customdhcpcd/src/logwriter.c
@@ -83,7 +83,8 @@ void sendToQt(log_msg * msg) {
ret = snprintf(outbuf, DHCP_MESSAGE_SIZE, tpl, msg->device, msg->status,
msg->substatus, msg->msg);
if (ret < 1) {
- syslog(LOG_INFO, "[fbgui] ERROR filling message buffer");
+ logger(LOG_INFO, "[fbgui] ERROR filling message buffer");
+ //syslog(LOG_INFO, "[fbgui] ERROR filling message buffer");
return;
}
if (outbuf != NULL) {
@@ -93,9 +94,12 @@ void sendToQt(log_msg * msg) {
msg->status, msg->substatus, msg->msg, msg->device);
if (n <= 0) {
- syslog(LOG_ERR, "[fbgui] ERROR writing to socket: [%d:%d] %s (%s)",
+ logger(LOG_ERR, "[fbgui] ERROR writing to socket: [%d:%d] %s (%s)",
msg->status, msg->substatus, msg->msg, msg->device);
+ //syslog(LOG_ERR, "[fbgui] ERROR writing to socket: [%d:%d] %s (%s)",
+ // msg->status, msg->substatus, msg->msg, msg->device);
}
+ /*
memset(ack, 0, ACK_SIZE);
if ((t = recv(sockfd, ack, ACK_SIZE, 0)) > 0) {
syslog(LOG_ERR, "[fbgui] recv ack echo> %s", ack);
@@ -106,6 +110,7 @@ void sendToQt(log_msg * msg) {
else
syslog(LOG_ERR, "[fbgui] ERROR Server closed");
}
+ */
}
void logToQt(int status, int substatus, const char * msg) {
diff --git a/src/fbgui.pro b/src/fbgui.pro
index c18e022..701402b 100644
--- a/src/fbgui.pro
+++ b/src/fbgui.pro
@@ -12,12 +12,20 @@ LIBS += -L/usr/local/qjson/lib \
-lQxtCore \
-L/usr/lib \
-lsysfs \
- -lusb-1.0
+ -lnl \
+ -lusb-1.0 \
+ -L/usr/local/lib \
+ -lcustomdhcpcd
INCLUDEPATH += /usr/local/qjson/include \
/usr/local/Qxt/include \
/usr/local/Qxt/include/QxtCore \
/usr/include/sysfs \
- /usr/include/libusb-1.0
+ /usr/include/libusb-1.0 \
+ /usr/include/net \
+ /usr/include/netlink \
+ /usr/include/netlink/route \
+ /usr/include/arpa \
+ ./../customdhcpcd/src
HEADERS += ../common/fbgui.h \
downloadmanager.h \
fbgui.h \
@@ -27,8 +35,12 @@ HEADERS += ../common/fbgui.h \
ndgui.h \
networkdiscovery.h \
networkmanager.h \
- sysinfo.h \
-SOURCES += sysinfo.cpp \
+ sysinfo.h
+SOURCES += networkdiscovery.cpp \
+ networkmanager.cpp \
+ ndgui.cpp \
+ interfaceconfiguration.cpp \
+ sysinfo.cpp \
loggerengine.cpp \
javascriptinterface.cpp \
downloadmanager.cpp \
diff --git a/src/html/js/networkDiscovery.js b/src/html/js/networkDiscovery.js
index 2200d82..1d67eac 100644
--- a/src/html/js/networkDiscovery.js
+++ b/src/html/js/networkDiscovery.js
@@ -31,20 +31,23 @@ 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").attr('readonly','readonly');
$("#nd_show_log_dialog").dialog(
{ minWidth: 450,
modal: true,
- resizable: false,
draggable: false
});
};
+var getInterfaceConf = function (i) {
+ var n = i.options[i.selectedIndex].text();
+};
+
var ip4_manualConfigurationDialog = function () {
var jsonArr = fbgui.getManualConfInterfaces();
//jsonArr = eval('(' + jsonArr + ')');
- var c = "<select name='nd_mc_ifname_select' id='nd_mc_ifname_select'>";
+ var c = "<select name='nd_mc_ifname_select' id='nd_mc_ifname_select' onChange='getInterfaceConf(this)'>";
if(jsonArr == "") {
c += "<option>NO INTERFACE</option>";
} else {
@@ -118,12 +121,13 @@ var abortBootDialog = function (m) {
ip4_manualConfigurationDialog();},
"Show Log": function() {
var text = fbgui.readLogFile();
- showLog(text);
- $(this).dialog("close");},
+ showLog(text);},
"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,
modal: true,
@@ -137,6 +141,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>";
}
);
diff --git a/src/html/networkdiscovery.css b/src/html/networkdiscovery.css
index 669ad58..a111ef6 100644
--- a/src/html/networkdiscovery.css
+++ b/src/html/networkdiscovery.css
@@ -66,7 +66,8 @@ aside {
textarea {
width: 400px;
- resize: none;
+ height: 200px;
+ /*resize: none;*/
}
h1 {
diff --git a/src/html/networkdiscovery.html b/src/html/networkdiscovery.html
index f6f50e4..1f24b0d 100644
--- a/src/html/networkdiscovery.html
+++ b/src/html/networkdiscovery.html
@@ -5,9 +5,9 @@
<link rel="stylesheet" type="text/css" href="qrc:/html/css/jquery-ui-1.8.16.css">
<script type="text/javascript" src="qrc:/html/js/jquery-1.6.4.min.js"></script>
<script type="text/javascript" src="qrc:/html/js/jquery-ui-1.8.16.min.js"></script>
-<!-- <script type="text/javascript" src="qrc:/html/js/networkDiscovery.js"></script> -->
-
+<script type="text/javascript" src="qrc:/html/js/networkDiscovery.js"></script>
+<!--
<script type="text/javascript">
var updateTips = function ( t ) {
@@ -208,7 +208,7 @@ var addInterface = function (i){
};
</script>
-
+-->
</head>
<body>
<header>
@@ -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/src/main.cpp b/src/main.cpp
index 21983ca..e408a33 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -175,12 +175,13 @@ int main(int argc, char *argv[]) {
else
logFilePath = DEFAULT_LOG_FILE_PATH;
- // activate file logger if debug mode activated.
- if (debugMode > -1) {
+ // write always a log file
+ // // activate file logger if debug mode activated.
+ // if (debugMode > -1) {
// start debug logging to file.
qxtLog->addLoggerEngine("file_logger", new LoggerEngine_file(logFilePath));
qxtLog->setMinimumLevel("file_logger", QxtLogger::DebugLevel);
- }
+ // }
// print config
qxtLog->debug() << "************* CONFIG INFO *************";
diff --git a/src/ndgui.cpp b/src/ndgui.cpp
index 80a64bc..8daef9e 100644
--- a/src/ndgui.cpp
+++ b/src/ndgui.cpp
@@ -25,10 +25,12 @@ ndgui::ndgui(QMainWindow *parent) :
setWindowTitle(tr("NetD"));
setAttribute(Qt::WA_QuitOnClose, true);
setWindowFlags(Qt::FramelessWindowHint);
+ showFullScreen();
_webView->load(QUrl("qrc:html/networkdiscovery_userchoice.html"));
_webView->show();
-
+
+ qxtLog->debug() << _tag << "start singel shot";
QTimer::singleShot(2000, this, SLOT(prepareNetworkDiscover()));
}
@@ -92,10 +94,13 @@ 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");
+ qxtLog->debug() << _tag << "Initializing networkDiscovery ...";
+ QStringList l;
+ l << "-d";
+ networkDiscovery.initAndRun("209.85.148.105", _userChoice, true, "/tmp/fbgui.log","/var/tmp/qt_c_socket_custom", "/bin/cdhcpcd", &l);
}
else {
- qDebug() << _tag << "NetworkDiscovery already started";
+ qxtLog->debug() << _tag << "NetworkDiscovery already started";
}
}
@@ -122,7 +127,7 @@ void ndgui::handleConnectionEstablished(QString ifName) {
* handleConnectionEstablished)).
*/
void ndgui::handleAllProcessesFinished() {
- qDebug() << _tag << "all Processes finished";
+ qxtLog->debug() << _tag << "all Processes finished";
if(_ifNameList.size() > 0) {
QString jsonArr = "[";
for(int i = 0; i < _ifNameList.size()-1; i++) {
@@ -177,10 +182,10 @@ void ndgui::shutDownSystem() {
void ndgui::continueBoot(QString ifName, int userChoice) {
if (!userChoice) {
QString text = "continue with interface: " + ifName;
- qDebug() << _tag << text << "no user choice";
+ qxtLog->debug() << _tag << text << "no user choice";
} else {
QString text = "continue with interface: " + ifName;
- qDebug() << _tag << text << "with user choice";
+ qxtLog->debug() << _tag << text << "with user choice";
QString gateway = networkDiscovery.getGatewayForInterface(ifName);
networkDiscovery.ip4_replaceDefaultRoute(ifName,gateway,0);
}
@@ -195,12 +200,20 @@ 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";
+ qxtLog->debug() << _tag << "show log";
return networkDiscovery.readLogFile();
}
+/**/
+void ndgui::tryAgain() {
+ qxtLog->debug() << _tag << "try again";
+
+}
+
+
+
/*test html gui version*/
/**
@@ -208,13 +221,13 @@ QString ndgui::readLogFile() {
* dialog.
*/
QVariantList ndgui::getManualConfInterfaces() {
- qDebug() << _tag << "call getManualConfInterfaces";
+ qxtLog->debug() << _tag << "call getManualConfInterfaces";
QVariantList jsonArr;
foreach (QString s, _manConfList) {
QVariant e(s);
jsonArr << e;
}
- qDebug() << _tag << "value of jsonArr:" << jsonArr;
+ qxtLog->debug() << _tag << "value of jsonArr:" << jsonArr;
return jsonArr;
}
@@ -257,7 +270,7 @@ void ndgui::loadJQuery() {
foreach(fi, fiList)
{
if (fi.suffix() == "js") {
- //qDebug()<< fi.fileName();
+ //qxtLog->debug()<< fi.fileName();
//qxtLog->debug() << fi.fileName();
//if (fi.fileName() != "test.js" && fi.fileName() != "nd-functions.js") {
QFile file;
@@ -366,5 +379,5 @@ void ndgui::addInterface(const QString &ifName) {
* just for debugging.
*/
void ndgui::notifyCall(QString msg){
- qDebug() << _tag << "------ called:" << msg;
+ qxtLog->debug() << _tag << "------ called:" << msg;
}
diff --git a/src/ndgui.h b/src/ndgui.h
index eb30d7a..ab1f82b 100644
--- a/src/ndgui.h
+++ b/src/ndgui.h
@@ -27,6 +27,7 @@ public slots:
void restartSystem();
void shutDownSystem();
void continueBoot(QString ifName, int userChoice);
+ void tryAgain();
void prepareNetworkDiscover();
diff --git a/src/networkdiscovery.cpp b/src/networkdiscovery.cpp
index da2cb1d..94d1f63 100644
--- a/src/networkdiscovery.cpp
+++ b/src/networkdiscovery.cpp
@@ -73,7 +73,7 @@ void NetworkDiscovery::initAndRun(QString serverIp, bool userChoice, bool autoUp
if (!_server->listen(serverPath)) {
// emit signal to the gui that a critial error occoured
- qDebug() << _tag << "Unable to start server: "
+ qxtLog->debug() << _tag << "Unable to start server: "
<< _server->errorString();
emit
abortBoot("Unable to start server: " + _server->errorString());
@@ -83,8 +83,8 @@ void NetworkDiscovery::initAndRun(QString serverIp, bool userChoice, bool autoUp
// 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.";
+ qxtLog->debug() << _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;
@@ -94,21 +94,27 @@ void NetworkDiscovery::initAndRun(QString serverIp, bool userChoice, bool autoUp
connect(this, SIGNAL(readyForRun()), this, SLOT(slotReadyForRun()));
if (args != NULL && !args->isEmpty()) {
- qDebug() << _tag << "added additional args";
+ qxtLog->debug() << _tag << "added additional args";
_dhcpcdArguments.append(*args);
}
// start the main work:
if (_autoUp) {
+ qxtLog->debug() << _tag << " call getListOfNetworkInterfacesWithAutoUp ...";
getListOfNetworkInterfacesWithAutoUp();
- _timer = new QTimer(this);
- connect(_timer, SIGNAL(timeout()), this, SLOT(checkForIsRunning()));
- _timer->start(1000);
+ qxtLog->debug() << _tag << " ifUpList size: " << _ifUpList.size();
+ qxtLog->debug() << _tag << " ifDownList size: " << _ifDownList.size();
} else {
+ qxtLog->debug() << _tag << " call getListOfNetworkInterfaces ...";
getListOfNetworkInterfaces();
- emit readyForRun();
}
+
+ qxtLog->debug() << _tag << " init timer ...";
+ _timer = new QTimer(this);
+ qxtLog->debug() << _tag << " call checkForIsRunning ...";
+ connect(_timer, SIGNAL(timeout()), this, SLOT(checkForIsRunning()));
+ _timer->start(1000);
}
@@ -122,12 +128,13 @@ void NetworkDiscovery::initAndRun(QString serverIp, bool userChoice, bool autoUp
void NetworkDiscovery::slotReadyForRun() {
if (_ifUpList.size() > 0) {
foreach(QString i, _ifUpList) {
+ qxtLog->debug() << _tag << "emit addInterface: " << i;
emit addInterface(i);
}
_numberOfProcesses = _ifUpList.size();
runDHCPCD( _ifUpList);
} else {
- qDebug() << _tag << "list is empty. Have not found usable interface.";
+ qxtLog->debug() << _tag << "list is empty. Have not found usable interface.";
emit
abortBoot("Have not found usable interface");
return;
@@ -204,10 +211,10 @@ int NetworkDiscovery::ip4_setManualConfiguration(QVariantMap result) {
"/etc/",
dns);
- qDebug() << _tag << "set man conf. and check connectivity";
+ qxtLog->debug() << _tag << "set man conf. and check connectivity";
if (!checkConnectivityViaTcp(_serverIp)) {
- qDebug() << _tag << "no connectivity. reset conf.";
+ qxtLog->debug() << _tag << "no connectivity. reset conf.";
interfaceconfiguration * ifc = _ifcMap.value(result["ifname"].toString(), NULL);
if(ifc != NULL) {
dns.clear();
@@ -269,6 +276,13 @@ QString NetworkDiscovery::readLogFile() {
+/**/
+void NetworkDiscovery::tryAgain() {
+
+}
+
+
+
/**
* ================================================================================
********************************* Private Methods ********************************
@@ -289,6 +303,23 @@ void NetworkDiscovery::getListOfNetworkInterfacesWithAutoUp() {
if (nIList.size() > 0) {
foreach(QNetworkInterface nI, nIList)
{
+ qxtLog->debug() << _tag << "found Interface:" << nI.humanReadableName();
+ if ((nI.flags() & QNetworkInterface::CanBroadcast)) {
+ qxtLog->debug() << _tag << "flags: can broadcast";
+ }
+ if ((nI.flags() & QNetworkInterface::IsLoopBack)) {
+ qxtLog->debug() << _tag << "flags: is LoopBack";
+ }
+ if ((nI.flags() & QNetworkInterface::IsPointToPoint)) {
+ qxtLog->debug() << _tag << "flags: is Point to Point";
+ }
+ if ((nI.flags() & QNetworkInterface::IsRunning)) {
+ qxtLog->debug() << _tag << "flags: is Running";
+ }
+ if ((nI.flags() & QNetworkInterface::IsUp)) {
+ qxtLog->debug() << _tag << "flags: is Up";
+ }
+
if (((!(nI.flags() & QNetworkInterface::CanBroadcast)
|| nI.flags() & QNetworkInterface::IsLoopBack)
|| nI.flags() & QNetworkInterface::IsPointToPoint)
@@ -300,12 +331,15 @@ void NetworkDiscovery::getListOfNetworkInterfacesWithAutoUp() {
}
else if (!(nI.flags() & QNetworkInterface::IsUp)) {
_networkManager.bringInterfaceUP(nI.humanReadableName());
- qDebug() << _tag << " bring up ..";
+ qxtLog->debug() << _tag << " bring up ..";
+ _ifDownList.append(nI.humanReadableName());
+ }
+ else if (!(nI.flags() & QNetworkInterface::IsRunning)) {
_ifDownList.append(nI.humanReadableName());
}
}
} else {
- qDebug() << _tag << "no interfaces found!";
+ qxtLog->debug() << _tag << "no interfaces found!";
}
}
@@ -321,18 +355,22 @@ void NetworkDiscovery::getListOfNetworkInterfaces() {
if (nIList.size() > 0) {
foreach(QNetworkInterface nI, nIList)
{
+ qxtLog->debug() << _tag << "found Interface:" << nI.humanReadableName();
if (((!(nI.flags() & QNetworkInterface::CanBroadcast)
|| nI.flags() & QNetworkInterface::IsLoopBack)
|| nI.flags() & QNetworkInterface::IsPointToPoint)
|| !(nI.flags() & QNetworkInterface::IsUp)
- || !(nI.flags() & QNetworkInterface::IsRunning)
|| checkBlackList(nI.humanReadableName())) {
continue;
}
- _ifUpList.append(nI.humanReadableName());
+ if (!(nI.flags() & QNetworkInterface::IsRunning)) {
+ _ifDownList.append(nI.humanReadableName())
+ } else {
+ _ifUpList.append(nI.humanReadableName());
+ }
}
} else {
- qDebug() << _tag << "no interfaces found!";
+ qxtLog->debug() << _tag << "no interfaces found!";
}
}
@@ -348,7 +386,7 @@ void NetworkDiscovery::getListOfNetworkInterfaces() {
*/
bool NetworkDiscovery::checkCarrierState(QString interface) {
- qDebug() << _tag << "check carrier state for interface " << interface;
+ qxtLog->debug() << _tag << "check carrier state for interface " << interface;
QByteArray ba = interface.toAscii();
const char * iface = ba.data();
@@ -365,21 +403,21 @@ bool NetworkDiscovery::checkCarrierState(QString interface) {
int v = value.toInt(pok);
if (*pok) {
if (v == 1) {
- qDebug()
+ qxtLog->debug()
<< "carrier is 1. Cable is plugged. return true";
return true;
} else {
- qDebug()
+ qxtLog->debug()
<< "carrier is 0. Cable is unplugged. return false";
return false;
}
} else {
- qDebug() << _tag << "conversion error";
+ qxtLog->debug() << _tag << "conversion error";
}
}
}
} else {
- qDebug() << _tag << "attrlist is Null";
+ qxtLog->debug() << _tag << "attrlist is Null";
}
sysfs_close_class_device(class_device);
@@ -414,7 +452,7 @@ void NetworkDiscovery::runDHCPCD(QString interface) {
_dhcpcdArguments.append(interface);
QProcess * p = new QProcess(this);
- qDebug() << _tag << _dhcpcdArguments;
+ qxtLog->debug() << _tag << _dhcpcdArguments;
_clientProcessToIfNameMap.insert(p, interface);
p->start(_pathToDhcpcdExe, _dhcpcdArguments);
@@ -451,12 +489,12 @@ bool NetworkDiscovery::checkConnectivity(QString ifName) {
_ifcMap.insert(ifName, ifConf);
// replace default route
- qDebug() << _tag << "replace default route";
+ qxtLog->debug() << _tag << "replace default route";
_networkManager.replaceDefaultRoute(ifName,
ifConf->getGateway(), mss, AF_INET);
if (checkConnectivityViaTcp(_serverIp)) {
- qDebug() << _tag << "internet: check passed! for interface" << ifName;
+ qxtLog->debug() << _tag << "internet: check passed! for interface" << ifName;
emit
updateStatusLabel(ifName, "connection possible");
if (!_userChoice) {
@@ -469,7 +507,7 @@ bool NetworkDiscovery::checkConnectivity(QString ifName) {
}
return true;
} else {
- qDebug() << _tag << "no internet connection with interface" << ifName;
+ qxtLog->debug() << _tag << "no internet connection with interface" << ifName;
emit
updateStatusLabel(ifName, "connection not possible");
return false;
@@ -493,7 +531,7 @@ bool NetworkDiscovery::checkConnectivityViaTcp(QString server) {
QTcpSocket *tcpSocket = new QTcpSocket(this);
tcpSocket->connectToHost(server, 80);
if (!tcpSocket->waitForConnected(500)) {
- qDebug() << _tag << tcpSocket->errorString();
+ qxtLog->debug() << _tag << tcpSocket->errorString();
return false;
} else {
return true;
@@ -507,7 +545,7 @@ bool NetworkDiscovery::checkConnectivityViaTcp(QString server) {
* connects the client readyRead signal with the handleNewInput slot.
*/
void NetworkDiscovery::handleNewConnection() {
- qDebug() << _tag << "New Connection arrived";
+ qxtLog->debug() << _tag << "New Connection arrived";
/*QLocalSocket **/
_client = _server ->nextPendingConnection();
@@ -527,7 +565,7 @@ void NetworkDiscovery::handleClientDisconnect() {
QLocalSocket * client = _clients.value(socket);
- qDebug() << _tag << "disconnect client";
+ qxtLog->debug() << _tag << "disconnect client";
handleNewInput(client);
client->deleteLater();
}
@@ -541,12 +579,12 @@ void NetworkDiscovery::handleClientDisconnect() {
* a client
*/
void NetworkDiscovery::handleNewInput(QLocalSocket * client) {
- qDebug() << _tag << "last read before exit";
+ qxtLog->debug() << _tag << "last read before exit";
while (client->canReadLine()) {
QString data(client->readLine());
data = data.trimmed();
- qDebug() << _tag << data;
+ qxtLog->debug() << _tag << data;
QStringList lines = data.split("\n");
for (int i = 0; i < lines.length(); i++) {
@@ -570,7 +608,7 @@ void NetworkDiscovery::handleNewInput() {
client->write("ACK", ACK_SIZE);
client->waitForBytesWritten();
data = data.trimmed();
- //qDebug() << _tag << data;
+ //qxtLog->debug() << _tag << data;
QStringList lines = data.split("\n");
for (int i = 0; i < lines.length(); i++) {
@@ -609,7 +647,7 @@ void NetworkDiscovery::handleNewInputLine(QLocalSocket * client, QString data) {
QString msg = logMsg.section(";", 3, 3);
int st = s_state.trimmed().toInt();
int sst = s_subState.trimmed().toInt();
- //qDebug() << _tag << logMsg;
+ //qxtLog->debug() << _tag << logMsg;
if (_ifNameToClient.size() < _numberOfProcesses && !_ifNameToClient.contains(
interface)) {
@@ -621,21 +659,27 @@ void NetworkDiscovery::handleNewInputLine(QLocalSocket * client, QString data) {
switch (sst) {
case DHCP_DISCOVER:
emit changeProgressBarValue(interface, 10);
+ qxtLog->debug() << _tag << " " << interface << " send discover";
break;
case DHCP_OFFER:
emit changeProgressBarValue(interface, 20);
+ qxtLog->debug() << _tag << " " << interface << " got offer";
break;
case DHCP_REQUEST:
emit changeProgressBarValue(interface, 30);
+ qxtLog->debug() << _tag << " " << interface << " send request";
break;
case DHCP_ACK:
emit changeProgressBarValue(interface, 40);
+ qxtLog->debug() << _tag << " " << interface << " ack";
break;
case DHCP_NAK:
emit changeProgressBarValue(interface, 40);
+ qxtLog->debug() << _tag << " " << interface << " nak";
break;
case DHCPCD_ARP_TEST:
emit changeProgressBarValue(interface, 50);
+ qxtLog->debug() << _tag << " " << interface << " do arp test";
break;
case DHCP_DECLINE:
emit changeProgressBarValue(interface, 60);
@@ -647,24 +691,28 @@ void NetworkDiscovery::handleNewInputLine(QLocalSocket * client, QString data) {
break;
case DHCPCD_CONFIGURE:
emit changeProgressBarValue(interface, 70);
+ qxtLog->debug() << _tag << " " << interface << " do configure interface";
break;
case DHCPCD_WRITE:
emit changeProgressBarValue(interface, 80);
+ qxtLog->debug() << _tag << " " << interface << " write conf file";
break;
case DHCPCD_EXIT:
emit changeProgressBarValue(interface, 100);
+ qxtLog->debug() << _tag << " " << interface << " exiting";
break;
case DHCPCD_LOG:
default:
+ qxtLog->debug() << _tag << " received error:" << msg;
break;
}
break;
case LOG_ERR:
- qDebug() << _tag << "received error:" << msg;
+ qxtLog->debug() << _tag << " received error:" << msg;
break;
default:
- //qDebug() << _tag << logMsg;
+ qxtLog->debug() << _tag << logMsg;
break;
}
}
@@ -704,17 +752,18 @@ 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!";
+ qxtLog->debug() << _tag << "--- \t [NetworkDiscovery::handleProcessFinished] haven't found process!";
} else {
- qDebug() << _tag << "process for interface" << ifName << "finished"
- << exitCode << exitStatus;
+ qxtLog->debug() << _tag << " process for interface " << ifName << " finished "
+ << " exit code: " << exitCode << " exit status " << exitStatus;
if (exitCode > 0) {
- qDebug() << _tag << "process exited unexpected";
+ qxtLog->debug() << _tag << "process exited unexpected";
emit updateStatusLabel(ifName, "process exited unexpected");
} else {
- qDebug() << _tag << "process normal exit";
+ qxtLog->debug() << _tag << "process normal exit";
emit changeProgressBarValue(ifName, 100);
emit updateStatusLabel(ifName, "check connectivity");
checkConnectivity(ifName);
@@ -725,13 +774,13 @@ 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();
}
}
} else {
- qDebug() << _tag << "already blocked";
+ qxtLog->debug() << _tag << "already blocked";
emit updateStatusLabel(ifName, "finished DHCP");
}
}
@@ -747,7 +796,7 @@ 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;
+ qxtLog->debug() << _tag << "process started for interface:" << ifName;
}
diff --git a/src/networkdiscovery.h b/src/networkdiscovery.h
index 49ac731..c45b5aa 100644
--- a/src/networkdiscovery.h
+++ b/src/networkdiscovery.h
@@ -22,7 +22,8 @@
#define DEFAULT_QTSOCKETADDRESS "/var/tmp/qt_c_socket_default"
-#define DEFAULT_PATHTODHCPCDEXE "/home/niklas/fbgui/customdhcpcd/src/build/cdhcpcd"
+//#define DEFAULT_PATHTODHCPCDEXE "/home/niklas/fbgui/customdhcpcd/src/build/cdhcpcd"
+#define DEFAULT_PATHTODHCPCDEXE "/bin/cdhcpcd"
class NetworkDiscovery: public QObject {
Q_OBJECT
@@ -42,6 +43,7 @@ public:
int ip4_setManualConfiguration(QVariantMap result);
QString readLogFile();
+ void tryAgain();
private slots:
void handleNewConnection();