0ab3a5b664801fff1728ac8f43355467497b6306
[motion2.git] / server / api / license / license.controller.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 _0x9220=['stack','name','send','../../config/license/util','index','model','License','query','keys','attributes','intersection','length','merge','options','getLicense','catch','body','find','params','key','demo','downloadLogFile','license-info.log','log','setHeader','Content-disposition','set','Content-Type','download','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','util','path','sox','to-csv','ejs','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','sendStatus','status','end','json','offset','undefined','count','Content-Range','apply','reject','save','update','then','error'];(function(_0x4b61ea,_0xd55301){var _0x4f3bdb=function(_0x5982ab){while(--_0x5982ab){_0x4b61ea['push'](_0x4b61ea['shift']());}};_0x4f3bdb(++_0xd55301);}(_0x9220,0x162));var _0x0922=function(_0x2aecb2,_0x343312){_0x2aecb2=_0x2aecb2-0x0;var _0x3ebb80=_0x9220[_0x2aecb2];return _0x3ebb80;};'use strict';var emlformat=require(_0x0922('0x0'));var rimraf=require(_0x0922('0x1'));var zipdir=require(_0x0922('0x2'));var jsonpatch=require(_0x0922('0x3'));var rp=require(_0x0922('0x4'));var moment=require(_0x0922('0x5'));var BPromise=require('bluebird');var Mustache=require(_0x0922('0x6'));var util=require(_0x0922('0x7'));var path=require(_0x0922('0x8'));var sox=require(_0x0922('0x9'));var csv=require(_0x0922('0xa'));var ejs=require(_0x0922('0xb'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require('squel');var crypto=require(_0x0922('0xc'));var jsforce=require(_0x0922('0xd'));var deskjs=require(_0x0922('0xe'));var toCsv=require(_0x0922('0xa'));var querystring=require(_0x0922('0xf'));var Papa=require(_0x0922('0x10'));var Redis=require(_0x0922('0x11'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0x0922('0x12'));var hardwareService=require(_0x0922('0x13'));var logger=require(_0x0922('0x14'))(_0x0922('0x15'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x4b7065,_0x3f1251){_0x3f1251=_0x3f1251||0xcc;return function(_0x13ad1f){if(_0x13ad1f){return _0x4b7065[_0x0922('0x16')](_0x3f1251);}return _0x4b7065[_0x0922('0x17')](_0x3f1251)[_0x0922('0x18')]();};}function respondWithResult(_0x1816b3,_0x554f0e){_0x554f0e=_0x554f0e||0xc8;return function(_0xd1349a){if(_0xd1349a){return _0x1816b3[_0x0922('0x17')](_0x554f0e)[_0x0922('0x19')](_0xd1349a);}};}function respondWithFilteredResult(_0x5075fa,_0x40d499){return function(_0x79a02d){if(_0x79a02d){var _0x143dd0=typeof _0x40d499[_0x0922('0x1a')]===_0x0922('0x1b')&&typeof _0x40d499['limit']===_0x0922('0x1b');var _0x1d7849=_0x79a02d[_0x0922('0x1c')];var _0x1a3711=_0x143dd0?0x0:_0x40d499['offset'];var _0x3d91c7=_0x143dd0?_0x79a02d[_0x0922('0x1c')]:_0x40d499['offset']+_0x40d499['limit'];var _0x22bf55;if(_0x3d91c7>=_0x1d7849){_0x3d91c7=_0x1d7849;_0x22bf55=0xc8;}else{_0x22bf55=0xce;}_0x5075fa[_0x0922('0x17')](_0x22bf55);return _0x5075fa['set'](_0x0922('0x1d'),_0x1a3711+'-'+_0x3d91c7+'/'+_0x1d7849)[_0x0922('0x19')](_0x79a02d);}return null;};}function patchUpdates(_0x490efe){return function(_0x10adbf){try{jsonpatch[_0x0922('0x1e')](_0x10adbf,_0x490efe,!![]);}catch(_0x4a6816){return BPromise[_0x0922('0x1f')](_0x4a6816);}return _0x10adbf[_0x0922('0x20')]();};}function saveUpdates(_0x5a1aef,_0x390474){return function(_0x48f3d4){if(_0x48f3d4){return _0x48f3d4[_0x0922('0x21')](_0x5a1aef)[_0x0922('0x22')](function(_0x390157){return _0x390157;});}return null;};}function removeEntity(_0x5ca715,_0x1e65db){return function(_0x4a7574){if(_0x4a7574){return _0x4a7574['destroy']()['then'](function(){_0x5ca715[_0x0922('0x17')](0xcc)[_0x0922('0x18')]();});}};}function handleEntityNotFound(_0x261158,_0x527465){return function(_0x1c9557){if(!_0x1c9557){_0x261158['sendStatus'](0x194);}return _0x1c9557;};}function handleError(_0x1fae9d,_0x2e82df){_0x2e82df=_0x2e82df||0x1f4;return function(_0x31f840){logger[_0x0922('0x23')](_0x31f840[_0x0922('0x24')]);if(_0x31f840[_0x0922('0x25')]){delete _0x31f840[_0x0922('0x25')];}_0x1fae9d[_0x0922('0x17')](_0x2e82df)[_0x0922('0x26')](_0x31f840);};}var utilLicense=require(_0x0922('0x27'));exports[_0x0922('0x28')]=function(_0x2c4bd4,_0xecc500){var _0x26640a={'raw':!![],'where':{'id':0x1}},_0x2af066={};_0x2af066[_0x0922('0x29')]=_['keys'](db[_0x0922('0x2a')]['rawAttributes']);_0x2af066[_0x0922('0x2b')]=_[_0x0922('0x2c')](_0x2c4bd4[_0x0922('0x2b')]);_0x2af066['filters']=_['intersection'](_0x2af066[_0x0922('0x29')],_0x2af066[_0x0922('0x2b')]);_0x26640a[_0x0922('0x2d')]=_[_0x0922('0x2e')](_0x2af066[_0x0922('0x29')],qs['fields'](_0x2c4bd4[_0x0922('0x2b')]['fields']));_0x26640a[_0x0922('0x2d')]=_0x26640a['attributes'][_0x0922('0x2f')]?_0x26640a[_0x0922('0x2d')]:_0x2af066[_0x0922('0x29')];_0x26640a=_[_0x0922('0x30')]({},_0x26640a,_0x2c4bd4[_0x0922('0x31')]);return utilLicense[_0x0922('0x32')](_0x26640a)[_0x0922('0x22')](respondWithResult(_0xecc500,null))[_0x0922('0x33')](handleError(_0xecc500,null));};exports[_0x0922('0x21')]=function(_0x479556,_0x222926){if(_0x479556[_0x0922('0x34')]['id']){delete _0x479556[_0x0922('0x34')]['id'];}return db[_0x0922('0x2a')][_0x0922('0x35')]({'where':{'id':_0x479556[_0x0922('0x36')]['id']}})[_0x0922('0x22')](handleEntityNotFound(_0x222926,null))[_0x0922('0x22')](function(_0xa43dd5){var _0x257aea=_0xa43dd5['get']({'plain':!![]});return utilLicense['checkLicense'](_0x257aea,_0x479556[_0x0922('0x34')][_0x0922('0x37')]);})[_0x0922('0x22')](function(_0x31cc8f){if(!_0x31cc8f[_0x0922('0x38')]){return saveUpdates(_0x479556['body'],null);}return _0x31cc8f;})[_0x0922('0x22')](respondWithResult(_0x222926,null))[_0x0922('0x33')](handleError(_0x222926,null));};exports[_0x0922('0x39')]=function(_0x2fbeb5,_0x280fe9){var _0x542d53=_0x0922('0x3a');var _0x2611d7=path['join']('/var',_0x0922('0x3b'),'xcally',_0x542d53);_0x280fe9[_0x0922('0x3c')](_0x0922('0x3d'),'attachment;\x20filename='+_0x542d53);_0x280fe9[_0x0922('0x3e')](_0x0922('0x3f'),'text/plain');_0x280fe9[_0x0922('0x40')](_0x2611d7);};