Built motion from commit 9e1399f3.|2.5.37
[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 _0x6c07=['GET','then','catch','get','data2','data1','active','license','info','THE\x20LICENSE\x20HAS\x20BEEN\x20ENABLED','THE\x20LICENSE\x20HAS\x20BEEN\x20UPDATED','update','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','diff','days','DEMO\x20START\x20AT\x20%s','error','message','finally','getUuid','License','findOrCreate','spread','default','moment','request-promise','bluebird','pkginfo','version','../../components/encryptor','../logger','https://www.xcallymotion.com','format','%s/api/servers/%s/check?version=%s','exports','%s/api/servers/%s/check?version=%s&oldtoken=%s'];(function(_0x334841,_0x2bbc4c){var _0x5beb4b=function(_0x4bea72){while(--_0x4bea72){_0x334841['push'](_0x334841['shift']());}};_0x5beb4b(++_0x2bbc4c);}(_0x6c07,0x1b7));var _0x76c0=function(_0x254330,_0x1d6d4a){_0x254330=_0x254330-0x0;var _0x489771=_0x6c07[_0x254330];return _0x489771;};'use strict';var util=require('util');var moment=require(_0x76c0('0x0'));var rp=require(_0x76c0('0x1'));var BPromise=require(_0x76c0('0x2'));var pkginfo=require(_0x76c0('0x3'))(module,_0x76c0('0x4'));var db=require('../../mysqldb')['db'];var encryptor=require(_0x76c0('0x5'));var hardware=require('./hardware');var logger=require(_0x76c0('0x6'))('license');var HOST=_0x76c0('0x7');var TIME=0x3c*0x1388;var DAYS=0x7;var GRAY_PERIOD_REASON;var oldToken;var isOldTokenSent=![];function httpRequest(_0x2216b8){return new BPromise(function(_0x104f74,_0x1b66e5){var _0x580600=util[_0x76c0('0x8')](_0x76c0('0x9'),HOST,_0x2216b8,module[_0x76c0('0xa')]['version']);if(oldToken){_0x580600=util[_0x76c0('0x8')](_0x76c0('0xb'),HOST,_0x2216b8,module[_0x76c0('0xa')]['version'],oldToken);}var _0x45c517={'uri':_0x580600,'method':_0x76c0('0xc'),'timeout':0xea60,'json':!![]};return rp(_0x45c517)[_0x76c0('0xd')](function(_0x18c75a){_0x104f74(_0x18c75a);})[_0x76c0('0xe')](function(_0x130576){_0x1b66e5(_0x130576);});});}function manageLicense(_0x1196ab,_0x17f922){var _0x52747e=_0x17f922[_0x76c0('0xf')]({'plain':!![]});if(!isOldTokenSent&&_0x52747e['data1']!==_0x1196ab&&!_0x52747e[_0x76c0('0x10')]){oldToken=_0x52747e[_0x76c0('0x11')];}httpRequest(_0x1196ab)['then'](function(_0x2d20ec){if(oldToken){oldToken=undefined;isOldTokenSent=!![];}if(_0x2d20ec[_0x76c0('0x12')]){isOldTokenSent=![];if(!_0x52747e[_0x76c0('0x13')]&&_0x52747e[_0x76c0('0x13')]!=_0x2d20ec['license']||_0x52747e[_0x76c0('0x13')]&&_0x52747e['data2']){logger[_0x76c0('0x14')](_0x76c0('0x15'));}if(_0x52747e[_0x76c0('0x13')]&&!_0x52747e[_0x76c0('0x10')]&&_0x52747e[_0x76c0('0x13')]!=_0x2d20ec[_0x76c0('0x13')]){logger[_0x76c0('0x14')](_0x76c0('0x16'));}if(_0x52747e['license']&&!_0x52747e[_0x76c0('0x10')]&&_0x52747e[_0x76c0('0x13')]==_0x2d20ec[_0x76c0('0x13')]){return _0x17f922;}return _0x17f922[_0x76c0('0x17')]({'data1':_0x1196ab,'data2':null,'license':_0x2d20ec[_0x76c0('0x13')]});}else{if(_0x2d20ec[_0x76c0('0x13')]||_0x52747e[_0x76c0('0x13')]){if(!_0x52747e[_0x76c0('0x10')]){if(_0x52747e['data1']==_0x1196ab){GRAY_PERIOD_REASON=_0x76c0('0x18');logger[_0x76c0('0x14')]('THE\x20LICENSE\x20HAS\x20BEEN\x20DISABLED');}else{GRAY_PERIOD_REASON=_0x76c0('0x19');logger[_0x76c0('0x14')](_0x76c0('0x1a'),_0x52747e['data1'],_0x1196ab);}logger['info'](_0x76c0('0x1b'),GRAY_PERIOD_REASON[_0x76c0('0x1c')](),moment()['format'](_0x76c0('0x1d')));return _0x17f922[_0x76c0('0x17')]({'data2':encryptor['encryptString'](moment()[_0x76c0('0x8')](_0x76c0('0x1d')))});}else{if(moment()[_0x76c0('0x1e')](encryptor['decryptString'](_0x52747e['data2']),_0x76c0('0x1f'))>DAYS){logger['info'](_0x76c0('0x20'),moment()[_0x76c0('0x8')]('YYYY-MM-DD\x20HH:mm'));isOldTokenSent=![];return _0x17f922[_0x76c0('0x17')]({'data1':_0x1196ab,'data2':null,'license':null});}}}else{if(_0x52747e[_0x76c0('0x11')]!=_0x1196ab){logger['info'](_0x76c0('0x1a'),_0x52747e[_0x76c0('0x11')],_0x1196ab);return _0x17f922[_0x76c0('0x17')]({'data1':_0x1196ab,'data2':null,'license':null});}}}return _0x17f922;})[_0x76c0('0xd')](function(_0x2463c7){_0x17f922=_0x2463c7;})['catch'](function(_0x535a5c){logger[_0x76c0('0x21')](_0x535a5c[_0x76c0('0x22')]);})[_0x76c0('0x23')](function(){setTimeout(function(){manageLicense(hardware[_0x76c0('0x24')](),_0x17f922);},TIME);});}function defaultLicense(){var _0x3626b9=hardware[_0x76c0('0x24')]();if(_0x3626b9){return db[_0x76c0('0x25')][_0x76c0('0x26')]({'where':{'id':0x1},'defaults':{'data1':_0x3626b9}})[_0x76c0('0x27')](function(_0x3e9b51,_0x165c7d){logger['info']('SERVICE\x20LICENSE\x20STARTED\x20%s',_0x3626b9);manageLicense(_0x3626b9,_0x3e9b51);})[_0x76c0('0xe')](function(_0x4c1c78){logger['error'](_0x4c1c78['message']);});}}exports[_0x76c0('0x28')]=defaultLicense;