03ba0ae49404adba1f8261f5da792aa9111dc022
[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 _0xa2a0=['message','User','findAll','role','sequelize','COUNT','col','count','admin','user','telephone','users','forEach','countBy','License\x20limit\x20reached\x20for\x20users','License\x20limit\x20reached\x20for\x20telephones','exports','util','lodash','moment','bluebird','./hardware','../../components/encryptor','2027-01-01T00:00:00.000Z','getUuid','Breaking\x20license','License','then','catch','uuid','data1','isEmpty','License\x20key\x20value\x20not\x20found','data2','split','decryptString','format','parse','demo','machineUuid','gray','days','changed','disabled'];(function(_0x5ec454,_0xfcd77e){var _0x5ebf50=function(_0x29de85){while(--_0x29de85){_0x5ec454['push'](_0x5ec454['shift']());}};_0x5ebf50(++_0xfcd77e);}(_0xa2a0,0x95));var _0x0a2a=function(_0x48f1ed,_0x39ae8c){_0x48f1ed=_0x48f1ed-0x0;var _0x1bf2dc=_0xa2a0[_0x48f1ed];return _0x1bf2dc;};'use strict';var util=require(_0x0a2a('0x0'));var _=require(_0x0a2a('0x1'));var moment=require(_0x0a2a('0x2'));var BPromise=require(_0x0a2a('0x3'));var hardware=require(_0x0a2a('0x4'));var encryptor=require(_0x0a2a('0x5'));var db=require('../../mysqldb')['db'];const demoLicense={'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':_0x0a2a('0x6'),'chat':![],'mail':![],'fax':![],'messaging':![],'whatsapp':![],'cm':![],'dialer':![],'jscripty':![],'openchannel':![],'callysquare':0x2,'webrtc':![],'jaws':![],'custom':![],'description':'Demo\x20license','machineUuid':hardware[_0x0a2a('0x7')](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};const breakingLicense={'breaking':!![],'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':_0x0a2a('0x6'),'chat':![],'mail':![],'fax':![],'messaging':![],'whatsapp':![],'cm':![],'dialer':![],'jscripty':![],'openchannel':![],'callysquare':0x2,'webrtc':![],'jaws':![],'custom':![],'update':![],'description':_0x0a2a('0x8'),'machineUuid':hardware['getUuid'](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};function getLicense(_0x115695){return new BPromise(function(_0x5cbd64,_0x25a49a){return db[_0x0a2a('0x9')]['find'](_['defaults'](_0x115695,{'raw':!![],'where':{'id':0x1}}))[_0x0a2a('0xa')](function(_0x279558){return checkLicense(_0x279558,null);})['then'](function(_0xc894c3){_0x5cbd64(_0xc894c3);return;})[_0x0a2a('0xb')](function(_0x40d7f3){_0x25a49a(_0x40d7f3);});});}function checkLicense(_0x56d9a3,_0x483d06){if(!_0x56d9a3){demoLicense[_0x0a2a('0xc')]=_0x56d9a3[_0x0a2a('0xd')];return demoLicense;}try{var _0x416891=_0x483d06||_0x56d9a3['license'];if(_[_0x0a2a('0xe')](_0x416891)){throw new Error(_0x0a2a('0xf'));}var _0x1aa2a5=_0x56d9a3[_0x0a2a('0xd')];var _0x6c65f5=_0x56d9a3[_0x0a2a('0x10')];var _0x51faf7=_0x1aa2a5[_0x0a2a('0x11')]('-')[0x4];var _0x26c74c=_0x1aa2a5[_0x0a2a('0x11')]('-')[0x0];var _0x2af35a=encryptor[_0x0a2a('0x12')](_0x416891,util[_0x0a2a('0x13')]('%s:%s:%s',_0x51faf7,_0x1aa2a5,_0x26c74c));var _0x32d624=JSON[_0x0a2a('0x14')](_0x2af35a);_0x32d624[_0x0a2a('0x15')]=![];_0x32d624[_0x0a2a('0xc')]=_0x1aa2a5;_0x32d624[_0x0a2a('0x16')]=hardware[_0x0a2a('0x7')]();if(_0x6c65f5){var _0x41ffea=encryptor[_0x0a2a('0x12')](_0x6c65f5);_0x32d624[_0x0a2a('0x17')]=_0x41ffea;_0x32d624['deadline']=moment(_0x41ffea)['add'](0x7,_0x0a2a('0x18'))['format']();_0x32d624['grayReason']=_0x32d624['uuid']!=_0x32d624[_0x0a2a('0x16')]?_0x0a2a('0x19'):_0x0a2a('0x1a');}return _0x32d624;}catch(_0x3df0f8){breakingLicense[_0x0a2a('0xc')]=_0x56d9a3[_0x0a2a('0xd')];breakingLicense[_0x0a2a('0x1b')]=_0x3df0f8[_0x0a2a('0x1b')];return breakingLicense;}}function getLimits(){return new BPromise(function(_0xb3605,_0x579a02){getLicense()[_0x0a2a('0xa')](function(_0x216012){return db[_0x0a2a('0x1c')][_0x0a2a('0x1d')]({'attributes':[_0x0a2a('0x1e'),[db[_0x0a2a('0x1f')]['fn'](_0x0a2a('0x20'),db[_0x0a2a('0x1f')][_0x0a2a('0x21')](_0x0a2a('0x1e'))),_0x0a2a('0x22')]],'group':_0x0a2a('0x1e'),'where':{'role':{'$or':[_0x0a2a('0x23'),_0x0a2a('0x24'),_0x0a2a('0x25')]}},'raw':!![]})[_0x0a2a('0xa')](function(_0x330c7f){var _0x93a828={'user':_0x216012[_0x0a2a('0x26')]||0x0,'telephone':_0x216012['telephones']||0x0};_0x330c7f[_0x0a2a('0x27')](function(_0x1d1584){var _0x37ec8c=_0x1d1584[_0x0a2a('0x1e')]==='admin'?_0x0a2a('0x24'):_0x1d1584[_0x0a2a('0x1e')];_0x93a828[_0x37ec8c]-=_0x1d1584[_0x0a2a('0x22')];if(_0x93a828[_0x37ec8c]<0x0)_0x93a828[_0x37ec8c]=0x0;});_0xb3605(_0x93a828);return;});})['catch'](function(_0x5d6646){_0x579a02(_0x5d6646);});});}function checkUserLimits(_0x5b0c06){return new BPromise(function(_0x34ea7c,_0x5df5dd){getLimits()[_0x0a2a('0xa')](function(_0x1468a1){var _0x55eebd=_['pick'](_[_0x0a2a('0x28')](_0x5b0c06,_0x0a2a('0x1e')),[_0x0a2a('0x23'),_0x0a2a('0x24'),'telephone']);var _0x3cbe43=(_0x55eebd['admin']||0x0)+(_0x55eebd[_0x0a2a('0x24')]||0x0);var _0x2765f9=_0x55eebd['telephone']||0x0;if(_0x3cbe43>_0x1468a1['user'])return _0x5df5dd(_0x0a2a('0x29'));if(_0x2765f9>_0x1468a1[_0x0a2a('0x25')])return _0x5df5dd(_0x0a2a('0x2a'));return _0x34ea7c();})[_0x0a2a('0xb')](function(_0x444f63){_0x5df5dd(_0x444f63);});});}module[_0x0a2a('0x2b')]={'checkLicense':checkLicense,'checkUserLimits':checkUserLimits,'getLicense':getLicense};