Built motion from commit (unavailable).|2.5.27
[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 _0xeb65=['Changed','NEW\x20UUID\x20DETECTED:\x20FROM\x20%s\x20TO\x20%s','data1','%s\x20-\x20GRAY\x20PERIOD\x20STARTED\x20AT\x20%s','toUpperCase','YYYY-MM-DD\x20HH:mm','encryptString','diff','decryptString','DEMO\x20START\x20AT\x20%s','message','finally','getUuid','License','findOrCreate','spread','SERVICE\x20LICENSE\x20STARTED\x20%s','error','default','util','moment','request-promise','bluebird','pkginfo','version','../../mysqldb','./hardware','../logger','license','https://www.xcallymotion.com','format','exports','GET','catch','get','data2','then','info','THE\x20LICENSE\x20HAS\x20BEEN\x20ENABLED','THE\x20LICENSE\x20HAS\x20BEEN\x20UPDATED','update','Disabled'];(function(_0x1db757,_0x4e2046){var _0x199572=function(_0x165b48){while(--_0x165b48){_0x1db757['push'](_0x1db757['shift']());}};_0x199572(++_0x4e2046);}(_0xeb65,0x163));var _0x5eb6=function(_0x40e63b,_0x58bb08){_0x40e63b=_0x40e63b-0x0;var _0x1dcc96=_0xeb65[_0x40e63b];return _0x1dcc96;};'use strict';var util=require(_0x5eb6('0x0'));var moment=require(_0x5eb6('0x1'));var rp=require(_0x5eb6('0x2'));var BPromise=require(_0x5eb6('0x3'));var pkginfo=require(_0x5eb6('0x4'))(module,_0x5eb6('0x5'));var db=require(_0x5eb6('0x6'))['db'];var encryptor=require('../../components/encryptor');var hardware=require(_0x5eb6('0x7'));var logger=require(_0x5eb6('0x8'))(_0x5eb6('0x9'));var HOST=_0x5eb6('0xa');var TIME=0x3c*0x1388;var DAYS=0x7;var GRAY_PERIOD_REASON;var oldToken;var isOldTokenSent=![];function httpRequest(_0x9346c6){return new BPromise(function(_0x5bd41d,_0x5a55cd){var _0x23e712=util[_0x5eb6('0xb')]('%s/api/servers/%s/check?version=%s',HOST,_0x9346c6,module[_0x5eb6('0xc')][_0x5eb6('0x5')]);if(oldToken){_0x23e712=util['format']('%s/api/servers/%s/check?version=%s&oldtoken=%s',HOST,_0x9346c6,module[_0x5eb6('0xc')][_0x5eb6('0x5')],oldToken);}var _0x38ff7c={'uri':_0x23e712,'method':_0x5eb6('0xd'),'timeout':0xea60,'json':!![]};return rp(_0x38ff7c)['then'](function(_0x5a5129){_0x5bd41d(_0x5a5129);})[_0x5eb6('0xe')](function(_0x427248){_0x5a55cd(_0x427248);});});}function manageLicense(_0x21adff,_0x526bd8){var _0x1a1750=_0x526bd8[_0x5eb6('0xf')]({'plain':!![]});if(!isOldTokenSent&&_0x1a1750['data1']!==_0x21adff&&!_0x1a1750[_0x5eb6('0x10')]){oldToken=_0x1a1750['data1'];}httpRequest(_0x21adff)[_0x5eb6('0x11')](function(_0xb40339){if(oldToken){oldToken=undefined;isOldTokenSent=!![];}if(_0xb40339['active']){isOldTokenSent=![];if(!_0x1a1750[_0x5eb6('0x9')]&&_0x1a1750[_0x5eb6('0x9')]!=_0xb40339[_0x5eb6('0x9')]||_0x1a1750[_0x5eb6('0x9')]&&_0x1a1750[_0x5eb6('0x10')]){logger[_0x5eb6('0x12')](_0x5eb6('0x13'));}if(_0x1a1750['license']&&!_0x1a1750[_0x5eb6('0x10')]&&_0x1a1750[_0x5eb6('0x9')]!=_0xb40339['license']){logger[_0x5eb6('0x12')](_0x5eb6('0x14'));}if(_0x1a1750[_0x5eb6('0x9')]&&!_0x1a1750[_0x5eb6('0x10')]&&_0x1a1750[_0x5eb6('0x9')]==_0xb40339[_0x5eb6('0x9')]){return _0x526bd8;}return _0x526bd8[_0x5eb6('0x15')]({'data1':_0x21adff,'data2':null,'license':_0xb40339['license']});}else{if(_0xb40339[_0x5eb6('0x9')]||_0x1a1750[_0x5eb6('0x9')]){if(!_0x1a1750[_0x5eb6('0x10')]){if(_0x1a1750['data1']==_0x21adff){GRAY_PERIOD_REASON=_0x5eb6('0x16');logger['info']('THE\x20LICENSE\x20HAS\x20BEEN\x20DISABLED');}else{GRAY_PERIOD_REASON=_0x5eb6('0x17');logger[_0x5eb6('0x12')](_0x5eb6('0x18'),_0x1a1750[_0x5eb6('0x19')],_0x21adff);}logger['info'](_0x5eb6('0x1a'),GRAY_PERIOD_REASON[_0x5eb6('0x1b')](),moment()['format'](_0x5eb6('0x1c')));return _0x526bd8[_0x5eb6('0x15')]({'data2':encryptor[_0x5eb6('0x1d')](moment()[_0x5eb6('0xb')](_0x5eb6('0x1c')))});}else{if(moment()[_0x5eb6('0x1e')](encryptor[_0x5eb6('0x1f')](_0x1a1750[_0x5eb6('0x10')]),'days')>DAYS){logger[_0x5eb6('0x12')](_0x5eb6('0x20'),moment()['format'](_0x5eb6('0x1c')));isOldTokenSent=![];return _0x526bd8[_0x5eb6('0x15')]({'data1':_0x21adff,'data2':null,'license':null});}}}else{if(_0x1a1750[_0x5eb6('0x19')]!=_0x21adff){logger[_0x5eb6('0x12')](_0x5eb6('0x18'),_0x1a1750[_0x5eb6('0x19')],_0x21adff);return _0x526bd8['update']({'data1':_0x21adff,'data2':null,'license':null});}}}return _0x526bd8;})['then'](function(_0x35324c){_0x526bd8=_0x35324c;})['catch'](function(_0x9e8838){logger['error'](_0x9e8838[_0x5eb6('0x21')]);})[_0x5eb6('0x22')](function(){setTimeout(function(){manageLicense(hardware[_0x5eb6('0x23')](),_0x526bd8);},TIME);});}function defaultLicense(){var _0x4295c9=hardware[_0x5eb6('0x23')]();if(_0x4295c9){return db[_0x5eb6('0x24')][_0x5eb6('0x25')]({'where':{'id':0x1},'defaults':{'data1':_0x4295c9}})[_0x5eb6('0x26')](function(_0x3c0b29,_0x60414d){logger['info'](_0x5eb6('0x27'),_0x4295c9);manageLicense(_0x4295c9,_0x3c0b29);})[_0x5eb6('0xe')](function(_0xec1024){logger[_0x5eb6('0x28')](_0xec1024['message']);});}}exports[_0x5eb6('0x29')]=defaultLicense;