fe5bd05153544cfa5cc525e5eef52f8f11b8abd8
[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 _0xdc29=['%s:%s:%s','parse','demo','uuid','machineUuid','gray','deadline','add','days','changed','message','User','findAll','role','sequelize','col','count','admin','telephone','users','telephones','catch','pick','countBy','user','util','lodash','bluebird','../../components/encryptor','../../mysqldb','2027-01-01T00:00:00.000Z','getUuid','Breaking\x20license','License','find','then','data1','license','isEmpty','split','format'];(function(_0x54e856,_0x313d5c){var _0x124873=function(_0x48547e){while(--_0x48547e){_0x54e856['push'](_0x54e856['shift']());}};_0x124873(++_0x313d5c);}(_0xdc29,0x138));var _0x9dc2=function(_0x27013d,_0xc982e8){_0x27013d=_0x27013d-0x0;var _0x3d653f=_0xdc29[_0x27013d];return _0x3d653f;};'use strict';var util=require(_0x9dc2('0x0'));var _=require(_0x9dc2('0x1'));var moment=require('moment');var BPromise=require(_0x9dc2('0x2'));var hardware=require('./hardware');var encryptor=require(_0x9dc2('0x3'));var db=require(_0x9dc2('0x4'))['db'];const demoLicense={'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':_0x9dc2('0x5'),'chat':![],'mail':![],'fax':![],'messaging':![],'whatsapp':![],'cm':![],'dialer':![],'jscripty':![],'openchannel':![],'callysquare':0x2,'webrtc':![],'jaws':![],'custom':![],'description':'Demo\x20license','machineUuid':hardware[_0x9dc2('0x6')](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};const breakingLicense={'breaking':!![],'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':_0x9dc2('0x5'),'chat':![],'mail':![],'fax':![],'messaging':![],'whatsapp':![],'cm':![],'dialer':![],'jscripty':![],'openchannel':![],'callysquare':0x2,'webrtc':![],'jaws':![],'custom':![],'update':![],'description':_0x9dc2('0x7'),'machineUuid':hardware['getUuid'](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};function getLicense(_0x5f4e37){return new BPromise(function(_0x452731,_0x2281d8){return db[_0x9dc2('0x8')][_0x9dc2('0x9')](_['defaults'](_0x5f4e37,{'raw':!![],'where':{'id':0x1}}))[_0x9dc2('0xa')](function(_0x334787){return checkLicense(_0x334787,null);})[_0x9dc2('0xa')](function(_0x1b8b66){_0x452731(_0x1b8b66);return;})['catch'](function(_0x17f07c){_0x2281d8(_0x17f07c);});});}function checkLicense(_0x2da9c4,_0x324af7){if(!_0x2da9c4){demoLicense['uuid']=_0x2da9c4[_0x9dc2('0xb')];return demoLicense;}try{var _0x10336c=_0x324af7||_0x2da9c4[_0x9dc2('0xc')];if(_[_0x9dc2('0xd')](_0x10336c)){throw new Error('License\x20key\x20value\x20not\x20found');}var _0x4656ff=_0x2da9c4[_0x9dc2('0xb')];var _0xf91841=_0x2da9c4['data2'];var _0x2ba78d=_0x4656ff[_0x9dc2('0xe')]('-')[0x4];var _0x429fb6=_0x4656ff[_0x9dc2('0xe')]('-')[0x0];var _0x314b11=encryptor['decryptString'](_0x10336c,util[_0x9dc2('0xf')](_0x9dc2('0x10'),_0x2ba78d,_0x4656ff,_0x429fb6));var _0x8c1393=JSON[_0x9dc2('0x11')](_0x314b11);_0x8c1393[_0x9dc2('0x12')]=![];_0x8c1393[_0x9dc2('0x13')]=_0x4656ff;_0x8c1393[_0x9dc2('0x14')]=hardware[_0x9dc2('0x6')]();if(_0xf91841){var _0x2f4852=encryptor['decryptString'](_0xf91841);_0x8c1393[_0x9dc2('0x15')]=_0x2f4852;_0x8c1393[_0x9dc2('0x16')]=moment(_0x2f4852)[_0x9dc2('0x17')](0x7,_0x9dc2('0x18'))[_0x9dc2('0xf')]();_0x8c1393['grayReason']=_0x8c1393[_0x9dc2('0x13')]!=_0x8c1393[_0x9dc2('0x14')]?_0x9dc2('0x19'):'disabled';}return _0x8c1393;}catch(_0x1743fa){breakingLicense[_0x9dc2('0x13')]=_0x2da9c4[_0x9dc2('0xb')];breakingLicense[_0x9dc2('0x1a')]=_0x1743fa[_0x9dc2('0x1a')];return breakingLicense;}}function getLimits(){return new BPromise(function(_0x13ecf6,_0x3e5c65){getLicense()[_0x9dc2('0xa')](function(_0x1e08fd){return db[_0x9dc2('0x1b')][_0x9dc2('0x1c')]({'attributes':[_0x9dc2('0x1d'),[db[_0x9dc2('0x1e')]['fn']('COUNT',db[_0x9dc2('0x1e')][_0x9dc2('0x1f')](_0x9dc2('0x1d'))),_0x9dc2('0x20')]],'group':_0x9dc2('0x1d'),'where':{'role':{'$or':[_0x9dc2('0x21'),'user',_0x9dc2('0x22')]}},'raw':!![]})[_0x9dc2('0xa')](function(_0x59b662){var _0x554c45={'user':_0x1e08fd[_0x9dc2('0x23')]||0x0,'telephone':_0x1e08fd[_0x9dc2('0x24')]||0x0};_0x59b662['forEach'](function(_0x2a4281){var _0x4de097=_0x2a4281[_0x9dc2('0x1d')]===_0x9dc2('0x21')?'user':_0x2a4281[_0x9dc2('0x1d')];_0x554c45[_0x4de097]-=_0x2a4281['count'];if(_0x554c45[_0x4de097]<0x0)_0x554c45[_0x4de097]=0x0;});_0x13ecf6(_0x554c45);return;});})[_0x9dc2('0x25')](function(_0x5c94fb){_0x3e5c65(_0x5c94fb);});});}function checkUserLimits(_0x132ebc){return new BPromise(function(_0x118c2b,_0x17ac2b){getLimits()[_0x9dc2('0xa')](function(_0x35df72){var _0x41f26d=_[_0x9dc2('0x26')](_[_0x9dc2('0x27')](_0x132ebc,_0x9dc2('0x1d')),['admin',_0x9dc2('0x28'),_0x9dc2('0x22')]);var _0xb9700f=(_0x41f26d[_0x9dc2('0x21')]||0x0)+(_0x41f26d[_0x9dc2('0x28')]||0x0);var _0x1bd3d4=_0x41f26d[_0x9dc2('0x22')]||0x0;if(_0xb9700f>_0x35df72[_0x9dc2('0x28')])return _0x17ac2b('License\x20limit\x20reached\x20for\x20users');if(_0x1bd3d4>_0x35df72[_0x9dc2('0x22')])return _0x17ac2b('License\x20limit\x20reached\x20for\x20telephones');return _0x118c2b();})[_0x9dc2('0x25')](function(_0x1b156e){_0x17ac2b(_0x1b156e);});});}module['exports']={'checkLicense':checkLicense,'checkUserLimits':checkUserLimits,'getLicense':getLicense};