7ef0c6330f8b253da7b83eb60e1975dbb69fbd37
[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 _0x9f34=['papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','offset','limit','count','set','Content-Range','apply','reject','update','then','destroy','error','stack','name','keys','License','rawAttributes','query','filters','intersection','fields','attributes','length','model','merge','catch','find','params','get','checkLicense','body','key','demo','join','/var','log','xcally','Content-disposition','attachment;\x20filename=','Content-Type','text/plain','download','eml-format','rimraf','zip-dir','request-promise','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','crypto','jsforce','desk.js','querystring'];(function(_0x17bc8f,_0x4f5c9e){var _0x2ee48e=function(_0x500ae6){while(--_0x500ae6){_0x17bc8f['push'](_0x17bc8f['shift']());}};_0x2ee48e(++_0x4f5c9e);}(_0x9f34,0x193));var _0x49f3=function(_0x380b08,_0x1df63a){_0x380b08=_0x380b08-0x0;var _0x22f65d=_0x9f34[_0x380b08];return _0x22f65d;};'use strict';var emlformat=require(_0x49f3('0x0'));var rimraf=require(_0x49f3('0x1'));var zipdir=require(_0x49f3('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x49f3('0x3'));var moment=require('moment');var BPromise=require(_0x49f3('0x4'));var Mustache=require(_0x49f3('0x5'));var util=require(_0x49f3('0x6'));var path=require(_0x49f3('0x7'));var sox=require(_0x49f3('0x8'));var csv=require(_0x49f3('0x9'));var ejs=require(_0x49f3('0xa'));var fs=require('fs');var fs_extra=require(_0x49f3('0xb'));var _=require(_0x49f3('0xc'));var squel=require('squel');var crypto=require(_0x49f3('0xd'));var jsforce=require(_0x49f3('0xe'));var deskjs=require(_0x49f3('0xf'));var toCsv=require(_0x49f3('0x9'));var querystring=require(_0x49f3('0x10'));var Papa=require(_0x49f3('0x11'));var Redis=require(_0x49f3('0x12'));var authService=require(_0x49f3('0x13'));var qs=require(_0x49f3('0x14'));var as=require(_0x49f3('0x15'));var hardwareService=require(_0x49f3('0x16'));var logger=require('../../config/logger')('api');var utils=require('../../config/utils');var config=require(_0x49f3('0x17'));var licenseUtil=require(_0x49f3('0x18'));var db=require(_0x49f3('0x19'))['db'];function respondWithStatusCode(_0x5c31e9,_0x4caebf){_0x4caebf=_0x4caebf||0xcc;return function(_0x3634a5){if(_0x3634a5){return _0x5c31e9[_0x49f3('0x1a')](_0x4caebf);}return _0x5c31e9[_0x49f3('0x1b')](_0x4caebf)[_0x49f3('0x1c')]();};}function respondWithResult(_0x92b177,_0xa11a2a){_0xa11a2a=_0xa11a2a||0xc8;return function(_0xa5f443){if(_0xa5f443){return _0x92b177[_0x49f3('0x1b')](_0xa11a2a)['json'](_0xa5f443);}};}function respondWithFilteredResult(_0x4fecb7,_0x4d203e){return function(_0x286366){if(_0x286366){var _0x4d352b=typeof _0x4d203e[_0x49f3('0x1d')]==='undefined'&&typeof _0x4d203e[_0x49f3('0x1e')]==='undefined';var _0x202297=_0x286366[_0x49f3('0x1f')];var _0x2e4838=_0x4d352b?0x0:_0x4d203e[_0x49f3('0x1d')];var _0xf239c3=_0x4d352b?_0x286366[_0x49f3('0x1f')]:_0x4d203e[_0x49f3('0x1d')]+_0x4d203e['limit'];var _0x601892;if(_0xf239c3>=_0x202297){_0xf239c3=_0x202297;_0x601892=0xc8;}else{_0x601892=0xce;}_0x4fecb7[_0x49f3('0x1b')](_0x601892);return _0x4fecb7[_0x49f3('0x20')](_0x49f3('0x21'),_0x2e4838+'-'+_0xf239c3+'/'+_0x202297)['json'](_0x286366);}return null;};}function patchUpdates(_0x102b03){return function(_0x1d9459){try{jsonpatch[_0x49f3('0x22')](_0x1d9459,_0x102b03,!![]);}catch(_0x1a3282){return BPromise[_0x49f3('0x23')](_0x1a3282);}return _0x1d9459['save']();};}function saveUpdates(_0x303707,_0x4bbc3f){return function(_0x208f2f){if(_0x208f2f){return _0x208f2f[_0x49f3('0x24')](_0x303707)[_0x49f3('0x25')](function(_0x54bd2b){return _0x54bd2b;});}return null;};}function removeEntity(_0x3585dc,_0x1ac95a){return function(_0x26109f){if(_0x26109f){return _0x26109f[_0x49f3('0x26')]()[_0x49f3('0x25')](function(){_0x3585dc['status'](0xcc)[_0x49f3('0x1c')]();});}};}function handleEntityNotFound(_0x1c0e19,_0x16cf67){return function(_0x78e716){if(!_0x78e716){_0x1c0e19[_0x49f3('0x1a')](0x194);}return _0x78e716;};}function handleError(_0xb14fb,_0x4142f0){_0x4142f0=_0x4142f0||0x1f4;return function(_0x4d7f74){logger[_0x49f3('0x27')](_0x4d7f74[_0x49f3('0x28')]);if(_0x4d7f74['name']){delete _0x4d7f74[_0x49f3('0x29')];}_0xb14fb[_0x49f3('0x1b')](_0x4142f0)['send'](_0x4d7f74);};}var utilLicense=require(_0x49f3('0x18'));exports['index']=function(_0x66f5da,_0x94e4cb){var _0x48f6ef={'raw':!![],'where':{'id':0x1}},_0x1c6a9e={};_0x1c6a9e['model']=_[_0x49f3('0x2a')](db[_0x49f3('0x2b')][_0x49f3('0x2c')]);_0x1c6a9e[_0x49f3('0x2d')]=_['keys'](_0x66f5da[_0x49f3('0x2d')]);_0x1c6a9e[_0x49f3('0x2e')]=_[_0x49f3('0x2f')](_0x1c6a9e['model'],_0x1c6a9e[_0x49f3('0x2d')]);_0x48f6ef['attributes']=_[_0x49f3('0x2f')](_0x1c6a9e['model'],qs['fields'](_0x66f5da[_0x49f3('0x2d')][_0x49f3('0x30')]));_0x48f6ef[_0x49f3('0x31')]=_0x48f6ef[_0x49f3('0x31')][_0x49f3('0x32')]?_0x48f6ef[_0x49f3('0x31')]:_0x1c6a9e[_0x49f3('0x33')];_0x48f6ef=_[_0x49f3('0x34')]({},_0x48f6ef,_0x66f5da['options']);return utilLicense['getLicense'](_0x48f6ef)[_0x49f3('0x25')](respondWithResult(_0x94e4cb,null))[_0x49f3('0x35')](handleError(_0x94e4cb,null));};exports['update']=function(_0x1b0f12,_0x12c661){if(_0x1b0f12['body']['id']){delete _0x1b0f12['body']['id'];}return db[_0x49f3('0x2b')][_0x49f3('0x36')]({'where':{'id':_0x1b0f12[_0x49f3('0x37')]['id']}})[_0x49f3('0x25')](handleEntityNotFound(_0x12c661,null))[_0x49f3('0x25')](function(_0x12e67e){var _0x5b602b=_0x12e67e[_0x49f3('0x38')]({'plain':!![]});return utilLicense[_0x49f3('0x39')](_0x5b602b,_0x1b0f12[_0x49f3('0x3a')][_0x49f3('0x3b')]);})[_0x49f3('0x25')](function(_0x237b58){if(!_0x237b58[_0x49f3('0x3c')]){return saveUpdates(_0x1b0f12['body'],null);}return _0x237b58;})[_0x49f3('0x25')](respondWithResult(_0x12c661,null))['catch'](handleError(_0x12c661,null));};exports['downloadLogFile']=function(_0x40cab1,_0x56f4c1){var _0x42add1='license-info.log';var _0x548062=path[_0x49f3('0x3d')](_0x49f3('0x3e'),_0x49f3('0x3f'),_0x49f3('0x40'),_0x42add1);_0x56f4c1['setHeader'](_0x49f3('0x41'),_0x49f3('0x42')+_0x42add1);_0x56f4c1[_0x49f3('0x20')](_0x49f3('0x43'),_0x49f3('0x44'));_0x56f4c1[_0x49f3('0x45')](_0x548062);};