Built motion from commit f3da74b7.|2.5.36
[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 _0xb8f6=['data2','split','decryptString','format','%s:%s:%s','parse','demo','uuid','gray','deadline','machineUuid','disabled','message','findAll','role','COUNT','sequelize','col','count','admin','user','telephone','telephones','forEach','pick','countBy','License\x20limit\x20reached\x20for\x20users','License\x20limit\x20reached\x20for\x20telephones','exports','util','moment','bluebird','./hardware','../../components/encryptor','../../mysqldb','2027-01-01T00:00:00.000Z','Demo\x20license','getUuid','Breaking\x20license','find','defaults','then','catch','data1','license','isEmpty'];(function(_0xca212f,_0x1e1152){var _0x624483=function(_0x6b36e1){while(--_0x6b36e1){_0xca212f['push'](_0xca212f['shift']());}};_0x624483(++_0x1e1152);}(_0xb8f6,0xa7));var _0x6b8f=function(_0x5bd426,_0x4878e5){_0x5bd426=_0x5bd426-0x0;var _0x23a7eb=_0xb8f6[_0x5bd426];return _0x23a7eb;};'use strict';var util=require(_0x6b8f('0x0'));var _=require('lodash');var moment=require(_0x6b8f('0x1'));var BPromise=require(_0x6b8f('0x2'));var hardware=require(_0x6b8f('0x3'));var encryptor=require(_0x6b8f('0x4'));var db=require(_0x6b8f('0x5'))['db'];const demoLicense={'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':_0x6b8f('0x6'),'chat':![],'mail':![],'fax':![],'messaging':![],'whatsapp':![],'cm':![],'dialer':![],'jscripty':![],'openchannel':![],'callysquare':0x2,'webrtc':![],'jaws':![],'custom':![],'description':_0x6b8f('0x7'),'machineUuid':hardware[_0x6b8f('0x8')](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};const breakingLicense={'breaking':!![],'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':![],'update':![],'description':_0x6b8f('0x9'),'machineUuid':hardware[_0x6b8f('0x8')](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};function getLicense(_0x353151){return new BPromise(function(_0x5b4aa6,_0x10514c){return db['License'][_0x6b8f('0xa')](_[_0x6b8f('0xb')](_0x353151,{'raw':!![],'where':{'id':0x1}}))[_0x6b8f('0xc')](function(_0x21f04a){return checkLicense(_0x21f04a,null);})['then'](function(_0x383f18){_0x5b4aa6(_0x383f18);return;})[_0x6b8f('0xd')](function(_0x729c84){_0x10514c(_0x729c84);});});}function checkLicense(_0x151d0d,_0x493bbf){if(!_0x151d0d){demoLicense['uuid']=_0x151d0d[_0x6b8f('0xe')];return demoLicense;}try{var _0x142725=_0x493bbf||_0x151d0d[_0x6b8f('0xf')];if(_[_0x6b8f('0x10')](_0x142725)){throw new Error('License\x20key\x20value\x20not\x20found');}var _0x26169f=_0x151d0d[_0x6b8f('0xe')];var _0x56cc11=_0x151d0d[_0x6b8f('0x11')];var _0x2c248f=_0x26169f[_0x6b8f('0x12')]('-')[0x4];var _0x23c79f=_0x26169f[_0x6b8f('0x12')]('-')[0x0];var _0x40b383=encryptor[_0x6b8f('0x13')](_0x142725,util[_0x6b8f('0x14')](_0x6b8f('0x15'),_0x2c248f,_0x26169f,_0x23c79f));var _0x37531a=JSON[_0x6b8f('0x16')](_0x40b383);_0x37531a[_0x6b8f('0x17')]=![];_0x37531a[_0x6b8f('0x18')]=_0x26169f;_0x37531a['machineUuid']=hardware[_0x6b8f('0x8')]();if(_0x56cc11){var _0x3b1aae=encryptor[_0x6b8f('0x13')](_0x56cc11);_0x37531a[_0x6b8f('0x19')]=_0x3b1aae;_0x37531a[_0x6b8f('0x1a')]=moment(_0x3b1aae)['add'](0x7,'days')[_0x6b8f('0x14')]();_0x37531a['grayReason']=_0x37531a[_0x6b8f('0x18')]!=_0x37531a[_0x6b8f('0x1b')]?'changed':_0x6b8f('0x1c');}return _0x37531a;}catch(_0x55e7e2){breakingLicense[_0x6b8f('0x18')]=_0x151d0d[_0x6b8f('0xe')];breakingLicense[_0x6b8f('0x1d')]=_0x55e7e2['message'];return breakingLicense;}}function getLimits(){return new BPromise(function(_0x372d76,_0x29e288){getLicense()[_0x6b8f('0xc')](function(_0x311ef2){return db['User'][_0x6b8f('0x1e')]({'attributes':[_0x6b8f('0x1f'),[db['sequelize']['fn'](_0x6b8f('0x20'),db[_0x6b8f('0x21')][_0x6b8f('0x22')](_0x6b8f('0x1f'))),_0x6b8f('0x23')]],'group':_0x6b8f('0x1f'),'where':{'role':{'$or':[_0x6b8f('0x24'),_0x6b8f('0x25'),_0x6b8f('0x26')]}},'raw':!![]})['then'](function(_0x4fb0ec){var _0x1895ce={'user':_0x311ef2['users']||0x0,'telephone':_0x311ef2[_0x6b8f('0x27')]||0x0};_0x4fb0ec[_0x6b8f('0x28')](function(_0x3ac3d6){var _0x26a55d=_0x3ac3d6[_0x6b8f('0x1f')]==='admin'?_0x6b8f('0x25'):_0x3ac3d6['role'];_0x1895ce[_0x26a55d]-=_0x3ac3d6[_0x6b8f('0x23')];if(_0x1895ce[_0x26a55d]<0x0)_0x1895ce[_0x26a55d]=0x0;});_0x372d76(_0x1895ce);return;});})[_0x6b8f('0xd')](function(_0x20f9e6){_0x29e288(_0x20f9e6);});});}function checkUserLimits(_0xe54bc0){return new BPromise(function(_0x4e8564,_0x2d2d00){getLimits()[_0x6b8f('0xc')](function(_0x10a4e3){var _0x5c0d6f=_[_0x6b8f('0x29')](_[_0x6b8f('0x2a')](_0xe54bc0,_0x6b8f('0x1f')),[_0x6b8f('0x24'),'user',_0x6b8f('0x26')]);var _0x493c18=(_0x5c0d6f['admin']||0x0)+(_0x5c0d6f[_0x6b8f('0x25')]||0x0);var _0x8db74=_0x5c0d6f['telephone']||0x0;if(_0x493c18>_0x10a4e3[_0x6b8f('0x25')])return _0x2d2d00(_0x6b8f('0x2b'));if(_0x8db74>_0x10a4e3[_0x6b8f('0x26')])return _0x2d2d00(_0x6b8f('0x2c'));return _0x4e8564();})[_0x6b8f('0xd')](function(_0x14941d){_0x2d2d00(_0x14941d);});});}module[_0x6b8f('0x2d')]={'checkLicense':checkLicense,'checkUserLimits':checkUserLimits,'getLicense':getLicense};