04f4221ab289dc49c0f93fadbe29f4d502ee3b4b
[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 _0xfd50=['options','getLicense','body','find','params','checkLicense','key','demo','catch','downloadLogFile','license-info.log','join','log','xcally','setHeader','Content-disposition','attachment;\x20filename=','Content-Type','text/plain','download','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','sendStatus','status','end','offset','undefined','limit','count','set','Content-Range','json','apply','reject','update','then','destroy','error','name','send','../../config/license/util','index','model','keys','License','rawAttributes','query','intersection','attributes','fields','length','merge'];(function(_0x29c2f7,_0x1ffb8b){var _0x3582e6=function(_0x4e91dc){while(--_0x4e91dc){_0x29c2f7['push'](_0x29c2f7['shift']());}};_0x3582e6(++_0x1ffb8b);}(_0xfd50,0x190));var _0x0fd5=function(_0x1c8c28,_0x3ee093){_0x1c8c28=_0x1c8c28-0x0;var _0x1f59b4=_0xfd50[_0x1c8c28];return _0x1f59b4;};'use strict';var emlformat=require(_0x0fd5('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x0fd5('0x1'));var jsonpatch=require(_0x0fd5('0x2'));var rp=require(_0x0fd5('0x3'));var moment=require(_0x0fd5('0x4'));var BPromise=require(_0x0fd5('0x5'));var Mustache=require(_0x0fd5('0x6'));var util=require('util');var path=require(_0x0fd5('0x7'));var sox=require(_0x0fd5('0x8'));var csv=require(_0x0fd5('0x9'));var ejs=require(_0x0fd5('0xa'));var fs=require('fs');var fs_extra=require(_0x0fd5('0xb'));var _=require(_0x0fd5('0xc'));var squel=require(_0x0fd5('0xd'));var crypto=require(_0x0fd5('0xe'));var jsforce=require(_0x0fd5('0xf'));var deskjs=require(_0x0fd5('0x10'));var toCsv=require(_0x0fd5('0x9'));var querystring=require('querystring');var Papa=require(_0x0fd5('0x11'));var Redis=require(_0x0fd5('0x12'));var authService=require(_0x0fd5('0x13'));var qs=require('../../components/parsers/qs');var as=require(_0x0fd5('0x14'));var hardwareService=require(_0x0fd5('0x15'));var logger=require(_0x0fd5('0x16'))(_0x0fd5('0x17'));var utils=require(_0x0fd5('0x18'));var config=require(_0x0fd5('0x19'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x49df7a,_0x57902a){_0x57902a=_0x57902a||0xcc;return function(_0x4c67fe){if(_0x4c67fe){return _0x49df7a[_0x0fd5('0x1a')](_0x57902a);}return _0x49df7a[_0x0fd5('0x1b')](_0x57902a)[_0x0fd5('0x1c')]();};}function respondWithResult(_0x58e353,_0x511ac9){_0x511ac9=_0x511ac9||0xc8;return function(_0x3df11c){if(_0x3df11c){return _0x58e353[_0x0fd5('0x1b')](_0x511ac9)['json'](_0x3df11c);}};}function respondWithFilteredResult(_0x1047e3,_0x57986c){return function(_0x1ab97c){if(_0x1ab97c){var _0xf78fa3=typeof _0x57986c[_0x0fd5('0x1d')]===_0x0fd5('0x1e')&&typeof _0x57986c[_0x0fd5('0x1f')]===_0x0fd5('0x1e');var _0x498acd=_0x1ab97c[_0x0fd5('0x20')];var _0x242111=_0xf78fa3?0x0:_0x57986c[_0x0fd5('0x1d')];var _0xd9a1ae=_0xf78fa3?_0x1ab97c[_0x0fd5('0x20')]:_0x57986c[_0x0fd5('0x1d')]+_0x57986c[_0x0fd5('0x1f')];var _0x1a89e7;if(_0xd9a1ae>=_0x498acd){_0xd9a1ae=_0x498acd;_0x1a89e7=0xc8;}else{_0x1a89e7=0xce;}_0x1047e3[_0x0fd5('0x1b')](_0x1a89e7);return _0x1047e3[_0x0fd5('0x21')](_0x0fd5('0x22'),_0x242111+'-'+_0xd9a1ae+'/'+_0x498acd)[_0x0fd5('0x23')](_0x1ab97c);}return null;};}function patchUpdates(_0x1a6229){return function(_0x284be3){try{jsonpatch[_0x0fd5('0x24')](_0x284be3,_0x1a6229,!![]);}catch(_0x214452){return BPromise[_0x0fd5('0x25')](_0x214452);}return _0x284be3['save']();};}function saveUpdates(_0x59f403,_0x3ff38a){return function(_0x520833){if(_0x520833){return _0x520833[_0x0fd5('0x26')](_0x59f403)[_0x0fd5('0x27')](function(_0x4fe772){return _0x4fe772;});}return null;};}function removeEntity(_0x574b07,_0x3de099){return function(_0x3b7658){if(_0x3b7658){return _0x3b7658[_0x0fd5('0x28')]()[_0x0fd5('0x27')](function(){_0x574b07[_0x0fd5('0x1b')](0xcc)['end']();});}};}function handleEntityNotFound(_0x571937,_0x364e7f){return function(_0x146398){if(!_0x146398){_0x571937[_0x0fd5('0x1a')](0x194);}return _0x146398;};}function handleError(_0x5d1abb,_0x31bee0){_0x31bee0=_0x31bee0||0x1f4;return function(_0x1f2f08){logger[_0x0fd5('0x29')](_0x1f2f08['stack']);if(_0x1f2f08[_0x0fd5('0x2a')]){delete _0x1f2f08['name'];}_0x5d1abb['status'](_0x31bee0)[_0x0fd5('0x2b')](_0x1f2f08);};}var utilLicense=require(_0x0fd5('0x2c'));exports[_0x0fd5('0x2d')]=function(_0x2c3052,_0x406bc0){var _0x49e320={'raw':!![],'where':{'id':0x1}},_0x1c9064={};_0x1c9064[_0x0fd5('0x2e')]=_[_0x0fd5('0x2f')](db[_0x0fd5('0x30')][_0x0fd5('0x31')]);_0x1c9064[_0x0fd5('0x32')]=_[_0x0fd5('0x2f')](_0x2c3052['query']);_0x1c9064['filters']=_[_0x0fd5('0x33')](_0x1c9064[_0x0fd5('0x2e')],_0x1c9064[_0x0fd5('0x32')]);_0x49e320[_0x0fd5('0x34')]=_[_0x0fd5('0x33')](_0x1c9064['model'],qs[_0x0fd5('0x35')](_0x2c3052[_0x0fd5('0x32')][_0x0fd5('0x35')]));_0x49e320[_0x0fd5('0x34')]=_0x49e320[_0x0fd5('0x34')][_0x0fd5('0x36')]?_0x49e320[_0x0fd5('0x34')]:_0x1c9064[_0x0fd5('0x2e')];_0x49e320=_[_0x0fd5('0x37')]({},_0x49e320,_0x2c3052[_0x0fd5('0x38')]);return utilLicense[_0x0fd5('0x39')](_0x49e320)[_0x0fd5('0x27')](respondWithResult(_0x406bc0,null))['catch'](handleError(_0x406bc0,null));};exports[_0x0fd5('0x26')]=function(_0x38720c,_0x528445){if(_0x38720c['body']['id']){delete _0x38720c[_0x0fd5('0x3a')]['id'];}return db[_0x0fd5('0x30')][_0x0fd5('0x3b')]({'where':{'id':_0x38720c[_0x0fd5('0x3c')]['id']}})[_0x0fd5('0x27')](handleEntityNotFound(_0x528445,null))[_0x0fd5('0x27')](function(_0x40436d){var _0x58e967=_0x40436d['get']({'plain':!![]});return utilLicense[_0x0fd5('0x3d')](_0x58e967,_0x38720c[_0x0fd5('0x3a')][_0x0fd5('0x3e')]);})[_0x0fd5('0x27')](function(_0x2ade06){if(!_0x2ade06[_0x0fd5('0x3f')]){return saveUpdates(_0x38720c[_0x0fd5('0x3a')],null);}return _0x2ade06;})[_0x0fd5('0x27')](respondWithResult(_0x528445,null))[_0x0fd5('0x40')](handleError(_0x528445,null));};exports[_0x0fd5('0x41')]=function(_0x436e94,_0x17243b){var _0x5c7781=_0x0fd5('0x42');var _0x26f569=path[_0x0fd5('0x43')]('/var',_0x0fd5('0x44'),_0x0fd5('0x45'),_0x5c7781);_0x17243b[_0x0fd5('0x46')](_0x0fd5('0x47'),_0x0fd5('0x48')+_0x5c7781);_0x17243b['set'](_0x0fd5('0x49'),_0x0fd5('0x4a'));_0x17243b[_0x0fd5('0x4b')](_0x26f569);};