Built motion from commit ac06311e.|2.6.28
[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 _0xf174=['save','update','destroy','then','sendStatus','error','stack','name','send','index','model','keys','License','query','filters','attributes','intersection','length','merge','options','catch','body','find','params','key','demo','downloadLogFile','join','/var','log','Content-disposition','attachment;\x20filename=','text/plain','download','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','util','sox','to-csv','ejs','fs-extra','lodash','squel','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','status','end','offset','undefined','limit','count','set','json','apply'];(function(_0x51020b,_0x38c2c7){var _0x371e47=function(_0x2a538f){while(--_0x2a538f){_0x51020b['push'](_0x51020b['shift']());}};_0x371e47(++_0x38c2c7);}(_0xf174,0x13e));var _0x4f17=function(_0x36fe2e,_0x209c3e){_0x36fe2e=_0x36fe2e-0x0;var _0x3368f6=_0xf174[_0x36fe2e];return _0x3368f6;};'use strict';var emlformat=require(_0x4f17('0x0'));var rimraf=require(_0x4f17('0x1'));var zipdir=require(_0x4f17('0x2'));var jsonpatch=require(_0x4f17('0x3'));var rp=require(_0x4f17('0x4'));var moment=require(_0x4f17('0x5'));var BPromise=require('bluebird');var Mustache=require(_0x4f17('0x6'));var util=require(_0x4f17('0x7'));var path=require('path');var sox=require(_0x4f17('0x8'));var csv=require(_0x4f17('0x9'));var ejs=require(_0x4f17('0xa'));var fs=require('fs');var fs_extra=require(_0x4f17('0xb'));var _=require(_0x4f17('0xc'));var squel=require(_0x4f17('0xd'));var crypto=require('crypto');var jsforce=require(_0x4f17('0xe'));var deskjs=require(_0x4f17('0xf'));var toCsv=require(_0x4f17('0x9'));var querystring=require(_0x4f17('0x10'));var Papa=require('papaparse');var Redis=require(_0x4f17('0x11'));var authService=require(_0x4f17('0x12'));var qs=require(_0x4f17('0x13'));var as=require(_0x4f17('0x14'));var hardwareService=require(_0x4f17('0x15'));var logger=require(_0x4f17('0x16'))(_0x4f17('0x17'));var utils=require(_0x4f17('0x18'));var config=require(_0x4f17('0x19'));var licenseUtil=require(_0x4f17('0x1a'));var db=require(_0x4f17('0x1b'))['db'];function respondWithStatusCode(_0x4384fc,_0x3df6aa){_0x3df6aa=_0x3df6aa||0xcc;return function(_0x4f5112){if(_0x4f5112){return _0x4384fc['sendStatus'](_0x3df6aa);}return _0x4384fc[_0x4f17('0x1c')](_0x3df6aa)[_0x4f17('0x1d')]();};}function respondWithResult(_0x260736,_0x3ae717){_0x3ae717=_0x3ae717||0xc8;return function(_0xde8d97){if(_0xde8d97){return _0x260736[_0x4f17('0x1c')](_0x3ae717)['json'](_0xde8d97);}};}function respondWithFilteredResult(_0x27c2f9,_0x1f7f89){return function(_0xba613d){if(_0xba613d){var _0x404db3=typeof _0x1f7f89[_0x4f17('0x1e')]===_0x4f17('0x1f')&&typeof _0x1f7f89[_0x4f17('0x20')]===_0x4f17('0x1f');var _0x3ebc32=_0xba613d[_0x4f17('0x21')];var _0x1d566c=_0x404db3?0x0:_0x1f7f89[_0x4f17('0x1e')];var _0x98ee41=_0x404db3?_0xba613d[_0x4f17('0x21')]:_0x1f7f89[_0x4f17('0x1e')]+_0x1f7f89['limit'];var _0x555c16;if(_0x98ee41>=_0x3ebc32){_0x98ee41=_0x3ebc32;_0x555c16=0xc8;}else{_0x555c16=0xce;}_0x27c2f9['status'](_0x555c16);return _0x27c2f9[_0x4f17('0x22')]('Content-Range',_0x1d566c+'-'+_0x98ee41+'/'+_0x3ebc32)[_0x4f17('0x23')](_0xba613d);}return null;};}function patchUpdates(_0x399b7f){return function(_0x2782c8){try{jsonpatch[_0x4f17('0x24')](_0x2782c8,_0x399b7f,!![]);}catch(_0x2c360a){return BPromise['reject'](_0x2c360a);}return _0x2782c8[_0x4f17('0x25')]();};}function saveUpdates(_0x5a84c0,_0x43fbd8){return function(_0x12091d){if(_0x12091d){return _0x12091d[_0x4f17('0x26')](_0x5a84c0)['then'](function(_0xcf0f02){return _0xcf0f02;});}return null;};}function removeEntity(_0x3d7afa,_0x1b879d){return function(_0x4949f0){if(_0x4949f0){return _0x4949f0[_0x4f17('0x27')]()[_0x4f17('0x28')](function(){_0x3d7afa[_0x4f17('0x1c')](0xcc)[_0x4f17('0x1d')]();});}};}function handleEntityNotFound(_0x19dce6,_0x1e4800){return function(_0x470ba5){if(!_0x470ba5){_0x19dce6[_0x4f17('0x29')](0x194);}return _0x470ba5;};}function handleError(_0x2f2e35,_0x288e89){_0x288e89=_0x288e89||0x1f4;return function(_0x3d0d77){logger[_0x4f17('0x2a')](_0x3d0d77[_0x4f17('0x2b')]);if(_0x3d0d77[_0x4f17('0x2c')]){delete _0x3d0d77[_0x4f17('0x2c')];}_0x2f2e35[_0x4f17('0x1c')](_0x288e89)[_0x4f17('0x2d')](_0x3d0d77);};}var utilLicense=require('../../config/license/util');exports[_0x4f17('0x2e')]=function(_0x355e33,_0x3f4ad0){var _0x2acb1f={'raw':!![],'where':{'id':0x1}},_0x41916c={};_0x41916c[_0x4f17('0x2f')]=_[_0x4f17('0x30')](db[_0x4f17('0x31')]['rawAttributes']);_0x41916c[_0x4f17('0x32')]=_[_0x4f17('0x30')](_0x355e33[_0x4f17('0x32')]);_0x41916c[_0x4f17('0x33')]=_['intersection'](_0x41916c[_0x4f17('0x2f')],_0x41916c[_0x4f17('0x32')]);_0x2acb1f[_0x4f17('0x34')]=_[_0x4f17('0x35')](_0x41916c[_0x4f17('0x2f')],qs['fields'](_0x355e33[_0x4f17('0x32')]['fields']));_0x2acb1f[_0x4f17('0x34')]=_0x2acb1f[_0x4f17('0x34')][_0x4f17('0x36')]?_0x2acb1f[_0x4f17('0x34')]:_0x41916c[_0x4f17('0x2f')];_0x2acb1f=_[_0x4f17('0x37')]({},_0x2acb1f,_0x355e33[_0x4f17('0x38')]);return utilLicense['getLicense'](_0x2acb1f)[_0x4f17('0x28')](respondWithResult(_0x3f4ad0,null))[_0x4f17('0x39')](handleError(_0x3f4ad0,null));};exports[_0x4f17('0x26')]=function(_0x4ab016,_0x5d5c5b){if(_0x4ab016[_0x4f17('0x3a')]['id']){delete _0x4ab016['body']['id'];}return db[_0x4f17('0x31')][_0x4f17('0x3b')]({'where':{'id':_0x4ab016[_0x4f17('0x3c')]['id']}})[_0x4f17('0x28')](handleEntityNotFound(_0x5d5c5b,null))[_0x4f17('0x28')](function(_0x9add8){var _0xf6e818=_0x9add8['get']({'plain':!![]});return utilLicense['checkLicense'](_0xf6e818,_0x4ab016['body'][_0x4f17('0x3d')]);})[_0x4f17('0x28')](function(_0x3fae59){if(!_0x3fae59[_0x4f17('0x3e')]){return saveUpdates(_0x4ab016[_0x4f17('0x3a')],null);}return _0x3fae59;})[_0x4f17('0x28')](respondWithResult(_0x5d5c5b,null))['catch'](handleError(_0x5d5c5b,null));};exports[_0x4f17('0x3f')]=function(_0x487346,_0xdd9346){var _0x598002='license-info.log';var _0x87c101=path[_0x4f17('0x40')](_0x4f17('0x41'),_0x4f17('0x42'),'xcally',_0x598002);_0xdd9346['setHeader'](_0x4f17('0x43'),_0x4f17('0x44')+_0x598002);_0xdd9346[_0x4f17('0x22')]('Content-Type',_0x4f17('0x45'));_0xdd9346[_0x4f17('0x46')](_0x87c101);};