Built motion from commit 775e2a94.|2.6.3
[motion2.git] / server / api / trunk / trunk.controller.js
index 1b2f45e..aee43b7 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xde5a=['send','map','Trunk','rawAttributes','fieldName','type','key','model','keys','query','filters','intersection','fields','length','attributes','nolimit','limit','order','sort','where','pick','filter','VIRTUAL','merge','options','include','rows','show','params','includeAll','find','clone','omit','createdAt','updatedAt','body','create','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','get','UserProfileSection','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','join','root','server/files/templates/trunk.ejs','server/files/templates/registry.ejs','utf8','render','writeFileSync','Reload','findAll','readFileSync','/etc/asterisk/sip_xcally_registers.conf','chan_sip.so','destroy','eml-format','rimraf','fast-json-patch','request-promise','moment','mustache','util','path','sox','to-csv','lodash','squel','crypto','jsforce','desk.js','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','http','then','Trunk,\x20%s,\x20%s','debug','Trunk,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','code','error','message','result','catch','sendStatus','end','status','count','offset','Content-Range','apply','reject','update','Trunks','UserProfileResource','stack','name'];(function(_0x7cb10c,_0x2fcc3a){var _0x11df59=function(_0x75305f){while(--_0x75305f){_0x7cb10c['push'](_0x7cb10c['shift']());}};_0x11df59(++_0x2fcc3a);}(_0xde5a,0x10f));var _0xade5=function(_0x29f110,_0x283f83){_0x29f110=_0x29f110-0x0;var _0x2793d5=_0xde5a[_0x29f110];return _0x2793d5;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0xade5('0x0'));var rimraf=require(_0xade5('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0xade5('0x2'));var rp=require(_0xade5('0x3'));var moment=require(_0xade5('0x4'));var BPromise=require('bluebird');var Mustache=require(_0xade5('0x5'));var util=require(_0xade5('0x6'));var path=require(_0xade5('0x7'));var sox=require(_0xade5('0x8'));var csv=require(_0xade5('0x9'));var ejs=require('ejs');var fs=require('fs');var _=require(_0xade5('0xa'));var squel=require(_0xade5('0xb'));var crypto=require(_0xade5('0xc'));var jsforce=require(_0xade5('0xd'));var deskjs=require(_0xade5('0xe'));var toCsv=require(_0xade5('0x9'));var querystring=require('querystring');var Papa=require(_0xade5('0xf'));var Redis=require(_0xade5('0x10'));var authService=require('../../components/auth/service');var qs=require(_0xade5('0x11'));var as=require(_0xade5('0x12'));var hardwareService=require(_0xade5('0x13'));var logger=require(_0xade5('0x14'))(_0xade5('0x15'));var utils=require(_0xade5('0x16'));var config=require('../../config/environment');var licenseUtil=require(_0xade5('0x17'));var db=require(_0xade5('0x18'))['db'];var jayson=require('jayson/promise');var client=jayson['client'][_0xade5('0x19')]({'port':0x232a});function respondWithRpcPromise(_0x2dbb8c,_0xc6b16f,_0x5ae988,_0x3a520c){return new BPromise(function(_0x17c8c1,_0x31a253){var _0x1ee2cd=_0x3a520c||client;return _0x1ee2cd['request'](_0x2dbb8c,_0x5ae988)[_0xade5('0x1a')](function(_0x5bd034){logger['info'](_0xade5('0x1b'),_0xc6b16f,'request\x20sent');logger[_0xade5('0x1c')](_0xade5('0x1d'),_0xc6b16f,_0xade5('0x1e'),JSON[_0xade5('0x1f')](_0x5bd034));if(_0x5bd034['error']){if(_0x5bd034['error'][_0xade5('0x20')]===0x1f4){logger[_0xade5('0x21')]('Trunk,\x20%s,\x20%s',_0xc6b16f,_0x5bd034[_0xade5('0x21')][_0xade5('0x22')]);return _0x31a253(_0x5bd034[_0xade5('0x21')][_0xade5('0x22')]);}logger[_0xade5('0x21')]('Trunk,\x20%s,\x20%s',_0xc6b16f,_0x5bd034['error']['message']);return _0x17c8c1(_0x5bd034['error'][_0xade5('0x22')]);}else{logger['info'](_0xade5('0x1b'),_0xc6b16f,_0xade5('0x1e'));_0x17c8c1(_0x5bd034[_0xade5('0x23')][_0xade5('0x22')]);}})[_0xade5('0x24')](function(_0x5768a2){logger[_0xade5('0x21')](_0xade5('0x1b'),_0xc6b16f,_0x5768a2);_0x31a253(_0x5768a2);});});}function respondWithStatusCode(_0x394d8c,_0x277fab){_0x277fab=_0x277fab||0xcc;return function(_0x432af1){if(_0x432af1){return _0x394d8c[_0xade5('0x25')](_0x277fab);}return _0x394d8c['status'](_0x277fab)[_0xade5('0x26')]();};}function respondWithResult(_0x28d65b,_0x378922){_0x378922=_0x378922||0xc8;return function(_0x42a8e3){if(_0x42a8e3){return _0x28d65b[_0xade5('0x27')](_0x378922)['json'](_0x42a8e3);}};}function respondWithFilteredResult(_0x5190b6,_0x4656bb){return function(_0xfb019){if(_0xfb019){var _0x1fc2c3=_0xfb019[_0xade5('0x28')],_0x59cf2b=_0x4656bb['offset'],_0x2f5ce4=_0x4656bb[_0xade5('0x29')]+_0x4656bb['limit'],_0x3b8aa2;if(_0x2f5ce4>=_0x1fc2c3){_0x2f5ce4=_0x1fc2c3;_0x3b8aa2=0xc8;}else{_0x3b8aa2=0xce;}_0x5190b6[_0xade5('0x27')](_0x3b8aa2);return _0x5190b6['set'](_0xade5('0x2a'),_0x59cf2b+'-'+_0x2f5ce4+'/'+_0x1fc2c3)['json'](_0xfb019);}return null;};}function patchUpdates(_0x122c8a){return function(_0x5e4c6d){try{jsonpatch[_0xade5('0x2b')](_0x5e4c6d,_0x122c8a,!![]);}catch(_0x4f4b91){return BPromise[_0xade5('0x2c')](_0x4f4b91);}return _0x5e4c6d['save']();};}function saveUpdates(_0x5c9eb3,_0x4bb67b){return function(_0x5e5368){if(_0x5e5368){return _0x5e5368[_0xade5('0x2d')](_0x5c9eb3)[_0xade5('0x1a')](function(_0x57381f){return _0x57381f;});}return null;};}function removeEntity(_0x86c87a,_0x5cc68a){return function(_0x1a5b7d){if(_0x1a5b7d){return _0x1a5b7d['destroy']()[_0xade5('0x1a')](function(){var _0x176670=_0x1a5b7d['get']({'plain':!![]});var _0xb1bb3c=_0xade5('0x2e');return db[_0xade5('0x2f')]['destroy']({'where':{'type':_0xb1bb3c,'resourceId':_0x176670['id']}})['then'](function(){return _0x1a5b7d;});})[_0xade5('0x1a')](function(){_0x86c87a[_0xade5('0x27')](0xcc)[_0xade5('0x26')]();});}};}function handleEntityNotFound(_0x3dba5d,_0xa7aeb2){return function(_0x529bee){if(!_0x529bee){_0x3dba5d['sendStatus'](0x194);}return _0x529bee;};}function handleError(_0x47484b,_0x15b8f3){_0x15b8f3=_0x15b8f3||0x1f4;return function(_0x53e7f3){logger[_0xade5('0x21')](_0x53e7f3[_0xade5('0x30')]);if(_0x53e7f3[_0xade5('0x31')]){delete _0x53e7f3['name'];}_0x47484b[_0xade5('0x27')](_0x15b8f3)[_0xade5('0x32')](_0x53e7f3);};}exports['index']=function(_0xfb3c34,_0x5ec60d){var _0x5865b7={},_0x129a43={},_0x4e4355={'count':0x0,'rows':[]};var _0x1151b6=_[_0xade5('0x33')](db[_0xade5('0x34')][_0xade5('0x35')],function(_0x1812da){return{'name':_0x1812da[_0xade5('0x36')],'type':_0x1812da[_0xade5('0x37')][_0xade5('0x38')]};});_0x129a43[_0xade5('0x39')]=_['map'](_0x1151b6,_0xade5('0x31'));_0x129a43['query']=_[_0xade5('0x3a')](_0xfb3c34[_0xade5('0x3b')]);_0x129a43[_0xade5('0x3c')]=_[_0xade5('0x3d')](_0x129a43[_0xade5('0x39')],_0x129a43[_0xade5('0x3b')]);_0x5865b7['attributes']=_[_0xade5('0x3d')](_0x129a43[_0xade5('0x39')],qs[_0xade5('0x3e')](_0xfb3c34[_0xade5('0x3b')][_0xade5('0x3e')]));_0x5865b7['attributes']=_0x5865b7['attributes'][_0xade5('0x3f')]?_0x5865b7[_0xade5('0x40')]:_0x129a43['model'];if(!_0xfb3c34[_0xade5('0x3b')]['hasOwnProperty'](_0xade5('0x41'))){_0x5865b7[_0xade5('0x42')]=qs[_0xade5('0x42')](_0xfb3c34[_0xade5('0x3b')]['limit']);_0x5865b7[_0xade5('0x29')]=qs[_0xade5('0x29')](_0xfb3c34[_0xade5('0x3b')][_0xade5('0x29')]);}_0x5865b7[_0xade5('0x43')]=qs[_0xade5('0x44')](_0xfb3c34[_0xade5('0x3b')][_0xade5('0x44')]);_0x5865b7[_0xade5('0x45')]=qs[_0xade5('0x3c')](_[_0xade5('0x46')](_0xfb3c34[_0xade5('0x3b')],_0x129a43[_0xade5('0x3c')]),_0x1151b6);if(_0xfb3c34['query'][_0xade5('0x47')]){_0x5865b7[_0xade5('0x45')]=_['merge'](_0x5865b7['where'],{'$or':_[_0xade5('0x33')](_0x1151b6,function(_0x1d90e5){if(_0x1d90e5[_0xade5('0x37')]!==_0xade5('0x48')){var _0x14459e={};_0x14459e[_0x1d90e5[_0xade5('0x31')]]={'$like':'%'+_0xfb3c34['query'][_0xade5('0x47')]+'%'};return _0x14459e;}})});}_0x5865b7=_[_0xade5('0x49')]({},_0x5865b7,_0xfb3c34[_0xade5('0x4a')]);var _0x23e843={'where':_0x5865b7[_0xade5('0x45')]};return db[_0xade5('0x34')][_0xade5('0x28')](_0x23e843)[_0xade5('0x1a')](function(_0x9231db){_0x4e4355['count']=_0x9231db;if(_0xfb3c34[_0xade5('0x3b')]['includeAll']){_0x5865b7[_0xade5('0x4b')]=[{'all':!![]}];}return db['Trunk']['findAll'](_0x5865b7);})[_0xade5('0x1a')](function(_0x21f366){_0x4e4355[_0xade5('0x4c')]=_0x21f366;return _0x4e4355;})['then'](respondWithFilteredResult(_0x5ec60d,_0x5865b7))[_0xade5('0x24')](handleError(_0x5ec60d,null));};exports[_0xade5('0x4d')]=function(_0x116622,_0x3e8d36){var _0x8e3f8e={'raw':![],'where':{'id':_0x116622[_0xade5('0x4e')]['id']}},_0x590a8e={};_0x590a8e['model']=_[_0xade5('0x3a')](db['Trunk'][_0xade5('0x35')]);_0x590a8e[_0xade5('0x3b')]=_['keys'](_0x116622[_0xade5('0x3b')]);_0x590a8e[_0xade5('0x3c')]=_[_0xade5('0x3d')](_0x590a8e[_0xade5('0x39')],_0x590a8e[_0xade5('0x3b')]);_0x8e3f8e[_0xade5('0x40')]=_[_0xade5('0x3d')](_0x590a8e[_0xade5('0x39')],qs[_0xade5('0x3e')](_0x116622[_0xade5('0x3b')][_0xade5('0x3e')]));_0x8e3f8e['attributes']=_0x8e3f8e[_0xade5('0x40')]['length']?_0x8e3f8e[_0xade5('0x40')]:_0x590a8e[_0xade5('0x39')];if(_0x116622[_0xade5('0x3b')][_0xade5('0x4f')]){_0x8e3f8e[_0xade5('0x4b')]=[{'all':!![]}];}_0x8e3f8e=_['merge']({},_0x8e3f8e,_0x116622['options']);return db[_0xade5('0x34')][_0xade5('0x50')](_0x8e3f8e)[_0xade5('0x1a')](handleEntityNotFound(_0x3e8d36,null))['then'](respondWithResult(_0x3e8d36,null))['catch'](handleError(_0x3e8d36,null));};exports[_0xade5('0x51')]=function(_0x5221de,_0x4cc17a){var _0x1fa7ff={'where':{'id':_0x5221de['params']['id']}},_0x3acfed={};_0x3acfed[_0xade5('0x39')]=_[_0xade5('0x3a')](db[_0xade5('0x34')][_0xade5('0x35')]);_0x1fa7ff[_0xade5('0x40')]=_[_0xade5('0x3d')](_0x3acfed[_0xade5('0x39')],qs[_0xade5('0x3e')](_0x5221de['query'][_0xade5('0x3e')]));_0x1fa7ff[_0xade5('0x40')]=_0x1fa7ff[_0xade5('0x40')][_0xade5('0x3f')]?_0x1fa7ff[_0xade5('0x40')]:_0x3acfed[_0xade5('0x39')];if(_0x5221de[_0xade5('0x3b')][_0xade5('0x4f')]){_0x1fa7ff[_0xade5('0x4b')]=[{'all':!![]}];}_0x1fa7ff=_[_0xade5('0x49')]({},_0x1fa7ff,_0x5221de['options']);return db[_0xade5('0x34')][_0xade5('0x50')](_0x1fa7ff)[_0xade5('0x1a')](handleEntityNotFound(_0x4cc17a,null))[_0xade5('0x1a')](function(_0x45265f){if(_0x45265f){var _0x2c2168=_0x45265f['get']({'plain':!![]});_0x2c2168=qs[_0xade5('0x52')](_0x2c2168,['id',_0xade5('0x53'),_0xade5('0x54')]);_0x5221de['body']=_[_0xade5('0x52')](_0x5221de[_0xade5('0x55')],['id',_0xade5('0x53'),_0xade5('0x54')]);return db[_0xade5('0x34')][_0xade5('0x56')](_[_0xade5('0x49')](_0x2c2168,_0x5221de[_0xade5('0x55')]),{'include':_0x5221de[_0xade5('0x3b')]['includeAll']?[{'all':!![]}]:undefined})['then'](function(_0x2f90df){var _0x3bce83=_0x5221de[_0xade5('0x57')]['get']({'plain':!![]});if(!_0x3bce83)throw new Error(_0xade5('0x58'));if(_0x3bce83[_0xade5('0x59')]===_0xade5('0x57')){var _0x4cfc1a=_0x2f90df[_0xade5('0x5a')]({'plain':!![]});var _0x9ae9ef=_0xade5('0x2e');return db[_0xade5('0x5b')][_0xade5('0x50')]({'where':{'name':_0x9ae9ef,'userProfileId':_0x3bce83['userProfileId']},'raw':!![]})[_0xade5('0x1a')](function(_0x5272f0){if(_0x5272f0&&_0x5272f0[_0xade5('0x5c')]===0x0){return db[_0xade5('0x2f')]['create']({'name':_0x4cfc1a[_0xade5('0x31')],'resourceId':_0x4cfc1a['id'],'type':_0x5272f0['name'],'sectionId':_0x5272f0['id']},{})['then'](function(){return _0x2f90df;});}else{return _0x2f90df;}})[_0xade5('0x24')](function(_0x366468){logger['error'](_0xade5('0x5d'),_0x366468);throw _0x366468;});}return _0x2f90df;});}})['then'](respondWithResult(_0x4cc17a,0xc9))['catch'](handleError(_0x4cc17a,null));};exports[_0xade5('0x56')]=function(_0x451b28,_0x30f11f,_0x9cd29d){var _0x2ad922;return db[_0xade5('0x34')][_0xade5('0x56')](_0x451b28['body'],{'raw':!![]})['then'](function(_0x3d858c){_0x2ad922=_0x3d858c;return db[_0xade5('0x34')]['findAll']({'raw':!![]});})[_0xade5('0x1a')](function(_0x4d8f2f){var _0x5d46f9=fs['readFileSync'](path[_0xade5('0x5e')](config[_0xade5('0x5f')],_0xade5('0x60')),'utf8');var _0x270c49=fs['readFileSync'](path['join'](config[_0xade5('0x5f')],_0xade5('0x61')),_0xade5('0x62'));var _0x9e222e=ejs[_0xade5('0x63')](_0x5d46f9,{'trunks':_0x4d8f2f||[]});fs['writeFileSync']('/etc/asterisk/sip_xcally_trunks.conf',_0x9e222e);if(_0x2ad922['registry']){var _0x457ac6=ejs[_0xade5('0x63')](_0x270c49,{'trunks':_0x4d8f2f||[]});fs[_0xade5('0x64')]('/etc/asterisk/sip_xcally_registers.conf',_0x457ac6);}})['then'](function(){return respondWithRpcPromise(_0xade5('0x65'),_0xade5('0x56'),{'module':'chan_sip.so'});})[_0xade5('0x1a')](function(){var _0xd35918=_0x451b28[_0xade5('0x57')][_0xade5('0x5a')]({'plain':!![]});if(!_0xd35918)throw new Error(_0xade5('0x58'));if(_0xd35918[_0xade5('0x59')]===_0xade5('0x57')){var _0x34aa7f=_0x2ad922[_0xade5('0x5a')]({'plain':!![]});return db[_0xade5('0x5b')][_0xade5('0x50')]({'where':{'name':'Trunks','userProfileId':_0xd35918['userProfileId']},'raw':!![]})[_0xade5('0x1a')](function(_0x190ae6){if(_0x190ae6&&_0x190ae6[_0xade5('0x5c')]===0x0){return db['UserProfileResource']['create']({'name':_0x34aa7f[_0xade5('0x31')],'resourceId':_0x34aa7f['id'],'type':_0x190ae6[_0xade5('0x31')],'sectionId':_0x190ae6['id']},{})['then'](function(){return _0x2ad922;});}else{return _0x2ad922;}})[_0xade5('0x24')](function(_0x81278a){logger[_0xade5('0x21')](_0xade5('0x5d'),_0x81278a);throw _0x81278a;});}return _0x2ad922;})[_0xade5('0x1a')](respondWithResult(_0x30f11f,0xc9))[_0xade5('0x24')](handleError(_0x30f11f,null));};exports[_0xade5('0x2d')]=function(_0x18c46b,_0x41d963,_0x3d373b){var _0xda7e3c;return db[_0xade5('0x34')][_0xade5('0x50')]({'where':{'id':_0x18c46b[_0xade5('0x4e')]['id']}})[_0xade5('0x1a')](handleEntityNotFound(_0x41d963,null))[_0xade5('0x1a')](saveUpdates(_0x18c46b['body'],null))[_0xade5('0x1a')](function(_0x33f8b0){if(_0x33f8b0){_0xda7e3c=_0x33f8b0;return db[_0xade5('0x34')][_0xade5('0x66')]({'raw':!![]});}})[_0xade5('0x1a')](function(_0xd4cd26){if(_0xd4cd26){var _0x9ed399=fs['readFileSync'](path[_0xade5('0x5e')](config[_0xade5('0x5f')],'server/files/templates/trunk.ejs'),_0xade5('0x62'));var _0x59a979=fs[_0xade5('0x67')](path['join'](config[_0xade5('0x5f')],_0xade5('0x61')),_0xade5('0x62'));var _0x4df488=ejs['render'](_0x9ed399,{'trunks':_0xd4cd26||[]});fs[_0xade5('0x64')]('/etc/asterisk/sip_xcally_trunks.conf',_0x4df488);var _0x206ec5=ejs['render'](_0x59a979,{'trunks':_0xd4cd26||[]});fs[_0xade5('0x64')](_0xade5('0x68'),_0x206ec5);return respondWithRpcPromise(_0xade5('0x65'),_0xade5('0x2d'),{'module':_0xade5('0x69')});}return null;})[_0xade5('0x1a')](function(_0x5e5d66){if(_0x5e5d66){return _0xda7e3c;}})['then'](respondWithResult(_0x41d963,null))[_0xade5('0x24')](handleError(_0x41d963,null));};exports['destroy']=function(_0x188671,_0x371f08,_0x32175e){var _0x463a35;return db[_0xade5('0x34')][_0xade5('0x50')]({'where':{'id':_0x188671[_0xade5('0x4e')]['id']}})[_0xade5('0x1a')](handleEntityNotFound(_0x371f08,null))[_0xade5('0x1a')](removeEntity(_0x371f08,null))[_0xade5('0x1a')](function(){return db[_0xade5('0x34')][_0xade5('0x66')]({'raw':!![]});})[_0xade5('0x1a')](function(_0x5d39e4){var _0x38450c=fs[_0xade5('0x67')](path[_0xade5('0x5e')](config[_0xade5('0x5f')],_0xade5('0x60')),_0xade5('0x62'));var _0x562799=fs[_0xade5('0x67')](path['join'](config[_0xade5('0x5f')],_0xade5('0x61')),_0xade5('0x62'));var _0x25ccf9=ejs[_0xade5('0x63')](_0x38450c,{'trunks':_0x5d39e4});var _0x3b4b4c=ejs['render'](_0x562799,{'trunks':_0x5d39e4});fs[_0xade5('0x64')]('/etc/asterisk/sip_xcally_trunks.conf',_0x25ccf9);fs[_0xade5('0x64')](_0xade5('0x68'),_0x3b4b4c);return respondWithRpcPromise(_0xade5('0x65'),_0xade5('0x6a'),{'module':_0xade5('0x69')});})['catch'](handleError(_0x371f08,null));};
\ No newline at end of file
+var _0xe14d=['options','includeAll','include','findAll','rows','params','keys','rawAttributes','find','omit','createdAt','updatedAt','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','userProfileId','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','join','server/files/templates/trunk.ejs','utf8','root','server/files/templates/registry.ejs','writeFileSync','/etc/asterisk/sip_xcally_trunks.conf','registry','Reload','UserProfileSection','autoAssociation','readFileSync','render','/etc/asterisk/sip_xcally_registers.conf','chan_sip.so','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','util','path','sox','to-csv','ejs','fs-extra','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','jayson/promise','client','http','request','then','info','Trunk,\x20%s,\x20%s','request\x20sent','debug','Trunk,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','apply','save','update','get','Trunks','UserProfileResource','destroy','stack','name','map','Trunk','fieldName','type','key','model','query','filters','intersection','fields','attributes','length','nolimit','order','where','pick','filter','merge','VIRTUAL'];(function(_0x5b479f,_0x1b3d7e){var _0x2cfdd0=function(_0x4a5ecd){while(--_0x4a5ecd){_0x5b479f['push'](_0x5b479f['shift']());}};_0x2cfdd0(++_0x1b3d7e);}(_0xe14d,0x1ee));var _0xde14=function(_0x2dafbe,_0x5d04de){_0x2dafbe=_0x2dafbe-0x0;var _0x58a45a=_0xe14d[_0x2dafbe];return _0x58a45a;};'use strict';var emlformat=require(_0xde14('0x0'));var rimraf=require(_0xde14('0x1'));var zipdir=require(_0xde14('0x2'));var jsonpatch=require(_0xde14('0x3'));var rp=require('request-promise');var moment=require(_0xde14('0x4'));var BPromise=require(_0xde14('0x5'));var Mustache=require('mustache');var util=require(_0xde14('0x6'));var path=require(_0xde14('0x7'));var sox=require(_0xde14('0x8'));var csv=require(_0xde14('0x9'));var ejs=require(_0xde14('0xa'));var fs=require('fs');var fs_extra=require(_0xde14('0xb'));var _=require('lodash');var squel=require('squel');var crypto=require(_0xde14('0xc'));var jsforce=require(_0xde14('0xd'));var deskjs=require(_0xde14('0xe'));var toCsv=require(_0xde14('0x9'));var querystring=require(_0xde14('0xf'));var Papa=require(_0xde14('0x10'));var Redis=require(_0xde14('0x11'));var authService=require(_0xde14('0x12'));var qs=require('../../components/parsers/qs');var as=require(_0xde14('0x13'));var hardwareService=require(_0xde14('0x14'));var logger=require(_0xde14('0x15'))(_0xde14('0x16'));var utils=require(_0xde14('0x17'));var config=require(_0xde14('0x18'));var licenseUtil=require(_0xde14('0x19'));var db=require(_0xde14('0x1a'))['db'];var jayson=require(_0xde14('0x1b'));var client=jayson[_0xde14('0x1c')][_0xde14('0x1d')]({'port':0x232a});function respondWithRpcPromise(_0x464624,_0x3521d4,_0x281c54,_0x1489e9){return new BPromise(function(_0x54c58b,_0x584959){var _0x23c878=_0x1489e9||client;return _0x23c878[_0xde14('0x1e')](_0x464624,_0x281c54)[_0xde14('0x1f')](function(_0x4c86ff){logger[_0xde14('0x20')](_0xde14('0x21'),_0x3521d4,_0xde14('0x22'));logger[_0xde14('0x23')](_0xde14('0x24'),_0x3521d4,_0xde14('0x22'),JSON[_0xde14('0x25')](_0x4c86ff));if(_0x4c86ff[_0xde14('0x26')]){if(_0x4c86ff[_0xde14('0x26')][_0xde14('0x27')]===0x1f4){logger['error'](_0xde14('0x21'),_0x3521d4,_0x4c86ff[_0xde14('0x26')][_0xde14('0x28')]);return _0x584959(_0x4c86ff[_0xde14('0x26')]['message']);}logger[_0xde14('0x26')]('Trunk,\x20%s,\x20%s',_0x3521d4,_0x4c86ff[_0xde14('0x26')]['message']);return _0x54c58b(_0x4c86ff[_0xde14('0x26')][_0xde14('0x28')]);}else{logger[_0xde14('0x20')](_0xde14('0x21'),_0x3521d4,_0xde14('0x22'));_0x54c58b(_0x4c86ff[_0xde14('0x29')][_0xde14('0x28')]);}})[_0xde14('0x2a')](function(_0xdd8d59){logger[_0xde14('0x26')](_0xde14('0x21'),_0x3521d4,_0xdd8d59);_0x584959(_0xdd8d59);});});}function respondWithStatusCode(_0xbaa078,_0x8f8033){_0x8f8033=_0x8f8033||0xcc;return function(_0x5ae4c1){if(_0x5ae4c1){return _0xbaa078[_0xde14('0x2b')](_0x8f8033);}return _0xbaa078[_0xde14('0x2c')](_0x8f8033)[_0xde14('0x2d')]();};}function respondWithResult(_0xbd05d6,_0x1bb7be){_0x1bb7be=_0x1bb7be||0xc8;return function(_0x21ef15){if(_0x21ef15){return _0xbd05d6[_0xde14('0x2c')](_0x1bb7be)[_0xde14('0x2e')](_0x21ef15);}};}function respondWithFilteredResult(_0x1618e1,_0x350a78){return function(_0x4eff65){if(_0x4eff65){var _0x309922=typeof _0x350a78[_0xde14('0x2f')]===_0xde14('0x30')&&typeof _0x350a78[_0xde14('0x31')]==='undefined';var _0x3fc2a4=_0x4eff65[_0xde14('0x32')];var _0x30c4a8=_0x309922?0x0:_0x350a78['offset'];var _0x4655fb=_0x309922?_0x4eff65['count']:_0x350a78[_0xde14('0x2f')]+_0x350a78[_0xde14('0x31')];var _0x3bb1da;if(_0x4655fb>=_0x3fc2a4){_0x4655fb=_0x3fc2a4;_0x3bb1da=0xc8;}else{_0x3bb1da=0xce;}_0x1618e1[_0xde14('0x2c')](_0x3bb1da);return _0x1618e1[_0xde14('0x33')](_0xde14('0x34'),_0x30c4a8+'-'+_0x4655fb+'/'+_0x3fc2a4)[_0xde14('0x2e')](_0x4eff65);}return null;};}function patchUpdates(_0x464666){return function(_0x4e7c5b){try{jsonpatch[_0xde14('0x35')](_0x4e7c5b,_0x464666,!![]);}catch(_0xbf49ac){return BPromise['reject'](_0xbf49ac);}return _0x4e7c5b[_0xde14('0x36')]();};}function saveUpdates(_0x4c9b15,_0x2e40ad){return function(_0x44e88a){if(_0x44e88a){return _0x44e88a[_0xde14('0x37')](_0x4c9b15)[_0xde14('0x1f')](function(_0x13c164){return _0x13c164;});}return null;};}function removeEntity(_0x57fc47,_0x26dfa9){return function(_0x57b98b){if(_0x57b98b){return _0x57b98b['destroy']()[_0xde14('0x1f')](function(){var _0x3c943b=_0x57b98b[_0xde14('0x38')]({'plain':!![]});var _0x319136=_0xde14('0x39');return db[_0xde14('0x3a')][_0xde14('0x3b')]({'where':{'type':_0x319136,'resourceId':_0x3c943b['id']}})[_0xde14('0x1f')](function(){return _0x57b98b;});})[_0xde14('0x1f')](function(){_0x57fc47['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x1c7136,_0x403007){return function(_0x20913d){if(!_0x20913d){_0x1c7136[_0xde14('0x2b')](0x194);}return _0x20913d;};}function handleError(_0x31cad4,_0x23813f){_0x23813f=_0x23813f||0x1f4;return function(_0x1f42ab){logger[_0xde14('0x26')](_0x1f42ab[_0xde14('0x3c')]);if(_0x1f42ab['name']){delete _0x1f42ab[_0xde14('0x3d')];}_0x31cad4['status'](_0x23813f)['send'](_0x1f42ab);};}exports['index']=function(_0xb0eba6,_0x258759){var _0x398f63={},_0x152dab={},_0x1228d8={'count':0x0,'rows':[]};var _0x8b5bb4=_[_0xde14('0x3e')](db[_0xde14('0x3f')]['rawAttributes'],function(_0xc2a39d){return{'name':_0xc2a39d[_0xde14('0x40')],'type':_0xc2a39d[_0xde14('0x41')][_0xde14('0x42')]};});_0x152dab[_0xde14('0x43')]=_[_0xde14('0x3e')](_0x8b5bb4,_0xde14('0x3d'));_0x152dab[_0xde14('0x44')]=_['keys'](_0xb0eba6[_0xde14('0x44')]);_0x152dab[_0xde14('0x45')]=_[_0xde14('0x46')](_0x152dab[_0xde14('0x43')],_0x152dab['query']);_0x398f63['attributes']=_[_0xde14('0x46')](_0x152dab[_0xde14('0x43')],qs[_0xde14('0x47')](_0xb0eba6[_0xde14('0x44')][_0xde14('0x47')]));_0x398f63['attributes']=_0x398f63[_0xde14('0x48')][_0xde14('0x49')]?_0x398f63[_0xde14('0x48')]:_0x152dab['model'];if(!_0xb0eba6[_0xde14('0x44')]['hasOwnProperty'](_0xde14('0x4a'))){_0x398f63['limit']=qs[_0xde14('0x31')](_0xb0eba6[_0xde14('0x44')][_0xde14('0x31')]);_0x398f63[_0xde14('0x2f')]=qs[_0xde14('0x2f')](_0xb0eba6[_0xde14('0x44')][_0xde14('0x2f')]);}_0x398f63[_0xde14('0x4b')]=qs['sort'](_0xb0eba6[_0xde14('0x44')]['sort']);_0x398f63[_0xde14('0x4c')]=qs['filters'](_[_0xde14('0x4d')](_0xb0eba6[_0xde14('0x44')],_0x152dab[_0xde14('0x45')]),_0x8b5bb4);if(_0xb0eba6[_0xde14('0x44')][_0xde14('0x4e')]){_0x398f63[_0xde14('0x4c')]=_[_0xde14('0x4f')](_0x398f63[_0xde14('0x4c')],{'$or':_['map'](_0x8b5bb4,function(_0x15859c){if(_0x15859c[_0xde14('0x41')]!==_0xde14('0x50')){var _0x4b1ef7={};_0x4b1ef7[_0x15859c['name']]={'$like':'%'+_0xb0eba6[_0xde14('0x44')][_0xde14('0x4e')]+'%'};return _0x4b1ef7;}})});}_0x398f63=_[_0xde14('0x4f')]({},_0x398f63,_0xb0eba6[_0xde14('0x51')]);var _0x39572b={'where':_0x398f63[_0xde14('0x4c')]};return db['Trunk'][_0xde14('0x32')](_0x39572b)['then'](function(_0xa408ec){_0x1228d8[_0xde14('0x32')]=_0xa408ec;if(_0xb0eba6['query'][_0xde14('0x52')]){_0x398f63[_0xde14('0x53')]=[{'all':!![]}];}return db[_0xde14('0x3f')][_0xde14('0x54')](_0x398f63);})[_0xde14('0x1f')](function(_0x1c87e1){_0x1228d8[_0xde14('0x55')]=_0x1c87e1;return _0x1228d8;})['then'](respondWithFilteredResult(_0x258759,_0x398f63))[_0xde14('0x2a')](handleError(_0x258759,null));};exports['show']=function(_0xfa80c8,_0x6aa9ab){var _0x237be4={'raw':![],'where':{'id':_0xfa80c8[_0xde14('0x56')]['id']}},_0x235202={};_0x235202[_0xde14('0x43')]=_[_0xde14('0x57')](db[_0xde14('0x3f')][_0xde14('0x58')]);_0x235202[_0xde14('0x44')]=_['keys'](_0xfa80c8[_0xde14('0x44')]);_0x235202[_0xde14('0x45')]=_[_0xde14('0x46')](_0x235202[_0xde14('0x43')],_0x235202[_0xde14('0x44')]);_0x237be4['attributes']=_[_0xde14('0x46')](_0x235202['model'],qs[_0xde14('0x47')](_0xfa80c8[_0xde14('0x44')][_0xde14('0x47')]));_0x237be4[_0xde14('0x48')]=_0x237be4[_0xde14('0x48')]['length']?_0x237be4['attributes']:_0x235202[_0xde14('0x43')];if(_0xfa80c8['query'][_0xde14('0x52')]){_0x237be4[_0xde14('0x53')]=[{'all':!![]}];}_0x237be4=_[_0xde14('0x4f')]({},_0x237be4,_0xfa80c8[_0xde14('0x51')]);return db[_0xde14('0x3f')][_0xde14('0x59')](_0x237be4)[_0xde14('0x1f')](handleEntityNotFound(_0x6aa9ab,null))[_0xde14('0x1f')](respondWithResult(_0x6aa9ab,null))[_0xde14('0x2a')](handleError(_0x6aa9ab,null));};exports['clone']=function(_0x205a94,_0x2c972b){var _0x1ea6d2={'where':{'id':_0x205a94[_0xde14('0x56')]['id']}},_0x21d226={};_0x21d226['model']=_[_0xde14('0x57')](db['Trunk'][_0xde14('0x58')]);_0x1ea6d2[_0xde14('0x48')]=_[_0xde14('0x46')](_0x21d226[_0xde14('0x43')],qs[_0xde14('0x47')](_0x205a94[_0xde14('0x44')][_0xde14('0x47')]));_0x1ea6d2[_0xde14('0x48')]=_0x1ea6d2['attributes']['length']?_0x1ea6d2['attributes']:_0x21d226[_0xde14('0x43')];if(_0x205a94['query']['includeAll']){_0x1ea6d2[_0xde14('0x53')]=[{'all':!![]}];}_0x1ea6d2=_[_0xde14('0x4f')]({},_0x1ea6d2,_0x205a94[_0xde14('0x51')]);return db[_0xde14('0x3f')][_0xde14('0x59')](_0x1ea6d2)[_0xde14('0x1f')](handleEntityNotFound(_0x2c972b,null))[_0xde14('0x1f')](function(_0x13f698){if(_0x13f698){var _0x2dd108=_0x13f698['get']({'plain':!![]});_0x2dd108=qs[_0xde14('0x5a')](_0x2dd108,['id',_0xde14('0x5b'),_0xde14('0x5c')]);_0x205a94['body']=_[_0xde14('0x5a')](_0x205a94['body'],['id',_0xde14('0x5b'),_0xde14('0x5c')]);return db[_0xde14('0x3f')][_0xde14('0x5d')](_[_0xde14('0x4f')](_0x2dd108,_0x205a94[_0xde14('0x5e')]),{'include':_0x205a94[_0xde14('0x44')]['includeAll']?[{'all':!![]}]:undefined})[_0xde14('0x1f')](function(_0x25ba7e){var _0x1a0bb1=_0x205a94[_0xde14('0x5f')][_0xde14('0x38')]({'plain':!![]});if(!_0x1a0bb1)throw new Error(_0xde14('0x60'));if(_0x1a0bb1[_0xde14('0x61')]==='user'){var _0x4a9e85=_0x25ba7e[_0xde14('0x38')]({'plain':!![]});var _0x19a162=_0xde14('0x39');return db['UserProfileSection'][_0xde14('0x59')]({'where':{'name':_0x19a162,'userProfileId':_0x1a0bb1[_0xde14('0x62')]},'raw':!![]})[_0xde14('0x1f')](function(_0x32e075){if(_0x32e075&&_0x32e075['autoAssociation']===0x0){return db['UserProfileResource'][_0xde14('0x5d')]({'name':_0x4a9e85[_0xde14('0x3d')],'resourceId':_0x4a9e85['id'],'type':_0x32e075[_0xde14('0x3d')],'sectionId':_0x32e075['id']},{})[_0xde14('0x1f')](function(){return _0x25ba7e;});}else{return _0x25ba7e;}})[_0xde14('0x2a')](function(_0x120284){logger[_0xde14('0x26')](_0xde14('0x63'),_0x120284);throw _0x120284;});}return _0x25ba7e;});}})[_0xde14('0x1f')](respondWithResult(_0x2c972b,0xc9))[_0xde14('0x2a')](handleError(_0x2c972b,null));};exports[_0xde14('0x5d')]=function(_0x299b69,_0x1ff577,_0x42329a){var _0x6a641f;return db[_0xde14('0x3f')][_0xde14('0x5d')](_0x299b69[_0xde14('0x5e')],{'raw':!![]})[_0xde14('0x1f')](function(_0x1b5d70){_0x6a641f=_0x1b5d70;return db[_0xde14('0x3f')][_0xde14('0x54')]({'raw':!![]});})[_0xde14('0x1f')](function(_0x4809fa){var _0x1084fb=fs['readFileSync'](path[_0xde14('0x64')](config['root'],_0xde14('0x65')),_0xde14('0x66'));var _0x3aaba2=fs['readFileSync'](path['join'](config[_0xde14('0x67')],_0xde14('0x68')),_0xde14('0x66'));var _0x430bdb=ejs['render'](_0x1084fb,{'trunks':_0x4809fa||[]});fs[_0xde14('0x69')](_0xde14('0x6a'),_0x430bdb);if(_0x6a641f[_0xde14('0x6b')]){var _0x500344=ejs['render'](_0x3aaba2,{'trunks':_0x4809fa||[]});fs['writeFileSync']('/etc/asterisk/sip_xcally_registers.conf',_0x500344);}})[_0xde14('0x1f')](function(){return respondWithRpcPromise(_0xde14('0x6c'),_0xde14('0x5d'),{'module':'chan_sip.so'});})[_0xde14('0x1f')](function(){var _0x37f7c3=_0x299b69[_0xde14('0x5f')][_0xde14('0x38')]({'plain':!![]});if(!_0x37f7c3)throw new Error(_0xde14('0x60'));if(_0x37f7c3[_0xde14('0x61')]==='user'){var _0x579a6c=_0x6a641f[_0xde14('0x38')]({'plain':!![]});return db[_0xde14('0x6d')]['find']({'where':{'name':_0xde14('0x39'),'userProfileId':_0x37f7c3[_0xde14('0x62')]},'raw':!![]})[_0xde14('0x1f')](function(_0x367ede){if(_0x367ede&&_0x367ede[_0xde14('0x6e')]===0x0){return db[_0xde14('0x3a')][_0xde14('0x5d')]({'name':_0x579a6c['name'],'resourceId':_0x579a6c['id'],'type':_0x367ede['name'],'sectionId':_0x367ede['id']},{})['then'](function(){return _0x6a641f;});}else{return _0x6a641f;}})['catch'](function(_0x3dbda9){logger[_0xde14('0x26')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x3dbda9);throw _0x3dbda9;});}return _0x6a641f;})['then'](respondWithResult(_0x1ff577,0xc9))[_0xde14('0x2a')](handleError(_0x1ff577,null));};exports[_0xde14('0x37')]=function(_0xe2b9f5,_0x5805ec,_0x1aa75d){var _0x2b1e2e;return db['Trunk'][_0xde14('0x59')]({'where':{'id':_0xe2b9f5[_0xde14('0x56')]['id']}})[_0xde14('0x1f')](handleEntityNotFound(_0x5805ec,null))[_0xde14('0x1f')](saveUpdates(_0xe2b9f5['body'],null))[_0xde14('0x1f')](function(_0x5a5b25){if(_0x5a5b25){_0x2b1e2e=_0x5a5b25;return db[_0xde14('0x3f')][_0xde14('0x54')]({'raw':!![]});}})[_0xde14('0x1f')](function(_0x5f49d1){if(_0x5f49d1){var _0x283eb8=fs[_0xde14('0x6f')](path[_0xde14('0x64')](config[_0xde14('0x67')],_0xde14('0x65')),'utf8');var _0x53433d=fs[_0xde14('0x6f')](path[_0xde14('0x64')](config[_0xde14('0x67')],'server/files/templates/registry.ejs'),_0xde14('0x66'));var _0x1a12b5=ejs[_0xde14('0x70')](_0x283eb8,{'trunks':_0x5f49d1||[]});fs[_0xde14('0x69')](_0xde14('0x6a'),_0x1a12b5);var _0x2cc5b7=ejs[_0xde14('0x70')](_0x53433d,{'trunks':_0x5f49d1||[]});fs['writeFileSync'](_0xde14('0x71'),_0x2cc5b7);return respondWithRpcPromise(_0xde14('0x6c'),_0xde14('0x37'),{'module':_0xde14('0x72')});}return null;})[_0xde14('0x1f')](function(_0x1732d0){if(_0x1732d0){return _0x2b1e2e;}})[_0xde14('0x1f')](respondWithResult(_0x5805ec,null))['catch'](handleError(_0x5805ec,null));};exports[_0xde14('0x3b')]=function(_0x1bdeae,_0x5f4b92,_0x4543f1){var _0x4a0108;return db[_0xde14('0x3f')]['find']({'where':{'id':_0x1bdeae[_0xde14('0x56')]['id']}})[_0xde14('0x1f')](handleEntityNotFound(_0x5f4b92,null))[_0xde14('0x1f')](removeEntity(_0x5f4b92,null))[_0xde14('0x1f')](function(){return db[_0xde14('0x3f')][_0xde14('0x54')]({'raw':!![]});})['then'](function(_0x43a155){var _0x58cf06=fs[_0xde14('0x6f')](path['join'](config[_0xde14('0x67')],_0xde14('0x65')),_0xde14('0x66'));var _0x4a1114=fs[_0xde14('0x6f')](path[_0xde14('0x64')](config[_0xde14('0x67')],'server/files/templates/registry.ejs'),'utf8');var _0x495741=ejs['render'](_0x58cf06,{'trunks':_0x43a155});var _0x381d6d=ejs[_0xde14('0x70')](_0x4a1114,{'trunks':_0x43a155});fs['writeFileSync'](_0xde14('0x6a'),_0x495741);fs[_0xde14('0x69')](_0xde14('0x71'),_0x381d6d);return respondWithRpcPromise(_0xde14('0x6c'),_0xde14('0x3b'),{'module':'chan_sip.so'});})[_0xde14('0x2a')](handleError(_0x5f4b92,null));};
\ No newline at end of file