73cc7a1008f9193b0804ee514ec300e4afbcad7d
[motion.git] / server / config / scheduler / reports.js
1 var _0x9227=["\x63\x68\x69\x6C\x64\x5F\x70\x72\x6F\x63\x65\x73\x73","\x6D\x6F\x6D\x65\x6E\x74","\x6D\x6F\x6D\x65\x6E\x74\x2D\x72\x61\x6E\x67\x65","\x2E\x2E\x2F\x75\x74\x69\x6C","\x43\x75\x73\x74\x6F\x6D\x52\x65\x70\x6F\x72\x74","\x2E\x2E\x2F\x2E\x2E\x2F\x6D\x6F\x64\x65\x6C\x73","\x44\x65\x66\x61\x75\x6C\x74\x52\x65\x70\x6F\x72\x74","\x45\x78\x74\x72\x61\x63\x74\x65\x64\x52\x65\x70\x6F\x72\x74","\x4D\x61\x69\x6C\x41\x74\x74\x61\x63\x68\x6D\x65\x6E\x74","\x4D\x61\x69\x6C\x53\x65\x72\x76\x65\x72\x4F\x75\x74","\x4D\x61\x69\x6C\x41\x63\x63\x6F\x75\x6E\x74","\x4D\x61\x69\x6C\x4D\x65\x73\x73\x61\x67\x65","\x70\x61\x74\x68","\x2E\x2E\x2F\x2E\x2E\x2F\x63\x6F\x6E\x66\x69\x67\x2F\x65\x6E\x76\x69\x72\x6F\x6E\x6D\x65\x6E\x74","\x66\x73\x2D\x65\x78\x74\x72\x61","\x6C\x6F\x64\x61\x73\x68","\x52\x65\x70\x6F\x72\x74\x54\x72\x65\x65","\x52\x65\x70\x6F\x72\x74\x73\x20\x73\x63\x68\x65\x64\x75\x6C\x65\x73\x20\x6C\x61\x75\x6E\x63\x68\x65\x72\x20\x49\x6E\x69\x74\x69\x61\x6C\x69\x7A\x61\x74\x69\x6F\x6E\x2E\x2E\x2E","\x6C\x6F\x67","\x65\x78\x74\x72\x61\x63\x74\x52\x65\x70\x6F\x72\x74","\x70\x72\x6F\x74\x6F\x74\x79\x70\x65","\x45\x78\x74\x72\x61\x63\x74\x69\x6E\x67\x20\x72\x65\x70\x6F\x72\x74\x2E\x2E\x2E","\x63\x75\x72\x72\x65\x6E\x74\x44\x61\x79","\x63\x72\x6F\x6E\x54\x79\x70\x65","\x43\x68\x65\x63\x6B\x69\x6E\x67\x20\x74\x6F\x64\x61\x79\x20\x73\x63\x68\x65\x64\x75\x6C\x65\x20\x72\x61\x6E\x67\x65\x20\x76\x61\x6C\x69\x64\x69\x74\x79\x2E\x2E\x2E","\x76\x61\x6C\x69\x64\x69\x74\x79\x53\x74\x61\x72\x74","\x76\x61\x6C\x69\x64\x69\x74\x79\x45\x6E\x64","\x54\x68\x65\x20\x68\x6F\x75\x72\x73\x20\x72\x61\x6E\x67\x65\x20\x69\x73\x20\x76\x61\x6C\x69\x64\x2C\x20\x65\x78\x74\x72\x61\x63\x74\x69\x6E\x67\x20\x74\x6F\x64\x61\x79\x20\x72\x65\x70\x6F\x72\x74\x2E\x2E\x2E","\x59\x59\x59\x59\x2D\x4D\x4D\x2D\x44\x44","\x66\x6F\x72\x6D\x61\x74","\x30\x30\x3A\x30\x30","\x32\x33\x3A\x35\x39","\x4F\x75\x74\x20\x6F\x66\x20\x68\x6F\x75\x72\x73\x20\x72\x61\x6E\x67\x65\x2C\x20\x73\x6B\x69\x70\x70\x69\x6E\x67\x20\x72\x65\x63\x6F\x72\x64\x20\x65\x78\x74\x72\x61\x63\x74\x69\x6F\x6E\x21","\x64\x61\x79\x73","\x73\x75\x62\x74\x72\x61\x63\x74","\x79\x65\x73\x74\x65\x72\x64\x61\x79","\x6C\x61\x73\x74\x37","\x6C\x61\x73\x74\x33\x30","\x6D\x6F\x6E\x74\x68","\x73\x74\x61\x72\x74\x4F\x66","\x6D\x6F\x6E\x74\x68\x73","\x65\x6E\x64\x4F\x66","\x6C\x61\x73\x74\x4D\x6F\x6E\x74\x68","\x72\x65\x70\x6F\x72\x74\x52\x61\x6E\x67\x65","\x63\x6F\x6E\x74\x61\x69\x6E\x73","\x68","\x72\x61\x6E\x67\x65","\x74\x65\x78\x74","\x2F\x20","\x70\x61\x72\x65\x6E\x74","\x23","\x66\x69\x6E\x64","\x72\x65\x70\x6F\x72\x74\x54\x79\x70\x65","\x64\x65\x66\x61\x75\x6C\x74","\x53\x63\x68\x65\x64\x75\x6C\x65\x64\x20\x72\x65\x70\x6F\x72\x74\x20\x65\x78\x74\x72\x61\x63\x74\x69\x6F\x6E\x20\x65\x72\x72\x6F\x72\x3A\x20","\x63\x61\x74\x63\x68","\x2F\x2E\x2E\x2F\x2E\x2E\x2F\x75\x74\x69\x6C\x73\x2F\x72\x65\x70\x6F\x72\x74\x5F\x65\x78\x74\x72\x61\x63\x74\x69\x6F\x6E\x2E\x6A\x73","\x66\x6F\x72\x6B","\x65\x72\x72\x6F\x72","\x63\x68\x69\x6C\x64\x20\x65\x72\x72\x6F\x72","\x6F\x6E","\x63\x6C\x6F\x73\x65","\x63\x68\x69\x6C\x64\x20\x63\x6C\x6F\x73\x65","\x6D\x65\x73\x73\x61\x67\x65","\x63\x68\x69\x6C\x64\x20\x6D\x65\x73\x73\x61\x67\x65","\x73\x65\x6E\x64\x4D\x61\x69\x6C","\x73\x74\x61\x74\x75\x73","\x63\x6F\x6D\x70\x6C\x65\x74\x65\x64","\x69\x64","\x6B\x69\x6C\x6C","\x61\x64\x6D\x69\x6E","\x72\x65\x70\x6F\x72\x74\x4F\x75\x74\x70\x75\x74","\x73\x65\x6E\x64","\x73\x70\x72\x65\x61\x64","\x74\x72\x65\x65","\x70\x61\x72\x73\x65","\x6E\x61\x6D\x65","\x74\x61\x62\x6C\x65","\x64\x61\x74\x61\x56\x61\x6C\x75\x65\x73","\x5F\x68\x69\x73\x74\x6F\x72\x79","","\x72\x65\x70\x6C\x61\x63\x65","\x6D\x61\x6E\x75\x61\x6C","\x73\x63\x68\x65\x64\x75\x6C\x65\x64","\x63\x72\x65\x61\x74\x65","\x74\x68\x65\x6E","\x52\x65\x70\x6F\x72\x74\x20\x6E\x6F\x74\x20\x66\x6F\x75\x6E\x64\x21","\x66\x69\x6E\x64\x42\x79\x49\x64","\x72\x65\x70\x6F\x72\x74\x49\x64","\x66\x69\x65\x6C\x64\x73","\x73\x63\x6F\x70\x65","\x66\x69\x6E\x61\x6C\x6C\x79","\x45\x72\x72\x6F\x72\x20\x73\x65\x6E\x64\x69\x6E\x67\x20\x65\x78\x74\x72\x61\x63\x74\x65\x64\x20\x72\x65\x70\x6F\x72\x74\x20\x62\x79\x20\x6D\x61\x69\x6C\x21","\x53\x63\x68\x65\x64\x75\x6C\x65\x64\x20\x6D\x65\x73\x73\x61\x67\x65\x20\x73\x65\x6E\x74\x21","\x73\x65\x74\x4D\x61\x69\x6C\x4D\x65\x73\x73\x61\x67\x65","\x53\x63\x68\x65\x64\x75\x6C\x65\x64\x20\x52\x65\x70\x6F\x72\x74","\x61\x64\x64\x72\x65\x73\x73","\x65\x6D\x61\x69\x6C","\x41\x20\x6E\x65\x77\x20\x72\x65\x70\x6F\x72\x74\x20\x68\x61\x73\x20\x62\x65\x65\x6E\x20\x63\x72\x65\x61\x74\x65\x64\x2C\x20\x79\x6F\x75\x20\x63\x61\x6E\x20\x63\x68\x65\x63\x6B\x20\x74\x68\x65\x20\x61\x74\x74\x61\x63\x68\x65\x64\x20\x66\x69\x6C\x65\x2E","\x53\x45\x4E\x44\x49\x4E\x47","\x45\x78\x74\x72\x61\x63\x74\x65\x64\x20\x72\x65\x70\x6F\x72\x74\x20\x6E\x6F\x74\x20\x66\x6F\x75\x6E\x64\x21","\x75\x73\x65\x72\x6E\x61\x6D\x65","\x4E\x6F\x20\x41\x63\x63\x6F\x75\x6E\x74\x20\x6F\x72\x20\x53\x4D\x54\x50\x20\x61\x64\x64\x72\x65\x73\x73\x20\x63\x6F\x6E\x66\x69\x67\x75\x72\x65\x64","\x72\x6F\x6F\x74","\x73\x65\x72\x76\x65\x72","\x66\x69\x6C\x65\x73","\x72\x65\x70\x6F\x72\x74\x73","\x73\x61\x76\x65\x6E\x61\x6D\x65","\x6A\x6F\x69\x6E","\x61\x74\x74\x61\x63\x68\x6D\x65\x6E\x74\x73","\x2E","\x74\x6F\x4C\x6F\x77\x65\x72\x43\x61\x73\x65","\x6F\x75\x74\x70\x75\x74","\x62\x61\x73\x65\x6E\x61\x6D\x65","\x63\x6F\x70\x79\x53\x79\x6E\x63","\x73\x75\x63\x63\x65\x73\x73\x21","\x45\x72\x72\x6F\x72\x20\x67\x65\x74\x74\x69\x6E\x67\x20\x74\x68\x65\x20\x65\x78\x74\x72\x61\x63\x74\x65\x64\x20\x72\x65\x70\x6F\x72\x74\x20\x61\x74\x74\x61\x63\x68\x6D\x65\x6E\x74\x21","\x67\x65\x74\x46\x69\x6C\x65\x53\x69\x7A\x65","\x5F","\x44\x44\x2D\x4D\x4D\x2D\x59\x59\x59\x59","\x73\x74\x61\x72\x74\x44\x61\x74\x65","\x65\x6E\x64\x44\x61\x74\x65","\x61\x70\x70\x6C\x69\x63\x61\x74\x69\x6F\x6E\x2F","\x65\x78\x70\x6F\x72\x74\x73"];var cp=require(_0x9227[0]);var moment=require(_0x9227[1]);require(_0x9227[2]);var Util=require(_0x9227[3]);var CustomReport=require(_0x9227[5])[_0x9227[4]];var DefaultReport=require(_0x9227[5])[_0x9227[6]];var ExtractedReport=require(_0x9227[5])[_0x9227[7]];var MailAttachment=require(_0x9227[5])[_0x9227[8]];var MailServerOut=require(_0x9227[5])[_0x9227[9]];var MailAccount=require(_0x9227[5])[_0x9227[10]];var MailMessage=require(_0x9227[5])[_0x9227[11]];var path=require(_0x9227[12]);var config=require(_0x9227[13]);var fs=require(_0x9227[14]);var _=require(_0x9227[15]);var ReportTree=require(_0x9227[5])[_0x9227[16]];function Reports(){console[_0x9227[18]](_0x9227[17])}Reports[_0x9227[20]][_0x9227[19]]= function(_0x2456x11,_0x2456x12){console[_0x9227[18]](_0x9227[21]);extract(_0x2456x11,_0x2456x12)};function extract(_0x2456x11,_0x2456x12){switch(_0x2456x11[_0x9227[23]]){case _0x9227[22]:extractTodayReport(_0x2456x11,_0x2456x12);break;default:extractRangeReport(_0x2456x11,_0x2456x12);break}}function extractTodayReport(_0x2456x11,_0x2456x12){console[_0x9227[18]](_0x9227[24]);if(_0x2456x12|| checkValidity(_0x2456x11[_0x9227[25]],_0x2456x11[_0x9227[26]])){console[_0x9227[18]](_0x9227[27]);docExtract(_0x2456x11,moment()[_0x9227[29]](_0x9227[28]),moment()[_0x9227[29]](_0x9227[28]),_0x2456x12,_0x9227[30],_0x9227[31])}else {console[_0x9227[18]](_0x9227[32])}}function extractRangeReport(_0x2456x11,_0x2456x12){switch(_0x2456x11[_0x9227[43]]){case _0x9227[35]:docExtract(_0x2456x11,moment()[_0x9227[34]](1,_0x9227[33])[_0x9227[29]](_0x9227[28]),moment()[_0x9227[34]](1,_0x9227[33])[_0x9227[29]](_0x9227[28]),_0x2456x12);break;case _0x9227[36]:docExtract(_0x2456x11,moment()[_0x9227[34]](7,_0x9227[33])[_0x9227[29]](_0x9227[28]),moment()[_0x9227[34]](1,_0x9227[33])[_0x9227[29]](_0x9227[28]),_0x2456x12);break;case _0x9227[37]:docExtract(_0x2456x11,moment()[_0x9227[34]](30,_0x9227[33])[_0x9227[29]](_0x9227[28]),moment()[_0x9227[34]](1,_0x9227[33])[_0x9227[29]](_0x9227[28]),_0x2456x12);break;case _0x9227[42]:docExtract(_0x2456x11,moment()[_0x9227[34]](1,_0x9227[40])[_0x9227[39]](_0x9227[38])[_0x9227[29]](_0x9227[28]),moment()[_0x9227[34]](1,_0x9227[40])[_0x9227[41]](_0x9227[38])[_0x9227[29]](_0x9227[28]),_0x2456x12);break}}function checkValidity(_0x2456x17,_0x2456x18){return moment()[_0x9227[46]](moment(_0x2456x17,_0x9227[45]),moment(_0x2456x18,_0x9227[45]))[_0x9227[44]](moment())}function getReportPath(_0x2456x1a,_0x2456x1b,path){path= _0x2456x1a[_0x9227[47]]+ _0x9227[48]+ path;if(_0x2456x1a[_0x9227[49]]=== _0x9227[50]){return path}else {return getReportPath(_[_0x9227[51]](_0x2456x1b,{id:_0x2456x1a[_0x9227[49]]}),_0x2456x1b,path)}}function docExtract(_0x2456x11,_0x2456x1d,_0x2456x1e,_0x2456x12,_0x2456x1f,_0x2456x20){var _0x2456x21=_0x2456x11[_0x9227[52]]=== _0x9227[53]?DefaultReport:CustomReport;var _0x2456x22;_0x2456x21[_0x9227[90]](_0x9227[89])[_0x9227[87]](_0x2456x11[_0x9227[88]])[_0x9227[85]](function(_0x2456x27){if(!_0x2456x27){console[_0x9227[18]](_0x9227[86]);return};_0x2456x22= _0x2456x27;return ReportTree[_0x9227[87]](_0x2456x11[_0x9227[52]]=== _0x9227[53]?1:2)})[_0x9227[85]](function(_0x2456x1b){_0x2456x1b= JSON[_0x9227[75]](_0x2456x1b[_0x9227[74]]);var _0x2456x1a=_[_0x9227[51]](_0x2456x1b,{id:_0x2456x22[_0x9227[49]]});var path=getReportPath(_0x2456x1a,_0x2456x1b,_0x2456x22[_0x9227[76]]);if(_0x2456x11[_0x9227[23]]=== _0x9227[22]){_0x2456x22[_0x9227[78]][_0x9227[77]]= _0x2456x22[_0x9227[78]][_0x9227[77]][_0x9227[81]](_0x9227[79],_0x9227[80])};return [_0x2456x22,ExtractedReport[_0x9227[84]]({name:_0x2456x22[_0x9227[76]],startDate:_0x2456x1d,endDate:_0x2456x1e,output:_0x2456x11[_0x9227[71]],type:_0x2456x12?_0x9227[82]:_0x9227[83],UserId:_0x2456x12?_0x2456x12[_0x9227[68]]:null})]})[_0x9227[73]](function(_0x2456x22,_0x2456x24){var _0x2456x25=cp[_0x9227[57]](__dirname+ _0x9227[56]);_0x2456x25[_0x9227[60]](_0x9227[63],function(_0x2456x26){console[_0x9227[18]](_0x9227[64],_0x2456x26);if(_0x2456x11[_0x9227[65]]&& _0x2456x26[_0x9227[66]]=== _0x9227[67]){sendReportByMail(_0x2456x11,_0x2456x24[_0x9227[68]],_0x2456x12,_0x2456x25)}else {_0x2456x25[_0x9227[69]]()}})[_0x9227[60]](_0x9227[61],function(){console[_0x9227[18]](_0x9227[62])})[_0x9227[60]](_0x9227[58],function(_0x2456x23){console[_0x9227[18]](_0x9227[59],_0x2456x23)});_0x2456x25[_0x9227[72]]({report:_0x2456x22,query:{startDate:_0x2456x1d,endDate:_0x2456x1e,startTime:_0x2456x1f|| null,endTime:_0x2456x20|| null},extractedId:_0x2456x24[_0x9227[68]],user:_0x2456x12?_0x2456x12:{role:_0x9227[70]},type:_0x2456x11[_0x9227[71]]})})[_0x9227[55]](function(_0x2456x23){console[_0x9227[18]](_0x9227[54],_0x2456x23)})}function sendReportByMail(_0x2456x11,_0x2456x29,_0x2456x12,_0x2456x25){var _0x2456x2a;return ExtractedReport[_0x9227[87]](_0x2456x29)[_0x9227[85]](function(extract){if(!extract){throw  new Error(_0x9227[100])};_0x2456x2a= extract;if(_0x2456x11[_0x9227[9]]&& _0x2456x11[_0x9227[9]][_0x9227[68]]){return MailAccount[_0x9227[51]]({attributes:[_0x9227[68],_0x9227[96]],include:[{model:MailServerOut,attributes:[_0x9227[68],_0x9227[101]],where:{id:_0x2456x11[_0x9227[9]][_0x9227[68]]}}]})}else {throw  new Error(_0x9227[102])}})[_0x9227[85]](function(_0x2456x2c){var _0x2456x2d=getAttachment(_0x2456x2a);var _0x2456x2e={subject:_0x9227[95],from:[_0x2456x2c[_0x9227[96]]],to:[_0x2456x11[_0x9227[97]]],cc:[],html:_0x9227[98],text:null,inReplyTo:null,status:_0x9227[99],attachment:true,UserId:_0x2456x12?_0x2456x12[_0x9227[68]]:null,MailAttachments:[_0x2456x2d]};return MailMessage[_0x9227[84]](_0x2456x2e,{include:[{model:MailAttachment}]})})[_0x9227[85]](function(_0x2456x2b){return _0x2456x2a[_0x9227[94]](_0x2456x2b)})[_0x9227[85]](function(){console[_0x9227[18]](_0x9227[93])})[_0x9227[55]](function(_0x2456x23){console[_0x9227[18]](_0x9227[92],_0x2456x23)})[_0x9227[91]](function(){_0x2456x25[_0x9227[69]]()})}function getAttachment(extract){var _0x2456x30=path[_0x9227[108]](config[_0x9227[103]],_0x9227[104],_0x9227[105],_0x9227[106],extract[_0x9227[107]]);var _0x2456x31=path[_0x9227[108]](config[_0x9227[103]],_0x9227[104],_0x9227[105],_0x9227[109]);var _0x2456x32=path[_0x9227[113]](extract[_0x9227[107]],_0x9227[110]+ extract[_0x9227[112]][_0x9227[111]]());try{fs[_0x9227[114]](_0x2456x30,path[_0x9227[108]](_0x2456x31,_0x2456x32));console[_0x9227[18]](_0x9227[115])}catch(err){console[_0x9227[58]](_0x9227[116]);return null};return {size:Util[_0x9227[117]](_0x2456x30),path:path[_0x9227[108]](_0x2456x31,_0x2456x32),name:extract[_0x9227[76]]+ _0x9227[118]+ moment(extract[_0x9227[120]])[_0x9227[29]](_0x9227[119])+ _0x9227[118]+ moment(extract[_0x9227[121]])[_0x9227[29]](_0x9227[119])+ _0x9227[110]+ extract[_0x9227[112]][_0x9227[111]](),type:_0x9227[122]+ extract[_0x9227[112]][_0x9227[111]](),basename:_0x2456x32}}module[_0x9227[123]]= Reports