Built motion from commit 47436d59.|2.6.7
[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 _0x2182=['sequelize','role','count','admin','user','telephone','users','telephones','forEach','pick','countBy','License\x20limit\x20reached\x20for\x20users','exports','util','bluebird','../../mysqldb','Demo\x20license','getUuid','License','defaults','then','catch','uuid','data1','license','isEmpty','License\x20key\x20value\x20not\x20found','data2','split','decryptString','%s:%s:%s','parse','demo','gray','deadline','add','grayReason','machineUuid','disabled','message','User','findAll'];(function(_0x4cf2a8,_0x5b82e7){var _0x580659=function(_0x370355){while(--_0x370355){_0x4cf2a8['push'](_0x4cf2a8['shift']());}};_0x580659(++_0x5b82e7);}(_0x2182,0xdf));var _0x2218=function(_0x3b380d,_0x4bf247){_0x3b380d=_0x3b380d-0x0;var _0x54502b=_0x2182[_0x3b380d];return _0x54502b;};'use strict';var util=require(_0x2218('0x0'));var _=require('lodash');var moment=require('moment');var BPromise=require(_0x2218('0x1'));var hardware=require('./hardware');var encryptor=require('../../components/encryptor');var db=require(_0x2218('0x2'))['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':_0x2218('0x3'),'machineUuid':hardware[_0x2218('0x4')](),'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':'Breaking\x20license','machineUuid':hardware[_0x2218('0x4')](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};function getLicense(_0x3c8184){return new BPromise(function(_0x1fe6fa,_0x7b2c25){return db[_0x2218('0x5')]['find'](_[_0x2218('0x6')](_0x3c8184,{'raw':!![],'where':{'id':0x1}}))[_0x2218('0x7')](function(_0x38d2fe){return checkLicense(_0x38d2fe,null);})['then'](function(_0x8d21b3){_0x1fe6fa(_0x8d21b3);return;})[_0x2218('0x8')](function(_0x3ce5cd){_0x7b2c25(_0x3ce5cd);});});}function checkLicense(_0x41e902,_0x15789f){if(!_0x41e902){demoLicense[_0x2218('0x9')]=_0x41e902[_0x2218('0xa')];return demoLicense;}try{var _0x5f4de1=_0x15789f||_0x41e902[_0x2218('0xb')];if(_[_0x2218('0xc')](_0x5f4de1)){throw new Error(_0x2218('0xd'));}var _0x38c0e0=_0x41e902[_0x2218('0xa')];var _0x33031=_0x41e902[_0x2218('0xe')];var _0x4c71dc=_0x38c0e0[_0x2218('0xf')]('-')[0x4];var _0x35370a=_0x38c0e0[_0x2218('0xf')]('-')[0x0];var _0x286e6a=encryptor[_0x2218('0x10')](_0x5f4de1,util['format'](_0x2218('0x11'),_0x4c71dc,_0x38c0e0,_0x35370a));var _0x14ad9a=JSON[_0x2218('0x12')](_0x286e6a);_0x14ad9a[_0x2218('0x13')]=![];_0x14ad9a['uuid']=_0x38c0e0;_0x14ad9a['machineUuid']=hardware[_0x2218('0x4')]();if(_0x33031){var _0x23c92f=encryptor[_0x2218('0x10')](_0x33031);_0x14ad9a[_0x2218('0x14')]=_0x23c92f;_0x14ad9a[_0x2218('0x15')]=moment(_0x23c92f)[_0x2218('0x16')](0x7,'days')['format']();_0x14ad9a[_0x2218('0x17')]=_0x14ad9a[_0x2218('0x9')]!=_0x14ad9a[_0x2218('0x18')]?'changed':_0x2218('0x19');}return _0x14ad9a;}catch(_0x48e5ce){breakingLicense['uuid']=_0x41e902['data1'];breakingLicense['message']=_0x48e5ce[_0x2218('0x1a')];return breakingLicense;}}function getLimits(){return new BPromise(function(_0x4df74b,_0x19e410){getLicense()[_0x2218('0x7')](function(_0x36add2){return db[_0x2218('0x1b')][_0x2218('0x1c')]({'attributes':['role',[db[_0x2218('0x1d')]['fn']('COUNT',db[_0x2218('0x1d')]['col'](_0x2218('0x1e'))),_0x2218('0x1f')]],'group':_0x2218('0x1e'),'where':{'role':{'$or':[_0x2218('0x20'),_0x2218('0x21'),_0x2218('0x22')]}},'raw':!![]})[_0x2218('0x7')](function(_0xfb1ba3){var _0xfaf75={'user':_0x36add2[_0x2218('0x23')]||0x0,'telephone':_0x36add2[_0x2218('0x24')]||0x0};_0xfb1ba3[_0x2218('0x25')](function(_0xd2588){var _0x424ea4=_0xd2588[_0x2218('0x1e')]===_0x2218('0x20')?_0x2218('0x21'):_0xd2588[_0x2218('0x1e')];_0xfaf75[_0x424ea4]-=_0xd2588[_0x2218('0x1f')];if(_0xfaf75[_0x424ea4]<0x0)_0xfaf75[_0x424ea4]=0x0;});_0x4df74b(_0xfaf75);return;});})[_0x2218('0x8')](function(_0x10caaf){_0x19e410(_0x10caaf);});});}function checkUserLimits(_0x4f00aa){return new BPromise(function(_0x35afdf,_0x565e08){getLimits()[_0x2218('0x7')](function(_0x76543f){var _0x179536=_[_0x2218('0x26')](_[_0x2218('0x27')](_0x4f00aa,'role'),[_0x2218('0x20'),_0x2218('0x21'),_0x2218('0x22')]);var _0x4a86da=(_0x179536[_0x2218('0x20')]||0x0)+(_0x179536[_0x2218('0x21')]||0x0);var _0x5b0290=_0x179536['telephone']||0x0;if(_0x4a86da>_0x76543f[_0x2218('0x21')])return _0x565e08(_0x2218('0x28'));if(_0x5b0290>_0x76543f[_0x2218('0x22')])return _0x565e08('License\x20limit\x20reached\x20for\x20telephones');return _0x35afdf();})[_0x2218('0x8')](function(_0x3d470e){_0x565e08(_0x3d470e);});});}module[_0x2218('0x29')]={'checkLicense':checkLicense,'checkUserLimits':checkUserLimits,'getLicense':getLicense};