|
@@ -1,19 +1,50 @@
|
|
|
import QtQuick 2.5
|
|
|
import ApplicationLauncher 1.0
|
|
|
|
|
|
+
|
|
|
Item {
|
|
|
property string mode: "static"
|
|
|
property string ifacename: "eth0"
|
|
|
property string address: "192.168.0.125"
|
|
|
property string netmask: "255.255.255.0"
|
|
|
property string gateway: "192.168.0.10"
|
|
|
- property string infile: "/etc/networks/interfaces"
|
|
|
- property string outfile: "/etc/networks/interfaces"
|
|
|
+ property string nameserver: "192.168.0.10"
|
|
|
+ property string infile: "/etc/network/interfaces"
|
|
|
+ property string outfile: "/etc/network/interfaces"
|
|
|
+
|
|
|
|
|
|
function doSetInterface() {
|
|
|
+ setInterface.interfaceMode = "Set";
|
|
|
+ setInterface.launchScript();
|
|
|
+ }
|
|
|
+
|
|
|
+ function doGetInterface() {
|
|
|
+ setInterface.interfaceMode = "Get";
|
|
|
setInterface.launchScript();
|
|
|
}
|
|
|
|
|
|
+ function doRestartNetwork() {
|
|
|
+ worker.appName = "/etc/init.d/S40network";
|
|
|
+ worker.arguments = "restart";
|
|
|
+ worker.launchScript();
|
|
|
+ }
|
|
|
+
|
|
|
+ Application{
|
|
|
+ id: worker
|
|
|
+ onAppFinished: {
|
|
|
+ console.log("WorkerDone");
|
|
|
+ }
|
|
|
+
|
|
|
+ onAppStarted: {
|
|
|
+ console.debug("WorkerappStarted :");
|
|
|
+ }
|
|
|
+
|
|
|
+ onAppError: {
|
|
|
+ console.debug("WorkerappError : " + exitError + " appStatus : " + exitStatus + " appCode " + exitCode );
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
Application {
|
|
|
id: writeInterfaces
|
|
|
outFName: outfile
|
|
@@ -31,16 +62,18 @@ Item {
|
|
|
}
|
|
|
|
|
|
Application {
|
|
|
+ property string interfaceMode:""
|
|
|
+
|
|
|
id: setInterface
|
|
|
appName: "cat"
|
|
|
arguments: infile
|
|
|
|
|
|
onAppFinished: {
|
|
|
console.debug("AppFinished :");
|
|
|
- //console.debug("appError : " + exitError + " appStatus : " + exitStatus + " appCode " + exitCode );
|
|
|
+ console.debug("appError : " + exitError + " appStatus : " + exitStatus + " appCode " + exitCode );
|
|
|
console.debug("stdERR :" + stdERR);
|
|
|
- //console.debug("stdOUT :" + stdOUT);
|
|
|
- //console.debug("======================================");
|
|
|
+ console.debug("stdOUT :" + stdOUT);
|
|
|
+ console.debug("======================================");
|
|
|
|
|
|
var lines = stdOUT.split(/[\r\n]+/g);
|
|
|
var idx = 0;
|
|
@@ -71,68 +104,122 @@ Item {
|
|
|
++idx;
|
|
|
});
|
|
|
|
|
|
- lines.splice(iface[0].index, iface[iface.length - 1].index - iface[0].index + 1);
|
|
|
-
|
|
|
- var insertIdx = iface[0].index;
|
|
|
- var insertText;
|
|
|
- if(mode === "static") {
|
|
|
- insertText = "iface " + ifacename + " inet " + mode;
|
|
|
- lines.splice(insertIdx, 0, insertText);
|
|
|
- ++insertIdx;
|
|
|
- insertText = "\taddress " + address;
|
|
|
- lines.splice(insertIdx, 0, insertText);
|
|
|
- ++insertIdx;
|
|
|
- insertText = "\tnetmask " + netmask;
|
|
|
- lines.splice(insertIdx, 0, insertText);
|
|
|
- ++insertIdx;
|
|
|
-
|
|
|
-
|
|
|
- //Broadcas Adresse ausrechnen
|
|
|
- var wrkAddr = address.split(".");
|
|
|
- var ipAddress = new Uint8Array(4);
|
|
|
- var i;
|
|
|
-
|
|
|
- for (i = 0; i< 4; i++) {
|
|
|
- ipAddress[i] = wrkAddr[i];
|
|
|
- }
|
|
|
+ var interfaceCMD = interfaceMode;
|
|
|
|
|
|
- wrkAddr = netmask.split(".");
|
|
|
- var ipMask = new Uint8Array(4);
|
|
|
- for (i = 0; i< 4; i++) {
|
|
|
- ipMask[i] = wrkAddr[i];
|
|
|
+ if (interfaceCMD === "Get"){ // Auslesen der aktuellen Einstellungen
|
|
|
+ console.log(">>>>>>>>>:: " + JSON.stringify(interfaceCMD));
|
|
|
+ mode = "";
|
|
|
+ address = "";
|
|
|
+ netmask = "";
|
|
|
+ nameserver = "";
|
|
|
+ gateway = "";
|
|
|
+
|
|
|
+ if (iface[0].txt.indexOf("dhcp") !== -1) {
|
|
|
+ mode = "dhcp";
|
|
|
}
|
|
|
+ if (iface[0].txt.indexOf("static") !== -1) {
|
|
|
+ mode = "static";
|
|
|
+
|
|
|
+ var i;
|
|
|
+ var wdata;
|
|
|
+ for ( i = 1; i < iface.length; i++) {
|
|
|
+ if ( iface[i].txt.indexOf("address") !== -1) {
|
|
|
+ wdata = iface[i].txt.split(" ");
|
|
|
+ address = wdata[1];
|
|
|
+ }
|
|
|
|
|
|
- var broadcastUINT = new Uint8Array(4);
|
|
|
+ if ( iface[i].txt.indexOf("netmask") !== -1) {
|
|
|
+ wdata = iface[i].txt.split(" ");
|
|
|
+ netmask = wdata[1];
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( iface[i].txt.indexOf("gateway") !== -1) {
|
|
|
+ wdata = iface[i].txt.split(" ");
|
|
|
+ gateway = wdata[1];
|
|
|
+ }
|
|
|
|
|
|
- for (i = 0; i< 4; i++) {
|
|
|
- broadcastUINT[i] = ipAddress[i] | (~ipMask[i]);
|
|
|
+ if ( iface[i].txt.indexOf("nameserver") !== -1) {
|
|
|
+ wdata = iface[i].txt.split(" ");
|
|
|
+ wdata[3] = wdata[3].replace(/\'/g, '').replace(/\"/g, '');
|
|
|
+ nameserver = wdata[3];
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ if (interfaceCMD === "Set") { // Setzen der Gewälten Einstellungen
|
|
|
+ console.log(">>>>>>>>>:: " + JSON.stringify(interfaceCMD));
|
|
|
+ lines.splice(iface[0].index, iface[iface.length - 1].index - iface[0].index + 1);
|
|
|
+
|
|
|
+ var insertIdx = iface[0].index;
|
|
|
+ var insertText;
|
|
|
+ if(mode === "static") {
|
|
|
+ insertText = "iface " + ifacename + " inet " + mode;
|
|
|
+ lines.splice(insertIdx, 0, insertText);
|
|
|
+ ++insertIdx;
|
|
|
+ insertText = "\taddress " + address;
|
|
|
+ lines.splice(insertIdx, 0, insertText);
|
|
|
+ ++insertIdx;
|
|
|
+ insertText = "\tnetmask " + netmask;
|
|
|
+ lines.splice(insertIdx, 0, insertText);
|
|
|
+ ++insertIdx;
|
|
|
+ insertText = "\tgateway " + gateway;
|
|
|
+ lines.splice(insertIdx, 0, insertText);
|
|
|
+ ++insertIdx;
|
|
|
+
|
|
|
+ //Broadcast Adresse ausrechnen
|
|
|
+ var wrkAddr = address.split(".");
|
|
|
+ var ipAddress = new Uint8Array(4);
|
|
|
+ var i;
|
|
|
+
|
|
|
+ for (i = 0; i< 4; i++) {
|
|
|
+ ipAddress[i] = wrkAddr[i];
|
|
|
+ }
|
|
|
|
|
|
- var broadcast = broadcastUINT[0] +"." +
|
|
|
- broadcastUINT[1] +"." + broadcastUINT[2] +"." +
|
|
|
- broadcastUINT[3];
|
|
|
+ wrkAddr = netmask.split(".");
|
|
|
+ var ipMask = new Uint8Array(4);
|
|
|
+ for (i = 0; i< 4; i++) {
|
|
|
+ ipMask[i] = wrkAddr[i];
|
|
|
+ }
|
|
|
|
|
|
- insertText = "\tbroadcast " + broadcast;
|
|
|
- lines.splice(insertIdx, 0, insertText);
|
|
|
- ++insertIdx;
|
|
|
+ var broadcastUINT = new Uint8Array(4);
|
|
|
|
|
|
- insertText = "\tpost-up echo " + "'nameserver " + gateway + "' > /etc/resolv.conf";
|
|
|
- lines.splice(insertIdx, 0, insertText);
|
|
|
- } else if (mode === "dhcp") {
|
|
|
- insertText = "iface " + ifacename + " inet " + mode;
|
|
|
- lines.splice(insertIdx, 0, insertText);
|
|
|
- ++insertIdx;
|
|
|
- }
|
|
|
+ for (i = 0; i< 4; i++) {
|
|
|
+ broadcastUINT[i] = ipAddress[i] | (~ipMask[i]);
|
|
|
+ }
|
|
|
|
|
|
- var cmd = "echo -e " + "\"";
|
|
|
- lines.forEach(function(entry){
|
|
|
- cmd = cmd + entry + "\\n"
|
|
|
- //console.log(JSON.stringify(entry));
|
|
|
- });
|
|
|
+ var broadcast = broadcastUINT[0] +"." +
|
|
|
+ broadcastUINT[1] +"." + broadcastUINT[2] +"." +
|
|
|
+ broadcastUINT[3];
|
|
|
+
|
|
|
+ insertText = "\tbroadcast " + broadcast;
|
|
|
+ lines.splice(insertIdx, 0, insertText);
|
|
|
+ ++insertIdx;
|
|
|
+
|
|
|
+ insertText = "\tpost-up echo " + "'nameserver " + nameserver + "' > /etc/resolv.conf";
|
|
|
+ lines.splice(insertIdx, 0, insertText);
|
|
|
+ } else if (mode === "dhcp") {
|
|
|
+ insertText = "iface " + ifacename + " inet " + mode;
|
|
|
+ lines.splice(insertIdx, 0, insertText);
|
|
|
+ ++insertIdx;
|
|
|
+ }
|
|
|
+
|
|
|
+ var cmd = "echo -e " + "\"";
|
|
|
+ lines.forEach(function(entry){
|
|
|
+ cmd = cmd + entry + "\\n"
|
|
|
+ //console.log(JSON.stringify(entry));
|
|
|
+ });
|
|
|
+
|
|
|
+ cmd = cmd + "\"";
|
|
|
+ writeInterfaces.appName = cmd;
|
|
|
+ writeInterfaces.launchScript();
|
|
|
+ }
|
|
|
|
|
|
- cmd = cmd + "\"";
|
|
|
- writeInterfaces.appName = cmd;
|
|
|
- writeInterfaces.launchScript();
|
|
|
+ console.log(">> mode :: " + JSON.stringify(mode));
|
|
|
+ console.log(">> address :: " + JSON.stringify(address));
|
|
|
+ console.log(">> netmask :: " + JSON.stringify(netmask));
|
|
|
+ console.log(">> gateway :: " + JSON.stringify(gateway));
|
|
|
+ console.log(">> nameserver :: " + JSON.stringify(nameserver));
|
|
|
|
|
|
}
|
|
|
|