e956b1e6466985e09976c556c2404e1654426fc3
[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 _0xb003=['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','encryptString','format','YYYY-MM-DD\x20HH:mm','diff','decryptString','days','DEMO\x20START\x20AT\x20%s','message','finally','getUuid','License','findOrCreate','spread','SERVICE\x20LICENSE\x20STARTED\x20%s','error','default','util','moment','request-promise','pkginfo','version','./hardware','../logger','license','https://www.xcallymotion.com','%s/api/servers/%s/check?version=%s','exports','%s/api/servers/%s/check?version=%s&oldtoken=%s','catch','data2','data1','then','info','THE\x20LICENSE\x20HAS\x20BEEN\x20ENABLED','THE\x20LICENSE\x20HAS\x20BEEN\x20UPDATED'];(function(_0x144b4f,_0x34069c){var _0x5f5978=function(_0x3ecd67){while(--_0x3ecd67){_0x144b4f['push'](_0x144b4f['shift']());}};_0x5f5978(++_0x34069c);}(_0xb003,0xbf));var _0x3b00=function(_0x527ce8,_0x122695){_0x527ce8=_0x527ce8-0x0;var _0x2a8a56=_0xb003[_0x527ce8];return _0x2a8a56;};'use strict';var util=require(_0x3b00('0x0'));var moment=require(_0x3b00('0x1'));var rp=require(_0x3b00('0x2'));var BPromise=require('bluebird');var pkginfo=require(_0x3b00('0x3'))(module,_0x3b00('0x4'));var db=require('../../mysqldb')['db'];var encryptor=require('../../components/encryptor');var hardware=require(_0x3b00('0x5'));var logger=require(_0x3b00('0x6'))(_0x3b00('0x7'));var HOST=_0x3b00('0x8');var TIME=0x3c*0x1388;var DAYS=0x7;var GRAY_PERIOD_REASON;var oldToken;var isOldTokenSent=![];function httpRequest(_0x1f48eb){return new BPromise(function(_0x302807,_0x47c8c6){var _0x4d6696=util['format'](_0x3b00('0x9'),HOST,_0x1f48eb,module[_0x3b00('0xa')][_0x3b00('0x4')]);if(oldToken){_0x4d6696=util['format'](_0x3b00('0xb'),HOST,_0x1f48eb,module['exports'][_0x3b00('0x4')],oldToken);}var _0x8c4e91={'uri':_0x4d6696,'method':'GET','timeout':0xea60,'json':!![]};return rp(_0x8c4e91)['then'](function(_0x218ba2){_0x302807(_0x218ba2);})[_0x3b00('0xc')](function(_0x14660a){_0x47c8c6(_0x14660a);});});}function manageLicense(_0x954b2c,_0x559a02){var _0x344956=_0x559a02['get']({'plain':!![]});if(!isOldTokenSent&&_0x344956['data1']!==_0x954b2c&&!_0x344956[_0x3b00('0xd')]){oldToken=_0x344956[_0x3b00('0xe')];}httpRequest(_0x954b2c)[_0x3b00('0xf')](function(_0x143597){if(oldToken){oldToken=undefined;isOldTokenSent=!![];}if(_0x143597['active']){isOldTokenSent=![];if(!_0x344956[_0x3b00('0x7')]&&_0x344956[_0x3b00('0x7')]!=_0x143597[_0x3b00('0x7')]||_0x344956[_0x3b00('0x7')]&&_0x344956[_0x3b00('0xd')]){logger[_0x3b00('0x10')](_0x3b00('0x11'));}if(_0x344956[_0x3b00('0x7')]&&!_0x344956['data2']&&_0x344956[_0x3b00('0x7')]!=_0x143597[_0x3b00('0x7')]){logger[_0x3b00('0x10')](_0x3b00('0x12'));}if(_0x344956[_0x3b00('0x7')]&&!_0x344956[_0x3b00('0xd')]&&_0x344956[_0x3b00('0x7')]==_0x143597[_0x3b00('0x7')]){return _0x559a02;}return _0x559a02[_0x3b00('0x13')]({'data1':_0x954b2c,'data2':null,'license':_0x143597[_0x3b00('0x7')]});}else{if(_0x143597['license']||_0x344956[_0x3b00('0x7')]){if(!_0x344956[_0x3b00('0xd')]){if(_0x344956[_0x3b00('0xe')]==_0x954b2c){GRAY_PERIOD_REASON=_0x3b00('0x14');logger['info'](_0x3b00('0x15'));}else{GRAY_PERIOD_REASON=_0x3b00('0x16');logger['info'](_0x3b00('0x17'),_0x344956[_0x3b00('0xe')],_0x954b2c);}logger[_0x3b00('0x10')](_0x3b00('0x18'),GRAY_PERIOD_REASON[_0x3b00('0x19')](),moment()['format']('YYYY-MM-DD\x20HH:mm'));return _0x559a02['update']({'data2':encryptor[_0x3b00('0x1a')](moment()[_0x3b00('0x1b')](_0x3b00('0x1c')))});}else{if(moment()[_0x3b00('0x1d')](encryptor[_0x3b00('0x1e')](_0x344956[_0x3b00('0xd')]),_0x3b00('0x1f'))>DAYS){logger['info'](_0x3b00('0x20'),moment()[_0x3b00('0x1b')]('YYYY-MM-DD\x20HH:mm'));isOldTokenSent=![];return _0x559a02[_0x3b00('0x13')]({'data1':_0x954b2c,'data2':null,'license':null});}}}else{if(_0x344956['data1']!=_0x954b2c){logger[_0x3b00('0x10')](_0x3b00('0x17'),_0x344956[_0x3b00('0xe')],_0x954b2c);return _0x559a02[_0x3b00('0x13')]({'data1':_0x954b2c,'data2':null,'license':null});}}}return _0x559a02;})['then'](function(_0x15f593){_0x559a02=_0x15f593;})[_0x3b00('0xc')](function(_0x5131a8){logger['error'](_0x5131a8[_0x3b00('0x21')]);})[_0x3b00('0x22')](function(){setTimeout(function(){manageLicense(hardware[_0x3b00('0x23')](),_0x559a02);},TIME);});}function defaultLicense(){var _0x204147=hardware['getUuid']();if(_0x204147){return db[_0x3b00('0x24')][_0x3b00('0x25')]({'where':{'id':0x1},'defaults':{'data1':_0x204147}})[_0x3b00('0x26')](function(_0x16a619,_0x195d68){logger[_0x3b00('0x10')](_0x3b00('0x27'),_0x204147);manageLicense(_0x204147,_0x16a619);})['catch'](function(_0x1af9df){logger[_0x3b00('0x28')](_0x1af9df[_0x3b00('0x21')]);});}}exports[_0x3b00('0x29')]=defaultLicense;