Built motion from commit a679711e.|2.6.15
[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 _0x0c7f=['bluebird','version','../../mysqldb','../../components/encryptor','./hardware','https://www.xcallymotion.com','format','%s/api/servers/%s/check?version=%s','exports','%s/api/servers/%s/check?version=%s&oldtoken=%s','catch','get','data1','data2','then','active','license','info','THE\x20LICENSE\x20HAS\x20BEEN\x20ENABLED','THE\x20LICENSE\x20HAS\x20BEEN\x20UPDATED','Disabled','THE\x20LICENSE\x20HAS\x20BEEN\x20DISABLED','Changed','YYYY-MM-DD\x20HH:mm','update','encryptString','diff','decryptString','days','DEMO\x20START\x20AT\x20%s','NEW\x20UUID\x20DETECTED:\x20FROM\x20%s\x20TO\x20%s','error','message','finally','getUuid','findOrCreate','SERVICE\x20LICENSE\x20STARTED\x20%s','default','util','moment','request-promise'];(function(_0x2d8fc2,_0x1c461d){var _0x3a9e53=function(_0x18941c){while(--_0x18941c){_0x2d8fc2['push'](_0x2d8fc2['shift']());}};_0x3a9e53(++_0x1c461d);}(_0x0c7f,0x1e9));var _0xf0c7=function(_0x14add3,_0x13ce8d){_0x14add3=_0x14add3-0x0;var _0x4a174f=_0x0c7f[_0x14add3];return _0x4a174f;};'use strict';var util=require(_0xf0c7('0x0'));var moment=require(_0xf0c7('0x1'));var rp=require(_0xf0c7('0x2'));var BPromise=require(_0xf0c7('0x3'));var pkginfo=require('pkginfo')(module,_0xf0c7('0x4'));var db=require(_0xf0c7('0x5'))['db'];var encryptor=require(_0xf0c7('0x6'));var hardware=require(_0xf0c7('0x7'));var logger=require('../logger')('license');var HOST=_0xf0c7('0x8');var TIME=0x3c*0x1388;var DAYS=0x7;var GRAY_PERIOD_REASON;var oldToken;var isOldTokenSent=![];function httpRequest(_0x230f31){return new BPromise(function(_0x3c9751,_0x132c0c){var _0x34c579=util[_0xf0c7('0x9')](_0xf0c7('0xa'),HOST,_0x230f31,module[_0xf0c7('0xb')][_0xf0c7('0x4')]);if(oldToken){_0x34c579=util['format'](_0xf0c7('0xc'),HOST,_0x230f31,module[_0xf0c7('0xb')][_0xf0c7('0x4')],oldToken);}var _0x14ad0b={'uri':_0x34c579,'method':'GET','timeout':0xea60,'json':!![]};return rp(_0x14ad0b)['then'](function(_0x3ed815){_0x3c9751(_0x3ed815);})[_0xf0c7('0xd')](function(_0x53e13d){_0x132c0c(_0x53e13d);});});}function manageLicense(_0x14c269,_0x408f13){var _0x57a114=_0x408f13[_0xf0c7('0xe')]({'plain':!![]});if(!isOldTokenSent&&_0x57a114[_0xf0c7('0xf')]!==_0x14c269&&!_0x57a114[_0xf0c7('0x10')]){oldToken=_0x57a114[_0xf0c7('0xf')];}httpRequest(_0x14c269)[_0xf0c7('0x11')](function(_0x3ee2ed){if(oldToken){oldToken=undefined;isOldTokenSent=!![];}if(_0x3ee2ed[_0xf0c7('0x12')]){isOldTokenSent=![];if(!_0x57a114[_0xf0c7('0x13')]&&_0x57a114[_0xf0c7('0x13')]!=_0x3ee2ed[_0xf0c7('0x13')]||_0x57a114['license']&&_0x57a114['data2']){logger[_0xf0c7('0x14')](_0xf0c7('0x15'));}if(_0x57a114[_0xf0c7('0x13')]&&!_0x57a114[_0xf0c7('0x10')]&&_0x57a114['license']!=_0x3ee2ed['license']){logger['info'](_0xf0c7('0x16'));}if(_0x57a114[_0xf0c7('0x13')]&&!_0x57a114[_0xf0c7('0x10')]&&_0x57a114[_0xf0c7('0x13')]==_0x3ee2ed[_0xf0c7('0x13')]){return _0x408f13;}return _0x408f13['update']({'data1':_0x14c269,'data2':null,'license':_0x3ee2ed[_0xf0c7('0x13')]});}else{if(_0x3ee2ed[_0xf0c7('0x13')]||_0x57a114[_0xf0c7('0x13')]){if(!_0x57a114[_0xf0c7('0x10')]){if(_0x57a114[_0xf0c7('0xf')]==_0x14c269){GRAY_PERIOD_REASON=_0xf0c7('0x17');logger['info'](_0xf0c7('0x18'));}else{GRAY_PERIOD_REASON=_0xf0c7('0x19');logger[_0xf0c7('0x14')]('NEW\x20UUID\x20DETECTED:\x20FROM\x20%s\x20TO\x20%s',_0x57a114[_0xf0c7('0xf')],_0x14c269);}logger[_0xf0c7('0x14')]('%s\x20-\x20GRAY\x20PERIOD\x20STARTED\x20AT\x20%s',GRAY_PERIOD_REASON['toUpperCase'](),moment()[_0xf0c7('0x9')](_0xf0c7('0x1a')));return _0x408f13[_0xf0c7('0x1b')]({'data2':encryptor[_0xf0c7('0x1c')](moment()[_0xf0c7('0x9')](_0xf0c7('0x1a')))});}else{if(moment()[_0xf0c7('0x1d')](encryptor[_0xf0c7('0x1e')](_0x57a114[_0xf0c7('0x10')]),_0xf0c7('0x1f'))>DAYS){logger[_0xf0c7('0x14')](_0xf0c7('0x20'),moment()[_0xf0c7('0x9')](_0xf0c7('0x1a')));isOldTokenSent=![];return _0x408f13[_0xf0c7('0x1b')]({'data1':_0x14c269,'data2':null,'license':null});}}}else{if(_0x57a114[_0xf0c7('0xf')]!=_0x14c269){logger[_0xf0c7('0x14')](_0xf0c7('0x21'),_0x57a114[_0xf0c7('0xf')],_0x14c269);return _0x408f13[_0xf0c7('0x1b')]({'data1':_0x14c269,'data2':null,'license':null});}}}return _0x408f13;})[_0xf0c7('0x11')](function(_0x2bd3d2){_0x408f13=_0x2bd3d2;})['catch'](function(_0x360a5b){logger[_0xf0c7('0x22')](_0x360a5b[_0xf0c7('0x23')]);})[_0xf0c7('0x24')](function(){setTimeout(function(){manageLicense(hardware[_0xf0c7('0x25')](),_0x408f13);},TIME);});}function defaultLicense(){var _0x20ed4c=hardware[_0xf0c7('0x25')]();if(_0x20ed4c){return db['License'][_0xf0c7('0x26')]({'where':{'id':0x1},'defaults':{'data1':_0x20ed4c}})['spread'](function(_0x2920bc,_0x1d154d){logger[_0xf0c7('0x14')](_0xf0c7('0x27'),_0x20ed4c);manageLicense(_0x20ed4c,_0x2920bc);})['catch'](function(_0x19ac03){logger[_0xf0c7('0x22')](_0x19ac03[_0xf0c7('0x23')]);});}}exports[_0xf0c7('0x28')]=defaultLicense;