Built motion from commit d69f4380.|2.6.29
[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 _0x4f67=['../../mysqldb','../../components/encryptor','../logger','license','%s/api/servers/%s/check?version=%s','exports','%s/api/servers/%s/check?version=%s&oldtoken=%s','GET','catch','get','data1','data2','then','active','info','THE\x20LICENSE\x20HAS\x20BEEN\x20ENABLED','THE\x20LICENSE\x20HAS\x20BEEN\x20UPDATED','update','THE\x20LICENSE\x20HAS\x20BEEN\x20DISABLED','NEW\x20UUID\x20DETECTED:\x20FROM\x20%s\x20TO\x20%s','%s\x20-\x20GRAY\x20PERIOD\x20STARTED\x20AT\x20%s','format','diff','decryptString','DEMO\x20START\x20AT\x20%s','YYYY-MM-DD\x20HH:mm','error','message','finally','getUuid','findOrCreate','spread','default','moment','request-promise','bluebird','version'];(function(_0x467375,_0x328c2f){var _0x584af5=function(_0x6c098c){while(--_0x6c098c){_0x467375['push'](_0x467375['shift']());}};_0x584af5(++_0x328c2f);}(_0x4f67,0xb5));var _0x74f6=function(_0x33f1f1,_0x3f2a10){_0x33f1f1=_0x33f1f1-0x0;var _0x3052d4=_0x4f67[_0x33f1f1];return _0x3052d4;};'use strict';var util=require('util');var moment=require(_0x74f6('0x0'));var rp=require(_0x74f6('0x1'));var BPromise=require(_0x74f6('0x2'));var pkginfo=require('pkginfo')(module,_0x74f6('0x3'));var db=require(_0x74f6('0x4'))['db'];var encryptor=require(_0x74f6('0x5'));var hardware=require('./hardware');var logger=require(_0x74f6('0x6'))(_0x74f6('0x7'));var HOST='https://www.xcallymotion.com';var TIME=0x3c*0x1388;var DAYS=0x7;var GRAY_PERIOD_REASON;var oldToken;var isOldTokenSent=![];function httpRequest(_0x2bec91){return new BPromise(function(_0x69c482,_0x28fb84){var _0x1908da=util['format'](_0x74f6('0x8'),HOST,_0x2bec91,module[_0x74f6('0x9')][_0x74f6('0x3')]);if(oldToken){_0x1908da=util['format'](_0x74f6('0xa'),HOST,_0x2bec91,module['exports']['version'],oldToken);}var _0x32c025={'uri':_0x1908da,'method':_0x74f6('0xb'),'timeout':0xea60,'json':!![]};return rp(_0x32c025)['then'](function(_0x5af6cb){_0x69c482(_0x5af6cb);})[_0x74f6('0xc')](function(_0x4f28b6){_0x28fb84(_0x4f28b6);});});}function manageLicense(_0x39cc66,_0x3db1ae){var _0x41f8c1=_0x3db1ae[_0x74f6('0xd')]({'plain':!![]});if(!isOldTokenSent&&_0x41f8c1[_0x74f6('0xe')]!==_0x39cc66&&!_0x41f8c1[_0x74f6('0xf')]){oldToken=_0x41f8c1['data1'];}httpRequest(_0x39cc66)[_0x74f6('0x10')](function(_0x4a6089){if(oldToken){oldToken=undefined;isOldTokenSent=!![];}if(_0x4a6089[_0x74f6('0x11')]){isOldTokenSent=![];if(!_0x41f8c1['license']&&_0x41f8c1[_0x74f6('0x7')]!=_0x4a6089['license']||_0x41f8c1[_0x74f6('0x7')]&&_0x41f8c1['data2']){logger[_0x74f6('0x12')](_0x74f6('0x13'));}if(_0x41f8c1['license']&&!_0x41f8c1[_0x74f6('0xf')]&&_0x41f8c1[_0x74f6('0x7')]!=_0x4a6089['license']){logger[_0x74f6('0x12')](_0x74f6('0x14'));}if(_0x41f8c1[_0x74f6('0x7')]&&!_0x41f8c1['data2']&&_0x41f8c1['license']==_0x4a6089[_0x74f6('0x7')]){return _0x3db1ae;}return _0x3db1ae[_0x74f6('0x15')]({'data1':_0x39cc66,'data2':null,'license':_0x4a6089[_0x74f6('0x7')]});}else{if(_0x4a6089[_0x74f6('0x7')]||_0x41f8c1[_0x74f6('0x7')]){if(!_0x41f8c1[_0x74f6('0xf')]){if(_0x41f8c1[_0x74f6('0xe')]==_0x39cc66){GRAY_PERIOD_REASON='Disabled';logger['info'](_0x74f6('0x16'));}else{GRAY_PERIOD_REASON='Changed';logger[_0x74f6('0x12')](_0x74f6('0x17'),_0x41f8c1[_0x74f6('0xe')],_0x39cc66);}logger[_0x74f6('0x12')](_0x74f6('0x18'),GRAY_PERIOD_REASON['toUpperCase'](),moment()[_0x74f6('0x19')]('YYYY-MM-DD\x20HH:mm'));return _0x3db1ae[_0x74f6('0x15')]({'data2':encryptor['encryptString'](moment()[_0x74f6('0x19')]('YYYY-MM-DD\x20HH:mm'))});}else{if(moment()[_0x74f6('0x1a')](encryptor[_0x74f6('0x1b')](_0x41f8c1['data2']),'days')>DAYS){logger[_0x74f6('0x12')](_0x74f6('0x1c'),moment()['format'](_0x74f6('0x1d')));isOldTokenSent=![];return _0x3db1ae[_0x74f6('0x15')]({'data1':_0x39cc66,'data2':null,'license':null});}}}else{if(_0x41f8c1['data1']!=_0x39cc66){logger[_0x74f6('0x12')]('NEW\x20UUID\x20DETECTED:\x20FROM\x20%s\x20TO\x20%s',_0x41f8c1[_0x74f6('0xe')],_0x39cc66);return _0x3db1ae[_0x74f6('0x15')]({'data1':_0x39cc66,'data2':null,'license':null});}}}return _0x3db1ae;})[_0x74f6('0x10')](function(_0x47f15c){_0x3db1ae=_0x47f15c;})['catch'](function(_0x21c7d0){logger[_0x74f6('0x1e')](_0x21c7d0[_0x74f6('0x1f')]);})[_0x74f6('0x20')](function(){setTimeout(function(){manageLicense(hardware[_0x74f6('0x21')](),_0x3db1ae);},TIME);});}function defaultLicense(){var _0x3f131e=hardware[_0x74f6('0x21')]();if(_0x3f131e){return db['License'][_0x74f6('0x22')]({'where':{'id':0x1},'defaults':{'data1':_0x3f131e}})[_0x74f6('0x23')](function(_0x498bbd,_0xaa2fbe){logger['info']('SERVICE\x20LICENSE\x20STARTED\x20%s',_0x3f131e);manageLicense(_0x3f131e,_0x498bbd);})[_0x74f6('0xc')](function(_0xdce9f7){logger[_0x74f6('0x1e')](_0xdce9f7['message']);});}}exports[_0x74f6('0x24')]=defaultLicense;