4081a624042e0e373a3041967bbff75f0a78c3ed
[motion-next.git] / server / config / license / util.js
1 const a845_0x5a12=['User','changed','telephones','user','data1','gray','col','days','getUuid','admin','2027-01-01T00:00:00.000Z','forEach','pick','Breaking\x20license','users','license','data2','findAll','moment','defaults','exports','machineUuid','deadline','findOne','COUNT','License\x20limit\x20reached\x20for\x20users','License','disabled','add','format','grayReason','count','then','decryptString','catch','uuid','License\x20key\x20value\x20not\x20found','sequelize','lodash','message','License\x20limit\x20reached\x20for\x20telephones','role','split','demo','telephone'];(function(_0x6534a8,_0x5a12f9){const _0x1ed70c=function(_0x2105dc){while(--_0x2105dc){_0x6534a8['push'](_0x6534a8['shift']());}};_0x1ed70c(++_0x5a12f9);}(a845_0x5a12,0x9b));const a845_0x1ed7=function(_0x6534a8,_0x5a12f9){_0x6534a8=_0x6534a8-0x0;let _0x1ed70c=a845_0x5a12[_0x6534a8];return _0x1ed70c;};const _0x1a0ed7=a845_0x1ed7;'use strict';const encryptor=require('../../components/encryptor'),util=require('util'),_=require(_0x1a0ed7('0x12')),moment=require(_0x1a0ed7('0x2b')),hardware=require('./hardware'),db=require('../../mysqldb')['db'],{Op}=require('sequelize'),demoLicense={'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':_0x1a0ed7('0x23'),'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':![]},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':_0x1a0ed7('0x26'),'machineUuid':hardware[_0x1a0ed7('0x21')](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};function getLicense(_0x2105dc){return new Promise(function(_0x3deb86,_0xadeabc){const _0x442ef1=a845_0x1ed7;return db[_0x442ef1('0x6')][_0x442ef1('0x3')](_[_0x442ef1('0x2c')](_0x2105dc,{'raw':!![],'where':{'id':0x1}}))['then'](function(_0x4e1c71){return checkLicense(_0x4e1c71,null);})[_0x442ef1('0xc')](function(_0x3b2782){_0x3deb86(_0x3b2782);return;})['catch'](function(_0x3a6910){_0xadeabc(_0x3a6910);});});}function checkLicense(_0x5ab309,_0x2225bd){const _0x1bfb49=_0x1a0ed7;if(!_0x5ab309)return demoLicense['uuid']=_0x5ab309[_0x1bfb49('0x1d')],demoLicense;try{const _0x390aeb=_0x2225bd||_0x5ab309[_0x1bfb49('0x28')];if(_['isEmpty'](_0x390aeb))throw new Error(_0x1bfb49('0x10'));const _0x518ffb=_0x5ab309[_0x1bfb49('0x1d')],_0x5e0fc5=_0x5ab309[_0x1bfb49('0x29')],_0x5a0f41=_0x518ffb['split']('-')[0x4],_0x337154=_0x518ffb[_0x1bfb49('0x16')]('-')[0x0],_0x4c5b4f=encryptor[_0x1bfb49('0xd')](_0x390aeb,util['format']('%s:%s:%s',_0x5a0f41,_0x518ffb,_0x337154)),_0x4fc8e7=JSON['parse'](_0x4c5b4f);_0x4fc8e7[_0x1bfb49('0x17')]=![],_0x4fc8e7[_0x1bfb49('0xf')]=_0x518ffb,_0x4fc8e7[_0x1bfb49('0x1')]=hardware['getUuid']();if(_0x5e0fc5){const _0x3b1dbf=encryptor[_0x1bfb49('0xd')](_0x5e0fc5);_0x4fc8e7[_0x1bfb49('0x1e')]=_0x3b1dbf,_0x4fc8e7[_0x1bfb49('0x2')]=moment(_0x3b1dbf)[_0x1bfb49('0x8')](0x7,_0x1bfb49('0x20'))[_0x1bfb49('0x9')](),_0x4fc8e7[_0x1bfb49('0xa')]=_0x4fc8e7[_0x1bfb49('0xf')]!=_0x4fc8e7[_0x1bfb49('0x1')]?_0x1bfb49('0x1a'):_0x1bfb49('0x7');}return _0x4fc8e7;}catch(_0x2bf63c){return breakingLicense[_0x1bfb49('0xf')]=_0x5ab309['data1'],breakingLicense[_0x1bfb49('0x13')]=_0x2bf63c[_0x1bfb49('0x13')],breakingLicense;}}function getLimits(){return new Promise(function(_0x2c97a9,_0xaec910){getLicense()['then'](function(_0x4ca782){const _0x380d37=a845_0x1ed7;return db[_0x380d37('0x19')][_0x380d37('0x2a')]({'attributes':[_0x380d37('0x15'),[db[_0x380d37('0x11')]['fn'](_0x380d37('0x4'),db[_0x380d37('0x11')][_0x380d37('0x1f')](_0x380d37('0x15'))),'count']],'group':'role','where':{'role':{[Op['or']]:[_0x380d37('0x22'),'user',_0x380d37('0x18')]}},'raw':!![]})['then'](function(_0x5149e8){const _0x22ef54=_0x380d37,_0x2ba41d={'user':_0x4ca782[_0x22ef54('0x27')]||0x0,'telephone':_0x4ca782[_0x22ef54('0x1b')]||0x0};_0x5149e8[_0x22ef54('0x24')](function(_0x34fbe6){const _0x205a99=_0x22ef54,_0x270d6f=_0x34fbe6[_0x205a99('0x15')]===_0x205a99('0x22')?_0x205a99('0x1c'):_0x34fbe6[_0x205a99('0x15')];_0x2ba41d[_0x270d6f]-=_0x34fbe6[_0x205a99('0xb')];if(_0x2ba41d[_0x270d6f]<0x0)_0x2ba41d[_0x270d6f]=0x0;}),_0x2c97a9(_0x2ba41d);return;});})['catch'](function(_0x4f5967){_0xaec910(_0x4f5967);});});}function checkUserLimits(_0x4d6452){return new Promise(function(_0x419075,_0x2ebedf){const _0x27e391=a845_0x1ed7;getLimits()[_0x27e391('0xc')](function(_0x20ff14){const _0xcb225=_0x27e391,_0x4075b7=_[_0xcb225('0x25')](_['countBy'](_0x4d6452,'role'),[_0xcb225('0x22'),_0xcb225('0x1c'),_0xcb225('0x18')]),_0x4641d9=(_0x4075b7[_0xcb225('0x22')]||0x0)+(_0x4075b7[_0xcb225('0x1c')]||0x0),_0x3888f1=_0x4075b7['telephone']||0x0;if(_0x4641d9>_0x20ff14[_0xcb225('0x1c')])return _0x2ebedf(_0xcb225('0x5'));if(_0x3888f1>_0x20ff14[_0xcb225('0x18')])return _0x2ebedf(_0xcb225('0x14'));return _0x419075();})[_0x27e391('0xe')](function(_0x37d5d4){_0x2ebedf(_0x37d5d4);});});}module[_0x1a0ed7('0x0')]={'checkLicense':checkLicense,'checkUserLimits':checkUserLimits,'getLicense':getLicense};