Built motion from commit 37e1ed56.|2.6.29
[motion2.git] / server / api / network / network.controller.js
index e1bf6b7..6005078 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x16f9=['Network,\x20%s,\x20%s,\x20%s','stringify','error','message','result','catch','status','limit','undefined','count','offset','set','Content-Range','json','update','destroy','end','sendStatus','stack','name','index','map','Network','rawAttributes','fieldName','type','key','query','keys','filters','intersection','model','attributes','fields','length','hasOwnProperty','order','sort','where','pick','filter','merge','VIRTUAL','include','show','params','includeAll','create','body','toUpperCase','readFileSync','root','utf8','render','/etc/asterisk/stun_xcally.conf','Reload','TURN','server/files/templates/turn_multiple.ejs','writeFileSync','/etc/asterisk/turn_xcally.conf','res_stun_monitor.so','join','server/files/templates/network.ejs','format','/etc/asterisk/sip_xcally_%s.conf','find','findAll','STUN','server/files/templates/stun_multiple.ejs','chan_sip.so','util','ejs','lodash','../../components/parsers/qs','../../config/logger','api','../../config/environment','../../mysqldb','client','http','request','then','info','Network,\x20%s,\x20%s','request\x20sent'];(function(_0x37851a,_0x1e457f){var _0x219d24=function(_0x8ace06){while(--_0x8ace06){_0x37851a['push'](_0x37851a['shift']());}};_0x219d24(++_0x1e457f);}(_0x16f9,0xf0));var _0x916f=function(_0x4a7e93,_0x561d34){_0x4a7e93=_0x4a7e93-0x0;var _0x5f303a=_0x16f9[_0x4a7e93];return _0x5f303a;};'use strict';var util=require(_0x916f('0x0'));var path=require('path');var ejs=require(_0x916f('0x1'));var fs=require('fs');var _=require(_0x916f('0x2'));var qs=require(_0x916f('0x3'));var logger=require(_0x916f('0x4'))(_0x916f('0x5'));var config=require(_0x916f('0x6'));var db=require(_0x916f('0x7'))['db'];var jayson=require('jayson/promise');var client=jayson[_0x916f('0x8')][_0x916f('0x9')]({'port':0x232a});function respondWithRpcPromise(_0x8eaf7b,_0x2ee96d,_0x45fc34,_0x3bf59f){return new Promise(function(_0x460a2f,_0x4bb4c4){var _0x3d8284=_0x3bf59f||client;return _0x3d8284[_0x916f('0xa')](_0x8eaf7b,_0x45fc34)[_0x916f('0xb')](function(_0x3abac5){logger[_0x916f('0xc')](_0x916f('0xd'),_0x2ee96d,_0x916f('0xe'));logger['debug'](_0x916f('0xf'),_0x2ee96d,_0x916f('0xe'),JSON[_0x916f('0x10')](_0x3abac5));if(_0x3abac5[_0x916f('0x11')]){if(_0x3abac5['error']['code']===0x1f4){logger[_0x916f('0x11')](_0x916f('0xd'),_0x2ee96d,_0x3abac5[_0x916f('0x11')][_0x916f('0x12')]);return _0x4bb4c4(_0x3abac5[_0x916f('0x11')][_0x916f('0x12')]);}logger[_0x916f('0x11')](_0x916f('0xd'),_0x2ee96d,_0x3abac5[_0x916f('0x11')]['message']);return _0x460a2f(_0x3abac5[_0x916f('0x11')][_0x916f('0x12')]);}else{logger[_0x916f('0xc')](_0x916f('0xd'),_0x2ee96d,_0x916f('0xe'));_0x460a2f(_0x3abac5[_0x916f('0x13')][_0x916f('0x12')]);}})[_0x916f('0x14')](function(_0x7e15b7){logger[_0x916f('0x11')](_0x916f('0xd'),_0x2ee96d,_0x7e15b7);_0x4bb4c4(_0x7e15b7);});});}function respondWithResult(_0x55561e,_0x2d8340){_0x2d8340=_0x2d8340||0xc8;return function(_0x2350ce){if(_0x2350ce){return _0x55561e[_0x916f('0x15')](_0x2d8340)['json'](_0x2350ce);}};}function respondWithFilteredResult(_0x442a5a,_0xca2e75){return function(_0x200462){if(_0x200462){var _0x4c8ebd=typeof _0xca2e75['offset']==='undefined'&&typeof _0xca2e75[_0x916f('0x16')]===_0x916f('0x17');var _0x16d166=_0x200462[_0x916f('0x18')];var _0x4bbb3f=_0x4c8ebd?0x0:_0xca2e75['offset'];var _0x51ba77=_0x4c8ebd?_0x200462[_0x916f('0x18')]:_0xca2e75[_0x916f('0x19')]+_0xca2e75[_0x916f('0x16')];var _0x3f94a6;if(_0x51ba77>=_0x16d166){_0x51ba77=_0x16d166;_0x3f94a6=0xc8;}else{_0x3f94a6=0xce;}_0x442a5a[_0x916f('0x15')](_0x3f94a6);return _0x442a5a[_0x916f('0x1a')](_0x916f('0x1b'),_0x4bbb3f+'-'+_0x51ba77+'/'+_0x16d166)[_0x916f('0x1c')](_0x200462);}return null;};}function saveUpdates(_0x5cab8d){return function(_0xbdbb9c){if(_0xbdbb9c){return _0xbdbb9c[_0x916f('0x1d')](_0x5cab8d)[_0x916f('0xb')](function(_0x1be4c4){return _0x1be4c4;});}return null;};}function removeEntity(_0x11b49b){return function(_0x1fea89){if(_0x1fea89){return _0x1fea89[_0x916f('0x1e')]()[_0x916f('0xb')](function(){_0x11b49b[_0x916f('0x15')](0xcc)[_0x916f('0x1f')]();});}};}function handleEntityNotFound(_0xd2fc79){return function(_0x52027a){if(!_0x52027a){_0xd2fc79[_0x916f('0x20')](0x194);}return _0x52027a;};}function handleError(_0x1b654a,_0x13ae07){_0x13ae07=_0x13ae07||0x1f4;return function(_0xdb5c33){logger[_0x916f('0x11')](_0xdb5c33[_0x916f('0x21')]);if(_0xdb5c33['name']){delete _0xdb5c33[_0x916f('0x22')];}_0x1b654a[_0x916f('0x15')](_0x13ae07)['send'](_0xdb5c33);};}exports[_0x916f('0x23')]=function(_0x3cb626,_0x5e2c27){var _0x41b722={},_0x3237e2={},_0x489f89={'count':0x0,'rows':[]};var _0x58367c=_[_0x916f('0x24')](db[_0x916f('0x25')][_0x916f('0x26')],function(_0x2cab64){return{'name':_0x2cab64[_0x916f('0x27')],'type':_0x2cab64[_0x916f('0x28')][_0x916f('0x29')]};});_0x3237e2['model']=_[_0x916f('0x24')](_0x58367c,_0x916f('0x22'));_0x3237e2[_0x916f('0x2a')]=_[_0x916f('0x2b')](_0x3cb626[_0x916f('0x2a')]);_0x3237e2[_0x916f('0x2c')]=_[_0x916f('0x2d')](_0x3237e2[_0x916f('0x2e')],_0x3237e2[_0x916f('0x2a')]);_0x41b722[_0x916f('0x2f')]=_[_0x916f('0x2d')](_0x3237e2[_0x916f('0x2e')],qs['fields'](_0x3cb626[_0x916f('0x2a')][_0x916f('0x30')]));_0x41b722['attributes']=_0x41b722[_0x916f('0x2f')][_0x916f('0x31')]?_0x41b722[_0x916f('0x2f')]:_0x3237e2[_0x916f('0x2e')];if(!_0x3cb626[_0x916f('0x2a')][_0x916f('0x32')]('nolimit')){_0x41b722[_0x916f('0x16')]=qs[_0x916f('0x16')](_0x3cb626[_0x916f('0x2a')][_0x916f('0x16')]);_0x41b722[_0x916f('0x19')]=qs[_0x916f('0x19')](_0x3cb626[_0x916f('0x2a')][_0x916f('0x19')]);}_0x41b722[_0x916f('0x33')]=qs[_0x916f('0x34')](_0x3cb626[_0x916f('0x2a')][_0x916f('0x34')]);_0x41b722[_0x916f('0x35')]=qs[_0x916f('0x2c')](_[_0x916f('0x36')](_0x3cb626[_0x916f('0x2a')],_0x3237e2[_0x916f('0x2c')]),_0x58367c);if(_0x3cb626[_0x916f('0x2a')][_0x916f('0x37')]){_0x41b722['where']=_[_0x916f('0x38')](_0x41b722[_0x916f('0x35')],{'$or':_[_0x916f('0x24')](_0x58367c,function(_0x40ce8c){if(_0x40ce8c[_0x916f('0x28')]!==_0x916f('0x39')){var _0x1cf194={};_0x1cf194[_0x40ce8c[_0x916f('0x22')]]={'$like':'%'+_0x3cb626[_0x916f('0x2a')]['filter']+'%'};return _0x1cf194;}})});}_0x41b722=_['merge']({},_0x41b722,_0x3cb626['options']);var _0x32bda9={'where':_0x41b722[_0x916f('0x35')]};return db[_0x916f('0x25')][_0x916f('0x18')](_0x32bda9)[_0x916f('0xb')](function(_0x103027){_0x489f89[_0x916f('0x18')]=_0x103027;if(_0x3cb626[_0x916f('0x2a')]['includeAll']){_0x41b722[_0x916f('0x3a')]=[{'all':!![]}];}return db[_0x916f('0x25')]['findAll'](_0x41b722);})[_0x916f('0xb')](function(_0x3c12d4){_0x489f89['rows']=_0x3c12d4;return _0x489f89;})[_0x916f('0xb')](respondWithFilteredResult(_0x5e2c27,_0x41b722))[_0x916f('0x14')](handleError(_0x5e2c27,null));};exports[_0x916f('0x3b')]=function(_0x1a5b17,_0xbff791){var _0x50b5c8={'raw':!![],'where':{'id':_0x1a5b17[_0x916f('0x3c')]['id']}},_0x5a1ad8={};_0x5a1ad8['model']=_[_0x916f('0x2b')](db[_0x916f('0x25')]['rawAttributes']);_0x5a1ad8[_0x916f('0x2a')]=_[_0x916f('0x2b')](_0x1a5b17['query']);_0x5a1ad8[_0x916f('0x2c')]=_[_0x916f('0x2d')](_0x5a1ad8[_0x916f('0x2e')],_0x5a1ad8[_0x916f('0x2a')]);_0x50b5c8[_0x916f('0x2f')]=_['intersection'](_0x5a1ad8[_0x916f('0x2e')],qs[_0x916f('0x30')](_0x1a5b17[_0x916f('0x2a')][_0x916f('0x30')]));_0x50b5c8[_0x916f('0x2f')]=_0x50b5c8[_0x916f('0x2f')]['length']?_0x50b5c8['attributes']:_0x5a1ad8[_0x916f('0x2e')];if(_0x1a5b17[_0x916f('0x2a')][_0x916f('0x3d')]){_0x50b5c8[_0x916f('0x3a')]=[{'all':!![]}];}_0x50b5c8=_[_0x916f('0x38')]({},_0x50b5c8,_0x1a5b17['options']);return db[_0x916f('0x25')]['find'](_0x50b5c8)['then'](handleEntityNotFound(_0xbff791,null))[_0x916f('0xb')](respondWithResult(_0xbff791,null))[_0x916f('0x14')](handleError(_0xbff791,null));};exports[_0x916f('0x3e')]=function(_0x37bec8,_0x5b4540){var _0x498bec;return db[_0x916f('0x25')][_0x916f('0x3e')](_0x37bec8[_0x916f('0x3f')],{'raw':!![]})[_0x916f('0xb')](function(_0x133c5b){_0x498bec=_0x133c5b;return db[_0x916f('0x25')]['findAll']({'where':{'type':_0x37bec8['body'][_0x916f('0x28')]},'raw':!![]});})[_0x916f('0xb')](function(_0x3e40c8){if(_0x498bec[_0x916f('0x28')][_0x916f('0x40')]()=='STUN'){var _0x2e31a2=fs[_0x916f('0x41')](path['join'](config[_0x916f('0x42')],'server/files/templates/stun_multiple.ejs'),_0x916f('0x43'));var _0x18ebaf=ejs[_0x916f('0x44')](_0x2e31a2,{'networks':_0x3e40c8||[]});fs['writeFileSync'](_0x916f('0x45'),_0x18ebaf);return respondWithRpcPromise(_0x916f('0x46'),'create',{'module':'res_stun_monitor.so'});}else if(_0x498bec[_0x916f('0x28')][_0x916f('0x40')]()==_0x916f('0x47')){var _0x9deedd=fs[_0x916f('0x41')](path['join'](config['root'],_0x916f('0x48')),_0x916f('0x43'));var _0x76aeb3=ejs[_0x916f('0x44')](_0x9deedd,{'networks':_0x3e40c8||[]});fs[_0x916f('0x49')](_0x916f('0x4a'),_0x76aeb3);return respondWithRpcPromise(_0x916f('0x46'),'create',{'module':_0x916f('0x4b')});}else{var _0x28ceb6=fs['readFileSync'](path[_0x916f('0x4c')](config[_0x916f('0x42')],_0x916f('0x4d')),'utf8');var _0x17977e=ejs[_0x916f('0x44')](_0x28ceb6,{'networks':_0x3e40c8||[]});fs['writeFileSync'](util[_0x916f('0x4e')](_0x916f('0x4f'),_0x37bec8[_0x916f('0x3f')]['type']['toLowerCase']()),_0x17977e);return respondWithRpcPromise(_0x916f('0x46'),'create',{'module':'chan_sip.so'});}})['then'](function(){return _0x498bec;})['then'](respondWithResult(_0x5b4540,0xc9))[_0x916f('0x14')](handleError(_0x5b4540,null));};exports['update']=function(_0x53dbfa,_0xd11b20){var _0xbf3fe3;return db['Network'][_0x916f('0x50')]({'where':{'id':_0x53dbfa[_0x916f('0x3c')]['id']}})[_0x916f('0xb')](handleEntityNotFound(_0xd11b20,null))[_0x916f('0xb')](saveUpdates(_0x53dbfa['body'],null))[_0x916f('0xb')](function(_0x1891a2){if(_0x1891a2){_0xbf3fe3=_0x1891a2;return db['Network'][_0x916f('0x51')]({'where':{'type':_0xbf3fe3['type']},'raw':!![]});}return null;})[_0x916f('0xb')](function(_0xce1256){if(_0xbf3fe3['type']['toUpperCase']()==_0x916f('0x52')){var _0xccf187=fs['readFileSync'](path[_0x916f('0x4c')](config[_0x916f('0x42')],_0x916f('0x53')),_0x916f('0x43'));var _0x4a5088=ejs[_0x916f('0x44')](_0xccf187,{'networks':_0xce1256||[]});fs['writeFileSync'](_0x916f('0x45'),_0x4a5088);return respondWithRpcPromise(_0x916f('0x46'),_0x916f('0x1d'),{'module':_0x916f('0x4b')});}else if(_0xbf3fe3[_0x916f('0x28')][_0x916f('0x40')]()==_0x916f('0x47')){var _0x109028=fs['readFileSync'](path[_0x916f('0x4c')](config[_0x916f('0x42')],_0x916f('0x48')),_0x916f('0x43'));var _0x40702a=ejs[_0x916f('0x44')](_0x109028,{'networks':_0xce1256||[]});fs[_0x916f('0x49')]('/etc/asterisk/turn_xcally.conf',_0x40702a);return respondWithRpcPromise(_0x916f('0x46'),_0x916f('0x1d'),{'module':_0x916f('0x4b')});}else{var _0x5be957=fs[_0x916f('0x41')](path[_0x916f('0x4c')](config[_0x916f('0x42')],_0x916f('0x4d')),_0x916f('0x43'));var _0xee9237=ejs[_0x916f('0x44')](_0x5be957,{'networks':_0xce1256||[]});fs[_0x916f('0x49')](util[_0x916f('0x4e')](_0x916f('0x4f'),_0x53dbfa['body'][_0x916f('0x28')]['toLowerCase']()),_0xee9237);return respondWithRpcPromise(_0x916f('0x46'),_0x916f('0x1d'),{'module':_0x916f('0x54')});}})[_0x916f('0xb')](function(_0x261998){if(_0x261998){return _0xbf3fe3;}return null;})[_0x916f('0xb')](respondWithResult(_0xd11b20,null))['catch'](handleError(_0xd11b20,null));};exports[_0x916f('0x1e')]=function(_0x570256,_0xa16018){var _0x49eddb;return db['Network'][_0x916f('0x50')]({'where':{'id':_0x570256[_0x916f('0x3c')]['id']}})['then'](function(_0x4f64cc){_0x49eddb=_0x4f64cc;return _0x4f64cc;})['then'](handleEntityNotFound(_0xa16018,null))[_0x916f('0xb')](removeEntity(_0xa16018,null))[_0x916f('0xb')](function(){if(_0x49eddb){return db[_0x916f('0x25')][_0x916f('0x51')]({'where':{'type':_0x49eddb[_0x916f('0x28')]},'raw':!![]});}})[_0x916f('0xb')](function(_0x5417b5){if(_0x49eddb[_0x916f('0x28')][_0x916f('0x40')]()==_0x916f('0x52')){var _0x30a3b4=fs[_0x916f('0x41')](path['join'](config['root'],_0x916f('0x53')),_0x916f('0x43'));var _0x1ff34a=ejs['render'](_0x30a3b4,{'networks':_0x5417b5||[]});fs[_0x916f('0x49')]('/etc/asterisk/stun_xcally.conf',_0x1ff34a);return respondWithRpcPromise(_0x916f('0x46'),_0x916f('0x1e'),{'module':'res_stun_monitor.so'});}else if(_0x49eddb[_0x916f('0x28')][_0x916f('0x40')]()==_0x916f('0x47')){var _0x30efb3=fs['readFileSync'](path[_0x916f('0x4c')](config[_0x916f('0x42')],_0x916f('0x48')),_0x916f('0x43'));var _0x4d6665=ejs[_0x916f('0x44')](_0x30efb3,{'networks':_0x5417b5||[]});fs[_0x916f('0x49')](_0x916f('0x4a'),_0x4d6665);return respondWithRpcPromise('Reload',_0x916f('0x1e'),{'module':_0x916f('0x4b')});}else{var _0x5c7118=fs[_0x916f('0x41')](path['join'](config[_0x916f('0x42')],_0x916f('0x4d')),_0x916f('0x43'));var _0x311828=ejs['render'](_0x5c7118,{'networks':_0x5417b5||[]});fs[_0x916f('0x49')](util['format'](_0x916f('0x4f'),_0x49eddb[_0x916f('0x28')]['toLowerCase']()),_0x311828);return respondWithRpcPromise(_0x916f('0x46'),'destroy',{'module':_0x916f('0x54')});}})[_0x916f('0x14')](handleError(_0xa16018,null));};
\ No newline at end of file
+var _0xb194=['Network,\x20%s,\x20%s','result','catch','status','json','offset','undefined','limit','count','set','Content-Range','update','end','sendStatus','stack','name','send','index','Network','rawAttributes','fieldName','type','model','query','keys','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','pick','filters','filter','where','merge','map','VIRTUAL','rows','show','includeAll','include','find','create','findAll','body','readFileSync','server/files/templates/stun_multiple.ejs','utf8','render','writeFileSync','Reload','res_stun_monitor.so','toUpperCase','TURN','root','server/files/templates/turn_multiple.ejs','server/files/templates/network.ejs','format','toLowerCase','chan_sip.so','params','STUN','join','/etc/asterisk/stun_xcally.conf','/etc/asterisk/turn_xcally.conf','destroy','util','path','ejs','lodash','../../components/parsers/qs','../../config/logger','../../config/environment','../../mysqldb','client','http','request','then','request\x20sent','stringify','error','message'];(function(_0x3d6110,_0x178d4f){var _0x49d211=function(_0x155def){while(--_0x155def){_0x3d6110['push'](_0x3d6110['shift']());}};_0x49d211(++_0x178d4f);}(_0xb194,0x1ee));var _0x4b19=function(_0x5b71ca,_0xabd1a1){_0x5b71ca=_0x5b71ca-0x0;var _0x5922b0=_0xb194[_0x5b71ca];return _0x5922b0;};'use strict';var util=require(_0x4b19('0x0'));var path=require(_0x4b19('0x1'));var ejs=require(_0x4b19('0x2'));var fs=require('fs');var _=require(_0x4b19('0x3'));var qs=require(_0x4b19('0x4'));var logger=require(_0x4b19('0x5'))('api');var config=require(_0x4b19('0x6'));var db=require(_0x4b19('0x7'))['db'];var jayson=require('jayson/promise');var client=jayson[_0x4b19('0x8')][_0x4b19('0x9')]({'port':0x232a});function respondWithRpcPromise(_0x530ec4,_0x2de584,_0x4dfb63,_0x275468){return new Promise(function(_0xfcc007,_0x5439c5){var _0x1ed83c=_0x275468||client;return _0x1ed83c[_0x4b19('0xa')](_0x530ec4,_0x4dfb63)[_0x4b19('0xb')](function(_0x254aff){logger['info']('Network,\x20%s,\x20%s',_0x2de584,_0x4b19('0xc'));logger['debug']('Network,\x20%s,\x20%s,\x20%s',_0x2de584,_0x4b19('0xc'),JSON[_0x4b19('0xd')](_0x254aff));if(_0x254aff[_0x4b19('0xe')]){if(_0x254aff[_0x4b19('0xe')]['code']===0x1f4){logger[_0x4b19('0xe')]('Network,\x20%s,\x20%s',_0x2de584,_0x254aff['error'][_0x4b19('0xf')]);return _0x5439c5(_0x254aff['error'][_0x4b19('0xf')]);}logger[_0x4b19('0xe')](_0x4b19('0x10'),_0x2de584,_0x254aff[_0x4b19('0xe')][_0x4b19('0xf')]);return _0xfcc007(_0x254aff[_0x4b19('0xe')][_0x4b19('0xf')]);}else{logger['info'](_0x4b19('0x10'),_0x2de584,_0x4b19('0xc'));_0xfcc007(_0x254aff[_0x4b19('0x11')][_0x4b19('0xf')]);}})[_0x4b19('0x12')](function(_0xea4f4c){logger['error'](_0x4b19('0x10'),_0x2de584,_0xea4f4c);_0x5439c5(_0xea4f4c);});});}function respondWithResult(_0x41cba5,_0x37aebe){_0x37aebe=_0x37aebe||0xc8;return function(_0x59015d){if(_0x59015d){return _0x41cba5[_0x4b19('0x13')](_0x37aebe)[_0x4b19('0x14')](_0x59015d);}};}function respondWithFilteredResult(_0x282bb2,_0x451fdb){return function(_0x313ee1){if(_0x313ee1){var _0x2e8d6e=typeof _0x451fdb[_0x4b19('0x15')]===_0x4b19('0x16')&&typeof _0x451fdb[_0x4b19('0x17')]===_0x4b19('0x16');var _0x172f32=_0x313ee1[_0x4b19('0x18')];var _0x102621=_0x2e8d6e?0x0:_0x451fdb[_0x4b19('0x15')];var _0x5929c6=_0x2e8d6e?_0x313ee1[_0x4b19('0x18')]:_0x451fdb[_0x4b19('0x15')]+_0x451fdb[_0x4b19('0x17')];var _0x55bfb9;if(_0x5929c6>=_0x172f32){_0x5929c6=_0x172f32;_0x55bfb9=0xc8;}else{_0x55bfb9=0xce;}_0x282bb2[_0x4b19('0x13')](_0x55bfb9);return _0x282bb2[_0x4b19('0x19')](_0x4b19('0x1a'),_0x102621+'-'+_0x5929c6+'/'+_0x172f32)[_0x4b19('0x14')](_0x313ee1);}return null;};}function saveUpdates(_0x3be43f){return function(_0x373b11){if(_0x373b11){return _0x373b11[_0x4b19('0x1b')](_0x3be43f)[_0x4b19('0xb')](function(_0x4c72a3){return _0x4c72a3;});}return null;};}function removeEntity(_0x2d93c9){return function(_0x226559){if(_0x226559){return _0x226559['destroy']()['then'](function(){_0x2d93c9[_0x4b19('0x13')](0xcc)[_0x4b19('0x1c')]();});}};}function handleEntityNotFound(_0xfd786d){return function(_0x6371bb){if(!_0x6371bb){_0xfd786d[_0x4b19('0x1d')](0x194);}return _0x6371bb;};}function handleError(_0x326c74,_0x3b2913){_0x3b2913=_0x3b2913||0x1f4;return function(_0x41d6f9){logger['error'](_0x41d6f9[_0x4b19('0x1e')]);if(_0x41d6f9[_0x4b19('0x1f')]){delete _0x41d6f9[_0x4b19('0x1f')];}_0x326c74['status'](_0x3b2913)[_0x4b19('0x20')](_0x41d6f9);};}exports[_0x4b19('0x21')]=function(_0x4d3179,_0x50bd23){var _0x220e2d={},_0x23f7bf={},_0x1118a1={'count':0x0,'rows':[]};var _0x49d651=_['map'](db[_0x4b19('0x22')][_0x4b19('0x23')],function(_0x39f924){return{'name':_0x39f924[_0x4b19('0x24')],'type':_0x39f924[_0x4b19('0x25')]['key']};});_0x23f7bf[_0x4b19('0x26')]=_['map'](_0x49d651,_0x4b19('0x1f'));_0x23f7bf[_0x4b19('0x27')]=_[_0x4b19('0x28')](_0x4d3179[_0x4b19('0x27')]);_0x23f7bf['filters']=_[_0x4b19('0x29')](_0x23f7bf['model'],_0x23f7bf[_0x4b19('0x27')]);_0x220e2d[_0x4b19('0x2a')]=_[_0x4b19('0x29')](_0x23f7bf[_0x4b19('0x26')],qs[_0x4b19('0x2b')](_0x4d3179['query']['fields']));_0x220e2d[_0x4b19('0x2a')]=_0x220e2d[_0x4b19('0x2a')][_0x4b19('0x2c')]?_0x220e2d[_0x4b19('0x2a')]:_0x23f7bf[_0x4b19('0x26')];if(!_0x4d3179[_0x4b19('0x27')][_0x4b19('0x2d')](_0x4b19('0x2e'))){_0x220e2d[_0x4b19('0x17')]=qs[_0x4b19('0x17')](_0x4d3179[_0x4b19('0x27')][_0x4b19('0x17')]);_0x220e2d[_0x4b19('0x15')]=qs[_0x4b19('0x15')](_0x4d3179[_0x4b19('0x27')][_0x4b19('0x15')]);}_0x220e2d[_0x4b19('0x2f')]=qs[_0x4b19('0x30')](_0x4d3179[_0x4b19('0x27')][_0x4b19('0x30')]);_0x220e2d['where']=qs['filters'](_[_0x4b19('0x31')](_0x4d3179[_0x4b19('0x27')],_0x23f7bf[_0x4b19('0x32')]),_0x49d651);if(_0x4d3179['query'][_0x4b19('0x33')]){_0x220e2d[_0x4b19('0x34')]=_[_0x4b19('0x35')](_0x220e2d['where'],{'$or':_[_0x4b19('0x36')](_0x49d651,function(_0x43d48a){if(_0x43d48a[_0x4b19('0x25')]!==_0x4b19('0x37')){var _0x4a0b7d={};_0x4a0b7d[_0x43d48a[_0x4b19('0x1f')]]={'$like':'%'+_0x4d3179['query'][_0x4b19('0x33')]+'%'};return _0x4a0b7d;}})});}_0x220e2d=_['merge']({},_0x220e2d,_0x4d3179['options']);var _0x2feefe={'where':_0x220e2d[_0x4b19('0x34')]};return db['Network']['count'](_0x2feefe)[_0x4b19('0xb')](function(_0x3c02b2){_0x1118a1[_0x4b19('0x18')]=_0x3c02b2;if(_0x4d3179[_0x4b19('0x27')]['includeAll']){_0x220e2d['include']=[{'all':!![]}];}return db['Network']['findAll'](_0x220e2d);})[_0x4b19('0xb')](function(_0x2a8124){_0x1118a1[_0x4b19('0x38')]=_0x2a8124;return _0x1118a1;})[_0x4b19('0xb')](respondWithFilteredResult(_0x50bd23,_0x220e2d))[_0x4b19('0x12')](handleError(_0x50bd23,null));};exports[_0x4b19('0x39')]=function(_0x32fc4e,_0x497041){var _0x21e34f={'raw':!![],'where':{'id':_0x32fc4e['params']['id']}},_0x3d256c={};_0x3d256c[_0x4b19('0x26')]=_[_0x4b19('0x28')](db[_0x4b19('0x22')][_0x4b19('0x23')]);_0x3d256c[_0x4b19('0x27')]=_[_0x4b19('0x28')](_0x32fc4e[_0x4b19('0x27')]);_0x3d256c[_0x4b19('0x32')]=_[_0x4b19('0x29')](_0x3d256c[_0x4b19('0x26')],_0x3d256c[_0x4b19('0x27')]);_0x21e34f[_0x4b19('0x2a')]=_[_0x4b19('0x29')](_0x3d256c['model'],qs['fields'](_0x32fc4e['query'][_0x4b19('0x2b')]));_0x21e34f[_0x4b19('0x2a')]=_0x21e34f[_0x4b19('0x2a')][_0x4b19('0x2c')]?_0x21e34f['attributes']:_0x3d256c[_0x4b19('0x26')];if(_0x32fc4e['query'][_0x4b19('0x3a')]){_0x21e34f[_0x4b19('0x3b')]=[{'all':!![]}];}_0x21e34f=_[_0x4b19('0x35')]({},_0x21e34f,_0x32fc4e['options']);return db[_0x4b19('0x22')][_0x4b19('0x3c')](_0x21e34f)[_0x4b19('0xb')](handleEntityNotFound(_0x497041,null))['then'](respondWithResult(_0x497041,null))[_0x4b19('0x12')](handleError(_0x497041,null));};exports[_0x4b19('0x3d')]=function(_0xa9d482,_0x4fc1e3){var _0x379317;return db[_0x4b19('0x22')]['create'](_0xa9d482['body'],{'raw':!![]})[_0x4b19('0xb')](function(_0x52dd95){_0x379317=_0x52dd95;return db[_0x4b19('0x22')][_0x4b19('0x3e')]({'where':{'type':_0xa9d482[_0x4b19('0x3f')][_0x4b19('0x25')]},'raw':!![]});})[_0x4b19('0xb')](function(_0x1ec91d){if(_0x379317[_0x4b19('0x25')]['toUpperCase']()=='STUN'){var _0x29809a=fs[_0x4b19('0x40')](path['join'](config['root'],_0x4b19('0x41')),_0x4b19('0x42'));var _0x1470f7=ejs[_0x4b19('0x43')](_0x29809a,{'networks':_0x1ec91d||[]});fs[_0x4b19('0x44')]('/etc/asterisk/stun_xcally.conf',_0x1470f7);return respondWithRpcPromise(_0x4b19('0x45'),_0x4b19('0x3d'),{'module':_0x4b19('0x46')});}else if(_0x379317[_0x4b19('0x25')][_0x4b19('0x47')]()==_0x4b19('0x48')){var _0xb3e1bf=fs[_0x4b19('0x40')](path['join'](config[_0x4b19('0x49')],_0x4b19('0x4a')),'utf8');var _0x2d088c=ejs[_0x4b19('0x43')](_0xb3e1bf,{'networks':_0x1ec91d||[]});fs[_0x4b19('0x44')]('/etc/asterisk/turn_xcally.conf',_0x2d088c);return respondWithRpcPromise(_0x4b19('0x45'),_0x4b19('0x3d'),{'module':_0x4b19('0x46')});}else{var _0x16b523=fs[_0x4b19('0x40')](path['join'](config[_0x4b19('0x49')],_0x4b19('0x4b')),_0x4b19('0x42'));var _0x32d7af=ejs[_0x4b19('0x43')](_0x16b523,{'networks':_0x1ec91d||[]});fs[_0x4b19('0x44')](util[_0x4b19('0x4c')]('/etc/asterisk/sip_xcally_%s.conf',_0xa9d482[_0x4b19('0x3f')][_0x4b19('0x25')][_0x4b19('0x4d')]()),_0x32d7af);return respondWithRpcPromise(_0x4b19('0x45'),_0x4b19('0x3d'),{'module':_0x4b19('0x4e')});}})[_0x4b19('0xb')](function(){return _0x379317;})[_0x4b19('0xb')](respondWithResult(_0x4fc1e3,0xc9))[_0x4b19('0x12')](handleError(_0x4fc1e3,null));};exports[_0x4b19('0x1b')]=function(_0x88a7bb,_0x203edd){var _0x2b929d;return db[_0x4b19('0x22')][_0x4b19('0x3c')]({'where':{'id':_0x88a7bb[_0x4b19('0x4f')]['id']}})[_0x4b19('0xb')](handleEntityNotFound(_0x203edd,null))[_0x4b19('0xb')](saveUpdates(_0x88a7bb[_0x4b19('0x3f')],null))[_0x4b19('0xb')](function(_0x3ec34e){if(_0x3ec34e){_0x2b929d=_0x3ec34e;return db[_0x4b19('0x22')][_0x4b19('0x3e')]({'where':{'type':_0x2b929d[_0x4b19('0x25')]},'raw':!![]});}return null;})[_0x4b19('0xb')](function(_0x25f4ea){if(_0x2b929d[_0x4b19('0x25')][_0x4b19('0x47')]()==_0x4b19('0x50')){var _0x1e710b=fs['readFileSync'](path[_0x4b19('0x51')](config[_0x4b19('0x49')],_0x4b19('0x41')),_0x4b19('0x42'));var _0x13daa0=ejs[_0x4b19('0x43')](_0x1e710b,{'networks':_0x25f4ea||[]});fs[_0x4b19('0x44')](_0x4b19('0x52'),_0x13daa0);return respondWithRpcPromise(_0x4b19('0x45'),'update',{'module':'res_stun_monitor.so'});}else if(_0x2b929d[_0x4b19('0x25')][_0x4b19('0x47')]()==_0x4b19('0x48')){var _0x4be348=fs[_0x4b19('0x40')](path[_0x4b19('0x51')](config['root'],'server/files/templates/turn_multiple.ejs'),_0x4b19('0x42'));var _0x2a804e=ejs[_0x4b19('0x43')](_0x4be348,{'networks':_0x25f4ea||[]});fs[_0x4b19('0x44')](_0x4b19('0x53'),_0x2a804e);return respondWithRpcPromise(_0x4b19('0x45'),'update',{'module':'res_stun_monitor.so'});}else{var _0x668516=fs[_0x4b19('0x40')](path['join'](config[_0x4b19('0x49')],_0x4b19('0x4b')),'utf8');var _0x4b96d1=ejs[_0x4b19('0x43')](_0x668516,{'networks':_0x25f4ea||[]});fs['writeFileSync'](util[_0x4b19('0x4c')]('/etc/asterisk/sip_xcally_%s.conf',_0x88a7bb[_0x4b19('0x3f')][_0x4b19('0x25')][_0x4b19('0x4d')]()),_0x4b96d1);return respondWithRpcPromise('Reload',_0x4b19('0x1b'),{'module':_0x4b19('0x4e')});}})[_0x4b19('0xb')](function(_0x3b6771){if(_0x3b6771){return _0x2b929d;}return null;})['then'](respondWithResult(_0x203edd,null))[_0x4b19('0x12')](handleError(_0x203edd,null));};exports[_0x4b19('0x54')]=function(_0x44dc16,_0xb6c0aa){var _0x1b77f7;return db[_0x4b19('0x22')]['find']({'where':{'id':_0x44dc16[_0x4b19('0x4f')]['id']}})[_0x4b19('0xb')](function(_0x53a422){_0x1b77f7=_0x53a422;return _0x53a422;})[_0x4b19('0xb')](handleEntityNotFound(_0xb6c0aa,null))['then'](removeEntity(_0xb6c0aa,null))['then'](function(){if(_0x1b77f7){return db[_0x4b19('0x22')]['findAll']({'where':{'type':_0x1b77f7[_0x4b19('0x25')]},'raw':!![]});}})[_0x4b19('0xb')](function(_0x4557e7){if(_0x1b77f7[_0x4b19('0x25')][_0x4b19('0x47')]()==_0x4b19('0x50')){var _0x4b21f5=fs[_0x4b19('0x40')](path[_0x4b19('0x51')](config[_0x4b19('0x49')],'server/files/templates/stun_multiple.ejs'),_0x4b19('0x42'));var _0x3e171b=ejs[_0x4b19('0x43')](_0x4b21f5,{'networks':_0x4557e7||[]});fs['writeFileSync'](_0x4b19('0x52'),_0x3e171b);return respondWithRpcPromise(_0x4b19('0x45'),_0x4b19('0x54'),{'module':'res_stun_monitor.so'});}else if(_0x1b77f7[_0x4b19('0x25')][_0x4b19('0x47')]()==_0x4b19('0x48')){var _0x4f5d1f=fs[_0x4b19('0x40')](path['join'](config['root'],_0x4b19('0x4a')),_0x4b19('0x42'));var _0x538e4a=ejs[_0x4b19('0x43')](_0x4f5d1f,{'networks':_0x4557e7||[]});fs[_0x4b19('0x44')](_0x4b19('0x53'),_0x538e4a);return respondWithRpcPromise(_0x4b19('0x45'),'destroy',{'module':_0x4b19('0x46')});}else{var _0x41a871=fs[_0x4b19('0x40')](path['join'](config['root'],'server/files/templates/network.ejs'),'utf8');var _0x2627ba=ejs[_0x4b19('0x43')](_0x41a871,{'networks':_0x4557e7||[]});fs[_0x4b19('0x44')](util[_0x4b19('0x4c')]('/etc/asterisk/sip_xcally_%s.conf',_0x1b77f7['type']['toLowerCase']()),_0x2627ba);return respondWithRpcPromise(_0x4b19('0x45'),_0x4b19('0x54'),{'module':_0x4b19('0x4e')});}})['catch'](handleError(_0xb6c0aa,null));};
\ No newline at end of file