text: var m=m||{};m.aio=m.aio||{};m.aio.infomanager=m.aio.infomanager||{};
  m.aio.infomanager.Manager=function(){var t=-1,f={},q=[],w="webservice.mediola.com",u=443,z="/creatorneo/license/getlicensesummary",A="/creatorneo/license/getblocked2",B=["mcontrol","xs1","cloud_device"],p=["aio","hm","hue","harmony","instar","ip","telefunken","konine","contronics","7links","dlink","hama","foscam","edimax","ipsync","wemo","sonos","redeye","itach","irtrans","digitus","dmx4all","easysh","moehlenhoff","internorm","siegenia","miele","rwe","ez","vera","knx","synco","bub","rademacher","max",
  "nueva","osram","netatmo","intertechno","brennenstuhl","spro","milight","aio_upgrade","hm_upgrade",null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,"ultimate","tado","denon","pioneer","yamaha","onkyo","marantz","doorbird","homewizard","rehau","fritz","qivicon","mobotix","ipcam","netatmo_welcome","yellowstone","samsung","esco","mydlink","orvibo","raumfeld","bose","axis","neoserver","nuki","warema","feller","enocean","zwave","tahoma","fibaro","zigbee","digitalstrom",
  "mystrom","hautau","brelag","hm_ccu3","wir","iobroker","kopp","enoceanip","cloud_device","gealan"],L=["neo","neo2"],g=function(b,c){for(var a=0;a<b.length;a++)if(b[a]===c)return!0;return!1},r=function(b){var c=require("crypto"),a=new Buffer("fO4gAeDjh4HwO0D8+/9Bfw==","base64"),d=new Buffer("+ubtPBJR9uejkjXiN6c1Bg==","base64");c=c.createCipheriv("aes-128-cbc",a,d);c.setAutoPadding(!0);b=[c.update(b,"utf8")];b.push(c.final());return Buffer.concat(b).toString("base64")},x=function(b){var c=require("crypto"),
  a=new Buffer("fO4gAeDjh4HwO0D8+/9Bfw==","base64"),d=new Buffer("+ubtPBJR9uejkjXiN6c1Bg==","base64");c=c.createDecipheriv("aes-128-cbc",a,d);c.setAutoPadding(!0);b=[c.update(new Buffer(b,"base64"))];b.push(c.final());b=Buffer.concat(b).toString("utf8");return JSON.parse(b)},C=function(b,c){var a={"aio@10":{full:0,upgrade:42},"hm@10":{full:1,upgrade:43}};if(c&&b&&0!==c.length)for(var d in a){var e=a[d];if(e){var f=c.indexOf(d);if(!(0>f)){var g=b.indexOf(e.upgrade);0<=g?(c.splice(f,1),0>b.indexOf(e.full)&&
  (b.splice(g,1),b.push(e.full))):0<=b.indexOf(e.full)&&c.splice(f,1)}}}},G=function(b){for(var c=[],a=0;a<b.length;a++){var d=-1;for(var e=0;e<p.length;e++)if(p[e]==b[a]){d=e;break}-1!=d&&(g(c,d)||c.push(d))}return c},H=function(b,c){var a=[],d;for(d=0;d<b.length;d++)a.push(b[d]);for(d=0;d<c.length;d++)g(b,c[d])||a.push(c[d]);return a},M=function(b){var c="",a=require("https").request({host:w,port:u,path:A,method:"GET",timeout:2E4,headers:{"User-Agent":"mediola",Connection:"close"}},function(a){a.setEncoding("utf8");
  a.on("data",function(a){c+=a});a.on("end",function(){b&&(200==a.statusCode?b(null,c):b(Error("equest failed:"+c)));b=null})});if(a.on&&"function"==typeof a.on)a.on("error",function(a){b&&b(a);b=null});a.setTimeout&&a.setTimeout(2E4);a.end()},I=function(b,c,a){M(function(d,e){if(d)a&&a(d);else{if(e){try{q=JSON.parse(e)}catch(l){}c&&c.updateBlockedLicenses(q,function(){});b&&q&&b.save("blocked",r(JSON.stringify(q)))}a&&a()}})},E=function(b,c,a){var d=require("https");443!=u&&(d=require("http"));var e=
  2E4;a&&a.timeout&&(e=a.timeout);a={host:w,port:u,path:z,method:"POST",timeout:e,headers:{"User-Agent":"mediola",Connection:"close"}};m.aio.infomanager.IM._logger.log("trace","try to download info from "+a.host+":"+a.port);var f="";d=d.request(a,function(a){a.setEncoding("utf8");a.on("data",function(a){f+=a});a.on("end",function(){if(200==a.statusCode)m.aio.infomanager.IM._logger.log("trace","download info success"),c&&c(null,f);else{m.aio.infomanager.IM._logger.log("trace","download info failed:"+
  a.statusCode+" :"+f);var b=Error("request failed:"+f);b.code="http";c&&c(b)}c=null})});d.on("error",function(a){a.code="connection";m.aio.infomanager.IM._logger.log("trace","download info error:"+a.stack);c&&c(a);c=null});d.setTimeout(e,function(){m.aio.infomanager.IM._logger.log("trace","download info timeout");var a=Error("http timeout");a.code="timeout";c&&c(a);c=null});d.write(b);d.end()},F=function(b){b=x(b);var c={},a;for(a in b)if(b.hasOwnProperty(a)){var d=b[a],e={};c[a]=e;e.feature=d.feature;
  e.blocked=d.blocked;e.skins=d.skins;e.sus_info=d.sus_info;e.sus_flatrate=d.sus_flatrate;e.codes={};if(d.codes)for(var f in d.codes)if(d.codes.hasOwnProperty(f)){var g=d.codes[f];e.codes[f]={};g.op&&(e.codes[f].op=x(g.op));e.codes[f].blocked=g.blocked}}return c},J=function(b,c,a){c.trace("config/tenants",function(c,e){if(c)a&&a(c);else if(e)if((c=e.getChildren())&&0!=c.length){e=[];for(var d=0;d<c.length;d++){var g=c[d];g&&g.license&&g.license.licenseTxt&&e.push(g.license.licenseTxt)}0==e.length?a&&
  a():(c=e.join(":"),c=r(c),E(c,function(c,d){if(c)a&&a(c);else{if(d)try{var e=F(d),g;for(g in f)f.hasOwnProperty(g)&&e&&!e[g]&&(e[g]=f[g]);e&&(f=e);b&&f&&(m.aio.infomanager.IM._logger.log("trace","save pref"),b.save("info",r(JSON.stringify(f))))}catch(N){m.aio.infomanager.IM._logger.log("trace","decode info error:"+N.stack)}a&&a()}}))}else a&&a();else a&&a()})},K=function(b){var c=v(b),a=y(b),d=!1;b=b.version+":"+("normal"==b.type?0:1)+":"+b.id;f&&f[b]&&f[b].sus_info&&(b=f[b].sus_info,b.hm&&b.hm.lite&&
  (d=!0));d?(d=c.indexOf(1),-1!=d&&c.splice(d,1)):C(c,a);d=[];if(g(c,63)){for(b=0;b<p.length;b++)42!=b&&43!=b&&d.push(p[b]);d=p}else{for(b=0;b<c.length;b++)63!=c[b]&&(42==c[b]?g(c,0)||d.push(p[0]):43==c[b]?g(c,1)||d.push(p[1]):d.push(p[c[b]]));for(b=0;b<a.length;b++)c=a[b].split("@"),2==c.length&&g(p,c[0])&&10>=parseInt(c[1])&&d.push(c[0]+"_lite")}d=H(d,B);a=[];for(b=0;b<d.length;b++)d[b]&&a.push(d[b]);a&&-1!=a.indexOf("hm_ccu3")&&-1==a.indexOf("hm")&&a.push("hm");return a},v=function(b){var c=b.version+
  ":"+("normal"==b.type?0:1)+":"+b.id,a=[],d=[];if(f)for(var e in f)if(f.hasOwnProperty(e)&&e==c){var l=f[e].codes;if(l)for(var n in l)if(l.hasOwnProperty(n)&&l[n]&&l[n].op){var D=l[n],h=D.op;h.features&&0<h.features.length&&(D.blocked?a=a.concat(h.features):d=d.concat(h.features))}}a=G(a);d=G(d);c=[];e=b.features;if(0==b.version)for(b=0;b<e.length;b++)for(l=e.readUInt8(e.length-1-b),n=0;8>n;n++)l>>n&1&&c.push(8*b+n);else 1==b.version?(b=e.readUInt8(7),b&1&&c.push(0),b>>1&1&&c.push(1),b=e.readUInt8(3),
  b>>2&1&&c.push(34),b>>3&1&&c.push(35),b>>6&1&&c.push(38),b>>7&1&&c.push(39),b=e.readUInt8(2),b&1&&c.push(40),b>>2&1&&c.push(42),b>>3&1&&c.push(43),b=e.readUInt8(0),b>>7&1&&c.push(63)):2==b.version&&(b=e.readUInt8(0),b>>7&1&&c.push(63));b=[];for(e=0;e<c.length;e++)g(a,c[e])||b.push(c[e]);return d=H(b,d)},O=function(b){var c=m.aio.infomanager.IM.hasPartnerUltimate(),a=b.version+":"+("normal"==b.type?0:1)+":"+b.id,d=[];if(f&&f[a]&&f[a].sus_info){d=[];b=f[a].sus_info;if(b.ultimate)return[63];for(var e in b)b.hasOwnProperty(e)&&
  (a=b[e],!a.lite&&a.deadline>=t||-1==a.deadline||c)&&(a=p.indexOf(e),d.push(a))}else e=v(b),-1!=e.indexOf(63)?d=e:c?d=e:1504223999E3>=t&&(d=e);return d},P=function(b){var c=m.aio.infomanager.IM.hasPartnerUltimate(),a=b.version+":"+("normal"==b.type?0:1)+":"+b.id,d=[];if(f&&f[a]&&f[a].sus_info){d=[];b=f[a].sus_info;for(var e in b)b.hasOwnProperty(e)&&(a=b[e],(a.lite&&a.deadline>=t||-1==a.deadline||c)&&d.push(e+"@"+a.devCount))}else e=y(b),1504223999E3>=t?d=e:c&&(d=e);return d},Q=function(b){var c=m.aio.infomanager.IM.hasPartnerUltimate(),
  a=b.version+":"+("normal"==b.type?0:1)+":"+b.id,d=null;if(f&&f[a]&&f[a].sus_info){d={};b=f[a].sus_info;a=!1;b.ultimate&&(a=!0);for(var e in b)if(b.hasOwnProperty(e)){var l=b[e];l.lite?(d[e+"_lite"]=l.deadline,c&&(d[e+"_lite"]=-1)):(d[e]=a?-1:l.deadline,c&&(d[e]=-1))}B.forEach(function(a){d[a]=-1})}else{var n=1504216799E3;e=v(b);g(e,63)&&(n=-1);e=K(b);d={};e.forEach(function(a){-1!=B.indexOf(a)?d[a]=-1:(d[a]=n,c&&(d[a]=-1))})}d.hm_ccu3&&(d.hm||(d.hm=d.hm_ccu3),d.hm&&d.hm<d.hm_ccu3&&(d.hm=d.hm_ccu3));
  return d},y=function(b){var c=b.version+":"+("normal"==b.type?0:1)+":"+b.id;b=[];if(f)for(var a in f)if(f.hasOwnProperty(a)&&a==c){var d=f[a].codes;if(d)for(var e in d)if(d.hasOwnProperty(e)&&d[e]&&d[e].op){var l=d[e],n=l.op;n.features_lite&&0<n.features_lite.length&&(l.blocked||(b=b.concat(n.features_lite)))}}a=[];for(e=0;e<b.length;e++)g(a,b[e])||a.push(b[e]);return a},k=function(){this._configmanager=this.preference=null;this._logger=require("x.logger.js").getLogger("m.aio.infomanager.Manager")};
  k.prototype.init=function(b,c,a,d){a&&(t=a);this._configmanager=c;if(b&&b.Preference){this.preference=b.Preference;if(c=b.Preference.read("info"))try{f=x(c)}catch(e){}if(b=b.Preference.read("blocked"))try{q=x(b)}catch(e){}}switch(process.env.CLOUD){case "local":w=process.env.CLOUD_HOST?process.env.CLOUD_HOST:"localhost";u=8080;z="/webservice"+z;A="/webservice"+A;break;case "dev":w=process.env.CLOUD_HOST?process.env.CLOUD_HOST:"mediola-dev.elasticbeanstalk.com";u=80;break;default:w=process.env.CLOUD_HOST?
  process.env.CLOUD_HOST:"webservice.mediola.com",u=443}d&&d()};k.prototype.retrieveInfo=function(b){var c=require("m.aio.configmanager.js"),a=this,d=2;J(this.preference,c,function(){setInterval(function(){J(a.preference,c)},9E5);d--;0==d&&(b&&b(),b=null)});I(this.preference,c,function(){setInterval(function(){I(a.preference,c)},9E5);d--;0==d&&(b&&b(),b=null)})};k.prototype.permitSkin=function(b,c){if(!b||!c)return!1;var a=v(c);if(g(a,63)||g(L,b))return!0;c=c.version+":"+("normal"==c.type?0:1)+":"+
  c.id;return f&&f[c]&&f[c].skins?g(f[c].skins,b):!1};k.prototype.permitFeature=function(b,c,a,d,e,f){var n=function(a){switch(a){case "telefunken":return 6;case "konine":return 7;case "abus":return 0;case "7links":return 9;case "dlink":return 10;case "hama":return 11;case "foscam":return 12;case "instar":return 4;case "edimax":return 13;case "nueva":return 35;case "digitus":return 20;case "doorbird":return 70;case "mobotix":return 75;case "generic":return 76;case "netatmo":return 77;case "axis":return 85;
  default:return-1}},l=function(a,b){if(!k||!a)return 0;for(var c=0;c<b.length;c++)if(b[c]&&0==b[c].indexOf(a))return parseInt(b[c].replace(a+"@",""));return 0};b=function(a,b,c){var d=-1;if(c)for(var e=0;e<c.length&&(!c[e]||!c[e].info||c[e].info.sys!=a||(d++,c[e].index!==b));e++);return d};if(!a)return!1;if(-1==t){var h=v(a);var k=y(a);if(g(h,63))return!0;C(h,k)}else if(h=O(a),k=P(a),g(h,63))return!0;a=0;switch(c.sys){case "mcontrol":case "xs1":case "virtualdevice":case "neoserver":case "cloudservice":return!0;
  case "hcgw":if(null!=c.ip&&"undefined"!=typeof c.ip)switch(c.vendor){case "brennenstuhl":a=39;break;case "intertechno":a=38;break;default:a=40}else{if(g(h,38)||g(h,39))return!0;a=40}break;case "netatmo":a=37;break;case "lightify":a=36;break;case "max":a=34;break;case "homepilot1":case "homepilot2":case "homepilot2v5":a=33;break;case "orvibo_ir":switch(c.vendor){case "orvibo":a=82;break;default:a=35}break;case "orvibo_socket":a=82;break;case "execengine":a=8;break;case "siegenia":a=25;break;case "aio":if(c.gateway_vendor||
  null!=c.ip&&"undefined"!=typeof c.ip){if("KNX"==c.type)return g(h,30);switch(c.gateway_vendor){case "siegenia":a=25;break;case "internorm":a=24;break;case "nueva":a=35;break;case "brelag":a=98;break;case "wir":a=100;break;case "kopp":a=102;break;default:if("EA"==c.version&&g(h,24)||"E2"==c.version&&g(h,102)||g(h,42)||g(h,90)||g(h,91)||g(h,94)||g(h,30))return!0;if(c=l(p[1],k))return d=b("aio",d,e),d<c;a=0}}else switch(c.type){case "IN":case "IW":a=24;break;case "SIAU":a=25;break;case "QA":a=80;break;
  case "ENOCEAN":if(f&&"aio"==f.sys&&f.version&&("C1"==f.version||"C2"==f.version))return!0;a=90;break;case "ZWAVE2":a=91;break;case "KNX":a=30;break;case "ZIGBEE":a=94;break;case "BG":a=98;break;default:if(g(h,24)||g(h,25)||g(h,35)||g(h,42)||g(h,98)||g(h,100)||g(h,102)||l(p[0],k))return!0;a=0}break;case "hm":if(g(h,43)||g(h,99))return!0;if(c=l(p[1],k))return d=b("hm",d,e),d<c;a=1;break;case "hue":a=2;break;case "easyled":a=22;break;case "milight":case "milightv6":a=41;break;case "wifiled2":a=21;break;
  case "dmx4all":a=21;break;case "artnet":a=21;break;case "itach":a=18;break;case "irtrans":a=19;break;case "redeye":a=17;break;case "harmony":a=3;break;case "ip":a=5;break;case "edimax":a=13;break;case "ipsync":a=14;break;case "wemo":a=15;break;case "sonos":a=16;break;case "alpha2":a=23;break;case "tado":a=64;break;case "denon":case "heos":a=65;break;case "pioneer":a=66;break;case "yamaha":a=67;break;case "onkyo":a=68;break;case "marantz":a=69;break;case "homewizard":a=71;break;case "neasmart":a=72;
  break;case "fritz":a=73;break;case "qivicon":a=74;break;case "rwe":a=27;break;case "cloudy":a=78;break;case "samsung_smarthome":a=79;break;case "dlink":a=81;break;case "raumfeld":a=83;break;case "bose":a=84;break;case "nuki":a=87;break;case "warema":a=88;break;case "feller":a=89;break;case "tahoma":a=92;break;case "fibaro":a=93;break;case "digitalstrom":a=95;break;case "mystrom":a=96;break;case "hautau":a=97;break;case "ioBroker":a=101;break;case "dcgw":a=103;break;case "cloud_service":a=104;break;
  case "gealan":a=105;break;case "cam":switch(c.type){case "jpeg":return!0;case "system":switch(c.manufacturer){case "7links":case "hama":if(g(h,76))return!0}a=n(c.manufacturer);if(-1==a)return!1;break;case "custom":a=5;break;case null:case void 0:return!0}break;case "webpage":return!0;default:if(a=n(c.sys),-1==a)return!1}return g(h,a)};k.prototype.getFeatureModules=function(b){return K(b)};k.prototype.getFeatureModulesSUS=function(b){return-1==t?null:Q(b)};k.prototype.getSUSFlatrate=function(b){b=
  b.version+":"+("normal"==b.type?0:1)+":"+b.id;b=f&&f[b]&&f[b].sus_flatrate?f[b].sus_flatrate:null;return b};k.prototype.getDeviceCount=function(b,c){if(!c||!b)return-1;var a=v(c);c=y(c);C(a,c);if(g(a,63))return-1;switch(b.sys){case "aio":switch(b.type){case "IN":case "IW":return-1;case "SIAU":return-1;default:if(g(a,0)||g(a,24)||g(a,25)||g(a,35)||g(a,30))return-1;if(g(a,42))return 10;if(g(a,90)||g(a,91)||g(a,94)||g(a,98)||g(a,100)||g(a,102))return-1;b=p[0]}break;case "hm":if(g(a,1)||g(a,99))return-1;
  if(g(a,43))return 10;b=p[1];break;default:return-1}if(!b)return-1;for(var d=a=0;d<c.length;d++){var e=c[d].split("@");2==e.length&&e[0]==b&&(e=parseInt(e[1]),e>a&&(a=e))}return a};k.prototype.getDeviceCount2=function(b,c,a){b&&c?(c=require("m.aio.configmanager.js").LicenseManager.resolve(c))?(b=this.getDeviceCount(b,c),a&&a(null,b)):a&&a(Error("resolve license fail")):a&&a(Error("argument is null"))};k.prototype.updateLicense=function(b,c){if(b){var a=this;b=r(b);E(b,function(b,e){if(b)c&&c(b);else{if(e)try{var d=
  F(e),g;for(g in f)f.hasOwnProperty(g)&&d&&!d[g]&&(d[g]=f[g]);d&&(f=d);a.preference&&f&&a.preference.save("info",r(JSON.stringify(f)))}catch(D){}c&&c()}})}else c&&c(Error("license is empty"))};k.prototype.updateCodeOld=function(b,c,a,d){if(b&&c&&a)if(c=require("m.aio.configmanager.js").LicenseManager.resolve(c)){c=c.version+":"+("normal"==c.type?0:1)+":"+c.id;f||(f={});f[c]||(f[c]={blocked:!1,codes:{}});f[c].codes||(f[c].codes={});f[c].codes[b]={op:x(a),blocked:!1};if(f[c].codes[b].op&&f[c].codes[b].op.skins&&
  0<f[c].codes[b].op.skins.length)for(f[c].skins||(f[c].skins=[]),b=f[c].codes[b].op.skins,a=0;a<b.length;a++)b[a]&&!g(f[c].skins,b[a])&&f[c].skins.push(b[a]);this.preference&&this.preference.save("info",r(JSON.stringify(f)));d&&d()}else d&&d(Error("resolve license fail"));else d&&d(Error("argument is null"))};k.prototype.updateCode=function(b,c,a,d){if(c){b=r(c);var e=this;E(b,function(a,b){if(a)d&&d(a);else{if(b)try{var c=F(b),g;for(g in f)f.hasOwnProperty(g)&&c&&!c[g]&&(c[g]=f[g]);c&&(f=c);e.preference&&
  e.preference.save("info",r(JSON.stringify(f)))}catch(R){}d&&d()}})}else d&&d(Error("argument is null"))};k.prototype.updateDownloadSkin=function(b,c,a){b&&c?(b=b.version+":"+("normal"==b.type?0:1)+":"+b.id,f||(f={}),f[b]||(f[b]={blocked:!1,codes:{},skins:[]}),f[b].skins||(f[b].skins=[]),g(f[b].skins,c)||f[b].skins.push(c),this.preference&&this.preference.save("info",r(JSON.stringify(f))),a&&a()):a&&a(Error("argument is null"))};k.prototype.isLicenseBlocked=function(b){if(!q)return!1;for(var c=0;c<
  q.length;c++)if(q[c].version==b.version&&q[c].id==b.id&&q[c].type==("test"==b.type?1:0))return!0;return!1};k.prototype.hasPartnerUltimate=function(){var b=this._configmanager.getAllLicenses();if(!b||0==b.length)return!1;for(var c=0;c<b.length;c++){var a=b[c];if(a&&a.isPartnerUltimateLicense())return!0}return!1};return k}();m.aio.infomanager.IM=new m.aio.infomanager.Manager;"undefined"!=typeof module&&null!=module&&(module.exports=m.aio.infomanager.IM);
  