Built motion from commit 953226e6.|2.6.32
[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 _0x953f=['role','sequelize','count','admin','user','telephone','users','telephones','forEach','catch','pick','countBy','License\x20limit\x20reached\x20for\x20users','License\x20limit\x20reached\x20for\x20telephones','exports','util','lodash','moment','bluebird','./hardware','../../components/encryptor','Demo\x20license','getUuid','2027-01-01T00:00:00.000Z','find','defaults','then','uuid','data1','license','data2','split','decryptString','format','%s:%s:%s','parse','demo','machineUuid','gray','deadline','add','days','changed','disabled','message','User','findAll'];(function(_0x3877b5,_0x5794e7){var _0xb5ac48=function(_0x2e4ca6){while(--_0x2e4ca6){_0x3877b5['push'](_0x3877b5['shift']());}};_0xb5ac48(++_0x5794e7);}(_0x953f,0x187));var _0xf953=function(_0x1969a7,_0x5a133a){_0x1969a7=_0x1969a7-0x0;var _0x3d665f=_0x953f[_0x1969a7];return _0x3d665f;};'use strict';var util=require(_0xf953('0x0'));var _=require(_0xf953('0x1'));var moment=require(_0xf953('0x2'));var BPromise=require(_0xf953('0x3'));var hardware=require(_0xf953('0x4'));var encryptor=require(_0xf953('0x5'));var db=require('../../mysqldb')['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':_0xf953('0x6'),'machineUuid':hardware[_0xf953('0x7')](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};const breakingLicense={'breaking':!![],'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':_0xf953('0x8'),'chat':![],'mail':![],'fax':![],'messaging':![],'whatsapp':![],'cm':![],'dialer':![],'jscripty':![],'openchannel':![],'callysquare':0x2,'webrtc':![],'jaws':![],'custom':![],'update':![],'description':'Breaking\x20license','machineUuid':hardware[_0xf953('0x7')](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};function getLicense(_0x4f12ad){return new BPromise(function(_0x1073b5,_0x2c116a){return db['License'][_0xf953('0x9')](_[_0xf953('0xa')](_0x4f12ad,{'raw':!![],'where':{'id':0x1}}))[_0xf953('0xb')](function(_0x40bbdd){return checkLicense(_0x40bbdd,null);})[_0xf953('0xb')](function(_0x153522){_0x1073b5(_0x153522);return;})['catch'](function(_0x5277ec){_0x2c116a(_0x5277ec);});});}function checkLicense(_0x494666,_0x152b81){if(!_0x494666){demoLicense[_0xf953('0xc')]=_0x494666[_0xf953('0xd')];return demoLicense;}try{var _0x16c5c2=_0x152b81||_0x494666[_0xf953('0xe')];if(_['isEmpty'](_0x16c5c2)){throw new Error('License\x20key\x20value\x20not\x20found');}var _0x412e48=_0x494666[_0xf953('0xd')];var _0xadc1f9=_0x494666[_0xf953('0xf')];var _0x402581=_0x412e48['split']('-')[0x4];var _0x505d2c=_0x412e48[_0xf953('0x10')]('-')[0x0];var _0x1abe59=encryptor[_0xf953('0x11')](_0x16c5c2,util[_0xf953('0x12')](_0xf953('0x13'),_0x402581,_0x412e48,_0x505d2c));var _0x4396c1=JSON[_0xf953('0x14')](_0x1abe59);_0x4396c1[_0xf953('0x15')]=![];_0x4396c1['uuid']=_0x412e48;_0x4396c1[_0xf953('0x16')]=hardware['getUuid']();if(_0xadc1f9){var _0x5e1614=encryptor['decryptString'](_0xadc1f9);_0x4396c1[_0xf953('0x17')]=_0x5e1614;_0x4396c1[_0xf953('0x18')]=moment(_0x5e1614)[_0xf953('0x19')](0x7,_0xf953('0x1a'))[_0xf953('0x12')]();_0x4396c1['grayReason']=_0x4396c1[_0xf953('0xc')]!=_0x4396c1[_0xf953('0x16')]?_0xf953('0x1b'):_0xf953('0x1c');}return _0x4396c1;}catch(_0x13e3ae){breakingLicense[_0xf953('0xc')]=_0x494666[_0xf953('0xd')];breakingLicense[_0xf953('0x1d')]=_0x13e3ae[_0xf953('0x1d')];return breakingLicense;}}function getLimits(){return new BPromise(function(_0x11022d,_0x4026d2){getLicense()[_0xf953('0xb')](function(_0x39321c){return db[_0xf953('0x1e')][_0xf953('0x1f')]({'attributes':[_0xf953('0x20'),[db[_0xf953('0x21')]['fn']('COUNT',db[_0xf953('0x21')]['col'](_0xf953('0x20'))),_0xf953('0x22')]],'group':_0xf953('0x20'),'where':{'role':{'$or':[_0xf953('0x23'),_0xf953('0x24'),_0xf953('0x25')]}},'raw':!![]})['then'](function(_0x2d7bd1){var _0x2c39f7={'user':_0x39321c[_0xf953('0x26')]||0x0,'telephone':_0x39321c[_0xf953('0x27')]||0x0};_0x2d7bd1[_0xf953('0x28')](function(_0x94d7ca){var _0x258cc2=_0x94d7ca[_0xf953('0x20')]===_0xf953('0x23')?_0xf953('0x24'):_0x94d7ca[_0xf953('0x20')];_0x2c39f7[_0x258cc2]-=_0x94d7ca[_0xf953('0x22')];if(_0x2c39f7[_0x258cc2]<0x0)_0x2c39f7[_0x258cc2]=0x0;});_0x11022d(_0x2c39f7);return;});})[_0xf953('0x29')](function(_0xc0ce23){_0x4026d2(_0xc0ce23);});});}function checkUserLimits(_0x48263c){return new BPromise(function(_0x5c6e9c,_0x10a892){getLimits()[_0xf953('0xb')](function(_0x43d5ba){var _0x2cda50=_[_0xf953('0x2a')](_[_0xf953('0x2b')](_0x48263c,_0xf953('0x20')),['admin','user',_0xf953('0x25')]);var _0x39b090=(_0x2cda50[_0xf953('0x23')]||0x0)+(_0x2cda50[_0xf953('0x24')]||0x0);var _0x21bcee=_0x2cda50[_0xf953('0x25')]||0x0;if(_0x39b090>_0x43d5ba['user'])return _0x10a892(_0xf953('0x2c'));if(_0x21bcee>_0x43d5ba[_0xf953('0x25')])return _0x10a892(_0xf953('0x2d'));return _0x5c6e9c();})['catch'](function(_0x3c9afc){_0x10a892(_0x3c9afc);});});}module[_0xf953('0x2e')]={'checkLicense':checkLicense,'checkUserLimits':checkUserLimits,'getLicense':getLicense};