Built motion from commit 08fb8613.|2.6.31
[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 _0x266f=['bluebird','./hardware','../../components/encryptor','../../mysqldb','2027-01-01T00:00:00.000Z','Breaking\x20license','getUuid','License','find','defaults','then','catch','uuid','data1','license','data2','split','format','parse','machineUuid','gray','add','days','grayReason','changed','disabled','message','User','findAll','role','sequelize','COUNT','count','admin','user','telephone','users','telephones','forEach','pick','countBy','License\x20limit\x20reached\x20for\x20users','License\x20limit\x20reached\x20for\x20telephones','util','lodash','moment'];(function(_0x2c91e9,_0x2fb965){var _0x13f0ff=function(_0xb39edf){while(--_0xb39edf){_0x2c91e9['push'](_0x2c91e9['shift']());}};_0x13f0ff(++_0x2fb965);}(_0x266f,0x16d));var _0xf266=function(_0x3c2166,_0x41fc16){_0x3c2166=_0x3c2166-0x0;var _0x30ccc3=_0x266f[_0x3c2166];return _0x30ccc3;};'use strict';var util=require(_0xf266('0x0'));var _=require(_0xf266('0x1'));var moment=require(_0xf266('0x2'));var BPromise=require(_0xf266('0x3'));var hardware=require(_0xf266('0x4'));var encryptor=require(_0xf266('0x5'));var db=require(_0xf266('0x6'))['db'];const demoLicense={'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':_0xf266('0x7'),'chat':![],'mail':![],'fax':![],'messaging':![],'whatsapp':![],'cm':![],'dialer':![],'jscripty':![],'openchannel':![],'callysquare':0x2,'webrtc':![],'jaws':![],'custom':![],'description':'Demo\x20license','machineUuid':hardware['getUuid'](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};const breakingLicense={'breaking':!![],'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':_0xf266('0x7'),'chat':![],'mail':![],'fax':![],'messaging':![],'whatsapp':![],'cm':![],'dialer':![],'jscripty':![],'openchannel':![],'callysquare':0x2,'webrtc':![],'jaws':![],'custom':![],'update':![],'description':_0xf266('0x8'),'machineUuid':hardware[_0xf266('0x9')](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};function getLicense(_0x948e8b){return new BPromise(function(_0x5f4f40,_0x371b0d){return db[_0xf266('0xa')][_0xf266('0xb')](_[_0xf266('0xc')](_0x948e8b,{'raw':!![],'where':{'id':0x1}}))[_0xf266('0xd')](function(_0x3dd7df){return checkLicense(_0x3dd7df,null);})[_0xf266('0xd')](function(_0x4569ec){_0x5f4f40(_0x4569ec);return;})[_0xf266('0xe')](function(_0x399a79){_0x371b0d(_0x399a79);});});}function checkLicense(_0x24db4e,_0x11f9f8){if(!_0x24db4e){demoLicense[_0xf266('0xf')]=_0x24db4e[_0xf266('0x10')];return demoLicense;}try{var _0x5751e4=_0x11f9f8||_0x24db4e[_0xf266('0x11')];if(_['isEmpty'](_0x5751e4)){throw new Error('License\x20key\x20value\x20not\x20found');}var _0x639a12=_0x24db4e[_0xf266('0x10')];var _0x17dab6=_0x24db4e[_0xf266('0x12')];var _0x4edd7a=_0x639a12['split']('-')[0x4];var _0x266efc=_0x639a12[_0xf266('0x13')]('-')[0x0];var _0x2843c9=encryptor['decryptString'](_0x5751e4,util[_0xf266('0x14')]('%s:%s:%s',_0x4edd7a,_0x639a12,_0x266efc));var _0x29687f=JSON[_0xf266('0x15')](_0x2843c9);_0x29687f['demo']=![];_0x29687f['uuid']=_0x639a12;_0x29687f[_0xf266('0x16')]=hardware[_0xf266('0x9')]();if(_0x17dab6){var _0x4eb0c2=encryptor['decryptString'](_0x17dab6);_0x29687f[_0xf266('0x17')]=_0x4eb0c2;_0x29687f['deadline']=moment(_0x4eb0c2)[_0xf266('0x18')](0x7,_0xf266('0x19'))[_0xf266('0x14')]();_0x29687f[_0xf266('0x1a')]=_0x29687f['uuid']!=_0x29687f[_0xf266('0x16')]?_0xf266('0x1b'):_0xf266('0x1c');}return _0x29687f;}catch(_0x4a4d96){breakingLicense[_0xf266('0xf')]=_0x24db4e['data1'];breakingLicense[_0xf266('0x1d')]=_0x4a4d96[_0xf266('0x1d')];return breakingLicense;}}function getLimits(){return new BPromise(function(_0x2248f8,_0x848bf5){getLicense()['then'](function(_0x528ab2){return db[_0xf266('0x1e')][_0xf266('0x1f')]({'attributes':[_0xf266('0x20'),[db[_0xf266('0x21')]['fn'](_0xf266('0x22'),db[_0xf266('0x21')]['col'](_0xf266('0x20'))),_0xf266('0x23')]],'group':_0xf266('0x20'),'where':{'role':{'$or':[_0xf266('0x24'),_0xf266('0x25'),_0xf266('0x26')]}},'raw':!![]})[_0xf266('0xd')](function(_0x2346f3){var _0x147842={'user':_0x528ab2[_0xf266('0x27')]||0x0,'telephone':_0x528ab2[_0xf266('0x28')]||0x0};_0x2346f3[_0xf266('0x29')](function(_0x9c2d2e){var _0xbf8944=_0x9c2d2e['role']===_0xf266('0x24')?_0xf266('0x25'):_0x9c2d2e[_0xf266('0x20')];_0x147842[_0xbf8944]-=_0x9c2d2e[_0xf266('0x23')];if(_0x147842[_0xbf8944]<0x0)_0x147842[_0xbf8944]=0x0;});_0x2248f8(_0x147842);return;});})[_0xf266('0xe')](function(_0x5326f8){_0x848bf5(_0x5326f8);});});}function checkUserLimits(_0x518e7e){return new BPromise(function(_0x25b186,_0x185cfc){getLimits()['then'](function(_0x330c1d){var _0x709e58=_[_0xf266('0x2a')](_[_0xf266('0x2b')](_0x518e7e,'role'),[_0xf266('0x24'),_0xf266('0x25'),'telephone']);var _0x91cc0c=(_0x709e58[_0xf266('0x24')]||0x0)+(_0x709e58[_0xf266('0x25')]||0x0);var _0x32938e=_0x709e58[_0xf266('0x26')]||0x0;if(_0x91cc0c>_0x330c1d[_0xf266('0x25')])return _0x185cfc(_0xf266('0x2c'));if(_0x32938e>_0x330c1d[_0xf266('0x26')])return _0x185cfc(_0xf266('0x2d'));return _0x25b186();})[_0xf266('0xe')](function(_0x6794eb){_0x185cfc(_0x6794eb);});});}module['exports']={'checkLicense':checkLicense,'checkUserLimits':checkUserLimits,'getLicense':getLicense};