summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNiklas2011-09-27 17:03:35 +0200
committerNiklas2011-09-27 17:03:35 +0200
commitfcb16100b5aa80934c90ddd4a386acb14317f460 (patch)
treed8e4fc7920ba20965919b3d53c47695194b96c1f
parentadded a new function for manual configuration of an interface including a fun... (diff)
downloadfbgui-fcb16100b5aa80934c90ddd4a386acb14317f460.tar.gz
fbgui-fcb16100b5aa80934c90ddd4a386acb14317f460.tar.xz
fbgui-fcb16100b5aa80934c90ddd4a386acb14317f460.zip
manual config gui added. put the interfaceconfig map into networkDiscovery and adopted the signals.
-rw-r--r--LogReceiver/html/networkdiscovery.css26
-rw-r--r--LogReceiver/html/networkdiscovery.html130
-rw-r--r--LogReceiver/interfaceconfiguration.h3
-rw-r--r--LogReceiver/ndgui.cpp25
-rw-r--r--LogReceiver/ndgui.h6
-rw-r--r--LogReceiver/networkdiscovery.cpp45
-rw-r--r--LogReceiver/networkdiscovery.h15
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 @@
<script type="text/javascript" src="qrc:/html/js/nd-functions.js"></script>
<script type="text/javascript">
+
+var updateTips = function ( t ) {
+ $( ".validateTips" )
+ .text( t )
+ .addClass( "ui-state-highlight" );
+ setTimeout(
+ function() {
+ $( ".validateTips" ).removeClass( "ui-state-highlight", 1500 );
+ },
+ 500 );
+};
+
+var checkLength = function ( o, n, min, max ) {
+ if ( o.val().length > max || o.val().length < min ) {
+ o.addClass( "ui-state-error" );
+ updateTips( "Length of " + n + " must be between " +
+ min + " and " + max + "." );
+ return false;
+ } else {
+ return true;
+ }
+};
+
+var checkRegexp = function ( o, regexp, n ) {
+ if ( !( regexp.test( o.val() ) ) ) {
+ o.addClass( "ui-state-error" );
+ updateTips( n );
+ return false;
+ } else {
+ return true;
+ }
+};
+
+var ip4_manualConfigurationDialog = function () {
+ var ifname = $("#ifname"),
+ ipaddr = $("#ipaddr"),
+ netmask = $("#netmask"),
+ broadcast = $("#broadcast"),
+ gateway = $("#gateway"),
+ dns = $("#dns"),
+ allFields = $([]).add(ifname).add(ipaddr).add(netmask).add(broadcast).add(gateway).add(dns);
+
+ $("#nd_manual_configuration_dialog").dialog(
+ { buttons: { "Cancel": function() {
+ $(this).dialog("close");},
+ "Ok": function() {
+ var bValid = true;
+ allFields.removeClass("ui-state-error");
+
+ //the interface name has to be choosen out of a dropdown menue
+ //bValid = bValid && checkLength(ifname, "Interface", 2, 15);
+ bValid = bValid && checkLength(ipaddr, "IP-Address", 7, 15);
+ bValid = bValid && checkLength(netmask, "Netmask Address", 7, 15);
+ bValid = bValid && checkLength(broadcast, "Broadcast Address", 7, 15);
+ bValid = bValid && checkLength(gateway, "Gateway Address", 7, 15);
+ bValid = bValid && checkLength(dns, "DNS Address", 7, 15);
+
+ bValid = bValid && checkRegexp(ipaddr, /\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/, "Is not a valid IP-Address! Format has to be e.g.: 192.168.1.2 (max value is 255)");
+ bValid = bValid && checkRegexp(netmask, /\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/, "Is not a valid IP-Address! Format has to be e.g.: 255.255.255.0 (max value is 255)");
+ bValid = bValid && checkRegexp(broadcast, /\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/, "Is not a valid IP-Address! Format has to be e.g.: 192.168.1.255 (max value is 255)");
+ bValid = bValid && checkRegexp(gateway, /\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/, "Is not a valid IP-Address! Format has to be e.g.: 192.168.1.254 (max value is 255)");
+ bValid = bValid && checkRegexp(dns, /\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/, "Is not a valid IP-Address! Format has to be e.g.: 192.168.1.111 (max value is 255)");
+
+ if (bValid) {
+ // put variables into a json object
+ // send to qt networkdiscovery
+ var o = {"ifname" : ifname,
+ "ipaddr" : ipaddr,
+ "netmask" : netmask,
+ "broadcast" : broadcast,
+ "gateway" : gateway,
+ "dns" : dns }
+ fbgui.ip4_setManualConfiguraton(o);
+ $(this).dialog("close");
+ } }
+ } ,
+ //autoOpen: false,
+ minWidth: 450,
+ modal: true,
+ resizable: false,
+ draggable: false,
+ close: function() {allFields.val("").removeClass("ui-state-error");},
+ open: function(event, ui) { $(".ui-dialog-titlebar-close").hide();}
+ });
+};
+
var abortBootDialog = function (m) {
$("#nd_abort_boot_msg").html(m);
$("#nd_abort_boot_dialog").dialog(
- { buttons: { "Manual Configure": function() {
+ { buttons: { "Manual Configure": function() {
+ ip4_manualConfigurationDialog();
$(this).dialog("close");},
"Show Log": function() {fbgui.showLog();
$(this).dialog("close");},
@@ -30,11 +117,13 @@ var abortBootDialog = function (m) {
var chooseInterfaceDialog = function (i) {
var cb = "<label> Choose your interface: </label>"+
- "<select>"+
- " <option>eth0</option>"+ //should look like this: " <option>"+ +"</option>"+
- " <option>eth1</option>"+
- " <option>eth2</option>"+
- "</select>";
+ "<select id='nd_ifName_select'>";
+ jQuery.each(i, function() {
+ cb += " <option>"+ this +"</option>";
+ }
+ );
+ cb += "</select>";
+
$("#nd_choose_interface_msg").html(cb);
$("#nd_choose_interface_dialog").dialog(
{ buttons: { "Show Log": function() {fbgui.showLog();
@@ -43,8 +132,11 @@ var chooseInterfaceDialog = function (i) {
$(this).dialog("close"); },
"Shut Down": function() { fbgui.shutDownSystem();
$(this).dialog("close"); },
- "Continue": function() { fbgui.continueBoot();
- $(this).dialog("close"); }
+ "Continue": function() {
+ var ifName = $("#nd_ifName_select :selected").text();
+ fbgui.continueBoot(ifName,1);
+ $(this).dialog("close");
+ }
} ,
minWidth: 550,
modal: true,
@@ -81,7 +173,6 @@ var addInterface = function (i){
);
$("#"+i+"_progress").progressbar({ value: 33 });
};
-
</script>
@@ -111,6 +202,27 @@ var addInterface = function (i){
<div id="nd_choose_interface_dialog">
<p id="nd_choose_interface_msg"></p>
</div>
+ <!-- anchor for the manual configuration dialog -->
+ <div id="nd_manual_configuration_dialog">
+ <p id="nd_manual_configuration_msg"></p>
+ <p class="validateTips">All form fields are required.</p>
+ <form>
+ <fieldset>
+ <label for="ifname">Interface</label>
+ <input type="text" name="ifname" id="ifname" class="text ui-widget-content ui-corner-all"/>
+ <label for="ipaddr">IP-Address</label>
+ <input type="text" name="ipaddr" id="ipaddr" class="text ui-widget-content ui-corner-all"/>
+ <label for="netmask">Netmask</label>
+ <input type="text" name="netmask" id="netmask" class="text ui-widget-content ui-corner-all"/>
+ <label for="broadcast">Broadcast Address</label>
+ <input type="text" name="broadcast" id="broadcast" class="text ui-widget-content ui-corner-all"/>
+ <label for="gateway">Gateway Address</label>
+ <input type="text" name="gateway" id="gateway" class="text ui-widget-content ui-corner-all"/>
+ <label for="dns">DNS</label>
+ <input type="text" name="dns" id="dns" class="text ui-widget-content ui-corner-all"/>
+ </fieldset>
+ </form>
+ </div>
<!-- anchor for qt interface progress foo -->
<div id="nd_progress_container"></div>
</section>
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<QString, interfaceconfiguration*> finalUsableIntefacesMap; // maps interfaceName to its gateway
+ QList<QString> _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<QString> 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<QString> NetworkDiscovery::getListOfNetworkInterfaces() {
QList<QNetworkInterface> nIList = QNetworkInterface::allInterfaces();
QList<QString> 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 <syslog.h>
#include <sysfs/libsysfs.h>
+
+
#include "interfaceconfiguration.h"
#include "networkmanager.h"
-//#include <qlocalserver.h>
-//#include <qlocalsocket.h>
#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<QProcess*, QString> clientProcessToIfNameMap;
QString pathToDhcpcdExe;
QStringList dhcpcdArguments;
- QNetworkConfigurationManager configurationManager;
- QNetworkAccessManager *accessManager;
int numberOfProcesses;
NetworkManager networkManager;
bool _userChoice;
bool _blocked;
+ QMap<QString, interfaceconfiguration*> _ifcMap;
+
void handleNewInput(QLocalSocket * client);
void runDHCPCD(QList<QString> &interfaces);