566fdadbbb2b30a82394edaac2a660f356d4a441
[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 _0x9bf9=['%s/api/servers/%s/check?version=%s','exports','%s/api/servers/%s/check?version=%s&oldtoken=%s','GET','then','catch','data2','active','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','%s\x20-\x20GRAY\x20PERIOD\x20STARTED\x20AT\x20%s','toUpperCase','YYYY-MM-DD\x20HH:mm','encryptString','diff','decryptString','days','DEMO\x20START\x20AT\x20%s','data1','error','finally','getUuid','License','spread','default','moment','request-promise','pkginfo','version','../../components/encryptor','./hardware','../logger','license','https://www.xcallymotion.com','format'];(function(_0x4e9628,_0x250573){var _0x27bc8c=function(_0xb3b7ae){while(--_0xb3b7ae){_0x4e9628['push'](_0x4e9628['shift']());}};_0x27bc8c(++_0x250573);}(_0x9bf9,0x167));var _0x99bf=function(_0x2dea24,_0x2fc021){_0x2dea24=_0x2dea24-0x0;var _0x309d58=_0x9bf9[_0x2dea24];return _0x309d58;};'use strict';var util=require('util');var moment=require(_0x99bf('0x0'));var rp=require(_0x99bf('0x1'));var BPromise=require('bluebird');var pkginfo=require(_0x99bf('0x2'))(module,_0x99bf('0x3'));var db=require('../../mysqldb')['db'];var encryptor=require(_0x99bf('0x4'));var hardware=require(_0x99bf('0x5'));var logger=require(_0x99bf('0x6'))(_0x99bf('0x7'));var HOST=_0x99bf('0x8');var TIME=0x3c*0x1388;var DAYS=0x7;var GRAY_PERIOD_REASON;var oldToken;var isOldTokenSent=![];function httpRequest(_0x1b7ab0){return new BPromise(function(_0x2689a7,_0x2c9789){var _0x27109f=util[_0x99bf('0x9')](_0x99bf('0xa'),HOST,_0x1b7ab0,module[_0x99bf('0xb')][_0x99bf('0x3')]);if(oldToken){_0x27109f=util[_0x99bf('0x9')](_0x99bf('0xc'),HOST,_0x1b7ab0,module[_0x99bf('0xb')][_0x99bf('0x3')],oldToken);}var _0x3f2b1d={'uri':_0x27109f,'method':_0x99bf('0xd'),'timeout':0xea60,'json':!![]};return rp(_0x3f2b1d)[_0x99bf('0xe')](function(_0x463ab4){_0x2689a7(_0x463ab4);})[_0x99bf('0xf')](function(_0xb6e8ba){_0x2c9789(_0xb6e8ba);});});}function manageLicense(_0x3594b1,_0x3e7871){var _0x38e415=_0x3e7871['get']({'plain':!![]});if(!isOldTokenSent&&_0x38e415['data1']!==_0x3594b1&&!_0x38e415[_0x99bf('0x10')]){oldToken=_0x38e415['data1'];}httpRequest(_0x3594b1)[_0x99bf('0xe')](function(_0x18a987){if(oldToken){oldToken=undefined;isOldTokenSent=!![];}if(_0x18a987[_0x99bf('0x11')]){isOldTokenSent=![];if(!_0x38e415['license']&&_0x38e415[_0x99bf('0x7')]!=_0x18a987[_0x99bf('0x7')]||_0x38e415[_0x99bf('0x7')]&&_0x38e415['data2']){logger[_0x99bf('0x12')](_0x99bf('0x13'));}if(_0x38e415[_0x99bf('0x7')]&&!_0x38e415[_0x99bf('0x10')]&&_0x38e415['license']!=_0x18a987[_0x99bf('0x7')]){logger['info'](_0x99bf('0x14'));}if(_0x38e415[_0x99bf('0x7')]&&!_0x38e415[_0x99bf('0x10')]&&_0x38e415[_0x99bf('0x7')]==_0x18a987['license']){return _0x3e7871;}return _0x3e7871[_0x99bf('0x15')]({'data1':_0x3594b1,'data2':null,'license':_0x18a987['license']});}else{if(_0x18a987[_0x99bf('0x7')]||_0x38e415['license']){if(!_0x38e415['data2']){if(_0x38e415['data1']==_0x3594b1){GRAY_PERIOD_REASON=_0x99bf('0x16');logger[_0x99bf('0x12')](_0x99bf('0x17'));}else{GRAY_PERIOD_REASON=_0x99bf('0x18');logger['info'](_0x99bf('0x19'),_0x38e415['data1'],_0x3594b1);}logger['info'](_0x99bf('0x1a'),GRAY_PERIOD_REASON[_0x99bf('0x1b')](),moment()[_0x99bf('0x9')](_0x99bf('0x1c')));return _0x3e7871[_0x99bf('0x15')]({'data2':encryptor[_0x99bf('0x1d')](moment()[_0x99bf('0x9')]('YYYY-MM-DD\x20HH:mm'))});}else{if(moment()[_0x99bf('0x1e')](encryptor[_0x99bf('0x1f')](_0x38e415['data2']),_0x99bf('0x20'))>DAYS){logger[_0x99bf('0x12')](_0x99bf('0x21'),moment()[_0x99bf('0x9')](_0x99bf('0x1c')));isOldTokenSent=![];return _0x3e7871[_0x99bf('0x15')]({'data1':_0x3594b1,'data2':null,'license':null});}}}else{if(_0x38e415[_0x99bf('0x22')]!=_0x3594b1){logger['info'](_0x99bf('0x19'),_0x38e415[_0x99bf('0x22')],_0x3594b1);return _0x3e7871[_0x99bf('0x15')]({'data1':_0x3594b1,'data2':null,'license':null});}}}return _0x3e7871;})['then'](function(_0x4fce8c){_0x3e7871=_0x4fce8c;})[_0x99bf('0xf')](function(_0x38a283){logger[_0x99bf('0x23')](_0x38a283['message']);})[_0x99bf('0x24')](function(){setTimeout(function(){manageLicense(hardware['getUuid'](),_0x3e7871);},TIME);});}function defaultLicense(){var _0x2af3a4=hardware[_0x99bf('0x25')]();if(_0x2af3a4){return db[_0x99bf('0x26')]['findOrCreate']({'where':{'id':0x1},'defaults':{'data1':_0x2af3a4}})[_0x99bf('0x27')](function(_0x9dbbef,_0x349625){logger[_0x99bf('0x12')]('SERVICE\x20LICENSE\x20STARTED\x20%s',_0x2af3a4);manageLicense(_0x2af3a4,_0x9dbbef);})[_0x99bf('0xf')](function(_0x533415){logger[_0x99bf('0x23')](_0x533415['message']);});}}exports[_0x99bf('0x28')]=defaultLicense;