5df9f9d342583826f78a6c8ebc1c437abe18af66
[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 _0xf478=['changed','message','User','findAll','role','COUNT','col','count','admin','user','telephone','telephones','forEach','pick','countBy','License\x20limit\x20reached\x20for\x20telephones','lodash','moment','bluebird','../../components/encryptor','../../mysqldb','Demo\x20license','getUuid','2027-01-01T00:00:00.000Z','Breaking\x20license','License','find','defaults','then','catch','data1','License\x20key\x20value\x20not\x20found','split','decryptString','%s:%s:%s','parse','machineUuid','gray','deadline','add','days','format','grayReason','uuid'];(function(_0x239b31,_0x44a64d){var _0x41c8be=function(_0x27f031){while(--_0x27f031){_0x239b31['push'](_0x239b31['shift']());}};_0x41c8be(++_0x44a64d);}(_0xf478,0x170));var _0x8f47=function(_0x2a6809,_0x44edde){_0x2a6809=_0x2a6809-0x0;var _0x11c371=_0xf478[_0x2a6809];return _0x11c371;};'use strict';var util=require('util');var _=require(_0x8f47('0x0'));var moment=require(_0x8f47('0x1'));var BPromise=require(_0x8f47('0x2'));var hardware=require('./hardware');var encryptor=require(_0x8f47('0x3'));var db=require(_0x8f47('0x4'))['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':_0x8f47('0x5'),'machineUuid':hardware[_0x8f47('0x6')](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};const breakingLicense={'breaking':!![],'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':_0x8f47('0x7'),'chat':![],'mail':![],'fax':![],'messaging':![],'whatsapp':![],'cm':![],'dialer':![],'jscripty':![],'openchannel':![],'callysquare':0x2,'webrtc':![],'jaws':![],'custom':![],'update':![],'description':_0x8f47('0x8'),'machineUuid':hardware['getUuid'](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};function getLicense(_0x208f54){return new BPromise(function(_0x5ebd16,_0xa3ffd9){return db[_0x8f47('0x9')][_0x8f47('0xa')](_[_0x8f47('0xb')](_0x208f54,{'raw':!![],'where':{'id':0x1}}))['then'](function(_0x2a8e87){return checkLicense(_0x2a8e87,null);})[_0x8f47('0xc')](function(_0x5e0016){_0x5ebd16(_0x5e0016);return;})[_0x8f47('0xd')](function(_0x247355){_0xa3ffd9(_0x247355);});});}function checkLicense(_0x58aab4,_0x3c0f18){if(!_0x58aab4){demoLicense['uuid']=_0x58aab4[_0x8f47('0xe')];return demoLicense;}try{var _0x1f26e3=_0x3c0f18||_0x58aab4['license'];if(_['isEmpty'](_0x1f26e3)){throw new Error(_0x8f47('0xf'));}var _0x4322ec=_0x58aab4['data1'];var _0x55432c=_0x58aab4['data2'];var _0x33bb62=_0x4322ec[_0x8f47('0x10')]('-')[0x4];var _0x40e7d0=_0x4322ec[_0x8f47('0x10')]('-')[0x0];var _0x5cc969=encryptor[_0x8f47('0x11')](_0x1f26e3,util['format'](_0x8f47('0x12'),_0x33bb62,_0x4322ec,_0x40e7d0));var _0x39797=JSON[_0x8f47('0x13')](_0x5cc969);_0x39797['demo']=![];_0x39797['uuid']=_0x4322ec;_0x39797[_0x8f47('0x14')]=hardware['getUuid']();if(_0x55432c){var _0x53e112=encryptor['decryptString'](_0x55432c);_0x39797[_0x8f47('0x15')]=_0x53e112;_0x39797[_0x8f47('0x16')]=moment(_0x53e112)[_0x8f47('0x17')](0x7,_0x8f47('0x18'))[_0x8f47('0x19')]();_0x39797[_0x8f47('0x1a')]=_0x39797[_0x8f47('0x1b')]!=_0x39797[_0x8f47('0x14')]?_0x8f47('0x1c'):'disabled';}return _0x39797;}catch(_0x130fbf){breakingLicense[_0x8f47('0x1b')]=_0x58aab4[_0x8f47('0xe')];breakingLicense[_0x8f47('0x1d')]=_0x130fbf[_0x8f47('0x1d')];return breakingLicense;}}function getLimits(){return new BPromise(function(_0x1aaf2f,_0x212f5f){getLicense()[_0x8f47('0xc')](function(_0x2c82a3){return db[_0x8f47('0x1e')][_0x8f47('0x1f')]({'attributes':[_0x8f47('0x20'),[db['sequelize']['fn'](_0x8f47('0x21'),db['sequelize'][_0x8f47('0x22')]('role')),_0x8f47('0x23')]],'group':'role','where':{'role':{'$or':[_0x8f47('0x24'),_0x8f47('0x25'),_0x8f47('0x26')]}},'raw':!![]})['then'](function(_0x5d6f3f){var _0x2a9a0e={'user':_0x2c82a3['users']||0x0,'telephone':_0x2c82a3[_0x8f47('0x27')]||0x0};_0x5d6f3f[_0x8f47('0x28')](function(_0x3f9a0d){var _0x2930d5=_0x3f9a0d[_0x8f47('0x20')]===_0x8f47('0x24')?_0x8f47('0x25'):_0x3f9a0d['role'];_0x2a9a0e[_0x2930d5]-=_0x3f9a0d[_0x8f47('0x23')];if(_0x2a9a0e[_0x2930d5]<0x0)_0x2a9a0e[_0x2930d5]=0x0;});_0x1aaf2f(_0x2a9a0e);return;});})[_0x8f47('0xd')](function(_0x266a93){_0x212f5f(_0x266a93);});});}function checkUserLimits(_0x3915d0){return new BPromise(function(_0x3e18ce,_0x526e8b){getLimits()['then'](function(_0x413a13){var _0x3bbe85=_[_0x8f47('0x29')](_[_0x8f47('0x2a')](_0x3915d0,'role'),[_0x8f47('0x24'),_0x8f47('0x25'),_0x8f47('0x26')]);var _0x58c0d0=(_0x3bbe85[_0x8f47('0x24')]||0x0)+(_0x3bbe85[_0x8f47('0x25')]||0x0);var _0x766e82=_0x3bbe85[_0x8f47('0x26')]||0x0;if(_0x58c0d0>_0x413a13[_0x8f47('0x25')])return _0x526e8b('License\x20limit\x20reached\x20for\x20users');if(_0x766e82>_0x413a13['telephone'])return _0x526e8b(_0x8f47('0x2b'));return _0x3e18ce();})[_0x8f47('0xd')](function(_0x32f01f){_0x526e8b(_0x32f01f);});});}module['exports']={'checkLicense':checkLicense,'checkUserLimits':checkUserLimits,'getLicense':getLicense};