From fcb16100b5aa80934c90ddd4a386acb14317f460 Mon Sep 17 00:00:00 2001 From: Niklas Date: Tue, 27 Sep 2011 17:03:35 +0200 Subject: manual config gui added. put the interfaceconfig map into networkDiscovery and adopted the signals. --- LogReceiver/html/networkdiscovery.css | 26 +++++++ LogReceiver/html/networkdiscovery.html | 130 ++++++++++++++++++++++++++++++--- LogReceiver/interfaceconfiguration.h | 3 + LogReceiver/ndgui.cpp | 25 ++++--- LogReceiver/ndgui.h | 6 +- LogReceiver/networkdiscovery.cpp | 45 ++++++++++-- LogReceiver/networkdiscovery.h | 15 ++-- 7 files changed, 217 insertions(+), 33 deletions(-) diff --git a/LogReceiver/html/networkdiscovery.css b/LogReceiver/html/networkdiscovery.css index 8e6b364..1346810 100644 --- a/LogReceiver/html/networkdiscovery.css +++ b/LogReceiver/html/networkdiscovery.css @@ -1,6 +1,28 @@ html,body{ height:100%; } + +label, input { + display:block +} + +input.text { + margin-bottom:12px; + width:95%; + padding: .4em; +} + +fieldset { + padding:0; + border:0; + margin-top:25px; +} + +.validateTips { + border:1px solid transparent; + padding: 0.3; +} + body{ margin:0; padding:0; @@ -38,6 +60,10 @@ aside { width: 300px; } +#nd_manual_configuration_dialog { + display:none; +} + h1 { margin-top: 20px; } diff --git a/LogReceiver/html/networkdiscovery.html b/LogReceiver/html/networkdiscovery.html index c24c86b..1302071 100644 --- a/LogReceiver/html/networkdiscovery.html +++ b/LogReceiver/html/networkdiscovery.html @@ -8,10 +8,97 @@ @@ -111,6 +202,27 @@ var addInterface = function (i){

+ +
+

+

All form fields are required.

+
+
+ + + + + + + + + + + + +
+
+
diff --git a/LogReceiver/interfaceconfiguration.h b/LogReceiver/interfaceconfiguration.h index d12bd14..3b0a14d 100644 --- a/LogReceiver/interfaceconfiguration.h +++ b/LogReceiver/interfaceconfiguration.h @@ -15,6 +15,9 @@ Q_OBJECT public: interfaceconfiguration(); + interfaceconfiguration(const interfaceconfiguration &other); + + interfaceconfiguration &operator=(const interfaceconfiguration &other); virtual ~interfaceconfiguration(); bool readConfigOutOfFile(QString pathToConfig); diff --git a/LogReceiver/ndgui.cpp b/LogReceiver/ndgui.cpp index 624bbde..e3ddfd4 100644 --- a/LogReceiver/ndgui.cpp +++ b/LogReceiver/ndgui.cpp @@ -5,11 +5,11 @@ ndgui::ndgui(QMainWindow *parent) : connect(&networkDiscovery, SIGNAL(addInterface(const QString &)), this, SLOT(addInterface( const QString &))); connect(&networkDiscovery, SIGNAL(changeProgressBarValue(const QString & , const int& )), this, SLOT(updateIfProgressBar(const QString & , const int&))); - //connect(&networkDiscovery, SIGNAL(connectionEstablished(interfaceconfiguration*)), this, SLOT(handleConnectionEstablished(interfaceconfiguration*))); + connect(&networkDiscovery, SIGNAL(connectionEstablished(QString)), this, SLOT(handleConnectionEstablished(QString))); connect(&networkDiscovery, SIGNAL(abortBoot(QString)), this, SLOT(abortBoot(const QString))); connect(&networkDiscovery, SIGNAL(updateStatusLabel(QString,QString)), this, SLOT(updateIfStatus(const QString &, const QString &))); - //connect(&networkDiscovery, SIGNAL(allProcessesFinished()), this, SLOT(handleAllProcessesFinished())); - connect(&networkDiscovery, SIGNAL(continueBoot(QString, bool)), this, SLOT(continueBoot(QString, bool))); + connect(&networkDiscovery, SIGNAL(allProcessesFinished()), this, SLOT(handleAllProcessesFinished())); + connect(&networkDiscovery, SIGNAL(continueBoot(QString, int)), this, SLOT(continueBoot(QString, int))); _started = false; @@ -44,14 +44,19 @@ void ndgui::startNetworkDiscovery(){ } } -void ndgui::handleConnectionEstablished(interfaceconfiguration *ifConf) { - finalUsableIntefacesMap.insert(ifConf->getInterface(), ifConf); +void ndgui::handleConnectionEstablished(QString ifName) { + _ifNameList.append(ifName); } void ndgui::handleAllProcessesFinished() { qDebug() << "all Processes finished"; - if(finalUsableIntefacesMap.size() > 0) { - // chooseInterfaceDialog(); + if(_ifNameList.size() > 0) { + QString jsonArr = "["; + for(int i = 0; i < _ifNameList.size()-1; i++) { + jsonArr += "\"" + _ifNameList.value(i) + "\","; + } + jsonArr += "\"" + _ifNameList.last() + "\"]"; + chooseInterfaceDialog(jsonArr); } else { abortBoot("No usable interfaces found!"); } @@ -65,7 +70,7 @@ void ndgui::shutDownSystem() { } -void ndgui::continueBoot(QString ifName, bool userChoice) { +void ndgui::continueBoot(QString ifName, int userChoice) { if (!userChoice) { QString text = "continue with interface: " + ifName; qDebug() << text << "no user choice"; @@ -74,6 +79,8 @@ void ndgui::continueBoot(QString ifName, bool userChoice) { QString text = "continue with interface: " + ifName; qDebug() << text << "with user choice"; _webView->load(QUrl("qrc:html/continueBoot.html")); + QString gateway = networkDiscovery.getGatewayForInterface(ifName); + networkDiscovery.ip4_replaceDefaultRoute(ifName,gateway,0); } } @@ -132,7 +139,7 @@ void ndgui::abortBoot(const QString msg) { } void ndgui::chooseInterfaceDialog(const QString msg) { - QString code = QString("chooseInterfaceDialog('\%1')").arg(msg); + QString code = QString("chooseInterfaceDialog(\%1)").arg(msg); _webView->page()->mainFrame()->evaluateJavaScript(code); } diff --git a/LogReceiver/ndgui.h b/LogReceiver/ndgui.h index 21217ec..c41cecd 100644 --- a/LogReceiver/ndgui.h +++ b/LogReceiver/ndgui.h @@ -20,14 +20,14 @@ public: ~ndgui(); public slots: - void handleConnectionEstablished(interfaceconfiguration *ifConf); + void handleConnectionEstablished(QString ifName); void abortBoot(QString msg); void chooseInterfaceDialog(QString msg); void handleAllProcessesFinished(); void restartSystem(); void shutDownSystem(); - void continueBoot(QString ifName, bool userChoice); + void continueBoot(QString ifName, int userChoice); void showLog(); void startNetworkDiscovery(); @@ -50,7 +50,7 @@ private: NetworkDiscovery networkDiscovery; - QMap finalUsableIntefacesMap; // maps interfaceName to its gateway + QList _ifNameList; // maps interfaceName to its gateway }; diff --git a/LogReceiver/networkdiscovery.cpp b/LogReceiver/networkdiscovery.cpp index beca24f..159321d 100644 --- a/LogReceiver/networkdiscovery.cpp +++ b/LogReceiver/networkdiscovery.cpp @@ -14,7 +14,7 @@ NetworkDiscovery::~NetworkDiscovery() { void NetworkDiscovery::initAndRun(QString serverPath, QString pathToExe, QStringList* args) { - _userChoice = false; + _userChoice = true; _blocked = false; if (serverPath != DEFAULT_QTSOCKETADDRESS) { @@ -83,6 +83,38 @@ int NetworkDiscovery::replaceDefaultRoute(QString &ifName, QString &gateway, int networkManager.replaceDefaultRoute(ifName, gateway, mss, AF_INET); } +int NetworkDiscovery::ip4_replaceDefaultRoute(QString ifName, QString gateway, int mss) { + networkManager.replaceDefaultRoute(ifName, gateway, mss, AF_INET); +} + +int NetworkDiscovery::ip4_setManualConfiguration(QVariantMap result) { + //QJson::Parser parser; + //bool ok; + + //QVariantMap result = parser.parse(, &ok); + //if(!ok) { + // error + //return -1; + //} + QList dns; + dns.append(result["dns"].toString()); + return networkManager.ip4_setManualConfiguration(result["ifname"].toString(), + result["ipaddr"].toString(), + result["netmask"].toString(), + result["broadcast"].toString(), + result["gateway"].toString(), + 0, + AF_INET, + true, + "/etc/", + dns); +} + +QString NetworkDiscovery::getGatewayForInterface(QString ifName) { + interfaceconfiguration * ifConf = _ifcMap.value(ifName); + return ifConf->getGateway(); +} + QList NetworkDiscovery::getListOfNetworkInterfaces() { QList nIList = QNetworkInterface::allInterfaces(); QList result; @@ -194,11 +226,12 @@ bool NetworkDiscovery::checkConnectivity(QString ifName) { // get gateway address QString pathToGatewayFile(DEFAULT_GATEWAY_INFO_LOCATION); pathToGatewayFile += ifName; - interfaceconfiguration ifConf; - ifConf.readConfigOutOfFile(pathToGatewayFile); + interfaceconfiguration *ifConf = new interfaceconfiguration(); + ifConf->readConfigOutOfFile(pathToGatewayFile); + _ifcMap.insert(ifName, ifConf); // replace default route - qDebug() << networkManager.replaceDefaultRoute(ifName, ifConf.getGateway(), 0, AF_INET); + qDebug() << networkManager.replaceDefaultRoute(ifName, ifConf->getGateway(), 0, AF_INET); // check connectivity via tcp connection QTcpSocket *tcpSocket = new QTcpSocket(this); @@ -216,9 +249,9 @@ bool NetworkDiscovery::checkConnectivity(QString ifName) { // blockiere jeden weiteren check // emite continueBoot _blocked = true; - emit continueBoot(ifName, _userChoice); + emit continueBoot(ifName, 0); } else { - emit connectionEstablished(&ifConf); + emit connectionEstablished(ifName); } return true; } diff --git a/LogReceiver/networkdiscovery.h b/LogReceiver/networkdiscovery.h index 6efd926..48a6a7e 100644 --- a/LogReceiver/networkdiscovery.h +++ b/LogReceiver/networkdiscovery.h @@ -13,10 +13,10 @@ #include #include + + #include "interfaceconfiguration.h" #include "networkmanager.h" -//#include -//#include #include "status.h" #include "dhcp.h" #include "interface.h" @@ -47,6 +47,9 @@ public: 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); + int ip4_setManualConfiguration(QVariantMap result); + QString getGatewayForInterface(QString); private slots: void handleNewConnection(); @@ -59,11 +62,11 @@ private slots: signals: void addInterface(const QString &ifName); void changeProgressBarValue(const QString & ifName, const int $newValue); - void connectionEstablished(interfaceconfiguration *ifConf); + void connectionEstablished(QString ifName); void abortBoot(QString msg); void updateStatusLabel(QString ifName, QString status); void allProcessesFinished(); - void continueBoot(QString ifName, bool userChoice); + void continueBoot(QString ifName, int userChoice); private: QLocalServer *server; @@ -76,13 +79,13 @@ private: QMap clientProcessToIfNameMap; QString pathToDhcpcdExe; QStringList dhcpcdArguments; - QNetworkConfigurationManager configurationManager; - QNetworkAccessManager *accessManager; int numberOfProcesses; NetworkManager networkManager; bool _userChoice; bool _blocked; + QMap _ifcMap; + void handleNewInput(QLocalSocket * client); void runDHCPCD(QList &interfaces); -- cgit v1.2.3-55-g7522