4822a43a96a8a832776827c4895803b348110c6f
[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 _0x3f97=['https://www.xcallymotion.com','format','%s/api/servers/%s/check?version=%s','exports','%s/api/servers/%s/check?version=%s&oldtoken=%s','GET','then','catch','data1','active','THE\x20LICENSE\x20HAS\x20BEEN\x20ENABLED','data2','info','THE\x20LICENSE\x20HAS\x20BEEN\x20UPDATED','Disabled','THE\x20LICENSE\x20HAS\x20BEEN\x20DISABLED','Changed','%s\x20-\x20GRAY\x20PERIOD\x20STARTED\x20AT\x20%s','toUpperCase','YYYY-MM-DD\x20HH:mm','update','diff','days','DEMO\x20START\x20AT\x20%s','NEW\x20UUID\x20DETECTED:\x20FROM\x20%s\x20TO\x20%s','finally','getUuid','License','spread','SERVICE\x20LICENSE\x20STARTED\x20%s','message','default','util','request-promise','version','../../mysqldb','../../components/encryptor','./hardware','license'];(function(_0x5416db,_0x55683a){var _0x243e35=function(_0x1eb623){while(--_0x1eb623){_0x5416db['push'](_0x5416db['shift']());}};_0x243e35(++_0x55683a);}(_0x3f97,0x1f4));var _0x73f9=function(_0x1140dd,_0x4c5fba){_0x1140dd=_0x1140dd-0x0;var _0x1d46a7=_0x3f97[_0x1140dd];return _0x1d46a7;};'use strict';var util=require(_0x73f9('0x0'));var moment=require('moment');var rp=require(_0x73f9('0x1'));var BPromise=require('bluebird');var pkginfo=require('pkginfo')(module,_0x73f9('0x2'));var db=require(_0x73f9('0x3'))['db'];var encryptor=require(_0x73f9('0x4'));var hardware=require(_0x73f9('0x5'));var logger=require('../logger')(_0x73f9('0x6'));var HOST=_0x73f9('0x7');var TIME=0x3c*0x1388;var DAYS=0x7;var GRAY_PERIOD_REASON;var oldToken;var isOldTokenSent=![];function httpRequest(_0x565384){return new BPromise(function(_0x2071fe,_0x43e2d0){var _0x293746=util[_0x73f9('0x8')](_0x73f9('0x9'),HOST,_0x565384,module[_0x73f9('0xa')]['version']);if(oldToken){_0x293746=util[_0x73f9('0x8')](_0x73f9('0xb'),HOST,_0x565384,module[_0x73f9('0xa')]['version'],oldToken);}var _0x5be7d3={'uri':_0x293746,'method':_0x73f9('0xc'),'timeout':0xea60,'json':!![]};return rp(_0x5be7d3)[_0x73f9('0xd')](function(_0x2d368c){_0x2071fe(_0x2d368c);})[_0x73f9('0xe')](function(_0x3fd7f5){_0x43e2d0(_0x3fd7f5);});});}function manageLicense(_0x51b1b2,_0x2d7b6e){var _0x53f52e=_0x2d7b6e['get']({'plain':!![]});if(!isOldTokenSent&&_0x53f52e[_0x73f9('0xf')]!==_0x51b1b2&&!_0x53f52e['data2']){oldToken=_0x53f52e[_0x73f9('0xf')];}httpRequest(_0x51b1b2)['then'](function(_0xdc80d1){if(oldToken){oldToken=undefined;isOldTokenSent=!![];}if(_0xdc80d1[_0x73f9('0x10')]){isOldTokenSent=![];if(!_0x53f52e['license']&&_0x53f52e[_0x73f9('0x6')]!=_0xdc80d1[_0x73f9('0x6')]||_0x53f52e['license']&&_0x53f52e['data2']){logger['info'](_0x73f9('0x11'));}if(_0x53f52e[_0x73f9('0x6')]&&!_0x53f52e[_0x73f9('0x12')]&&_0x53f52e[_0x73f9('0x6')]!=_0xdc80d1['license']){logger[_0x73f9('0x13')](_0x73f9('0x14'));}if(_0x53f52e[_0x73f9('0x6')]&&!_0x53f52e['data2']&&_0x53f52e['license']==_0xdc80d1['license']){return _0x2d7b6e;}return _0x2d7b6e['update']({'data1':_0x51b1b2,'data2':null,'license':_0xdc80d1['license']});}else{if(_0xdc80d1[_0x73f9('0x6')]||_0x53f52e[_0x73f9('0x6')]){if(!_0x53f52e['data2']){if(_0x53f52e[_0x73f9('0xf')]==_0x51b1b2){GRAY_PERIOD_REASON=_0x73f9('0x15');logger['info'](_0x73f9('0x16'));}else{GRAY_PERIOD_REASON=_0x73f9('0x17');logger[_0x73f9('0x13')]('NEW\x20UUID\x20DETECTED:\x20FROM\x20%s\x20TO\x20%s',_0x53f52e[_0x73f9('0xf')],_0x51b1b2);}logger[_0x73f9('0x13')](_0x73f9('0x18'),GRAY_PERIOD_REASON[_0x73f9('0x19')](),moment()[_0x73f9('0x8')](_0x73f9('0x1a')));return _0x2d7b6e[_0x73f9('0x1b')]({'data2':encryptor['encryptString'](moment()[_0x73f9('0x8')](_0x73f9('0x1a')))});}else{if(moment()[_0x73f9('0x1c')](encryptor['decryptString'](_0x53f52e[_0x73f9('0x12')]),_0x73f9('0x1d'))>DAYS){logger[_0x73f9('0x13')](_0x73f9('0x1e'),moment()[_0x73f9('0x8')]('YYYY-MM-DD\x20HH:mm'));isOldTokenSent=![];return _0x2d7b6e[_0x73f9('0x1b')]({'data1':_0x51b1b2,'data2':null,'license':null});}}}else{if(_0x53f52e[_0x73f9('0xf')]!=_0x51b1b2){logger[_0x73f9('0x13')](_0x73f9('0x1f'),_0x53f52e['data1'],_0x51b1b2);return _0x2d7b6e[_0x73f9('0x1b')]({'data1':_0x51b1b2,'data2':null,'license':null});}}}return _0x2d7b6e;})[_0x73f9('0xd')](function(_0x4bc04b){_0x2d7b6e=_0x4bc04b;})['catch'](function(_0x374942){logger['error'](_0x374942['message']);})[_0x73f9('0x20')](function(){setTimeout(function(){manageLicense(hardware[_0x73f9('0x21')](),_0x2d7b6e);},TIME);});}function defaultLicense(){var _0x29c6c1=hardware[_0x73f9('0x21')]();if(_0x29c6c1){return db[_0x73f9('0x22')]['findOrCreate']({'where':{'id':0x1},'defaults':{'data1':_0x29c6c1}})[_0x73f9('0x23')](function(_0x4ac057,_0xac30fe){logger['info'](_0x73f9('0x24'),_0x29c6c1);manageLicense(_0x29c6c1,_0x4ac057);})[_0x73f9('0xe')](function(_0x9f3b90){logger['error'](_0x9f3b90[_0x73f9('0x25')]);});}}exports[_0x73f9('0x26')]=defaultLicense;