Built motion from commit d1eab355.|2.6.28
[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 _0x010b=['then','catch','get','data2','data1','active','info','THE\x20LICENSE\x20HAS\x20BEEN\x20ENABLED','THE\x20LICENSE\x20HAS\x20BEEN\x20UPDATED','update','Disabled','Changed','%s\x20-\x20GRAY\x20PERIOD\x20STARTED\x20AT\x20%s','toUpperCase','encryptString','YYYY-MM-DD\x20HH:mm','diff','decryptString','days','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','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'];(function(_0x3f4378,_0x449d99){var _0x3c0bc8=function(_0x1f5cd9){while(--_0x1f5cd9){_0x3f4378['push'](_0x3f4378['shift']());}};_0x3c0bc8(++_0x449d99);}(_0x010b,0xf9));var _0xb010=function(_0x3c416,_0x17fec5){_0x3c416=_0x3c416-0x0;var _0x464b67=_0x010b[_0x3c416];return _0x464b67;};'use strict';var util=require(_0xb010('0x0'));var moment=require(_0xb010('0x1'));var rp=require(_0xb010('0x2'));var BPromise=require(_0xb010('0x3'));var pkginfo=require(_0xb010('0x4'))(module,_0xb010('0x5'));var db=require('../../mysqldb')['db'];var encryptor=require('../../components/encryptor');var hardware=require(_0xb010('0x6'));var logger=require(_0xb010('0x7'))(_0xb010('0x8'));var HOST=_0xb010('0x9');var TIME=0x3c*0x1388;var DAYS=0x7;var GRAY_PERIOD_REASON;var oldToken;var isOldTokenSent=![];function httpRequest(_0x5ec0c0){return new BPromise(function(_0x504f29,_0x12b7cb){var _0x33d0e2=util[_0xb010('0xa')](_0xb010('0xb'),HOST,_0x5ec0c0,module[_0xb010('0xc')][_0xb010('0x5')]);if(oldToken){_0x33d0e2=util[_0xb010('0xa')](_0xb010('0xd'),HOST,_0x5ec0c0,module['exports']['version'],oldToken);}var _0x43997f={'uri':_0x33d0e2,'method':_0xb010('0xe'),'timeout':0xea60,'json':!![]};return rp(_0x43997f)[_0xb010('0xf')](function(_0x4fd69b){_0x504f29(_0x4fd69b);})[_0xb010('0x10')](function(_0x598a7e){_0x12b7cb(_0x598a7e);});});}function manageLicense(_0x51e2f0,_0x306331){var _0x416e25=_0x306331[_0xb010('0x11')]({'plain':!![]});if(!isOldTokenSent&&_0x416e25['data1']!==_0x51e2f0&&!_0x416e25[_0xb010('0x12')]){oldToken=_0x416e25[_0xb010('0x13')];}httpRequest(_0x51e2f0)['then'](function(_0x4a7bbe){if(oldToken){oldToken=undefined;isOldTokenSent=!![];}if(_0x4a7bbe[_0xb010('0x14')]){isOldTokenSent=![];if(!_0x416e25['license']&&_0x416e25[_0xb010('0x8')]!=_0x4a7bbe[_0xb010('0x8')]||_0x416e25[_0xb010('0x8')]&&_0x416e25['data2']){logger[_0xb010('0x15')](_0xb010('0x16'));}if(_0x416e25['license']&&!_0x416e25[_0xb010('0x12')]&&_0x416e25[_0xb010('0x8')]!=_0x4a7bbe[_0xb010('0x8')]){logger[_0xb010('0x15')](_0xb010('0x17'));}if(_0x416e25[_0xb010('0x8')]&&!_0x416e25[_0xb010('0x12')]&&_0x416e25[_0xb010('0x8')]==_0x4a7bbe['license']){return _0x306331;}return _0x306331[_0xb010('0x18')]({'data1':_0x51e2f0,'data2':null,'license':_0x4a7bbe[_0xb010('0x8')]});}else{if(_0x4a7bbe[_0xb010('0x8')]||_0x416e25[_0xb010('0x8')]){if(!_0x416e25[_0xb010('0x12')]){if(_0x416e25[_0xb010('0x13')]==_0x51e2f0){GRAY_PERIOD_REASON=_0xb010('0x19');logger['info']('THE\x20LICENSE\x20HAS\x20BEEN\x20DISABLED');}else{GRAY_PERIOD_REASON=_0xb010('0x1a');logger[_0xb010('0x15')]('NEW\x20UUID\x20DETECTED:\x20FROM\x20%s\x20TO\x20%s',_0x416e25[_0xb010('0x13')],_0x51e2f0);}logger[_0xb010('0x15')](_0xb010('0x1b'),GRAY_PERIOD_REASON[_0xb010('0x1c')](),moment()['format']('YYYY-MM-DD\x20HH:mm'));return _0x306331[_0xb010('0x18')]({'data2':encryptor[_0xb010('0x1d')](moment()['format'](_0xb010('0x1e')))});}else{if(moment()[_0xb010('0x1f')](encryptor[_0xb010('0x20')](_0x416e25[_0xb010('0x12')]),_0xb010('0x21'))>DAYS){logger['info'](_0xb010('0x22'),moment()['format'](_0xb010('0x1e')));isOldTokenSent=![];return _0x306331[_0xb010('0x18')]({'data1':_0x51e2f0,'data2':null,'license':null});}}}else{if(_0x416e25['data1']!=_0x51e2f0){logger[_0xb010('0x15')](_0xb010('0x23'),_0x416e25[_0xb010('0x13')],_0x51e2f0);return _0x306331[_0xb010('0x18')]({'data1':_0x51e2f0,'data2':null,'license':null});}}}return _0x306331;})[_0xb010('0xf')](function(_0x176c08){_0x306331=_0x176c08;})[_0xb010('0x10')](function(_0x26d2e6){logger[_0xb010('0x24')](_0x26d2e6[_0xb010('0x25')]);})[_0xb010('0x26')](function(){setTimeout(function(){manageLicense(hardware[_0xb010('0x27')](),_0x306331);},TIME);});}function defaultLicense(){var _0x1b3a8d=hardware[_0xb010('0x27')]();if(_0x1b3a8d){return db['License'][_0xb010('0x28')]({'where':{'id':0x1},'defaults':{'data1':_0x1b3a8d}})[_0xb010('0x29')](function(_0x5451c1,_0x45e553){logger[_0xb010('0x15')](_0xb010('0x2a'),_0x1b3a8d);manageLicense(_0x1b3a8d,_0x5451c1);})[_0xb010('0x10')](function(_0x387c83){logger[_0xb010('0x24')](_0x387c83['message']);});}}exports[_0xb010('0x2b')]=defaultLicense;