89e251be7324c533aa4f4eabfb44c0c4e7536dfd
[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 _0x2c1e=['count','catch','pick','countBy','License\x20limit\x20reached\x20for\x20telephones','util','moment','bluebird','./hardware','../../components/encryptor','../../mysqldb','Demo\x20license','getUuid','2027-01-01T00:00:00.000Z','find','defaults','then','uuid','data1','license','isEmpty','License\x20key\x20value\x20not\x20found','split','decryptString','%s:%s:%s','parse','demo','machineUuid','deadline','days','changed','disabled','message','findAll','sequelize','COUNT','col','role','admin','telephone','users','telephones','forEach','user'];(function(_0x38ff1e,_0x3b9385){var _0x3755d4=function(_0x6e6692){while(--_0x6e6692){_0x38ff1e['push'](_0x38ff1e['shift']());}};_0x3755d4(++_0x3b9385);}(_0x2c1e,0x165));var _0xe2c1=function(_0x3899a3,_0xcb527){_0x3899a3=_0x3899a3-0x0;var _0x13e1ce=_0x2c1e[_0x3899a3];return _0x13e1ce;};'use strict';var util=require(_0xe2c1('0x0'));var _=require('lodash');var moment=require(_0xe2c1('0x1'));var BPromise=require(_0xe2c1('0x2'));var hardware=require(_0xe2c1('0x3'));var encryptor=require(_0xe2c1('0x4'));var db=require(_0xe2c1('0x5'))['db'];const demoLicense={'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':![],'description':_0xe2c1('0x6'),'machineUuid':hardware[_0xe2c1('0x7')](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};const breakingLicense={'breaking':!![],'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':_0xe2c1('0x8'),'chat':![],'mail':![],'fax':![],'messaging':![],'whatsapp':![],'cm':![],'dialer':![],'jscripty':![],'openchannel':![],'callysquare':0x2,'webrtc':![],'jaws':![],'custom':![],'update':![],'description':'Breaking\x20license','machineUuid':hardware[_0xe2c1('0x7')](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};function getLicense(_0x31ad33){return new BPromise(function(_0x579048,_0x58e2e8){return db['License'][_0xe2c1('0x9')](_[_0xe2c1('0xa')](_0x31ad33,{'raw':!![],'where':{'id':0x1}}))[_0xe2c1('0xb')](function(_0x55f8ae){return checkLicense(_0x55f8ae,null);})[_0xe2c1('0xb')](function(_0x59f722){_0x579048(_0x59f722);return;})['catch'](function(_0x1f875f){_0x58e2e8(_0x1f875f);});});}function checkLicense(_0x1e1648,_0x4ba45e){if(!_0x1e1648){demoLicense[_0xe2c1('0xc')]=_0x1e1648[_0xe2c1('0xd')];return demoLicense;}try{var _0x5c9311=_0x4ba45e||_0x1e1648[_0xe2c1('0xe')];if(_[_0xe2c1('0xf')](_0x5c9311)){throw new Error(_0xe2c1('0x10'));}var _0x3a7c5d=_0x1e1648[_0xe2c1('0xd')];var _0x2493d5=_0x1e1648['data2'];var _0x368d0e=_0x3a7c5d[_0xe2c1('0x11')]('-')[0x4];var _0x3e764c=_0x3a7c5d[_0xe2c1('0x11')]('-')[0x0];var _0x558e9c=encryptor[_0xe2c1('0x12')](_0x5c9311,util['format'](_0xe2c1('0x13'),_0x368d0e,_0x3a7c5d,_0x3e764c));var _0x437bf8=JSON[_0xe2c1('0x14')](_0x558e9c);_0x437bf8[_0xe2c1('0x15')]=![];_0x437bf8[_0xe2c1('0xc')]=_0x3a7c5d;_0x437bf8[_0xe2c1('0x16')]=hardware['getUuid']();if(_0x2493d5){var _0x175af9=encryptor[_0xe2c1('0x12')](_0x2493d5);_0x437bf8['gray']=_0x175af9;_0x437bf8[_0xe2c1('0x17')]=moment(_0x175af9)['add'](0x7,_0xe2c1('0x18'))['format']();_0x437bf8['grayReason']=_0x437bf8['uuid']!=_0x437bf8[_0xe2c1('0x16')]?_0xe2c1('0x19'):_0xe2c1('0x1a');}return _0x437bf8;}catch(_0x1b15d8){breakingLicense[_0xe2c1('0xc')]=_0x1e1648[_0xe2c1('0xd')];breakingLicense['message']=_0x1b15d8[_0xe2c1('0x1b')];return breakingLicense;}}function getLimits(){return new BPromise(function(_0x2c602f,_0x48da6a){getLicense()[_0xe2c1('0xb')](function(_0x54d824){return db['User'][_0xe2c1('0x1c')]({'attributes':['role',[db[_0xe2c1('0x1d')]['fn'](_0xe2c1('0x1e'),db[_0xe2c1('0x1d')][_0xe2c1('0x1f')](_0xe2c1('0x20'))),'count']],'group':_0xe2c1('0x20'),'where':{'role':{'$or':[_0xe2c1('0x21'),'user',_0xe2c1('0x22')]}},'raw':!![]})[_0xe2c1('0xb')](function(_0x11f5cf){var _0x5368db={'user':_0x54d824[_0xe2c1('0x23')]||0x0,'telephone':_0x54d824[_0xe2c1('0x24')]||0x0};_0x11f5cf[_0xe2c1('0x25')](function(_0x1a38c8){var _0x11db67=_0x1a38c8[_0xe2c1('0x20')]===_0xe2c1('0x21')?_0xe2c1('0x26'):_0x1a38c8['role'];_0x5368db[_0x11db67]-=_0x1a38c8[_0xe2c1('0x27')];if(_0x5368db[_0x11db67]<0x0)_0x5368db[_0x11db67]=0x0;});_0x2c602f(_0x5368db);return;});})[_0xe2c1('0x28')](function(_0x2b0db3){_0x48da6a(_0x2b0db3);});});}function checkUserLimits(_0x5ca802){return new BPromise(function(_0x3be9cb,_0x316dc3){getLimits()['then'](function(_0x2934c9){var _0xc0f244=_[_0xe2c1('0x29')](_[_0xe2c1('0x2a')](_0x5ca802,'role'),[_0xe2c1('0x21'),_0xe2c1('0x26'),_0xe2c1('0x22')]);var _0x1c3a18=(_0xc0f244[_0xe2c1('0x21')]||0x0)+(_0xc0f244[_0xe2c1('0x26')]||0x0);var _0x6b9206=_0xc0f244[_0xe2c1('0x22')]||0x0;if(_0x1c3a18>_0x2934c9['user'])return _0x316dc3('License\x20limit\x20reached\x20for\x20users');if(_0x6b9206>_0x2934c9[_0xe2c1('0x22')])return _0x316dc3(_0xe2c1('0x2b'));return _0x3be9cb();})[_0xe2c1('0x28')](function(_0x192686){_0x316dc3(_0x192686);});});}module['exports']={'checkLicense':checkLicense,'checkUserLimits':checkUserLimits,'getLicense':getLicense};