d9e879fc06f84d30b6f26f5ec08fb35af5114763
[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 _0xfb66=['pkginfo','version','../../mysqldb','./hardware','../logger','https://www.xcallymotion.com','format','%s/api/servers/%s/check?version=%s&oldtoken=%s','GET','then','catch','get','data1','data2','active','license','info','THE\x20LICENSE\x20HAS\x20BEEN\x20ENABLED','THE\x20LICENSE\x20HAS\x20BEEN\x20UPDATED','update','Disabled','THE\x20LICENSE\x20HAS\x20BEEN\x20DISABLED','Changed','NEW\x20UUID\x20DETECTED:\x20FROM\x20%s\x20TO\x20%s','toUpperCase','YYYY-MM-DD\x20HH:mm','encryptString','DEMO\x20START\x20AT\x20%s','error','message','getUuid','License','findOrCreate','spread','SERVICE\x20LICENSE\x20STARTED\x20%s','default','util','request-promise','bluebird'];(function(_0x528a82,_0xb73a74){var _0x414c1a=function(_0x3ab260){while(--_0x3ab260){_0x528a82['push'](_0x528a82['shift']());}};_0x414c1a(++_0xb73a74);}(_0xfb66,0xc0));var _0x6fb6=function(_0x3e5086,_0x48f4a2){_0x3e5086=_0x3e5086-0x0;var _0xfeb102=_0xfb66[_0x3e5086];return _0xfeb102;};'use strict';var util=require(_0x6fb6('0x0'));var moment=require('moment');var rp=require(_0x6fb6('0x1'));var BPromise=require(_0x6fb6('0x2'));var pkginfo=require(_0x6fb6('0x3'))(module,_0x6fb6('0x4'));var db=require(_0x6fb6('0x5'))['db'];var encryptor=require('../../components/encryptor');var hardware=require(_0x6fb6('0x6'));var logger=require(_0x6fb6('0x7'))('license');var HOST=_0x6fb6('0x8');var TIME=0x3c*0x1388;var DAYS=0x7;var GRAY_PERIOD_REASON;var oldToken;var isOldTokenSent=![];function httpRequest(_0x27d377){return new BPromise(function(_0x4f9016,_0x446cca){var _0x1fd4b1=util[_0x6fb6('0x9')]('%s/api/servers/%s/check?version=%s',HOST,_0x27d377,module['exports'][_0x6fb6('0x4')]);if(oldToken){_0x1fd4b1=util[_0x6fb6('0x9')](_0x6fb6('0xa'),HOST,_0x27d377,module['exports'][_0x6fb6('0x4')],oldToken);}var _0x52c7de={'uri':_0x1fd4b1,'method':_0x6fb6('0xb'),'timeout':0xea60,'json':!![]};return rp(_0x52c7de)[_0x6fb6('0xc')](function(_0x3856e2){_0x4f9016(_0x3856e2);})[_0x6fb6('0xd')](function(_0x4e4b88){_0x446cca(_0x4e4b88);});});}function manageLicense(_0x556213,_0x32a049){var _0x5e3b06=_0x32a049[_0x6fb6('0xe')]({'plain':!![]});if(!isOldTokenSent&&_0x5e3b06[_0x6fb6('0xf')]!==_0x556213&&!_0x5e3b06[_0x6fb6('0x10')]){oldToken=_0x5e3b06[_0x6fb6('0xf')];}httpRequest(_0x556213)['then'](function(_0x3fa419){if(oldToken){oldToken=undefined;isOldTokenSent=!![];}if(_0x3fa419[_0x6fb6('0x11')]){isOldTokenSent=![];if(!_0x5e3b06[_0x6fb6('0x12')]&&_0x5e3b06[_0x6fb6('0x12')]!=_0x3fa419[_0x6fb6('0x12')]||_0x5e3b06[_0x6fb6('0x12')]&&_0x5e3b06[_0x6fb6('0x10')]){logger[_0x6fb6('0x13')](_0x6fb6('0x14'));}if(_0x5e3b06[_0x6fb6('0x12')]&&!_0x5e3b06[_0x6fb6('0x10')]&&_0x5e3b06[_0x6fb6('0x12')]!=_0x3fa419[_0x6fb6('0x12')]){logger['info'](_0x6fb6('0x15'));}if(_0x5e3b06['license']&&!_0x5e3b06[_0x6fb6('0x10')]&&_0x5e3b06[_0x6fb6('0x12')]==_0x3fa419[_0x6fb6('0x12')]){return _0x32a049;}return _0x32a049[_0x6fb6('0x16')]({'data1':_0x556213,'data2':null,'license':_0x3fa419['license']});}else{if(_0x3fa419[_0x6fb6('0x12')]||_0x5e3b06[_0x6fb6('0x12')]){if(!_0x5e3b06[_0x6fb6('0x10')]){if(_0x5e3b06['data1']==_0x556213){GRAY_PERIOD_REASON=_0x6fb6('0x17');logger[_0x6fb6('0x13')](_0x6fb6('0x18'));}else{GRAY_PERIOD_REASON=_0x6fb6('0x19');logger[_0x6fb6('0x13')](_0x6fb6('0x1a'),_0x5e3b06[_0x6fb6('0xf')],_0x556213);}logger[_0x6fb6('0x13')]('%s\x20-\x20GRAY\x20PERIOD\x20STARTED\x20AT\x20%s',GRAY_PERIOD_REASON[_0x6fb6('0x1b')](),moment()[_0x6fb6('0x9')](_0x6fb6('0x1c')));return _0x32a049[_0x6fb6('0x16')]({'data2':encryptor[_0x6fb6('0x1d')](moment()[_0x6fb6('0x9')]('YYYY-MM-DD\x20HH:mm'))});}else{if(moment()['diff'](encryptor['decryptString'](_0x5e3b06[_0x6fb6('0x10')]),'days')>DAYS){logger[_0x6fb6('0x13')](_0x6fb6('0x1e'),moment()[_0x6fb6('0x9')]('YYYY-MM-DD\x20HH:mm'));isOldTokenSent=![];return _0x32a049[_0x6fb6('0x16')]({'data1':_0x556213,'data2':null,'license':null});}}}else{if(_0x5e3b06['data1']!=_0x556213){logger[_0x6fb6('0x13')](_0x6fb6('0x1a'),_0x5e3b06[_0x6fb6('0xf')],_0x556213);return _0x32a049['update']({'data1':_0x556213,'data2':null,'license':null});}}}return _0x32a049;})[_0x6fb6('0xc')](function(_0x113166){_0x32a049=_0x113166;})[_0x6fb6('0xd')](function(_0x20f8e3){logger[_0x6fb6('0x1f')](_0x20f8e3[_0x6fb6('0x20')]);})['finally'](function(){setTimeout(function(){manageLicense(hardware[_0x6fb6('0x21')](),_0x32a049);},TIME);});}function defaultLicense(){var _0x278723=hardware[_0x6fb6('0x21')]();if(_0x278723){return db[_0x6fb6('0x22')][_0x6fb6('0x23')]({'where':{'id':0x1},'defaults':{'data1':_0x278723}})[_0x6fb6('0x24')](function(_0x22c3d3,_0x472619){logger[_0x6fb6('0x13')](_0x6fb6('0x25'),_0x278723);manageLicense(_0x278723,_0x22c3d3);})['catch'](function(_0x3c3850){logger[_0x6fb6('0x1f')](_0x3c3850[_0x6fb6('0x20')]);});}}exports[_0x6fb6('0x26')]=defaultLicense;