56114f713de681b81c84fc0bc535f02ff59984f7
[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 _0xf492=['../../components/encryptor','../logger','format','%s/api/servers/%s/check?version=%s','%s/api/servers/%s/check?version=%s&oldtoken=%s','exports','GET','then','catch','get','data1','data2','active','license','THE\x20LICENSE\x20HAS\x20BEEN\x20ENABLED','info','THE\x20LICENSE\x20HAS\x20BEEN\x20UPDATED','update','Disabled','THE\x20LICENSE\x20HAS\x20BEEN\x20DISABLED','Changed','NEW\x20UUID\x20DETECTED:\x20FROM\x20%s\x20TO\x20%s','toUpperCase','YYYY-MM-DD\x20HH:mm','encryptString','days','DEMO\x20START\x20AT\x20%s','error','message','getUuid','License','SERVICE\x20LICENSE\x20STARTED\x20%s','default','util','moment','request-promise','bluebird','version'];(function(_0x164af1,_0x3cf772){var _0x5d81a2=function(_0xa57547){while(--_0xa57547){_0x164af1['push'](_0x164af1['shift']());}};_0x5d81a2(++_0x3cf772);}(_0xf492,0x105));var _0x2f49=function(_0x1021d9,_0x55d7fc){_0x1021d9=_0x1021d9-0x0;var _0xdfd252=_0xf492[_0x1021d9];return _0xdfd252;};'use strict';var util=require(_0x2f49('0x0'));var moment=require(_0x2f49('0x1'));var rp=require(_0x2f49('0x2'));var BPromise=require(_0x2f49('0x3'));var pkginfo=require('pkginfo')(module,_0x2f49('0x4'));var db=require('../../mysqldb')['db'];var encryptor=require(_0x2f49('0x5'));var hardware=require('./hardware');var logger=require(_0x2f49('0x6'))('license');var HOST='https://www.xcallymotion.com';var TIME=0x3c*0x1388;var DAYS=0x7;var GRAY_PERIOD_REASON;var oldToken;var isOldTokenSent=![];function httpRequest(_0x78b8c8){return new BPromise(function(_0xd51099,_0x11c172){var _0x315cf0=util[_0x2f49('0x7')](_0x2f49('0x8'),HOST,_0x78b8c8,module['exports'][_0x2f49('0x4')]);if(oldToken){_0x315cf0=util['format'](_0x2f49('0x9'),HOST,_0x78b8c8,module[_0x2f49('0xa')][_0x2f49('0x4')],oldToken);}var _0x4ee219={'uri':_0x315cf0,'method':_0x2f49('0xb'),'timeout':0xea60,'json':!![]};return rp(_0x4ee219)[_0x2f49('0xc')](function(_0x5aeaa9){_0xd51099(_0x5aeaa9);})[_0x2f49('0xd')](function(_0x595980){_0x11c172(_0x595980);});});}function manageLicense(_0x430461,_0x3bac3e){var _0xb73cc9=_0x3bac3e[_0x2f49('0xe')]({'plain':!![]});if(!isOldTokenSent&&_0xb73cc9[_0x2f49('0xf')]!==_0x430461&&!_0xb73cc9[_0x2f49('0x10')]){oldToken=_0xb73cc9[_0x2f49('0xf')];}httpRequest(_0x430461)[_0x2f49('0xc')](function(_0x5b2f67){if(oldToken){oldToken=undefined;isOldTokenSent=!![];}if(_0x5b2f67[_0x2f49('0x11')]){isOldTokenSent=![];if(!_0xb73cc9[_0x2f49('0x12')]&&_0xb73cc9[_0x2f49('0x12')]!=_0x5b2f67[_0x2f49('0x12')]||_0xb73cc9[_0x2f49('0x12')]&&_0xb73cc9[_0x2f49('0x10')]){logger['info'](_0x2f49('0x13'));}if(_0xb73cc9[_0x2f49('0x12')]&&!_0xb73cc9[_0x2f49('0x10')]&&_0xb73cc9[_0x2f49('0x12')]!=_0x5b2f67[_0x2f49('0x12')]){logger[_0x2f49('0x14')](_0x2f49('0x15'));}if(_0xb73cc9[_0x2f49('0x12')]&&!_0xb73cc9['data2']&&_0xb73cc9[_0x2f49('0x12')]==_0x5b2f67[_0x2f49('0x12')]){return _0x3bac3e;}return _0x3bac3e[_0x2f49('0x16')]({'data1':_0x430461,'data2':null,'license':_0x5b2f67[_0x2f49('0x12')]});}else{if(_0x5b2f67[_0x2f49('0x12')]||_0xb73cc9[_0x2f49('0x12')]){if(!_0xb73cc9['data2']){if(_0xb73cc9[_0x2f49('0xf')]==_0x430461){GRAY_PERIOD_REASON=_0x2f49('0x17');logger[_0x2f49('0x14')](_0x2f49('0x18'));}else{GRAY_PERIOD_REASON=_0x2f49('0x19');logger[_0x2f49('0x14')](_0x2f49('0x1a'),_0xb73cc9[_0x2f49('0xf')],_0x430461);}logger[_0x2f49('0x14')]('%s\x20-\x20GRAY\x20PERIOD\x20STARTED\x20AT\x20%s',GRAY_PERIOD_REASON[_0x2f49('0x1b')](),moment()[_0x2f49('0x7')](_0x2f49('0x1c')));return _0x3bac3e['update']({'data2':encryptor[_0x2f49('0x1d')](moment()[_0x2f49('0x7')](_0x2f49('0x1c')))});}else{if(moment()['diff'](encryptor['decryptString'](_0xb73cc9[_0x2f49('0x10')]),_0x2f49('0x1e'))>DAYS){logger[_0x2f49('0x14')](_0x2f49('0x1f'),moment()[_0x2f49('0x7')](_0x2f49('0x1c')));isOldTokenSent=![];return _0x3bac3e[_0x2f49('0x16')]({'data1':_0x430461,'data2':null,'license':null});}}}else{if(_0xb73cc9[_0x2f49('0xf')]!=_0x430461){logger[_0x2f49('0x14')]('NEW\x20UUID\x20DETECTED:\x20FROM\x20%s\x20TO\x20%s',_0xb73cc9['data1'],_0x430461);return _0x3bac3e[_0x2f49('0x16')]({'data1':_0x430461,'data2':null,'license':null});}}}return _0x3bac3e;})[_0x2f49('0xc')](function(_0x2e1d60){_0x3bac3e=_0x2e1d60;})[_0x2f49('0xd')](function(_0x19bc4d){logger[_0x2f49('0x20')](_0x19bc4d[_0x2f49('0x21')]);})['finally'](function(){setTimeout(function(){manageLicense(hardware[_0x2f49('0x22')](),_0x3bac3e);},TIME);});}function defaultLicense(){var _0x3c031e=hardware[_0x2f49('0x22')]();if(_0x3c031e){return db[_0x2f49('0x23')]['findOrCreate']({'where':{'id':0x1},'defaults':{'data1':_0x3c031e}})['spread'](function(_0x47f407,_0x4bc4f2){logger[_0x2f49('0x14')](_0x2f49('0x24'),_0x3c031e);manageLicense(_0x3c031e,_0x47f407);})['catch'](function(_0x3d71e4){logger['error'](_0x3d71e4[_0x2f49('0x21')]);});}}exports[_0x2f49('0x25')]=defaultLicense;