Built motion from commit d301b742.|2.6.29
[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 _0x43df=['format','%s:%s:%s','demo','machineUuid','gray','deadline','add','days','disabled','message','User','findAll','role','sequelize','count','admin','telephone','users','telephones','forEach','user','pick','countBy','License\x20limit\x20reached\x20for\x20telephones','lodash','moment','2027-01-01T00:00:00.000Z','getUuid','Breaking\x20license','License','defaults','then','catch','uuid','data1','license','isEmpty','License\x20key\x20value\x20not\x20found','data2','split','decryptString'];(function(_0x1fc122,_0x5e2c17){var _0xa2cb13=function(_0x263b13){while(--_0x263b13){_0x1fc122['push'](_0x1fc122['shift']());}};_0xa2cb13(++_0x5e2c17);}(_0x43df,0x1b2));var _0xf43d=function(_0x434380,_0x46abb2){_0x434380=_0x434380-0x0;var _0x5973a1=_0x43df[_0x434380];return _0x5973a1;};'use strict';var util=require('util');var _=require(_0xf43d('0x0'));var moment=require(_0xf43d('0x1'));var BPromise=require('bluebird');var hardware=require('./hardware');var encryptor=require('../../components/encryptor');var db=require('../../mysqldb')['db'];const demoLicense={'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':_0xf43d('0x2'),'chat':![],'mail':![],'fax':![],'messaging':![],'whatsapp':![],'cm':![],'dialer':![],'jscripty':![],'openchannel':![],'callysquare':0x2,'webrtc':![],'jaws':![],'custom':![],'description':'Demo\x20license','machineUuid':hardware[_0xf43d('0x3')](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};const breakingLicense={'breaking':!![],'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':![],'update':![],'description':_0xf43d('0x4'),'machineUuid':hardware['getUuid'](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};function getLicense(_0x5b2670){return new BPromise(function(_0xb1f12a,_0x20778f){return db[_0xf43d('0x5')]['find'](_[_0xf43d('0x6')](_0x5b2670,{'raw':!![],'where':{'id':0x1}}))[_0xf43d('0x7')](function(_0x1e1462){return checkLicense(_0x1e1462,null);})[_0xf43d('0x7')](function(_0x4dfb35){_0xb1f12a(_0x4dfb35);return;})[_0xf43d('0x8')](function(_0x413ddd){_0x20778f(_0x413ddd);});});}function checkLicense(_0x43bb1b,_0x2dd30f){if(!_0x43bb1b){demoLicense[_0xf43d('0x9')]=_0x43bb1b[_0xf43d('0xa')];return demoLicense;}try{var _0x37971d=_0x2dd30f||_0x43bb1b[_0xf43d('0xb')];if(_[_0xf43d('0xc')](_0x37971d)){throw new Error(_0xf43d('0xd'));}var _0x3e513f=_0x43bb1b[_0xf43d('0xa')];var _0xb7c596=_0x43bb1b[_0xf43d('0xe')];var _0xfa67ee=_0x3e513f[_0xf43d('0xf')]('-')[0x4];var _0x402c23=_0x3e513f[_0xf43d('0xf')]('-')[0x0];var _0x527a08=encryptor[_0xf43d('0x10')](_0x37971d,util[_0xf43d('0x11')](_0xf43d('0x12'),_0xfa67ee,_0x3e513f,_0x402c23));var _0x259d18=JSON['parse'](_0x527a08);_0x259d18[_0xf43d('0x13')]=![];_0x259d18[_0xf43d('0x9')]=_0x3e513f;_0x259d18[_0xf43d('0x14')]=hardware[_0xf43d('0x3')]();if(_0xb7c596){var _0x411220=encryptor[_0xf43d('0x10')](_0xb7c596);_0x259d18[_0xf43d('0x15')]=_0x411220;_0x259d18[_0xf43d('0x16')]=moment(_0x411220)[_0xf43d('0x17')](0x7,_0xf43d('0x18'))[_0xf43d('0x11')]();_0x259d18['grayReason']=_0x259d18['uuid']!=_0x259d18[_0xf43d('0x14')]?'changed':_0xf43d('0x19');}return _0x259d18;}catch(_0x39ee75){breakingLicense['uuid']=_0x43bb1b[_0xf43d('0xa')];breakingLicense[_0xf43d('0x1a')]=_0x39ee75['message'];return breakingLicense;}}function getLimits(){return new BPromise(function(_0x44140e,_0x3c58b8){getLicense()[_0xf43d('0x7')](function(_0xf44a08){return db[_0xf43d('0x1b')][_0xf43d('0x1c')]({'attributes':[_0xf43d('0x1d'),[db['sequelize']['fn']('COUNT',db[_0xf43d('0x1e')]['col'](_0xf43d('0x1d'))),_0xf43d('0x1f')]],'group':_0xf43d('0x1d'),'where':{'role':{'$or':[_0xf43d('0x20'),'user',_0xf43d('0x21')]}},'raw':!![]})[_0xf43d('0x7')](function(_0x13134f){var _0xaca3ac={'user':_0xf44a08[_0xf43d('0x22')]||0x0,'telephone':_0xf44a08[_0xf43d('0x23')]||0x0};_0x13134f[_0xf43d('0x24')](function(_0x2bc666){var _0x1de776=_0x2bc666['role']==='admin'?_0xf43d('0x25'):_0x2bc666[_0xf43d('0x1d')];_0xaca3ac[_0x1de776]-=_0x2bc666['count'];if(_0xaca3ac[_0x1de776]<0x0)_0xaca3ac[_0x1de776]=0x0;});_0x44140e(_0xaca3ac);return;});})[_0xf43d('0x8')](function(_0x263c43){_0x3c58b8(_0x263c43);});});}function checkUserLimits(_0x244f00){return new BPromise(function(_0x4df69c,_0x286c10){getLimits()[_0xf43d('0x7')](function(_0x4e5cf4){var _0x4579fc=_[_0xf43d('0x26')](_[_0xf43d('0x27')](_0x244f00,_0xf43d('0x1d')),[_0xf43d('0x20'),_0xf43d('0x25'),_0xf43d('0x21')]);var _0x527ac5=(_0x4579fc[_0xf43d('0x20')]||0x0)+(_0x4579fc[_0xf43d('0x25')]||0x0);var _0x34aee8=_0x4579fc[_0xf43d('0x21')]||0x0;if(_0x527ac5>_0x4e5cf4[_0xf43d('0x25')])return _0x286c10('License\x20limit\x20reached\x20for\x20users');if(_0x34aee8>_0x4e5cf4[_0xf43d('0x21')])return _0x286c10(_0xf43d('0x28'));return _0x4df69c();})[_0xf43d('0x8')](function(_0x24faa4){_0x286c10(_0x24faa4);});});}module['exports']={'checkLicense':checkLicense,'checkUserLimits':checkUserLimits,'getLicense':getLicense};