7b48424dd3aef0e6df4eaf4f67af2698db7f91c0
[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 _0xc830=['SERVICE\x20LICENSE\x20STARTED\x20%s','default','util','moment','request-promise','bluebird','pkginfo','../../mysqldb','../../components/encryptor','./hardware','../logger','license','https://www.xcallymotion.com','%s/api/servers/%s/check?version=%s','version','format','exports','GET','then','get','data1','data2','active','THE\x20LICENSE\x20HAS\x20BEEN\x20ENABLED','info','THE\x20LICENSE\x20HAS\x20BEEN\x20UPDATED','update','Disabled','THE\x20LICENSE\x20HAS\x20BEEN\x20DISABLED','NEW\x20UUID\x20DETECTED:\x20FROM\x20%s\x20TO\x20%s','YYYY-MM-DD\x20HH:mm','encryptString','diff','decryptString','days','catch','error','message','finally','getUuid','License','findOrCreate','spread'];(function(_0x2d8d95,_0x3d36a4){var _0x379afa=function(_0xe7f8f9){while(--_0xe7f8f9){_0x2d8d95['push'](_0x2d8d95['shift']());}};_0x379afa(++_0x3d36a4);}(_0xc830,0x185));var _0x0c83=function(_0x534b67,_0x5872f5){_0x534b67=_0x534b67-0x0;var _0xcbaa75=_0xc830[_0x534b67];return _0xcbaa75;};'use strict';var util=require(_0x0c83('0x0'));var moment=require(_0x0c83('0x1'));var rp=require(_0x0c83('0x2'));var BPromise=require(_0x0c83('0x3'));var pkginfo=require(_0x0c83('0x4'))(module,'version');var db=require(_0x0c83('0x5'))['db'];var encryptor=require(_0x0c83('0x6'));var hardware=require(_0x0c83('0x7'));var logger=require(_0x0c83('0x8'))(_0x0c83('0x9'));var HOST=_0x0c83('0xa');var TIME=0x3c*0x1388;var DAYS=0x7;var GRAY_PERIOD_REASON;var oldToken;var isOldTokenSent=![];function httpRequest(_0x259502){return new BPromise(function(_0x1752e7,_0x5d7a63){var _0x35e0c8=util['format'](_0x0c83('0xb'),HOST,_0x259502,module['exports'][_0x0c83('0xc')]);if(oldToken){_0x35e0c8=util[_0x0c83('0xd')]('%s/api/servers/%s/check?version=%s&oldtoken=%s',HOST,_0x259502,module[_0x0c83('0xe')][_0x0c83('0xc')],oldToken);}var _0x42201b={'uri':_0x35e0c8,'method':_0x0c83('0xf'),'timeout':0xea60,'json':!![]};return rp(_0x42201b)[_0x0c83('0x10')](function(_0x48f706){_0x1752e7(_0x48f706);})['catch'](function(_0x3cce18){_0x5d7a63(_0x3cce18);});});}function manageLicense(_0x36ed7a,_0x2361aa){var _0x382e1d=_0x2361aa[_0x0c83('0x11')]({'plain':!![]});if(!isOldTokenSent&&_0x382e1d[_0x0c83('0x12')]!==_0x36ed7a&&!_0x382e1d[_0x0c83('0x13')]){oldToken=_0x382e1d[_0x0c83('0x12')];}httpRequest(_0x36ed7a)[_0x0c83('0x10')](function(_0x3f6313){if(oldToken){oldToken=undefined;isOldTokenSent=!![];}if(_0x3f6313[_0x0c83('0x14')]){isOldTokenSent=![];if(!_0x382e1d[_0x0c83('0x9')]&&_0x382e1d[_0x0c83('0x9')]!=_0x3f6313[_0x0c83('0x9')]||_0x382e1d[_0x0c83('0x9')]&&_0x382e1d['data2']){logger['info'](_0x0c83('0x15'));}if(_0x382e1d[_0x0c83('0x9')]&&!_0x382e1d[_0x0c83('0x13')]&&_0x382e1d[_0x0c83('0x9')]!=_0x3f6313[_0x0c83('0x9')]){logger[_0x0c83('0x16')](_0x0c83('0x17'));}if(_0x382e1d[_0x0c83('0x9')]&&!_0x382e1d[_0x0c83('0x13')]&&_0x382e1d['license']==_0x3f6313[_0x0c83('0x9')]){return _0x2361aa;}return _0x2361aa[_0x0c83('0x18')]({'data1':_0x36ed7a,'data2':null,'license':_0x3f6313[_0x0c83('0x9')]});}else{if(_0x3f6313[_0x0c83('0x9')]||_0x382e1d[_0x0c83('0x9')]){if(!_0x382e1d[_0x0c83('0x13')]){if(_0x382e1d[_0x0c83('0x12')]==_0x36ed7a){GRAY_PERIOD_REASON=_0x0c83('0x19');logger[_0x0c83('0x16')](_0x0c83('0x1a'));}else{GRAY_PERIOD_REASON='Changed';logger[_0x0c83('0x16')](_0x0c83('0x1b'),_0x382e1d[_0x0c83('0x12')],_0x36ed7a);}logger[_0x0c83('0x16')]('%s\x20-\x20GRAY\x20PERIOD\x20STARTED\x20AT\x20%s',GRAY_PERIOD_REASON['toUpperCase'](),moment()['format'](_0x0c83('0x1c')));return _0x2361aa[_0x0c83('0x18')]({'data2':encryptor[_0x0c83('0x1d')](moment()['format']('YYYY-MM-DD\x20HH:mm'))});}else{if(moment()[_0x0c83('0x1e')](encryptor[_0x0c83('0x1f')](_0x382e1d['data2']),_0x0c83('0x20'))>DAYS){logger['info']('DEMO\x20START\x20AT\x20%s',moment()['format'](_0x0c83('0x1c')));isOldTokenSent=![];return _0x2361aa[_0x0c83('0x18')]({'data1':_0x36ed7a,'data2':null,'license':null});}}}else{if(_0x382e1d['data1']!=_0x36ed7a){logger[_0x0c83('0x16')]('NEW\x20UUID\x20DETECTED:\x20FROM\x20%s\x20TO\x20%s',_0x382e1d['data1'],_0x36ed7a);return _0x2361aa[_0x0c83('0x18')]({'data1':_0x36ed7a,'data2':null,'license':null});}}}return _0x2361aa;})['then'](function(_0x48a7b1){_0x2361aa=_0x48a7b1;})[_0x0c83('0x21')](function(_0x11174e){logger[_0x0c83('0x22')](_0x11174e[_0x0c83('0x23')]);})[_0x0c83('0x24')](function(){setTimeout(function(){manageLicense(hardware[_0x0c83('0x25')](),_0x2361aa);},TIME);});}function defaultLicense(){var _0x44f48b=hardware[_0x0c83('0x25')]();if(_0x44f48b){return db[_0x0c83('0x26')][_0x0c83('0x27')]({'where':{'id':0x1},'defaults':{'data1':_0x44f48b}})[_0x0c83('0x28')](function(_0x1d678b,_0x1abdee){logger[_0x0c83('0x16')](_0x0c83('0x29'),_0x44f48b);manageLicense(_0x44f48b,_0x1d678b);})[_0x0c83('0x21')](function(_0x52c9f0){logger['error'](_0x52c9f0[_0x0c83('0x23')]);});}}exports[_0x0c83('0x2a')]=defaultLicense;