f7d4be9b5f0670c48576fb1e87678ab6e599a49c
[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 _0xcfc7=['merge','getLicense','catch','body','find','checkLicense','key','demo','join','/var','log','Content-disposition','attachment;\x20filename=','text/plain','download','zip-dir','fast-json-patch','request-promise','moment','mustache','util','path','to-csv','ejs','fs-extra','lodash','crypto','jsforce','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/license/util','sendStatus','status','end','json','offset','undefined','count','limit','set','Content-Range','apply','reject','save','destroy','then','error','stack','name','send','model','License','rawAttributes','keys','filters','intersection','query','fields','attributes'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0xcfc7,0x107));var _0x7cfc=function(_0x1bdc52,_0x4876a9){_0x1bdc52=_0x1bdc52-0x0;var _0xdf3fa3=_0xcfc7[_0x1bdc52];return _0xdf3fa3;};'use strict';var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0x7cfc('0x0'));var jsonpatch=require(_0x7cfc('0x1'));var rp=require(_0x7cfc('0x2'));var moment=require(_0x7cfc('0x3'));var BPromise=require('bluebird');var Mustache=require(_0x7cfc('0x4'));var util=require(_0x7cfc('0x5'));var path=require(_0x7cfc('0x6'));var sox=require('sox');var csv=require(_0x7cfc('0x7'));var ejs=require(_0x7cfc('0x8'));var fs=require('fs');var fs_extra=require(_0x7cfc('0x9'));var _=require(_0x7cfc('0xa'));var squel=require('squel');var crypto=require(_0x7cfc('0xb'));var jsforce=require(_0x7cfc('0xc'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0x7cfc('0xd'));var qs=require(_0x7cfc('0xe'));var as=require(_0x7cfc('0xf'));var hardwareService=require(_0x7cfc('0x10'));var logger=require('../../config/logger')(_0x7cfc('0x11'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0x7cfc('0x12'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x22406f,_0x2e951f){_0x2e951f=_0x2e951f||0xcc;return function(_0x373ba3){if(_0x373ba3){return _0x22406f[_0x7cfc('0x13')](_0x2e951f);}return _0x22406f[_0x7cfc('0x14')](_0x2e951f)[_0x7cfc('0x15')]();};}function respondWithResult(_0x13ead7,_0x30fdc3){_0x30fdc3=_0x30fdc3||0xc8;return function(_0x4a4009){if(_0x4a4009){return _0x13ead7[_0x7cfc('0x14')](_0x30fdc3)[_0x7cfc('0x16')](_0x4a4009);}};}function respondWithFilteredResult(_0x2653db,_0x100f9b){return function(_0x2537db){if(_0x2537db){var _0x3cb2ad=typeof _0x100f9b[_0x7cfc('0x17')]===_0x7cfc('0x18')&&typeof _0x100f9b['limit']===_0x7cfc('0x18');var _0x1f6a76=_0x2537db['count'];var _0x231331=_0x3cb2ad?0x0:_0x100f9b[_0x7cfc('0x17')];var _0x4c2bae=_0x3cb2ad?_0x2537db[_0x7cfc('0x19')]:_0x100f9b[_0x7cfc('0x17')]+_0x100f9b[_0x7cfc('0x1a')];var _0x19344c;if(_0x4c2bae>=_0x1f6a76){_0x4c2bae=_0x1f6a76;_0x19344c=0xc8;}else{_0x19344c=0xce;}_0x2653db['status'](_0x19344c);return _0x2653db[_0x7cfc('0x1b')](_0x7cfc('0x1c'),_0x231331+'-'+_0x4c2bae+'/'+_0x1f6a76)[_0x7cfc('0x16')](_0x2537db);}return null;};}function patchUpdates(_0x50cece){return function(_0x2489fd){try{jsonpatch[_0x7cfc('0x1d')](_0x2489fd,_0x50cece,!![]);}catch(_0x3797b8){return BPromise[_0x7cfc('0x1e')](_0x3797b8);}return _0x2489fd[_0x7cfc('0x1f')]();};}function saveUpdates(_0x227267,_0x4c8a43){return function(_0x3fa68f){if(_0x3fa68f){return _0x3fa68f['update'](_0x227267)['then'](function(_0x26f281){return _0x26f281;});}return null;};}function removeEntity(_0x1b24e9,_0x26be44){return function(_0x4c0f95){if(_0x4c0f95){return _0x4c0f95[_0x7cfc('0x20')]()[_0x7cfc('0x21')](function(){_0x1b24e9[_0x7cfc('0x14')](0xcc)[_0x7cfc('0x15')]();});}};}function handleEntityNotFound(_0x56925f,_0x3b5acc){return function(_0x24188e){if(!_0x24188e){_0x56925f[_0x7cfc('0x13')](0x194);}return _0x24188e;};}function handleError(_0x527797,_0xf1ba50){_0xf1ba50=_0xf1ba50||0x1f4;return function(_0x587a80){logger[_0x7cfc('0x22')](_0x587a80[_0x7cfc('0x23')]);if(_0x587a80[_0x7cfc('0x24')]){delete _0x587a80[_0x7cfc('0x24')];}_0x527797[_0x7cfc('0x14')](_0xf1ba50)[_0x7cfc('0x25')](_0x587a80);};}var utilLicense=require(_0x7cfc('0x12'));exports['index']=function(_0x506823,_0x4c836e){var _0x2a611b={'raw':!![],'where':{'id':0x1}},_0x54fb43={};_0x54fb43[_0x7cfc('0x26')]=_['keys'](db[_0x7cfc('0x27')][_0x7cfc('0x28')]);_0x54fb43['query']=_[_0x7cfc('0x29')](_0x506823['query']);_0x54fb43[_0x7cfc('0x2a')]=_[_0x7cfc('0x2b')](_0x54fb43[_0x7cfc('0x26')],_0x54fb43[_0x7cfc('0x2c')]);_0x2a611b['attributes']=_['intersection'](_0x54fb43['model'],qs['fields'](_0x506823['query'][_0x7cfc('0x2d')]));_0x2a611b['attributes']=_0x2a611b[_0x7cfc('0x2e')]['length']?_0x2a611b['attributes']:_0x54fb43[_0x7cfc('0x26')];_0x2a611b=_[_0x7cfc('0x2f')]({},_0x2a611b,_0x506823['options']);return utilLicense[_0x7cfc('0x30')](_0x2a611b)[_0x7cfc('0x21')](respondWithResult(_0x4c836e,null))[_0x7cfc('0x31')](handleError(_0x4c836e,null));};exports['update']=function(_0x17392d,_0x5a6a25){if(_0x17392d['body']['id']){delete _0x17392d[_0x7cfc('0x32')]['id'];}return db['License'][_0x7cfc('0x33')]({'where':{'id':_0x17392d['params']['id']}})[_0x7cfc('0x21')](handleEntityNotFound(_0x5a6a25,null))['then'](function(_0x23c964){var _0x68f4e8=_0x23c964['get']({'plain':!![]});return utilLicense[_0x7cfc('0x34')](_0x68f4e8,_0x17392d['body'][_0x7cfc('0x35')]);})[_0x7cfc('0x21')](function(_0x382576){if(!_0x382576[_0x7cfc('0x36')]){return saveUpdates(_0x17392d[_0x7cfc('0x32')],null);}return _0x382576;})[_0x7cfc('0x21')](respondWithResult(_0x5a6a25,null))['catch'](handleError(_0x5a6a25,null));};exports['downloadLogFile']=function(_0x5dcdc2,_0x3a9c3b){var _0x5cf7d2='license-info.log';var _0x839feb=path[_0x7cfc('0x37')](_0x7cfc('0x38'),_0x7cfc('0x39'),'xcally',_0x5cf7d2);_0x3a9c3b['setHeader'](_0x7cfc('0x3a'),_0x7cfc('0x3b')+_0x5cf7d2);_0x3a9c3b[_0x7cfc('0x1b')]('Content-Type',_0x7cfc('0x3c'));_0x3a9c3b[_0x7cfc('0x3d')](_0x839feb);};