Built motion from commit 6362bb75.|2.6.13
[motion2.git] / server / config / license / util.js
index a014a73..d72b7e7 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x95a8=['pick','countBy','License\x20limit\x20reached\x20for\x20telephones','exports','util','lodash','moment','bluebird','../../components/encryptor','../../mysqldb','2027-01-01T00:00:00.000Z','Demo\x20license','getUuid','License','find','then','catch','uuid','data1','license','License\x20key\x20value\x20not\x20found','data2','split','decryptString','%s:%s:%s','parse','demo','gray','deadline','add','days','format','grayReason','machineUuid','message','User','role','sequelize','COUNT','col','admin','telephone','telephones','forEach','user'];(function(_0x54e1ad,_0x410c73){var _0x466a43=function(_0x2d7f13){while(--_0x2d7f13){_0x54e1ad['push'](_0x54e1ad['shift']());}};_0x466a43(++_0x410c73);}(_0x95a8,0x8b));var _0x895a=function(_0x8b1642,_0x438b4c){_0x8b1642=_0x8b1642-0x0;var _0x163e28=_0x95a8[_0x8b1642];return _0x163e28;};'use strict';var util=require(_0x895a('0x0'));var _=require(_0x895a('0x1'));var moment=require(_0x895a('0x2'));var BPromise=require(_0x895a('0x3'));var hardware=require('./hardware');var encryptor=require(_0x895a('0x4'));var db=require(_0x895a('0x5'))['db'];const demoLicense={'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':_0x895a('0x6'),'chat':![],'mail':![],'fax':![],'messaging':![],'whatsapp':![],'cm':![],'dialer':![],'jscripty':![],'openchannel':![],'callysquare':0x2,'webrtc':![],'jaws':![],'custom':![],'description':_0x895a('0x7'),'machineUuid':hardware['getUuid'](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};const breakingLicense={'breaking':!![],'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':_0x895a('0x6'),'chat':![],'mail':![],'fax':![],'messaging':![],'whatsapp':![],'cm':![],'dialer':![],'jscripty':![],'openchannel':![],'callysquare':0x2,'webrtc':![],'jaws':![],'custom':![],'update':![],'description':'Breaking\x20license','machineUuid':hardware[_0x895a('0x8')](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};function getLicense(_0x2b333c){return new BPromise(function(_0x13a274,_0x1aede9){return db[_0x895a('0x9')][_0x895a('0xa')](_['defaults'](_0x2b333c,{'raw':!![],'where':{'id':0x1}}))[_0x895a('0xb')](function(_0x14d676){return checkLicense(_0x14d676,null);})[_0x895a('0xb')](function(_0xa97853){_0x13a274(_0xa97853);return;})[_0x895a('0xc')](function(_0xdc14c6){_0x1aede9(_0xdc14c6);});});}function checkLicense(_0x4879e5,_0x3ed55a){if(!_0x4879e5){demoLicense[_0x895a('0xd')]=_0x4879e5[_0x895a('0xe')];return demoLicense;}try{var _0x10396a=_0x3ed55a||_0x4879e5[_0x895a('0xf')];if(_['isEmpty'](_0x10396a)){throw new Error(_0x895a('0x10'));}var _0x5d25b2=_0x4879e5[_0x895a('0xe')];var _0x159025=_0x4879e5[_0x895a('0x11')];var _0x59e53b=_0x5d25b2[_0x895a('0x12')]('-')[0x4];var _0x2c1ba7=_0x5d25b2[_0x895a('0x12')]('-')[0x0];var _0x25e1cc=encryptor[_0x895a('0x13')](_0x10396a,util['format'](_0x895a('0x14'),_0x59e53b,_0x5d25b2,_0x2c1ba7));var _0x4ee7f0=JSON[_0x895a('0x15')](_0x25e1cc);_0x4ee7f0[_0x895a('0x16')]=![];_0x4ee7f0[_0x895a('0xd')]=_0x5d25b2;_0x4ee7f0['machineUuid']=hardware['getUuid']();if(_0x159025){var _0x3d2cc8=encryptor[_0x895a('0x13')](_0x159025);_0x4ee7f0[_0x895a('0x17')]=_0x3d2cc8;_0x4ee7f0[_0x895a('0x18')]=moment(_0x3d2cc8)[_0x895a('0x19')](0x7,_0x895a('0x1a'))[_0x895a('0x1b')]();_0x4ee7f0[_0x895a('0x1c')]=_0x4ee7f0['uuid']!=_0x4ee7f0[_0x895a('0x1d')]?'changed':'disabled';}return _0x4ee7f0;}catch(_0x3fc481){breakingLicense[_0x895a('0xd')]=_0x4879e5[_0x895a('0xe')];breakingLicense[_0x895a('0x1e')]=_0x3fc481[_0x895a('0x1e')];return breakingLicense;}}function getLimits(){return new BPromise(function(_0x84cfde,_0x55e436){getLicense()[_0x895a('0xb')](function(_0x20e455){return db[_0x895a('0x1f')]['findAll']({'attributes':[_0x895a('0x20'),[db[_0x895a('0x21')]['fn'](_0x895a('0x22'),db['sequelize'][_0x895a('0x23')](_0x895a('0x20'))),'count']],'group':'role','where':{'role':{'$or':[_0x895a('0x24'),'user',_0x895a('0x25')]}},'raw':!![]})[_0x895a('0xb')](function(_0x149961){var _0x65a803={'user':_0x20e455['users']||0x0,'telephone':_0x20e455[_0x895a('0x26')]||0x0};_0x149961[_0x895a('0x27')](function(_0x62b529){var _0x3416e2=_0x62b529[_0x895a('0x20')]===_0x895a('0x24')?_0x895a('0x28'):_0x62b529[_0x895a('0x20')];_0x65a803[_0x3416e2]-=_0x62b529['count'];if(_0x65a803[_0x3416e2]<0x0)_0x65a803[_0x3416e2]=0x0;});_0x84cfde(_0x65a803);return;});})[_0x895a('0xc')](function(_0x171406){_0x55e436(_0x171406);});});}function checkUserLimits(_0x56d7ff){return new BPromise(function(_0x1b9b42,_0x2571c3){getLimits()['then'](function(_0x39b517){var _0x329d63=_[_0x895a('0x29')](_[_0x895a('0x2a')](_0x56d7ff,_0x895a('0x20')),[_0x895a('0x24'),_0x895a('0x28'),_0x895a('0x25')]);var _0x30692d=(_0x329d63[_0x895a('0x24')]||0x0)+(_0x329d63[_0x895a('0x28')]||0x0);var _0xfb26f1=_0x329d63['telephone']||0x0;if(_0x30692d>_0x39b517['user'])return _0x2571c3('License\x20limit\x20reached\x20for\x20users');if(_0xfb26f1>_0x39b517[_0x895a('0x25')])return _0x2571c3(_0x895a('0x2b'));return _0x1b9b42();})[_0x895a('0xc')](function(_0xe9408b){_0x2571c3(_0xe9408b);});});}module[_0x895a('0x2c')]={'checkLicense':checkLicense,'checkUserLimits':checkUserLimits,'getLicense':getLicense};
\ No newline at end of file
+var _0xf2bb=['users','telephones','forEach','pick','countBy','telephone','License\x20limit\x20reached\x20for\x20users','exports','lodash','moment','bluebird','./hardware','../../components/encryptor','2027-01-01T00:00:00.000Z','Demo\x20license','getUuid','Breaking\x20license','License','find','defaults','then','uuid','data1','license','License\x20key\x20value\x20not\x20found','data2','%s:%s:%s','parse','demo','machineUuid','decryptString','gray','deadline','add','changed','disabled','message','findAll','sequelize','COUNT','col','role','count','admin','user'];(function(_0xf98100,_0xf2ff2c){var _0x2c9018=function(_0x1dcb42){while(--_0x1dcb42){_0xf98100['push'](_0xf98100['shift']());}};_0x2c9018(++_0xf2ff2c);}(_0xf2bb,0x1ca));var _0xbf2b=function(_0x1928c9,_0x13a6d1){_0x1928c9=_0x1928c9-0x0;var _0x51b5fb=_0xf2bb[_0x1928c9];return _0x51b5fb;};'use strict';var util=require('util');var _=require(_0xbf2b('0x0'));var moment=require(_0xbf2b('0x1'));var BPromise=require(_0xbf2b('0x2'));var hardware=require(_0xbf2b('0x3'));var encryptor=require(_0xbf2b('0x4'));var db=require('../../mysqldb')['db'];const demoLicense={'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':_0xbf2b('0x5'),'chat':![],'mail':![],'fax':![],'messaging':![],'whatsapp':![],'cm':![],'dialer':![],'jscripty':![],'openchannel':![],'callysquare':0x2,'webrtc':![],'jaws':![],'custom':![],'description':_0xbf2b('0x6'),'machineUuid':hardware[_0xbf2b('0x7')](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};const breakingLicense={'breaking':!![],'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':_0xbf2b('0x5'),'chat':![],'mail':![],'fax':![],'messaging':![],'whatsapp':![],'cm':![],'dialer':![],'jscripty':![],'openchannel':![],'callysquare':0x2,'webrtc':![],'jaws':![],'custom':![],'update':![],'description':_0xbf2b('0x8'),'machineUuid':hardware[_0xbf2b('0x7')](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};function getLicense(_0x2022ce){return new BPromise(function(_0x32a395,_0xd63284){return db[_0xbf2b('0x9')][_0xbf2b('0xa')](_[_0xbf2b('0xb')](_0x2022ce,{'raw':!![],'where':{'id':0x1}}))['then'](function(_0x4c0c44){return checkLicense(_0x4c0c44,null);})[_0xbf2b('0xc')](function(_0x159fe6){_0x32a395(_0x159fe6);return;})['catch'](function(_0x5048d5){_0xd63284(_0x5048d5);});});}function checkLicense(_0x931521,_0x5aa4f3){if(!_0x931521){demoLicense[_0xbf2b('0xd')]=_0x931521[_0xbf2b('0xe')];return demoLicense;}try{var _0x104bf1=_0x5aa4f3||_0x931521[_0xbf2b('0xf')];if(_['isEmpty'](_0x104bf1)){throw new Error(_0xbf2b('0x10'));}var _0x50740a=_0x931521['data1'];var _0x2b8338=_0x931521[_0xbf2b('0x11')];var _0x1702b5=_0x50740a['split']('-')[0x4];var _0x135ce0=_0x50740a['split']('-')[0x0];var _0x25d4aa=encryptor['decryptString'](_0x104bf1,util['format'](_0xbf2b('0x12'),_0x1702b5,_0x50740a,_0x135ce0));var _0x14d250=JSON[_0xbf2b('0x13')](_0x25d4aa);_0x14d250[_0xbf2b('0x14')]=![];_0x14d250[_0xbf2b('0xd')]=_0x50740a;_0x14d250[_0xbf2b('0x15')]=hardware[_0xbf2b('0x7')]();if(_0x2b8338){var _0x3ede39=encryptor[_0xbf2b('0x16')](_0x2b8338);_0x14d250[_0xbf2b('0x17')]=_0x3ede39;_0x14d250[_0xbf2b('0x18')]=moment(_0x3ede39)[_0xbf2b('0x19')](0x7,'days')['format']();_0x14d250['grayReason']=_0x14d250[_0xbf2b('0xd')]!=_0x14d250['machineUuid']?_0xbf2b('0x1a'):_0xbf2b('0x1b');}return _0x14d250;}catch(_0x54f095){breakingLicense[_0xbf2b('0xd')]=_0x931521[_0xbf2b('0xe')];breakingLicense[_0xbf2b('0x1c')]=_0x54f095[_0xbf2b('0x1c')];return breakingLicense;}}function getLimits(){return new BPromise(function(_0x228ac6,_0x9c7b45){getLicense()[_0xbf2b('0xc')](function(_0x92f64d){return db['User'][_0xbf2b('0x1d')]({'attributes':['role',[db[_0xbf2b('0x1e')]['fn'](_0xbf2b('0x1f'),db['sequelize'][_0xbf2b('0x20')](_0xbf2b('0x21'))),_0xbf2b('0x22')]],'group':_0xbf2b('0x21'),'where':{'role':{'$or':[_0xbf2b('0x23'),_0xbf2b('0x24'),'telephone']}},'raw':!![]})[_0xbf2b('0xc')](function(_0x590752){var _0x2e7823={'user':_0x92f64d[_0xbf2b('0x25')]||0x0,'telephone':_0x92f64d[_0xbf2b('0x26')]||0x0};_0x590752[_0xbf2b('0x27')](function(_0x3394d8){var _0x101a5e=_0x3394d8[_0xbf2b('0x21')]===_0xbf2b('0x23')?_0xbf2b('0x24'):_0x3394d8['role'];_0x2e7823[_0x101a5e]-=_0x3394d8['count'];if(_0x2e7823[_0x101a5e]<0x0)_0x2e7823[_0x101a5e]=0x0;});_0x228ac6(_0x2e7823);return;});})['catch'](function(_0xd5ef65){_0x9c7b45(_0xd5ef65);});});}function checkUserLimits(_0xb13ea2){return new BPromise(function(_0x1cab67,_0x4695d4){getLimits()['then'](function(_0x5a59ea){var _0x55a872=_[_0xbf2b('0x28')](_[_0xbf2b('0x29')](_0xb13ea2,_0xbf2b('0x21')),['admin',_0xbf2b('0x24'),_0xbf2b('0x2a')]);var _0x2d900b=(_0x55a872['admin']||0x0)+(_0x55a872[_0xbf2b('0x24')]||0x0);var _0x426807=_0x55a872[_0xbf2b('0x2a')]||0x0;if(_0x2d900b>_0x5a59ea[_0xbf2b('0x24')])return _0x4695d4(_0xbf2b('0x2b'));if(_0x426807>_0x5a59ea['telephone'])return _0x4695d4('License\x20limit\x20reached\x20for\x20telephones');return _0x1cab67();})['catch'](function(_0x1724e8){_0x4695d4(_0x1724e8);});});}module[_0xbf2b('0x2c')]={'checkLicense':checkLicense,'checkUserLimits':checkUserLimits,'getLicense':getLicense};
\ No newline at end of file