Built motion from commit 753c950e.|2.5.42
[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 _0x7bcb=['role','sequelize','COUNT','count','user','users','telephones','forEach','admin','pick','countBy','telephone','License\x20limit\x20reached\x20for\x20users','License\x20limit\x20reached\x20for\x20telephones','util','lodash','moment','bluebird','./hardware','../../components/encryptor','../../mysqldb','2027-01-01T00:00:00.000Z','Demo\x20license','getUuid','License','find','then','catch','uuid','license','isEmpty','License\x20key\x20value\x20not\x20found','data1','split','format','%s:%s:%s','parse','demo','machineUuid','gray','deadline','add','days','changed','disabled','message','User'];(function(_0x3947c9,_0x4d6c97){var _0x2e7871=function(_0x1236cc){while(--_0x1236cc){_0x3947c9['push'](_0x3947c9['shift']());}};_0x2e7871(++_0x4d6c97);}(_0x7bcb,0xf9));var _0xb7bc=function(_0x12a674,_0x475b5b){_0x12a674=_0x12a674-0x0;var _0x28680a=_0x7bcb[_0x12a674];return _0x28680a;};'use strict';var util=require(_0xb7bc('0x0'));var _=require(_0xb7bc('0x1'));var moment=require(_0xb7bc('0x2'));var BPromise=require(_0xb7bc('0x3'));var hardware=require(_0xb7bc('0x4'));var encryptor=require(_0xb7bc('0x5'));var db=require(_0xb7bc('0x6'))['db'];const demoLicense={'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':_0xb7bc('0x7'),'chat':![],'mail':![],'fax':![],'messaging':![],'whatsapp':![],'cm':![],'dialer':![],'jscripty':![],'openchannel':![],'callysquare':0x2,'webrtc':![],'jaws':![],'custom':![],'description':_0xb7bc('0x8'),'machineUuid':hardware['getUuid'](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};const breakingLicense={'breaking':!![],'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':_0xb7bc('0x7'),'chat':![],'mail':![],'fax':![],'messaging':![],'whatsapp':![],'cm':![],'dialer':![],'jscripty':![],'openchannel':![],'callysquare':0x2,'webrtc':![],'jaws':![],'custom':![],'update':![],'description':'Breaking\x20license','machineUuid':hardware[_0xb7bc('0x9')](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};function getLicense(_0x3795d2){return new BPromise(function(_0xb011b2,_0x5199e1){return db[_0xb7bc('0xa')][_0xb7bc('0xb')](_['defaults'](_0x3795d2,{'raw':!![],'where':{'id':0x1}}))[_0xb7bc('0xc')](function(_0x54d4cf){return checkLicense(_0x54d4cf,null);})[_0xb7bc('0xc')](function(_0x5cd054){_0xb011b2(_0x5cd054);return;})[_0xb7bc('0xd')](function(_0x446577){_0x5199e1(_0x446577);});});}function checkLicense(_0x3378db,_0x883bd9){if(!_0x3378db){demoLicense[_0xb7bc('0xe')]=_0x3378db['data1'];return demoLicense;}try{var _0x3d5afa=_0x883bd9||_0x3378db[_0xb7bc('0xf')];if(_[_0xb7bc('0x10')](_0x3d5afa)){throw new Error(_0xb7bc('0x11'));}var _0x25ad61=_0x3378db[_0xb7bc('0x12')];var _0x841201=_0x3378db['data2'];var _0x3decb6=_0x25ad61['split']('-')[0x4];var _0x5ccdf0=_0x25ad61[_0xb7bc('0x13')]('-')[0x0];var _0x4a4526=encryptor['decryptString'](_0x3d5afa,util[_0xb7bc('0x14')](_0xb7bc('0x15'),_0x3decb6,_0x25ad61,_0x5ccdf0));var _0x470690=JSON[_0xb7bc('0x16')](_0x4a4526);_0x470690[_0xb7bc('0x17')]=![];_0x470690[_0xb7bc('0xe')]=_0x25ad61;_0x470690[_0xb7bc('0x18')]=hardware[_0xb7bc('0x9')]();if(_0x841201){var _0x35c183=encryptor['decryptString'](_0x841201);_0x470690[_0xb7bc('0x19')]=_0x35c183;_0x470690[_0xb7bc('0x1a')]=moment(_0x35c183)[_0xb7bc('0x1b')](0x7,_0xb7bc('0x1c'))['format']();_0x470690['grayReason']=_0x470690['uuid']!=_0x470690['machineUuid']?_0xb7bc('0x1d'):_0xb7bc('0x1e');}return _0x470690;}catch(_0x5c1b02){breakingLicense[_0xb7bc('0xe')]=_0x3378db[_0xb7bc('0x12')];breakingLicense[_0xb7bc('0x1f')]=_0x5c1b02[_0xb7bc('0x1f')];return breakingLicense;}}function getLimits(){return new BPromise(function(_0x349c24,_0x57253b){getLicense()['then'](function(_0x193103){return db[_0xb7bc('0x20')]['findAll']({'attributes':[_0xb7bc('0x21'),[db[_0xb7bc('0x22')]['fn'](_0xb7bc('0x23'),db[_0xb7bc('0x22')]['col']('role')),_0xb7bc('0x24')]],'group':'role','where':{'role':{'$or':['admin',_0xb7bc('0x25'),'telephone']}},'raw':!![]})[_0xb7bc('0xc')](function(_0x361ce2){var _0x2ab062={'user':_0x193103[_0xb7bc('0x26')]||0x0,'telephone':_0x193103[_0xb7bc('0x27')]||0x0};_0x361ce2[_0xb7bc('0x28')](function(_0x7b511){var _0x57adbe=_0x7b511['role']===_0xb7bc('0x29')?'user':_0x7b511[_0xb7bc('0x21')];_0x2ab062[_0x57adbe]-=_0x7b511['count'];if(_0x2ab062[_0x57adbe]<0x0)_0x2ab062[_0x57adbe]=0x0;});_0x349c24(_0x2ab062);return;});})[_0xb7bc('0xd')](function(_0x31f17a){_0x57253b(_0x31f17a);});});}function checkUserLimits(_0x395aa6){return new BPromise(function(_0x4a2fc3,_0x1020bd){getLimits()['then'](function(_0x48510a){var _0x2ffa21=_[_0xb7bc('0x2a')](_[_0xb7bc('0x2b')](_0x395aa6,_0xb7bc('0x21')),[_0xb7bc('0x29'),'user','telephone']);var _0x25f014=(_0x2ffa21['admin']||0x0)+(_0x2ffa21[_0xb7bc('0x25')]||0x0);var _0x5032c9=_0x2ffa21[_0xb7bc('0x2c')]||0x0;if(_0x25f014>_0x48510a[_0xb7bc('0x25')])return _0x1020bd(_0xb7bc('0x2d'));if(_0x5032c9>_0x48510a['telephone'])return _0x1020bd(_0xb7bc('0x2e'));return _0x4a2fc3();})[_0xb7bc('0xd')](function(_0x16b69e){_0x1020bd(_0x16b69e);});});}module['exports']={'checkLicense':checkLicense,'checkUserLimits':checkUserLimits,'getLicense':getLicense};