|
@@ -0,0 +1,149 @@
|
|
|
+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"
|
|
|
+
|
|
|
+ function doSetInterface() {
|
|
|
+ setInterface.launchScript();
|
|
|
+ }
|
|
|
+
|
|
|
+ Application {
|
|
|
+ id: writeInterfaces
|
|
|
+ outFName: outfile
|
|
|
+ onAppFinished: {
|
|
|
+ console.log("IfaceDone");
|
|
|
+ }
|
|
|
+
|
|
|
+ onAppStarted: {
|
|
|
+ console.debug("IFACEappStarted :");
|
|
|
+ }
|
|
|
+
|
|
|
+ onAppError: {
|
|
|
+ console.debug("IFACEappError : " + exitError + " appStatus : " + exitStatus + " appCode " + exitCode );
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Application {
|
|
|
+ id: setInterface
|
|
|
+ appName: "cat"
|
|
|
+ arguments: infile
|
|
|
+
|
|
|
+ onAppFinished: {
|
|
|
+ console.debug("AppFinished :");
|
|
|
+ //console.debug("appError : " + exitError + " appStatus : " + exitStatus + " appCode " + exitCode );
|
|
|
+ console.debug("stdERR :" + stdERR);
|
|
|
+ //console.debug("stdOUT :" + stdOUT);
|
|
|
+ //console.debug("======================================");
|
|
|
+
|
|
|
+ var lines = stdOUT.split(/[\r\n]+/g);
|
|
|
+ var idx = 0;
|
|
|
+ var iface = [];
|
|
|
+ var inIface = 0;
|
|
|
+
|
|
|
+ lines.forEach(function(entry) {
|
|
|
+ if (entry.length > 0) {
|
|
|
+
|
|
|
+ if(entry.charAt(0) === '#'){
|
|
|
+ //console.log(idx + ":: " + "=======>:" + JSON.stringify(entry));
|
|
|
+ } else {
|
|
|
+ if (entry.indexOf("iface") !== -1){ //Interface Entry start
|
|
|
+ var ifaceEntry = entry.split(" ");
|
|
|
+ if ((ifaceEntry.length >=2) && (ifaceEntry[1] === "eth0")) {
|
|
|
+ iface.push({index: idx, txt: entry});
|
|
|
+ inIface = 1;
|
|
|
+ } else {
|
|
|
+ inIface = 0;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if(inIface === 1) {
|
|
|
+ iface.push({index: idx, txt: entry});
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ++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];
|
|
|
+ }
|
|
|
+
|
|
|
+ wrkAddr = netmask.split(".");
|
|
|
+ var ipMask = new Uint8Array(4);
|
|
|
+ for (i = 0; i< 4; i++) {
|
|
|
+ ipMask[i] = wrkAddr[i];
|
|
|
+ }
|
|
|
+
|
|
|
+ var broadcastUINT = new Uint8Array(4);
|
|
|
+
|
|
|
+ for (i = 0; i< 4; i++) {
|
|
|
+ broadcastUINT[i] = ipAddress[i] | (~ipMask[i]);
|
|
|
+ }
|
|
|
+
|
|
|
+ var broadcast = broadcastUINT[0] +"." +
|
|
|
+ broadcastUINT[1] +"." + broadcastUINT[2] +"." +
|
|
|
+ broadcastUINT[3];
|
|
|
+
|
|
|
+ insertText = "\tbroadcast " + broadcast;
|
|
|
+ lines.splice(insertIdx, 0, insertText);
|
|
|
+ ++insertIdx;
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ var cmd = "echo -e " + "\"";
|
|
|
+ lines.forEach(function(entry){
|
|
|
+ cmd = cmd + entry + "\\n"
|
|
|
+ //console.log(JSON.stringify(entry));
|
|
|
+ });
|
|
|
+
|
|
|
+ cmd = cmd + "\"";
|
|
|
+ writeInterfaces.appName = cmd;
|
|
|
+ writeInterfaces.launchScript();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ onAppStarted: {
|
|
|
+ console.debug("appStarted :");
|
|
|
+ console.debug("appError : " + exitError + " appStatus : " + exitStatus + " appCode " + exitCode );
|
|
|
+ }
|
|
|
+
|
|
|
+ onAppError: {
|
|
|
+ console.debug("appError : " + exitError + " appStatus : " + exitStatus + " appCode " + exitCode );
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|