bcdbb5d688cf74c9b5d03ccfb9af98674c18b0a9
[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 _0x77b4=['disabled','message','User','findAll','role','sequelize','COUNT','col','admin','user','telephone','users','forEach','count','pick','countBy','License\x20limit\x20reached\x20for\x20users','License\x20limit\x20reached\x20for\x20telephones','exports','lodash','bluebird','./hardware','../../components/encryptor','../../mysqldb','2027-01-01T00:00:00.000Z','getUuid','Breaking\x20license','License','find','defaults','then','catch','uuid','license','License\x20key\x20value\x20not\x20found','data1','data2','split','decryptString','format','%s:%s:%s','parse','demo','gray','add','days','grayReason','machineUuid','changed'];(function(_0x4ef308,_0x19fa14){var _0xac5f09=function(_0x3570dd){while(--_0x3570dd){_0x4ef308['push'](_0x4ef308['shift']());}};_0xac5f09(++_0x19fa14);}(_0x77b4,0x16a));var _0x477b=function(_0x12b683,_0x124186){_0x12b683=_0x12b683-0x0;var _0xfb150b=_0x77b4[_0x12b683];return _0xfb150b;};'use strict';var util=require('util');var _=require(_0x477b('0x0'));var moment=require('moment');var BPromise=require(_0x477b('0x1'));var hardware=require(_0x477b('0x2'));var encryptor=require(_0x477b('0x3'));var db=require(_0x477b('0x4'))['db'];const demoLicense={'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':_0x477b('0x5'),'chat':![],'mail':![],'fax':![],'messaging':![],'whatsapp':![],'cm':![],'dialer':![],'jscripty':![],'openchannel':![],'callysquare':0x2,'webrtc':![],'jaws':![],'custom':![],'description':'Demo\x20license','machineUuid':hardware[_0x477b('0x6')](),'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':_0x477b('0x7'),'machineUuid':hardware['getUuid'](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};function getLicense(_0x308841){return new BPromise(function(_0x110c0b,_0x5a7dc5){return db[_0x477b('0x8')][_0x477b('0x9')](_[_0x477b('0xa')](_0x308841,{'raw':!![],'where':{'id':0x1}}))[_0x477b('0xb')](function(_0x115630){return checkLicense(_0x115630,null);})[_0x477b('0xb')](function(_0x40cd98){_0x110c0b(_0x40cd98);return;})[_0x477b('0xc')](function(_0x18d426){_0x5a7dc5(_0x18d426);});});}function checkLicense(_0x4737fe,_0x49a177){if(!_0x4737fe){demoLicense[_0x477b('0xd')]=_0x4737fe['data1'];return demoLicense;}try{var _0x112054=_0x49a177||_0x4737fe[_0x477b('0xe')];if(_['isEmpty'](_0x112054)){throw new Error(_0x477b('0xf'));}var _0x5f0675=_0x4737fe[_0x477b('0x10')];var _0x3a91d5=_0x4737fe[_0x477b('0x11')];var _0x1fffaa=_0x5f0675[_0x477b('0x12')]('-')[0x4];var _0x165bdd=_0x5f0675[_0x477b('0x12')]('-')[0x0];var _0x3b7e5a=encryptor[_0x477b('0x13')](_0x112054,util[_0x477b('0x14')](_0x477b('0x15'),_0x1fffaa,_0x5f0675,_0x165bdd));var _0x4f91a=JSON[_0x477b('0x16')](_0x3b7e5a);_0x4f91a[_0x477b('0x17')]=![];_0x4f91a[_0x477b('0xd')]=_0x5f0675;_0x4f91a['machineUuid']=hardware[_0x477b('0x6')]();if(_0x3a91d5){var _0x3c426f=encryptor[_0x477b('0x13')](_0x3a91d5);_0x4f91a[_0x477b('0x18')]=_0x3c426f;_0x4f91a['deadline']=moment(_0x3c426f)[_0x477b('0x19')](0x7,_0x477b('0x1a'))[_0x477b('0x14')]();_0x4f91a[_0x477b('0x1b')]=_0x4f91a['uuid']!=_0x4f91a[_0x477b('0x1c')]?_0x477b('0x1d'):_0x477b('0x1e');}return _0x4f91a;}catch(_0x56ca96){breakingLicense[_0x477b('0xd')]=_0x4737fe['data1'];breakingLicense[_0x477b('0x1f')]=_0x56ca96[_0x477b('0x1f')];return breakingLicense;}}function getLimits(){return new BPromise(function(_0x22f728,_0x3505f3){getLicense()[_0x477b('0xb')](function(_0x5c86be){return db[_0x477b('0x20')][_0x477b('0x21')]({'attributes':[_0x477b('0x22'),[db[_0x477b('0x23')]['fn'](_0x477b('0x24'),db[_0x477b('0x23')][_0x477b('0x25')](_0x477b('0x22'))),'count']],'group':_0x477b('0x22'),'where':{'role':{'$or':[_0x477b('0x26'),_0x477b('0x27'),_0x477b('0x28')]}},'raw':!![]})['then'](function(_0x2d5bb8){var _0x39e210={'user':_0x5c86be[_0x477b('0x29')]||0x0,'telephone':_0x5c86be['telephones']||0x0};_0x2d5bb8[_0x477b('0x2a')](function(_0x4c1d75){var _0xe878e8=_0x4c1d75[_0x477b('0x22')]===_0x477b('0x26')?_0x477b('0x27'):_0x4c1d75[_0x477b('0x22')];_0x39e210[_0xe878e8]-=_0x4c1d75[_0x477b('0x2b')];if(_0x39e210[_0xe878e8]<0x0)_0x39e210[_0xe878e8]=0x0;});_0x22f728(_0x39e210);return;});})[_0x477b('0xc')](function(_0x247820){_0x3505f3(_0x247820);});});}function checkUserLimits(_0x198351){return new BPromise(function(_0x51faa4,_0x4b912c){getLimits()[_0x477b('0xb')](function(_0x2523a1){var _0x3cb2ea=_[_0x477b('0x2c')](_[_0x477b('0x2d')](_0x198351,'role'),[_0x477b('0x26'),_0x477b('0x27'),_0x477b('0x28')]);var _0x2bc85e=(_0x3cb2ea[_0x477b('0x26')]||0x0)+(_0x3cb2ea[_0x477b('0x27')]||0x0);var _0x4d8a32=_0x3cb2ea['telephone']||0x0;if(_0x2bc85e>_0x2523a1[_0x477b('0x27')])return _0x4b912c(_0x477b('0x2e'));if(_0x4d8a32>_0x2523a1[_0x477b('0x28')])return _0x4b912c(_0x477b('0x2f'));return _0x51faa4();})[_0x477b('0xc')](function(_0x2b228f){_0x4b912c(_0x2b228f);});});}module[_0x477b('0x30')]={'checkLicense':checkLicense,'checkUserLimits':checkUserLimits,'getLicense':getLicense};