Built motion from commit bab6f49e.|2.6.17
[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 _0x5f88=['format','%s/api/servers/%s/check?version=%s','exports','version','%s/api/servers/%s/check?version=%s&oldtoken=%s','GET','then','catch','get','data1','data2','active','license','THE\x20LICENSE\x20HAS\x20BEEN\x20ENABLED','info','update','THE\x20LICENSE\x20HAS\x20BEEN\x20DISABLED','Changed','YYYY-MM-DD\x20HH:mm','encryptString','diff','days','DEMO\x20START\x20AT\x20%s','NEW\x20UUID\x20DETECTED:\x20FROM\x20%s\x20TO\x20%s','message','getUuid','findOrCreate','spread','SERVICE\x20LICENSE\x20STARTED\x20%s','error','default','util','moment','bluebird','../../mysqldb','./hardware','../logger','https://www.xcallymotion.com'];(function(_0x17356b,_0x581949){var _0x34ece9=function(_0x407739){while(--_0x407739){_0x17356b['push'](_0x17356b['shift']());}};_0x34ece9(++_0x581949);}(_0x5f88,0x103));var _0x85f8=function(_0x181f3c,_0x360d5a){_0x181f3c=_0x181f3c-0x0;var _0x431914=_0x5f88[_0x181f3c];return _0x431914;};'use strict';var util=require(_0x85f8('0x0'));var moment=require(_0x85f8('0x1'));var rp=require('request-promise');var BPromise=require(_0x85f8('0x2'));var pkginfo=require('pkginfo')(module,'version');var db=require(_0x85f8('0x3'))['db'];var encryptor=require('../../components/encryptor');var hardware=require(_0x85f8('0x4'));var logger=require(_0x85f8('0x5'))('license');var HOST=_0x85f8('0x6');var TIME=0x3c*0x1388;var DAYS=0x7;var GRAY_PERIOD_REASON;var oldToken;var isOldTokenSent=![];function httpRequest(_0x20eb8b){return new BPromise(function(_0x2714fe,_0x1011f7){var _0x366148=util[_0x85f8('0x7')](_0x85f8('0x8'),HOST,_0x20eb8b,module[_0x85f8('0x9')][_0x85f8('0xa')]);if(oldToken){_0x366148=util[_0x85f8('0x7')](_0x85f8('0xb'),HOST,_0x20eb8b,module[_0x85f8('0x9')][_0x85f8('0xa')],oldToken);}var _0x244d5a={'uri':_0x366148,'method':_0x85f8('0xc'),'timeout':0xea60,'json':!![]};return rp(_0x244d5a)[_0x85f8('0xd')](function(_0x4feff5){_0x2714fe(_0x4feff5);})[_0x85f8('0xe')](function(_0x209324){_0x1011f7(_0x209324);});});}function manageLicense(_0x2d606e,_0x22d1da){var _0x2ed68d=_0x22d1da[_0x85f8('0xf')]({'plain':!![]});if(!isOldTokenSent&&_0x2ed68d[_0x85f8('0x10')]!==_0x2d606e&&!_0x2ed68d[_0x85f8('0x11')]){oldToken=_0x2ed68d[_0x85f8('0x10')];}httpRequest(_0x2d606e)['then'](function(_0x50511a){if(oldToken){oldToken=undefined;isOldTokenSent=!![];}if(_0x50511a[_0x85f8('0x12')]){isOldTokenSent=![];if(!_0x2ed68d[_0x85f8('0x13')]&&_0x2ed68d[_0x85f8('0x13')]!=_0x50511a[_0x85f8('0x13')]||_0x2ed68d[_0x85f8('0x13')]&&_0x2ed68d[_0x85f8('0x11')]){logger['info'](_0x85f8('0x14'));}if(_0x2ed68d[_0x85f8('0x13')]&&!_0x2ed68d[_0x85f8('0x11')]&&_0x2ed68d[_0x85f8('0x13')]!=_0x50511a[_0x85f8('0x13')]){logger[_0x85f8('0x15')]('THE\x20LICENSE\x20HAS\x20BEEN\x20UPDATED');}if(_0x2ed68d['license']&&!_0x2ed68d[_0x85f8('0x11')]&&_0x2ed68d[_0x85f8('0x13')]==_0x50511a[_0x85f8('0x13')]){return _0x22d1da;}return _0x22d1da[_0x85f8('0x16')]({'data1':_0x2d606e,'data2':null,'license':_0x50511a[_0x85f8('0x13')]});}else{if(_0x50511a[_0x85f8('0x13')]||_0x2ed68d[_0x85f8('0x13')]){if(!_0x2ed68d[_0x85f8('0x11')]){if(_0x2ed68d[_0x85f8('0x10')]==_0x2d606e){GRAY_PERIOD_REASON='Disabled';logger[_0x85f8('0x15')](_0x85f8('0x17'));}else{GRAY_PERIOD_REASON=_0x85f8('0x18');logger[_0x85f8('0x15')]('NEW\x20UUID\x20DETECTED:\x20FROM\x20%s\x20TO\x20%s',_0x2ed68d[_0x85f8('0x10')],_0x2d606e);}logger[_0x85f8('0x15')]('%s\x20-\x20GRAY\x20PERIOD\x20STARTED\x20AT\x20%s',GRAY_PERIOD_REASON['toUpperCase'](),moment()['format'](_0x85f8('0x19')));return _0x22d1da[_0x85f8('0x16')]({'data2':encryptor[_0x85f8('0x1a')](moment()['format']('YYYY-MM-DD\x20HH:mm'))});}else{if(moment()[_0x85f8('0x1b')](encryptor['decryptString'](_0x2ed68d[_0x85f8('0x11')]),_0x85f8('0x1c'))>DAYS){logger[_0x85f8('0x15')](_0x85f8('0x1d'),moment()[_0x85f8('0x7')]('YYYY-MM-DD\x20HH:mm'));isOldTokenSent=![];return _0x22d1da[_0x85f8('0x16')]({'data1':_0x2d606e,'data2':null,'license':null});}}}else{if(_0x2ed68d[_0x85f8('0x10')]!=_0x2d606e){logger[_0x85f8('0x15')](_0x85f8('0x1e'),_0x2ed68d[_0x85f8('0x10')],_0x2d606e);return _0x22d1da['update']({'data1':_0x2d606e,'data2':null,'license':null});}}}return _0x22d1da;})[_0x85f8('0xd')](function(_0x1c262a){_0x22d1da=_0x1c262a;})[_0x85f8('0xe')](function(_0xf1a89f){logger['error'](_0xf1a89f[_0x85f8('0x1f')]);})['finally'](function(){setTimeout(function(){manageLicense(hardware['getUuid'](),_0x22d1da);},TIME);});}function defaultLicense(){var _0x4ca4a0=hardware[_0x85f8('0x20')]();if(_0x4ca4a0){return db['License'][_0x85f8('0x21')]({'where':{'id':0x1},'defaults':{'data1':_0x4ca4a0}})[_0x85f8('0x22')](function(_0x235426,_0x35d55b){logger[_0x85f8('0x15')](_0x85f8('0x23'),_0x4ca4a0);manageLicense(_0x4ca4a0,_0x235426);})[_0x85f8('0xe')](function(_0x41378e){logger[_0x85f8('0x24')](_0x41378e[_0x85f8('0x1f')]);});}}exports[_0x85f8('0x25')]=defaultLicense;