c72d0dec818019a0c67f30c01ec27bce641588ca
[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 _0xe55c=['isEmpty','License\x20key\x20value\x20not\x20found','data1','data2','split','%s:%s:%s','demo','decryptString','gray','deadline','add','days','grayReason','machineUuid','changed','disabled','message','User','role','sequelize','count','user','telephone','users','telephones','forEach','admin','pick','countBy','License\x20limit\x20reached\x20for\x20users','exports','lodash','moment','./hardware','../../components/encryptor','../../mysqldb','2027-01-01T00:00:00.000Z','Demo\x20license','getUuid','Breaking\x20license','find','then','catch','uuid','license'];(function(_0x1f7f0f,_0x56c866){var _0x467749=function(_0x44d893){while(--_0x44d893){_0x1f7f0f['push'](_0x1f7f0f['shift']());}};_0x467749(++_0x56c866);}(_0xe55c,0xa6));var _0xce55=function(_0x894352,_0x5dab9b){_0x894352=_0x894352-0x0;var _0x264863=_0xe55c[_0x894352];return _0x264863;};'use strict';var util=require('util');var _=require(_0xce55('0x0'));var moment=require(_0xce55('0x1'));var BPromise=require('bluebird');var hardware=require(_0xce55('0x2'));var encryptor=require(_0xce55('0x3'));var db=require(_0xce55('0x4'))['db'];const demoLicense={'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':_0xce55('0x5'),'chat':![],'mail':![],'fax':![],'messaging':![],'whatsapp':![],'cm':![],'dialer':![],'jscripty':![],'openchannel':![],'callysquare':0x2,'webrtc':![],'jaws':![],'custom':![],'description':_0xce55('0x6'),'machineUuid':hardware[_0xce55('0x7')](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};const breakingLicense={'breaking':!![],'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':_0xce55('0x5'),'chat':![],'mail':![],'fax':![],'messaging':![],'whatsapp':![],'cm':![],'dialer':![],'jscripty':![],'openchannel':![],'callysquare':0x2,'webrtc':![],'jaws':![],'custom':![],'update':![],'description':_0xce55('0x8'),'machineUuid':hardware[_0xce55('0x7')](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};function getLicense(_0x389c4f){return new BPromise(function(_0x4117a8,_0x3a6ac0){return db['License'][_0xce55('0x9')](_['defaults'](_0x389c4f,{'raw':!![],'where':{'id':0x1}}))[_0xce55('0xa')](function(_0x3f7423){return checkLicense(_0x3f7423,null);})['then'](function(_0x228f0b){_0x4117a8(_0x228f0b);return;})[_0xce55('0xb')](function(_0x6d9792){_0x3a6ac0(_0x6d9792);});});}function checkLicense(_0x357eab,_0x531524){if(!_0x357eab){demoLicense[_0xce55('0xc')]=_0x357eab['data1'];return demoLicense;}try{var _0x4127ec=_0x531524||_0x357eab[_0xce55('0xd')];if(_[_0xce55('0xe')](_0x4127ec)){throw new Error(_0xce55('0xf'));}var _0x53d0ce=_0x357eab[_0xce55('0x10')];var _0x5e92a2=_0x357eab[_0xce55('0x11')];var _0x4581ca=_0x53d0ce['split']('-')[0x4];var _0x1b4af6=_0x53d0ce[_0xce55('0x12')]('-')[0x0];var _0x5e5736=encryptor['decryptString'](_0x4127ec,util['format'](_0xce55('0x13'),_0x4581ca,_0x53d0ce,_0x1b4af6));var _0xc7a526=JSON['parse'](_0x5e5736);_0xc7a526[_0xce55('0x14')]=![];_0xc7a526[_0xce55('0xc')]=_0x53d0ce;_0xc7a526['machineUuid']=hardware[_0xce55('0x7')]();if(_0x5e92a2){var _0x5607a3=encryptor[_0xce55('0x15')](_0x5e92a2);_0xc7a526[_0xce55('0x16')]=_0x5607a3;_0xc7a526[_0xce55('0x17')]=moment(_0x5607a3)[_0xce55('0x18')](0x7,_0xce55('0x19'))['format']();_0xc7a526[_0xce55('0x1a')]=_0xc7a526['uuid']!=_0xc7a526[_0xce55('0x1b')]?_0xce55('0x1c'):_0xce55('0x1d');}return _0xc7a526;}catch(_0x3053ed){breakingLicense[_0xce55('0xc')]=_0x357eab['data1'];breakingLicense[_0xce55('0x1e')]=_0x3053ed['message'];return breakingLicense;}}function getLimits(){return new BPromise(function(_0x2efe08,_0x3228e3){getLicense()[_0xce55('0xa')](function(_0x32c23d){return db[_0xce55('0x1f')]['findAll']({'attributes':[_0xce55('0x20'),[db[_0xce55('0x21')]['fn']('COUNT',db[_0xce55('0x21')]['col'](_0xce55('0x20'))),_0xce55('0x22')]],'group':'role','where':{'role':{'$or':['admin',_0xce55('0x23'),_0xce55('0x24')]}},'raw':!![]})['then'](function(_0x1cd1d0){var _0x2a7ef9={'user':_0x32c23d[_0xce55('0x25')]||0x0,'telephone':_0x32c23d[_0xce55('0x26')]||0x0};_0x1cd1d0[_0xce55('0x27')](function(_0x48fecd){var _0x2998c4=_0x48fecd['role']===_0xce55('0x28')?_0xce55('0x23'):_0x48fecd[_0xce55('0x20')];_0x2a7ef9[_0x2998c4]-=_0x48fecd[_0xce55('0x22')];if(_0x2a7ef9[_0x2998c4]<0x0)_0x2a7ef9[_0x2998c4]=0x0;});_0x2efe08(_0x2a7ef9);return;});})[_0xce55('0xb')](function(_0x301eca){_0x3228e3(_0x301eca);});});}function checkUserLimits(_0x573992){return new BPromise(function(_0x503da3,_0x322d66){getLimits()[_0xce55('0xa')](function(_0x2d566e){var _0x550a11=_[_0xce55('0x29')](_[_0xce55('0x2a')](_0x573992,_0xce55('0x20')),[_0xce55('0x28'),_0xce55('0x23'),_0xce55('0x24')]);var _0x26f7de=(_0x550a11[_0xce55('0x28')]||0x0)+(_0x550a11[_0xce55('0x23')]||0x0);var _0x3e82dc=_0x550a11['telephone']||0x0;if(_0x26f7de>_0x2d566e[_0xce55('0x23')])return _0x322d66(_0xce55('0x2b'));if(_0x3e82dc>_0x2d566e[_0xce55('0x24')])return _0x322d66('License\x20limit\x20reached\x20for\x20telephones');return _0x503da3();})[_0xce55('0xb')](function(_0x364c83){_0x322d66(_0x364c83);});});}module[_0xce55('0x2c')]={'checkLicense':checkLicense,'checkUserLimits':checkUserLimits,'getLicense':getLicense};