Built motion from commit f25620e4.|2.6.30
[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 _0x3ec0=['message','finally','findOrCreate','spread','SERVICE\x20LICENSE\x20STARTED\x20%s','error','default','util','moment','request-promise','bluebird','version','../../components/encryptor','https://www.xcallymotion.com','format','exports','%s/api/servers/%s/check?version=%s&oldtoken=%s','then','catch','data1','data2','license','THE\x20LICENSE\x20HAS\x20BEEN\x20ENABLED','THE\x20LICENSE\x20HAS\x20BEEN\x20UPDATED','update','Disabled','info','THE\x20LICENSE\x20HAS\x20BEEN\x20DISABLED','Changed','toUpperCase','YYYY-MM-DD\x20HH:mm','encryptString','days','DEMO\x20START\x20AT\x20%s','NEW\x20UUID\x20DETECTED:\x20FROM\x20%s\x20TO\x20%s'];(function(_0x164eca,_0x555e28){var _0x2ce562=function(_0x148ca6){while(--_0x148ca6){_0x164eca['push'](_0x164eca['shift']());}};_0x2ce562(++_0x555e28);}(_0x3ec0,0x165));var _0x03ec=function(_0x44b18a,_0x2c02b2){_0x44b18a=_0x44b18a-0x0;var _0x2088a4=_0x3ec0[_0x44b18a];return _0x2088a4;};'use strict';var util=require(_0x03ec('0x0'));var moment=require(_0x03ec('0x1'));var rp=require(_0x03ec('0x2'));var BPromise=require(_0x03ec('0x3'));var pkginfo=require('pkginfo')(module,_0x03ec('0x4'));var db=require('../../mysqldb')['db'];var encryptor=require(_0x03ec('0x5'));var hardware=require('./hardware');var logger=require('../logger')('license');var HOST=_0x03ec('0x6');var TIME=0x3c*0x1388;var DAYS=0x7;var GRAY_PERIOD_REASON;var oldToken;var isOldTokenSent=![];function httpRequest(_0x2de593){return new BPromise(function(_0x27dd7a,_0x5e82ce){var _0x31eeeb=util[_0x03ec('0x7')]('%s/api/servers/%s/check?version=%s',HOST,_0x2de593,module[_0x03ec('0x8')][_0x03ec('0x4')]);if(oldToken){_0x31eeeb=util['format'](_0x03ec('0x9'),HOST,_0x2de593,module[_0x03ec('0x8')][_0x03ec('0x4')],oldToken);}var _0x35c7af={'uri':_0x31eeeb,'method':'GET','timeout':0xea60,'json':!![]};return rp(_0x35c7af)[_0x03ec('0xa')](function(_0x134faf){_0x27dd7a(_0x134faf);})[_0x03ec('0xb')](function(_0xedfb8){_0x5e82ce(_0xedfb8);});});}function manageLicense(_0x3111d0,_0x1fbe86){var _0x55e31e=_0x1fbe86['get']({'plain':!![]});if(!isOldTokenSent&&_0x55e31e[_0x03ec('0xc')]!==_0x3111d0&&!_0x55e31e[_0x03ec('0xd')]){oldToken=_0x55e31e[_0x03ec('0xc')];}httpRequest(_0x3111d0)['then'](function(_0x459f27){if(oldToken){oldToken=undefined;isOldTokenSent=!![];}if(_0x459f27['active']){isOldTokenSent=![];if(!_0x55e31e[_0x03ec('0xe')]&&_0x55e31e['license']!=_0x459f27['license']||_0x55e31e[_0x03ec('0xe')]&&_0x55e31e['data2']){logger['info'](_0x03ec('0xf'));}if(_0x55e31e['license']&&!_0x55e31e['data2']&&_0x55e31e[_0x03ec('0xe')]!=_0x459f27[_0x03ec('0xe')]){logger['info'](_0x03ec('0x10'));}if(_0x55e31e[_0x03ec('0xe')]&&!_0x55e31e['data2']&&_0x55e31e[_0x03ec('0xe')]==_0x459f27[_0x03ec('0xe')]){return _0x1fbe86;}return _0x1fbe86[_0x03ec('0x11')]({'data1':_0x3111d0,'data2':null,'license':_0x459f27[_0x03ec('0xe')]});}else{if(_0x459f27['license']||_0x55e31e[_0x03ec('0xe')]){if(!_0x55e31e[_0x03ec('0xd')]){if(_0x55e31e[_0x03ec('0xc')]==_0x3111d0){GRAY_PERIOD_REASON=_0x03ec('0x12');logger[_0x03ec('0x13')](_0x03ec('0x14'));}else{GRAY_PERIOD_REASON=_0x03ec('0x15');logger[_0x03ec('0x13')]('NEW\x20UUID\x20DETECTED:\x20FROM\x20%s\x20TO\x20%s',_0x55e31e[_0x03ec('0xc')],_0x3111d0);}logger['info']('%s\x20-\x20GRAY\x20PERIOD\x20STARTED\x20AT\x20%s',GRAY_PERIOD_REASON[_0x03ec('0x16')](),moment()['format'](_0x03ec('0x17')));return _0x1fbe86[_0x03ec('0x11')]({'data2':encryptor[_0x03ec('0x18')](moment()['format'](_0x03ec('0x17')))});}else{if(moment()['diff'](encryptor['decryptString'](_0x55e31e[_0x03ec('0xd')]),_0x03ec('0x19'))>DAYS){logger[_0x03ec('0x13')](_0x03ec('0x1a'),moment()[_0x03ec('0x7')](_0x03ec('0x17')));isOldTokenSent=![];return _0x1fbe86['update']({'data1':_0x3111d0,'data2':null,'license':null});}}}else{if(_0x55e31e[_0x03ec('0xc')]!=_0x3111d0){logger[_0x03ec('0x13')](_0x03ec('0x1b'),_0x55e31e[_0x03ec('0xc')],_0x3111d0);return _0x1fbe86[_0x03ec('0x11')]({'data1':_0x3111d0,'data2':null,'license':null});}}}return _0x1fbe86;})[_0x03ec('0xa')](function(_0x52aa7d){_0x1fbe86=_0x52aa7d;})[_0x03ec('0xb')](function(_0x105c40){logger['error'](_0x105c40[_0x03ec('0x1c')]);})[_0x03ec('0x1d')](function(){setTimeout(function(){manageLicense(hardware['getUuid'](),_0x1fbe86);},TIME);});}function defaultLicense(){var _0x594145=hardware['getUuid']();if(_0x594145){return db['License'][_0x03ec('0x1e')]({'where':{'id':0x1},'defaults':{'data1':_0x594145}})[_0x03ec('0x1f')](function(_0x69c8e9,_0x4a4980){logger['info'](_0x03ec('0x20'),_0x594145);manageLicense(_0x594145,_0x69c8e9);})[_0x03ec('0xb')](function(_0x423943){logger[_0x03ec('0x21')](_0x423943[_0x03ec('0x1c')]);});}}exports[_0x03ec('0x22')]=defaultLicense;