Built motion from commit (unavailable).|2.5.31
[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 _0xbe56=['../../components/encryptor','./hardware','../logger','license','https://www.xcallymotion.com','exports','format','%s/api/servers/%s/check?version=%s&oldtoken=%s','GET','catch','get','data1','then','active','data2','info','THE\x20LICENSE\x20HAS\x20BEEN\x20ENABLED','Disabled','THE\x20LICENSE\x20HAS\x20BEEN\x20DISABLED','Changed','%s\x20-\x20GRAY\x20PERIOD\x20STARTED\x20AT\x20%s','toUpperCase','YYYY-MM-DD\x20HH:mm','update','encryptString','decryptString','DEMO\x20START\x20AT\x20%s','NEW\x20UUID\x20DETECTED:\x20FROM\x20%s\x20TO\x20%s','error','message','finally','getUuid','findOrCreate','spread','SERVICE\x20LICENSE\x20STARTED\x20%s','default','util','bluebird','pkginfo','version','../../mysqldb'];(function(_0x2958ef,_0x31a84a){var _0x29187f=function(_0x48c4cd){while(--_0x48c4cd){_0x2958ef['push'](_0x2958ef['shift']());}};_0x29187f(++_0x31a84a);}(_0xbe56,0x143));var _0x6be5=function(_0x1232d1,_0x4a4ab5){_0x1232d1=_0x1232d1-0x0;var _0x473e31=_0xbe56[_0x1232d1];return _0x473e31;};'use strict';var util=require(_0x6be5('0x0'));var moment=require('moment');var rp=require('request-promise');var BPromise=require(_0x6be5('0x1'));var pkginfo=require(_0x6be5('0x2'))(module,_0x6be5('0x3'));var db=require(_0x6be5('0x4'))['db'];var encryptor=require(_0x6be5('0x5'));var hardware=require(_0x6be5('0x6'));var logger=require(_0x6be5('0x7'))(_0x6be5('0x8'));var HOST=_0x6be5('0x9');var TIME=0x3c*0x1388;var DAYS=0x7;var GRAY_PERIOD_REASON;var oldToken;var isOldTokenSent=![];function httpRequest(_0x31a1b6){return new BPromise(function(_0x7637fd,_0x33dde0){var _0x4d3c5a=util['format']('%s/api/servers/%s/check?version=%s',HOST,_0x31a1b6,module[_0x6be5('0xa')][_0x6be5('0x3')]);if(oldToken){_0x4d3c5a=util[_0x6be5('0xb')](_0x6be5('0xc'),HOST,_0x31a1b6,module[_0x6be5('0xa')][_0x6be5('0x3')],oldToken);}var _0x57164c={'uri':_0x4d3c5a,'method':_0x6be5('0xd'),'timeout':0xea60,'json':!![]};return rp(_0x57164c)['then'](function(_0x4e5b72){_0x7637fd(_0x4e5b72);})[_0x6be5('0xe')](function(_0x3c5685){_0x33dde0(_0x3c5685);});});}function manageLicense(_0x2b8768,_0x955c4d){var _0x129f54=_0x955c4d[_0x6be5('0xf')]({'plain':!![]});if(!isOldTokenSent&&_0x129f54[_0x6be5('0x10')]!==_0x2b8768&&!_0x129f54['data2']){oldToken=_0x129f54[_0x6be5('0x10')];}httpRequest(_0x2b8768)[_0x6be5('0x11')](function(_0x48ea05){if(oldToken){oldToken=undefined;isOldTokenSent=!![];}if(_0x48ea05[_0x6be5('0x12')]){isOldTokenSent=![];if(!_0x129f54['license']&&_0x129f54['license']!=_0x48ea05['license']||_0x129f54[_0x6be5('0x8')]&&_0x129f54[_0x6be5('0x13')]){logger[_0x6be5('0x14')](_0x6be5('0x15'));}if(_0x129f54[_0x6be5('0x8')]&&!_0x129f54[_0x6be5('0x13')]&&_0x129f54['license']!=_0x48ea05['license']){logger[_0x6be5('0x14')]('THE\x20LICENSE\x20HAS\x20BEEN\x20UPDATED');}if(_0x129f54[_0x6be5('0x8')]&&!_0x129f54[_0x6be5('0x13')]&&_0x129f54['license']==_0x48ea05['license']){return _0x955c4d;}return _0x955c4d['update']({'data1':_0x2b8768,'data2':null,'license':_0x48ea05[_0x6be5('0x8')]});}else{if(_0x48ea05['license']||_0x129f54[_0x6be5('0x8')]){if(!_0x129f54['data2']){if(_0x129f54[_0x6be5('0x10')]==_0x2b8768){GRAY_PERIOD_REASON=_0x6be5('0x16');logger[_0x6be5('0x14')](_0x6be5('0x17'));}else{GRAY_PERIOD_REASON=_0x6be5('0x18');logger[_0x6be5('0x14')]('NEW\x20UUID\x20DETECTED:\x20FROM\x20%s\x20TO\x20%s',_0x129f54[_0x6be5('0x10')],_0x2b8768);}logger[_0x6be5('0x14')](_0x6be5('0x19'),GRAY_PERIOD_REASON[_0x6be5('0x1a')](),moment()[_0x6be5('0xb')](_0x6be5('0x1b')));return _0x955c4d[_0x6be5('0x1c')]({'data2':encryptor[_0x6be5('0x1d')](moment()[_0x6be5('0xb')](_0x6be5('0x1b')))});}else{if(moment()['diff'](encryptor[_0x6be5('0x1e')](_0x129f54[_0x6be5('0x13')]),'days')>DAYS){logger[_0x6be5('0x14')](_0x6be5('0x1f'),moment()[_0x6be5('0xb')]('YYYY-MM-DD\x20HH:mm'));isOldTokenSent=![];return _0x955c4d[_0x6be5('0x1c')]({'data1':_0x2b8768,'data2':null,'license':null});}}}else{if(_0x129f54[_0x6be5('0x10')]!=_0x2b8768){logger[_0x6be5('0x14')](_0x6be5('0x20'),_0x129f54['data1'],_0x2b8768);return _0x955c4d[_0x6be5('0x1c')]({'data1':_0x2b8768,'data2':null,'license':null});}}}return _0x955c4d;})[_0x6be5('0x11')](function(_0x5530c6){_0x955c4d=_0x5530c6;})[_0x6be5('0xe')](function(_0x171031){logger[_0x6be5('0x21')](_0x171031[_0x6be5('0x22')]);})[_0x6be5('0x23')](function(){setTimeout(function(){manageLicense(hardware[_0x6be5('0x24')](),_0x955c4d);},TIME);});}function defaultLicense(){var _0x1a543a=hardware[_0x6be5('0x24')]();if(_0x1a543a){return db['License'][_0x6be5('0x25')]({'where':{'id':0x1},'defaults':{'data1':_0x1a543a}})[_0x6be5('0x26')](function(_0x313236,_0xf10a62){logger[_0x6be5('0x14')](_0x6be5('0x27'),_0x1a543a);manageLicense(_0x1a543a,_0x313236);})[_0x6be5('0xe')](function(_0xdd3a49){logger[_0x6be5('0x21')](_0xdd3a49[_0x6be5('0x22')]);});}}exports[_0x6be5('0x28')]=defaultLicense;