diff options
Diffstat (limited to 'NetworkDiscovery')
-rw-r--r-- | NetworkDiscovery/html/networkdiscovery.html | 6 | ||||
-rw-r--r-- | NetworkDiscovery/nd.qrc | 1 | ||||
-rw-r--r-- | NetworkDiscovery/ndgui.cpp | 36 | ||||
-rw-r--r-- | NetworkDiscovery/networkdiscovery.cpp | 158 | ||||
-rw-r--r-- | NetworkDiscovery/networkdiscovery.h | 1 | ||||
-rw-r--r-- | NetworkDiscovery/networkmanager.h | 2 |
6 files changed, 186 insertions, 18 deletions
diff --git a/NetworkDiscovery/html/networkdiscovery.html b/NetworkDiscovery/html/networkdiscovery.html index f6f50e4..84e88b3 100644 --- a/NetworkDiscovery/html/networkdiscovery.html +++ b/NetworkDiscovery/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> diff --git a/NetworkDiscovery/nd.qrc b/NetworkDiscovery/nd.qrc index 686419e..bf3aa8d 100644 --- a/NetworkDiscovery/nd.qrc +++ b/NetworkDiscovery/nd.qrc @@ -23,5 +23,6 @@ <file>html/css/images/ui-icons_ffffff_256x240.png</file> <file>html/continueBoot.html</file> <file>html/networkdiscovery_userchoice.html</file> + <file>html/js/networkDiscovery.js</file> </qresource> </RCC> diff --git a/NetworkDiscovery/ndgui.cpp b/NetworkDiscovery/ndgui.cpp index bbd6798..c1da989 100644 --- a/NetworkDiscovery/ndgui.cpp +++ b/NetworkDiscovery/ndgui.cpp @@ -222,6 +222,9 @@ int ndgui::ip4_setManualConfiguration(QVariantMap jsonArr) { ////////////////////////////////////////////////// /************************************************/ +/** + * stellt ein ndgui/fbgui Objekt zur verwendung durch die html bereit. + */ void ndgui::attachToDOM(){ _webView->page()->mainFrame()->addToJavaScriptWindowObject(QString("fbgui"), this); loadJQuery(); @@ -271,6 +274,9 @@ void ndgui::abortBoot(const QString msg) { +/** + * opens ths chooseInterfaceDialog + */ void ndgui::chooseInterfaceDialog(const QString msg) { QString code = QString("chooseInterfaceDialog(\%1)").arg(msg); _webView->page()->mainFrame()->evaluateJavaScript(code); @@ -278,6 +284,9 @@ void ndgui::chooseInterfaceDialog(const QString msg) { +/** + * updates the over all status + */ void ndgui::updateStatus(const QString &status) { if (status == "") return; @@ -287,6 +296,15 @@ void ndgui::updateStatus(const QString &status) { +/** + * updates the progress bar for each interface. + * + * @param ifname + * the name ot the interface to update + * + * @param percent + * the progress in percent + */ void ndgui::updateIfProgressBar(const QString &ifName, const int& percent) { if (percent == 0) return; @@ -296,6 +314,15 @@ void ndgui::updateIfProgressBar(const QString &ifName, const int& percent) { +/** + * update the status for each interface + * + * @param ifName + * the name ot the interface to update + * + * @param status + * the new status of the interface. + */ void ndgui::updateIfStatus(const QString &ifName, const QString &status) { if (ifName == "") return; @@ -305,6 +332,12 @@ void ndgui::updateIfStatus(const QString &ifName, const QString &status) { +/** + * adds an interface to the DOM tree. Creates its progress bar and it's status label. + * + * @param ifName + * name of the new interface. + */ void ndgui::addInterface(const QString &ifName) { if (ifName == "") return; @@ -315,6 +348,9 @@ void ndgui::addInterface(const QString &ifName) { +/** + * just for debugging. + */ void ndgui::notifyCall(QString msg){ qDebug() << _tag << "------ called:" << msg; } diff --git a/NetworkDiscovery/networkdiscovery.cpp b/NetworkDiscovery/networkdiscovery.cpp index e9710fd..da2cb1d 100644 --- a/NetworkDiscovery/networkdiscovery.cpp +++ b/NetworkDiscovery/networkdiscovery.cpp @@ -2,6 +2,10 @@ #include "../common/fbgui.h" + +/** + * constructor + */ NetworkDiscovery::NetworkDiscovery(QObject *parent) { _tag = "[nd:NetworkDiscovery]"; _server = new QLocalServer(this); @@ -9,12 +13,39 @@ NetworkDiscovery::NetworkDiscovery(QObject *parent) { +/** + * destructor + */ NetworkDiscovery::~NetworkDiscovery() { } +/** + * initialize all important class members and start the main work. + * + * @param serverIp + * the ip of the server with which we are testing the connectivity. + * + * @param userChoice + * true if the user wishes to have a user choice. true: the chooseInterfaceDialog will be showed. + * + * @param autoUp + * true if we want to "auto Up" all down interfaces. + * + * @param pathToLogFile + * the path to the log file. + * + * @param serverPath + * the path to the server socket (default value: DEFAULT_QTSOCKETADDRESS "/var/tmp/qt_c_socket_default") + * + * @param pathToExe + * the path to the customdhcpcd exe. (default value: #define DEFAULT_QTSOCKETADDRESS "/var/tmp/qt_c_socket_default") + * + * @param args + * additional arguments for the customdhcpcd client. (default value: NULL) + */ void NetworkDiscovery::initAndRun(QString serverIp, bool userChoice, bool autoUp, QString pathToLogFile, QString serverPath, QString pathToExe, QStringList* args) { @@ -82,6 +113,12 @@ void NetworkDiscovery::initAndRun(QString serverIp, bool userChoice, bool autoUp +/** + * emits the addInterface signal for each interface name in _ifUpList + * and calls the runDHCPCD method. + * if the _ifUpList is empty, this method emits an abortBoot signal. + * connected to the readyForRun signal. + */ void NetworkDiscovery::slotReadyForRun() { if (_ifUpList.size() > 0) { foreach(QString i, _ifUpList) { @@ -99,6 +136,11 @@ void NetworkDiscovery::slotReadyForRun() { +/** + * only called if autoUp == true. + * check the IsRunning flag of each interface in the _ifDownList. + * connected to the timeout signal of the timer. + */ void NetworkDiscovery::checkForIsRunning() { bool isRunning = false; QList<QString> copyOfIfDownList(_ifDownList); @@ -120,18 +162,35 @@ void NetworkDiscovery::checkForIsRunning() { -int NetworkDiscovery::replaceDefaultRoute(QString &ifName, QString &gateway, int af, int mss) { - return _networkManager.replaceDefaultRoute(ifName, gateway, mss, AF_INET); -} - - - +/** + * replace the default route. sets af automatically to AF_INET + * + * @param ifName + * interface name + * + * @param gateway + * gateway address + * + * @param mss + * mss value (i think this is the metric. in most cases this value is 0) + */ int NetworkDiscovery::ip4_replaceDefaultRoute(QString ifName, QString gateway, int mss) { return _networkManager.replaceDefaultRoute(ifName, gateway, mss, AF_INET); } +/** + * replace the dhcp configuration with the manual config, entered by the user. + * if we can not establish a connection with the entered values, reset to the old + * dhcp values. + * + * @param result + * a json object formated string. + * + * @return + * 0 if everything ok + */ int NetworkDiscovery::ip4_setManualConfiguration(QVariantMap result) { QList<QString> dns; dns.append(result["dns"].toString()); @@ -172,6 +231,15 @@ int NetworkDiscovery::ip4_setManualConfiguration(QVariantMap result) { +/** + * returns the gateway address, written into the dhcp config file. + * + * @param ifName + * name of the interface. + * + * @return + * gateway address as string. + */ QString NetworkDiscovery::getGatewayForInterface(QString ifName) { interfaceconfiguration * ifConf = _ifcMap.value(ifName); return ifConf->getGateway(); @@ -179,19 +247,24 @@ QString NetworkDiscovery::getGatewayForInterface(QString ifName) { +/** + * reads the log file. + * + * @return the log file as one string. + */ 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)) { + while (!logFile.atEnd()) { + retval.append(logFile.readLine()); + } return retval; } } - while (!logFile.atEnd()) { - retval.append(logFile.readLine()); - } - return retval; + } @@ -202,6 +275,14 @@ QString NetworkDiscovery::readLogFile() { * ================================================================================ **/ + + +/** + * searches for usable interfaces and puts them into a list. + * if the interface is down, put it in the _ifDownList, try to bring it up. + * else put it in the _ifUpList. + * usable interfaces are: can Broadcast, no loopback, no point to point, name is not in the BlackList, + */ void NetworkDiscovery::getListOfNetworkInterfacesWithAutoUp() { QList<QNetworkInterface> nIList = QNetworkInterface::allInterfaces(); @@ -230,6 +311,10 @@ void NetworkDiscovery::getListOfNetworkInterfacesWithAutoUp() { +/** + * searches for usable interfaces which are up and running and put them into a list. + * usable interfaces are: can Broadcast, no loopback, no point to point, name is not in the BlackList, + */ void NetworkDiscovery::getListOfNetworkInterfaces() { QList<QNetworkInterface> nIList = QNetworkInterface::allInterfaces(); @@ -253,6 +338,14 @@ void NetworkDiscovery::getListOfNetworkInterfaces() { +/** + * not used so far. checks the carrier state using the sysfs library. + * if carrier = 1 ==> the interface is running. + * interfaces have to be up in order to get right results. + * + * @param interface + * name of the interface + */ bool NetworkDiscovery::checkCarrierState(QString interface) { qDebug() << _tag << "check carrier state for interface " << interface; @@ -295,6 +388,12 @@ bool NetworkDiscovery::checkCarrierState(QString interface) { +/** + * call for every interface in the list the runDHCPCD method. + * + * @param interfaces + * list of interface names. + */ void NetworkDiscovery::runDHCPCD(QList<QString> &interfaces) { foreach(QString nI, interfaces) { @@ -304,6 +403,12 @@ void NetworkDiscovery::runDHCPCD(QList<QString> &interfaces) { +/** + * start a cdhcpcd process with the interface name as last argument. + * + * @param interface + * name of an interface. + */ void NetworkDiscovery::runDHCPCD(QString interface) { emit updateStatusLabel(interface, "start DHCP"); _dhcpcdArguments.append(interface); @@ -321,6 +426,20 @@ void NetworkDiscovery::runDHCPCD(QString interface) { +/** + * checks the connectivity. tries to open a TCP connection to the + * server (see _serverIp). For this it adjusts the routing table. + * (sets the gateway of the interface as default gateway) + * Gateway is written into the dhcpcd config file of this interface. + * (see DEFAULT_INTERFACE_CONF_LOCATION "/var/tmp/conf_") + * + * @param ifName + * name of a interface. + * + * @return + * true: connection is possible + * false: connection not possible + */ bool NetworkDiscovery::checkConnectivity(QString ifName) { int mss = 0; @@ -359,6 +478,16 @@ bool NetworkDiscovery::checkConnectivity(QString ifName) { +/** + * try to open a tcp connection to the server + * + * @param server + * a ip address. + * + * @return + * true: connection is possible + * false: connection not possible + */ bool NetworkDiscovery::checkConnectivityViaTcp(QString server) { // check connectivity via tcp connection QTcpSocket *tcpSocket = new QTcpSocket(this); @@ -374,7 +503,8 @@ bool NetworkDiscovery::checkConnectivityViaTcp(QString server) { /** - * + * connected to the new client arrived signal. + * connects the client readyRead signal with the handleNewInput slot. */ void NetworkDiscovery::handleNewConnection() { qDebug() << _tag << "New Connection arrived"; @@ -390,7 +520,7 @@ void NetworkDiscovery::handleNewConnection() { /** - * + * called when a client disconnects. */ void NetworkDiscovery::handleClientDisconnect() { QLocalSocket* socket = qobject_cast<QLocalSocket *> (QObject::sender()); @@ -405,7 +535,10 @@ void NetworkDiscovery::handleClientDisconnect() { /** + * same function as handleNewInput() but with a client as parameter. * + * @param cleint + * a client */ void NetworkDiscovery::handleNewInput(QLocalSocket * client) { qDebug() << _tag << "last read before exit"; @@ -425,7 +558,6 @@ void NetworkDiscovery::handleNewInput(QLocalSocket * client) { /** - * * This method is connected to the readyRead Signal of the QLocalSocket * client. * send an ACK to the client with every received message. diff --git a/NetworkDiscovery/networkdiscovery.h b/NetworkDiscovery/networkdiscovery.h index 8b1c70f..b4c4ef7 100644 --- a/NetworkDiscovery/networkdiscovery.h +++ b/NetworkDiscovery/networkdiscovery.h @@ -36,7 +36,6 @@ public: QString serverPath = DEFAULT_QTSOCKETADDRESS, QString pathToExe = DEFAULT_PATHTODHCPCDEXE, QStringList* args = NULL); - int replaceDefaultRoute(QString &ifName, QString &gateway, int af, int mss); int ip4_replaceDefaultRoute(QString ifName, QString gateway, int mss); QString getGatewayForInterface(QString ifName); diff --git a/NetworkDiscovery/networkmanager.h b/NetworkDiscovery/networkmanager.h index b6068a8..3fb1587 100644 --- a/NetworkDiscovery/networkmanager.h +++ b/NetworkDiscovery/networkmanager.h @@ -9,7 +9,7 @@ #define NETWORKMANAGER_H_ #include <arpa/inet.h> -#include <interface.h> +#include <net/if.h> #include <netlink/netlink.h> #include <netlink/netlink-kernel.h> #include <netlink/route/addr.h> |