0657a1438f1364e79d0f84f4ed19425bebd5c44c
[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 _0x087d=['default','util','moment','request-promise','bluebird','pkginfo','version','./hardware','../logger','license','https://www.xcallymotion.com','format','%s/api/servers/%s/check?version=%s','exports','%s/api/servers/%s/check?version=%s&oldtoken=%s','GET','then','get','data2','data1','active','THE\x20LICENSE\x20HAS\x20BEEN\x20ENABLED','info','THE\x20LICENSE\x20HAS\x20BEEN\x20UPDATED','Disabled','Changed','NEW\x20UUID\x20DETECTED:\x20FROM\x20%s\x20TO\x20%s','%s\x20-\x20GRAY\x20PERIOD\x20STARTED\x20AT\x20%s','toUpperCase','YYYY-MM-DD\x20HH:mm','update','diff','decryptString','days','DEMO\x20START\x20AT\x20%s','catch','error','finally','getUuid','spread','message'];(function(_0x20cb20,_0x256051){var _0x2fcf4b=function(_0x26200b){while(--_0x26200b){_0x20cb20['push'](_0x20cb20['shift']());}};_0x2fcf4b(++_0x256051);}(_0x087d,0xa5));var _0xd087=function(_0x233f44,_0x148a02){_0x233f44=_0x233f44-0x0;var _0x32349c=_0x087d[_0x233f44];return _0x32349c;};'use strict';var util=require(_0xd087('0x0'));var moment=require(_0xd087('0x1'));var rp=require(_0xd087('0x2'));var BPromise=require(_0xd087('0x3'));var pkginfo=require(_0xd087('0x4'))(module,_0xd087('0x5'));var db=require('../../mysqldb')['db'];var encryptor=require('../../components/encryptor');var hardware=require(_0xd087('0x6'));var logger=require(_0xd087('0x7'))(_0xd087('0x8'));var HOST=_0xd087('0x9');var TIME=0x3c*0x1388;var DAYS=0x7;var GRAY_PERIOD_REASON;var oldToken;var isOldTokenSent=![];function httpRequest(_0x55bb85){return new BPromise(function(_0x6e321d,_0x515a0d){var _0x48880d=util[_0xd087('0xa')](_0xd087('0xb'),HOST,_0x55bb85,module[_0xd087('0xc')][_0xd087('0x5')]);if(oldToken){_0x48880d=util[_0xd087('0xa')](_0xd087('0xd'),HOST,_0x55bb85,module['exports']['version'],oldToken);}var _0x465796={'uri':_0x48880d,'method':_0xd087('0xe'),'timeout':0xea60,'json':!![]};return rp(_0x465796)[_0xd087('0xf')](function(_0x30a41e){_0x6e321d(_0x30a41e);})['catch'](function(_0x52a959){_0x515a0d(_0x52a959);});});}function manageLicense(_0x5f125d,_0xfcbc70){var _0x53f211=_0xfcbc70[_0xd087('0x10')]({'plain':!![]});if(!isOldTokenSent&&_0x53f211['data1']!==_0x5f125d&&!_0x53f211[_0xd087('0x11')]){oldToken=_0x53f211[_0xd087('0x12')];}httpRequest(_0x5f125d)[_0xd087('0xf')](function(_0x112ead){if(oldToken){oldToken=undefined;isOldTokenSent=!![];}if(_0x112ead[_0xd087('0x13')]){isOldTokenSent=![];if(!_0x53f211[_0xd087('0x8')]&&_0x53f211[_0xd087('0x8')]!=_0x112ead['license']||_0x53f211[_0xd087('0x8')]&&_0x53f211[_0xd087('0x11')]){logger['info'](_0xd087('0x14'));}if(_0x53f211[_0xd087('0x8')]&&!_0x53f211[_0xd087('0x11')]&&_0x53f211[_0xd087('0x8')]!=_0x112ead['license']){logger[_0xd087('0x15')](_0xd087('0x16'));}if(_0x53f211[_0xd087('0x8')]&&!_0x53f211[_0xd087('0x11')]&&_0x53f211[_0xd087('0x8')]==_0x112ead['license']){return _0xfcbc70;}return _0xfcbc70['update']({'data1':_0x5f125d,'data2':null,'license':_0x112ead['license']});}else{if(_0x112ead[_0xd087('0x8')]||_0x53f211[_0xd087('0x8')]){if(!_0x53f211[_0xd087('0x11')]){if(_0x53f211[_0xd087('0x12')]==_0x5f125d){GRAY_PERIOD_REASON=_0xd087('0x17');logger[_0xd087('0x15')]('THE\x20LICENSE\x20HAS\x20BEEN\x20DISABLED');}else{GRAY_PERIOD_REASON=_0xd087('0x18');logger[_0xd087('0x15')](_0xd087('0x19'),_0x53f211[_0xd087('0x12')],_0x5f125d);}logger[_0xd087('0x15')](_0xd087('0x1a'),GRAY_PERIOD_REASON[_0xd087('0x1b')](),moment()[_0xd087('0xa')](_0xd087('0x1c')));return _0xfcbc70[_0xd087('0x1d')]({'data2':encryptor['encryptString'](moment()['format'](_0xd087('0x1c')))});}else{if(moment()[_0xd087('0x1e')](encryptor[_0xd087('0x1f')](_0x53f211[_0xd087('0x11')]),_0xd087('0x20'))>DAYS){logger['info'](_0xd087('0x21'),moment()[_0xd087('0xa')](_0xd087('0x1c')));isOldTokenSent=![];return _0xfcbc70[_0xd087('0x1d')]({'data1':_0x5f125d,'data2':null,'license':null});}}}else{if(_0x53f211[_0xd087('0x12')]!=_0x5f125d){logger['info']('NEW\x20UUID\x20DETECTED:\x20FROM\x20%s\x20TO\x20%s',_0x53f211[_0xd087('0x12')],_0x5f125d);return _0xfcbc70['update']({'data1':_0x5f125d,'data2':null,'license':null});}}}return _0xfcbc70;})[_0xd087('0xf')](function(_0x243734){_0xfcbc70=_0x243734;})[_0xd087('0x22')](function(_0x2a51b4){logger[_0xd087('0x23')](_0x2a51b4['message']);})[_0xd087('0x24')](function(){setTimeout(function(){manageLicense(hardware[_0xd087('0x25')](),_0xfcbc70);},TIME);});}function defaultLicense(){var _0x2a687a=hardware[_0xd087('0x25')]();if(_0x2a687a){return db['License']['findOrCreate']({'where':{'id':0x1},'defaults':{'data1':_0x2a687a}})[_0xd087('0x26')](function(_0x234a8a,_0x4a7a92){logger[_0xd087('0x15')]('SERVICE\x20LICENSE\x20STARTED\x20%s',_0x2a687a);manageLicense(_0x2a687a,_0x234a8a);})[_0xd087('0x22')](function(_0x148e3d){logger['error'](_0x148e3d[_0xd087('0x27')]);});}}exports[_0xd087('0x28')]=defaultLicense;