6d4afd744d9dfb8904f1214a3930b506758d6440
[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 _0xf980=['demo','deadline','add','days','grayReason','machineUuid','changed','disabled','User','findAll','role','sequelize','COUNT','col','user','telephone','telephones','forEach','admin','count','countBy','License\x20limit\x20reached\x20for\x20telephones','lodash','moment','./hardware','../../components/encryptor','../../mysqldb','2027-01-01T00:00:00.000Z','getUuid','Breaking\x20license','find','then','catch','uuid','data1','license','isEmpty','License\x20key\x20value\x20not\x20found','data2','split','decryptString','format','parse'];(function(_0x321bb2,_0x202794){var _0x9c12ed=function(_0x263dd3){while(--_0x263dd3){_0x321bb2['push'](_0x321bb2['shift']());}};_0x9c12ed(++_0x202794);}(_0xf980,0x118));var _0x0f98=function(_0x50439d,_0x3aed4c){_0x50439d=_0x50439d-0x0;var _0x5dc279=_0xf980[_0x50439d];return _0x5dc279;};'use strict';var util=require('util');var _=require(_0x0f98('0x0'));var moment=require(_0x0f98('0x1'));var BPromise=require('bluebird');var hardware=require(_0x0f98('0x2'));var encryptor=require(_0x0f98('0x3'));var db=require(_0x0f98('0x4'))['db'];const demoLicense={'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':_0x0f98('0x5'),'chat':![],'mail':![],'fax':![],'messaging':![],'whatsapp':![],'cm':![],'dialer':![],'jscripty':![],'openchannel':![],'callysquare':0x2,'webrtc':![],'jaws':![],'custom':![],'description':'Demo\x20license','machineUuid':hardware[_0x0f98('0x6')](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};const breakingLicense={'breaking':!![],'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':_0x0f98('0x5'),'chat':![],'mail':![],'fax':![],'messaging':![],'whatsapp':![],'cm':![],'dialer':![],'jscripty':![],'openchannel':![],'callysquare':0x2,'webrtc':![],'jaws':![],'custom':![],'update':![],'description':_0x0f98('0x7'),'machineUuid':hardware[_0x0f98('0x6')](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};function getLicense(_0x27dcbc){return new BPromise(function(_0x387d89,_0x5af53b){return db['License'][_0x0f98('0x8')](_['defaults'](_0x27dcbc,{'raw':!![],'where':{'id':0x1}}))['then'](function(_0x2c4a0d){return checkLicense(_0x2c4a0d,null);})[_0x0f98('0x9')](function(_0x523399){_0x387d89(_0x523399);return;})[_0x0f98('0xa')](function(_0xc59445){_0x5af53b(_0xc59445);});});}function checkLicense(_0x436c60,_0xf67212){if(!_0x436c60){demoLicense[_0x0f98('0xb')]=_0x436c60[_0x0f98('0xc')];return demoLicense;}try{var _0x1c1aee=_0xf67212||_0x436c60[_0x0f98('0xd')];if(_[_0x0f98('0xe')](_0x1c1aee)){throw new Error(_0x0f98('0xf'));}var _0x361284=_0x436c60[_0x0f98('0xc')];var _0xd719ba=_0x436c60[_0x0f98('0x10')];var _0x46584f=_0x361284['split']('-')[0x4];var _0x11d55a=_0x361284[_0x0f98('0x11')]('-')[0x0];var _0x4b6479=encryptor[_0x0f98('0x12')](_0x1c1aee,util[_0x0f98('0x13')]('%s:%s:%s',_0x46584f,_0x361284,_0x11d55a));var _0x19aaba=JSON[_0x0f98('0x14')](_0x4b6479);_0x19aaba[_0x0f98('0x15')]=![];_0x19aaba[_0x0f98('0xb')]=_0x361284;_0x19aaba['machineUuid']=hardware['getUuid']();if(_0xd719ba){var _0x5b921e=encryptor[_0x0f98('0x12')](_0xd719ba);_0x19aaba['gray']=_0x5b921e;_0x19aaba[_0x0f98('0x16')]=moment(_0x5b921e)[_0x0f98('0x17')](0x7,_0x0f98('0x18'))['format']();_0x19aaba[_0x0f98('0x19')]=_0x19aaba[_0x0f98('0xb')]!=_0x19aaba[_0x0f98('0x1a')]?_0x0f98('0x1b'):_0x0f98('0x1c');}return _0x19aaba;}catch(_0x1abb38){breakingLicense[_0x0f98('0xb')]=_0x436c60['data1'];breakingLicense['message']=_0x1abb38['message'];return breakingLicense;}}function getLimits(){return new BPromise(function(_0x58fed1,_0x191f55){getLicense()[_0x0f98('0x9')](function(_0xe77fbf){return db[_0x0f98('0x1d')][_0x0f98('0x1e')]({'attributes':[_0x0f98('0x1f'),[db[_0x0f98('0x20')]['fn'](_0x0f98('0x21'),db[_0x0f98('0x20')][_0x0f98('0x22')]('role')),'count']],'group':'role','where':{'role':{'$or':['admin',_0x0f98('0x23'),_0x0f98('0x24')]}},'raw':!![]})['then'](function(_0x3fe703){var _0x53cdda={'user':_0xe77fbf['users']||0x0,'telephone':_0xe77fbf[_0x0f98('0x25')]||0x0};_0x3fe703[_0x0f98('0x26')](function(_0x476baf){var _0x2ee144=_0x476baf[_0x0f98('0x1f')]===_0x0f98('0x27')?'user':_0x476baf[_0x0f98('0x1f')];_0x53cdda[_0x2ee144]-=_0x476baf[_0x0f98('0x28')];if(_0x53cdda[_0x2ee144]<0x0)_0x53cdda[_0x2ee144]=0x0;});_0x58fed1(_0x53cdda);return;});})['catch'](function(_0x12c0ed){_0x191f55(_0x12c0ed);});});}function checkUserLimits(_0x30d1e0){return new BPromise(function(_0x345d18,_0x36eecc){getLimits()[_0x0f98('0x9')](function(_0x37f4d6){var _0x5d18f3=_['pick'](_[_0x0f98('0x29')](_0x30d1e0,_0x0f98('0x1f')),['admin',_0x0f98('0x23'),_0x0f98('0x24')]);var _0x5ecd80=(_0x5d18f3[_0x0f98('0x27')]||0x0)+(_0x5d18f3[_0x0f98('0x23')]||0x0);var _0x5b19d8=_0x5d18f3[_0x0f98('0x24')]||0x0;if(_0x5ecd80>_0x37f4d6[_0x0f98('0x23')])return _0x36eecc('License\x20limit\x20reached\x20for\x20users');if(_0x5b19d8>_0x37f4d6[_0x0f98('0x24')])return _0x36eecc(_0x0f98('0x2a'));return _0x345d18();})['catch'](function(_0xa73373){_0x36eecc(_0xa73373);});});}module['exports']={'checkLicense':checkLicense,'checkUserLimits':checkUserLimits,'getLicense':getLicense};