From be915d3cfcc639d6303bf8bc0e5ad825e0ef2f95 Mon Sep 17 00:00:00 2001 From: Niklas Date: Wed, 5 Oct 2011 17:39:35 +0200 Subject: modified the check for carrier signal. on autoUp==true: if no interface is in running state, the app will check the state of the interface several times (can be specified by us with the _ifUpCountdown value) --- LogReceiver/LogReceiver.pro | 6 +- LogReceiver/html/networkdiscovery.css | 7 +- LogReceiver/html/networkdiscovery.html | 30 ++++-- LogReceiver/ndgui.cpp | 6 +- LogReceiver/ndgui.h | 3 +- LogReceiver/networkdiscovery.cpp | 163 +++++++++++++++++++++++++++------ LogReceiver/networkdiscovery.h | 42 +++++---- common/fbgui.h | 2 + customdhcpcd/src/dhcpcd.h | 6 +- customdhcpcd/src/logwriter.c | 2 +- 10 files changed, 205 insertions(+), 62 deletions(-) diff --git a/LogReceiver/LogReceiver.pro b/LogReceiver/LogReceiver.pro index 1bba39d..8313526 100644 --- a/LogReceiver/LogReceiver.pro +++ b/LogReceiver/LogReceiver.pro @@ -7,11 +7,13 @@ LIBS += -lsysfs \ -L/home/niklas/fbgui/customdhcpcd/src/build \ -llibcustomdhcpcd INCLUDEPATH += /home/niklas/fbgui/customdhcpcd/src -HEADERS += networkmanager.h \ +HEADERS += sleeper.h \ + networkmanager.h \ networkdiscovery.h \ interfaceconfiguration.h \ ndgui.h -SOURCES += networkmanager.cpp \ +SOURCES += sleeper.cpp \ + networkmanager.cpp \ networkdiscovery.cpp \ interfaceconfiguration.cpp \ ndgui.cpp \ diff --git a/LogReceiver/html/networkdiscovery.css b/LogReceiver/html/networkdiscovery.css index 1346810..669ad58 100644 --- a/LogReceiver/html/networkdiscovery.css +++ b/LogReceiver/html/networkdiscovery.css @@ -60,10 +60,15 @@ aside { width: 300px; } -#nd_manual_configuration_dialog { +#nd_manual_configuration_dialog, #nd_show_log_dialog { display:none; } +textarea { + width: 400px; + resize: none; +} + h1 { margin-top: 20px; } diff --git a/LogReceiver/html/networkdiscovery.html b/LogReceiver/html/networkdiscovery.html index 1f6125a..6d370d1 100644 --- a/LogReceiver/html/networkdiscovery.html +++ b/LogReceiver/html/networkdiscovery.html @@ -41,6 +41,17 @@ 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_dialog").dialog( + { minWidth: 450, + modal: true, + resizable: false, + draggable: false + }); +}; + var ip4_manualConfigurationDialog = function () { var jsonArr = fbgui.getManualConfInterfaces(); //jsonArr = eval('(' + jsonArr + ')'); @@ -116,7 +127,9 @@ var abortBootDialog = function (m) { $("#nd_abort_boot_dialog").dialog( { buttons: { "Manual Configure": function() { ip4_manualConfigurationDialog();}, - "Show Log": function() {fbgui.showLog(); + "Show Log": function() { + var text = fbgui.readLogFile(); + showLog(text); $(this).dialog("close");}, "Restart": function() {fbgui.restartSystem(); $(this).dialog("close"); }, @@ -144,8 +157,9 @@ var chooseInterfaceDialog = function (i) { $("#nd_choose_interface_dialog").dialog( { buttons: { "Manual Configure": function() { ip4_manualConfigurationDialog();}, - "Show Log": function() {fbgui.showLog(); - $(this).dialog("close");}, + "Show Log": function() { + var text = fbgui.readLogFile(); + showLog(text);}, "Restart": function() {fbgui.restartSystem(); $(this).dialog("close"); }, "Shut Down": function() { fbgui.shutDownSystem(); @@ -212,16 +226,20 @@ var addInterface = function (i){

test

+ +
+ +
-
+

-
+

-
+

All form fields are required.

