83a2a6a78f8a9c3486ea9e43f953640d2a698874
[motion.git] / server / config / scheduler / reports.js
1 var _0x4daa=["\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","\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\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","\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","\x53\x63\x68\x65\x64\x75\x6C\x65\x64\x20\x52\x65\x70\x6F\x72\x74","\x65\x6D\x61\x69\x6C","\x53\x45\x4E\x44\x49\x4E\x47","\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","\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","\x73\x74\x61\x74\x53\x79\x6E\x63","\x73\x69\x7A\x65","\x65\x78\x70\x6F\x72\x74\x73"];var cp=require(_0x4daa[0]);var moment=require(_0x4daa[1]);require(_0x4daa[2]);var CustomReport=require(_0x4daa[4])[_0x4daa[3]];var DefaultReport=require(_0x4daa[4])[_0x4daa[5]];var ExtractedReport=require(_0x4daa[4])[_0x4daa[6]];var MailAttachment=require(_0x4daa[4])[_0x4daa[7]];var MailServerOut=require(_0x4daa[4])[_0x4daa[8]];var MailMessage=require(_0x4daa[4])[_0x4daa[9]];var path=require(_0x4daa[10]);var config=require(_0x4daa[11]);var fs=require(_0x4daa[12]);var _=require(_0x4daa[13]);var ReportTree=require(_0x4daa[4])[_0x4daa[14]];function Reports(){console[_0x4daa[16]](_0x4daa[15])}Reports[_0x4daa[18]][_0x4daa[17]]= function(_0xb7fdxf,_0xb7fdx10){console[_0x4daa[16]](_0x4daa[19]);extract(_0xb7fdxf,_0xb7fdx10)};function extract(_0xb7fdxf,_0xb7fdx10){switch(_0xb7fdxf[_0x4daa[21]]){case _0x4daa[20]:extractTodayReport(_0xb7fdxf,_0xb7fdx10);break;default:extractRangeReport(_0xb7fdxf,_0xb7fdx10);break}}function extractTodayReport(_0xb7fdxf,_0xb7fdx10){console[_0x4daa[16]](_0x4daa[22]);if(_0xb7fdx10|| checkValidity(_0xb7fdxf[_0x4daa[23]],_0xb7fdxf[_0x4daa[24]])){console[_0x4daa[16]](_0x4daa[25]);docExtract(_0xb7fdxf,moment()[_0x4daa[27]](_0x4daa[26]),moment()[_0x4daa[27]](_0x4daa[26]),_0xb7fdx10,_0x4daa[28],_0x4daa[29])}else {console[_0x4daa[16]](_0x4daa[30])}}function extractRangeReport(_0xb7fdxf,_0xb7fdx10){switch(_0xb7fdxf[_0x4daa[41]]){case _0x4daa[33]:docExtract(_0xb7fdxf,moment()[_0x4daa[32]](1,_0x4daa[31])[_0x4daa[27]](_0x4daa[26]),moment()[_0x4daa[32]](1,_0x4daa[31])[_0x4daa[27]](_0x4daa[26]),_0xb7fdx10);break;case _0x4daa[34]:docExtract(_0xb7fdxf,moment()[_0x4daa[32]](7,_0x4daa[31])[_0x4daa[27]](_0x4daa[26]),moment()[_0x4daa[32]](1,_0x4daa[31])[_0x4daa[27]](_0x4daa[26]),_0xb7fdx10);break;case _0x4daa[35]:docExtract(_0xb7fdxf,moment()[_0x4daa[32]](30,_0x4daa[31])[_0x4daa[27]](_0x4daa[26]),moment()[_0x4daa[32]](1,_0x4daa[31])[_0x4daa[27]](_0x4daa[26]),_0xb7fdx10);break;case _0x4daa[40]:docExtract(_0xb7fdxf,moment()[_0x4daa[32]](1,_0x4daa[38])[_0x4daa[37]](_0x4daa[36])[_0x4daa[27]](_0x4daa[26]),moment()[_0x4daa[32]](1,_0x4daa[38])[_0x4daa[39]](_0x4daa[36])[_0x4daa[27]](_0x4daa[26]),_0xb7fdx10);break}}function checkValidity(_0xb7fdx15,_0xb7fdx16){return moment()[_0x4daa[44]](moment(_0xb7fdx15,_0x4daa[43]),moment(_0xb7fdx16,_0x4daa[43]))[_0x4daa[42]](moment())}function getReportPath(_0xb7fdx18,_0xb7fdx19,path){path= _0xb7fdx18[_0x4daa[45]]+ _0x4daa[46]+ path;if(_0xb7fdx18[_0x4daa[47]]=== _0x4daa[48]){return path}else {return getReportPath(_[_0x4daa[49]](_0xb7fdx19,{id:_0xb7fdx18[_0x4daa[47]]}),_0xb7fdx19,path)}}function docExtract(_0xb7fdxf,_0xb7fdx1b,_0xb7fdx1c,_0xb7fdx10,_0xb7fdx1d,_0xb7fdx1e){var _0xb7fdx1f=_0xb7fdxf[_0x4daa[50]]=== _0x4daa[51]?DefaultReport:CustomReport;var _0xb7fdx20;_0xb7fdx1f[_0x4daa[88]](_0x4daa[87])[_0x4daa[85]](_0xb7fdxf[_0x4daa[86]])[_0x4daa[83]](function(_0xb7fdx25){if(!_0xb7fdx25){console[_0x4daa[16]](_0x4daa[84]);return};_0xb7fdx20= _0xb7fdx25;return ReportTree[_0x4daa[85]](_0xb7fdxf[_0x4daa[50]]=== _0x4daa[51]?1:2)})[_0x4daa[83]](function(_0xb7fdx19){_0xb7fdx19= JSON[_0x4daa[73]](_0xb7fdx19[_0x4daa[72]]);var _0xb7fdx18=_[_0x4daa[49]](_0xb7fdx19,{id:_0xb7fdx20[_0x4daa[47]]});var path=getReportPath(_0xb7fdx18,_0xb7fdx19,_0xb7fdx20[_0x4daa[74]]);if(_0xb7fdxf[_0x4daa[21]]=== _0x4daa[20]){_0xb7fdx20[_0x4daa[76]][_0x4daa[75]]= _0xb7fdx20[_0x4daa[76]][_0x4daa[75]][_0x4daa[79]](_0x4daa[77],_0x4daa[78])};return [_0xb7fdx20,ExtractedReport[_0x4daa[82]]({name:_0xb7fdx20[_0x4daa[74]],startDate:_0xb7fdx1b,endDate:_0xb7fdx1c,output:_0xb7fdxf[_0x4daa[69]],type:_0xb7fdx10?_0x4daa[80]:_0x4daa[81],UserId:_0xb7fdx10?_0xb7fdx10[_0x4daa[66]]:null})]})[_0x4daa[71]](function(_0xb7fdx20,_0xb7fdx22){var _0xb7fdx23=cp[_0x4daa[55]](__dirname+ _0x4daa[54]);_0xb7fdx23[_0x4daa[58]](_0x4daa[61],function(_0xb7fdx24){console[_0x4daa[16]](_0x4daa[62],_0xb7fdx24);if(_0xb7fdxf[_0x4daa[63]]&& _0xb7fdx24[_0x4daa[64]]=== _0x4daa[65]){sendReportByMail(_0xb7fdxf,_0xb7fdx22[_0x4daa[66]],_0xb7fdx10,_0xb7fdx23)}else {_0xb7fdx23[_0x4daa[67]]()}})[_0x4daa[58]](_0x4daa[59],function(){console[_0x4daa[16]](_0x4daa[60])})[_0x4daa[58]](_0x4daa[56],function(_0xb7fdx21){console[_0x4daa[16]](_0x4daa[57],_0xb7fdx21)});_0xb7fdx23[_0x4daa[70]]({report:_0xb7fdx20,query:{startDate:_0xb7fdx1b,endDate:_0xb7fdx1c,startTime:_0xb7fdx1d|| null,endTime:_0xb7fdx1e|| null},extractedId:_0xb7fdx22[_0x4daa[66]],user:_0xb7fdx10?_0xb7fdx10:{role:_0x4daa[68]},type:_0xb7fdxf[_0x4daa[69]]})})[_0x4daa[53]](function(_0xb7fdx21){console[_0x4daa[16]](_0x4daa[52],_0xb7fdx21)})}function sendReportByMail(_0xb7fdxf,_0xb7fdx27,_0xb7fdx10,_0xb7fdx23){var _0xb7fdx28;return ExtractedReport[_0x4daa[85]](_0xb7fdx27)[_0x4daa[83]](function(extract){if(!extract){console[_0x4daa[16]](_0x4daa[93]);return};_0xb7fdx28= extract;if(_0xb7fdxf[_0x4daa[8]]&& _0xb7fdxf[_0x4daa[8]][_0x4daa[94]]){var _0xb7fdx2a=getAttachment(_0xb7fdx28);var _0xb7fdx2b={subject:_0x4daa[95],from:[_0xb7fdxf[_0x4daa[8]][_0x4daa[94]]],to:[_0xb7fdxf[_0x4daa[96]]],cc:[],html:null,text:null,inReplyTo:null,status:_0x4daa[97],attachment:true,UserId:_0xb7fdx10?_0xb7fdx10[_0x4daa[66]]:null,MailAttachments:[_0xb7fdx2a]};return MailMessage[_0x4daa[82]](_0xb7fdx2b,{include:[{model:MailAttachment}]})}else {throw  new Error(_0x4daa[98])}})[_0x4daa[83]](function(_0xb7fdx29){return _0xb7fdx28[_0x4daa[92]](_0xb7fdx29)})[_0x4daa[83]](function(){console[_0x4daa[16]](_0x4daa[91])})[_0x4daa[53]](function(_0xb7fdx21){console[_0x4daa[16]](_0x4daa[90],_0xb7fdx21)})[_0x4daa[89]](function(){_0xb7fdx23[_0x4daa[67]]()})}function getAttachment(extract){var _0xb7fdx2d=path[_0x4daa[104]](config[_0x4daa[99]],_0x4daa[100],_0x4daa[101],_0x4daa[102],extract[_0x4daa[103]]);var _0xb7fdx2e=path[_0x4daa[104]](config[_0x4daa[99]],_0x4daa[100],_0x4daa[101],_0x4daa[105]);var _0xb7fdx2f=path[_0x4daa[109]](extract[_0x4daa[103]],_0x4daa[106]+ extract[_0x4daa[108]][_0x4daa[107]]());try{fs[_0x4daa[110]](_0xb7fdx2d,path[_0x4daa[104]](_0xb7fdx2e,_0xb7fdx2f));console[_0x4daa[16]](_0x4daa[111])}catch(err){console[_0x4daa[56]](_0x4daa[112]);return null};return {size:getFilesizeInBytes(_0xb7fdx2d),path:path[_0x4daa[104]](_0xb7fdx2e,_0xb7fdx2f),name:extract[_0x4daa[74]]+ _0x4daa[113]+ moment(extract[_0x4daa[115]])[_0x4daa[27]](_0x4daa[114])+ _0x4daa[113]+ moment(extract[_0x4daa[116]])[_0x4daa[27]](_0x4daa[114])+ _0x4daa[106]+ extract[_0x4daa[108]][_0x4daa[107]](),type:_0x4daa[117]+ extract[_0x4daa[108]][_0x4daa[107]](),basename:_0xb7fdx2f}}function getFilesizeInBytes(_0xb7fdx31){try{var _0xb7fdx32=fs[_0x4daa[118]](_0xb7fdx31);var _0xb7fdx33=_0xb7fdx32[_0x4daa[119]];return _0xb7fdx33}catch(err){return 0}}module[_0x4daa[120]]= Reports