Built motion from commit b517aaa2a6638133380e4d135c64a80893061362. Version 3.0.0...
[motion-next.git] / server / config / license / util.js
1 const a845_0x470c=['split','isEmpty','COUNT','parse','telephone','machineUuid','countBy','2027-01-01T00:00:00.000Z','telephones','deadline','Breaking\x20license','role','moment','demo','col','users','disabled','../../mysqldb','admin','%s:%s:%s','forEach','gray','License\x20limit\x20reached\x20for\x20telephones','data1','user','findOne','catch','then','add','sequelize','grayReason','format','message','getUuid','License','util','findAll','uuid','days','exports','decryptString','license','./hardware','changed','defaults','License\x20limit\x20reached\x20for\x20users','data2','count'];(function(_0x2c1211,_0x470ceb){const _0x23e361=function(_0x210c05){while(--_0x210c05){_0x2c1211['push'](_0x2c1211['shift']());}};_0x23e361(++_0x470ceb);}(a845_0x470c,0xe3));const a845_0x23e3=function(_0x2c1211,_0x470ceb){_0x2c1211=_0x2c1211-0x0;let _0x23e361=a845_0x470c[_0x2c1211];return _0x23e361;};const _0xb7bf86=a845_0x23e3;'use strict';const encryptor=require('../../components/encryptor'),util=require(_0xb7bf86('0x0')),_=require('lodash'),moment=require(_0xb7bf86('0x19')),hardware=require(_0xb7bf86('0x7')),db=require(_0xb7bf86('0x1e'))['db'],{Op}=require(_0xb7bf86('0x2a')),demoLicense={'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':_0xb7bf86('0x14'),'chat':![],'mail':![],'fax':![],'messaging':![],'whatsapp':![],'cm':![],'dialer':![],'jscripty':![],'openchannel':![],'callysquare':0x2,'webrtc':![],'jaws':![],'custom':![],'description':'Demo\x20license','machineUuid':hardware[_0xb7bf86('0x2e')](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]},breakingLicense={'breaking':!![],'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':_0xb7bf86('0x14'),'chat':![],'mail':![],'fax':![],'messaging':![],'whatsapp':![],'cm':![],'dialer':![],'jscripty':![],'openchannel':![],'callysquare':0x2,'webrtc':![],'jaws':![],'custom':![],'update':![],'description':_0xb7bf86('0x17'),'machineUuid':hardware[_0xb7bf86('0x2e')](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};function getLicense(_0x210c05){return new Promise(function(_0x5a94bf,_0x4657c9){const _0x2bcc58=a845_0x23e3;return db[_0x2bcc58('0x2f')][_0x2bcc58('0x26')](_[_0x2bcc58('0x9')](_0x210c05,{'raw':!![],'where':{'id':0x1}}))[_0x2bcc58('0x28')](function(_0x198231){return checkLicense(_0x198231,null);})[_0x2bcc58('0x28')](function(_0x516b6c){_0x5a94bf(_0x516b6c);return;})[_0x2bcc58('0x27')](function(_0xeab34b){_0x4657c9(_0xeab34b);});});}function checkLicense(_0x5147e8,_0x3ef006){const _0x27531b=_0xb7bf86;if(!_0x5147e8)return demoLicense[_0x27531b('0x2')]=_0x5147e8[_0x27531b('0x24')],demoLicense;try{const _0x182ea3=_0x3ef006||_0x5147e8[_0x27531b('0x6')];if(_[_0x27531b('0xe')](_0x182ea3))throw new Error('License\x20key\x20value\x20not\x20found');const _0x4278aa=_0x5147e8[_0x27531b('0x24')],_0x19291d=_0x5147e8[_0x27531b('0xb')],_0x17fad8=_0x4278aa[_0x27531b('0xd')]('-')[0x4],_0x250d6d=_0x4278aa['split']('-')[0x0],_0x2ca5d5=encryptor[_0x27531b('0x5')](_0x182ea3,util[_0x27531b('0x2c')](_0x27531b('0x20'),_0x17fad8,_0x4278aa,_0x250d6d)),_0x55e293=JSON[_0x27531b('0x10')](_0x2ca5d5);_0x55e293[_0x27531b('0x1a')]=![],_0x55e293[_0x27531b('0x2')]=_0x4278aa,_0x55e293['machineUuid']=hardware[_0x27531b('0x2e')]();if(_0x19291d){const _0x96f929=encryptor['decryptString'](_0x19291d);_0x55e293[_0x27531b('0x22')]=_0x96f929,_0x55e293[_0x27531b('0x16')]=moment(_0x96f929)[_0x27531b('0x29')](0x7,_0x27531b('0x3'))[_0x27531b('0x2c')](),_0x55e293[_0x27531b('0x2b')]=_0x55e293[_0x27531b('0x2')]!=_0x55e293[_0x27531b('0x12')]?_0x27531b('0x8'):_0x27531b('0x1d');}return _0x55e293;}catch(_0x27eebb){return breakingLicense[_0x27531b('0x2')]=_0x5147e8[_0x27531b('0x24')],breakingLicense[_0x27531b('0x2d')]=_0x27eebb[_0x27531b('0x2d')],breakingLicense;}}function getLimits(){return new Promise(function(_0x3aa05e,_0x138dd6){const _0x2dcb20=a845_0x23e3;getLicense()['then'](function(_0x215d3a){const _0x509969=a845_0x23e3;return db['User'][_0x509969('0x1')]({'attributes':[_0x509969('0x18'),[db[_0x509969('0x2a')]['fn'](_0x509969('0xf'),db[_0x509969('0x2a')][_0x509969('0x1b')](_0x509969('0x18'))),'count']],'group':_0x509969('0x18'),'where':{'role':{[Op['or']]:[_0x509969('0x1f'),_0x509969('0x25'),_0x509969('0x11')]}},'raw':!![]})[_0x509969('0x28')](function(_0x29c32a){const _0x1f032a=_0x509969,_0x2fdb99={'user':_0x215d3a[_0x1f032a('0x1c')]||0x0,'telephone':_0x215d3a[_0x1f032a('0x15')]||0x0};_0x29c32a[_0x1f032a('0x21')](function(_0xa10984){const _0x3d3cc2=_0x1f032a,_0x80b20=_0xa10984[_0x3d3cc2('0x18')]===_0x3d3cc2('0x1f')?_0x3d3cc2('0x25'):_0xa10984['role'];_0x2fdb99[_0x80b20]-=_0xa10984[_0x3d3cc2('0xc')];if(_0x2fdb99[_0x80b20]<0x0)_0x2fdb99[_0x80b20]=0x0;}),_0x3aa05e(_0x2fdb99);return;});})[_0x2dcb20('0x27')](function(_0x5e36f4){_0x138dd6(_0x5e36f4);});});}function checkUserLimits(_0x7209c5){return new Promise(function(_0x48bce1,_0x331040){const _0x57c71c=a845_0x23e3;getLimits()[_0x57c71c('0x28')](function(_0x1c2aa6){const _0x33bd46=_0x57c71c,_0x1e4e1b=_['pick'](_[_0x33bd46('0x13')](_0x7209c5,_0x33bd46('0x18')),['admin',_0x33bd46('0x25'),'telephone']),_0x27b59e=(_0x1e4e1b[_0x33bd46('0x1f')]||0x0)+(_0x1e4e1b[_0x33bd46('0x25')]||0x0),_0x38c903=_0x1e4e1b['telephone']||0x0;if(_0x27b59e>_0x1c2aa6['user'])return _0x331040(_0x33bd46('0xa'));if(_0x38c903>_0x1c2aa6['telephone'])return _0x331040(_0x33bd46('0x23'));return _0x48bce1();})[_0x57c71c('0x27')](function(_0x9e73a9){_0x331040(_0x9e73a9);});});}module[_0xb7bf86('0x4')]={'checkLicense':checkLicense,'checkUserLimits':checkUserLimits,'getLicense':getLicense};