Built motion from commit 1ea47bf4.|2.6.34
[motion2.git] / server / config / license / util.js
index 9367306..6a7107e 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xc4e3=['./hardware','../../components/encryptor','../../mysqldb','2027-01-01T00:00:00.000Z','Demo\x20license','Breaking\x20license','getUuid','License','find','defaults','then','catch','uuid','data1','license','isEmpty','split','decryptString','format','%s:%s:%s','parse','machineUuid','gray','add','grayReason','changed','disabled','message','findAll','role','sequelize','COUNT','col','admin','telephone','users','telephones','forEach','user','count','pick','countBy','License\x20limit\x20reached\x20for\x20users','License\x20limit\x20reached\x20for\x20telephones','exports','lodash','moment','bluebird'];(function(_0x1bbf9e,_0x2efe4b){var _0x3741eb=function(_0x5a8bf0){while(--_0x5a8bf0){_0x1bbf9e['push'](_0x1bbf9e['shift']());}};_0x3741eb(++_0x2efe4b);}(_0xc4e3,0x1dd));var _0x3c4e=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0xc4e3[_0x3dd15e];return _0x231fd0;};'use strict';var util=require('util');var _=require(_0x3c4e('0x0'));var moment=require(_0x3c4e('0x1'));var BPromise=require(_0x3c4e('0x2'));var hardware=require(_0x3c4e('0x3'));var encryptor=require(_0x3c4e('0x4'));var db=require(_0x3c4e('0x5'))['db'];const demoLicense={'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':_0x3c4e('0x6'),'chat':![],'mail':![],'fax':![],'messaging':![],'whatsapp':![],'cm':![],'dialer':![],'jscripty':![],'openchannel':![],'callysquare':0x2,'webrtc':![],'jaws':![],'custom':![],'description':_0x3c4e('0x7'),'machineUuid':hardware['getUuid'](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};const breakingLicense={'breaking':!![],'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':_0x3c4e('0x6'),'chat':![],'mail':![],'fax':![],'messaging':![],'whatsapp':![],'cm':![],'dialer':![],'jscripty':![],'openchannel':![],'callysquare':0x2,'webrtc':![],'jaws':![],'custom':![],'update':![],'description':_0x3c4e('0x8'),'machineUuid':hardware[_0x3c4e('0x9')](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};function getLicense(_0xc32a25){return new BPromise(function(_0x971fd8,_0x3ffdcb){return db[_0x3c4e('0xa')][_0x3c4e('0xb')](_[_0x3c4e('0xc')](_0xc32a25,{'raw':!![],'where':{'id':0x1}}))[_0x3c4e('0xd')](function(_0x17bf7f){return checkLicense(_0x17bf7f,null);})['then'](function(_0xf45df7){_0x971fd8(_0xf45df7);return;})[_0x3c4e('0xe')](function(_0x496185){_0x3ffdcb(_0x496185);});});}function checkLicense(_0x4aa416,_0x2c92a7){if(!_0x4aa416){demoLicense[_0x3c4e('0xf')]=_0x4aa416[_0x3c4e('0x10')];return demoLicense;}try{var _0x231691=_0x2c92a7||_0x4aa416[_0x3c4e('0x11')];if(_[_0x3c4e('0x12')](_0x231691)){throw new Error('License\x20key\x20value\x20not\x20found');}var _0x2d4940=_0x4aa416[_0x3c4e('0x10')];var _0x41bf8d=_0x4aa416['data2'];var _0x15d132=_0x2d4940[_0x3c4e('0x13')]('-')[0x4];var _0x4b9152=_0x2d4940[_0x3c4e('0x13')]('-')[0x0];var _0x1bb8a6=encryptor[_0x3c4e('0x14')](_0x231691,util[_0x3c4e('0x15')](_0x3c4e('0x16'),_0x15d132,_0x2d4940,_0x4b9152));var _0x1ee6c=JSON[_0x3c4e('0x17')](_0x1bb8a6);_0x1ee6c['demo']=![];_0x1ee6c[_0x3c4e('0xf')]=_0x2d4940;_0x1ee6c[_0x3c4e('0x18')]=hardware['getUuid']();if(_0x41bf8d){var _0x3d2ea8=encryptor[_0x3c4e('0x14')](_0x41bf8d);_0x1ee6c[_0x3c4e('0x19')]=_0x3d2ea8;_0x1ee6c['deadline']=moment(_0x3d2ea8)[_0x3c4e('0x1a')](0x7,'days')[_0x3c4e('0x15')]();_0x1ee6c[_0x3c4e('0x1b')]=_0x1ee6c['uuid']!=_0x1ee6c[_0x3c4e('0x18')]?_0x3c4e('0x1c'):_0x3c4e('0x1d');}return _0x1ee6c;}catch(_0x296c7c){breakingLicense[_0x3c4e('0xf')]=_0x4aa416['data1'];breakingLicense[_0x3c4e('0x1e')]=_0x296c7c[_0x3c4e('0x1e')];return breakingLicense;}}function getLimits(){return new BPromise(function(_0x4a3218,_0x418993){getLicense()[_0x3c4e('0xd')](function(_0x183b01){return db['User'][_0x3c4e('0x1f')]({'attributes':[_0x3c4e('0x20'),[db[_0x3c4e('0x21')]['fn'](_0x3c4e('0x22'),db['sequelize'][_0x3c4e('0x23')](_0x3c4e('0x20'))),'count']],'group':'role','where':{'role':{'$or':[_0x3c4e('0x24'),'user',_0x3c4e('0x25')]}},'raw':!![]})['then'](function(_0x382914){var _0x82c3a1={'user':_0x183b01[_0x3c4e('0x26')]||0x0,'telephone':_0x183b01[_0x3c4e('0x27')]||0x0};_0x382914[_0x3c4e('0x28')](function(_0x49e48b){var _0x2c5743=_0x49e48b[_0x3c4e('0x20')]===_0x3c4e('0x24')?_0x3c4e('0x29'):_0x49e48b[_0x3c4e('0x20')];_0x82c3a1[_0x2c5743]-=_0x49e48b[_0x3c4e('0x2a')];if(_0x82c3a1[_0x2c5743]<0x0)_0x82c3a1[_0x2c5743]=0x0;});_0x4a3218(_0x82c3a1);return;});})[_0x3c4e('0xe')](function(_0x149295){_0x418993(_0x149295);});});}function checkUserLimits(_0x162eea){return new BPromise(function(_0x24c8f7,_0x3351d1){getLimits()['then'](function(_0x21038c){var _0x4e3eb4=_[_0x3c4e('0x2b')](_[_0x3c4e('0x2c')](_0x162eea,_0x3c4e('0x20')),['admin',_0x3c4e('0x29'),_0x3c4e('0x25')]);var _0x165e73=(_0x4e3eb4['admin']||0x0)+(_0x4e3eb4[_0x3c4e('0x29')]||0x0);var _0x78486=_0x4e3eb4[_0x3c4e('0x25')]||0x0;if(_0x165e73>_0x21038c[_0x3c4e('0x29')])return _0x3351d1(_0x3c4e('0x2d'));if(_0x78486>_0x21038c[_0x3c4e('0x25')])return _0x3351d1(_0x3c4e('0x2e'));return _0x24c8f7();})['catch'](function(_0x317200){_0x3351d1(_0x317200);});});}module[_0x3c4e('0x2f')]={'checkLicense':checkLicense,'checkUserLimits':checkUserLimits,'getLicense':getLicense};
\ No newline at end of file
+var _0x8a61=['telephone','pick','countBy','License\x20limit\x20reached\x20for\x20users','exports','util','lodash','moment','bluebird','../../components/encryptor','../../mysqldb','2027-01-01T00:00:00.000Z','Demo\x20license','getUuid','Breaking\x20license','License','find','defaults','then','catch','uuid','data1','License\x20key\x20value\x20not\x20found','data2','split','%s:%s:%s','parse','demo','machineUuid','decryptString','gray','deadline','days','format','changed','disabled','message','User','findAll','sequelize','COUNT','role','count','admin','user'];(function(_0x3dae0d,_0x3ecfdb){var _0x1e7d06=function(_0x4312b2){while(--_0x4312b2){_0x3dae0d['push'](_0x3dae0d['shift']());}};_0x1e7d06(++_0x3ecfdb);}(_0x8a61,0x1f4));var _0x18a6=function(_0x212e7a,_0x32e0d){_0x212e7a=_0x212e7a-0x0;var _0x445799=_0x8a61[_0x212e7a];return _0x445799;};'use strict';var util=require(_0x18a6('0x0'));var _=require(_0x18a6('0x1'));var moment=require(_0x18a6('0x2'));var BPromise=require(_0x18a6('0x3'));var hardware=require('./hardware');var encryptor=require(_0x18a6('0x4'));var db=require(_0x18a6('0x5'))['db'];const demoLicense={'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':_0x18a6('0x6'),'chat':![],'mail':![],'fax':![],'messaging':![],'whatsapp':![],'cm':![],'dialer':![],'jscripty':![],'openchannel':![],'callysquare':0x2,'webrtc':![],'jaws':![],'custom':![],'description':_0x18a6('0x7'),'machineUuid':hardware[_0x18a6('0x8')](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};const breakingLicense={'breaking':!![],'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':_0x18a6('0x6'),'chat':![],'mail':![],'fax':![],'messaging':![],'whatsapp':![],'cm':![],'dialer':![],'jscripty':![],'openchannel':![],'callysquare':0x2,'webrtc':![],'jaws':![],'custom':![],'update':![],'description':_0x18a6('0x9'),'machineUuid':hardware[_0x18a6('0x8')](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};function getLicense(_0x528e5a){return new BPromise(function(_0x523824,_0x3d8213){return db[_0x18a6('0xa')][_0x18a6('0xb')](_[_0x18a6('0xc')](_0x528e5a,{'raw':!![],'where':{'id':0x1}}))['then'](function(_0x222300){return checkLicense(_0x222300,null);})[_0x18a6('0xd')](function(_0x5a7e2a){_0x523824(_0x5a7e2a);return;})[_0x18a6('0xe')](function(_0x8a13bd){_0x3d8213(_0x8a13bd);});});}function checkLicense(_0x5eb7ed,_0x184b5e){if(!_0x5eb7ed){demoLicense[_0x18a6('0xf')]=_0x5eb7ed[_0x18a6('0x10')];return demoLicense;}try{var _0x521f14=_0x184b5e||_0x5eb7ed['license'];if(_['isEmpty'](_0x521f14)){throw new Error(_0x18a6('0x11'));}var _0x14e7e1=_0x5eb7ed[_0x18a6('0x10')];var _0x48528d=_0x5eb7ed[_0x18a6('0x12')];var _0x566f82=_0x14e7e1[_0x18a6('0x13')]('-')[0x4];var _0x597a8a=_0x14e7e1['split']('-')[0x0];var _0x1638fe=encryptor['decryptString'](_0x521f14,util['format'](_0x18a6('0x14'),_0x566f82,_0x14e7e1,_0x597a8a));var _0x533b5a=JSON[_0x18a6('0x15')](_0x1638fe);_0x533b5a[_0x18a6('0x16')]=![];_0x533b5a[_0x18a6('0xf')]=_0x14e7e1;_0x533b5a[_0x18a6('0x17')]=hardware['getUuid']();if(_0x48528d){var _0x29482a=encryptor[_0x18a6('0x18')](_0x48528d);_0x533b5a[_0x18a6('0x19')]=_0x29482a;_0x533b5a[_0x18a6('0x1a')]=moment(_0x29482a)['add'](0x7,_0x18a6('0x1b'))[_0x18a6('0x1c')]();_0x533b5a['grayReason']=_0x533b5a['uuid']!=_0x533b5a[_0x18a6('0x17')]?_0x18a6('0x1d'):_0x18a6('0x1e');}return _0x533b5a;}catch(_0x27a7a6){breakingLicense[_0x18a6('0xf')]=_0x5eb7ed['data1'];breakingLicense[_0x18a6('0x1f')]=_0x27a7a6[_0x18a6('0x1f')];return breakingLicense;}}function getLimits(){return new BPromise(function(_0x303ef5,_0x585487){getLicense()[_0x18a6('0xd')](function(_0x1f4d03){return db[_0x18a6('0x20')][_0x18a6('0x21')]({'attributes':['role',[db[_0x18a6('0x22')]['fn'](_0x18a6('0x23'),db[_0x18a6('0x22')]['col'](_0x18a6('0x24'))),_0x18a6('0x25')]],'group':_0x18a6('0x24'),'where':{'role':{'$or':[_0x18a6('0x26'),_0x18a6('0x27'),_0x18a6('0x28')]}},'raw':!![]})[_0x18a6('0xd')](function(_0x1129fd){var _0x45ac50={'user':_0x1f4d03['users']||0x0,'telephone':_0x1f4d03['telephones']||0x0};_0x1129fd['forEach'](function(_0x1c64b7){var _0x180ada=_0x1c64b7[_0x18a6('0x24')]===_0x18a6('0x26')?_0x18a6('0x27'):_0x1c64b7[_0x18a6('0x24')];_0x45ac50[_0x180ada]-=_0x1c64b7[_0x18a6('0x25')];if(_0x45ac50[_0x180ada]<0x0)_0x45ac50[_0x180ada]=0x0;});_0x303ef5(_0x45ac50);return;});})[_0x18a6('0xe')](function(_0x12d275){_0x585487(_0x12d275);});});}function checkUserLimits(_0x5d2038){return new BPromise(function(_0x4cc22d,_0xe38499){getLimits()['then'](function(_0x46d7ae){var _0x3d22fc=_[_0x18a6('0x29')](_[_0x18a6('0x2a')](_0x5d2038,_0x18a6('0x24')),[_0x18a6('0x26'),_0x18a6('0x27'),'telephone']);var _0x3e57e1=(_0x3d22fc[_0x18a6('0x26')]||0x0)+(_0x3d22fc[_0x18a6('0x27')]||0x0);var _0x2e9dfd=_0x3d22fc[_0x18a6('0x28')]||0x0;if(_0x3e57e1>_0x46d7ae[_0x18a6('0x27')])return _0xe38499(_0x18a6('0x2b'));if(_0x2e9dfd>_0x46d7ae['telephone'])return _0xe38499('License\x20limit\x20reached\x20for\x20telephones');return _0x4cc22d();})[_0x18a6('0xe')](function(_0x651bfc){_0xe38499(_0x651bfc);});});}module[_0x18a6('0x2c')]={'checkLicense':checkLicense,'checkUserLimits':checkUserLimits,'getLicense':getLicense};
\ No newline at end of file