Built motion from commit f8768ebe.|2.6.15
[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 _0x3350=['message','User','findAll','role','sequelize','COUNT','col','count','admin','user','telephone','users','telephones','forEach','catch','pick','countBy','License\x20limit\x20reached\x20for\x20users','License\x20limit\x20reached\x20for\x20telephones','exports','util','lodash','moment','./hardware','../../mysqldb','Demo\x20license','2027-01-01T00:00:00.000Z','Breaking\x20license','getUuid','License','find','defaults','then','uuid','data1','license','isEmpty','License\x20key\x20value\x20not\x20found','data2','decryptString','demo','machineUuid','deadline','add','format','grayReason','changed'];(function(_0x13ea00,_0x12f610){var _0x1f7347=function(_0x34ae63){while(--_0x34ae63){_0x13ea00['push'](_0x13ea00['shift']());}};_0x1f7347(++_0x12f610);}(_0x3350,0x18c));var _0x0335=function(_0xa9bd1c,_0x2b59c1){_0xa9bd1c=_0xa9bd1c-0x0;var _0x2c0161=_0x3350[_0xa9bd1c];return _0x2c0161;};'use strict';var util=require(_0x0335('0x0'));var _=require(_0x0335('0x1'));var moment=require(_0x0335('0x2'));var BPromise=require('bluebird');var hardware=require(_0x0335('0x3'));var encryptor=require('../../components/encryptor');var db=require(_0x0335('0x4'))['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':_0x0335('0x5'),'machineUuid':hardware['getUuid'](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};const breakingLicense={'breaking':!![],'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':_0x0335('0x6'),'chat':![],'mail':![],'fax':![],'messaging':![],'whatsapp':![],'cm':![],'dialer':![],'jscripty':![],'openchannel':![],'callysquare':0x2,'webrtc':![],'jaws':![],'custom':![],'update':![],'description':_0x0335('0x7'),'machineUuid':hardware[_0x0335('0x8')](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};function getLicense(_0x41030b){return new BPromise(function(_0x39dc54,_0x4ee87c){return db[_0x0335('0x9')][_0x0335('0xa')](_[_0x0335('0xb')](_0x41030b,{'raw':!![],'where':{'id':0x1}}))[_0x0335('0xc')](function(_0x4eb0e3){return checkLicense(_0x4eb0e3,null);})[_0x0335('0xc')](function(_0x17e881){_0x39dc54(_0x17e881);return;})['catch'](function(_0x41a130){_0x4ee87c(_0x41a130);});});}function checkLicense(_0x40449e,_0x1c6e60){if(!_0x40449e){demoLicense[_0x0335('0xd')]=_0x40449e[_0x0335('0xe')];return demoLicense;}try{var _0x172fc7=_0x1c6e60||_0x40449e[_0x0335('0xf')];if(_[_0x0335('0x10')](_0x172fc7)){throw new Error(_0x0335('0x11'));}var _0x503c20=_0x40449e['data1'];var _0x4b47d5=_0x40449e[_0x0335('0x12')];var _0x434a0d=_0x503c20['split']('-')[0x4];var _0x3454e9=_0x503c20['split']('-')[0x0];var _0x17f7a0=encryptor[_0x0335('0x13')](_0x172fc7,util['format']('%s:%s:%s',_0x434a0d,_0x503c20,_0x3454e9));var _0x1a53a2=JSON['parse'](_0x17f7a0);_0x1a53a2[_0x0335('0x14')]=![];_0x1a53a2[_0x0335('0xd')]=_0x503c20;_0x1a53a2[_0x0335('0x15')]=hardware[_0x0335('0x8')]();if(_0x4b47d5){var _0x55d013=encryptor[_0x0335('0x13')](_0x4b47d5);_0x1a53a2['gray']=_0x55d013;_0x1a53a2[_0x0335('0x16')]=moment(_0x55d013)[_0x0335('0x17')](0x7,'days')[_0x0335('0x18')]();_0x1a53a2[_0x0335('0x19')]=_0x1a53a2['uuid']!=_0x1a53a2[_0x0335('0x15')]?_0x0335('0x1a'):'disabled';}return _0x1a53a2;}catch(_0x29f5c2){breakingLicense[_0x0335('0xd')]=_0x40449e[_0x0335('0xe')];breakingLicense[_0x0335('0x1b')]=_0x29f5c2['message'];return breakingLicense;}}function getLimits(){return new BPromise(function(_0x28da45,_0x2300bb){getLicense()['then'](function(_0x4c0e81){return db[_0x0335('0x1c')][_0x0335('0x1d')]({'attributes':[_0x0335('0x1e'),[db[_0x0335('0x1f')]['fn'](_0x0335('0x20'),db[_0x0335('0x1f')][_0x0335('0x21')](_0x0335('0x1e'))),_0x0335('0x22')]],'group':_0x0335('0x1e'),'where':{'role':{'$or':[_0x0335('0x23'),_0x0335('0x24'),_0x0335('0x25')]}},'raw':!![]})[_0x0335('0xc')](function(_0x4bf4c9){var _0x47e2eb={'user':_0x4c0e81[_0x0335('0x26')]||0x0,'telephone':_0x4c0e81[_0x0335('0x27')]||0x0};_0x4bf4c9[_0x0335('0x28')](function(_0x1fb340){var _0x189547=_0x1fb340[_0x0335('0x1e')]===_0x0335('0x23')?_0x0335('0x24'):_0x1fb340[_0x0335('0x1e')];_0x47e2eb[_0x189547]-=_0x1fb340[_0x0335('0x22')];if(_0x47e2eb[_0x189547]<0x0)_0x47e2eb[_0x189547]=0x0;});_0x28da45(_0x47e2eb);return;});})[_0x0335('0x29')](function(_0x10f5b8){_0x2300bb(_0x10f5b8);});});}function checkUserLimits(_0xb58e64){return new BPromise(function(_0xe68b8c,_0x35a0c3){getLimits()['then'](function(_0x39162b){var _0x1f873d=_[_0x0335('0x2a')](_[_0x0335('0x2b')](_0xb58e64,_0x0335('0x1e')),[_0x0335('0x23'),_0x0335('0x24'),_0x0335('0x25')]);var _0xc5a68d=(_0x1f873d[_0x0335('0x23')]||0x0)+(_0x1f873d[_0x0335('0x24')]||0x0);var _0x24b038=_0x1f873d[_0x0335('0x25')]||0x0;if(_0xc5a68d>_0x39162b['user'])return _0x35a0c3(_0x0335('0x2c'));if(_0x24b038>_0x39162b[_0x0335('0x25')])return _0x35a0c3(_0x0335('0x2d'));return _0xe68b8c();})['catch'](function(_0x426745){_0x35a0c3(_0x426745);});});}module[_0x0335('0x2e')]={'checkLicense':checkLicense,'checkUserLimits':checkUserLimits,'getLicense':getLicense};