diff --git a/LogReceiver/ndgui.cpp b/LogReceiver/ndgui.cpp index eafc2f6..b77c2a1 100644 --- a/LogReceiver/ndgui.cpp +++ b/LogReceiver/ndgui.cpp @@ -62,7 +62,7 @@ void ndgui::startNetworkDiscovery(){ disconnect(_webView,SIGNAL(loadFinished(bool)), this, SLOT(startNetworkDiscovery())); if(!_started) { _started = true; - networkDiscovery.initAndRun("209.85.148.105", _userChoice,"/var/tmp/qt_c_socket_custom"); + networkDiscovery.initAndRun("209.85.148.105", _userChoice, true, "/var/tmp/logfile","/var/tmp/qt_c_socket_custom"); } else { qDebug() << "NetworkDiscovery already started"; @@ -108,8 +108,9 @@ void ndgui::continueBoot(QString ifName, int userChoice) { _webView->load(QUrl("qrc:html/continueBoot.html")); } -void ndgui::showLog() { +QString ndgui::readLogFile() { qDebug() << "show log"; + return networkDiscovery.readLogFile(); } /*test html gui version*/ @@ -130,6 +131,7 @@ int ndgui::ip4_setManualConfiguration(QVariantMap jsonArr) { } + /* slots */ diff --git a/LogReceiver/ndgui.h b/LogReceiver/ndgui.h index e0c12d1..3955303 100644 --- a/LogReceiver/ndgui.h +++ b/LogReceiver/ndgui.h @@ -17,6 +17,7 @@ public: ~ndgui(); Q_INVOKABLE QVariantList getManualConfInterfaces(); Q_INVOKABLE int ip4_setManualConfiguration(QVariantMap result); + Q_INVOKABLE QString readLogFile(); public slots: void handleConnectionEstablished(QString ifName); @@ -27,7 +28,7 @@ public slots: void restartSystem(); void shutDownSystem(); void continueBoot(QString ifName, int userChoice); - void showLog(); + void prepareNetworkDiscover(); void startNetworkDiscovery(); diff --git a/LogReceiver/networkdiscovery.cpp b/LogReceiver/networkdiscovery.cpp index ee0b5ad..052663f 100644 --- a/LogReceiver/networkdiscovery.cpp +++ b/LogReceiver/networkdiscovery.cpp @@ -11,14 +11,18 @@ NetworkDiscovery::~NetworkDiscovery() { } -void NetworkDiscovery::initAndRun(QString serverIp, bool userChoice,QString serverPath, QString pathToExe, +void NetworkDiscovery::initAndRun(QString serverIp, bool userChoice, bool autoUp, QString pathToLogFile, QString serverPath, QString pathToExe, QStringList* args) { _serverIp = serverIp; _userChoice = userChoice; - _blocked = false; + _autoUp = autoUp; + _pathToLogFile = pathToLogFile; + _pathToDhcpcdExe = pathToExe; + _blocked = false; _numberOfProcesses = 0; + _ifUpCountdown = 10; if (serverPath != DEFAULT_QTSOCKETADDRESS) { _dhcpcdArguments.append("-q"); @@ -48,6 +52,7 @@ void NetworkDiscovery::initAndRun(QString serverIp, bool userChoice,QString serv } connect(_server, SIGNAL(newConnection()), this, SLOT(handleNewConnection())); + connect(this, SIGNAL(readyForRun()), this, SLOT(slotReadyForRun())); // check if the path to the customdhcpcd file is correct @@ -69,24 +74,90 @@ void NetworkDiscovery::initAndRun(QString serverIp, bool userChoice,QString serv // start the main work: - QList list = getListOfNetworkInterfaces(); + // if autoup enabled + // emit ... up + // else get list uped ifs (einmal simpel ohne autoup) + // emit run - if (list.size() > 0) { + if (_autoUp) { + getListOfNetworkInterfacesWithAutoUp(); + _timer = new QTimer(this); + connect(_timer, SIGNAL(timeout()), this, SLOT(checkForIsRunning())); + _timer->start(1000); - //list = checkCarrierState(list); + } else { + getListOfNetworkInterfaces(); + emit readyForRun(); + } +} - //dhcpcdArguments.append("-d"); - _numberOfProcesses = list.size(); - runDHCPCD(list); +void NetworkDiscovery::slotReadyForRun() { + if (_ifUpList.size() > 0) { + foreach(QString i, _ifUpList) { + emit addInterface(i); + } + _numberOfProcesses = _ifUpList.size(); + runDHCPCD( _ifUpList); } else { qDebug() << "list is empty. Have not found usable interface."; - emit abortBoot("Haven not found usable interface"); + emit + abortBoot("Have not found usable interface"); return; } +} + +void NetworkDiscovery::checkForIsRunning() { + bool isRunning = false; + QList copyOfIfDownList(_ifDownList); + foreach(QString i, _ifDownList) { + QNetworkInterface networkInterface = QNetworkInterface::interfaceFromName(i); + isRunning = (networkInterface.flags() & QNetworkInterface::IsRunning); + if (isRunning) { + _ifUpList.append(i); + _ifDownList.removeAt(_ifDownList.indexOf(i)); + } + } + _ifUpCountdown--; + if ((_ifUpCountdown <= 0 ) || _ifDownList.isEmpty()) { + // shut down timer + _timer->stop(); + emit readyForRun(); + } + /* + for (int ii = 0; ii < copyOfIfDownList.size(); ii++) { + QNetworkInterface networkInterface = + QNetworkInterface::interfaceFromName(_ifDownList.value(ii)); + isRunning = (networkInterface.flags() & QNetworkInterface::IsRunning); + if (isRunning) { + _ifUpList.append(_ifDownList.value(ii)); + _ifDownList.removeAt(ii); + } + } + */ } +// autoup mit qtimer + +/* + if(!(nI.flags() & QNetworkInterface::IsRunning)) { + continue; + } + +// if(!checkForIsRunning(nI)) { +// qDebug() << "--- still down"; +// continue; +// } + /* + if (!checkCarrierState(nI.humanReadableName())) { + continue; + } + */ + + + + int NetworkDiscovery::replaceDefaultRoute(QString &ifName, QString &gateway, int af, int mss) { _networkManager.replaceDefaultRoute(ifName, gateway, mss, AF_INET); } @@ -138,7 +209,27 @@ QString NetworkDiscovery::getGatewayForInterface(QString ifName) { return ifConf->getGateway(); } -QList NetworkDiscovery::getListOfNetworkInterfaces() { +QString NetworkDiscovery::readLogFile() { + // path to log file is in _pathToLogFile. initialized in initAndRun(). + QString retval("the log file"); + QFile logFile(_pathToLogFile); + if (logFile.exists()) { + if (logFile.open(QIODevice::ReadOnly | QIODevice::Text)); + return retval; + } + while (!logFile.atEnd()) { + retval.append(logFile.readLine()); + } + return retval; +} + +/** + * ================================================================================ + ********************************* Private Methods ******************************** + * ================================================================================ + **/ + +QList NetworkDiscovery::getListOfNetworkInterfacesWithAutoUp() { QList nIList = QNetworkInterface::allInterfaces(); QList result; @@ -151,19 +242,17 @@ QList NetworkDiscovery::getListOfNetworkInterfaces() { || checkBlackList(nI.humanReadableName())) { continue; } - if(!(nI.flags() & QNetworkInterface::IsUp)) { - _networkManager.bringInterfaceUP(nI.humanReadableName()); - } - /* - * if(!checkForIsRunning(nI)) { - continue; + if ((nI.flags() & QNetworkInterface::IsRunning)) { + _ifUpList.append(nI.humanReadableName()); + _ifMap.insert(nI.humanReadableName(), true); } - */ - if (!checkCarrierState(nI.humanReadableName())) { - continue; + else if (!(nI.flags() & QNetworkInterface::IsUp)) { + _networkManager.bringInterfaceUP(nI.humanReadableName()); + qDebug() << "--- bring up .."; + _ifDownList.append(nI.humanReadableName()); + _ifMap.insert(nI.humanReadableName(), false); } result.append(nI.humanReadableName()); - emit addInterface(nI.humanReadableName()); } } else { qDebug() << "no interfaces found!"; @@ -171,18 +260,32 @@ QList NetworkDiscovery::getListOfNetworkInterfaces() { return result; } -bool NetworkDiscovery::checkForIsRunning(QNetworkInterface networkInterface) { - bool retval = false; - for (int i = 0; i < 4; i++) { - retval = (networkInterface.flags() & QNetworkInterface::IsRunning); - if(retval) { - return retval; - } - sleep(1); +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) + || !(nI.flags() & QNetworkInterface::IsUp) + || !(nI.flags() & QNetworkInterface::IsRunning) + || checkBlackList(nI.humanReadableName())) { + continue; + } + _ifUpList.append(nI.humanReadableName()); + _ifMap.insert(nI.humanReadableName(), true); + result.append(nI.humanReadableName()); + } + } else { + qDebug() << "no interfaces found!"; } - return retval; + return result; } + QList NetworkDiscovery::checkCarrierState(QList &interfaces) { QList result; foreach(QString nI, interfaces) @@ -264,7 +367,7 @@ bool NetworkDiscovery::checkConnectivity(QString ifName) { int metric = 0; // get gateway address - QString pathToGatewayFile(DEFAULT_GATEWAY_INFO_LOCATION); + QString pathToGatewayFile(DEFAULT_INTERFACE_CONF_LOCATION); pathToGatewayFile += ifName; interfaceconfiguration *ifConf = new interfaceconfiguration(); ifConf->readConfigOutOfFile(pathToGatewayFile); diff --git a/LogReceiver/networkdiscovery.h b/LogReceiver/networkdiscovery.h index 4a9bc3c..8b9359c 100644 --- a/LogReceiver/networkdiscovery.h +++ b/LogReceiver/networkdiscovery.h @@ -1,10 +1,8 @@ #ifndef NetworkDiscovery_H #define NetworkDiscovery_H -//#include #include #include -//#include #include #include @@ -14,28 +12,19 @@ #include #include - - #include "interfaceconfiguration.h" #include "networkmanager.h" +#include "sleeper.h" + +#include "../common/fbgui.h" + #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 +#define DEFAULT_PATHTODHCPCDEXE "/home/niklas/fbgui/customdhcpcd/src/build/cdhcpcd" class NetworkDiscovery: public QObject { Q_OBJECT @@ -45,6 +34,8 @@ public: ~NetworkDiscovery(); void initAndRun(QString serverIp, bool userChoice, + bool autoUp, + QString pathToLogFile, QString serverPath = DEFAULT_QTSOCKETADDRESS, QString pathToExe = DEFAULT_PATHTODHCPCDEXE, QStringList* args = NULL); @@ -53,6 +44,7 @@ public: QString getGatewayForInterface(QString ifName); int ip4_setManualConfiguration(QVariantMap result); + QString readLogFile(); private slots: void handleNewConnection(); @@ -62,6 +54,11 @@ private slots: void handleProcessStarted(); void handleClientDisconnect(); + void slotReadyForRun(); + + void checkForIsRunning(); + + signals: void addInterface(const QString &ifName); void changeProgressBarValue(const QString & ifName, const int $newValue); @@ -72,6 +69,8 @@ signals: void continueBoot(QString ifName, int userChoice); void setManualConfInterfaces(QString jsonArr); + void readyForRun(); + private: QLocalServer *_server; QMap _clients; @@ -84,7 +83,14 @@ private: NetworkManager _networkManager; bool _userChoice; bool _blocked; + bool _autoUp; QString _serverIp; + QString _pathToLogFile; + QList _ifUpList; + QList _ifDownList; + QMap _ifMap; + int _ifUpCountdown; + QTimer* _timer; QMap _ifcMap; @@ -94,12 +100,14 @@ private: void runDHCPCD(QString interface); QListcheckCarrierState(QList &interfaces); bool checkCarrierState(QString interface); - bool checkForIsRunning(QNetworkInterface networkInterface); bool checkConnectivity(QString ifName); bool checkConnectivityViaTcp(QString server); QList getListOfNetworkInterfaces(); bool checkBlackList(QString i); + QList getListOfNetworkInterfacesWithAutoUp(); + + }; #endif // NetworkDiscovery_H diff --git a/common/fbgui.h b/common/fbgui.h index 7a0faf5..a785b42 100644 --- a/common/fbgui.h +++ b/common/fbgui.h @@ -1,6 +1,8 @@ #ifndef FBGUI_H #define FBGUI_H +#define DEFAULT_INTERFACE_CONF_LOCATION "/var/tmp/conf_" +#define DEFAULT_QTSOCKETADDRESS "/var/tmp/qt_c_socket_default" #define DHCP_MESSAGE_SIZE 2048 #define ACK_SIZE 4 diff --git a/customdhcpcd/src/dhcpcd.h b/customdhcpcd/src/dhcpcd.h index 3f4c085..c8df616 100644 --- a/customdhcpcd/src/dhcpcd.h +++ b/customdhcpcd/src/dhcpcd.h @@ -37,13 +37,15 @@ #include "common.h" +#include "../../common/fbgui.h" + #define DEFAULT_TIMEOUT 20 #define DEFAULT_LEASETIME 3600 /* 1 hour */ /* added by Niklas Goby, additional field, storing the socket address path for * communicating with Qt "server" */ -#define DEFAULT_QTSOCKETADDRESS "/var/tmp/qt_c_socket_default" -#define DEFAULT_GATEWAY_INFO_LOCATION "/var/tmp/gateways_" + + #define QTSOCKETADDRESSLENGTH 255 #define CLASS_ID_MAX_LEN 48 diff --git a/customdhcpcd/src/logwriter.c b/customdhcpcd/src/logwriter.c index d41bbfb..1e34947 100644 --- a/customdhcpcd/src/logwriter.c +++ b/customdhcpcd/src/logwriter.c @@ -197,7 +197,7 @@ void logGatewayToFile(const interface_t *iface, const dhcp_t *dhcp) { route_t *route; char path[QTSOCKETADDRESSLENGTH]; - strcpy(path, DEFAULT_GATEWAY_INFO_LOCATION); + strcpy(path, DEFAULT_INTERFACE_CONF_LOCATION); strcat(path, iface->name); syslog(LOG_INFO, "[fbgui] try to open file: %s", path); -- cgit v1.2.3-55-g7522