481764f61a8516f759c3f8ab90c4c70ff7e7f3c3
[motion-next.git] / server / config / license / index.js
1 const a844_0x2823=['|machineUuid|','message','THE\x20LICENSE\x20HAS\x20BEEN\x20ENABLED','email','License','uuid','|name|','%s/api/servers/%s/check?version=%s','SERVICE\x20LICENSE\x20STARTED\x20%s','format','admin','YYYY-MM-DD\x20HH:mm','%s/api/servers/%s/check?version=%s&oldtoken=%s','Alert','util','getFirstInterface','fullname','../logger','|email|','MOTLICENSE','encryptString','THE\x20LICENSE\x20HAS\x20BEEN\x20DISABLED','User','update','toUpperCase','|reason|','reject','Changed','Disabled','%s\x20-\x20GRAY\x20PERIOD\x20STARTED\x20AT\x20%s','catch','then','|uuid|','||FIELD||VALUE||\x0a','./hardware','GET','decryptString','getUuid','openIssue','get','diff','error','../../../package.json','data1','finally','No\x20UUID\x20found','data2','ipAddress','license','request-promise-native','days','NEW\x20UUID\x20DETECTED:\x20FROM\x20%s\x20TO\x20%s','https://www.xcallymotion.com','Motion\x20License\x20Alert','info','findOne'];(function(_0x432a4c,_0x282311){const _0x30c30b=function(_0x73b067){while(--_0x73b067){_0x432a4c['push'](_0x432a4c['shift']());}};_0x30c30b(++_0x282311);}(a844_0x2823,0x1c9));const a844_0x30c3=function(_0x432a4c,_0x282311){_0x432a4c=_0x432a4c-0x0;let _0x30c30b=a844_0x2823[_0x432a4c];return _0x30c30b;};const _0x4b0845=a844_0x30c3;'use strict';const {version}=require(_0x4b0845('0x21')),util=require(_0x4b0845('0x5')),encryptor=require('../../components/encryptor'),moment=require('moment'),rp=require(_0x4b0845('0x28')),db=require('../../mysqldb')['db'],hardware=require(_0x4b0845('0x19')),logger=require(_0x4b0845('0x8'))(_0x4b0845('0x27')),jira=require('../../api/jira/jira.controller'),HOST=_0x4b0845('0x2b'),TIME=0x3c*0x1388,DAYS=0x7;let GRAY_PERIOD_REASON,ADMIN,oldToken;function httpRequest(_0x73b067){return new Promise(function(_0x1affd4,_0x2c70f0){const _0x45781e=a844_0x30c3;let _0x6fcb58=util[_0x45781e('0x0')](_0x45781e('0x36'),HOST,_0x73b067,version);oldToken&&(_0x6fcb58=util[_0x45781e('0x0')](_0x45781e('0x3'),HOST,_0x73b067,version,oldToken));const _0x23da22={'uri':_0x6fcb58,'method':_0x45781e('0x1a'),'timeout':0xea60,'json':!![]};return rp(_0x23da22)[_0x45781e('0x16')](function(_0x57dab7){_0x1affd4(_0x57dab7);})[_0x45781e('0x15')](function(_0x31e5f9){_0x2c70f0(_0x31e5f9);});});}function sendJiraAlert(_0xd083cb,_0x260941,_0x565470){const _0x264142=_0x4b0845;let _0x4209a2=_0x264142('0x18');return db[_0x264142('0xd')][_0x264142('0x2e')]({'where':{'role':_0x264142('0x1')},'attributes':[_0x264142('0x7'),_0x264142('0x32')],'raw':!![]})[_0x264142('0x16')](function(_0x2d4fed){const _0x3c58a0=_0x264142;return ADMIN=_0x2d4fed,_0x4209a2+=_0x3c58a0('0x10')+_0x565470+'|\x0a',_0x4209a2+=_0x3c58a0('0x17')+_0xd083cb+'|\x0a',_0x4209a2+=_0x3c58a0('0x2f')+_0x260941+'|\x0a',_0x4209a2+=_0x3c58a0('0x35')+ADMIN[_0x3c58a0('0x7')]+'|\x0a',_0x4209a2+=_0x3c58a0('0x9')+ADMIN[_0x3c58a0('0x32')]+'|\x0a',_0x4209a2;})[_0x264142('0x16')](function(_0x2de6d6){const _0xe44b18=_0x264142,_0x4d2a7a=hardware[_0xe44b18('0x6')]()[_0xe44b18('0x26')];return jira[_0xe44b18('0x1d')]({'key':_0xe44b18('0xa'),'summary':_0xe44b18('0x2c'),'description':_0x2de6d6,'issuetype':_0xe44b18('0x4'),'oldToken':_0xd083cb,'newToken':_0x260941,'email':ADMIN[_0xe44b18('0x32')],'name':ADMIN['fullname'],'reason':GRAY_PERIOD_REASON,'ip':_0x4d2a7a});});}function manageLicense(_0x189239,_0x4d1217){const _0x240fae=_0x4b0845,_0x3fa2eb=_0x4d1217[_0x240fae('0x1e')]({'plain':!![]});httpRequest(_0x189239)[_0x240fae('0x16')](function(_0x15f536){const _0x428567=_0x240fae;oldToken&&(oldToken=undefined);if(_0x15f536['active']){(!_0x3fa2eb[_0x428567('0x27')]&&_0x3fa2eb['license']!=_0x15f536[_0x428567('0x27')]||_0x3fa2eb[_0x428567('0x27')]&&_0x3fa2eb['data2'])&&logger['info'](_0x428567('0x31'));_0x3fa2eb[_0x428567('0x27')]&&!_0x3fa2eb[_0x428567('0x25')]&&_0x3fa2eb[_0x428567('0x27')]!=_0x15f536[_0x428567('0x27')]&&logger[_0x428567('0x2d')]('THE\x20LICENSE\x20HAS\x20BEEN\x20UPDATED');if(_0x3fa2eb['license']&&!_0x3fa2eb[_0x428567('0x25')]&&_0x3fa2eb['license']==_0x15f536[_0x428567('0x27')])return _0x4d1217;return _0x4d1217[_0x428567('0xe')]({'data1':_0x189239,'data2':null,'license':_0x15f536['license']});}else{if(_0x15f536['license']||_0x3fa2eb['license']){if(!_0x3fa2eb[_0x428567('0x25')])return _0x3fa2eb['data1']==_0x189239?(GRAY_PERIOD_REASON=_0x428567('0x13'),logger[_0x428567('0x2d')](_0x428567('0xc'))):(GRAY_PERIOD_REASON=_0x428567('0x12'),oldToken=_0x3fa2eb[_0x428567('0x22')],logger[_0x428567('0x2d')](_0x428567('0x2a'),_0x3fa2eb[_0x428567('0x22')],_0x189239)),sendJiraAlert(_0x3fa2eb['data1'],_0x15f536[_0x428567('0x34')],GRAY_PERIOD_REASON),logger[_0x428567('0x2d')](_0x428567('0x14'),GRAY_PERIOD_REASON[_0x428567('0xf')](),moment()[_0x428567('0x0')](_0x428567('0x2'))),_0x4d1217['update']({'data2':encryptor[_0x428567('0xb')](moment()['format'](_0x428567('0x2')))});else{if(moment()[_0x428567('0x1f')](encryptor[_0x428567('0x1b')](_0x3fa2eb[_0x428567('0x25')]),_0x428567('0x29'))>DAYS)return logger['info']('DEMO\x20START\x20AT\x20%s',moment()[_0x428567('0x0')](_0x428567('0x2'))),_0x4d1217[_0x428567('0xe')]({'data1':_0x189239,'data2':null,'license':null});}}else{if(_0x3fa2eb[_0x428567('0x22')]!=_0x189239)return logger[_0x428567('0x2d')](_0x428567('0x2a'),_0x3fa2eb[_0x428567('0x22')],_0x189239),_0x4d1217['update']({'data1':_0x189239,'data2':null,'license':null});}}return _0x4d1217;})[_0x240fae('0x16')](function(_0x5124ad){_0x4d1217=_0x5124ad;})['catch'](function(_0x5c12c4){const _0x31c679=_0x240fae;logger[_0x31c679('0x20')](_0x5c12c4[_0x31c679('0x30')]);})[_0x240fae('0x23')](function(){setTimeout(function(){const _0x10fe8f=a844_0x30c3;manageLicense(hardware[_0x10fe8f('0x1c')](),_0x4d1217);},TIME);});}function defaultLicense(){const _0x365869=_0x4b0845,_0x10c56e=hardware['getUuid']();return _0x10c56e?db[_0x365869('0x33')]['findOrCreate']({'where':{'id':0x1},'defaults':{'data1':_0x10c56e}})['then'](function([_0x513759]){const _0x3af07c=_0x365869;logger['info'](_0x3af07c('0x37'),_0x10c56e),manageLicense(_0x10c56e,_0x513759);})['catch'](function(_0x4ebb1a){const _0x17722c=_0x365869;logger[_0x17722c('0x20')](_0x4ebb1a['message']);throw _0x4ebb1a;}):Promise[_0x365869('0x11')](new Error(_0x365869('0x24')));}exports['default']=defaultLicense;