Built motion from commit 25580385.|2.6.2
[motion2.git] / server / config / license / index.js
index 5caadc0..d89fe4b 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x2ea2=['encryptString','decryptString','error','message','getUuid','findOrCreate','spread','catch','default','util','moment','request-promise','bluebird','pkginfo','version','../../mysqldb','./hardware','../logger','license','https://www.xcallymotion.com','format','%s/api/servers/%s/check?version=%s','exports','%s/api/servers/%s/check?version=%s&oldtoken=%s','then','||FIELD||VALUE||\x0a','User','findOne','fullname','|machineUuid|','|name|','email','getFirstInterface','ipAddress','openIssue','MOTLICENSE','get','active','data2','info','THE\x20LICENSE\x20HAS\x20BEEN\x20ENABLED','THE\x20LICENSE\x20HAS\x20BEEN\x20UPDATED','update','data1','Disabled','NEW\x20UUID\x20DETECTED:\x20FROM\x20%s\x20TO\x20%s','YYYY-MM-DD\x20HH:mm'];(function(_0x1f0988,_0x299c68){var _0x3caf61=function(_0x454981){while(--_0x454981){_0x1f0988['push'](_0x1f0988['shift']());}};_0x3caf61(++_0x299c68);}(_0x2ea2,0xc5));var _0x22ea=function(_0x6f79dd,_0xeaae7c){_0x6f79dd=_0x6f79dd-0x0;var _0x1279b8=_0x2ea2[_0x6f79dd];return _0x1279b8;};'use strict';var util=require(_0x22ea('0x0'));var moment=require(_0x22ea('0x1'));var rp=require(_0x22ea('0x2'));var BPromise=require(_0x22ea('0x3'));var pkginfo=require(_0x22ea('0x4'))(module,_0x22ea('0x5'));var db=require(_0x22ea('0x6'))['db'];var encryptor=require('../../components/encryptor');var hardware=require(_0x22ea('0x7'));var logger=require(_0x22ea('0x8'))(_0x22ea('0x9'));var jira=require('../../api/jira/jira.controller');const {config}=require('process');var HOST=_0x22ea('0xa');var TIME=0x3c*0x1388;var DAYS=0x7;var GRAY_PERIOD_REASON;var ADMIN;var oldToken;function httpRequest(_0x18acfc){return new BPromise(function(_0x3dc6d4,_0x127cc3){var _0x15c1cb=util[_0x22ea('0xb')](_0x22ea('0xc'),HOST,_0x18acfc,module[_0x22ea('0xd')]['version']);if(oldToken){_0x15c1cb=util[_0x22ea('0xb')](_0x22ea('0xe'),HOST,_0x18acfc,module['exports'][_0x22ea('0x5')],oldToken);}var _0x499a22={'uri':_0x15c1cb,'method':'GET','timeout':0xea60,'json':!![]};return rp(_0x499a22)[_0x22ea('0xf')](function(_0x45531f){_0x3dc6d4(_0x45531f);})['catch'](function(_0x4b89d6){_0x127cc3(_0x4b89d6);});});}function sendJiraAlert(_0x54150a,_0x3e19a5,_0x3da559){var _0x58ecbb=_0x22ea('0x10');return db[_0x22ea('0x11')][_0x22ea('0x12')]({'where':{'role':'admin'},'attributes':[_0x22ea('0x13'),'email'],'raw':!![]})[_0x22ea('0xf')](function(_0x68daba){ADMIN=_0x68daba;_0x58ecbb+='|reason|'+_0x3da559+'|\x0a';_0x58ecbb+='|uuid|'+_0x54150a+'|\x0a';_0x58ecbb+=_0x22ea('0x14')+_0x3e19a5+'|\x0a';_0x58ecbb+=_0x22ea('0x15')+ADMIN[_0x22ea('0x13')]+'|\x0a';_0x58ecbb+='|email|'+ADMIN[_0x22ea('0x16')]+'|\x0a';return _0x58ecbb;})[_0x22ea('0xf')](function(_0x5198a2){var _0x12dc0d=hardware[_0x22ea('0x17')]()[_0x22ea('0x18')];return jira[_0x22ea('0x19')]({'key':_0x22ea('0x1a'),'summary':'Motion\x20License\x20Alert','description':_0x5198a2,'issuetype':'Alert','oldToken':_0x54150a,'newToken':_0x3e19a5,'email':ADMIN[_0x22ea('0x16')],'name':ADMIN[_0x22ea('0x13')],'reason':GRAY_PERIOD_REASON,'ip':_0x12dc0d});});}function manageLicense(_0x369e69,_0x4e76f4){var _0xcdab27=_0x4e76f4[_0x22ea('0x1b')]({'plain':!![]});httpRequest(_0x369e69)[_0x22ea('0xf')](function(_0x45241b){if(oldToken){oldToken=undefined;}if(_0x45241b[_0x22ea('0x1c')]){if(!_0xcdab27[_0x22ea('0x9')]&&_0xcdab27[_0x22ea('0x9')]!=_0x45241b[_0x22ea('0x9')]||_0xcdab27[_0x22ea('0x9')]&&_0xcdab27[_0x22ea('0x1d')]){logger[_0x22ea('0x1e')](_0x22ea('0x1f'));}if(_0xcdab27[_0x22ea('0x9')]&&!_0xcdab27['data2']&&_0xcdab27[_0x22ea('0x9')]!=_0x45241b[_0x22ea('0x9')]){logger[_0x22ea('0x1e')](_0x22ea('0x20'));}if(_0xcdab27['license']&&!_0xcdab27['data2']&&_0xcdab27['license']==_0x45241b[_0x22ea('0x9')]){return _0x4e76f4;}return _0x4e76f4[_0x22ea('0x21')]({'data1':_0x369e69,'data2':null,'license':_0x45241b[_0x22ea('0x9')]});}else{if(_0x45241b['license']||_0xcdab27[_0x22ea('0x9')]){if(!_0xcdab27[_0x22ea('0x1d')]){if(_0xcdab27[_0x22ea('0x22')]==_0x369e69){GRAY_PERIOD_REASON=_0x22ea('0x23');logger[_0x22ea('0x1e')]('THE\x20LICENSE\x20HAS\x20BEEN\x20DISABLED');}else{GRAY_PERIOD_REASON='Changed';oldToken=_0xcdab27[_0x22ea('0x22')];logger['info'](_0x22ea('0x24'),_0xcdab27[_0x22ea('0x22')],_0x369e69);}sendJiraAlert(_0xcdab27[_0x22ea('0x22')],_0x45241b['uuid'],GRAY_PERIOD_REASON);logger[_0x22ea('0x1e')]('%s\x20-\x20GRAY\x20PERIOD\x20STARTED\x20AT\x20%s',GRAY_PERIOD_REASON['toUpperCase'](),moment()[_0x22ea('0xb')](_0x22ea('0x25')));return _0x4e76f4[_0x22ea('0x21')]({'data2':encryptor[_0x22ea('0x26')](moment()[_0x22ea('0xb')](_0x22ea('0x25')))});}else{if(moment()['diff'](encryptor[_0x22ea('0x27')](_0xcdab27[_0x22ea('0x1d')]),'days')>DAYS){logger[_0x22ea('0x1e')]('DEMO\x20START\x20AT\x20%s',moment()[_0x22ea('0xb')](_0x22ea('0x25')));return _0x4e76f4[_0x22ea('0x21')]({'data1':_0x369e69,'data2':null,'license':null});}}}else{if(_0xcdab27['data1']!=_0x369e69){logger[_0x22ea('0x1e')]('NEW\x20UUID\x20DETECTED:\x20FROM\x20%s\x20TO\x20%s',_0xcdab27[_0x22ea('0x22')],_0x369e69);return _0x4e76f4['update']({'data1':_0x369e69,'data2':null,'license':null});}}}return _0x4e76f4;})[_0x22ea('0xf')](function(_0x279660){_0x4e76f4=_0x279660;})['catch'](function(_0x5bda38){logger[_0x22ea('0x28')](_0x5bda38[_0x22ea('0x29')]);})['finally'](function(){setTimeout(function(){manageLicense(hardware[_0x22ea('0x2a')](),_0x4e76f4);},TIME);});}function defaultLicense(){var _0x57015b=hardware[_0x22ea('0x2a')]();if(_0x57015b){return db['License'][_0x22ea('0x2b')]({'where':{'id':0x1},'defaults':{'data1':_0x57015b}})[_0x22ea('0x2c')](function(_0x1a075e,_0x3bb4b3){logger['info']('SERVICE\x20LICENSE\x20STARTED\x20%s',_0x57015b);manageLicense(_0x57015b,_0x1a075e);})[_0x22ea('0x2d')](function(_0x11097d){logger[_0x22ea('0x28')](_0x11097d[_0x22ea('0x29')]);});}}exports[_0x22ea('0x2e')]=defaultLicense;
\ No newline at end of file
+var _0x57f3=['Disabled','NEW\x20UUID\x20DETECTED:\x20FROM\x20%s\x20TO\x20%s','%s\x20-\x20GRAY\x20PERIOD\x20STARTED\x20AT\x20%s','YYYY-MM-DD\x20HH:mm','update','diff','decryptString','error','getUuid','License','findOrCreate','SERVICE\x20LICENSE\x20STARTED\x20%s','default','util','request-promise','bluebird','version','../../mysqldb','../../components/encryptor','../logger','license','https://www.xcallymotion.com','format','%s/api/servers/%s/check?version=%s','exports','then','catch','data2','data1','active','info','THE\x20LICENSE\x20HAS\x20BEEN\x20ENABLED','THE\x20LICENSE\x20HAS\x20BEEN\x20UPDATED'];(function(_0x568496,_0x565afd){var _0x26c5c1=function(_0x4d251e){while(--_0x4d251e){_0x568496['push'](_0x568496['shift']());}};_0x26c5c1(++_0x565afd);}(_0x57f3,0x178));var _0x357f=function(_0x17d9e3,_0x1f969c){_0x17d9e3=_0x17d9e3-0x0;var _0x14192d=_0x57f3[_0x17d9e3];return _0x14192d;};'use strict';var util=require(_0x357f('0x0'));var moment=require('moment');var rp=require(_0x357f('0x1'));var BPromise=require(_0x357f('0x2'));var pkginfo=require('pkginfo')(module,_0x357f('0x3'));var db=require(_0x357f('0x4'))['db'];var encryptor=require(_0x357f('0x5'));var hardware=require('./hardware');var logger=require(_0x357f('0x6'))(_0x357f('0x7'));var HOST=_0x357f('0x8');var TIME=0x3c*0x1388;var DAYS=0x7;var GRAY_PERIOD_REASON;var oldToken;var isOldTokenSent=![];function httpRequest(_0x68b72a){return new BPromise(function(_0x4e77f1,_0x5a052f){var _0x3af30c=util[_0x357f('0x9')](_0x357f('0xa'),HOST,_0x68b72a,module['exports'][_0x357f('0x3')]);if(oldToken){_0x3af30c=util[_0x357f('0x9')]('%s/api/servers/%s/check?version=%s&oldtoken=%s',HOST,_0x68b72a,module[_0x357f('0xb')][_0x357f('0x3')],oldToken);}var _0x3e197d={'uri':_0x3af30c,'method':'GET','timeout':0xea60,'json':!![]};return rp(_0x3e197d)[_0x357f('0xc')](function(_0x4c914f){_0x4e77f1(_0x4c914f);})[_0x357f('0xd')](function(_0x48116e){_0x5a052f(_0x48116e);});});}function manageLicense(_0x4192a4,_0x275faf){var _0x40156f=_0x275faf['get']({'plain':!![]});if(!isOldTokenSent&&_0x40156f['data1']!==_0x4192a4&&!_0x40156f[_0x357f('0xe')]){oldToken=_0x40156f[_0x357f('0xf')];}httpRequest(_0x4192a4)['then'](function(_0x551f6b){if(oldToken){oldToken=undefined;isOldTokenSent=!![];}if(_0x551f6b[_0x357f('0x10')]){isOldTokenSent=![];if(!_0x40156f[_0x357f('0x7')]&&_0x40156f[_0x357f('0x7')]!=_0x551f6b['license']||_0x40156f[_0x357f('0x7')]&&_0x40156f[_0x357f('0xe')]){logger[_0x357f('0x11')](_0x357f('0x12'));}if(_0x40156f[_0x357f('0x7')]&&!_0x40156f['data2']&&_0x40156f[_0x357f('0x7')]!=_0x551f6b[_0x357f('0x7')]){logger[_0x357f('0x11')](_0x357f('0x13'));}if(_0x40156f[_0x357f('0x7')]&&!_0x40156f['data2']&&_0x40156f[_0x357f('0x7')]==_0x551f6b[_0x357f('0x7')]){return _0x275faf;}return _0x275faf['update']({'data1':_0x4192a4,'data2':null,'license':_0x551f6b[_0x357f('0x7')]});}else{if(_0x551f6b[_0x357f('0x7')]||_0x40156f[_0x357f('0x7')]){if(!_0x40156f[_0x357f('0xe')]){if(_0x40156f['data1']==_0x4192a4){GRAY_PERIOD_REASON=_0x357f('0x14');logger['info']('THE\x20LICENSE\x20HAS\x20BEEN\x20DISABLED');}else{GRAY_PERIOD_REASON='Changed';logger['info'](_0x357f('0x15'),_0x40156f[_0x357f('0xf')],_0x4192a4);}logger[_0x357f('0x11')](_0x357f('0x16'),GRAY_PERIOD_REASON['toUpperCase'](),moment()[_0x357f('0x9')](_0x357f('0x17')));return _0x275faf[_0x357f('0x18')]({'data2':encryptor['encryptString'](moment()[_0x357f('0x9')](_0x357f('0x17')))});}else{if(moment()[_0x357f('0x19')](encryptor[_0x357f('0x1a')](_0x40156f[_0x357f('0xe')]),'days')>DAYS){logger[_0x357f('0x11')]('DEMO\x20START\x20AT\x20%s',moment()[_0x357f('0x9')]('YYYY-MM-DD\x20HH:mm'));isOldTokenSent=![];return _0x275faf[_0x357f('0x18')]({'data1':_0x4192a4,'data2':null,'license':null});}}}else{if(_0x40156f['data1']!=_0x4192a4){logger[_0x357f('0x11')](_0x357f('0x15'),_0x40156f[_0x357f('0xf')],_0x4192a4);return _0x275faf[_0x357f('0x18')]({'data1':_0x4192a4,'data2':null,'license':null});}}}return _0x275faf;})[_0x357f('0xc')](function(_0x52a73d){_0x275faf=_0x52a73d;})[_0x357f('0xd')](function(_0x3505c2){logger[_0x357f('0x1b')](_0x3505c2['message']);})['finally'](function(){setTimeout(function(){manageLicense(hardware['getUuid'](),_0x275faf);},TIME);});}function defaultLicense(){var _0x5e089b=hardware[_0x357f('0x1c')]();if(_0x5e089b){return db[_0x357f('0x1d')][_0x357f('0x1e')]({'where':{'id':0x1},'defaults':{'data1':_0x5e089b}})['spread'](function(_0x5c0dc7,_0x32bb7e){logger[_0x357f('0x11')](_0x357f('0x1f'),_0x5e089b);manageLicense(_0x5e089b,_0x5c0dc7);})[_0x357f('0xd')](function(_0x28f494){logger['error'](_0x28f494['message']);});}}exports[_0x357f('0x20')]=defaultLicense;
\ No newline at end of file