965a3ee54c29202b27f6355b793501df6fe63d8a
[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 _0x6649=['users','catch','License\x20limit\x20reached\x20for\x20users','License\x20limit\x20reached\x20for\x20telephones','exports','util','lodash','moment','bluebird','./hardware','../../mysqldb','2027-01-01T00:00:00.000Z','Demo\x20license','getUuid','find','defaults','then','uuid','data1','license','isEmpty','License\x20key\x20value\x20not\x20found','data2','split','decryptString','format','%s:%s:%s','demo','machineUuid','gray','deadline','add','grayReason','changed','disabled','message','User','findAll','sequelize','COUNT','col','count','role','admin','user','telephone'];(function(_0x3f47b6,_0xd08f31){var _0x57698f=function(_0x33052a){while(--_0x33052a){_0x3f47b6['push'](_0x3f47b6['shift']());}};_0x57698f(++_0xd08f31);}(_0x6649,0xbd));var _0x9664=function(_0x21cbfa,_0x5e6982){_0x21cbfa=_0x21cbfa-0x0;var _0x2eef1b=_0x6649[_0x21cbfa];return _0x2eef1b;};'use strict';var util=require(_0x9664('0x0'));var _=require(_0x9664('0x1'));var moment=require(_0x9664('0x2'));var BPromise=require(_0x9664('0x3'));var hardware=require(_0x9664('0x4'));var encryptor=require('../../components/encryptor');var db=require(_0x9664('0x5'))['db'];const demoLicense={'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':_0x9664('0x6'),'chat':![],'mail':![],'fax':![],'messaging':![],'whatsapp':![],'cm':![],'dialer':![],'jscripty':![],'openchannel':![],'callysquare':0x2,'webrtc':![],'jaws':![],'custom':![],'description':_0x9664('0x7'),'machineUuid':hardware['getUuid'](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};const breakingLicense={'breaking':!![],'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':_0x9664('0x6'),'chat':![],'mail':![],'fax':![],'messaging':![],'whatsapp':![],'cm':![],'dialer':![],'jscripty':![],'openchannel':![],'callysquare':0x2,'webrtc':![],'jaws':![],'custom':![],'update':![],'description':'Breaking\x20license','machineUuid':hardware[_0x9664('0x8')](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};function getLicense(_0xe01c57){return new BPromise(function(_0x5e0293,_0x13cfa1){return db['License'][_0x9664('0x9')](_[_0x9664('0xa')](_0xe01c57,{'raw':!![],'where':{'id':0x1}}))['then'](function(_0x150ea1){return checkLicense(_0x150ea1,null);})[_0x9664('0xb')](function(_0x55c959){_0x5e0293(_0x55c959);return;})['catch'](function(_0x3386d3){_0x13cfa1(_0x3386d3);});});}function checkLicense(_0x26455d,_0x9eb001){if(!_0x26455d){demoLicense[_0x9664('0xc')]=_0x26455d[_0x9664('0xd')];return demoLicense;}try{var _0x1dad5c=_0x9eb001||_0x26455d[_0x9664('0xe')];if(_[_0x9664('0xf')](_0x1dad5c)){throw new Error(_0x9664('0x10'));}var _0x33d013=_0x26455d[_0x9664('0xd')];var _0x18d222=_0x26455d[_0x9664('0x11')];var _0x54e259=_0x33d013[_0x9664('0x12')]('-')[0x4];var _0x4973c0=_0x33d013[_0x9664('0x12')]('-')[0x0];var _0x413e04=encryptor[_0x9664('0x13')](_0x1dad5c,util[_0x9664('0x14')](_0x9664('0x15'),_0x54e259,_0x33d013,_0x4973c0));var _0x2fc96f=JSON['parse'](_0x413e04);_0x2fc96f[_0x9664('0x16')]=![];_0x2fc96f[_0x9664('0xc')]=_0x33d013;_0x2fc96f[_0x9664('0x17')]=hardware['getUuid']();if(_0x18d222){var _0x2f1c03=encryptor[_0x9664('0x13')](_0x18d222);_0x2fc96f[_0x9664('0x18')]=_0x2f1c03;_0x2fc96f[_0x9664('0x19')]=moment(_0x2f1c03)[_0x9664('0x1a')](0x7,'days')[_0x9664('0x14')]();_0x2fc96f[_0x9664('0x1b')]=_0x2fc96f['uuid']!=_0x2fc96f[_0x9664('0x17')]?_0x9664('0x1c'):_0x9664('0x1d');}return _0x2fc96f;}catch(_0x2f6b60){breakingLicense[_0x9664('0xc')]=_0x26455d['data1'];breakingLicense['message']=_0x2f6b60[_0x9664('0x1e')];return breakingLicense;}}function getLimits(){return new BPromise(function(_0x55cb96,_0x4079a8){getLicense()[_0x9664('0xb')](function(_0x58614c){return db[_0x9664('0x1f')][_0x9664('0x20')]({'attributes':['role',[db[_0x9664('0x21')]['fn'](_0x9664('0x22'),db[_0x9664('0x21')][_0x9664('0x23')]('role')),_0x9664('0x24')]],'group':_0x9664('0x25'),'where':{'role':{'$or':[_0x9664('0x26'),_0x9664('0x27'),_0x9664('0x28')]}},'raw':!![]})[_0x9664('0xb')](function(_0x33d31d){var _0xc30139={'user':_0x58614c[_0x9664('0x29')]||0x0,'telephone':_0x58614c['telephones']||0x0};_0x33d31d['forEach'](function(_0x5d9fb9){var _0x11c3d0=_0x5d9fb9[_0x9664('0x25')]===_0x9664('0x26')?_0x9664('0x27'):_0x5d9fb9['role'];_0xc30139[_0x11c3d0]-=_0x5d9fb9['count'];if(_0xc30139[_0x11c3d0]<0x0)_0xc30139[_0x11c3d0]=0x0;});_0x55cb96(_0xc30139);return;});})[_0x9664('0x2a')](function(_0x1935b0){_0x4079a8(_0x1935b0);});});}function checkUserLimits(_0xa52cb9){return new BPromise(function(_0x12b976,_0x15933a){getLimits()['then'](function(_0xc5878b){var _0x4c8555=_['pick'](_['countBy'](_0xa52cb9,_0x9664('0x25')),[_0x9664('0x26'),_0x9664('0x27'),'telephone']);var _0x422d21=(_0x4c8555[_0x9664('0x26')]||0x0)+(_0x4c8555[_0x9664('0x27')]||0x0);var _0x211347=_0x4c8555[_0x9664('0x28')]||0x0;if(_0x422d21>_0xc5878b[_0x9664('0x27')])return _0x15933a(_0x9664('0x2b'));if(_0x211347>_0xc5878b[_0x9664('0x28')])return _0x15933a(_0x9664('0x2c'));return _0x12b976();})[_0x9664('0x2a')](function(_0x42ebec){_0x15933a(_0x42ebec);});});}module[_0x9664('0x2d')]={'checkLicense':checkLicense,'checkUserLimits':checkUserLimits,'getLicense':getLicense};