b193a57241161d9532e7b0ad3c53187884536a95
[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 _0xdad3=['request-promise','bluebird','version','../logger','https://www.xcallymotion.com','format','exports','%s/api/servers/%s/check?version=%s&oldtoken=%s','GET','then','catch','get','data1','license','data2','THE\x20LICENSE\x20HAS\x20BEEN\x20ENABLED','info','THE\x20LICENSE\x20HAS\x20BEEN\x20UPDATED','Disabled','Changed','%s\x20-\x20GRAY\x20PERIOD\x20STARTED\x20AT\x20%s','YYYY-MM-DD\x20HH:mm','update','encryptString','diff','days','DEMO\x20START\x20AT\x20%s','NEW\x20UUID\x20DETECTED:\x20FROM\x20%s\x20TO\x20%s','error','message','finally','getUuid','spread','SERVICE\x20LICENSE\x20STARTED\x20%s','default','util','moment'];(function(_0x40c345,_0x4f7530){var _0x13bff3=function(_0x4ba4e9){while(--_0x4ba4e9){_0x40c345['push'](_0x40c345['shift']());}};_0x13bff3(++_0x4f7530);}(_0xdad3,0x1ba));var _0x3dad=function(_0x14345f,_0x299964){_0x14345f=_0x14345f-0x0;var _0x3053d2=_0xdad3[_0x14345f];return _0x3053d2;};'use strict';var util=require(_0x3dad('0x0'));var moment=require(_0x3dad('0x1'));var rp=require(_0x3dad('0x2'));var BPromise=require(_0x3dad('0x3'));var pkginfo=require('pkginfo')(module,_0x3dad('0x4'));var db=require('../../mysqldb')['db'];var encryptor=require('../../components/encryptor');var hardware=require('./hardware');var logger=require(_0x3dad('0x5'))('license');var HOST=_0x3dad('0x6');var TIME=0x3c*0x1388;var DAYS=0x7;var GRAY_PERIOD_REASON;var oldToken;var isOldTokenSent=![];function httpRequest(_0x437107){return new BPromise(function(_0x4d3bd4,_0x492c1a){var _0xaf8aa5=util[_0x3dad('0x7')]('%s/api/servers/%s/check?version=%s',HOST,_0x437107,module[_0x3dad('0x8')][_0x3dad('0x4')]);if(oldToken){_0xaf8aa5=util[_0x3dad('0x7')](_0x3dad('0x9'),HOST,_0x437107,module['exports'][_0x3dad('0x4')],oldToken);}var _0x353d48={'uri':_0xaf8aa5,'method':_0x3dad('0xa'),'timeout':0xea60,'json':!![]};return rp(_0x353d48)[_0x3dad('0xb')](function(_0x513bbc){_0x4d3bd4(_0x513bbc);})[_0x3dad('0xc')](function(_0x132723){_0x492c1a(_0x132723);});});}function manageLicense(_0x5c8a87,_0x91b691){var _0x3d189b=_0x91b691[_0x3dad('0xd')]({'plain':!![]});if(!isOldTokenSent&&_0x3d189b[_0x3dad('0xe')]!==_0x5c8a87&&!_0x3d189b['data2']){oldToken=_0x3d189b[_0x3dad('0xe')];}httpRequest(_0x5c8a87)['then'](function(_0x116038){if(oldToken){oldToken=undefined;isOldTokenSent=!![];}if(_0x116038['active']){isOldTokenSent=![];if(!_0x3d189b['license']&&_0x3d189b['license']!=_0x116038[_0x3dad('0xf')]||_0x3d189b['license']&&_0x3d189b[_0x3dad('0x10')]){logger['info'](_0x3dad('0x11'));}if(_0x3d189b[_0x3dad('0xf')]&&!_0x3d189b['data2']&&_0x3d189b[_0x3dad('0xf')]!=_0x116038['license']){logger[_0x3dad('0x12')](_0x3dad('0x13'));}if(_0x3d189b['license']&&!_0x3d189b[_0x3dad('0x10')]&&_0x3d189b[_0x3dad('0xf')]==_0x116038[_0x3dad('0xf')]){return _0x91b691;}return _0x91b691['update']({'data1':_0x5c8a87,'data2':null,'license':_0x116038[_0x3dad('0xf')]});}else{if(_0x116038[_0x3dad('0xf')]||_0x3d189b[_0x3dad('0xf')]){if(!_0x3d189b[_0x3dad('0x10')]){if(_0x3d189b[_0x3dad('0xe')]==_0x5c8a87){GRAY_PERIOD_REASON=_0x3dad('0x14');logger[_0x3dad('0x12')]('THE\x20LICENSE\x20HAS\x20BEEN\x20DISABLED');}else{GRAY_PERIOD_REASON=_0x3dad('0x15');logger[_0x3dad('0x12')]('NEW\x20UUID\x20DETECTED:\x20FROM\x20%s\x20TO\x20%s',_0x3d189b[_0x3dad('0xe')],_0x5c8a87);}logger['info'](_0x3dad('0x16'),GRAY_PERIOD_REASON['toUpperCase'](),moment()[_0x3dad('0x7')](_0x3dad('0x17')));return _0x91b691[_0x3dad('0x18')]({'data2':encryptor[_0x3dad('0x19')](moment()['format']('YYYY-MM-DD\x20HH:mm'))});}else{if(moment()[_0x3dad('0x1a')](encryptor['decryptString'](_0x3d189b['data2']),_0x3dad('0x1b'))>DAYS){logger[_0x3dad('0x12')](_0x3dad('0x1c'),moment()['format'](_0x3dad('0x17')));isOldTokenSent=![];return _0x91b691[_0x3dad('0x18')]({'data1':_0x5c8a87,'data2':null,'license':null});}}}else{if(_0x3d189b['data1']!=_0x5c8a87){logger[_0x3dad('0x12')](_0x3dad('0x1d'),_0x3d189b['data1'],_0x5c8a87);return _0x91b691[_0x3dad('0x18')]({'data1':_0x5c8a87,'data2':null,'license':null});}}}return _0x91b691;})[_0x3dad('0xb')](function(_0x1edfcb){_0x91b691=_0x1edfcb;})[_0x3dad('0xc')](function(_0x1a5456){logger[_0x3dad('0x1e')](_0x1a5456[_0x3dad('0x1f')]);})[_0x3dad('0x20')](function(){setTimeout(function(){manageLicense(hardware['getUuid'](),_0x91b691);},TIME);});}function defaultLicense(){var _0x54be9d=hardware[_0x3dad('0x21')]();if(_0x54be9d){return db['License']['findOrCreate']({'where':{'id':0x1},'defaults':{'data1':_0x54be9d}})[_0x3dad('0x22')](function(_0x30de2d,_0x362eeb){logger[_0x3dad('0x12')](_0x3dad('0x23'),_0x54be9d);manageLicense(_0x54be9d,_0x30de2d);})['catch'](function(_0x428a85){logger[_0x3dad('0x1e')](_0x428a85[_0x3dad('0x1f')]);});}}exports[_0x3dad('0x24')]=defaultLicense;