93673068e667d609d0683ec2160528e2ace87d0a
[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 _0xc4e3=['./hardware','../../components/encryptor','../../mysqldb','2027-01-01T00:00:00.000Z','Demo\x20license','Breaking\x20license','getUuid','License','find','defaults','then','catch','uuid','data1','license','isEmpty','split','decryptString','format','%s:%s:%s','parse','machineUuid','gray','add','grayReason','changed','disabled','message','findAll','role','sequelize','COUNT','col','admin','telephone','users','telephones','forEach','user','count','pick','countBy','License\x20limit\x20reached\x20for\x20users','License\x20limit\x20reached\x20for\x20telephones','exports','lodash','moment','bluebird'];(function(_0x1bbf9e,_0x2efe4b){var _0x3741eb=function(_0x5a8bf0){while(--_0x5a8bf0){_0x1bbf9e['push'](_0x1bbf9e['shift']());}};_0x3741eb(++_0x2efe4b);}(_0xc4e3,0x1dd));var _0x3c4e=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0xc4e3[_0x3dd15e];return _0x231fd0;};'use strict';var util=require('util');var _=require(_0x3c4e('0x0'));var moment=require(_0x3c4e('0x1'));var BPromise=require(_0x3c4e('0x2'));var hardware=require(_0x3c4e('0x3'));var encryptor=require(_0x3c4e('0x4'));var db=require(_0x3c4e('0x5'))['db'];const demoLicense={'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':_0x3c4e('0x6'),'chat':![],'mail':![],'fax':![],'messaging':![],'whatsapp':![],'cm':![],'dialer':![],'jscripty':![],'openchannel':![],'callysquare':0x2,'webrtc':![],'jaws':![],'custom':![],'description':_0x3c4e('0x7'),'machineUuid':hardware['getUuid'](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};const breakingLicense={'breaking':!![],'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':_0x3c4e('0x6'),'chat':![],'mail':![],'fax':![],'messaging':![],'whatsapp':![],'cm':![],'dialer':![],'jscripty':![],'openchannel':![],'callysquare':0x2,'webrtc':![],'jaws':![],'custom':![],'update':![],'description':_0x3c4e('0x8'),'machineUuid':hardware[_0x3c4e('0x9')](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};function getLicense(_0xc32a25){return new BPromise(function(_0x971fd8,_0x3ffdcb){return db[_0x3c4e('0xa')][_0x3c4e('0xb')](_[_0x3c4e('0xc')](_0xc32a25,{'raw':!![],'where':{'id':0x1}}))[_0x3c4e('0xd')](function(_0x17bf7f){return checkLicense(_0x17bf7f,null);})['then'](function(_0xf45df7){_0x971fd8(_0xf45df7);return;})[_0x3c4e('0xe')](function(_0x496185){_0x3ffdcb(_0x496185);});});}function checkLicense(_0x4aa416,_0x2c92a7){if(!_0x4aa416){demoLicense[_0x3c4e('0xf')]=_0x4aa416[_0x3c4e('0x10')];return demoLicense;}try{var _0x231691=_0x2c92a7||_0x4aa416[_0x3c4e('0x11')];if(_[_0x3c4e('0x12')](_0x231691)){throw new Error('License\x20key\x20value\x20not\x20found');}var _0x2d4940=_0x4aa416[_0x3c4e('0x10')];var _0x41bf8d=_0x4aa416['data2'];var _0x15d132=_0x2d4940[_0x3c4e('0x13')]('-')[0x4];var _0x4b9152=_0x2d4940[_0x3c4e('0x13')]('-')[0x0];var _0x1bb8a6=encryptor[_0x3c4e('0x14')](_0x231691,util[_0x3c4e('0x15')](_0x3c4e('0x16'),_0x15d132,_0x2d4940,_0x4b9152));var _0x1ee6c=JSON[_0x3c4e('0x17')](_0x1bb8a6);_0x1ee6c['demo']=![];_0x1ee6c[_0x3c4e('0xf')]=_0x2d4940;_0x1ee6c[_0x3c4e('0x18')]=hardware['getUuid']();if(_0x41bf8d){var _0x3d2ea8=encryptor[_0x3c4e('0x14')](_0x41bf8d);_0x1ee6c[_0x3c4e('0x19')]=_0x3d2ea8;_0x1ee6c['deadline']=moment(_0x3d2ea8)[_0x3c4e('0x1a')](0x7,'days')[_0x3c4e('0x15')]();_0x1ee6c[_0x3c4e('0x1b')]=_0x1ee6c['uuid']!=_0x1ee6c[_0x3c4e('0x18')]?_0x3c4e('0x1c'):_0x3c4e('0x1d');}return _0x1ee6c;}catch(_0x296c7c){breakingLicense[_0x3c4e('0xf')]=_0x4aa416['data1'];breakingLicense[_0x3c4e('0x1e')]=_0x296c7c[_0x3c4e('0x1e')];return breakingLicense;}}function getLimits(){return new BPromise(function(_0x4a3218,_0x418993){getLicense()[_0x3c4e('0xd')](function(_0x183b01){return db['User'][_0x3c4e('0x1f')]({'attributes':[_0x3c4e('0x20'),[db[_0x3c4e('0x21')]['fn'](_0x3c4e('0x22'),db['sequelize'][_0x3c4e('0x23')](_0x3c4e('0x20'))),'count']],'group':'role','where':{'role':{'$or':[_0x3c4e('0x24'),'user',_0x3c4e('0x25')]}},'raw':!![]})['then'](function(_0x382914){var _0x82c3a1={'user':_0x183b01[_0x3c4e('0x26')]||0x0,'telephone':_0x183b01[_0x3c4e('0x27')]||0x0};_0x382914[_0x3c4e('0x28')](function(_0x49e48b){var _0x2c5743=_0x49e48b[_0x3c4e('0x20')]===_0x3c4e('0x24')?_0x3c4e('0x29'):_0x49e48b[_0x3c4e('0x20')];_0x82c3a1[_0x2c5743]-=_0x49e48b[_0x3c4e('0x2a')];if(_0x82c3a1[_0x2c5743]<0x0)_0x82c3a1[_0x2c5743]=0x0;});_0x4a3218(_0x82c3a1);return;});})[_0x3c4e('0xe')](function(_0x149295){_0x418993(_0x149295);});});}function checkUserLimits(_0x162eea){return new BPromise(function(_0x24c8f7,_0x3351d1){getLimits()['then'](function(_0x21038c){var _0x4e3eb4=_[_0x3c4e('0x2b')](_[_0x3c4e('0x2c')](_0x162eea,_0x3c4e('0x20')),['admin',_0x3c4e('0x29'),_0x3c4e('0x25')]);var _0x165e73=(_0x4e3eb4['admin']||0x0)+(_0x4e3eb4[_0x3c4e('0x29')]||0x0);var _0x78486=_0x4e3eb4[_0x3c4e('0x25')]||0x0;if(_0x165e73>_0x21038c[_0x3c4e('0x29')])return _0x3351d1(_0x3c4e('0x2d'));if(_0x78486>_0x21038c[_0x3c4e('0x25')])return _0x3351d1(_0x3c4e('0x2e'));return _0x24c8f7();})['catch'](function(_0x317200){_0x3351d1(_0x317200);});});}module[_0x3c4e('0x2f')]={'checkLicense':checkLicense,'checkUserLimits':checkUserLimits,'getLicense':getLicense};