Built motion from commit e0fa946e.|2.6.5
[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 _0x2e19=['findAll','role','sequelize','COUNT','col','count','telephone','telephones','forEach','admin','user','catch','pick','countBy','License\x20limit\x20reached\x20for\x20users','License\x20limit\x20reached\x20for\x20telephones','lodash','moment','bluebird','./hardware','../../components/encryptor','../../mysqldb','2027-01-01T00:00:00.000Z','Demo\x20license','getUuid','defaults','then','uuid','data1','isEmpty','data2','split','decryptString','format','parse','machineUuid','gray','deadline','add','days','disabled','message','User'];(function(_0x243b2f,_0x30aa15){var _0xcb3c2d=function(_0x213bb2){while(--_0x213bb2){_0x243b2f['push'](_0x243b2f['shift']());}};_0xcb3c2d(++_0x30aa15);}(_0x2e19,0x112));var _0x92e1=function(_0xb2588a,_0x4709a8){_0xb2588a=_0xb2588a-0x0;var _0x2d4d54=_0x2e19[_0xb2588a];return _0x2d4d54;};'use strict';var util=require('util');var _=require(_0x92e1('0x0'));var moment=require(_0x92e1('0x1'));var BPromise=require(_0x92e1('0x2'));var hardware=require(_0x92e1('0x3'));var encryptor=require(_0x92e1('0x4'));var db=require(_0x92e1('0x5'))['db'];const demoLicense={'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':_0x92e1('0x6'),'chat':![],'mail':![],'fax':![],'messaging':![],'whatsapp':![],'cm':![],'dialer':![],'jscripty':![],'openchannel':![],'callysquare':0x2,'webrtc':![],'jaws':![],'custom':![],'description':_0x92e1('0x7'),'machineUuid':hardware[_0x92e1('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[_0x92e1('0x8')](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};function getLicense(_0x359228){return new BPromise(function(_0xfa1a3b,_0x30b3c6){return db['License']['find'](_[_0x92e1('0x9')](_0x359228,{'raw':!![],'where':{'id':0x1}}))[_0x92e1('0xa')](function(_0x5a6e92){return checkLicense(_0x5a6e92,null);})[_0x92e1('0xa')](function(_0x2c2dc4){_0xfa1a3b(_0x2c2dc4);return;})['catch'](function(_0x4fbfb3){_0x30b3c6(_0x4fbfb3);});});}function checkLicense(_0x20fdc,_0x5282c5){if(!_0x20fdc){demoLicense[_0x92e1('0xb')]=_0x20fdc[_0x92e1('0xc')];return demoLicense;}try{var _0x45f0e3=_0x5282c5||_0x20fdc['license'];if(_[_0x92e1('0xd')](_0x45f0e3)){throw new Error('License\x20key\x20value\x20not\x20found');}var _0x815745=_0x20fdc['data1'];var _0x32d130=_0x20fdc[_0x92e1('0xe')];var _0xd1f06a=_0x815745['split']('-')[0x4];var _0x25bad9=_0x815745[_0x92e1('0xf')]('-')[0x0];var _0x4b675e=encryptor[_0x92e1('0x10')](_0x45f0e3,util[_0x92e1('0x11')]('%s:%s:%s',_0xd1f06a,_0x815745,_0x25bad9));var _0x5d6c08=JSON[_0x92e1('0x12')](_0x4b675e);_0x5d6c08['demo']=![];_0x5d6c08['uuid']=_0x815745;_0x5d6c08[_0x92e1('0x13')]=hardware[_0x92e1('0x8')]();if(_0x32d130){var _0x5d967f=encryptor['decryptString'](_0x32d130);_0x5d6c08[_0x92e1('0x14')]=_0x5d967f;_0x5d6c08[_0x92e1('0x15')]=moment(_0x5d967f)[_0x92e1('0x16')](0x7,_0x92e1('0x17'))['format']();_0x5d6c08['grayReason']=_0x5d6c08['uuid']!=_0x5d6c08[_0x92e1('0x13')]?'changed':_0x92e1('0x18');}return _0x5d6c08;}catch(_0x14c841){breakingLicense[_0x92e1('0xb')]=_0x20fdc[_0x92e1('0xc')];breakingLicense[_0x92e1('0x19')]=_0x14c841[_0x92e1('0x19')];return breakingLicense;}}function getLimits(){return new BPromise(function(_0x4d2e4a,_0x11d4b5){getLicense()[_0x92e1('0xa')](function(_0x57611b){return db[_0x92e1('0x1a')][_0x92e1('0x1b')]({'attributes':[_0x92e1('0x1c'),[db[_0x92e1('0x1d')]['fn'](_0x92e1('0x1e'),db['sequelize'][_0x92e1('0x1f')](_0x92e1('0x1c'))),_0x92e1('0x20')]],'group':_0x92e1('0x1c'),'where':{'role':{'$or':['admin','user',_0x92e1('0x21')]}},'raw':!![]})[_0x92e1('0xa')](function(_0x47091b){var _0xd7ec8c={'user':_0x57611b['users']||0x0,'telephone':_0x57611b[_0x92e1('0x22')]||0x0};_0x47091b[_0x92e1('0x23')](function(_0x125618){var _0x39e002=_0x125618[_0x92e1('0x1c')]===_0x92e1('0x24')?_0x92e1('0x25'):_0x125618[_0x92e1('0x1c')];_0xd7ec8c[_0x39e002]-=_0x125618[_0x92e1('0x20')];if(_0xd7ec8c[_0x39e002]<0x0)_0xd7ec8c[_0x39e002]=0x0;});_0x4d2e4a(_0xd7ec8c);return;});})[_0x92e1('0x26')](function(_0xc7bb61){_0x11d4b5(_0xc7bb61);});});}function checkUserLimits(_0x52592a){return new BPromise(function(_0x4f1c87,_0xfdaea7){getLimits()[_0x92e1('0xa')](function(_0x5579d3){var _0x500331=_[_0x92e1('0x27')](_[_0x92e1('0x28')](_0x52592a,_0x92e1('0x1c')),[_0x92e1('0x24'),_0x92e1('0x25'),'telephone']);var _0x44be4=(_0x500331['admin']||0x0)+(_0x500331['user']||0x0);var _0x2dad1c=_0x500331[_0x92e1('0x21')]||0x0;if(_0x44be4>_0x5579d3['user'])return _0xfdaea7(_0x92e1('0x29'));if(_0x2dad1c>_0x5579d3['telephone'])return _0xfdaea7(_0x92e1('0x2a'));return _0x4f1c87();})[_0x92e1('0x26')](function(_0x40b204){_0xfdaea7(_0x40b204);});});}module['exports']={'checkLicense':checkLicense,'checkUserLimits':checkUserLimits,'getLicense':getLicense};