Built motion from commit (unavailable).|2.5.29
[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 _0xf5c6=['get','data2','data1','active','info','update','Changed','NEW\x20UUID\x20DETECTED:\x20FROM\x20%s\x20TO\x20%s','encryptString','YYYY-MM-DD\x20HH:mm','diff','decryptString','days','DEMO\x20START\x20AT\x20%s','error','message','finally','getUuid','findOrCreate','spread','default','util','request-promise','bluebird','pkginfo','version','../../components/encryptor','./hardware','../logger','license','exports','format','GET','then','catch'];(function(_0x388d80,_0x3594c1){var _0x1627bd=function(_0x48086e){while(--_0x48086e){_0x388d80['push'](_0x388d80['shift']());}};_0x1627bd(++_0x3594c1);}(_0xf5c6,0xc4));var _0x6f5c=function(_0x550a9c,_0x1bf725){_0x550a9c=_0x550a9c-0x0;var _0x796881=_0xf5c6[_0x550a9c];return _0x796881;};'use strict';var util=require(_0x6f5c('0x0'));var moment=require('moment');var rp=require(_0x6f5c('0x1'));var BPromise=require(_0x6f5c('0x2'));var pkginfo=require(_0x6f5c('0x3'))(module,_0x6f5c('0x4'));var db=require('../../mysqldb')['db'];var encryptor=require(_0x6f5c('0x5'));var hardware=require(_0x6f5c('0x6'));var logger=require(_0x6f5c('0x7'))(_0x6f5c('0x8'));var HOST='https://www.xcallymotion.com';var TIME=0x3c*0x1388;var DAYS=0x7;var GRAY_PERIOD_REASON;var oldToken;var isOldTokenSent=![];function httpRequest(_0x18926d){return new BPromise(function(_0x34c0b4,_0x39beea){var _0x255b1e=util['format']('%s/api/servers/%s/check?version=%s',HOST,_0x18926d,module[_0x6f5c('0x9')][_0x6f5c('0x4')]);if(oldToken){_0x255b1e=util[_0x6f5c('0xa')]('%s/api/servers/%s/check?version=%s&oldtoken=%s',HOST,_0x18926d,module[_0x6f5c('0x9')][_0x6f5c('0x4')],oldToken);}var _0xe8a554={'uri':_0x255b1e,'method':_0x6f5c('0xb'),'timeout':0xea60,'json':!![]};return rp(_0xe8a554)[_0x6f5c('0xc')](function(_0x550fb7){_0x34c0b4(_0x550fb7);})[_0x6f5c('0xd')](function(_0x230859){_0x39beea(_0x230859);});});}function manageLicense(_0x8ea6d2,_0x2e2898){var _0x25ee43=_0x2e2898[_0x6f5c('0xe')]({'plain':!![]});if(!isOldTokenSent&&_0x25ee43['data1']!==_0x8ea6d2&&!_0x25ee43[_0x6f5c('0xf')]){oldToken=_0x25ee43[_0x6f5c('0x10')];}httpRequest(_0x8ea6d2)[_0x6f5c('0xc')](function(_0x3266d9){if(oldToken){oldToken=undefined;isOldTokenSent=!![];}if(_0x3266d9[_0x6f5c('0x11')]){isOldTokenSent=![];if(!_0x25ee43[_0x6f5c('0x8')]&&_0x25ee43[_0x6f5c('0x8')]!=_0x3266d9[_0x6f5c('0x8')]||_0x25ee43[_0x6f5c('0x8')]&&_0x25ee43[_0x6f5c('0xf')]){logger[_0x6f5c('0x12')]('THE\x20LICENSE\x20HAS\x20BEEN\x20ENABLED');}if(_0x25ee43[_0x6f5c('0x8')]&&!_0x25ee43[_0x6f5c('0xf')]&&_0x25ee43[_0x6f5c('0x8')]!=_0x3266d9[_0x6f5c('0x8')]){logger['info']('THE\x20LICENSE\x20HAS\x20BEEN\x20UPDATED');}if(_0x25ee43[_0x6f5c('0x8')]&&!_0x25ee43[_0x6f5c('0xf')]&&_0x25ee43['license']==_0x3266d9[_0x6f5c('0x8')]){return _0x2e2898;}return _0x2e2898[_0x6f5c('0x13')]({'data1':_0x8ea6d2,'data2':null,'license':_0x3266d9[_0x6f5c('0x8')]});}else{if(_0x3266d9[_0x6f5c('0x8')]||_0x25ee43[_0x6f5c('0x8')]){if(!_0x25ee43[_0x6f5c('0xf')]){if(_0x25ee43['data1']==_0x8ea6d2){GRAY_PERIOD_REASON='Disabled';logger[_0x6f5c('0x12')]('THE\x20LICENSE\x20HAS\x20BEEN\x20DISABLED');}else{GRAY_PERIOD_REASON=_0x6f5c('0x14');logger[_0x6f5c('0x12')](_0x6f5c('0x15'),_0x25ee43['data1'],_0x8ea6d2);}logger[_0x6f5c('0x12')]('%s\x20-\x20GRAY\x20PERIOD\x20STARTED\x20AT\x20%s',GRAY_PERIOD_REASON['toUpperCase'](),moment()[_0x6f5c('0xa')]('YYYY-MM-DD\x20HH:mm'));return _0x2e2898[_0x6f5c('0x13')]({'data2':encryptor[_0x6f5c('0x16')](moment()[_0x6f5c('0xa')](_0x6f5c('0x17')))});}else{if(moment()[_0x6f5c('0x18')](encryptor[_0x6f5c('0x19')](_0x25ee43['data2']),_0x6f5c('0x1a'))>DAYS){logger['info'](_0x6f5c('0x1b'),moment()[_0x6f5c('0xa')](_0x6f5c('0x17')));isOldTokenSent=![];return _0x2e2898[_0x6f5c('0x13')]({'data1':_0x8ea6d2,'data2':null,'license':null});}}}else{if(_0x25ee43[_0x6f5c('0x10')]!=_0x8ea6d2){logger['info']('NEW\x20UUID\x20DETECTED:\x20FROM\x20%s\x20TO\x20%s',_0x25ee43[_0x6f5c('0x10')],_0x8ea6d2);return _0x2e2898['update']({'data1':_0x8ea6d2,'data2':null,'license':null});}}}return _0x2e2898;})[_0x6f5c('0xc')](function(_0x2b9895){_0x2e2898=_0x2b9895;})['catch'](function(_0x4b42a4){logger[_0x6f5c('0x1c')](_0x4b42a4[_0x6f5c('0x1d')]);})[_0x6f5c('0x1e')](function(){setTimeout(function(){manageLicense(hardware[_0x6f5c('0x1f')](),_0x2e2898);},TIME);});}function defaultLicense(){var _0x292b46=hardware['getUuid']();if(_0x292b46){return db['License'][_0x6f5c('0x20')]({'where':{'id':0x1},'defaults':{'data1':_0x292b46}})[_0x6f5c('0x21')](function(_0x3c6876,_0xa181e8){logger[_0x6f5c('0x12')]('SERVICE\x20LICENSE\x20STARTED\x20%s',_0x292b46);manageLicense(_0x292b46,_0x3c6876);})[_0x6f5c('0xd')](function(_0x169010){logger[_0x6f5c('0x1c')](_0x169010[_0x6f5c('0x1d')]);});}}exports[_0x6f5c('0x22')]=defaultLicense;