4cb0e59e37a3f4cf9fce3c18dc0612bde710a394
[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 _0xc77c=['forEach','role','user','License\x20limit\x20reached\x20for\x20users','License\x20limit\x20reached\x20for\x20telephones','exports','util','lodash','moment','./hardware','../../components/encryptor','../../mysqldb','2027-01-01T00:00:00.000Z','Demo\x20license','getUuid','then','catch','uuid','license','isEmpty','data1','data2','split','decryptString','parse','machineUuid','gray','add','days','grayReason','changed','disabled','message','User','findAll','sequelize','COUNT','col','count','admin','telephone','users','telephones'];(function(_0x3a16d4,_0x221ae7){var _0x48310b=function(_0x462be1){while(--_0x462be1){_0x3a16d4['push'](_0x3a16d4['shift']());}};_0x48310b(++_0x221ae7);}(_0xc77c,0xdd));var _0xcc77=function(_0x2d54ba,_0x3d5c1a){_0x2d54ba=_0x2d54ba-0x0;var _0x445649=_0xc77c[_0x2d54ba];return _0x445649;};'use strict';var util=require(_0xcc77('0x0'));var _=require(_0xcc77('0x1'));var moment=require(_0xcc77('0x2'));var BPromise=require('bluebird');var hardware=require(_0xcc77('0x3'));var encryptor=require(_0xcc77('0x4'));var db=require(_0xcc77('0x5'))['db'];const demoLicense={'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':_0xcc77('0x6'),'chat':![],'mail':![],'fax':![],'messaging':![],'whatsapp':![],'cm':![],'dialer':![],'jscripty':![],'openchannel':![],'callysquare':0x2,'webrtc':![],'jaws':![],'custom':![],'description':_0xcc77('0x7'),'machineUuid':hardware[_0xcc77('0x8')](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};const 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':'Breaking\x20license','machineUuid':hardware[_0xcc77('0x8')](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};function getLicense(_0x220f02){return new BPromise(function(_0x37c2a4,_0x335356){return db['License']['find'](_['defaults'](_0x220f02,{'raw':!![],'where':{'id':0x1}}))[_0xcc77('0x9')](function(_0x51f44e){return checkLicense(_0x51f44e,null);})[_0xcc77('0x9')](function(_0x46a8c6){_0x37c2a4(_0x46a8c6);return;})[_0xcc77('0xa')](function(_0x50128a){_0x335356(_0x50128a);});});}function checkLicense(_0x5ba931,_0x81422){if(!_0x5ba931){demoLicense[_0xcc77('0xb')]=_0x5ba931['data1'];return demoLicense;}try{var _0x53dc69=_0x81422||_0x5ba931[_0xcc77('0xc')];if(_[_0xcc77('0xd')](_0x53dc69)){throw new Error('License\x20key\x20value\x20not\x20found');}var _0xa32a84=_0x5ba931[_0xcc77('0xe')];var _0x1a4882=_0x5ba931[_0xcc77('0xf')];var _0x142041=_0xa32a84['split']('-')[0x4];var _0x376714=_0xa32a84[_0xcc77('0x10')]('-')[0x0];var _0xc750f1=encryptor[_0xcc77('0x11')](_0x53dc69,util['format']('%s:%s:%s',_0x142041,_0xa32a84,_0x376714));var _0x3f4a84=JSON[_0xcc77('0x12')](_0xc750f1);_0x3f4a84['demo']=![];_0x3f4a84[_0xcc77('0xb')]=_0xa32a84;_0x3f4a84[_0xcc77('0x13')]=hardware[_0xcc77('0x8')]();if(_0x1a4882){var _0x272660=encryptor[_0xcc77('0x11')](_0x1a4882);_0x3f4a84[_0xcc77('0x14')]=_0x272660;_0x3f4a84['deadline']=moment(_0x272660)[_0xcc77('0x15')](0x7,_0xcc77('0x16'))['format']();_0x3f4a84[_0xcc77('0x17')]=_0x3f4a84[_0xcc77('0xb')]!=_0x3f4a84['machineUuid']?_0xcc77('0x18'):_0xcc77('0x19');}return _0x3f4a84;}catch(_0xc9b551){breakingLicense['uuid']=_0x5ba931[_0xcc77('0xe')];breakingLicense[_0xcc77('0x1a')]=_0xc9b551['message'];return breakingLicense;}}function getLimits(){return new BPromise(function(_0x51eb07,_0x3f4d1e){getLicense()[_0xcc77('0x9')](function(_0x3e6c00){return db[_0xcc77('0x1b')][_0xcc77('0x1c')]({'attributes':['role',[db[_0xcc77('0x1d')]['fn'](_0xcc77('0x1e'),db[_0xcc77('0x1d')][_0xcc77('0x1f')]('role')),_0xcc77('0x20')]],'group':'role','where':{'role':{'$or':[_0xcc77('0x21'),'user',_0xcc77('0x22')]}},'raw':!![]})[_0xcc77('0x9')](function(_0x59df84){var _0x2773bd={'user':_0x3e6c00[_0xcc77('0x23')]||0x0,'telephone':_0x3e6c00[_0xcc77('0x24')]||0x0};_0x59df84[_0xcc77('0x25')](function(_0x5a2c4c){var _0x5eb2e1=_0x5a2c4c[_0xcc77('0x26')]===_0xcc77('0x21')?'user':_0x5a2c4c[_0xcc77('0x26')];_0x2773bd[_0x5eb2e1]-=_0x5a2c4c[_0xcc77('0x20')];if(_0x2773bd[_0x5eb2e1]<0x0)_0x2773bd[_0x5eb2e1]=0x0;});_0x51eb07(_0x2773bd);return;});})[_0xcc77('0xa')](function(_0x4b78c6){_0x3f4d1e(_0x4b78c6);});});}function checkUserLimits(_0x1c34fd){return new BPromise(function(_0x4f3091,_0x4349db){getLimits()['then'](function(_0x2ff378){var _0x372b3d=_['pick'](_['countBy'](_0x1c34fd,_0xcc77('0x26')),['admin','user',_0xcc77('0x22')]);var _0x390be9=(_0x372b3d[_0xcc77('0x21')]||0x0)+(_0x372b3d[_0xcc77('0x27')]||0x0);var _0x9079cf=_0x372b3d['telephone']||0x0;if(_0x390be9>_0x2ff378[_0xcc77('0x27')])return _0x4349db(_0xcc77('0x28'));if(_0x9079cf>_0x2ff378['telephone'])return _0x4349db(_0xcc77('0x29'));return _0x4f3091();})['catch'](function(_0xa716ee){_0x4349db(_0xa716ee);});});}module[_0xcc77('0x2a')]={'checkLicense':checkLicense,'checkUserLimits':checkUserLimits,'getLicense':getLicense};