Built motion from commit 13c3002c.|2.6.9
[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 _0x00e6=['find','defaults','then','catch','data1','license','isEmpty','data2','split','decryptString','format','%s:%s:%s','parse','demo','uuid','machineUuid','add','days','grayReason','changed','disabled','message','User','findAll','COUNT','sequelize','col','role','count','admin','user','telephones','forEach','pick','countBy','telephone','License\x20limit\x20reached\x20for\x20users','exports','util','bluebird','../../mysqldb','getUuid','2027-01-01T00:00:00.000Z','Breaking\x20license'];(function(_0x224f65,_0x4750bf){var _0x3f921c=function(_0x1b5f64){while(--_0x1b5f64){_0x224f65['push'](_0x224f65['shift']());}};_0x3f921c(++_0x4750bf);}(_0x00e6,0x12e));var _0x600e=function(_0x28d225,_0x43be18){_0x28d225=_0x28d225-0x0;var _0x1f79e1=_0x00e6[_0x28d225];return _0x1f79e1;};'use strict';var util=require(_0x600e('0x0'));var _=require('lodash');var moment=require('moment');var BPromise=require(_0x600e('0x1'));var hardware=require('./hardware');var encryptor=require('../../components/encryptor');var db=require(_0x600e('0x2'))['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':'Demo\x20license','machineUuid':hardware[_0x600e('0x3')](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};const breakingLicense={'breaking':!![],'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':_0x600e('0x4'),'chat':![],'mail':![],'fax':![],'messaging':![],'whatsapp':![],'cm':![],'dialer':![],'jscripty':![],'openchannel':![],'callysquare':0x2,'webrtc':![],'jaws':![],'custom':![],'update':![],'description':_0x600e('0x5'),'machineUuid':hardware[_0x600e('0x3')](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};function getLicense(_0x610582){return new BPromise(function(_0x1755fe,_0x52bbb1){return db['License'][_0x600e('0x6')](_[_0x600e('0x7')](_0x610582,{'raw':!![],'where':{'id':0x1}}))[_0x600e('0x8')](function(_0x41a5f9){return checkLicense(_0x41a5f9,null);})[_0x600e('0x8')](function(_0x557a17){_0x1755fe(_0x557a17);return;})[_0x600e('0x9')](function(_0x1cc602){_0x52bbb1(_0x1cc602);});});}function checkLicense(_0x1196d6,_0x4f1d20){if(!_0x1196d6){demoLicense['uuid']=_0x1196d6[_0x600e('0xa')];return demoLicense;}try{var _0x4efa11=_0x4f1d20||_0x1196d6[_0x600e('0xb')];if(_[_0x600e('0xc')](_0x4efa11)){throw new Error('License\x20key\x20value\x20not\x20found');}var _0x47f146=_0x1196d6[_0x600e('0xa')];var _0x43a8a4=_0x1196d6[_0x600e('0xd')];var _0x527e9e=_0x47f146[_0x600e('0xe')]('-')[0x4];var _0x1e5d80=_0x47f146[_0x600e('0xe')]('-')[0x0];var _0x3b41de=encryptor[_0x600e('0xf')](_0x4efa11,util[_0x600e('0x10')](_0x600e('0x11'),_0x527e9e,_0x47f146,_0x1e5d80));var _0x4f99d9=JSON[_0x600e('0x12')](_0x3b41de);_0x4f99d9[_0x600e('0x13')]=![];_0x4f99d9[_0x600e('0x14')]=_0x47f146;_0x4f99d9[_0x600e('0x15')]=hardware[_0x600e('0x3')]();if(_0x43a8a4){var _0x6c92fb=encryptor[_0x600e('0xf')](_0x43a8a4);_0x4f99d9['gray']=_0x6c92fb;_0x4f99d9['deadline']=moment(_0x6c92fb)[_0x600e('0x16')](0x7,_0x600e('0x17'))[_0x600e('0x10')]();_0x4f99d9[_0x600e('0x18')]=_0x4f99d9['uuid']!=_0x4f99d9['machineUuid']?_0x600e('0x19'):_0x600e('0x1a');}return _0x4f99d9;}catch(_0x4baa72){breakingLicense[_0x600e('0x14')]=_0x1196d6['data1'];breakingLicense[_0x600e('0x1b')]=_0x4baa72[_0x600e('0x1b')];return breakingLicense;}}function getLimits(){return new BPromise(function(_0x5d8552,_0x4ecb5f){getLicense()[_0x600e('0x8')](function(_0x483bc5){return db[_0x600e('0x1c')][_0x600e('0x1d')]({'attributes':['role',[db['sequelize']['fn'](_0x600e('0x1e'),db[_0x600e('0x1f')][_0x600e('0x20')](_0x600e('0x21'))),_0x600e('0x22')]],'group':'role','where':{'role':{'$or':[_0x600e('0x23'),_0x600e('0x24'),'telephone']}},'raw':!![]})[_0x600e('0x8')](function(_0x30d871){var _0x23354a={'user':_0x483bc5['users']||0x0,'telephone':_0x483bc5[_0x600e('0x25')]||0x0};_0x30d871[_0x600e('0x26')](function(_0x43c568){var _0x2febf4=_0x43c568[_0x600e('0x21')]===_0x600e('0x23')?_0x600e('0x24'):_0x43c568[_0x600e('0x21')];_0x23354a[_0x2febf4]-=_0x43c568['count'];if(_0x23354a[_0x2febf4]<0x0)_0x23354a[_0x2febf4]=0x0;});_0x5d8552(_0x23354a);return;});})['catch'](function(_0x4fef5a){_0x4ecb5f(_0x4fef5a);});});}function checkUserLimits(_0xb6d974){return new BPromise(function(_0xef9a87,_0x45e645){getLimits()[_0x600e('0x8')](function(_0x182026){var _0x377e7b=_[_0x600e('0x27')](_[_0x600e('0x28')](_0xb6d974,_0x600e('0x21')),[_0x600e('0x23'),_0x600e('0x24'),_0x600e('0x29')]);var _0x581162=(_0x377e7b[_0x600e('0x23')]||0x0)+(_0x377e7b[_0x600e('0x24')]||0x0);var _0x18620c=_0x377e7b['telephone']||0x0;if(_0x581162>_0x182026['user'])return _0x45e645(_0x600e('0x2a'));if(_0x18620c>_0x182026[_0x600e('0x29')])return _0x45e645('License\x20limit\x20reached\x20for\x20telephones');return _0xef9a87();})[_0x600e('0x9')](function(_0xa735dc){_0x45e645(_0xa735dc);});});}module[_0x600e('0x2b')]={'checkLicense':checkLicense,'checkUserLimits':checkUserLimits,'getLicense':getLicense};