4daf4e093d83f5054000d588eab72c0783e6024d
[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 _0xab5b=['forEach','pick','countBy','License\x20limit\x20reached\x20for\x20users','License\x20limit\x20reached\x20for\x20telephones','util','lodash','bluebird','./hardware','../../components/encryptor','../../mysqldb','2027-01-01T00:00:00.000Z','Demo\x20license','getUuid','Breaking\x20license','then','catch','uuid','data1','license','isEmpty','License\x20key\x20value\x20not\x20found','data2','split','decryptString','format','parse','demo','gray','deadline','add','days','machineUuid','changed','disabled','User','findAll','sequelize','col','count','role','admin','user','telephone','users','telephones'];(function(_0x8ed10c,_0xa2e38f){var _0x151e12=function(_0x49b509){while(--_0x49b509){_0x8ed10c['push'](_0x8ed10c['shift']());}};_0x151e12(++_0xa2e38f);}(_0xab5b,0xbd));var _0xbab5=function(_0x5d8444,_0x2d7c8d){_0x5d8444=_0x5d8444-0x0;var _0x67716d=_0xab5b[_0x5d8444];return _0x67716d;};'use strict';var util=require(_0xbab5('0x0'));var _=require(_0xbab5('0x1'));var moment=require('moment');var BPromise=require(_0xbab5('0x2'));var hardware=require(_0xbab5('0x3'));var encryptor=require(_0xbab5('0x4'));var db=require(_0xbab5('0x5'))['db'];const demoLicense={'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':_0xbab5('0x6'),'chat':![],'mail':![],'fax':![],'messaging':![],'whatsapp':![],'cm':![],'dialer':![],'jscripty':![],'openchannel':![],'callysquare':0x2,'webrtc':![],'jaws':![],'custom':![],'description':_0xbab5('0x7'),'machineUuid':hardware[_0xbab5('0x8')](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};const breakingLicense={'breaking':!![],'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':_0xbab5('0x6'),'chat':![],'mail':![],'fax':![],'messaging':![],'whatsapp':![],'cm':![],'dialer':![],'jscripty':![],'openchannel':![],'callysquare':0x2,'webrtc':![],'jaws':![],'custom':![],'update':![],'description':_0xbab5('0x9'),'machineUuid':hardware[_0xbab5('0x8')](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};function getLicense(_0x5d37f3){return new BPromise(function(_0x19c168,_0x235afd){return db['License']['find'](_['defaults'](_0x5d37f3,{'raw':!![],'where':{'id':0x1}}))[_0xbab5('0xa')](function(_0xcb5f2f){return checkLicense(_0xcb5f2f,null);})[_0xbab5('0xa')](function(_0x3be436){_0x19c168(_0x3be436);return;})[_0xbab5('0xb')](function(_0x2824ce){_0x235afd(_0x2824ce);});});}function checkLicense(_0x1da085,_0x1c48ff){if(!_0x1da085){demoLicense[_0xbab5('0xc')]=_0x1da085[_0xbab5('0xd')];return demoLicense;}try{var _0x5558f8=_0x1c48ff||_0x1da085[_0xbab5('0xe')];if(_[_0xbab5('0xf')](_0x5558f8)){throw new Error(_0xbab5('0x10'));}var _0x3967ea=_0x1da085[_0xbab5('0xd')];var _0x1689b4=_0x1da085[_0xbab5('0x11')];var _0x3f1d78=_0x3967ea[_0xbab5('0x12')]('-')[0x4];var _0x1130d5=_0x3967ea[_0xbab5('0x12')]('-')[0x0];var _0x3a9349=encryptor[_0xbab5('0x13')](_0x5558f8,util[_0xbab5('0x14')]('%s:%s:%s',_0x3f1d78,_0x3967ea,_0x1130d5));var _0x24b605=JSON[_0xbab5('0x15')](_0x3a9349);_0x24b605[_0xbab5('0x16')]=![];_0x24b605[_0xbab5('0xc')]=_0x3967ea;_0x24b605['machineUuid']=hardware[_0xbab5('0x8')]();if(_0x1689b4){var _0x2f3f4f=encryptor[_0xbab5('0x13')](_0x1689b4);_0x24b605[_0xbab5('0x17')]=_0x2f3f4f;_0x24b605[_0xbab5('0x18')]=moment(_0x2f3f4f)[_0xbab5('0x19')](0x7,_0xbab5('0x1a'))['format']();_0x24b605['grayReason']=_0x24b605[_0xbab5('0xc')]!=_0x24b605[_0xbab5('0x1b')]?_0xbab5('0x1c'):_0xbab5('0x1d');}return _0x24b605;}catch(_0x314e67){breakingLicense[_0xbab5('0xc')]=_0x1da085[_0xbab5('0xd')];breakingLicense['message']=_0x314e67['message'];return breakingLicense;}}function getLimits(){return new BPromise(function(_0x249772,_0x21262e){getLicense()[_0xbab5('0xa')](function(_0x1ea35b){return db[_0xbab5('0x1e')][_0xbab5('0x1f')]({'attributes':['role',[db[_0xbab5('0x20')]['fn']('COUNT',db['sequelize'][_0xbab5('0x21')]('role')),_0xbab5('0x22')]],'group':_0xbab5('0x23'),'where':{'role':{'$or':[_0xbab5('0x24'),_0xbab5('0x25'),_0xbab5('0x26')]}},'raw':!![]})['then'](function(_0x58a7f6){var _0xe8e07c={'user':_0x1ea35b[_0xbab5('0x27')]||0x0,'telephone':_0x1ea35b[_0xbab5('0x28')]||0x0};_0x58a7f6[_0xbab5('0x29')](function(_0x1adc73){var _0x503174=_0x1adc73[_0xbab5('0x23')]===_0xbab5('0x24')?_0xbab5('0x25'):_0x1adc73[_0xbab5('0x23')];_0xe8e07c[_0x503174]-=_0x1adc73['count'];if(_0xe8e07c[_0x503174]<0x0)_0xe8e07c[_0x503174]=0x0;});_0x249772(_0xe8e07c);return;});})['catch'](function(_0x3d66e0){_0x21262e(_0x3d66e0);});});}function checkUserLimits(_0x864fa4){return new BPromise(function(_0x230918,_0x1953f9){getLimits()[_0xbab5('0xa')](function(_0x42c257){var _0x2348d7=_[_0xbab5('0x2a')](_[_0xbab5('0x2b')](_0x864fa4,_0xbab5('0x23')),[_0xbab5('0x24'),'user',_0xbab5('0x26')]);var _0x452c7e=(_0x2348d7['admin']||0x0)+(_0x2348d7['user']||0x0);var _0x5de666=_0x2348d7[_0xbab5('0x26')]||0x0;if(_0x452c7e>_0x42c257[_0xbab5('0x25')])return _0x1953f9(_0xbab5('0x2c'));if(_0x5de666>_0x42c257[_0xbab5('0x26')])return _0x1953f9(_0xbab5('0x2d'));return _0x230918();})[_0xbab5('0xb')](function(_0x5610a9){_0x1953f9(_0x5610a9);});});}module['exports']={'checkLicense':checkLicense,'checkUserLimits':checkUserLimits,'getLicense':getLicense};