808eaf8d201d0128dd435704cc4c94ce6b4f3e72
[motion2.git] / server / config / license / util.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 _0x4b24=['defaults','then','catch','uuid','data1','isEmpty','License\x20key\x20value\x20not\x20found','data2','split','decryptString','format','parse','demo','machineUuid','getUuid','gray','deadline','add','days','grayReason','changed','message','findAll','sequelize','col','role','count','admin','telephone','users','telephones','forEach','user','License\x20limit\x20reached\x20for\x20telephones','exports','util','lodash','moment','bluebird','../../components/encryptor','../../mysqldb','Demo\x20license','2027-01-01T00:00:00.000Z','Breaking\x20license','License'];(function(_0xe4c712,_0x1e26d5){var _0x101962=function(_0x1bfc5a){while(--_0x1bfc5a){_0xe4c712['push'](_0xe4c712['shift']());}};_0x101962(++_0x1e26d5);}(_0x4b24,0x7d));var _0x44b2=function(_0x3f5bf8,_0x5514d2){_0x3f5bf8=_0x3f5bf8-0x0;var _0x2a912f=_0x4b24[_0x3f5bf8];return _0x2a912f;};'use strict';var util=require(_0x44b2('0x0'));var _=require(_0x44b2('0x1'));var moment=require(_0x44b2('0x2'));var BPromise=require(_0x44b2('0x3'));var hardware=require('./hardware');var encryptor=require(_0x44b2('0x4'));var db=require(_0x44b2('0x5'))['db'];const demoLicense={'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':'2027-01-01T00:00:00.000Z','chat':![],'mail':![],'fax':![],'messaging':![],'whatsapp':![],'cm':![],'dialer':![],'jscripty':![],'openchannel':![],'callysquare':0x2,'webrtc':![],'jaws':![],'custom':![],'description':_0x44b2('0x6'),'machineUuid':hardware['getUuid'](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};const breakingLicense={'breaking':!![],'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':_0x44b2('0x7'),'chat':![],'mail':![],'fax':![],'messaging':![],'whatsapp':![],'cm':![],'dialer':![],'jscripty':![],'openchannel':![],'callysquare':0x2,'webrtc':![],'jaws':![],'custom':![],'update':![],'description':_0x44b2('0x8'),'machineUuid':hardware['getUuid'](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};function getLicense(_0x17695e){return new BPromise(function(_0x30f770,_0x1efcf5){return db[_0x44b2('0x9')]['find'](_[_0x44b2('0xa')](_0x17695e,{'raw':!![],'where':{'id':0x1}}))[_0x44b2('0xb')](function(_0x4ece5b){return checkLicense(_0x4ece5b,null);})['then'](function(_0x94b5a7){_0x30f770(_0x94b5a7);return;})[_0x44b2('0xc')](function(_0x551e0c){_0x1efcf5(_0x551e0c);});});}function checkLicense(_0x1a1fd7,_0x2c292e){if(!_0x1a1fd7){demoLicense[_0x44b2('0xd')]=_0x1a1fd7[_0x44b2('0xe')];return demoLicense;}try{var _0x3c1b5e=_0x2c292e||_0x1a1fd7['license'];if(_[_0x44b2('0xf')](_0x3c1b5e)){throw new Error(_0x44b2('0x10'));}var _0x9090d7=_0x1a1fd7[_0x44b2('0xe')];var _0x45e74c=_0x1a1fd7[_0x44b2('0x11')];var _0x2d698a=_0x9090d7[_0x44b2('0x12')]('-')[0x4];var _0x50a610=_0x9090d7['split']('-')[0x0];var _0x763f10=encryptor[_0x44b2('0x13')](_0x3c1b5e,util[_0x44b2('0x14')]('%s:%s:%s',_0x2d698a,_0x9090d7,_0x50a610));var _0x3120ec=JSON[_0x44b2('0x15')](_0x763f10);_0x3120ec[_0x44b2('0x16')]=![];_0x3120ec[_0x44b2('0xd')]=_0x9090d7;_0x3120ec[_0x44b2('0x17')]=hardware[_0x44b2('0x18')]();if(_0x45e74c){var _0x4c095d=encryptor[_0x44b2('0x13')](_0x45e74c);_0x3120ec[_0x44b2('0x19')]=_0x4c095d;_0x3120ec[_0x44b2('0x1a')]=moment(_0x4c095d)[_0x44b2('0x1b')](0x7,_0x44b2('0x1c'))[_0x44b2('0x14')]();_0x3120ec[_0x44b2('0x1d')]=_0x3120ec['uuid']!=_0x3120ec['machineUuid']?_0x44b2('0x1e'):'disabled';}return _0x3120ec;}catch(_0x53fd86){breakingLicense[_0x44b2('0xd')]=_0x1a1fd7[_0x44b2('0xe')];breakingLicense['message']=_0x53fd86[_0x44b2('0x1f')];return breakingLicense;}}function getLimits(){return new BPromise(function(_0x218a38,_0x319f04){getLicense()[_0x44b2('0xb')](function(_0x1935a8){return db['User'][_0x44b2('0x20')]({'attributes':['role',[db[_0x44b2('0x21')]['fn']('COUNT',db[_0x44b2('0x21')][_0x44b2('0x22')](_0x44b2('0x23'))),_0x44b2('0x24')]],'group':_0x44b2('0x23'),'where':{'role':{'$or':[_0x44b2('0x25'),'user',_0x44b2('0x26')]}},'raw':!![]})[_0x44b2('0xb')](function(_0x18a302){var _0x4d32dc={'user':_0x1935a8[_0x44b2('0x27')]||0x0,'telephone':_0x1935a8[_0x44b2('0x28')]||0x0};_0x18a302[_0x44b2('0x29')](function(_0x412364){var _0x314a07=_0x412364[_0x44b2('0x23')]===_0x44b2('0x25')?_0x44b2('0x2a'):_0x412364[_0x44b2('0x23')];_0x4d32dc[_0x314a07]-=_0x412364[_0x44b2('0x24')];if(_0x4d32dc[_0x314a07]<0x0)_0x4d32dc[_0x314a07]=0x0;});_0x218a38(_0x4d32dc);return;});})['catch'](function(_0x581f02){_0x319f04(_0x581f02);});});}function checkUserLimits(_0x12660a){return new BPromise(function(_0x103f72,_0x4a0b41){getLimits()[_0x44b2('0xb')](function(_0x3c2f7e){var _0x2f405e=_['pick'](_['countBy'](_0x12660a,_0x44b2('0x23')),['admin',_0x44b2('0x2a'),'telephone']);var _0x734b51=(_0x2f405e[_0x44b2('0x25')]||0x0)+(_0x2f405e[_0x44b2('0x2a')]||0x0);var _0x15f528=_0x2f405e[_0x44b2('0x26')]||0x0;if(_0x734b51>_0x3c2f7e[_0x44b2('0x2a')])return _0x4a0b41('License\x20limit\x20reached\x20for\x20users');if(_0x15f528>_0x3c2f7e['telephone'])return _0x4a0b41(_0x44b2('0x2b'));return _0x103f72();})[_0x44b2('0xc')](function(_0x2141db){_0x4a0b41(_0x2141db);});});}module[_0x44b2('0x2c')]={'checkLicense':checkLicense,'checkUserLimits':checkUserLimits,'getLicense':getLicense};