//-----------------AB HIER NICHTS MEHR ÄNDERN------------------------------------------------------
const versionNr = "19122019-3.1"
const dpPrefix = "javascript."+ instance +".";
// Hier Definition iqontrol-Style für Popup
const format = "
Voucher";
const format2 = "Clients";
const format3 = "";
const format6 =" | |
"
const apHead = "Voucher"
const apTable = "";
const request = require('request-promise-native').defaults({ rejectUnauthorized: false });
const pathVoucher = "/htmlvoucher.html"; const pathClient = "/htmlclients.html"; const pathInfo = "/htmlinfo.html"; const pathAlarm = "/htmlalarm.html"; const pathAbmelung = "/htmlLog.html";
const pathOnlyWLAN = "/htmlwlan.html";const pathOnlyLAN = "/htmllan.html";const pathOnlyDISC = "/htmldisc.html";
let cookies = [];
let loggedIn = false;
let debug = false;
let mylogs = false;
let syslogs = false;
let xxClientxx="Galaxy-S9"; // falls der name leerzeichen beinhaltet müssen diese mit _ ersetzt werden z.b : "liv in sky handy" zu "liv_in_sky_handy"
let xxClientxxIndex=0;
let clientPause = false;
let clientPauseVal;
let wifiDPs = [];
let wifiDPsHide = [];
let vouchiesDPs=[];
let myname = 'hostname';
let respv; let respc; let respw; let resph; let respgv; let respa; let respal; //geholte Daten
let countFalse=1;
let statusarr=[];
let writeFileVar =0;
let listValue=[]; //iqontrol löschen kachel
let listValue2; //iqontrol löschen kachel
let listValue3; //iqontrol löschen VIS
let nichtSchalten=true;
//let nichtSchalten2=false; //iqontrol löschen kachel
let versuch;
let listeDatenpunkte = [];
let listeDatenpunkteControl=[];
let countie;
let binAmArbeiten=false;
var midnight=false;
let apListeTable;
let apListe;
let healthListe;
let healthListeTable;
let notSeen=[];
let ipArrFehlt=[];
var notseenLengthOld;
var notseenLength;
let lastChange=[];
let mybodyVouchers2; // create-one-click-standard-voucher
let expire_var; // create-one-click-standard-voucher
let n_var; // create-one-click-standard-voucher
let quota_var; // create-one-click-standard-voucher
let note_var; // create-one-click-standard-voucher
let up_var; // create-one-click-standard-voucher
let down_var; // create-one-click-standard-voucher
let MBytes_var; // create-one-click-standard-voucher
let testerral=false; let testerrc=false; let testerrl=false; let testerrv=false; let testerrs=false; let testerrh=false; let testerrcv=false; let testerrdv=false; let testerrws=false; let testerrap=false;
var scriptCounter=0;
let health = true; // Angaben zum Systemstatus - die Healtdaten werden nur alle 5 Abfragezyklen geholt
let alarmSwitch =false;
let alarmCounter =0;
let firstTime=0;
let mybodyVouchers;
let monthChangeData=false;
let checkNetwork=false;
var wifiLength=0;
for(let wifi_name in wifis) {
wifiLength++; }
if (aliasname) myname="name";
if (ohneClientAbfrage) anwesenheit=false;
writeMyFile("neugestartet ... bitte warten", pathClient);
writeMyFile("neugestartet ... bitte warten", pathVoucher);
writeMyFile("neugestartet ... bitte warten", pathAlarm);
writeMyFile("neugestartet ... bitte warten", pathInfo);
writeMyFile("neugestartet ... bitte warten", pathOnlyWLAN);
writeMyFile("neugestartet ... bitte warten", pathOnlyLAN);
writeMyFile("neugestartet ... bitte warten", pathOnlyDISC);
if ( !anwesenheit) {writeMyFile("variable anwesenheit und/oder iqontrol ist nicht im unifiscript aktiviert - auf true setzen", pathClient);
writeMyFile("variable anwesenheit und/oder iqontrol ist nicht im unifiscript aktiviert - auf true setzen", pathOnlyWLAN);
writeMyFile("variable anwesenheit und/oder iqontrol ist nicht im unifiscript aktiviert - auf true setzen", pathOnlyLAN);
writeMyFile("variable anwesenheit und/oder iqontrol ist nicht im unifiscript aktiviert - auf true setzen", pathOnlyDISC);}
if ( !vouchers && !iqontrol) writeMyFile("variable vouchers und/oder iqontrol ist nicht im unifiscript aktiviert - auf true setzen", pathVoucher);
for(let wifi_name in wifis) {
wifiDPsHide.push(dpPrefix + "WLANUnifi.WLANSSIDsHide." + wifis[wifi_name].name);
createState(dpPrefix + "WLANUnifi.WLANSSIDsHide."+ wifi_name, false, { name: wifis[wifi_name].desc, role: 'switch', read: true, write: true, type: "boolean" });}
//Erstelle Datenpunkte für die WLANs automatisch
for(let wifi_name in wifis) {
wifiDPs.push(dpPrefix + "WLANUnifi." + wifis[wifi_name].name);
createState(dpPrefix + "WLANUnifi."+ wifi_name, { name: wifis[wifi_name].desc, role: 'switch', read: true, write: true, type: "boolean" });}
createState(dpPrefix + "WLANUnifi.Wifi_Clients", "not available",{ name: 'Clients_HTML_Table_VIS', role: 'string', read: true, write: true,});
createState(dpPrefix + "WLANUnifi.Wifi_ClientsOnlyLAN", "not available",{ name: 'Clients_LAN_HTML_Table_VIS', role: 'string', read: true, write: true,});
createState(dpPrefix + "WLANUnifi.Wifi_ClientsOnlyWLAN", "not available",{ name: 'Clients__WLAN_HTML_Table_VIS', role: 'string', read: true, write: true,});
createState(dpPrefix + "WLANUnifi.Wifi_ClientsOnlyDISC", "not available",{ name: 'Clients__Disconnected_HTML_Table_VIS', role: 'string', read: true, write: true,});
createState(dpPrefix + "WLANUnifi.Wifi_Clients_Anzahl_LAN", { name: 'Wifi_Clients_Anzahl_LAN', desc: 'Wifi_Clients_Anzahl_LAN', type: 'number',def:0, unit: '', min: '0', max: '100', role: '',read: true, write: false });
createState(dpPrefix + "WLANUnifi.Wifi_Clients_Anzahl_WLAN", { name: 'Wifi_Clients_Anzahl_WLAN', desc: 'Wifi_Clients_Anzahl_WLAN', type: 'number',def:0, unit: '', min: '0', max: '100', role: '',read: true, write: false });
createState(dpPrefix + "WLANUnifi.Wifi_Clients_Anzahl_DISC", { name: 'Wifi_Clients_Anzahl_DISC', desc: 'Wifi_Clients_Anzahl_DISC', type: 'number',def:0, unit: '', min: '0', max: '100', role: '',read: true, write: false });
createState(dpPrefix + "WLANUnifi.SiteLED", false, { name: 'SiteLED', type: 'boolean', role: 'switch', read: true, write: true,});
createState(dpPrefix + "WLANUnifi.Client_WhiteList", "default", { name: 'Client_WhiteList_Filter_String', desc: 'Alarm_Table', type: 'string', unit: '', role: '',read: true, write: true });
createState(dpPrefix + "WLANUnifi.Alarm.Alarm", { name: 'Alarm_Table_not_archieved', desc: 'Alarm_Table', type: 'string', unit: '', role: '',read: true, write: true });
createState(dpPrefix + "WLANUnifi.Missing_Name", "not available", { name: 'Missing_Name', desc: 'Missing_Name', type: 'string', unit: '', role: '',read: true, write: true });
createState(dpPrefix + "WLANUnifi.Alarm.Alarm_Anzahl", { name: 'Alarm_Anzahl', desc: 'Alarm_Table', type: 'number', unit: '', role: '',read: true, write: true });
createState(dpPrefix + "WLANUnifi.ZyklusZaehler", 1, { name: 'ZyklusZaehler', desc: 'ZyklusZaehler', type: 'number', unit: '', role: '',read: true, write: true });
createState(dpPrefix + "WLANUnifi.xxxScriptVersionxxx", versionNr,{ name: 'ScriptVersion', desc: 'ScriptVersion', type: 'string', unit: '', role: '',read: true, write: true });
if (anwesenheit) createState(dpPrefix + "WLANUnifi.Wifi_Clients_Log", { name: 'Clients_HTML_Table_VIS_Log', role: 'string', read: true, write: true,});
var foo = (aliasname) ? true : false;
createState(dpPrefix + "WLANUnifi.AliasName", foo, { name: ' AliasName', desc: 'schaltet Aliasnamen ein', role: 'switch', type: 'boolean', read: true, write: true,
} , function() {setStateDelayed(dpPrefix + "WLANUnifi.AliasName", foo, 200)});
//createState(dpPrefix + "WLANUnifi.Aussortiert", { name: 'Aussortiert', role: 'string', read: true, write: true,});
if (vouchers) {
createState(dpPrefix + "WLANUnifi.Wifi_Vouchers", { name: 'Vouchers_HTML_Table_VIS', role: 'string', read: true, write: true,});
createState(dpPrefix + "WLANUnifi.Wifi_Vouchers_List", { name: 'Vouchers_ID_List', role: 'string', read: true, write: true,});
createState(dpPrefix + "WLANUnifi.Wifi_Vouchers_CodeList", { name: 'Vouchers_Texte_Delete_VIS_Widget', role: 'string', read: true, write: true,});
createState(dpPrefix + "WLANUnifi.Wifi_Vouchers_CodeList2", { name: 'Vouchers_Werte_Delete_VIS_Widget', role: 'string', read: true, write: true,});
createState(dpPrefix + "WLANUnifi.Wifi_Vouchers_ValueCodeList", { name: 'Vouchers_ValueList_IQontrol', desc:"ValueCodeList", role: "", type:'number', states: "1:please wait ...;2:refresh webpage", def:1, min: 0, max: 20, read: true, write: true,});
createState(dpPrefix + "WLANUnifi.Wifi_Vouchers-CODES.A_New_Voucher.Create", false, { name: 'A_New_Voucher_Create', role: 'switch', type: 'boolean', read: true, write: true,});
createState(dpPrefix + "WLANUnifi.Wifi_Vouchers_DeleteVIS", { name: 'Vouchers_Schalter_Delete_VIS_Widget', role: 'switch', type: 'number', read: true, write: true,});
createState(dpPrefix + "WLANUnifi.Wifi_Vouchers_CreateStandard", 1, { name: 'Vouchers_Schalter_Create_VIS_Widget', role: 'switch', type: 'number', read: true, write: true,});
//createState(dpPrefix + "WLANUnifi.Wifi_Create_Standard_Voucher", false, { name: 'A_Delete_Voucher', role: 'switch', type: 'boolean', read: true, write: true,});
createState(dpPrefix + "WLANUnifi.Wifi_Vouchers-CODES.A_Delete_Voucher.Delete", false, { name: 'Voucher_Delete__Botton_VIS', role: 'switch', type: 'boolean', read: true, write: true,});
createState(dpPrefix + "WLANUnifi.Wifi_Vouchers-CODES.A_Delete_Voucher.Voucher_ID", "must be set",{ name: 'A_Delete_Voucher.Voucher_ID', role: 'string', read: true, write: true,});
createState(dpPrefix + "WLANUnifi.Wifi_Vouchers-CODES.A_New_Voucher.Dauer", "must be set",{ name: ' A_New_Voucher_Dauer', role: 'string', read: true, write: true,});
createState(dpPrefix + "WLANUnifi.Wifi_Vouchers-CODES.A_New_Voucher.MultiUse", "must be set",{ name: ' A_New_Voucher_MultiUse', role: 'string', read: true, write: true,});
createState(dpPrefix + "WLANUnifi.Wifi_Vouchers-CODES.A_New_Voucher.Anzahl", "must be set",{ name: ' A_New_Voucher_Anzahl', role: 'string', read: true, write: true,});
createState(dpPrefix + "WLANUnifi.Wifi_Vouchers-CODES.A_New_Voucher.Notiz", "",{ name: ' A_New_Voucher_Notiz', role: 'string', read: true, write: true,});
createState(dpPrefix + "WLANUnifi.Wifi_Vouchers-CODES.A_New_Voucher.Upload", "",{ name: ' A_New_Voucher_Uplaod', role: 'string', read: true, write: true,});
createState(dpPrefix + "WLANUnifi.Wifi_Vouchers-CODES.A_New_Voucher.Download", "",{ name: ' A_New_Voucher_Download', role: 'string', read: true, write: true,});
createState(dpPrefix + "WLANUnifi.Wifi_Vouchers-CODES.A_New_Voucher.Mb_Begrenzung", "", { name: ' A_New_Voucher_Mb_Begrenzung', role: 'string', read: true, write: true,});
for (var i = 1; i < 21; i++) {
var x=i.toString();
if (i<10) x="0"+x;
createState(dpPrefix + "WLANUnifi.Wifi_Vouchers-CODES.CODE"+x, { name: 'Unifi Voucher_Code'+x, role: 'string', read: true, write: true, });
createState(dpPrefix + "WLANUnifi.Wifi_Vouchers-CODES.CODE"+x+".code"+x, { name: 'Unifi Voucher_Code_code'+x, role: 'string', read: true, write: true, });
createState(dpPrefix + "WLANUnifi.Wifi_Vouchers-CODES.CODE"+x+".erstellt", { name: 'Unifi Voucher_Code_erstellt'+x, role: 'string', read: true, write: true, });
createState(dpPrefix + "WLANUnifi.Wifi_Vouchers-CODES.CODE"+x+".dauer", { name: 'Unifi Voucher_Code_duration'+x, role: 'string', read: true, write: true, });
createState(dpPrefix + "WLANUnifi.Wifi_Vouchers-CODES.CODE"+x+".abgelaufen", { name: 'Unifi Voucher_Code_expires'+x, role: 'string', read: true, write: true, });
createState(dpPrefix + "WLANUnifi.Wifi_Vouchers-CODES.CODE"+x+".id", { name: 'Unifi Voucher_Code_id'+x, role: 'string', read: true, write: true, });
createState(dpPrefix + "WLANUnifi.Wifi_Vouchers-CODES.CODE"+x+".notiz", { name: 'Unifi Voucher_Code_notiz'+x, role: 'string', read: true, write: true, });
}
let vouchiesHelper="" //Werteliste-Datenpunkt für StandardVouchies
let vouchiesHelper2="Wähle Standard;"
let vouchiesHelper3="1;"
countie=0;
for(let vouchies in standardVouchers){
countie++
vouchiesHelper2 = vouchiesHelper2 + vouchies + " ("+standardVouchers[vouchies].notiz +");"
vouchiesHelper3 = vouchiesHelper3+(countie+1)+";"
vouchiesHelper = vouchiesHelper+countie + ":" + vouchies + " (" +standardVouchers[vouchies].notiz +");"
vouchiesDPs.push(vouchies);
}
// + " " + "("+standardVouchers[vouchies].notiz+");"}
// vouchiesHelper=vouchiesHelper.substr(0, vouchiesHelper.length-1);
vouchiesHelper=vouchiesHelper + (countie+1)+":"+"Standard-Voucher-Auswahl";
createState(dpPrefix + "WLANUnifi.Wifi_Vouchers_StandardList", { name: 'Vouchers_StandardList_IQontrol', desc:"Vouchers_StandardList", role: "", type:'number', states: vouchiesHelper, def:(countie+1), min: 0, max: 20, read: true, write: true,});
createState(dpPrefix + "WLANUnifi.Wifi_Vouchers_CreateList", { name: 'Vouchers_Texte_Create_VIS_Widget', desc:"Wifi_Vouchers_CreateList", role: "string", type:'string', read: true, write: true}, function() {
mylog("created"); setState(dpPrefix + "WLANUnifi.Wifi_Vouchers_CreateList",vouchiesHelper2)});
createState(dpPrefix + "WLANUnifi.Wifi_Vouchers_CreateListStandard", { name: 'Vouchers_Werte_Create_VIS_Widget', desc:"Wifi_Vouchers_CreateList", role: "string", type:'string', read: true, write: true}, function() {
mylog("created"); setState(dpPrefix + "WLANUnifi.Wifi_Vouchers_CreateListStandard",vouchiesHelper3)});
}
createState(dpPrefix + "WLANUnifi.Wifi_Client_Pause", false, { name: 'Wifi_Client_Pause', role: 'switch', type: 'boolean', read: true, write: true,});
createState(dpPrefix + "WLANUnifi.Wifi_Clients_Anzahl", { name: 'Wifi_Clients_Anzahl', desc: 'Wifi_Clients_Anzahl', type: 'number',def:0, unit: '', min: '0', max: '100', role: '',read: true, write: false });
if (vouchers) createState(dpPrefix + "WLANUnifi.Wifi_Vouchers_Anzahl", { name: 'Wifi_Vouchers_Anzahl', desc: 'Wifi_Vouchers_Anzahl', type: 'number', unit: '', min: '0', max: '100', role: '',read: true, write: true });
createState(dpPrefix + "WLANUnifi.Wifi_Info", { name: 'Info_HTML_Table_VIS', role: 'string', read: true, write: true,});
if (health) {createState(dpPrefix + "WLANUnifi.Health.WLAN.Status", { name: 'Health_Status', desc: 'Health_Status', type: 'string', unit: '', role: '',read: true, write: true });
createState(dpPrefix + "WLANUnifi.Health.WLAN.Users", { name: 'Health_Users', desc: 'Health_Users', type: 'number', unit: '', min: '0', max: '1000', role: '',read: true, write: true });
createState(dpPrefix + "WLANUnifi.Health.WLAN.Guests", { name: 'Health_Guests', desc: 'Health_Guests', type: 'number', unit: '', min: '0', max: '100', role: '',read: true, write: true });
createState(dpPrefix + "WLANUnifi.Health.WLAN.TXBytes", { name: 'Health_TXBytes', desc: 'Health_TXBytes', type: 'number', unit: '', min: '0', max: '9999999', role: '',read: true, write: true });
createState(dpPrefix + "WLANUnifi.Health.WLAN.RXBytes", { name: 'Health_RXBytes', desc: 'Health_RXBytes', type: 'number', unit: '', min: '0', max: '9999999', role: '',read: true, write: true });
createState(dpPrefix + "WLANUnifi.Health.WLAN.Adopted", { name: 'Health_Adopted', desc: 'Health_Adopted', type: 'number', unit: '', min: '0', max: '100', role: '',read: true, write: true });
createState(dpPrefix + "WLANUnifi.Health.WLAN.Disabled", { name: 'Health_Disabled', desc: 'Health_Disabled', type: 'number', unit: '', min: '0', max: '100', role: '',read: true, write: true });
createState(dpPrefix + "WLANUnifi.Health.WLAN.Disconnected", { name: 'Health_Disconnected', desc: 'Health_Disconnected', type: 'number', unit: '', min: '0', max: '100', role: '',read: true, write: true }); }
if (apInfo) {
for(let ap_name in apName) {
createState(dpPrefix + "WLANUnifi.APInfo."+ apName[ap_name].aname, {name: apName[ap_name].aname,role: 'state',read: true,write: true,type: "string" } );
createState(dpPrefix + "WLANUnifi.APInfo."+ apName[ap_name].aname+".Model", {name: "Model",role: 'state',read: true,write: true,type: "string" } );
createState(dpPrefix + "WLANUnifi.APInfo."+ apName[ap_name].aname+".IP_Adresse", {name:"IP_Adresse",role: 'state',read: true,write: true,type: "string" } );
createState(dpPrefix + "WLANUnifi.APInfo."+ apName[ap_name].aname+".Satisfaction", {name:"Satisfaction",role: 'state',read: true,write: true,type: "number" } );
createState(dpPrefix + "WLANUnifi.APInfo."+ apName[ap_name].aname+".LoadAVG1", {name:"Durchschnitt Wartezeit pro Min",role: 'state',read: true,write: true, type: "number" } );
createState(dpPrefix + "WLANUnifi.APInfo."+ apName[ap_name].aname+".LoadAVG5", {name:"Durchschnitt Wartezeit pro 5Min",role: 'state',read: true,write: true, type: "number" } );
createState(dpPrefix + "WLANUnifi.APInfo."+ apName[ap_name].aname+".LoadAVG15", {name:"Durchschnitt Wartezeit pro 15Min",role: 'state',read: true,write: true, type: "number" } );
createState(dpPrefix + "WLANUnifi.APInfo."+ apName[ap_name].aname+".Adopted", {name:"Adopted",role: 'state',read: true,write: true,type: "boolean" } );
createState(dpPrefix + "WLANUnifi.APInfo."+ apName[ap_name].aname+".ToController", {name:"ToController",role: 'state',read: true,write: true,type: "string" } );
createState(dpPrefix + "WLANUnifi.APInfo."+ apName[ap_name].aname+".State", {name:"State",role: 'state',read: true,write: true,type: "boolean" } );}
createState(dpPrefix + "WLANUnifi.APInfo.SpeedTest.Xput-Download", "not available", {name:"SpeedTest_Xput_Download",role: 'state',read: true,write: true,type: "string" } );
createState(dpPrefix + "WLANUnifi.APInfo.SpeedTest.Xput-Upload", "not available", {name:"SpeedTest_Xput_Upload",role: 'state',read: true,write: true,type: "string" } );
createState(dpPrefix + "WLANUnifi.APInfo.SpeedTest.RunTime", "not available", {name:"SpeedTest_RunTime",role: 'state',read: true,write: true,type: "string" } );
createState(dpPrefix + "WLANUnifi.APInfo.SpeedTest.RunTimeDate", "not available", {name:"SpeedTest_RunTimeDate",role: 'state',read: true,write: true,type: "string" } );
createState(dpPrefix + "WLANUnifi.APInfo.SpeedTest.RunTimeOrginal", "not available", {name:"SpeedTest_RunTimeOrginal",role: 'state',read: true,write: true,type: "string" } );
createState(dpPrefix + "WLANUnifi.APInfo.SpeedTest.Latency", "not available", {name:"SpeedTest_Latency",role: 'state',read: true,write: true,type: "number" } );
createState(dpPrefix + "WLANUnifi.WWW-OnlineTest.Internet_Verbindung", false, {name:"Internet_Verbindung",role: 'state',read: true,write: true,type: "boolean" } );
}
if (apInfo) {
createState(dpPrefix + "WLANUnifiHelp.WAN1TransferDaily.Uplink_RX", 0, {name:"Uplink_RX",role: 'state',unit: "GB", read: true,write: true, type: "number" } );
createState(dpPrefix + "WLANUnifiHelp.WAN1TransferDaily.Uplink_TX", 0, {name:"Uplink_TX",role: 'state',unit: "GB", read: true,write: true, type: "number" } );
}
if(anwesenheit) createState(dpPrefix + "WLANUnifiHelp.Others.WLANClientDP",[] ,{name: "WLANClientDP",role: 'state',read: true,write: true,type: "array" } );
function dlog(message) {
if(debug)
console.log(message);
}
function mylog(message) {
if(mylogs)
console.log(message);
}
function syslog(message) {
if(syslogs)
log(message,"error");
}
//-----------------------------------------LOGIN---------------------------------------------------------------
async function login() {
return new Promise(async (resolve, reject) => {
cookies=[];
let respl = await request.post({
resolveWithFullResponse: true,
url: unifi_controller + "/api/login",
body: JSON.stringify({ username: unifi_username, password: unifi_password }),
headers: { 'Content-Type': 'application/json' }
}).catch((e) => { log("login: reject"), reject(e); loggedIn =false;return respl=[];});
if(respl != null) {
mylog("login: login war erfolgreich! " + ((respl.headers && respl.headers.hasOwnProperty("set-cookie")) ? "Mit Cookies":"Ohne Cookies"));
if(respl.headers && respl.headers.hasOwnProperty("set-cookie")) {
let set_cookies = respl.headers["set-cookie"];
for(i = 0; i < set_cookies.length; i++) {
let cookie = set_cookies[i];
//log(set_cookies[i]);
cookie = cookie.split(";")[0];
cookies.push(cookie);
}
} else {
log("login: no cookies to set!")
}
loggedIn = true;
resolve();
} else {
log("login: rejected")
loggedIn = false;
reject("respl = null");
}
});
}
//-----------------------------------------LOGOUT---------------------------------------------------------------
async function logout() {
log("BIN IN LOGOUT");
return new Promise(async (resolve, reject) => {
let respo = await request.get({
url: unifi_controller + "/logout",
headers: { Cookie: cookies.join("; ") }
}).catch((e) => { log("logout fehler" + e)/*reject(e)*/ ;return testerrl=true;} );
if (!testerrl) {
if(respo != null) {
log("Du bist nun ausgedloggt.");
dlog(respo);
log("BIN raus aus LOGOUT");
loggedIn = true;
resolve();
} else {
reject("resp = null");
}
} else {log("reject weil resplogin ist 00"); log("BIN raus aus LOGOUT"); reject();}
log("BIN raus aus LOGOUT");
});
}
//-----------------------------------------STATUS WIFI ---------------------------------------------------------
//Updatet status vom Wifi
//wifi: wifi object aus der konstanten wifis
function getStatus(wifi) {
mylog("BIN IN STATUS");
return new Promise(async (resolve, reject) => {
dlog("nur mal so");
if (!loggedIn) await login().catch((e) => reject(e));
let resp = await request.get({
url: unifi_controller + "/api/s/"+siteName+"/rest/wlanconf/" + wifi.id,
headers: { Cookie: cookies.join("; ") }
}).catch((e) => { dlog("getStatus reject " + e); /*reject(e)*/ return testerrs=true; });
if (!testerrs) {
dlog("got response " + JSON.stringify(resp));
resp = JSON.parse(resp);
let wlanOn = resp.data[0].enabled;
dlog("WLAN " + wifi.name + " ist: " + (wlanOn ? "an" : "aus"));
if (resp != null && resp.meta && resp.meta.rc == "ok") {
dlog("Status erfolgreich geholt!");
dlog(resp);
let wlanOn = resp.data[0].enabled;
dlog("WLAN ist: " + (wlanOn ? "an" : "aus"));
setStateDelayed(dpPrefix + "WLANUnifi." + wifi.name, wlanOn, 200);
resolve(wlanOn);
} else {
log("nicht ok... getStatusWifi")
reject(JSON.stringify(resp));
}
} else {mylog("reject weil respslogin ist 00"); mylog("BIN raus aus LOGOUT"); reject();}
mylog("BIN aus STATUS raus");
});
}
//-----------------------------------------GETCLIENTS---------------------------------------------------------------
async function getClients() {
mylog("BIN IN getclients");
return new Promise(async (resolve, reject) => {
dlog("getclient nur mal so" + loggedIn);
if(!loggedIn) await login().catch((e) => reject(e));
respc = await request.get({
url: unifi_controller + "/api/s/"+siteName+"/stat/sta",
headers: { Cookie: cookies.join("; ") }
}).catch((e) => { log("getStatus reject " + e); /*reject(e)*/ return testerrc=true; });
if (!testerrc) {
dlog("got respconse nach log in getclient " + JSON.stringify(respc));
dlog(typeof respc);
dlog("--------------------- " + respc);
//respc = JSON.stringify(testemal2);
//Sortierung Daten und Verwandlung Json
var unfiltered = [];
unfiltered = JSON.parse(respc).data;
dlog("bin da");
dlog(unfiltered[5][myname] + unfiltered[2].mac);
versuch = [];
let trash="";
//let county=0
//log("status 1");
for (var blackie in blackList){ //BLACKLIST aussortiert aber nur mit existierenden alias
for(var index in unfiltered) {
if (unfiltered[index].hasOwnProperty("name")){
if ( unfiltered[index].name.indexOf(blackList[blackie]) == -1 ) {
// log("anfang : "+ unfiltered[index].name.indexOf(blackList[blackie]) + " name : " + unfiltered[index].name);
}else { dlog( "Raus ist: " +unfiltered[index].name);
unfiltered.splice(index,1) } }}}
//log("status 2");
for(var index in unfiltered) {
let device = unfiltered[index];
mylog(device)
let switchHelper3=0;
mylog(unfiltered[index].hasOwnProperty(myname)+"-----IP---:"+unfiltered[index].ip+"---name---:"+unfiltered[index].hostname+"----alias---:"+unfiltered[index].name);
mylog(unfiltered[index].ip)
let fehlerName=false;
if (!unfiltered[index].hasOwnProperty("ip") || unfiltered[index].ip == undefined ||unfiltered[index].ip == null || unfiltered[index].ip == "undefined") {switchHelper3=3;mylog("_____________________fehler")}
else{
if (unfiltered[index].hasOwnProperty(myname) && device[myname] !== undefined && device[myname] !== null && device[myname] !== "") {switchHelper3=2;} else {fehlerName=true;}
if (unfiltered[index].hasOwnProperty("name") && device.name !== undefined && device.name !== null && device.name !== "") {switchHelper3=1;}} //Alias hat vorrang
// log("status 3 case : "+switchHelper3);
switch (switchHelper3) {
case 0: // kein hostname und kein alias
device[myname]=unfiltered[index].ip.replace(/\./g,"-")+"--repaired";
unfiltered[index].essid="MISSING ALIAS"
versuch.push(device);
trash = trash+"
"+unfiltered[index].ip.replace(".","-")+"-missing: client alias in controller |
";
mylog("ein fehler: -----------------"+device[myname])
break;
case 1: // kein hostname
device[myname]=unfiltered[index].name;
if (device[myname].indexOf(".")>-1) { device[myname]=device[myname].replace(/\./g, "-");trash = trash+""+device[myname]+" - hat Punkt im Alias !!! |
";unfiltered[index].essid="PKT IM ALIAS"} else{dlog(device[myname])}
versuch.push(device);
mylog("hat nur alias: -----------------"+device[myname])
if ( fehlerName) trash = trash+""+unfiltered[index].ip.replace(".","-")+"-missing: hostname |
";
break;
case 2: // alles in ordnung mit client
// if (device[myname].indexOf(".")>-1) { device[myname]=device[myname].replace(/\./g, "-")+"---change-alias";trash = trash+device[myname]+" hat Punkt im Namen !!!"} else{dlog(device[myname])}
versuch.push(device);
mylog("ein richtiger: -----------------"+device[myname])
break;
case 3: //IP FEHLT - DANGER
//versuch.push(device);
//log("IP Adresse fehlt (Unifi Client): -----------------"+device[myname],"warn");
if (unfiltered[index].hasOwnProperty("name")) {
if(unfiltered[index].name ==""){
unfiltered[index].ip="IP Adresse fehlt-"+index+"";
unfiltered[index].hostname=unfiltered[index].mac
versuch.push(device);
trash = trash+""+unfiltered[index].mac + " -- IP Adresse fehlt"+" |
";
}
else{
unfiltered[index].ip="IP Adresse fehlt-"+index+"";
unfiltered[index].hostname=unfiltered[index].name;
versuch.push(device);
trash = trash+""+unfiltered[index].name + " -- IP Adresse fehlt"+" |
";} }
else {
//trash = trash+""+unfiltered[index].hostname + " IP Adresse fehlt"+" |
"
unfiltered[index].ip="IP Adresse fehlt-"+index+"";
unfiltered[index].hostname="Alias_fehlt-"+index;
versuch.push(device);
trash = trash+"Name-Alias und IP Adresse fehlt"+" |
"}
break;
}
device[myname]=device[myname].replace(/\s/g,"_")
}
//log("status 4");
mylog("trash -------------"+trash);
setState(dpPrefix + "WLANUnifi.Missing_Name", "");
if (!sortedByIP) {versuch.sort(function (alpha, beta) {
if (alpha[myname].toLowerCase() < beta[myname].toLowerCase())
return -1;
if (alpha[myname].toLowerCase() > beta[myname].toLowerCase())
return 1;
return 0;
});}
else {
versuch.sort(function (alpha, beta) {
if (alpha.ip.toLowerCase() < beta.ip.toLowerCase())
return -1;
if (alpha.ip.toLowerCase() > beta.ip.toLowerCase())
return 1;
return 0;
});}
//log("status 5");
resolve();
} else {log("reject weil respc 00"); reject() } mylog("bin raus aus getclients");
}); //new promise
} //getclientend
//-----------------------------------------workCLIENTS---------------------------------------------------------------
function workClients() {
mylog("BIN IN workclients");
dlog("got respconse versuch " + JSON.stringify(versuch));
dlog(typeof respc);
dlog("--------------------- " + respc);
//let writeFile = true;
let writeFileVar = 0;
let fileeWriteHelper=false;
let writeClientTable = true;
let writeAnwesenheit = true;
var fileeWriteHelperOld;
var anzahlClients = versuch.length;
//setStateDelayed(dpPrefix + "WLANUnifi.Wifi_Clients_Anzahl",anzahlClients,100);
// überprüfe ob aliasname einen punkt enthält !!! ist in getclient !!!!
/*if(aliasname) {for (var i = 0; i < versuch.length; i++) {
if (versuch[i][myname].indexOf(".")>-1) { versuch[i][myname]=versuch[i][myname].replace(/\./g, "-")+"---change-alias";log(versuch[i][myname])} else{dlog(versuch[i][myname])}
}}*/
//var clientListe = "";
var clientListeArray=[];
var clientListeArrayWLAN=[];
var clientListeArrayLAN=[];
var clientListeArrayDISC=[];
var wlanClientDB=[];
wlanClientDB= getState(dpPrefix + "WLANUnifiHelp.Others.WLANClientDP").val;
getExistingClients();
//für zugehörigkeit netzwerk
for (var z = 0; z < listeDatenpunkte.length; z++) {
for (var checkyConn in checkConnType ) {
if( checkConnType[checkyConn]==listeDatenpunkte[z] ) {dlog(listeDatenpunkte[z]+checkConnType[checkyConn]);
checkNetwork=true;
createState(dpPrefix + "WLANUnifi.Wifi_Client_Network."+listeDatenpunkte[z], { name: checkConnType[checkyConn]+'_Netwok', type: 'string', role: '',read: true, write: true }); }}}
mylog("Status1");
var listeDatenpunkteNew=[]; //erstelle aktuelles array von controller daten
for (var i = 0; i < versuch.length; i++) {
// hier name des zu überwachenden clients
listeDatenpunkteNew[i] = versuch[i][myname];
if(syslogs && listeDatenpunkteNew[i]==xxClientxx) {xxClientxxIndex=i;syslog("__client hat Indexnummer: "+ i + " Gesamtanzahl Cliens: "+listeDatenpunkteNew.length.toString());}
if( versuch[i].hasOwnProperty("_last_seen_by_uap") && !wlanClientDB.includes(versuch[i][myname])) { dlog("write"+versuch[i][myname]); wlanClientDB.push(versuch[i][myname]); }
}
dlog(wlanClientDB.toString());
setStateDelayed(dpPrefix + "WLANUnifiHelp.Others.WLANClientDP", wlanClientDB,800);
dlog (listeDatenpunkteNew[22]);
//syslog("___Anzahl Clients: "+listeDatenpunkteNew.length.toString());
dlog(getState(dpPrefix + "WLANUnifiHelp.Others.WLANClientDP").val);
if (true) {
// sind clients von controller in verzeichnisliste ?
for (var z = 0; z < listeDatenpunkteNew.length; z++) {
if ( listeDatenpunkte.indexOf(listeDatenpunkteNew[z]) == -1 ){ //ist controller-client existent nicht in verzeichnis-list
mylog("Datenpunktanlegen" + listeDatenpunkteNew[z] +"index:"+ listeDatenpunkte.indexOf(listeDatenpunkteNew[z]).toString());
var ipWandler= versuch[z].ip;
var data = dpPrefix + "WLANUnifi.Wifi_Client_States."+listeDatenpunkteNew[z];
createState(data, true, {name: ipWandler, role: 'boolean',read: true, write: true, }, function() {mylog("created"); });
//setState(dpPrefix + "WLANUnifi.Wifi_Client_States."+ versuch[z][myname], true);
fileeWriteHelper=true;
mylog("Datenpunktanlegen fertig" + listeDatenpunkteNew[z] + listeDatenpunkte[z]) ;
}
}
mylog("Status2");
}
//sind datenpunkte noch in controller vorhanden
if (anwesenheit) {
dlog("checknetwork: "+checkNetwork.toString());
notSeen=[];
countFalse++; mylog("------------countFalse: "+countFalse.toString());
for (var z = 0; z < listeDatenpunkte.length; z++) {
if ( listeDatenpunkteNew.indexOf(listeDatenpunkte[z]) == -1 ){ //ist datenpunkt-verzeihnis existent und nicht in controller liste
notSeen.push(listeDatenpunkte[z]); mylog(listeDatenpunkte[z]); //array der notSeen datenpunkte sind nicht im controller
if(!problemWLAN && countFalse==countFalseSetting ) {
if (getState(dpPrefix + "WLANUnifi.Wifi_Client_States."+listeDatenpunkte[z]).val) { // setze datenpunkt auf false - nur wenn true war
//log("bin davor1"+listeDatenpunkte[z])
setStateDelayed(dpPrefix + "WLANUnifi.Wifi_Client_States."+listeDatenpunkte[z], false, 200);
// if (checkNetwork){ for (var checkyConn in checkConnType ) { if( checkConnType[checkyConn]==versuch[z][myname] ) setState(dpPrefix + "WLANUnifi.Wifi_Client_Network."+versuch[z][myname],"noConn"); }}
if (checkNetwork){ log("bin in check");for (var checkyConn in checkConnType ) { if( checkConnType[checkyConn]==listeDatenpunkte[z] ) {setState(dpPrefix + "WLANUnifi.Wifi_Client_Network."+listeDatenpunkte[z],"noConn");log("setzte Datenpunkt auf false");} }}
fileeWriteHelper=true;
countFalse=0;
if(syslogs && listeDatenpunkte[z]==xxClientxx){syslog("_______________________________________Datenpunkt ist falsch zu setzen (normalWLAN) - da nicht mehr in Daten "+listeDatenpunkte[z]);}
// syslog("Datenpunkt ist falsch zu setzen - da nicht mehr in Daten "+listeDatenpunkte[z]);
} //else{ if (checkNetwork){ for (var checkyConn in checkConnType ) {
//if( checkConnType[checkyConn]==listeDatenpunkte[z] ) {setState(dpPrefix + "WLANUnifi.Wifi_Client_Network."+listeDatenpunkte[z],"noConn");dlog("setzte Datenpunkt auf false");} }}}
}//}
if(problemWLAN && countFalse==countFalseSetting+1 ) {
if (getState(dpPrefix + "WLANUnifi.Wifi_Client_States."+listeDatenpunkte[z]).val) { // setze datenpunkt auf false - nur wenn true war
mylog("bin davor2" +listeDatenpunkte[z])
setStateDelayed(dpPrefix + "WLANUnifi.Wifi_Client_States."+listeDatenpunkte[z], false, 200);
if (checkNetwork){ for (var checkyConn in checkConnType ) { if( checkConnType[checkyConn]==listeDatenpunkte[z] ) {setState(dpPrefix + "WLANUnifi.Wifi_Client_Network."+listeDatenpunkte[z],"noConn");dlog("setzte Datenpunkt auf false");} }}
fileeWriteHelper=true;
countFalse=0;
// syslog("Datenpunkt ist falsch zu setzen - da nicht mehr in daten"+listeDatenpunkte[z]);
if(syslogs && listeDatenpunkte[z]==xxClientxx){syslog("_______________________________________Datenpunkt ist falsch zu setzen (problemWLAN) - da nicht mehr in daten "+listeDatenpunkte[z]);}
} //else{ if (checkNetwork){ for (var checkyConn in checkConnType ) {
//if( checkConnType[checkyConn]==listeDatenpunkte[z] ) {setState(dpPrefix + "WLANUnifi.Wifi_Client_Network."+listeDatenpunkte[z],"noConn");dlog("setzte Datenpunkt auf false");} }} }
} //}
//} else {dlog("ist noch im controller" + listeDatenpunkte[z]); }
//if (checkNetwork){ for (var checkyConn in checkConnType ) { if( checkConnType[checkyConn]==listeDatenpunkte[z] ) {setState(dpPrefix + "WLANUnifi.Wifi_Client_Network."+listeDatenpunkte[z],"noConn");dlog("setzte Datenpunkt auf false");} }}
} //ende if DP nicht in neuer liste
} //for liste datenpunkt ende
} //anwesenheit ende
if (!problemWLAN && countFalse==countFalseSetting ) countFalse=0;
if (problemWLAN && countFalse==countFalseSetting+1 ) countFalse=0;
notseenLengthOld=notseenLength; // ist für writefile wenn datenpunkte schon falsch sind
notseenLength=notSeen.length;
if (notseenLength!=notseenLengthOld) fileeWriteHelper=true;
//sind datenpunkte nicht in controller vorhanden
mylog("Status3");
// setze datenpunkte nach last_seen_by_uap - ausnahme: controller-clients sind nicht mehr connectet aber in vereichnis
let lastChangeList;
if (anwesenheit) {
var timeout = setTimeout(function () { //wegen createstate und zu schnelles setstate
let caseHelper=0;
for (var z = 0; z < listeDatenpunkteNew.length; z++) {
if(versuch[z].hasOwnProperty("last_seen")) caseHelper=1;
// if(versuch[z].hasOwnProperty("_last_seen_by_ugw") && versuch[z].hasOwnProperty("gw_mac") ) caseHelper=2;
if(versuch[z].hasOwnProperty("_last_seen_by_usw") && versuch[z].hasOwnProperty("sw_mac") ) caseHelper=3;
if(versuch[z].hasOwnProperty("_last_seen_by_uap") && versuch[z].hasOwnProperty("ap_mac") ) caseHelper=4;
if(!versuch[z].hasOwnProperty("_last_seen_by_uap") && wlanClientDB.includes(versuch[z][myname])) caseHelper=5;
if (listeDatenpunkteNew[z]==xxClientxx && syslogs) syslog("____Client hat Case : "+caseHelper); //Fehlersuche
let tester;
//log(caseHelper.toString());
switch (caseHelper) {
case 1: /*________________________------------------------------------_____CASE1*/
dlog(caseHelper.toString());
tester = parseInt((new Date().getTime())) - (versuch[z].last_seen*1000);
dlog(tester.toString() + "laenge : " +listeDatenpunkteNew.length);
if (parseInt((new Date().getTime())) - (versuch[z].last_seen*1000) > abfragezyklus+abfageoffset && getState(dpPrefix + "WLANUnifi.Wifi_Client_States."+versuch[z][myname]).val) {
setStateDelayed(dpPrefix + "WLANUnifi.Wifi_Client_States."+versuch[z][myname], false, 100); fileeWriteHelper=true;
mylog("abgesetzt: " +listeDatenpunkteNew[z] + " um " +formatDate(getDateObject((parseFloat((new Date().getTime())) - tester)), "SS:mm:ss") + " Uhr");
if(syslogs && listeDatenpunkteNew[z]==xxClientxx){syslog("_______________________________________Datenpunkt false über lastSeen - zeit: "+tester);}
mylog(tester.toString());
if (lastChange.length>=10) lastChange.shift()
lastChange.push(""+listeDatenpunkteNew[z]+" | "+formatDate(getDateObject((parseFloat((new Date().getTime())) - tester)), "SS:mm:ss")+" | out | vor: "+tester/1000+" Sek |
");
mylog(lastChange[0]);
}
if (!wlanClientDB.includes(versuch[z][myname])) {
if (parseFloat((new Date().getTime())) - (versuch[z].last_seen*1000) < abfragezyklus && !getState(dpPrefix + "WLANUnifi.Wifi_Client_States."+versuch[z][myname]).val || getState(dpPrefix + "WLANUnifi.Wifi_Client_States."+versuch[z][myname]).val ==null ) {
setStateDelayed(dpPrefix + "WLANUnifi.Wifi_Client_States."+versuch[z][myname], true, 100);fileeWriteHelper=true;
if(syslogs && listeDatenpunkteNew[z]==xxClientxx){syslog("_______________________________________Datenpunkt true über lastSeen - zeit: "+tester);}
mylog("gesetzt" +listeDatenpunkteNew[z]+" " +formatDate(getDateObject((parseFloat((new Date().getTime())) - tester)), "SS:mm:ss") + " Uhr");
if (lastChange.length>=10) lastChange.shift()
lastChange.push(""+listeDatenpunkteNew[z]+" | "+formatDate(getDateObject((parseFloat((new Date().getTime())) - tester)), "SS:mm:ss")+" | in | vor: " + tester/1000+" Sek |
");
}}
break; /*________________________------------------------------------_____CASE1*/
case 2: /*________________________------------------------------------_____CASE2*/
dlog(caseHelper.toString());
tester = parseInt((new Date().getTime())) - (versuch[z]._last_seen_by_ugw*1000);
dlog(tester.toString() + "laenge : " +listeDatenpunkteNew.length);
if (parseInt((new Date().getTime())) - (versuch[z]._last_seen_by_ugw*1000) > abfragezyklus+abfageoffset && getState(dpPrefix + "WLANUnifi.Wifi_Client_States."+versuch[z][myname]).val) {
setStateDelayed(dpPrefix + "WLANUnifi.Wifi_Client_States."+versuch[z][myname], false, 100);fileeWriteHelper=true;
if(syslogs && listeDatenpunkteNew[z]==xxClientxx){syslog("_______________________________________Datenpunkt false über lastSeen ugw - zeit: "+tester);}
mylog("abgesetzt: " +listeDatenpunkteNew[z] + " um " +formatDate(getDateObject((parseFloat((new Date().getTime())) - tester)), "SS:mm:ss") + " Uhr");
mylog(tester.toString());
if (lastChange.length>=10) lastChange.shift()
lastChange.push(""+listeDatenpunkteNew[z]+" | "+formatDate(getDateObject((parseFloat((new Date().getTime())) - tester)), "SS:mm:ss")+" | out | vor: "+tester/1000+" Sek |
");
mylog(lastChange[0]);
}
if (!wlanClientDB.includes(versuch[z][myname])) { // log("---------------------"+versuch[z][myname]+" datenbank :" +wlanClientDB);
if (parseFloat((new Date().getTime())) - (versuch[z]._last_seen_by_ugw*1000) < abfragezyklus && !getState(dpPrefix + "WLANUnifi.Wifi_Client_States."+versuch[z][myname]).val || getState(dpPrefix + "WLANUnifi.Wifi_Client_States."+versuch[z][myname]).val ==null ) {
setStateDelayed(dpPrefix + "WLANUnifi.Wifi_Client_States."+versuch[z][myname], true, 100);fileeWriteHelper=true;
if(syslogs && listeDatenpunkteNew[z]==xxClientxx){syslog("_______________________________________Datenpunkt true über lastSeen ugw - zeit: "+tester);}
mylog("gesetzt" +listeDatenpunkteNew[z]+" " +formatDate(getDateObject((parseFloat((new Date().getTime())) - tester)), "SS:mm:ss") + " Uhr");
if (lastChange.length>=10) lastChange.shift()
lastChange.push(""+listeDatenpunkteNew[z]+" | "+formatDate(getDateObject((parseFloat((new Date().getTime())) - tester)), "SS:mm:ss")+" | in | vor: " + tester/1000+" Sek |
");
}}
break; /*________________________------------------------------------_____CASE2*/
case 3: /*________________________------------------------------------_____CASE3*/
dlog(caseHelper.toString());
tester = parseInt((new Date().getTime())) - (versuch[z]._last_seen_by_usw*1000);
dlog(tester.toString() + "laenge : " +listeDatenpunkteNew.length);
if (parseInt((new Date().getTime())) - (versuch[z]._last_seen_by_usw*1000) > abfragezyklus+abfageoffset && getState(dpPrefix + "WLANUnifi.Wifi_Client_States."+versuch[z][myname]).val) {
setStateDelayed(dpPrefix + "WLANUnifi.Wifi_Client_States."+versuch[z][myname], false, 100);fileeWriteHelper=true;
if(syslogs && listeDatenpunkteNew[z]==xxClientxx){syslog("_______________________________________Datenpunkt false über lastSeen usw - zeit: "+tester);}
mylog("abgesetzt: " +listeDatenpunkteNew[z] + " um " +formatDate(getDateObject((parseFloat((new Date().getTime())) - tester)), "SS:mm:ss") + " Uhr");
mylog(tester.toString());
if (lastChange.length>=10) lastChange.shift()
lastChange.push(""+listeDatenpunkteNew[z]+" | "+formatDate(getDateObject((parseFloat((new Date().getTime())) - tester)), "SS:mm:ss")+" | out | vor: "+tester/1000+" Sek |
");
mylog(lastChange[0]);
}
if (!wlanClientDB.includes(versuch[z][myname])) {
if (parseFloat((new Date().getTime())) - (versuch[z]._last_seen_by_usw*1000) < abfragezyklus && !getState(dpPrefix + "WLANUnifi.Wifi_Client_States."+versuch[z][myname]).val || getState(dpPrefix + "WLANUnifi.Wifi_Client_States."+versuch[z][myname]).val ==null ) {
setStateDelayed(dpPrefix + "WLANUnifi.Wifi_Client_States."+versuch[z][myname], true, 100);fileeWriteHelper=true;
if(syslogs && listeDatenpunkteNew[z]==xxClientxx){syslog("_______________________________________Datenpunkt true über lastSeen usw - zeit: "+tester);}
mylog("gesetzt" +listeDatenpunkteNew[z]+" " +formatDate(getDateObject((parseFloat((new Date().getTime())) - tester)), "SS:mm:ss") + " Uhr");
if (lastChange.length>=10) lastChange.shift()
lastChange.push(""+listeDatenpunkteNew[z]+" | "+formatDate(getDateObject((parseFloat((new Date().getTime())) - tester)), "SS:mm:ss")+" | in | vor: " + tester/1000+" Sek |
");
}}
break;/*________________________------------------------------------_____CASE3*/
case 4: /*________________________------------------------------------_____CASE4*/
dlog(caseHelper.toString());
tester = parseInt((new Date().getTime())) - (versuch[z]._last_seen_by_uap*1000);
if(listeDatenpunkteNew[z]==xxClientxx && syslogs){syslog("___________________________LAST_SEEN-BY_UAP: "+versuch[z]._last_seen_by_uap+" Time: "+formatDate(getDateObject(parseFloat(versuch[z]._last_seen_by_uap)*1000), "SS:mm:ss")+ " Jetzt: "+formatDate(getDateObject((parseFloat(new Date().getTime()))), "SS:mm:ss"));}
dlog(tester.toString() + "laenge : " +listeDatenpunkteNew.length);
if (parseInt((new Date().getTime())) - (versuch[z]._last_seen_by_uap*1000) > abfragezyklus+abfageoffset && getState(dpPrefix + "WLANUnifi.Wifi_Client_States."+versuch[z][myname]).val) {
setStateDelayed(dpPrefix + "WLANUnifi.Wifi_Client_States."+versuch[z][myname], false, 100);fileeWriteHelper=true;
// if (checkNetwork){ for (var checkyConn in checkConnType ) { if( checkConnType[checkyConn]==versuch[i][myname] ) setState(dpPrefix + "WLANUnifi.Wifi_Client_Network."+versuch[i][myname],"noConn"); }}
if(syslogs && listeDatenpunkteNew[z]==xxClientxx){syslog("_______________________________________Datenpunkt false über lastSeen uap - zeit: "+tester);}
mylog("abgesetzt: " +listeDatenpunkteNew[z] + " um " +formatDate(getDateObject((parseFloat((new Date().getTime())) - tester)), "SS:mm:ss") + " Uhr");
mylog(tester.toString());
if (lastChange.length>=10) lastChange.shift()
lastChange.push(""+listeDatenpunkteNew[z]+" | "+formatDate(getDateObject((parseFloat((new Date().getTime())) - tester)), "SS:mm:ss")+" | out | vor: "+tester/1000+" Sek |
");
mylog(lastChange[0]);
}
if (parseFloat((new Date().getTime())) - (versuch[z]._last_seen_by_uap*1000) < abfragezyklus && !getState(dpPrefix + "WLANUnifi.Wifi_Client_States."+versuch[z][myname]).val || getState(dpPrefix + "WLANUnifi.Wifi_Client_States."+versuch[z][myname]).val ==null ) {
setStateDelayed(dpPrefix + "WLANUnifi.Wifi_Client_States."+versuch[z][myname], true, 100);fileeWriteHelper=true;
if(syslogs && listeDatenpunkteNew[z]==xxClientxx){syslog("_______________________________________Datenpunkt true über lastSeen uap - zeit: "+tester);}
mylog("gesetzt" +listeDatenpunkteNew[z]+" " +formatDate(getDateObject((parseFloat((new Date().getTime())) - tester)), "SS:mm:ss") + " Uhr");
if (lastChange.length>=10) lastChange.shift()
lastChange.push(""+listeDatenpunkteNew[z]+" | "+formatDate(getDateObject((parseFloat((new Date().getTime())) - tester)), "SS:mm:ss")+" | in | vor: " + tester/1000+" Sek |
");
}
break; /*________________________------------------------------------_____CASE4*/
case 5: //Sonderfall unifi bug
if(getState(dpPrefix + "WLANUnifi.Wifi_Client_States."+versuch[z][myname]).val) {
setStateDelayed(dpPrefix + "WLANUnifi.Wifi_Client_States."+versuch[z][myname], false, 100);fileeWriteHelper=true;
if(syslogs && listeDatenpunkteNew[z]==xxClientxx){syslog("_______________________________________Datenpunkt false über sonderfall case 5 - zeit: ");}
//mylog("abgesetzt: " +listeDatenpunkteNew[z] + " um " +formatDate(getDateObject((parseFloat((new Date().getTime())) - tester)), "SS:mm:ss") + " Uhr");
if (lastChange.length>=10) lastChange.shift()
lastChange.push(""+listeDatenpunkteNew[z]+" | "+"Sonderfall"+" | out | vor: "+"UnifiBug"+" Sek |
");
mylog(lastChange[0]);
}
break;
} //case
}
mylog("Status4");
// erstelle htmlclientliste
for (var i = 0; i < versuch.length; i++) {
if(versuch[i].hasOwnProperty("last_seen")) caseHelper=1;
// if(versuch[i].hasOwnProperty("_last_seen_by_ugw") && versuch[i].hasOwnProperty("gw_mac") ) caseHelper=2;
if(versuch[i].hasOwnProperty("_last_seen_by_usw") && versuch[i].hasOwnProperty("sw_mac") ) caseHelper=3;
if(versuch[i].hasOwnProperty("_last_seen_by_uap") && versuch[i].hasOwnProperty("ap_mac") ) caseHelper=4;
if(!versuch[i].hasOwnProperty("_last_seen_by_uap") && wlanClientDB.includes(versuch[i][myname])) caseHelper=5;
//log(caseHelper.toString());
if (versuch[i][myname]==xxClientxx && syslogs) syslog("__________________________Client hat Case bei listen-schreiben: "+caseHelper); //Fehlersuche
switch (caseHelper) {
case 1:
if (checkNetwork && anwesenheit){ for (var checkyConn in checkConnType ) { if( checkConnType[checkyConn]==versuch[i][myname] ) //prüfung network connection
{dlog(versuch[i]+checkConnType[checkyConn]);setState(dpPrefix + "WLANUnifi.Wifi_Client_Network."+versuch[i][myname],"noConn");}}}
if (parseInt((new Date().getTime())) - (versuch[i].last_seen*1000) < abfragezyklus+abfageoffset) {
for(let device_name in apName) { //Abfrage welcher AP
dlog(versuch[i].ap_mac +" - " + device_name +" - " + apName[device_name].aname);
if (versuch[i].sw_mac==device_name) var apTransfer = apName[device_name].aname};
if (versuch[i][myname]==xxClientxx && syslogs) syslog("______________________________Client ist angemeldet : "+apTransfer +" mit: " + versuch[i].sw_mac); //Fehlersuche
if (checkNetwork && anwesenheit){ for (var checkyConn in checkConnType ) { if( checkConnType[checkyConn]==versuch[i][myname] && !wlanClientDB.includes(versuch[i][myname]) )
{dlog(versuch[i]+checkConnType[checkyConn]);setState(dpPrefix + "WLANUnifi.Wifi_Client_Network."+versuch[i][myname],apTransfer);}}}
// clientListe = clientListe.concat(""+versuch[i][myname]+" | LAN | "+versuch[i].ip+" | "+apTransfer+" |
");
clientListeArray.push(""+versuch[i][myname]+" | LAN | "+versuch[i].ip+" | "+apTransfer+" |
");
clientListeArrayLAN.push(""+versuch[i][myname]+" | LAN | "+versuch[i].ip+" | "+apTransfer+" |
");
;}
else {anzahlClients=anzahlClients-1; //clientListe = clientListe.concat(""+versuch[i][myname]+" | LAN | "+versuch[i].ip+" | noConn |
");
// if (checkNetwork && anwesenheit){ for (var checkyConn in checkConnType ) { if( checkConnType[checkyConn]==versuch[i][myname] ) //prüfung network connection
// {dlog(versuch[i]+checkConnType[checkyConn]);setState(dpPrefix + "WLANUnifi.Wifi_Client_Network."+versuch[i][myname],"noConn");}}}
clientListeArray.push(""+versuch[i][myname]+" | LAN | "+versuch[i].ip+" | noConn |
");
clientListeArrayLAN.push(""+versuch[i][myname]+" | LAN | "+versuch[i].ip+" | noConn |
");}
break;
case 2:
if (checkNetwork && anwesenheit){ for (var checkyConn in checkConnType ) { if( checkConnType[checkyConn]==versuch[i][myname] ) //prüfung network connection
{dlog(versuch[i]+checkConnType[checkyConn]);setState(dpPrefix + "WLANUnifi.Wifi_Client_Network."+versuch[i][myname],"noConn");}}}
if (parseInt((new Date().getTime())) - (versuch[i]._last_seen_by_ugw*1000) < abfragezyklus+abfageoffset) {
for(let device_name in apName) { //Abfrage welcher AP
dlog(versuch[i].ap_mac +" - " + device_name +" - " + apName[device_name].aname);
if (versuch[i].gw_mac==device_name) var apTransfer = apName[device_name].aname};
if (versuch[i][myname]==xxClientxx && syslogs) syslog("______________________________Client ist angemeldet : "+apTransfer +" mit: " + versuch[i].gw_mac); //Fehlersuche
// clientListe = clientListe.concat(""+versuch[i][myname]+" | LAN | "+versuch[i].ip+" | "+apTransfer+" |
");
clientListeArray.push(""+versuch[i][myname]+" | LAN | "+versuch[i].ip+" | "+apTransfer+" |
");
clientListeArrayLAN.push(""+versuch[i][myname]+" | LAN | "+versuch[i].ip+" | "+apTransfer+" |
");
;}
else {anzahlClients=anzahlClients-1; //clientListe = clientListe.concat(""+versuch[i][myname]+" | LAN | "+versuch[i].ip+" | noConn |
");
// if (checkNetwork && anwesenheit){ for (var checkyConn in checkConnType ) { if( checkConnType[checkyConn]==versuch[i][myname] ) //prüfung network connection
// {dlog(versuch[i]+checkConnType[checkyConn]);setState(dpPrefix + "WLANUnifi.Wifi_Client_Network."+versuch[i][myname],"noConn");}}}
clientListeArray.push(""+versuch[i][myname]+" | LAN | "+versuch[i].ip+" | noConn |
");
clientListeArrayLAN.push(""+versuch[i][myname]+" | LAN | "+versuch[i].ip+" | noConn |
");}
break;
case 3:
dlog(versuch[i][myname] + " --- " + versuch[i].essid + " --- " + versuch[i].ip);
if (checkNetwork && anwesenheit){ for (var checkyConn in checkConnType ) { if( checkConnType[checkyConn]==versuch[i][myname] ) //prüfung network connection
{dlog(versuch[i]+checkConnType[checkyConn]);setState(dpPrefix + "WLANUnifi.Wifi_Client_Network."+versuch[i][myname],"noConn");}}}
if (parseInt((new Date().getTime())) - (versuch[i]._last_seen_by_usw*1000) < abfragezyklus+abfageoffset) {
for(let device_name in apName) { //Abfrage welcher AP
dlog(versuch[i].ap_mac +" - " + device_name +" - " + apName[device_name].aname);
if (versuch[i].sw_mac==device_name) var apTransfer = apName[device_name].aname};
if (versuch[i][myname]==xxClientxx && syslogs) syslog("______________________________Client ist angemeldet : "+apTransfer +" mit: " + versuch[i].sw_mac); //Fehlersuche
// clientListe = clientListe.concat(""+versuch[i][myname]+" | LAN | "+versuch[i].ip+" | "+apTransfer+" |
");
clientListeArray.push(""+versuch[i][myname]+" | LAN | "+versuch[i].ip+" | "+apTransfer+" |
");
clientListeArrayLAN.push(""+versuch[i][myname]+" | LAN | "+versuch[i].ip+" | "+apTransfer+" |
");
;}
else {anzahlClients=anzahlClients-1; //clientListe = clientListe.concat(""+versuch[i][myname]+" | LAN | "+versuch[i].ip+" | noConn |
");
//if (checkNetwork && anwesenheit){ for (var checkyConn in checkConnType ) { if( checkConnType[checkyConn]==versuch[i][myname] ) //prüfung network connection
// {dlog(versuch[i]+checkConnType[checkyConn]);setState(dpPrefix + "WLANUnifi.Wifi_Client_Network."+versuch[i][myname],"noConn");}}}
clientListeArray.push(""+versuch[i][myname]+" | LAN | "+versuch[i].ip+" | noConn |
");
clientListeArrayLAN.push(""+versuch[i][myname]+" | LAN | "+versuch[i].ip+" | noConn |
");}
dlog("------------------ist nicht war");
break;
case 4:
dlog("------------------uap ist war");
dlog(versuch[i][myname] + " --- " + versuch[i].essid + " --- " + versuch[i].ip);
if (parseInt((new Date().getTime())) - (versuch[i]._last_seen_by_uap*1000) < abfragezyklus+abfageoffset) {
for(let device_name in apName) { //Abfrage welcher AP
dlog(versuch[i].ap_mac +" - " + device_name +" - " + apName[device_name].aname);
if (versuch[i].ap_mac==device_name) var apTransfer = apName[device_name].aname};
if (versuch[i][myname]==xxClientxx && syslogs) syslog("______________________________Client :"+versuch[i][myname]+ " ist angemeldet "+apTransfer +" mit: " + versuch[i].ap_mac); //Fehlersuche
if (checkNetwork && anwesenheit){ for (var checkyConn in checkConnType ) { if( checkConnType[checkyConn]==versuch[i][myname] ) //prüfung network connection
{ fileeWriteHelperOld=getState(dpPrefix + "WLANUnifi.Wifi_Client_Network."+versuch[i][myname]).val;setState(dpPrefix + "WLANUnifi.Wifi_Client_Network."+versuch[i][myname],apTransfer);}}}
//clientListe = clientListe.concat(""+versuch[i][myname]+" | "+versuch[i].essid+" | "+versuch[i].ip+" | "+apTransfer+" |
");
clientListeArray.push(""+versuch[i][myname]+" | "+versuch[i].essid+" | "+versuch[i].ip+" | "+apTransfer+" |
");
clientListeArrayWLAN.push(""+versuch[i][myname]+" | "+versuch[i].essid+" | "+versuch[i].ip+" | "+apTransfer+" |
");
;}
else {anzahlClients=anzahlClients-1; //clientListe = clientListe.concat(""+versuch[i][myname]+" | "+versuch[i].essid+" | "+versuch[i].ip+" | noConn |
");
if (checkNetwork && anwesenheit){ for (var checkyConn in checkConnType ) { if( checkConnType[checkyConn]==versuch[i][myname] ) //prüfung network connection
if (versuch[i][myname]==xxClientxx && syslogs) syslog("______________________________Client ist angemeldet : "+"" +" mit: " +"");
{ fileeWriteHelperOld=getState(dpPrefix + "WLANUnifi.Wifi_Client_Network."+versuch[i][myname]).val;setState(dpPrefix + "WLANUnifi.Wifi_Client_Network."+versuch[i][myname],"noConn");}}}
clientListeArray.push(""+versuch[i][myname]+" | "+versuch[i].essid+" | "+versuch[i].ip+" | noConn |
");
clientListeArrayWLAN.push(""+versuch[i][myname]+" | "+versuch[i].essid+" | "+versuch[i].ip+" | noConn |
");}
if (fileeWriteHelperOld!=apTransfer)fileeWriteHelper=true;
break;
case 5: //Sonderfall unifi bug
anzahlClients=anzahlClients-1;
if (checkNetwork && anwesenheit){ for (var checkyConn in checkConnType ) { if( checkConnType[checkyConn]==versuch[i][myname] && getState(dpPrefix + "WLANUnifi.Wifi_Client_Network."+versuch[i][myname]).val != "noConn" ) //prüfung network connection
{ fileeWriteHelperOld=getState(dpPrefix + "WLANUnifi.Wifi_Client_Network."+versuch[i][myname]).val;setState(dpPrefix + "WLANUnifi.Wifi_Client_Network."+versuch[i][myname],"noConn");}}}
clientListeArray.push(""+versuch[i][myname]+" | "+"no SSID"+" | "+"no IP"+" | noConn |
");
clientListeArrayWLAN.push(""+versuch[i][myname]+" | "+"no SSID"+" | "+versuch[i].ip+" | noConn |
");
if (fileeWriteHelperOld!=apTransfer)fileeWriteHelper=true;
break;
} //case
} //for
checkNetwork=false;
setStateDelayed(dpPrefix + "WLANUnifi.Wifi_Clients_Anzahl",anzahlClients,100); //korrigiert
for (var h =0; h"+notSeen[h]+
//" | noConn | noConn | noConn | ");
if (disConClientsFirst) {
clientListeArray.unshift(""+notSeen[h]+
" | noConn | noConn | noConn |
");
}
else{
clientListeArray.push(""+notSeen[h]+
" | noConn | noConn | noConn |
");}
clientListeArrayDISC.push(""+notSeen[h]+
" | noConn | noConn | noConn |
");
}
//setStateDelayed(dpPrefix + "WLANUnifi.Wifi_Clients_Anzahl",anzahlClients,100); //korrigiert
mylog("Status5");
lastChangeList=format3; // erstellt die liste für letzte änderung im netzwerk
for (var g = lastChange.length-1; g >= 0 ; g--) {
lastChangeList=lastChangeList.concat(lastChange[g]/*+"
"*/);
lastChangeList.concat(lastChange[g]+"
");
}
//log(lastChangeList,"error");
// log(clientListeArray.toString());
//Filterfunktion - comma-separated list
var whitelist=getState(dpPrefix + "WLANUnifi.Client_WhiteList").val.split(',');
var clientListArrayStg="";
var clientListArrayStgLAN="";
var clientListArrayStgWLAN="";
var clientListArrayStgDISC="";
dlog(whitelist.join());
// erstelle client-table aus array
for (var wz=0; wz < clientListeArray.length ; wz++){
if(whitelist.toString().includes("default") || whitelist.toString=="") { dlog("-------------default im filter");
clientListArrayStg=clientListArrayStg+clientListeArray[wz]; }
else{ for(let filter in whitelist){
dlog("filter : "+whitelist[filter] +" ------- name :"+clientListeArray[wz]);
if (clientListeArray[wz].includes(whitelist[filter]) && !clientListArrayStg.includes(clientListeArray[wz]) ) clientListArrayStg=clientListArrayStg+clientListeArray[wz];} } //str.includes("world");
}
var cliAnz1 =0; var cliAnz2 =0; var cliAnz3 =0;
for ( cliAnz1=0; cliAnz1 < clientListeArrayLAN.length ; cliAnz1++){clientListArrayStgLAN=clientListArrayStgLAN+clientListeArrayLAN[cliAnz1];}; setState(dpPrefix + "WLANUnifi.Wifi_Clients_Anzahl_LAN",cliAnz1);
for ( cliAnz2=0; cliAnz2 < clientListeArrayWLAN.length ; cliAnz2++){clientListArrayStgWLAN=clientListArrayStgWLAN+clientListeArrayWLAN[cliAnz2];}; setState(dpPrefix + "WLANUnifi.Wifi_Clients_Anzahl_WLAN",cliAnz2);
for ( cliAnz3=0; cliAnz3 < clientListeArrayDISC.length ; cliAnz3++){clientListArrayStgDISC=clientListArrayStgDISC+clientListeArrayDISC[cliAnz3];}; setState(dpPrefix + "WLANUnifi.Wifi_Clients_Anzahl_DISC",cliAnz3);
if (iqontrol && anwesenheit && fileeWriteHelper ) {
var lastUpdate=formatDate(getDateObject((parseFloat((new Date().getTime())))), "SS:mm:ss");
var clientTableEnde="
Geamtanzahl angemeldeter Clients:"+anzahlClients+"
Insgesamt Clients registriert: "+ listeDatenpunkte.length+
"
Letztes File Update: "+lastUpdate+"
"+
"Letzter Wechsel im Netzwerk:
"+lastChangeList+""
var clientTableEndeWLAN="
Geamtanzahl angemeldeter WLAN Clients:"+cliAnz2+"
Insgesamt Clients registriert: "+ listeDatenpunkte.length+
"
Letztes File Update: "+lastUpdate+"
"+
"Letzter Wechsel im Netzwerk:
"+lastChangeList+""
var clientTableEndeLAN="
Geamtanzahl angemeldeter LAN Clients:"+cliAnz1+"
Insgesamt Clients registriert: "+ listeDatenpunkte.length+
"
Letztes File Update: "+lastUpdate+"
"+
"Letzter Wechsel im Netzwerk:
"+lastChangeList+""
var clientTableEndeDISC="
Geamtanzahl angemeldeter LAN Clients:"+cliAnz3+"
Insgesamt Clients registriert: "+ listeDatenpunkte.length+
"
Letztes File Update: "+lastUpdate+"
"+
"Letzter Wechsel im Netzwerk:
"+lastChangeList+""
//log("clientfile wird geschrieben","error");
/* let dataHelp = format2+clientListe.concat("
Geamtanzahl angemeldeter Clients:"+anzahlClients+"
Insgesamt Clients registriert: "+ listeDatenpunkte.length+
"
Letztes File Update: "+formatDate(getDateObject((parseFloat((new Date().getTime())))), "SS:mm:ss")+"
"+
"Letzter Wechsel im Netzwerk:
"+lastChangeList+"");
*/
//writeMyFile(dataHelp, pathClient);
writeMyFile(format2+clientListArrayStg+clientTableEnde, pathClient);
writeMyFile(format2+clientListArrayStgWLAN+clientTableEndeWLAN, pathOnlyWLAN);
writeMyFile(format2+clientListArrayStgLAN+clientTableEndeLAN, pathOnlyLAN);
writeMyFile(format2+clientListArrayStgDISC+clientTableEndeDISC, pathOnlyDISC);
}
//if (lastChange.length>10) lastChange=[];
dlog("ClientFile schreibt! "+iqontrol.toString()+writeClientTable.toString());
//if (true) setState(dpPrefix + "WLANUnifi.Wifi_Clients", "
")); //schreibe client table
if (true) setState(dpPrefix + "WLANUnifi.Wifi_Clients", "") ;//schreibe client table
setState(dpPrefix + "WLANUnifi.Wifi_ClientsOnlyLAN", ""+clientListArrayStgLAN+"
");
setState(dpPrefix + "WLANUnifi.Wifi_ClientsOnlyWLAN", ""+clientListArrayStgWLAN+"
");
setState(dpPrefix + "WLANUnifi.Wifi_ClientsOnlyDISC", ""+clientListArrayStgDISC+"
");
if (anwesenheit) setState(dpPrefix + "WLANUnifi.Wifi_Clients_Log", "Letzter Wechsel im Netzwerk:"+lastChangeList+"
");
// log("------------------------frstTime: ------"+ firstTime, "warn")
if (firstTime < 2 && iqontrol && anwesenheit) writeMyFile(format2+clientListArrayStg+clientTableEnde, pathClient);
if (anwesenheit) getWrongIPClients();
}, 3000);}
mylog("bin raus aus workclients");
} //workclientend
//-----------------------------------------WRITING FILES---------------------------------------------------------------
function writeMyFile(dataHelpWrite, path) {
mylog("bin in writemyfile")
writeFile('iqontrol.meta', path ,dataHelpWrite, function (error) {
mylog('file written');
});
//readFile('iqontrol.meta', '/htmltest3.html', function (error, data) {
// mylog("mein text: ----:"+data.substring(0, 50));});
mylog("bin raus aus writemyfile")
}
//-----------------------------------------EXISTING CLIENTS---------------------------------------------------------------
function getExistingClients() {
dlog("BIN IN EXISTING CLIENTS");
listeDatenpunkte = [];
var cacheSelectorState = $("state[state.id=" + dpPrefix + "WLANUnifi.Wifi_Client_States.*]");
cacheSelectorState.each(function (id, c) {
if (!id.includes("undefined")) {
listeDatenpunkte[c] = id.replace(dpPrefix + "WLANUnifi.Wifi_Client_States.", "");
}
});
dlog("bin raus a existing clients");
}
//-----------------------------------------DELETE CLIENTS mit fehlender ip adresse---------------------------------------------------------------
function getWrongIPClients() {
ipArrFehlt=[];
dlog("BIN IN WRONG IP CLIENTS");
listeDatenpunkte = [];
var cacheSelectorState = $("state[state.id=" + dpPrefix + "WLANUnifi.Wifi_Client_States.*]");
cacheSelectorState.each(function (id, c) {
if (getObject(id).common.name =="IP Adresse fehlt"){
deleteState(id);}
});
dlog("bin raus WRONG IP clients");
}
//-----------------------------------------GET--VOUCHERS---------------------------------------------------------------
async function getVouchers() {
if (vouchers) {
mylog("BIN IN getvouchers");
return new Promise(async (resolve, reject) => {
dlog("nur mal so");
if(!loggedIn) await login().catch((e) => reject(e));
respv = await request.get({
url: unifi_controller + "/api/s/"+siteName+"/stat/voucher",
headers: { Cookie: cookies.join("; ") }
}).catch((e) => { dlog("getStatus reject " + e); /*reject(e)*/ return testerrv=true; });
if (!testerrv) {
dlog("got response " + JSON.stringify(respv));
dlog(typeof respv);
dlog("--------------------- " + respv);
resolve("done");
} else {log("reject weil respv ist 00"); reject();}
mylog("bin raus a GET vouchers");
});
}}
//-----------------------------------------WORK--VOUCHERS---------------------------------------------------------------
function workVouchers() {
if (vouchers) {
// mylog("BIN IN workvouchers");
dlog("got response " + JSON.stringify(respv));
dlog(typeof respv);
dlog("--------------------- " + respv);
respv = JSON.parse(respv);
//if (respv.data == null) log("respv ist NULLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL -"+ respv.length)
mylog(JSON.stringify(respv.data).length.toString() + "----------------------writeFilevr : " + writeFileVar.toString())
dlog(respv.meta);dlog(respv.meta.rc);
var writeDatei=true;
var laengeMessage=JSON.stringify(respv.data).length;
if (laengeMessage==writeFileVar) {writeDatei = false;} else {writeDatei=true}
mylog("writefile: "+ writeDatei)
writeFileVar=JSON.stringify(respv.data).length;
if (writeDatei) {
mylog("------------------------------------------------schreibe")
var list ="";
var listCode="";
listValue=[];
listValue2=[];
listValue3=[];
let listHelper2='';
//zuerst Datenpunktealt löschen
for (i = 0; i < 20; i++) {
var y=i+1;
var yy=y.toString();
if (y<10 ) yy="0"+yy;
setState(dpPrefix + "WLANUnifi.Wifi_Vouchers-CODES.CODE"+yy+".code"+yy, " na " );
setState(dpPrefix + "WLANUnifi.Wifi_Vouchers-CODES.CODE"+yy+".erstellt", " na " );
setState(dpPrefix + "WLANUnifi.Wifi_Vouchers-CODES.CODE"+yy+".dauer", " na " );
setState(dpPrefix + "WLANUnifi.Wifi_Vouchers-CODES.CODE"+yy+".abgelaufen", " na " );
setState(dpPrefix + "WLANUnifi.Wifi_Vouchers-CODES.CODE"+yy+".id", "na" );
setState(dpPrefix + "WLANUnifi.Wifi_Vouchers-CODES.CODE"+yy+".notiz", "na" );
}
//tabelle vorbereiten
var clientListe = "Nr. | DAUER | FERTIG | CODE | ERSTELLT | NOTIZ |
";
for (var r = 1; r < 21; r++) {
var x=r.toString();
if ( r < 10) { var yyy="0"+x;} else {yyy=x};
setStateDelayed(dpPrefix + "WLANUnifi.Wifi_Vouchers-CODES.CODE"+yyy, "", 100);
}
for (var i = 0; i < respv.data.length; i++) {
var zeit= respv.data[i].create_time*1000
listValue.push(respv.data[i]._id);
listValue3.push((i+1));
list=list.concat(respv.data[i]._id,";") // für VIS anzeige - löschen
let zeit1 = formatDate(getDateObject(zeit), "TT.MM.JJJJ SS:mm").toString();
let notizen;
if (respv.data[i].note !== null) { notizen=respv.data[i].note} else {notizen= " - ";}
var y=i+1;
var yy=y.toString();
if (y<10 ) yy="0"+yy;
clientListe = clientListe.concat(""+yy+" | "+respv.data[i].duration+" | "+respv.data[i].status_expires+" | "+respv.data[i].code.slice(0,5)
+"-"+respv.data[i].code.slice(5)+" | " +zeit1 + " | "+notizen+" |
");
if (i<20 ) {
listValue2.push("CODE"+yy);
listCode = listCode.concat("CODE"+yy , ";"); // für VIS anzeige - löschen
dlog(zeit1);
setState(dpPrefix + "WLANUnifi.Wifi_Vouchers-CODES.CODE"+yy+".code"+yy, respv.data[i].code.slice(0,5)+"-"+respv.data[i].code.slice(5) ); //respv.data[i].code
setState(dpPrefix + "WLANUnifi.Wifi_Vouchers-CODES.CODE"+yy+".erstellt", zeit1 );
setState(dpPrefix + "WLANUnifi.Wifi_Vouchers-CODES.CODE"+yy+".dauer", respv.data[i].duration );
setState(dpPrefix + "WLANUnifi.Wifi_Vouchers-CODES.CODE"+yy+".abgelaufen", respv.data[i].status_expires );
setState(dpPrefix + "WLANUnifi.Wifi_Vouchers-CODES.CODE"+yy+".id", respv.data[i]._id );
if(respv.data[i].note !== null) {
setState(dpPrefix + "WLANUnifi.Wifi_Vouchers-CODES.CODE"+yy+".notiz", respv.data[i].note );}
else {setState(dpPrefix + "WLANUnifi.Wifi_Vouchers-CODES.CODE"+yy+".notiz", " - " );}
}}
//nur für Löschen Iqontrol VIS
listCode=listCode+"Wähle Code"
list=list+"xxx"
listValue3.push((respv.data.length+1));
setState(dpPrefix + "WLANUnifi.Wifi_Vouchers_CodeList2",listValue3.join(";"))
setState(dpPrefix + "WLANUnifi.Wifi_Vouchers_DeleteVIS",(respv.data.length+1))
//setState(dpPrefix + "WLANUnifi.Wifi_Vouchers-CODES.A_Delete_Voucher.Voucher_ID",(respv.data.length+1))
//nur für Löschen Iqontrol Kachel
for (i=0; iGeamtanzahl Vouchers:"+respv.data.length+"
")+"Letztes File Update: "+formatDate(getDateObject((parseFloat((new Date().getTime())))), "SS:mm:ss")+"