Built motion from commit 3d3e98f2.|2.6.29
[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 _0xa41c=['util','moment','request-promise','bluebird','version','../../mysqldb','../../components/encryptor','./hardware','../logger','license','exports','format','%s/api/servers/%s/check?version=%s&oldtoken=%s','GET','then','catch','data1','data2','active','info','THE\x20LICENSE\x20HAS\x20BEEN\x20ENABLED','THE\x20LICENSE\x20HAS\x20BEEN\x20UPDATED','update','Disabled','Changed','NEW\x20UUID\x20DETECTED:\x20FROM\x20%s\x20TO\x20%s','%s\x20-\x20GRAY\x20PERIOD\x20STARTED\x20AT\x20%s','YYYY-MM-DD\x20HH:mm','decryptString','error','message','finally','getUuid','License','findOrCreate','spread','SERVICE\x20LICENSE\x20STARTED\x20%s','default'];(function(_0x186376,_0x5d988a){var _0x2dbdd9=function(_0x96908e){while(--_0x96908e){_0x186376['push'](_0x186376['shift']());}};_0x2dbdd9(++_0x5d988a);}(_0xa41c,0x98));var _0xca41=function(_0x1955c2,_0x58dc5a){_0x1955c2=_0x1955c2-0x0;var _0x1f2e02=_0xa41c[_0x1955c2];return _0x1f2e02;};'use strict';var util=require(_0xca41('0x0'));var moment=require(_0xca41('0x1'));var rp=require(_0xca41('0x2'));var BPromise=require(_0xca41('0x3'));var pkginfo=require('pkginfo')(module,_0xca41('0x4'));var db=require(_0xca41('0x5'))['db'];var encryptor=require(_0xca41('0x6'));var hardware=require(_0xca41('0x7'));var logger=require(_0xca41('0x8'))(_0xca41('0x9'));var HOST='https://www.xcallymotion.com';var TIME=0x3c*0x1388;var DAYS=0x7;var GRAY_PERIOD_REASON;var oldToken;var isOldTokenSent=![];function httpRequest(_0x41f693){return new BPromise(function(_0x5dda7c,_0x104dc0){var _0x131eb3=util['format']('%s/api/servers/%s/check?version=%s',HOST,_0x41f693,module[_0xca41('0xa')][_0xca41('0x4')]);if(oldToken){_0x131eb3=util[_0xca41('0xb')](_0xca41('0xc'),HOST,_0x41f693,module[_0xca41('0xa')][_0xca41('0x4')],oldToken);}var _0x3f6151={'uri':_0x131eb3,'method':_0xca41('0xd'),'timeout':0xea60,'json':!![]};return rp(_0x3f6151)[_0xca41('0xe')](function(_0x564fcf){_0x5dda7c(_0x564fcf);})[_0xca41('0xf')](function(_0x405bda){_0x104dc0(_0x405bda);});});}function manageLicense(_0x787b01,_0x304716){var _0x32ded7=_0x304716['get']({'plain':!![]});if(!isOldTokenSent&&_0x32ded7[_0xca41('0x10')]!==_0x787b01&&!_0x32ded7[_0xca41('0x11')]){oldToken=_0x32ded7[_0xca41('0x10')];}httpRequest(_0x787b01)[_0xca41('0xe')](function(_0x2b9b37){if(oldToken){oldToken=undefined;isOldTokenSent=!![];}if(_0x2b9b37[_0xca41('0x12')]){isOldTokenSent=![];if(!_0x32ded7[_0xca41('0x9')]&&_0x32ded7[_0xca41('0x9')]!=_0x2b9b37[_0xca41('0x9')]||_0x32ded7['license']&&_0x32ded7[_0xca41('0x11')]){logger[_0xca41('0x13')](_0xca41('0x14'));}if(_0x32ded7['license']&&!_0x32ded7[_0xca41('0x11')]&&_0x32ded7[_0xca41('0x9')]!=_0x2b9b37['license']){logger[_0xca41('0x13')](_0xca41('0x15'));}if(_0x32ded7[_0xca41('0x9')]&&!_0x32ded7[_0xca41('0x11')]&&_0x32ded7[_0xca41('0x9')]==_0x2b9b37[_0xca41('0x9')]){return _0x304716;}return _0x304716[_0xca41('0x16')]({'data1':_0x787b01,'data2':null,'license':_0x2b9b37[_0xca41('0x9')]});}else{if(_0x2b9b37[_0xca41('0x9')]||_0x32ded7[_0xca41('0x9')]){if(!_0x32ded7[_0xca41('0x11')]){if(_0x32ded7[_0xca41('0x10')]==_0x787b01){GRAY_PERIOD_REASON=_0xca41('0x17');logger[_0xca41('0x13')]('THE\x20LICENSE\x20HAS\x20BEEN\x20DISABLED');}else{GRAY_PERIOD_REASON=_0xca41('0x18');logger[_0xca41('0x13')](_0xca41('0x19'),_0x32ded7[_0xca41('0x10')],_0x787b01);}logger[_0xca41('0x13')](_0xca41('0x1a'),GRAY_PERIOD_REASON['toUpperCase'](),moment()['format'](_0xca41('0x1b')));return _0x304716[_0xca41('0x16')]({'data2':encryptor['encryptString'](moment()[_0xca41('0xb')](_0xca41('0x1b')))});}else{if(moment()['diff'](encryptor[_0xca41('0x1c')](_0x32ded7['data2']),'days')>DAYS){logger[_0xca41('0x13')]('DEMO\x20START\x20AT\x20%s',moment()[_0xca41('0xb')](_0xca41('0x1b')));isOldTokenSent=![];return _0x304716[_0xca41('0x16')]({'data1':_0x787b01,'data2':null,'license':null});}}}else{if(_0x32ded7['data1']!=_0x787b01){logger[_0xca41('0x13')](_0xca41('0x19'),_0x32ded7[_0xca41('0x10')],_0x787b01);return _0x304716[_0xca41('0x16')]({'data1':_0x787b01,'data2':null,'license':null});}}}return _0x304716;})[_0xca41('0xe')](function(_0x11c234){_0x304716=_0x11c234;})[_0xca41('0xf')](function(_0x2c623f){logger[_0xca41('0x1d')](_0x2c623f[_0xca41('0x1e')]);})[_0xca41('0x1f')](function(){setTimeout(function(){manageLicense(hardware[_0xca41('0x20')](),_0x304716);},TIME);});}function defaultLicense(){var _0x3c4e93=hardware[_0xca41('0x20')]();if(_0x3c4e93){return db[_0xca41('0x21')][_0xca41('0x22')]({'where':{'id':0x1},'defaults':{'data1':_0x3c4e93}})[_0xca41('0x23')](function(_0x1d0387,_0x26e37b){logger['info'](_0xca41('0x24'),_0x3c4e93);manageLicense(_0x3c4e93,_0x1d0387);})[_0xca41('0xf')](function(_0x500c3f){logger[_0xca41('0x1d')](_0x500c3f[_0xca41('0x1e')]);});}}exports[_0xca41('0x25')]=defaultLicense;