Built motion from commit (unavailable).|2.5.14
[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 _0x9e9e=['2027-01-01T00:00:00.000Z','Demo\x20license','getUuid','License','find','defaults','then','catch','data1','license','isEmpty','data2','split','decryptString','format','parse','demo','gray','deadline','add','days','grayReason','uuid','machineUuid','changed','disabled','message','findAll','role','COUNT','sequelize','col','count','admin','user','telephone','users','pick','License\x20limit\x20reached\x20for\x20users','License\x20limit\x20reached\x20for\x20telephones','exports','util','moment','bluebird','../../components/encryptor','../../mysqldb'];(function(_0x5b02ce,_0x22679e){var _0x1fcca4=function(_0x182a30){while(--_0x182a30){_0x5b02ce['push'](_0x5b02ce['shift']());}};_0x1fcca4(++_0x22679e);}(_0x9e9e,0x1c7));var _0xe9e9=function(_0x36ed48,_0x1ee0d4){_0x36ed48=_0x36ed48-0x0;var _0x51c63a=_0x9e9e[_0x36ed48];return _0x51c63a;};'use strict';var util=require(_0xe9e9('0x0'));var _=require('lodash');var moment=require(_0xe9e9('0x1'));var BPromise=require(_0xe9e9('0x2'));var hardware=require('./hardware');var encryptor=require(_0xe9e9('0x3'));var db=require(_0xe9e9('0x4'))['db'];const demoLicense={'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':_0xe9e9('0x5'),'chat':![],'mail':![],'fax':![],'messaging':![],'whatsapp':![],'cm':![],'dialer':![],'jscripty':![],'openchannel':![],'callysquare':0x2,'webrtc':![],'jaws':![],'custom':![],'description':_0xe9e9('0x6'),'machineUuid':hardware[_0xe9e9('0x7')](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};const breakingLicense={'breaking':!![],'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':_0xe9e9('0x5'),'chat':![],'mail':![],'fax':![],'messaging':![],'whatsapp':![],'cm':![],'dialer':![],'jscripty':![],'openchannel':![],'callysquare':0x2,'webrtc':![],'jaws':![],'custom':![],'update':![],'description':'Breaking\x20license','machineUuid':hardware[_0xe9e9('0x7')](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};function getLicense(_0x47d839){return new BPromise(function(_0x1b1d2a,_0xfdb2ce){return db[_0xe9e9('0x8')][_0xe9e9('0x9')](_[_0xe9e9('0xa')](_0x47d839,{'raw':!![],'where':{'id':0x1}}))[_0xe9e9('0xb')](function(_0x434efa){return checkLicense(_0x434efa,null);})[_0xe9e9('0xb')](function(_0x42e4b9){_0x1b1d2a(_0x42e4b9);return;})[_0xe9e9('0xc')](function(_0x1ca15d){_0xfdb2ce(_0x1ca15d);});});}function checkLicense(_0x330edf,_0x1fad92){if(!_0x330edf){demoLicense['uuid']=_0x330edf[_0xe9e9('0xd')];return demoLicense;}try{var _0x379a80=_0x1fad92||_0x330edf[_0xe9e9('0xe')];if(_[_0xe9e9('0xf')](_0x379a80)){throw new Error('License\x20key\x20value\x20not\x20found');}var _0x1b0beb=_0x330edf[_0xe9e9('0xd')];var _0x59132d=_0x330edf[_0xe9e9('0x10')];var _0x43f1ac=_0x1b0beb[_0xe9e9('0x11')]('-')[0x4];var _0x1987b7=_0x1b0beb[_0xe9e9('0x11')]('-')[0x0];var _0x29e2ce=encryptor[_0xe9e9('0x12')](_0x379a80,util[_0xe9e9('0x13')]('%s:%s:%s',_0x43f1ac,_0x1b0beb,_0x1987b7));var _0x9c3400=JSON[_0xe9e9('0x14')](_0x29e2ce);_0x9c3400[_0xe9e9('0x15')]=![];_0x9c3400['uuid']=_0x1b0beb;_0x9c3400['machineUuid']=hardware[_0xe9e9('0x7')]();if(_0x59132d){var _0x394497=encryptor[_0xe9e9('0x12')](_0x59132d);_0x9c3400[_0xe9e9('0x16')]=_0x394497;_0x9c3400[_0xe9e9('0x17')]=moment(_0x394497)[_0xe9e9('0x18')](0x7,_0xe9e9('0x19'))[_0xe9e9('0x13')]();_0x9c3400[_0xe9e9('0x1a')]=_0x9c3400[_0xe9e9('0x1b')]!=_0x9c3400[_0xe9e9('0x1c')]?_0xe9e9('0x1d'):_0xe9e9('0x1e');}return _0x9c3400;}catch(_0x24c780){breakingLicense[_0xe9e9('0x1b')]=_0x330edf[_0xe9e9('0xd')];breakingLicense[_0xe9e9('0x1f')]=_0x24c780[_0xe9e9('0x1f')];return breakingLicense;}}function getLimits(){return new BPromise(function(_0x4bb9ed,_0x3c7062){getLicense()[_0xe9e9('0xb')](function(_0x3c53a8){return db['User'][_0xe9e9('0x20')]({'attributes':[_0xe9e9('0x21'),[db['sequelize']['fn'](_0xe9e9('0x22'),db[_0xe9e9('0x23')][_0xe9e9('0x24')](_0xe9e9('0x21'))),_0xe9e9('0x25')]],'group':_0xe9e9('0x21'),'where':{'role':{'$or':[_0xe9e9('0x26'),_0xe9e9('0x27'),_0xe9e9('0x28')]}},'raw':!![]})['then'](function(_0x3a5b92){var _0x3a9cd0={'user':_0x3c53a8[_0xe9e9('0x29')]||0x0,'telephone':_0x3c53a8['telephones']||0x0};_0x3a5b92['forEach'](function(_0x549fdf){var _0x4feb5d=_0x549fdf[_0xe9e9('0x21')]==='admin'?_0xe9e9('0x27'):_0x549fdf['role'];_0x3a9cd0[_0x4feb5d]-=_0x549fdf[_0xe9e9('0x25')];if(_0x3a9cd0[_0x4feb5d]<0x0)_0x3a9cd0[_0x4feb5d]=0x0;});_0x4bb9ed(_0x3a9cd0);return;});})['catch'](function(_0x11d062){_0x3c7062(_0x11d062);});});}function checkUserLimits(_0x439ba5){return new BPromise(function(_0x535899,_0x124fa8){getLimits()['then'](function(_0x382123){var _0x5a2880=_[_0xe9e9('0x2a')](_['countBy'](_0x439ba5,_0xe9e9('0x21')),['admin',_0xe9e9('0x27'),_0xe9e9('0x28')]);var _0x2a29f3=(_0x5a2880[_0xe9e9('0x26')]||0x0)+(_0x5a2880['user']||0x0);var _0x384597=_0x5a2880[_0xe9e9('0x28')]||0x0;if(_0x2a29f3>_0x382123['user'])return _0x124fa8(_0xe9e9('0x2b'));if(_0x384597>_0x382123[_0xe9e9('0x28')])return _0x124fa8(_0xe9e9('0x2c'));return _0x535899();})[_0xe9e9('0xc')](function(_0x2acc20){_0x124fa8(_0x2acc20);});});}module[_0xe9e9('0x2d')]={'checkLicense':checkLicense,'checkUserLimits':checkUserLimits,'getLicense':getLicense};