Built motion from commit b7e79837.|2.6.29
[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 _0x2184=['isEmpty','License\x20key\x20value\x20not\x20found','data2','split','format','%s:%s:%s','parse','demo','gray','deadline','grayReason','changed','disabled','message','User','findAll','role','sequelize','COUNT','col','count','admin','users','forEach','user','telephone','License\x20limit\x20reached\x20for\x20users','License\x20limit\x20reached\x20for\x20telephones','exports','util','moment','bluebird','./hardware','../../components/encryptor','../../mysqldb','2027-01-01T00:00:00.000Z','Demo\x20license','getUuid','Breaking\x20license','License','find','defaults','then','catch','uuid','data1','license'];(function(_0x33381e,_0x2545aa){var _0x82b8d7=function(_0x32c975){while(--_0x32c975){_0x33381e['push'](_0x33381e['shift']());}};_0x82b8d7(++_0x2545aa);}(_0x2184,0xaa));var _0x4218=function(_0x5e7209,_0x171c09){_0x5e7209=_0x5e7209-0x0;var _0x252d03=_0x2184[_0x5e7209];return _0x252d03;};'use strict';var util=require(_0x4218('0x0'));var _=require('lodash');var moment=require(_0x4218('0x1'));var BPromise=require(_0x4218('0x2'));var hardware=require(_0x4218('0x3'));var encryptor=require(_0x4218('0x4'));var db=require(_0x4218('0x5'))['db'];const demoLicense={'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':_0x4218('0x6'),'chat':![],'mail':![],'fax':![],'messaging':![],'whatsapp':![],'cm':![],'dialer':![],'jscripty':![],'openchannel':![],'callysquare':0x2,'webrtc':![],'jaws':![],'custom':![],'description':_0x4218('0x7'),'machineUuid':hardware[_0x4218('0x8')](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};const breakingLicense={'breaking':!![],'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':_0x4218('0x6'),'chat':![],'mail':![],'fax':![],'messaging':![],'whatsapp':![],'cm':![],'dialer':![],'jscripty':![],'openchannel':![],'callysquare':0x2,'webrtc':![],'jaws':![],'custom':![],'update':![],'description':_0x4218('0x9'),'machineUuid':hardware[_0x4218('0x8')](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};function getLicense(_0x2f2054){return new BPromise(function(_0x1845dc,_0x123c7a){return db[_0x4218('0xa')][_0x4218('0xb')](_[_0x4218('0xc')](_0x2f2054,{'raw':!![],'where':{'id':0x1}}))[_0x4218('0xd')](function(_0x3805a2){return checkLicense(_0x3805a2,null);})['then'](function(_0x4c5703){_0x1845dc(_0x4c5703);return;})[_0x4218('0xe')](function(_0x2f1dfa){_0x123c7a(_0x2f1dfa);});});}function checkLicense(_0x25d5d1,_0xa06597){if(!_0x25d5d1){demoLicense[_0x4218('0xf')]=_0x25d5d1[_0x4218('0x10')];return demoLicense;}try{var _0x31b389=_0xa06597||_0x25d5d1[_0x4218('0x11')];if(_[_0x4218('0x12')](_0x31b389)){throw new Error(_0x4218('0x13'));}var _0x3a05c6=_0x25d5d1['data1'];var _0x38a2ad=_0x25d5d1[_0x4218('0x14')];var _0x17d442=_0x3a05c6[_0x4218('0x15')]('-')[0x4];var _0x1fb9a9=_0x3a05c6[_0x4218('0x15')]('-')[0x0];var _0x242f3d=encryptor['decryptString'](_0x31b389,util[_0x4218('0x16')](_0x4218('0x17'),_0x17d442,_0x3a05c6,_0x1fb9a9));var _0x40a1ee=JSON[_0x4218('0x18')](_0x242f3d);_0x40a1ee[_0x4218('0x19')]=![];_0x40a1ee[_0x4218('0xf')]=_0x3a05c6;_0x40a1ee['machineUuid']=hardware[_0x4218('0x8')]();if(_0x38a2ad){var _0x1b0ad2=encryptor['decryptString'](_0x38a2ad);_0x40a1ee[_0x4218('0x1a')]=_0x1b0ad2;_0x40a1ee[_0x4218('0x1b')]=moment(_0x1b0ad2)['add'](0x7,'days')['format']();_0x40a1ee[_0x4218('0x1c')]=_0x40a1ee['uuid']!=_0x40a1ee['machineUuid']?_0x4218('0x1d'):_0x4218('0x1e');}return _0x40a1ee;}catch(_0x3e6531){breakingLicense['uuid']=_0x25d5d1['data1'];breakingLicense[_0x4218('0x1f')]=_0x3e6531[_0x4218('0x1f')];return breakingLicense;}}function getLimits(){return new BPromise(function(_0x211178,_0x4a1ce9){getLicense()[_0x4218('0xd')](function(_0x24b967){return db[_0x4218('0x20')][_0x4218('0x21')]({'attributes':[_0x4218('0x22'),[db[_0x4218('0x23')]['fn'](_0x4218('0x24'),db[_0x4218('0x23')][_0x4218('0x25')](_0x4218('0x22'))),_0x4218('0x26')]],'group':_0x4218('0x22'),'where':{'role':{'$or':[_0x4218('0x27'),'user','telephone']}},'raw':!![]})['then'](function(_0x3c33e4){var _0x539fe3={'user':_0x24b967[_0x4218('0x28')]||0x0,'telephone':_0x24b967['telephones']||0x0};_0x3c33e4[_0x4218('0x29')](function(_0x330690){var _0x2b8116=_0x330690['role']==='admin'?'user':_0x330690[_0x4218('0x22')];_0x539fe3[_0x2b8116]-=_0x330690[_0x4218('0x26')];if(_0x539fe3[_0x2b8116]<0x0)_0x539fe3[_0x2b8116]=0x0;});_0x211178(_0x539fe3);return;});})[_0x4218('0xe')](function(_0x5d986a){_0x4a1ce9(_0x5d986a);});});}function checkUserLimits(_0x37a7b3){return new BPromise(function(_0x5a4c65,_0x15594b){getLimits()['then'](function(_0x2b3aca){var _0x69ce17=_['pick'](_['countBy'](_0x37a7b3,_0x4218('0x22')),[_0x4218('0x27'),_0x4218('0x2a'),_0x4218('0x2b')]);var _0x2d4875=(_0x69ce17[_0x4218('0x27')]||0x0)+(_0x69ce17[_0x4218('0x2a')]||0x0);var _0xda3519=_0x69ce17[_0x4218('0x2b')]||0x0;if(_0x2d4875>_0x2b3aca[_0x4218('0x2a')])return _0x15594b(_0x4218('0x2c'));if(_0xda3519>_0x2b3aca[_0x4218('0x2b')])return _0x15594b(_0x4218('0x2d'));return _0x5a4c65();})[_0x4218('0xe')](function(_0x50ed71){_0x15594b(_0x50ed71);});});}module[_0x4218('0x2e')]={'checkLicense':checkLicense,'checkUserLimits':checkUserLimits,'getLicense':getLicense};