Built motion from commit 2b9af5da.|2.6.26
[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 _0xc18a=['THE\x20LICENSE\x20HAS\x20BEEN\x20ENABLED','THE\x20LICENSE\x20HAS\x20BEEN\x20UPDATED','update','Disabled','THE\x20LICENSE\x20HAS\x20BEEN\x20DISABLED','Changed','NEW\x20UUID\x20DETECTED:\x20FROM\x20%s\x20TO\x20%s','%s\x20-\x20GRAY\x20PERIOD\x20STARTED\x20AT\x20%s','toUpperCase','YYYY-MM-DD\x20HH:mm','encryptString','diff','decryptString','days','DEMO\x20START\x20AT\x20%s','error','message','getUuid','findOrCreate','spread','SERVICE\x20LICENSE\x20STARTED\x20%s','default','util','bluebird','pkginfo','version','../../mysqldb','../../components/encryptor','../logger','license','https://www.xcallymotion.com','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','info'];(function(_0x5266e7,_0x97b16b){var _0x5470f1=function(_0x10258e){while(--_0x10258e){_0x5266e7['push'](_0x5266e7['shift']());}};_0x5470f1(++_0x97b16b);}(_0xc18a,0x199));var _0xac18=function(_0x5201a9,_0x4250dc){_0x5201a9=_0x5201a9-0x0;var _0xaa7d8b=_0xc18a[_0x5201a9];return _0xaa7d8b;};'use strict';var util=require(_0xac18('0x0'));var moment=require('moment');var rp=require('request-promise');var BPromise=require(_0xac18('0x1'));var pkginfo=require(_0xac18('0x2'))(module,_0xac18('0x3'));var db=require(_0xac18('0x4'))['db'];var encryptor=require(_0xac18('0x5'));var hardware=require('./hardware');var logger=require(_0xac18('0x6'))(_0xac18('0x7'));var HOST=_0xac18('0x8');var TIME=0x3c*0x1388;var DAYS=0x7;var GRAY_PERIOD_REASON;var oldToken;var isOldTokenSent=![];function httpRequest(_0x4573e0){return new BPromise(function(_0x391edb,_0x5b6484){var _0x43256f=util[_0xac18('0x9')](_0xac18('0xa'),HOST,_0x4573e0,module['exports'][_0xac18('0x3')]);if(oldToken){_0x43256f=util[_0xac18('0x9')](_0xac18('0xb'),HOST,_0x4573e0,module[_0xac18('0xc')][_0xac18('0x3')],oldToken);}var _0x5188ba={'uri':_0x43256f,'method':_0xac18('0xd'),'timeout':0xea60,'json':!![]};return rp(_0x5188ba)[_0xac18('0xe')](function(_0xbc64f5){_0x391edb(_0xbc64f5);})[_0xac18('0xf')](function(_0x59bd4c){_0x5b6484(_0x59bd4c);});});}function manageLicense(_0x4042b2,_0x2fddc3){var _0x1766a0=_0x2fddc3[_0xac18('0x10')]({'plain':!![]});if(!isOldTokenSent&&_0x1766a0[_0xac18('0x11')]!==_0x4042b2&&!_0x1766a0[_0xac18('0x12')]){oldToken=_0x1766a0[_0xac18('0x11')];}httpRequest(_0x4042b2)[_0xac18('0xe')](function(_0x241b5e){if(oldToken){oldToken=undefined;isOldTokenSent=!![];}if(_0x241b5e[_0xac18('0x13')]){isOldTokenSent=![];if(!_0x1766a0['license']&&_0x1766a0[_0xac18('0x7')]!=_0x241b5e['license']||_0x1766a0[_0xac18('0x7')]&&_0x1766a0['data2']){logger[_0xac18('0x14')](_0xac18('0x15'));}if(_0x1766a0[_0xac18('0x7')]&&!_0x1766a0['data2']&&_0x1766a0['license']!=_0x241b5e[_0xac18('0x7')]){logger[_0xac18('0x14')](_0xac18('0x16'));}if(_0x1766a0[_0xac18('0x7')]&&!_0x1766a0[_0xac18('0x12')]&&_0x1766a0[_0xac18('0x7')]==_0x241b5e[_0xac18('0x7')]){return _0x2fddc3;}return _0x2fddc3[_0xac18('0x17')]({'data1':_0x4042b2,'data2':null,'license':_0x241b5e[_0xac18('0x7')]});}else{if(_0x241b5e[_0xac18('0x7')]||_0x1766a0['license']){if(!_0x1766a0[_0xac18('0x12')]){if(_0x1766a0['data1']==_0x4042b2){GRAY_PERIOD_REASON=_0xac18('0x18');logger['info'](_0xac18('0x19'));}else{GRAY_PERIOD_REASON=_0xac18('0x1a');logger[_0xac18('0x14')](_0xac18('0x1b'),_0x1766a0[_0xac18('0x11')],_0x4042b2);}logger[_0xac18('0x14')](_0xac18('0x1c'),GRAY_PERIOD_REASON[_0xac18('0x1d')](),moment()['format'](_0xac18('0x1e')));return _0x2fddc3[_0xac18('0x17')]({'data2':encryptor[_0xac18('0x1f')](moment()[_0xac18('0x9')](_0xac18('0x1e')))});}else{if(moment()[_0xac18('0x20')](encryptor[_0xac18('0x21')](_0x1766a0[_0xac18('0x12')]),_0xac18('0x22'))>DAYS){logger[_0xac18('0x14')](_0xac18('0x23'),moment()[_0xac18('0x9')]('YYYY-MM-DD\x20HH:mm'));isOldTokenSent=![];return _0x2fddc3['update']({'data1':_0x4042b2,'data2':null,'license':null});}}}else{if(_0x1766a0[_0xac18('0x11')]!=_0x4042b2){logger[_0xac18('0x14')](_0xac18('0x1b'),_0x1766a0['data1'],_0x4042b2);return _0x2fddc3['update']({'data1':_0x4042b2,'data2':null,'license':null});}}}return _0x2fddc3;})['then'](function(_0x2be98e){_0x2fddc3=_0x2be98e;})[_0xac18('0xf')](function(_0x5cd31c){logger[_0xac18('0x24')](_0x5cd31c[_0xac18('0x25')]);})['finally'](function(){setTimeout(function(){manageLicense(hardware[_0xac18('0x26')](),_0x2fddc3);},TIME);});}function defaultLicense(){var _0x5b5e86=hardware[_0xac18('0x26')]();if(_0x5b5e86){return db['License'][_0xac18('0x27')]({'where':{'id':0x1},'defaults':{'data1':_0x5b5e86}})[_0xac18('0x28')](function(_0x15c7e8,_0x21f3dd){logger[_0xac18('0x14')](_0xac18('0x29'),_0x5b5e86);manageLicense(_0x5b5e86,_0x15c7e8);})[_0xac18('0xf')](function(_0x9f3d99){logger[_0xac18('0x24')](_0x9f3d99[_0xac18('0x25')]);});}}exports[_0xac18('0x2a')]=defaultLicense;