Built motion from commit da617fac.|2.6.6
[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 _0x95cc=['update','THE\x20LICENSE\x20HAS\x20BEEN\x20DISABLED','NEW\x20UUID\x20DETECTED:\x20FROM\x20%s\x20TO\x20%s','%s\x20-\x20GRAY\x20PERIOD\x20STARTED\x20AT\x20%s','toUpperCase','encryptString','diff','days','DEMO\x20START\x20AT\x20%s','YYYY-MM-DD\x20HH:mm','error','finally','getUuid','findOrCreate','SERVICE\x20LICENSE\x20STARTED\x20%s','message','util','moment','request-promise','pkginfo','version','../../mysqldb','../../components/encryptor','../logger','https://www.xcallymotion.com','format','%s/api/servers/%s/check?version=%s&oldtoken=%s','catch','get','data1','data2','then','active','license','info','THE\x20LICENSE\x20HAS\x20BEEN\x20UPDATED'];(function(_0x29cdd0,_0x5595fc){var _0x1937af=function(_0x7d37cd){while(--_0x7d37cd){_0x29cdd0['push'](_0x29cdd0['shift']());}};_0x1937af(++_0x5595fc);}(_0x95cc,0x1c0));var _0xc95c=function(_0x4b627a,_0x390c28){_0x4b627a=_0x4b627a-0x0;var _0x2fe234=_0x95cc[_0x4b627a];return _0x2fe234;};'use strict';var util=require(_0xc95c('0x0'));var moment=require(_0xc95c('0x1'));var rp=require(_0xc95c('0x2'));var BPromise=require('bluebird');var pkginfo=require(_0xc95c('0x3'))(module,_0xc95c('0x4'));var db=require(_0xc95c('0x5'))['db'];var encryptor=require(_0xc95c('0x6'));var hardware=require('./hardware');var logger=require(_0xc95c('0x7'))('license');var HOST=_0xc95c('0x8');var TIME=0x3c*0x1388;var DAYS=0x7;var GRAY_PERIOD_REASON;var oldToken;var isOldTokenSent=![];function httpRequest(_0x1e2479){return new BPromise(function(_0x2ac8a2,_0x41c2e8){var _0x330249=util['format']('%s/api/servers/%s/check?version=%s',HOST,_0x1e2479,module['exports'][_0xc95c('0x4')]);if(oldToken){_0x330249=util[_0xc95c('0x9')](_0xc95c('0xa'),HOST,_0x1e2479,module['exports']['version'],oldToken);}var _0x4a3174={'uri':_0x330249,'method':'GET','timeout':0xea60,'json':!![]};return rp(_0x4a3174)['then'](function(_0xc09c48){_0x2ac8a2(_0xc09c48);})[_0xc95c('0xb')](function(_0x959074){_0x41c2e8(_0x959074);});});}function manageLicense(_0xa2328e,_0x213f40){var _0x23803b=_0x213f40[_0xc95c('0xc')]({'plain':!![]});if(!isOldTokenSent&&_0x23803b[_0xc95c('0xd')]!==_0xa2328e&&!_0x23803b[_0xc95c('0xe')]){oldToken=_0x23803b[_0xc95c('0xd')];}httpRequest(_0xa2328e)[_0xc95c('0xf')](function(_0x5003c8){if(oldToken){oldToken=undefined;isOldTokenSent=!![];}if(_0x5003c8[_0xc95c('0x10')]){isOldTokenSent=![];if(!_0x23803b[_0xc95c('0x11')]&&_0x23803b[_0xc95c('0x11')]!=_0x5003c8['license']||_0x23803b['license']&&_0x23803b[_0xc95c('0xe')]){logger[_0xc95c('0x12')]('THE\x20LICENSE\x20HAS\x20BEEN\x20ENABLED');}if(_0x23803b[_0xc95c('0x11')]&&!_0x23803b[_0xc95c('0xe')]&&_0x23803b[_0xc95c('0x11')]!=_0x5003c8['license']){logger[_0xc95c('0x12')](_0xc95c('0x13'));}if(_0x23803b[_0xc95c('0x11')]&&!_0x23803b[_0xc95c('0xe')]&&_0x23803b[_0xc95c('0x11')]==_0x5003c8[_0xc95c('0x11')]){return _0x213f40;}return _0x213f40[_0xc95c('0x14')]({'data1':_0xa2328e,'data2':null,'license':_0x5003c8[_0xc95c('0x11')]});}else{if(_0x5003c8[_0xc95c('0x11')]||_0x23803b[_0xc95c('0x11')]){if(!_0x23803b[_0xc95c('0xe')]){if(_0x23803b[_0xc95c('0xd')]==_0xa2328e){GRAY_PERIOD_REASON='Disabled';logger[_0xc95c('0x12')](_0xc95c('0x15'));}else{GRAY_PERIOD_REASON='Changed';logger[_0xc95c('0x12')](_0xc95c('0x16'),_0x23803b[_0xc95c('0xd')],_0xa2328e);}logger[_0xc95c('0x12')](_0xc95c('0x17'),GRAY_PERIOD_REASON[_0xc95c('0x18')](),moment()[_0xc95c('0x9')]('YYYY-MM-DD\x20HH:mm'));return _0x213f40[_0xc95c('0x14')]({'data2':encryptor[_0xc95c('0x19')](moment()['format']('YYYY-MM-DD\x20HH:mm'))});}else{if(moment()[_0xc95c('0x1a')](encryptor['decryptString'](_0x23803b[_0xc95c('0xe')]),_0xc95c('0x1b'))>DAYS){logger[_0xc95c('0x12')](_0xc95c('0x1c'),moment()['format'](_0xc95c('0x1d')));isOldTokenSent=![];return _0x213f40[_0xc95c('0x14')]({'data1':_0xa2328e,'data2':null,'license':null});}}}else{if(_0x23803b[_0xc95c('0xd')]!=_0xa2328e){logger['info']('NEW\x20UUID\x20DETECTED:\x20FROM\x20%s\x20TO\x20%s',_0x23803b[_0xc95c('0xd')],_0xa2328e);return _0x213f40[_0xc95c('0x14')]({'data1':_0xa2328e,'data2':null,'license':null});}}}return _0x213f40;})[_0xc95c('0xf')](function(_0x518c5c){_0x213f40=_0x518c5c;})[_0xc95c('0xb')](function(_0x167e10){logger[_0xc95c('0x1e')](_0x167e10['message']);})[_0xc95c('0x1f')](function(){setTimeout(function(){manageLicense(hardware[_0xc95c('0x20')](),_0x213f40);},TIME);});}function defaultLicense(){var _0x2fbfb7=hardware['getUuid']();if(_0x2fbfb7){return db['License'][_0xc95c('0x21')]({'where':{'id':0x1},'defaults':{'data1':_0x2fbfb7}})['spread'](function(_0x1cdcb6,_0x17e461){logger[_0xc95c('0x12')](_0xc95c('0x22'),_0x2fbfb7);manageLicense(_0x2fbfb7,_0x1cdcb6);})[_0xc95c('0xb')](function(_0x1d6d89){logger[_0xc95c('0x1e')](_0x1d6d89[_0xc95c('0x23')]);});}}exports['default']=defaultLicense;