//-----------------AB HIER NICHTS MEHR ÄNDERN------------------------------------------------------
const dpPrefix = "javascript."+ instance +".";
// Hier Definition iqontrol-Style für Popup
const format = "
Geamtanzahl Vouchers:"+respv.data.length+"
"));}
if (writeFile) setState(dpPrefix + "WLANUnifi.Wifi_Vouchers", "Geamtanzahl Vouchers:"+respv.data.length+"
"));
if (writeFile) {setState(dpPrefix + "WLANUnifi.Wifi_Vouchers_Anzahl", respv.data.length);
mylog(listCode +" -- " +list)
setState(dpPrefix + "WLANUnifi.Wifi_Vouchers_List", list ); // für VIS anzeige - löschen
setState(dpPrefix + "WLANUnifi.Wifi_Vouchers_CodeList", listCode ); } // für VIS anzeige - löschen
//mylog("BIN RAUS AUS workvouchers");
}
//-----------------------------------------GET--Health---------------------------------------------------------------
async function getHealth() {
if (health) {
mylog("BIN IN gethealth");
return new Promise(async (resolve, reject) => {
dlog("nur mal so");
if(!loggedIn) await login().catch((e) => reject(e));
resph = await request.get({
url: unifi_controller + "/api/s/"+siteName+"/stat/health",
headers: { Cookie: cookies.join("; ") }
}).catch((e) => { log("getStatus reject " + e); /*reject(e)*/ return testerrh=true; });
if (!testerrh) {
dlog("got response " + JSON.stringify(resph));
dlog(typeof resph);
mylog("--------------------- " + resph);
resolve("done");
} else {log("reject weil resph ist 00"); reject();}
mylog("bin raus a GET health");
});
}}
//-----------------------------------------WORK--HEALTH---------------------------------------------------------------
function workHealth() {
mylog("BIN IN workhealth");
dlog("got response " + JSON.stringify(resph));
dlog(typeof resph);
mylog("--------------------- " + resph);
resph=resph.replace(/-r/g, "_r")
resph = JSON.parse(resph);
mylog(resph.data[0].rx_bytes_r);
setState(dpPrefix + "WLANUnifi.Health.WLAN.Status",resph.data[0].status );
setState(dpPrefix + "WLANUnifi.Health.WLAN.Users",resph.data[0].num_user);
setState(dpPrefix + "WLANUnifi.Health.WLAN.Guests",resph.data[0].num_guest );
setState(dpPrefix + "WLANUnifi.Health.WLAN.TXBytes",resph.data[0].tx_bytes_r );
setState(dpPrefix + "WLANUnifi.Health.WLAN.RXBytes",resph.data[0].rx_bytes_r );
setState(dpPrefix + "WLANUnifi.Health.WLAN.Adopted",resph.data[0].num_adopted );
setState(dpPrefix + "WLANUnifi.Health.WLAN.Disabled",resph.data[0].num_disabled );
setState(dpPrefix + "WLANUnifi.Health.WLAN.Disconnected",resph.data[0].num_disconnected );
// if (apInfo) healthListe = apHead;
healthListe = "";
healthListeTable="";
//healthListe = apHead + apTable +"Health-Daten: | |
"
healthListeTable = "Status | "+resph.data[0].status+
" |
Users | "+resph.data[0].num_user +
" |
Gäste | " +resph.data[0].num_guest +
" |
TxBytes | "+resph.data[0].tx_bytes_r +
" |
RxBytes | "+resph.data[0].rx_bytes_r+
" |
Disabled | "+resph.data[0].num_disabled+
" |
Adopted | "+resph.data[0].num_adopted+
" |
Disconnected | "+resph.data[0].num_disconnected+
" |
"
healthListe = apHead + apTable +"Health-Daten: | |
" + healthListeTable;
healthListeTable="Health Daten: | |
" + healthListeTable;
mylog(healthListe);
mylog("bin raus a work health");
}
//-----------------------------------------SET WIFIS - WIFI EIN-AUSSCHALTEN----------------------------------------------
//Wifi an-/ausschalten
//enabled: true = anschalten; false = ausschalten
//wifi: wifi object aus der konstanten wifis
async function setWifi(enabled, wifi) {
if (!clientPause) {
return new Promise(async (resolve, reject) => {
dlog("setWifi: start set Wifi_haupt");
if (!loggedIn) { dlog("need to login"); await login().catch((e) => reject(e)); }
dlog("setWifi: now setting Wifi_haupt");
let resp = request.post({
url: unifi_controller + "/api/s/"+siteName+"/upd/wlanconf/" + wifi.id,
body: JSON.stringify({ enabled }),
headers: { 'Content-Type': 'application/json', Cookie: cookies.join("; ") }
}).catch((e) => { dlog("setWifi: rejected: " + e); /*reject(e)*/ return testerrws=true; });
dlog("setWifi: got response")
if (resp != null) {
dlog("setWifi: Wifi wurde erfolgreich " + (enabled ? "eingeschaltet" : "ausgeschaltet"));
dlog(resp);
// getclient() Pause für umschalten
if (firstTime>=wifiLength) {
// if (true) {
clientPause = true;
setState(dpPrefix + "WLANUnifi.Wifi_Client_Pause",true);
clientPauseVal=parseInt((new Date().getTime()));
}
setState(dpPrefix + "WLANUnifi." + wifi.name, enabled, enabled);
resolve();
} else {
dlog("setWifi: rejetced")
dlog("resp: " + JSON.stringify(resp));
reject("msg: " + JSON.parse(resp.body).meta.msg);}
});
} else { log("WLAN wird gerade umgeschaltet"); }
}
//-----------------------------------------CREATE VOUCHERS----------------------------------------------
async function createVoucher (mybody) {
mylog(JSON.stringify( mybody ));
return new Promise(async (resolve, reject) => {
mylog("createVoucher in aktion");
if (!loggedIn) { mylog("need to login"); await login().catch((e) => reject(e)); }
mylog("do it !");
let respcv = request.post({
url: unifi_controller + "/api/s/"+siteName+"/cmd/hotspot/" ,
body: JSON.stringify( mybody ),
// body: mybody,
headers: { 'Content-Type': 'application/json', Cookie: cookies.join("; ") }
}).catch((e) => { log("setWifi: rejected: " + e); /*reject(e)*/ return testerrcv=true; });
dlog("setWifi: got response")
dlog("------------: "+respcv);
dlog("resp: " + JSON.stringify(respcv));
});
}
//-----------------------------------------DELETE VOUCHERS----------------------------------------------
async function deleteVoucher (mybody) {
mylog(JSON.stringify( mybody ));
return new Promise(async (resolve, reject) => {
dlog("deleteVoucher in aktion");
if (!loggedIn) { mylog("need to login"); await login().catch((e) => reject(e)); }
mylog("do it !");
let respdv = request.post({
url: unifi_controller + "/api/s/"+siteName+"/cmd/hotspot/" ,
body: JSON.stringify( mybody ),
// body: mybody,
headers: { 'Content-Type': 'application/json', Cookie: cookies.join("; ") }
}).catch((e) => { log("setWifi: rejected: " + e); /*reject(e)*/ return testerrdv=true; });
dlog("setWifi: got response")
dlog("------------: "+respdv);
dlog("resp: " + JSON.stringify(respdv));
dlog("resp: " + JSON.parse(respdv));
});
}
//-----------------------------------------GET--APs---------------------------------------------------------------
async function getAp(id) {
if (apInfo) {
mylog("BIN IN getap mit Wert" + id);
return new Promise(async (resolve, reject) => {
dlog("nur mal so");
if(!loggedIn) await login().catch((e) => reject(e));
respa = await request.get({
url: unifi_controller + "/api/s/"+siteName+"/stat/device/"+id,
headers: { Cookie: cookies.join("; ") }
}).catch((e) => { dlog("getStatus reject " + e); /*reject(e)*/ return testerrap=true; });
if (!testerrv) {
dlog("got response " + JSON.stringify(respv));
dlog(typeof respa);
dlog("--------------------- " + respa);
resolve("done");
} else {log("reject weil respv ist 00"); reject();}
mylog("bin raus a GETap");
});
}}
//-----------------------------------------WORK--APs---------------------------------------------------------------
function workAP (aliasAPname) {
let satisfy;
dlog("BIN IN work ap");
dlog("got response " + JSON.stringify(respa));
dlog(typeof respa);
dlog("--------------------- " + respa);
let abfrage = respa.indexOf("satisfaction");
respa = JSON.parse(respa);
if(abfrage>-1) { dlog("------------------ist war"); satisfy = respa.data[0].satisfaction;
} else { satisfy = 777 ;dlog("------------------ist nicht war");}
dlog(respa.data[0].model)
setState(dpPrefix + "WLANUnifi.APInfo."+ aliasAPname+".Model",respa.data[0].model );
setState(dpPrefix + "WLANUnifi.APInfo."+ aliasAPname+".IP_Adresse",respa.data[0].connect_request_ip );
setState(dpPrefix + "WLANUnifi.APInfo."+ aliasAPname+".Satisfaction", satisfy /*respa.data[0].satisfaction*/ );
setState(dpPrefix + "WLANUnifi.APInfo."+ aliasAPname+".Adopted",respa.data[0].adopted );
setState(dpPrefix + "WLANUnifi.APInfo."+ aliasAPname+".LoadAVG1",parseFloat(respa.data[0].sys_stats.loadavg_1));
setState(dpPrefix + "WLANUnifi.APInfo."+ aliasAPname+".LoadAVG5",parseFloat(respa.data[0].sys_stats.loadavg_5));
setState(dpPrefix + "WLANUnifi.APInfo."+ aliasAPname+".LoadAVG15",parseFloat(respa.data[0].sys_stats.loadavg_15));
setState(dpPrefix + "WLANUnifi.APInfo."+ aliasAPname+".ToController",respa.data[0].inform_ip );
var apListeHelfer= /*apListeTable +*/ "Model | "+respa.data[0].model+
" |
IP-Adresse | "+respa.data[0].connect_request_ip +
" |
Satisfaction | " + satisfy + //respa.data[0].satisfaction +
" |
Adopted | "+respa.data[0].adopted +
" |
LoadAVG1 | "+respa.data[0].sys_stats.loadavg_1 +
" |
ToController | "+respa.data[0].inform_ip+" |
";
apListeTable= apListeTable + apListeHelfer ;
apListe = apListe + " | |
"+"AP-Daten: | "+aliasAPname+" |
"+apListeHelfer;
mylog (apListe)
mylog("bin raus a work ap");
}
//-----------------------------------------GET--Alarms---------------------------------------------------------------
function getAlarm() {
dlog("BIN IN ALARM");
return new Promise(async (resolve, reject) => {
dlog("nur mal so");
if (!loggedIn) await login().catch((e) => reject(e));
respal = await request.get({
url: unifi_controller + "/api/s/"+siteName+"/rest/alarm?archived=false", //?archived=false
headers: { Cookie: cookies.join("; ") }
}).catch((e) => { dlog("getStatus reject " + e); /*reject(e)*/ return testerral=true; });
dlog("got response " + JSON.stringify(respal));
//resp = JSON.parse(resp);
if (!testerral) {
resolve("done");
mylog("BIN raus aus ALARM");}
});
}
//-----------------------------------------WORK--Alarms---------------------------------------------------------------
function workAlarm() {
mylog("BIN IN work ALARM")
respal = JSON.parse(respal).data;
dlog("--------------------- " + JSON.stringify(respal));
let alarmHelfer="";
let alarmLength = Object.keys(respal).length;
setState(dpPrefix + "WLANUnifi.Alarm.Alarm_Anzahl", alarmLength);
mylog(Object.keys(respal).length.toString())
mylog(alarmLength.toString())
if (alarmLength >0) {
for (var j=0; j < alarmLength; j++) {
let datum = new Date (respal[j].time).toString();
mylog(datum.slice(0,datum.indexOf("GMT"))+"---"+respal[j].msg);
alarmHelfer=alarmHelfer +""+ datum.slice(0,datum.indexOf("GMT"))+" | "+respal[j].msg.slice(0, 50) + " |
";
}
alarmHelfer= alarmHelfer + "";
setState(dpPrefix + "WLANUnifi.Alarm.Alarm", ""+alarmHelfer);
if (iqontrol) fs.writeFileSync(datei4, apHead + "Geamtanzahl nicht archivierter Alarme:"+alarmLength+"
" +apTable +alarmHelfer) ;
} else {setState(dpPrefix + "WLANUnifi.Alarm.Alarm", "keine neuen Alarme");
if (iqontrol) fs.writeFileSync(datei4, apHead + "Geamtanzahl nicht archivierter Alarme:"+alarmLength+"