efbb86d5676f843f18757fbe5528bf375cef33dc
[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 _0x3963=['countBy','telephone','user','License\x20limit\x20reached\x20for\x20telephones','util','lodash','moment','bluebird','./hardware','../../mysqldb','2027-01-01T00:00:00.000Z','getUuid','defaults','data1','license','License\x20key\x20value\x20not\x20found','split','decryptString','format','%s:%s:%s','demo','uuid','machineUuid','gray','deadline','days','grayReason','changed','disabled','message','then','findAll','role','sequelize','COUNT','col','forEach','admin','count','catch'];(function(_0x1c24e9,_0x2e038a){var _0x5460e1=function(_0x10322e){while(--_0x10322e){_0x1c24e9['push'](_0x1c24e9['shift']());}};_0x5460e1(++_0x2e038a);}(_0x3963,0xcc));var _0x3396=function(_0xbd08b4,_0x4790ed){_0xbd08b4=_0xbd08b4-0x0;var _0x314f1e=_0x3963[_0xbd08b4];return _0x314f1e;};'use strict';var util=require(_0x3396('0x0'));var _=require(_0x3396('0x1'));var moment=require(_0x3396('0x2'));var BPromise=require(_0x3396('0x3'));var hardware=require(_0x3396('0x4'));var encryptor=require('../../components/encryptor');var db=require(_0x3396('0x5'))['db'];const demoLicense={'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':_0x3396('0x6'),'chat':![],'mail':![],'fax':![],'messaging':![],'whatsapp':![],'cm':![],'dialer':![],'jscripty':![],'openchannel':![],'callysquare':0x2,'webrtc':![],'jaws':![],'custom':![],'description':'Demo\x20license','machineUuid':hardware[_0x3396('0x7')](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};const breakingLicense={'breaking':!![],'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':_0x3396('0x6'),'chat':![],'mail':![],'fax':![],'messaging':![],'whatsapp':![],'cm':![],'dialer':![],'jscripty':![],'openchannel':![],'callysquare':0x2,'webrtc':![],'jaws':![],'custom':![],'update':![],'description':'Breaking\x20license','machineUuid':hardware[_0x3396('0x7')](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};function getLicense(_0x3f84f3){return new BPromise(function(_0x1f97a9,_0x468223){return db['License']['find'](_[_0x3396('0x8')](_0x3f84f3,{'raw':!![],'where':{'id':0x1}}))['then'](function(_0x4a7369){return checkLicense(_0x4a7369,null);})['then'](function(_0x430cd5){_0x1f97a9(_0x430cd5);return;})['catch'](function(_0x4fa11c){_0x468223(_0x4fa11c);});});}function checkLicense(_0x4c8cb1,_0x5a099c){if(!_0x4c8cb1){demoLicense['uuid']=_0x4c8cb1[_0x3396('0x9')];return demoLicense;}try{var _0x13e16e=_0x5a099c||_0x4c8cb1[_0x3396('0xa')];if(_['isEmpty'](_0x13e16e)){throw new Error(_0x3396('0xb'));}var _0x350ed6=_0x4c8cb1[_0x3396('0x9')];var _0x2c8193=_0x4c8cb1['data2'];var _0x269505=_0x350ed6[_0x3396('0xc')]('-')[0x4];var _0x2132b8=_0x350ed6[_0x3396('0xc')]('-')[0x0];var _0x1f2081=encryptor[_0x3396('0xd')](_0x13e16e,util[_0x3396('0xe')](_0x3396('0xf'),_0x269505,_0x350ed6,_0x2132b8));var _0x31cd99=JSON['parse'](_0x1f2081);_0x31cd99[_0x3396('0x10')]=![];_0x31cd99[_0x3396('0x11')]=_0x350ed6;_0x31cd99[_0x3396('0x12')]=hardware[_0x3396('0x7')]();if(_0x2c8193){var _0x40ce93=encryptor[_0x3396('0xd')](_0x2c8193);_0x31cd99[_0x3396('0x13')]=_0x40ce93;_0x31cd99[_0x3396('0x14')]=moment(_0x40ce93)['add'](0x7,_0x3396('0x15'))['format']();_0x31cd99[_0x3396('0x16')]=_0x31cd99[_0x3396('0x11')]!=_0x31cd99[_0x3396('0x12')]?_0x3396('0x17'):_0x3396('0x18');}return _0x31cd99;}catch(_0x329178){breakingLicense[_0x3396('0x11')]=_0x4c8cb1[_0x3396('0x9')];breakingLicense['message']=_0x329178[_0x3396('0x19')];return breakingLicense;}}function getLimits(){return new BPromise(function(_0x167a06,_0x5eefea){getLicense()[_0x3396('0x1a')](function(_0x4f201d){return db['User'][_0x3396('0x1b')]({'attributes':[_0x3396('0x1c'),[db[_0x3396('0x1d')]['fn'](_0x3396('0x1e'),db['sequelize'][_0x3396('0x1f')](_0x3396('0x1c'))),'count']],'group':_0x3396('0x1c'),'where':{'role':{'$or':['admin','user','telephone']}},'raw':!![]})[_0x3396('0x1a')](function(_0x5061cc){var _0x617a0c={'user':_0x4f201d['users']||0x0,'telephone':_0x4f201d['telephones']||0x0};_0x5061cc[_0x3396('0x20')](function(_0x5ecf10){var _0x83ca27=_0x5ecf10['role']===_0x3396('0x21')?'user':_0x5ecf10[_0x3396('0x1c')];_0x617a0c[_0x83ca27]-=_0x5ecf10[_0x3396('0x22')];if(_0x617a0c[_0x83ca27]<0x0)_0x617a0c[_0x83ca27]=0x0;});_0x167a06(_0x617a0c);return;});})[_0x3396('0x23')](function(_0x27a8cb){_0x5eefea(_0x27a8cb);});});}function checkUserLimits(_0x2ac0ad){return new BPromise(function(_0x417544,_0x12bdb8){getLimits()[_0x3396('0x1a')](function(_0x5223f7){var _0x2fe0a6=_['pick'](_[_0x3396('0x24')](_0x2ac0ad,_0x3396('0x1c')),[_0x3396('0x21'),'user',_0x3396('0x25')]);var _0x544ac3=(_0x2fe0a6[_0x3396('0x21')]||0x0)+(_0x2fe0a6[_0x3396('0x26')]||0x0);var _0x2e0b18=_0x2fe0a6[_0x3396('0x25')]||0x0;if(_0x544ac3>_0x5223f7[_0x3396('0x26')])return _0x12bdb8('License\x20limit\x20reached\x20for\x20users');if(_0x2e0b18>_0x5223f7[_0x3396('0x25')])return _0x12bdb8(_0x3396('0x27'));return _0x417544();})[_0x3396('0x23')](function(_0x4932a6){_0x12bdb8(_0x4932a6);});});}module['exports']={'checkLicense':checkLicense,'checkUserLimits':checkUserLimits,'getLicense':getLicense};