Built motion from commit 10af8726.|2.6.34
[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 _0x2539=['defaults','then','catch','uuid','isEmpty','data1','data2','split','%s:%s:%s','parse','demo','machineUuid','decryptString','gray','deadline','days','grayReason','disabled','message','User','role','sequelize','col','count','admin','user','telephone','users','telephones','forEach','pick','countBy','License\x20limit\x20reached\x20for\x20users','util','lodash','moment','bluebird','./hardware','../../components/encryptor','../../mysqldb','2027-01-01T00:00:00.000Z','getUuid','Breaking\x20license','License','find'];(function(_0x5c1c41,_0x407fb4){var _0x5ea2e8=function(_0x277850){while(--_0x277850){_0x5c1c41['push'](_0x5c1c41['shift']());}};_0x5ea2e8(++_0x407fb4);}(_0x2539,0x1b6));var _0x9253=function(_0x2d9201,_0x238825){_0x2d9201=_0x2d9201-0x0;var _0x9ef658=_0x2539[_0x2d9201];return _0x9ef658;};'use strict';var util=require(_0x9253('0x0'));var _=require(_0x9253('0x1'));var moment=require(_0x9253('0x2'));var BPromise=require(_0x9253('0x3'));var hardware=require(_0x9253('0x4'));var encryptor=require(_0x9253('0x5'));var db=require(_0x9253('0x6'))['db'];const demoLicense={'demo':!![],'agents':0x2,'telephones':0x0,'users':0x1,'expiration':_0x9253('0x7'),'chat':![],'mail':![],'fax':![],'messaging':![],'whatsapp':![],'cm':![],'dialer':![],'jscripty':![],'openchannel':![],'callysquare':0x2,'webrtc':![],'jaws':![],'custom':![],'description':'Demo\x20license','machineUuid':hardware[_0x9253('0x8')](),'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':_0x9253('0x9'),'machineUuid':hardware[_0x9253('0x8')](),'virtual':0x0,'voice':!![],'screenrecording':![],'preferred':![],'ai':![]};function getLicense(_0x5c7f13){return new BPromise(function(_0x40d592,_0x4772f4){return db[_0x9253('0xa')][_0x9253('0xb')](_[_0x9253('0xc')](_0x5c7f13,{'raw':!![],'where':{'id':0x1}}))[_0x9253('0xd')](function(_0x21812f){return checkLicense(_0x21812f,null);})[_0x9253('0xd')](function(_0xe4599a){_0x40d592(_0xe4599a);return;})[_0x9253('0xe')](function(_0x4f8f87){_0x4772f4(_0x4f8f87);});});}function checkLicense(_0x1797db,_0x3d7f36){if(!_0x1797db){demoLicense[_0x9253('0xf')]=_0x1797db['data1'];return demoLicense;}try{var _0x1ec255=_0x3d7f36||_0x1797db['license'];if(_[_0x9253('0x10')](_0x1ec255)){throw new Error('License\x20key\x20value\x20not\x20found');}var _0x2a75c9=_0x1797db[_0x9253('0x11')];var _0x5297bc=_0x1797db[_0x9253('0x12')];var _0x1c5b64=_0x2a75c9[_0x9253('0x13')]('-')[0x4];var _0x593692=_0x2a75c9[_0x9253('0x13')]('-')[0x0];var _0x3aaa01=encryptor['decryptString'](_0x1ec255,util['format'](_0x9253('0x14'),_0x1c5b64,_0x2a75c9,_0x593692));var _0x41708e=JSON[_0x9253('0x15')](_0x3aaa01);_0x41708e[_0x9253('0x16')]=![];_0x41708e[_0x9253('0xf')]=_0x2a75c9;_0x41708e[_0x9253('0x17')]=hardware[_0x9253('0x8')]();if(_0x5297bc){var _0x325550=encryptor[_0x9253('0x18')](_0x5297bc);_0x41708e[_0x9253('0x19')]=_0x325550;_0x41708e[_0x9253('0x1a')]=moment(_0x325550)['add'](0x7,_0x9253('0x1b'))['format']();_0x41708e[_0x9253('0x1c')]=_0x41708e[_0x9253('0xf')]!=_0x41708e[_0x9253('0x17')]?'changed':_0x9253('0x1d');}return _0x41708e;}catch(_0x37dcd2){breakingLicense[_0x9253('0xf')]=_0x1797db[_0x9253('0x11')];breakingLicense[_0x9253('0x1e')]=_0x37dcd2[_0x9253('0x1e')];return breakingLicense;}}function getLimits(){return new BPromise(function(_0x408b3a,_0x2f3c89){getLicense()[_0x9253('0xd')](function(_0x3855ee){return db[_0x9253('0x1f')]['findAll']({'attributes':[_0x9253('0x20'),[db[_0x9253('0x21')]['fn']('COUNT',db[_0x9253('0x21')][_0x9253('0x22')](_0x9253('0x20'))),_0x9253('0x23')]],'group':_0x9253('0x20'),'where':{'role':{'$or':[_0x9253('0x24'),_0x9253('0x25'),_0x9253('0x26')]}},'raw':!![]})['then'](function(_0x4fb31c){var _0x5d4c4f={'user':_0x3855ee[_0x9253('0x27')]||0x0,'telephone':_0x3855ee[_0x9253('0x28')]||0x0};_0x4fb31c[_0x9253('0x29')](function(_0xbb73c1){var _0x3ccb7a=_0xbb73c1['role']==='admin'?_0x9253('0x25'):_0xbb73c1[_0x9253('0x20')];_0x5d4c4f[_0x3ccb7a]-=_0xbb73c1[_0x9253('0x23')];if(_0x5d4c4f[_0x3ccb7a]<0x0)_0x5d4c4f[_0x3ccb7a]=0x0;});_0x408b3a(_0x5d4c4f);return;});})[_0x9253('0xe')](function(_0x553e37){_0x2f3c89(_0x553e37);});});}function checkUserLimits(_0x31302b){return new BPromise(function(_0x1ae036,_0x401da3){getLimits()['then'](function(_0x4e9978){var _0x289fc9=_[_0x9253('0x2a')](_[_0x9253('0x2b')](_0x31302b,_0x9253('0x20')),[_0x9253('0x24'),_0x9253('0x25'),_0x9253('0x26')]);var _0x4e518f=(_0x289fc9['admin']||0x0)+(_0x289fc9[_0x9253('0x25')]||0x0);var _0xe713df=_0x289fc9[_0x9253('0x26')]||0x0;if(_0x4e518f>_0x4e9978[_0x9253('0x25')])return _0x401da3(_0x9253('0x2c'));if(_0xe713df>_0x4e9978['telephone'])return _0x401da3('License\x20limit\x20reached\x20for\x20telephones');return _0x1ae036();})[_0x9253('0xe')](function(_0x5b2bcd){_0x401da3(_0x5b2bcd);});});}module['exports']={'checkLicense':checkLicense,'checkUserLimits':checkUserLimits,'getLicense':getLicense};