(g.size=b.size,h._md5(d,function(a,b){a?c(a):(g.md5=b,h._sha1(d,function(a,b){a?c(a):(g.sha1=b,c(null,g))}))})):c(Error(d+" is not a file"))})},_md5:function(d,b){var c=require("fs"),a=require("crypto").createHash("md5"),e=c.createReadStream(d);e.on("readable",function(){for(var c;null!==(c=e.read());)a.update(c)}).on("end",function(){b(null,a.digest("base64"))})},_sha1:function(d,b){var c=require("fs"),a=require("crypto").createHash("sha1"),e=c.createReadStream(d);e.on("readable",function(){for(var c;null!==
(c=e.read());)a.update(c)}).on("end",function(){b(null,a.digest("base64"))})}};
k);a._logger.log("error",d.message);c&&c(d);c=null;return}n.finalize()})};d.prototype._requestUpload=function(b){var c=this;this._reportProgress(1,"send upload request",function(){c._logger.log("trace","send upload user database request.");c._doRequest("POST","/creatorneo/userdb/requestUpload",null,null,function(a,c){if(c)try{c=JSON.parse(c)}catch(f){a=f,a.code=103}a||(c&&"success"==c.status?c.result&&c.result.ref&&c.result.credential||(a=Error("request upload response foramt error"),a.code=102):
(a=Error("request upload response error:"+c.message),a.code=101));a&&!a.code&&(a.code=100);b&&b(a,c&&c.result)})})};d.prototype._uploadZip=function(b,c,a){var e=this;this._reportProgress(2,"upload zip file",function(){e._logger.log("trace","upload zip file with ref:"+c.ref);var d=new (require("aws-sdk").S3)({apiVersion:"2006-03-01",region:"eu-central-1",accessKeyId:c.credential.accessKeyId,secretAccessKey:c.credential.secretAccessKey,sessionToken:c.credential.sessionToken}),g=require("fs");require("path");
e=[],f=this,g=function(h,k){if(k>=h.length)b(null,e);else{var l=a.join(d,h[k]);c.stat(l,function(a,c){a?b(a,e):c.isDirectory()?f._listAllFiles(l,function(a,c){a?b(a,e):(Array.isArray(c)&&(e=e.concat(c)),g(h,k+1))}):(e.push(l),g(h,k+1))})}};c.readdir(d,function(a,c){a?b&&b(a,e):g(c,0)})},_getFilesInfos:function(d,b){var c=[],a=require("m.aio.configmanager.js").Page.FILE_EXT,e=require("async"),f=require("path"),g=this;this._listAllFiles(d,function(h,k){h?b&&b(h):e.eachLimit(k,50,function(b,e){if(0==
f.basename(b).indexOf("."))e();else{var h=b.replace(d,""),l=f.extname(h);"controls"==h.substr(1,8)&&l!==a.PAGE&&l!==a.POPUP?e():"resources_"==h.substr(1,10)?e():g._getFileInfos(b,d,function(a,b){a?e(a):(b&&c.push(b),e())})}},function(a){b&&b(a,c)})})},_getFileInfos:function(d,b,c){var a=require("fs"),e=require("path"),f=require("unorm");b=e.relative(b,d);b=f.nfc(b);d=f.nfc(d);"\\"==e.sep&&(b=b.replace(/\\/g,"/"));e=e.basename(d);var g={file:b,name:e},h=this;a.stat(d,function(a,b){a?c(a):b.isFile()?
xnm.aio.moehlenhoff.Handler=function(){var d=function(){var a=require("x.logger.js");xnm.aio.moehlenhoff.DM._logger=a?a.getLogger("xnm.aio.moehlenhoff.DM"):{log:function(){}}};d.prototype.Alpha2=xnm.aio.moehlenhoff.Alpha2;d.prototype.NeaSmart=xnm.aio.rehau.NeaSmart;d.prototype.getDeviceCommandList=function(a,b){b=[];if("analog"==a.data||"digital"==a.data)b.push({id:window.XC_Text.auto,cmd:"auto"}),b.push({id:window.XC_Text.day,cmd:"day"}),b.push({id:window.XC_Text.night,cmd:"night"}),b.push({id:window.XC_Text.w_p0,
e.parallel([function(b){var e=d.getDeviceFile();e?f.exists(e,function(d){d?c._getFileInfos(e,a,function(a,c){b(a,c)}):b()}):b()},function(b){var e=d.getMacrosFile();e?f.exists(e,function(d){d?c._getFileInfos(e,a,function(a,c){b(a,c)}):b()}):b()},function(b){var e=d.getDeviceinfoFile();e?f.exists(e,function(d){d?c._getFileInfos(e,a,function(a,c){b(a,c)}):b()}):b()}],function(a,c){var e=[];c&&c.forEach(function(a){a&&e.push(a)});b&&b(a,e)})},_listAllFiles:function(d,b){var c=require("fs"),a=require("path"),
e=[],f=this,g=function(h,k){if(k>=h.length)b(null,e);else{var l=a.join(d,h[k]);c.stat(l,function(a,c){a?b(a,e):c.isDirectory()?f._listAllFiles(l,function(a,c){a?b(a,e):(Array.isArray(c)&&(e=e.concat(c)),g(h,k+1))}):(e.push(l),g(h,k+1))})}};c.readdir(d,function(a,c){a?b&&b(a,e):g(c,0)})},_getFilesInfos:function(d,b){var c=[],a=require("m.aio.configmanager.js").Page.FILE_EXT,e=require("async"),f=require("path"),g=this;this._listAllFiles(d,function(h,k){h?b&&b(h):e.eachLimit(k,50,function(b,e){if(0==
m.aio.syncmanager.RemoteUploader=function(d,b){var c=require("x.logger.js");this._logger=c?c.getLogger("RemoteUploader"):{log:function(){}};this._username=d.username?d.username:"";this._password=d.password?d.password:"";this._remotePassword=d.remotePassword?d.remotePassword:"";this._listener=b};m.aio.syncmanager.RemoteUploader.PROTOCOL="https";
g._copyFile(q,k,function(b){if(b)b.code=302,a&&a(b);else{var d=require("m.aio.devicemanager.js");require("m.aio.macromanager.js").reloadTenant(c,function(){d.reloadTenant(c,function(){a&&a()})})}})}})})})})};d.prototype._reportProgress=function(b,c,a){if(this._listener&&this._listener.onProgress)this._listener.onProgress(b,c,null,a);else a&&a()};d.prototype._fileExistsSync=function(b){var c=require("fs");try{c.statSync(b)}catch(a){if("ENOENT"==a.code)return!1}return!0};d.prototype._copyFile=function(b,
else c&&c(Error("s3 client not properly initialized"))};m.aio.syncmanager.RemoteDownloader.prototype._mkdir=function(d,b){var c=require("fs");try{c.mkdirSync(d)}catch(a){this._logger.log("warn","creator folder "+d+" error:"+a.message)}b&&b()};m.aio.syncmanager.RemoteDownloader.prototype._deldir=function(d){var b=require("fs"),c=this;b.existsSync(d)&&(b.readdirSync(d).forEach(function(a,e){a=d+"/"+a;b.lstatSync(a).isDirectory()?c._deldir(a):b.unlinkSync(a)}),b.rmdirSync(d))};
m.aio.syncmanager.RemoteDownloader.prototype._decrypt=function(d,b){try{return require("x.crypt.js").AES.decodeString(d,b).trim()}catch(c){return console.log(c),null}};m.aio.syncmanager.RemoteDownloader.prototype._decryptFile=function(d,b){var c=this,a=require("fs"),e=d+".bak";a.rename(d,e,function(f){f?b&&b(f):a.readFile(e,{encoding:"utf8"},function(f,h){f?b&&b(f):(f=c._decrypt(h,c._remotePassword))?a.writeFile(d,f,function(c){c?b&&b(c):a.unlink(e,function(a){b&&b(a)})}):b&&b(Error("decrypt error"))})})};
m.aio.syncmanager.RemoteDownloader=function(d,b){var c=require("x.logger.js");this._logger=c?c.getLogger("RemoteDownloader"):{log:function(){}};this._listener=b;this._host=d.host;this._port=d.port;this._username=d.username?d.username:"";this._password=d.password?d.password:"";this._override="true"==d.override;this._s3cred=d.credential;this._remotePassword=d.remotePassword;this._encrypted=!1;this._s3cred&&(this._s3Client=new (require("aws-sdk").S3)({apiVersion:"2006-03-01",region:"eu-central-1",accessKeyId:d.credential.accessKeyId,
secretAccessKey:d.credential.secretAccessKey,sessionToken:d.credential.sessionToken}))};m.aio.syncmanager.RemoteDownloader.PROTOCOL="https";m.aio.syncmanager.RemoteDownloader.OPTIONS={host:"127.0.0.1",port:8080,path:"",headers:{"Content-Type":'application/json; charset="UTF-8"',"User-Agent":"mediola",Connection:"close"}};
1)&&(c=c.substr(0,c.length-1)),this._parseStatus(c),this._socket.end()))}};g.prototype._parseStatus=function(b){var c=[];$($.parseXML(b)).find("return").each(function(){var b=$(this),d=b.attr("name");b=b.attr("value");c.push({id:d,status:b})});this._finish(null,c)};var f=function(b,c){var d=require("x.logger.js");this._logger=d?d.getLogger("xnm.aio.mcontrol.MControl"):{log:function(){}};this.ip=b;this.port=c;this.port||(this.port=8082)};f.prototype.REQ='<?xml version="1.0"?>\n<mctrlmessage>\n<request name="@1" module="@2">\n@3</request>\n</mctrlmessage>\n';
cmd:"w_p0"}),b.push({id:window.XC_Text.w_p1,cmd:"w_p1"}),b.push({id:window.XC_Text.w_p2,cmd:"w_p2"}),b.push({id:window.XC_Text.w_p3,cmd:"w_p3"}),b.push({id:window.XC_Text.we_p0,cmd:"we_p0"}),b.push({id:window.XC_Text.we_p1,cmd:"we_p1"}),b.push({id:window.XC_Text.we_p2,cmd:"we_p2"}),b.push({id:window.XC_Text.we_p3,cmd:"we_p3"});"digital"==a.data&&(a=this.getDeviceCommandListDigital(),b.push.apply(b,a));return b};d.prototype.getDeviceCommandListDigital=function(){for(var a=[],b=4.8,c=24,e=0;126>e;e++)b+=
.2,c++,a.push({id:window.XC_Text.target_temp+b.toFixed(1),cmd:c});return a};d.prototype.devicemanager=xnm.aio.moehlenhoff.DM;d.prototype.registModule=function(a){for(var b in xnm.aio.moehlenhoff)if(xnm.aio.moehlenhoff.hasOwnProperty(b)){var c=xnm.aio.moehlenhoff[b];c&&c.DM&&c.DM.registModule&&c.DM.registModule(a)}};d.prototype.resolveGateway=function(a){if(!a)return null;switch(a.sys){case xnm.aio.moehlenhoff.Alpha2.DM.SYS:return xnm.aio.moehlenhoff.Alpha2.parseJSON(a);case xnm.aio.moehlenhoff.Alpha2.DM.NEA_SMART_SYS:return xnm.aio.rehau.NeaSmart.parseJSON(a);
JSON.parse(b)}catch(g){a=g,a.code=303}a||b&&"success"==b.status||(a=Error("request upload response error:"+b.message),a.code=301);a&&!a.code&&(a.code=300);c&&c(a)})})};d.prototype._reportProgress=function(b,c,a){if(this._listener&&this._listener.onProgress)this._listener.onProgress(b,c,null,a);else a&&a()};d.prototype._fileExistsSync=function(b){var c=require("fs");try{c.statSync(b)}catch(a){if("ENOENT"==a.code)return!1}return!0};d.prototype._doRequest=function(b,c,a,e,d){var f=d;d=require(m.aio.syncmanager.PROTOCOL);
generateRemoteUploadReq:function(d,b,c){this.generateRemoteDownloadRsp(d,b,"from_upload_req",c)},_getRemoteInfo:function(d,b){var c=require("unorm"),a=d.getFolderPath(),e={name:c.nfc(d.id),resources:[]};this._getFilesInfos(a,function(a,c){a?b&&b(a):(c&&(e.resources=c),b&&b(null,e))})},_getRemoteDatabaseInfo:function(d,b,c){var a=this,e=d.getFolderPath(),f=require("async"),g=require("fs"),h=require("fs-extra");f.parallel([function(c){var f=d.getDeviceFile();f?g.exists(f,function(d){d?a._getFileInfos(f,
"download zip file error:"+d.stack),c&&c(d)):a._unzipFile(e,function(d,e){d?(a._logger.log("trace","unzip file error:"+d.stack),c&&c(d)):a._reloadUserDB(e,b,function(b){b&&a._logger.log("trace","reload user database error:"+b.stack);c&&c(b)})})})})};d.prototype._requestDownload=function(b){var c=this;this._reportProgress(0,"send download request",function(){c._logger.log("trace","send download user database request.");c._doRequest("GET","/creatorneo/userdb/requestDownload",null,null,function(a,c){if(c)try{c=
JSON.parse(c)}catch(f){a=f,a.code=103}a||(c&&"success"==c.status?c.result&&c.result.ref&&c.result.credential||(a=Error("request download response foramt error"),a.code=102):(a=Error("request download response error:"+c.message),a.code=101));a&&!a.code&&(a.code=100);b&&b(a,c.result)})})};d.prototype._downloadZip=function(b,c){var a=this;this._reportProgress(1,"download zip file",function(){a._logger.log("trace","download zip file with ref:"+b.ref);var d=require("m.aio.filemanager.js"),f=require("path"),
e.parallel([function(b){var e=d.getDeviceFile();e?f.exists(e,function(d){d?c._getFileInfos(e,a,function(a,c){b(a,c)}):b()}):b()},function(b){var e=d.getMacrosFile();e?f.exists(e,function(d){d?c._getFileInfos(e,a,function(a,c){b(a,c)}):b()}):b()},function(b){var e=d.getDeviceinfoFile();e?f.exists(e,function(d){d?c._getFileInfos(e,a,function(a,c){b(a,c)}):b()}):b()}],function(a,c){var e=[];c&&c.forEach(function(a){a&&e.push(a)});b&&b(a,e)})},_listAllFiles:function(d,b){var c=require("fs"),a=require("path"),
m.aio.syncmanager.RemotesDownloader.prototype.download=function(d,b){this._logger.log("debug","download remotes from account:"+this._username);var c=this;this._doRemoteDownloadReq(function(a,e){a?b&&b(a):e.infos?0==e.infos.length?b&&b():c._doDownloadRemotes(d,e.credential,e.infos,function(a){b&&b(a)}):b&&b(Error("download response format invalid"))})};
Exemple #19
0
var Logger=require("x.logger.js"),x=x||{};x.EventEmitter=function(){this._events=this._events||{};this._maxListeners=this._maxListeners||x.EventEmitter.defaultMaxListeners};x.EventEmitter._logger=Logger.getLogger("x.EventEmitter");x.EventEmitter.defaultMaxListeners=10;x.EventEmitter.prototype.setMaxListeners=function(b){if("number"!==typeof b||0>b||isNaN(b))throw new TypeError("n must be a positive number");this._maxListeners=b};
x.EventEmitter.prototype.emit=function(b){var a;this._events||(this._events={});if("error"===b&&(!this._events.error||"object"===typeof this._events.error&&!this._events.error.length)){var c=arguments[1];if(c instanceof Error)throw c;throw new TypeError('Uncaught, unspecified "error" event.');}var d=this._events[b];if("undefined"===typeof d)return!1;if("function"===typeof d)switch(arguments.length){case 1:d.call(this);break;case 2:d.call(this,arguments[1]);break;case 3:d.call(this,arguments[1],arguments[2]);
break;default:c=arguments.length;var e=Array(c-1);for(a=1;a<c;a++)e[a-1]=arguments[a];d.apply(this,e)}else if("object"===typeof d){c=arguments.length;e=Array(c-1);for(a=1;a<c;a++)e[a-1]=arguments[a];d=d.slice();c=d.length;for(a=0;a<c;a++)d[a].apply(this,e)}return!0};
x.EventEmitter.prototype.addListener=function(b,a){if("function"!==typeof a)throw new TypeError("listener must be a function");this._events||(this._events={});this._events.newListener&&this.emit("newListener",b,"function"===typeof a.listener?a.listener:a);this._events[b]?"object"===typeof this._events[b]?this._events[b].push(a):this._events[b]=[this._events[b],a]:this._events[b]=a;"object"!==typeof this._events[b]||this._events[b].warned||(a=this._maxListeners)&&0<a&&this._events[b].length>a&&(this._events[b].warned=
!0,x.EventEmitter._logger.log("warn",Error("(node) warning: possible EventEmitter memory leak detected. "+this._events[b].length+" listeners added. Use emitter.setMaxListeners() to increase limit.").stack));return this};x.EventEmitter.prototype.on=x.EventEmitter.prototype.addListener;
x.EventEmitter.prototype.once=function(b,a){function c(){this.removeListener(b,c);d||(d=!0,a.apply(this,arguments))}if("function"!==typeof a)throw new TypeError("listener must be a function");var d=!1;c.listener=a;this.on(b,c);return this};
x.EventEmitter.prototype.removeListener=function(b,a){if("function"!==typeof a)throw new TypeError("listener must be a function");if(!this._events||!this._events[b])return this;var c=this._events[b];var d=c.length;var e=-1;if(c===a||"function"===typeof c.listener&&c.listener===a)delete this._events[b],this._events.removeListener&&this.emit("removeListener",b,a);else if("object"===typeof c){for(;0<d--;)if(c[d]===a||c[d].listener&&c[d].listener===a){e=d;break}if(0>e)return this;1===c.length?(c.length=
0,delete this._events[b]):c.splice(e,1);this._events.removeListener&&this.emit("removeListener",b,a)}return this};
x.EventEmitter.prototype.removeAllListeners=function(b){if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[b]&&delete this._events[b],this;if(0===arguments.length){for(a in this._events)"removeListener"!==a&&this.removeAllListeners(a);this.removeAllListeners("removeListener");this._events={};return this}var a=this._events[b];if("function"===typeof a)this.removeListener(b,a);else if(Array.isArray(a))for(;a.length;)this.removeListener(b,
a[a.length-1]);delete this._events[b];return this};x.EventEmitter.prototype.listeners=function(b){return this._events&&this._events[b]?"function"===typeof this._events[b]?[this._events[b]]:this._events[b].slice():[]};x.EventEmitter.listenerCount=function(b,a){return b._events&&b._events[a]?"function"===typeof b._events[a]?1:b._events[a].length:0};exports&&(exports.EventEmitter=x.EventEmitter);