a4bef3bab2c03ccea52cfa5cd3b06ba14af7c575
[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 _0x2e32=['request-promise','bluebird','pkginfo','../../mysqldb','../../components/encryptor','./hardware','https://www.xcallymotion.com','format','%s/api/servers/%s/check?version=%s','version','%s/api/servers/%s/check?version=%s&oldtoken=%s','exports','GET','catch','get','data2','data1','then','active','license','info','THE\x20LICENSE\x20HAS\x20BEEN\x20ENABLED','THE\x20LICENSE\x20HAS\x20BEEN\x20UPDATED','update','Disabled','Changed','NEW\x20UUID\x20DETECTED:\x20FROM\x20%s\x20TO\x20%s','toUpperCase','encryptString','YYYY-MM-DD\x20HH:mm','diff','decryptString','days','DEMO\x20START\x20AT\x20%s','error','message','finally','getUuid','findOrCreate','spread','SERVICE\x20LICENSE\x20STARTED\x20%s','default'];(function(_0x341a5a,_0x4ae5ed){var _0x53f85b=function(_0x24899d){while(--_0x24899d){_0x341a5a['push'](_0x341a5a['shift']());}};_0x53f85b(++_0x4ae5ed);}(_0x2e32,0xd2));var _0x22e3=function(_0x1b6186,_0x1ec7f2){_0x1b6186=_0x1b6186-0x0;var _0x186121=_0x2e32[_0x1b6186];return _0x186121;};'use strict';var util=require('util');var moment=require('moment');var rp=require(_0x22e3('0x0'));var BPromise=require(_0x22e3('0x1'));var pkginfo=require(_0x22e3('0x2'))(module,'version');var db=require(_0x22e3('0x3'))['db'];var encryptor=require(_0x22e3('0x4'));var hardware=require(_0x22e3('0x5'));var logger=require('../logger')('license');var HOST=_0x22e3('0x6');var TIME=0x3c*0x1388;var DAYS=0x7;var GRAY_PERIOD_REASON;var oldToken;var isOldTokenSent=![];function httpRequest(_0x136b36){return new BPromise(function(_0x494b01,_0x124ed9){var _0x2da13c=util[_0x22e3('0x7')](_0x22e3('0x8'),HOST,_0x136b36,module['exports'][_0x22e3('0x9')]);if(oldToken){_0x2da13c=util[_0x22e3('0x7')](_0x22e3('0xa'),HOST,_0x136b36,module[_0x22e3('0xb')][_0x22e3('0x9')],oldToken);}var _0xaf1d4a={'uri':_0x2da13c,'method':_0x22e3('0xc'),'timeout':0xea60,'json':!![]};return rp(_0xaf1d4a)['then'](function(_0x13a16a){_0x494b01(_0x13a16a);})[_0x22e3('0xd')](function(_0x5d4489){_0x124ed9(_0x5d4489);});});}function manageLicense(_0x2eb5bc,_0x42113d){var _0x8e6300=_0x42113d[_0x22e3('0xe')]({'plain':!![]});if(!isOldTokenSent&&_0x8e6300['data1']!==_0x2eb5bc&&!_0x8e6300[_0x22e3('0xf')]){oldToken=_0x8e6300[_0x22e3('0x10')];}httpRequest(_0x2eb5bc)[_0x22e3('0x11')](function(_0x25c86d){if(oldToken){oldToken=undefined;isOldTokenSent=!![];}if(_0x25c86d[_0x22e3('0x12')]){isOldTokenSent=![];if(!_0x8e6300[_0x22e3('0x13')]&&_0x8e6300['license']!=_0x25c86d['license']||_0x8e6300[_0x22e3('0x13')]&&_0x8e6300[_0x22e3('0xf')]){logger[_0x22e3('0x14')](_0x22e3('0x15'));}if(_0x8e6300[_0x22e3('0x13')]&&!_0x8e6300[_0x22e3('0xf')]&&_0x8e6300[_0x22e3('0x13')]!=_0x25c86d[_0x22e3('0x13')]){logger[_0x22e3('0x14')](_0x22e3('0x16'));}if(_0x8e6300['license']&&!_0x8e6300[_0x22e3('0xf')]&&_0x8e6300['license']==_0x25c86d['license']){return _0x42113d;}return _0x42113d[_0x22e3('0x17')]({'data1':_0x2eb5bc,'data2':null,'license':_0x25c86d['license']});}else{if(_0x25c86d[_0x22e3('0x13')]||_0x8e6300['license']){if(!_0x8e6300[_0x22e3('0xf')]){if(_0x8e6300[_0x22e3('0x10')]==_0x2eb5bc){GRAY_PERIOD_REASON=_0x22e3('0x18');logger['info']('THE\x20LICENSE\x20HAS\x20BEEN\x20DISABLED');}else{GRAY_PERIOD_REASON=_0x22e3('0x19');logger[_0x22e3('0x14')](_0x22e3('0x1a'),_0x8e6300[_0x22e3('0x10')],_0x2eb5bc);}logger[_0x22e3('0x14')]('%s\x20-\x20GRAY\x20PERIOD\x20STARTED\x20AT\x20%s',GRAY_PERIOD_REASON[_0x22e3('0x1b')](),moment()[_0x22e3('0x7')]('YYYY-MM-DD\x20HH:mm'));return _0x42113d[_0x22e3('0x17')]({'data2':encryptor[_0x22e3('0x1c')](moment()['format'](_0x22e3('0x1d')))});}else{if(moment()[_0x22e3('0x1e')](encryptor[_0x22e3('0x1f')](_0x8e6300['data2']),_0x22e3('0x20'))>DAYS){logger[_0x22e3('0x14')](_0x22e3('0x21'),moment()[_0x22e3('0x7')]('YYYY-MM-DD\x20HH:mm'));isOldTokenSent=![];return _0x42113d['update']({'data1':_0x2eb5bc,'data2':null,'license':null});}}}else{if(_0x8e6300[_0x22e3('0x10')]!=_0x2eb5bc){logger[_0x22e3('0x14')](_0x22e3('0x1a'),_0x8e6300[_0x22e3('0x10')],_0x2eb5bc);return _0x42113d[_0x22e3('0x17')]({'data1':_0x2eb5bc,'data2':null,'license':null});}}}return _0x42113d;})[_0x22e3('0x11')](function(_0x4d4081){_0x42113d=_0x4d4081;})[_0x22e3('0xd')](function(_0x3f62ce){logger[_0x22e3('0x22')](_0x3f62ce[_0x22e3('0x23')]);})[_0x22e3('0x24')](function(){setTimeout(function(){manageLicense(hardware['getUuid'](),_0x42113d);},TIME);});}function defaultLicense(){var _0x5c8a23=hardware[_0x22e3('0x25')]();if(_0x5c8a23){return db['License'][_0x22e3('0x26')]({'where':{'id':0x1},'defaults':{'data1':_0x5c8a23}})[_0x22e3('0x27')](function(_0x5c82ff,_0x58350f){logger[_0x22e3('0x14')](_0x22e3('0x28'),_0x5c8a23);manageLicense(_0x5c8a23,_0x5c82ff);})[_0x22e3('0xd')](function(_0x1f2620){logger[_0x22e3('0x22')](_0x1f2620[_0x22e3('0x23')]);});}}exports[_0x22e3('0x29')]=defaultLicense;