Built motion from commit cb845558.|2.6.34
[motion2.git] / server / config / license / index.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0xbc4a=['exports','format','%s/api/servers/%s/check?version=%s&oldtoken=%s','then','catch','data1','data2','active','license','info','update','Disabled','THE\x20LICENSE\x20HAS\x20BEEN\x20DISABLED','Changed','NEW\x20UUID\x20DETECTED:\x20FROM\x20%s\x20TO\x20%s','toUpperCase','YYYY-MM-DD\x20HH:mm','diff','decryptString','days','DEMO\x20START\x20AT\x20%s','error','message','finally','getUuid','License','findOrCreate','SERVICE\x20LICENSE\x20STARTED\x20%s','util','moment','request-promise','bluebird','pkginfo','version','../../mysqldb','../../components/encryptor','./hardware','https://www.xcallymotion.com','%s/api/servers/%s/check?version=%s'];(function(_0x397e5f,_0x454c8f){var _0x5302b8=function(_0x1a29ef){while(--_0x1a29ef){_0x397e5f['push'](_0x397e5f['shift']());}};_0x5302b8(++_0x454c8f);}(_0xbc4a,0x106));var _0xabc4=function(_0x268711,_0x151157){_0x268711=_0x268711-0x0;var _0x296608=_0xbc4a[_0x268711];return _0x296608;};'use strict';var util=require(_0xabc4('0x0'));var moment=require(_0xabc4('0x1'));var rp=require(_0xabc4('0x2'));var BPromise=require(_0xabc4('0x3'));var pkginfo=require(_0xabc4('0x4'))(module,_0xabc4('0x5'));var db=require(_0xabc4('0x6'))['db'];var encryptor=require(_0xabc4('0x7'));var hardware=require(_0xabc4('0x8'));var logger=require('../logger')('license');var HOST=_0xabc4('0x9');var TIME=0x3c*0x1388;var DAYS=0x7;var GRAY_PERIOD_REASON;var oldToken;var isOldTokenSent=![];function httpRequest(_0x4e9509){return new BPromise(function(_0x546bfd,_0x522fc4){var _0x320856=util['format'](_0xabc4('0xa'),HOST,_0x4e9509,module[_0xabc4('0xb')][_0xabc4('0x5')]);if(oldToken){_0x320856=util[_0xabc4('0xc')](_0xabc4('0xd'),HOST,_0x4e9509,module[_0xabc4('0xb')][_0xabc4('0x5')],oldToken);}var _0x3dadc2={'uri':_0x320856,'method':'GET','timeout':0xea60,'json':!![]};return rp(_0x3dadc2)[_0xabc4('0xe')](function(_0x127f23){_0x546bfd(_0x127f23);})[_0xabc4('0xf')](function(_0x23d500){_0x522fc4(_0x23d500);});});}function manageLicense(_0x19b49e,_0x2a1660){var _0x5cb8f2=_0x2a1660['get']({'plain':!![]});if(!isOldTokenSent&&_0x5cb8f2[_0xabc4('0x10')]!==_0x19b49e&&!_0x5cb8f2[_0xabc4('0x11')]){oldToken=_0x5cb8f2['data1'];}httpRequest(_0x19b49e)[_0xabc4('0xe')](function(_0x1ab836){if(oldToken){oldToken=undefined;isOldTokenSent=!![];}if(_0x1ab836[_0xabc4('0x12')]){isOldTokenSent=![];if(!_0x5cb8f2[_0xabc4('0x13')]&&_0x5cb8f2[_0xabc4('0x13')]!=_0x1ab836[_0xabc4('0x13')]||_0x5cb8f2[_0xabc4('0x13')]&&_0x5cb8f2[_0xabc4('0x11')]){logger[_0xabc4('0x14')]('THE\x20LICENSE\x20HAS\x20BEEN\x20ENABLED');}if(_0x5cb8f2[_0xabc4('0x13')]&&!_0x5cb8f2[_0xabc4('0x11')]&&_0x5cb8f2[_0xabc4('0x13')]!=_0x1ab836[_0xabc4('0x13')]){logger[_0xabc4('0x14')]('THE\x20LICENSE\x20HAS\x20BEEN\x20UPDATED');}if(_0x5cb8f2[_0xabc4('0x13')]&&!_0x5cb8f2[_0xabc4('0x11')]&&_0x5cb8f2[_0xabc4('0x13')]==_0x1ab836[_0xabc4('0x13')]){return _0x2a1660;}return _0x2a1660[_0xabc4('0x15')]({'data1':_0x19b49e,'data2':null,'license':_0x1ab836[_0xabc4('0x13')]});}else{if(_0x1ab836[_0xabc4('0x13')]||_0x5cb8f2[_0xabc4('0x13')]){if(!_0x5cb8f2[_0xabc4('0x11')]){if(_0x5cb8f2[_0xabc4('0x10')]==_0x19b49e){GRAY_PERIOD_REASON=_0xabc4('0x16');logger[_0xabc4('0x14')](_0xabc4('0x17'));}else{GRAY_PERIOD_REASON=_0xabc4('0x18');logger[_0xabc4('0x14')](_0xabc4('0x19'),_0x5cb8f2[_0xabc4('0x10')],_0x19b49e);}logger[_0xabc4('0x14')]('%s\x20-\x20GRAY\x20PERIOD\x20STARTED\x20AT\x20%s',GRAY_PERIOD_REASON[_0xabc4('0x1a')](),moment()[_0xabc4('0xc')](_0xabc4('0x1b')));return _0x2a1660['update']({'data2':encryptor['encryptString'](moment()['format'](_0xabc4('0x1b')))});}else{if(moment()[_0xabc4('0x1c')](encryptor[_0xabc4('0x1d')](_0x5cb8f2[_0xabc4('0x11')]),_0xabc4('0x1e'))>DAYS){logger[_0xabc4('0x14')](_0xabc4('0x1f'),moment()[_0xabc4('0xc')]('YYYY-MM-DD\x20HH:mm'));isOldTokenSent=![];return _0x2a1660[_0xabc4('0x15')]({'data1':_0x19b49e,'data2':null,'license':null});}}}else{if(_0x5cb8f2[_0xabc4('0x10')]!=_0x19b49e){logger['info']('NEW\x20UUID\x20DETECTED:\x20FROM\x20%s\x20TO\x20%s',_0x5cb8f2[_0xabc4('0x10')],_0x19b49e);return _0x2a1660[_0xabc4('0x15')]({'data1':_0x19b49e,'data2':null,'license':null});}}}return _0x2a1660;})[_0xabc4('0xe')](function(_0x57a330){_0x2a1660=_0x57a330;})[_0xabc4('0xf')](function(_0x2bd14a){logger[_0xabc4('0x20')](_0x2bd14a[_0xabc4('0x21')]);})[_0xabc4('0x22')](function(){setTimeout(function(){manageLicense(hardware[_0xabc4('0x23')](),_0x2a1660);},TIME);});}function defaultLicense(){var _0x54bb64=hardware[_0xabc4('0x23')]();if(_0x54bb64){return db[_0xabc4('0x24')][_0xabc4('0x25')]({'where':{'id':0x1},'defaults':{'data1':_0x54bb64}})['spread'](function(_0x54a68d,_0x365b8c){logger[_0xabc4('0x14')](_0xabc4('0x26'),_0x54bb64);manageLicense(_0x54bb64,_0x54a68d);})[_0xabc4('0xf')](function(_0x150896){logger[_0xabc4('0x20')](_0x150896[_0xabc4('0x21')]);});}}exports['default']=defaultLicense;