Built motion from commit (unavailable).|2.4.4
[motion2.git] / server / services / ami / fax / index.js
index f1b42a5..389bbbc 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xfa85=['active','trunks','SIP/%s','reachable','unmonitored','checkTrunk','isTrunkReachable','Trunk\x20not\x20working','[Fax][checkTrunk][Empty\x20Fax]','Empty\x20Fax','Empty\x20path','Is\x20Valid','exports','lodash','path','tiff2pdf','./util/gs','../../../config/logger','../ami','./rpcDb','./channel','./util/util','./action','../rpc/faxAccount','../rpc/attachment','../rpc/faxMessage','channels','faxAccounts','actions','syncNewchannel','bind','syncVarSet','newstate','syncNewState','newexten','syncNewExten','faxstatus','syncFaxStatus','receivefax','hangup','syncHangup','originateresponse','syncOriginateResponse','prototype','context','hasOwnProperty','exten','localstationid','uniqueid','channel','name','info','\x20syncNewchannel\x20','variable','value','channelstate','channelstatedesc','operation','status','filename','\x20syncFaxStatus\x20','syncReceiveFax','remotestationid','pagestransferred','resolution','transferrate','calleridnum','message','create','parse','.pdf','then','notify','fax','catch','error','stringify','\x20receiveFax\x20','merge','pick','response','reason','AttachmentId','SENDING\x20FAILED\x20','logger','[Fax][Message][Error][Updated]','[Fax][Message][Error][NoUpdate1]','[Fax][Message][Error][NoUpdate2]','update','[Fax][Message][Updated]','[Fax][Message][NoUpdate2]','faxpages','updateStatus','faxstatusstring','SENDING\x20FAILED','send','FaxAccountId','[Fax][execOriginate][success]','Fax\x20received','Fax\x20failed','checkAfterSend','Trunk','isValid','Trunk\x20Reachable','format','execute','%s/%s.tif','XMF-PATH','Convert\x20pdf\x20to\x20tif','variablesAction','Action','addVariables','ext','isNil'];(function(_0x4d7894,_0x2dec54){var _0x508e49=function(_0xf2504f){while(--_0xf2504f){_0x4d7894['push'](_0x4d7894['shift']());}};_0x508e49(++_0x2dec54);}(_0xfa85,0x1d5));var _0x5fa8=function(_0x1efbf9,_0x50782b){_0x1efbf9=_0x1efbf9-0x0;var _0x485201=_0xfa85[_0x1efbf9];return _0x485201;};'use strict';var util=require('util');var _=require(_0x5fa8('0x0'));var BPromise=require('bluebird');var uuid=require('uuid');var moment=require('moment');var path=require(_0x5fa8('0x1'));var tiff2pdf=require(_0x5fa8('0x2'));var gs=require(_0x5fa8('0x3'));var logger=require(_0x5fa8('0x4'))('fax');var ami=require(_0x5fa8('0x5'));var rpcDb=require(_0x5fa8('0x6'));var Channel=require(_0x5fa8('0x7'));var ut=require(_0x5fa8('0x8'));var Action=require(_0x5fa8('0x9'));var faxAccount=require(_0x5fa8('0xa'));var attachment=require(_0x5fa8('0xb'));var faxMessage=require(_0x5fa8('0xc'));function Fax(_0x3237e7){this[_0x5fa8('0xd')]={};this[_0x5fa8('0xe')]=_0x3237e7[_0x5fa8('0xe')];this['trunks']=_0x3237e7['trunks'];this[_0x5fa8('0xf')]={};ami['on']('newchannel',this[_0x5fa8('0x10')][_0x5fa8('0x11')](this));ami['on']('varset',this[_0x5fa8('0x12')][_0x5fa8('0x11')](this));ami['on'](_0x5fa8('0x13'),this[_0x5fa8('0x14')][_0x5fa8('0x11')](this));ami['on'](_0x5fa8('0x15'),this[_0x5fa8('0x16')][_0x5fa8('0x11')](this));ami['on'](_0x5fa8('0x17'),this[_0x5fa8('0x18')]['bind'](this));ami['on'](_0x5fa8('0x19'),this['syncReceiveFax'][_0x5fa8('0x11')](this));ami['on'](_0x5fa8('0x1a'),this[_0x5fa8('0x1b')]['bind'](this));ami['on'](_0x5fa8('0x1c'),this[_0x5fa8('0x1d')][_0x5fa8('0x11')](this));}Fax[_0x5fa8('0x1e')]['syncNewchannel']=function(_0x1d969a){if(_0x1d969a[_0x5fa8('0x1f')]==='from-voip-provider'){for(var _0x3f13f2 in this[_0x5fa8('0xe')]){if(this[_0x5fa8('0xe')][_0x5fa8('0x20')](_0x3f13f2)){if(_0x1d969a[_0x5fa8('0x21')]===this[_0x5fa8('0xe')][_0x3f13f2][_0x5fa8('0x22')]){this[_0x5fa8('0xd')][_0x1d969a[_0x5fa8('0x23')]]={};this[_0x5fa8('0xd')][_0x1d969a[_0x5fa8('0x23')]][_0x5fa8('0x24')]=_0x1d969a[_0x5fa8('0x24')];this['channels'][_0x1d969a[_0x5fa8('0x23')]]['id']=this['faxAccounts'][_0x3f13f2]['id'];this[_0x5fa8('0xd')][_0x1d969a[_0x5fa8('0x23')]][_0x5fa8('0x25')]=this[_0x5fa8('0xe')][_0x3f13f2][_0x5fa8('0x25')];logger[_0x5fa8('0x26')](_0x1d969a[_0x5fa8('0x23')],_0x5fa8('0x27'));}}}}if(this[_0x5fa8('0xf')][_0x1d969a[_0x5fa8('0x23')]]){this['channels'][_0x1d969a[_0x5fa8('0x23')]]={};this[_0x5fa8('0xd')][_0x1d969a[_0x5fa8('0x23')]][_0x5fa8('0x24')]=_0x1d969a[_0x5fa8('0x24')];logger[_0x5fa8('0x26')](_0x1d969a['uniqueid'],_0x5fa8('0x27'));}};Fax[_0x5fa8('0x1e')]['syncVarSet']=function(_0x2b54de){if(this[_0x5fa8('0xd')][_0x2b54de[_0x5fa8('0x23')]]){for(var _0x34d686 in _0x2b54de[_0x5fa8('0x28')]){if(_0x2b54de['variable']['hasOwnProperty'](_0x34d686)){this[_0x5fa8('0xd')][_0x2b54de[_0x5fa8('0x23')]][_0x34d686]=_0x2b54de[_0x5fa8('0x29')];}}}};Fax[_0x5fa8('0x1e')][_0x5fa8('0x14')]=function(_0x5728c9){if(this['channels'][_0x5728c9[_0x5fa8('0x23')]]){this[_0x5fa8('0xd')][_0x5728c9['uniqueid']][_0x5fa8('0x2a')]=_0x5728c9[_0x5fa8('0x2a')];this[_0x5fa8('0xd')][_0x5728c9[_0x5fa8('0x23')]][_0x5fa8('0x2b')]=_0x5728c9['channelstatedesc'];}};Fax[_0x5fa8('0x1e')]['syncNewExten']=function(_0x3b1ad7){if(this[_0x5fa8('0xd')][_0x3b1ad7['uniqueid']]){for(var _0x163b3d in _0x3b1ad7['variable']){if(_0x3b1ad7['variable']['hasOwnProperty'](_0x163b3d)){this[_0x5fa8('0xd')][_0x3b1ad7[_0x5fa8('0x23')]][_0x163b3d]=_0x3b1ad7[_0x5fa8('0x29')];}}}};Fax[_0x5fa8('0x1e')]['syncFaxStatus']=function(_0x584fd6){if(this[_0x5fa8('0xd')][_0x584fd6[_0x5fa8('0x23')]]){this['channels'][_0x584fd6[_0x5fa8('0x23')]]['operation']=_0x584fd6[_0x5fa8('0x2c')];this[_0x5fa8('0xd')][_0x584fd6[_0x5fa8('0x23')]][_0x5fa8('0x2d')]=_0x584fd6[_0x5fa8('0x2d')];this[_0x5fa8('0xd')][_0x584fd6[_0x5fa8('0x23')]]['localstationid']=_0x584fd6['localstationid'];this['channels'][_0x584fd6[_0x5fa8('0x23')]][_0x5fa8('0x2e')]=_0x584fd6['filename'];logger[_0x5fa8('0x26')](_0x584fd6[_0x5fa8('0x23')],_0x5fa8('0x2f'));}};Fax[_0x5fa8('0x1e')][_0x5fa8('0x30')]=function(_0x3163bc){var _0x2d9504=this;if(this[_0x5fa8('0xd')][_0x3163bc[_0x5fa8('0x23')]]){var _0x4af394=this[_0x5fa8('0xd')][_0x3163bc['uniqueid']]['id'];this[_0x5fa8('0xd')][_0x3163bc['uniqueid']]['remotestationid']=_0x3163bc[_0x5fa8('0x31')];this[_0x5fa8('0xd')][_0x3163bc[_0x5fa8('0x23')]][_0x5fa8('0x32')]=_0x3163bc['pagestransferred'];this[_0x5fa8('0xd')][_0x3163bc[_0x5fa8('0x23')]]['localstationid']=_0x3163bc['localstationid'];this[_0x5fa8('0xd')][_0x3163bc['uniqueid']][_0x5fa8('0x33')]=_0x3163bc[_0x5fa8('0x33')];this[_0x5fa8('0xd')][_0x3163bc[_0x5fa8('0x23')]][_0x5fa8('0x34')]=_0x3163bc[_0x5fa8('0x34')];this[_0x5fa8('0xd')][_0x3163bc[_0x5fa8('0x23')]][_0x5fa8('0x2e')]=_0x3163bc[_0x5fa8('0x2e')];this[_0x5fa8('0xd')][_0x3163bc[_0x5fa8('0x23')]][_0x5fa8('0x35')]=_0x3163bc[_0x5fa8('0x35')];if(this['channels'][_0x3163bc['uniqueid']][_0x5fa8('0x32')]>0x0){tiff2pdf(_0x3163bc['filename'],'/var/opt/motion2/server/files/attachments/',function(_0x149d93){logger[_0x5fa8('0x26')](_0x3163bc[_0x5fa8('0x23')],'\x20result\x20conversion\x20file\x20',_0x149d93[_0x5fa8('0x36')]);attachment[_0x5fa8('0x37')]({'name':path[_0x5fa8('0x38')](_0x3163bc[_0x5fa8('0x2e')])['name'],'basename':path['parse'](_0x3163bc[_0x5fa8('0x2e')])['name']+_0x5fa8('0x39'),'type':'application/pdf'})[_0x5fa8('0x3a')](function(_0x19f036){faxAccount[_0x5fa8('0x3b')](_0x4af394,{'from':_0x3163bc[_0x5fa8('0x35')],'mapKey':_0x5fa8('0x3c'),'body':path[_0x5fa8('0x38')](_0x3163bc[_0x5fa8('0x2e')])[_0x5fa8('0x25')]+_0x5fa8('0x39'),'AttachmentId':_0x19f036['id']})[_0x5fa8('0x3d')](function(_0x221ccd){logger[_0x5fa8('0x3e')](_0x3163bc[_0x5fa8('0x23')],'\x20notify\x20',JSON[_0x5fa8('0x3f')](_0x221ccd));});})[_0x5fa8('0x3d')](function(_0x1828e6){logger['error'](_0x3163bc[_0x5fa8('0x23')],_0x5fa8('0x40'),JSON[_0x5fa8('0x3f')](_0x1828e6));});});}logger['info'](_0x3163bc[_0x5fa8('0x23')],_0x5fa8('0x40'));}};Fax['prototype'][_0x5fa8('0x1d')]=function(_0x58afdd){if(this['actions'][_0x58afdd[_0x5fa8('0x23')]]){_[_0x5fa8('0x41')](this[_0x5fa8('0xd')][_0x58afdd[_0x5fa8('0x23')]],_[_0x5fa8('0x42')](_0x58afdd,[_0x5fa8('0x43'),_0x5fa8('0x44')]));}};function updateStatus(_0x44701a){if(_0x44701a[_0x5fa8('0x45')]){faxMessage['update'](_0x44701a[_0x5fa8('0x45')],{'failMessage':_0x5fa8('0x46')})[_0x5fa8('0x3a')](function(_0x26aa61){ut[_0x5fa8('0x47')](_0x5fa8('0x48'),_0x26aa61);})[_0x5fa8('0x3d')](function(_0x37d9c4){ut['logger'](_0x5fa8('0x49'),_0x37d9c4);});}else{ut[_0x5fa8('0x47')](_0x5fa8('0x4a'));}}Fax[_0x5fa8('0x1e')]['updateStatus']=function(_0x42fba6,_0x5148ad,_0x228d4b){var _0x5db878=this;var _0x473056={};if(_0x5148ad){_0x473056={'read':_0x5148ad};}else{_0x473056={'failMessage':_0x228d4b};}if(this[_0x5fa8('0xf')][_0x42fba6][_0x5fa8('0x45')]){faxMessage[_0x5fa8('0x4b')](this[_0x5fa8('0xf')][_0x42fba6][_0x5fa8('0x45')],_0x473056)[_0x5fa8('0x3a')](function(_0x2a70e0){ut[_0x5fa8('0x47')](_0x5fa8('0x4c'),_0x2a70e0);})[_0x5fa8('0x3d')](function(_0x42aaae){ut[_0x5fa8('0x47')]('[Fax][Message][NoUpdate1]',_0x42aaae);})['finally'](function(){delete _0x5db878[_0x5fa8('0xd')][_0x42fba6];delete _0x5db878['actions'][_0x42fba6];});}else{ut[_0x5fa8('0x47')](_0x5fa8('0x4d'));delete this['channels'][_0x42fba6];delete this['actions'][_0x42fba6];}};Fax[_0x5fa8('0x1e')][_0x5fa8('0x1b')]=function(_0x33107d){var _0x7fa697=this;if(this[_0x5fa8('0xd')][_0x33107d[_0x5fa8('0x23')]]){if(this[_0x5fa8('0xf')][_0x33107d[_0x5fa8('0x23')]]){this[_0x5fa8('0xd')][_0x33107d[_0x5fa8('0x23')]]['id']=this['actions'][_0x33107d[_0x5fa8('0x23')]]['id'];this[_0x5fa8('0xd')][_0x33107d['uniqueid']][_0x5fa8('0x25')]=this['actions'][_0x33107d[_0x5fa8('0x23')]]['name'];}logger[_0x5fa8('0x26')](_0x33107d[_0x5fa8('0x23')],this[_0x5fa8('0xf')][_0x33107d[_0x5fa8('0x23')]]?'\x20hangup\x20sendFile\x20':'\x20hangup\x20faxRiceive\x20',JSON[_0x5fa8('0x3f')](this['channels'][_0x33107d[_0x5fa8('0x23')]]));if(this[_0x5fa8('0xf')][_0x33107d[_0x5fa8('0x23')]]){if(this['channels'][_0x33107d[_0x5fa8('0x23')]][_0x5fa8('0x4e')]>0x0&&this[_0x5fa8('0xd')][_0x33107d[_0x5fa8('0x23')]]['faxstatus']==='SUCCESS'){this['updateStatus'](_0x33107d[_0x5fa8('0x23')],!![]);}else{this[_0x5fa8('0x4f')](_0x33107d[_0x5fa8('0x23')],![],this[_0x5fa8('0xd')][_0x33107d[_0x5fa8('0x23')]][_0x5fa8('0x50')]?'SENDING\x20FAILED:\x20'+this[_0x5fa8('0xd')][_0x33107d['uniqueid']][_0x5fa8('0x50')]:_0x5fa8('0x51'));}}}};Fax[_0x5fa8('0x1e')][_0x5fa8('0x52')]=function(_0x52c4f4){var _0x31f953=this;return new BPromise(function(_0x14575a,_0x564a32){_0x31f953['execOriginate'](_0x52c4f4,_0x31f953[_0x5fa8('0xe')][_0x52c4f4[_0x5fa8('0x53')]])[_0x5fa8('0x3a')](function(_0x358b54){ut[_0x5fa8('0x47')](_0x5fa8('0x54'),_0x358b54);_0x14575a(ut['message'](_0x5fa8('0x55')));})[_0x5fa8('0x3d')](function(_0x5a9129){ut[_0x5fa8('0x47')]('[Fax][execOriginate][failure]',_0x5a9129);updateStatus(_0x52c4f4);_0x564a32(ut[_0x5fa8('0x36')](_0x5fa8('0x56')));});});};Fax[_0x5fa8('0x1e')][_0x5fa8('0x57')]=function(_0x4151a3){var _0x1c8cba=this;return new BPromise(function(_0xc5e1d7,_0x19e4c0){var _0x5e7733=_0x1c8cba['checkTrunk'](_0x1c8cba[_0x5fa8('0xe')][_0x4151a3['FaxAccountId']][_0x5fa8('0x58')],_0x4151a3);if(_0x5e7733[_0x5fa8('0x59')]){_0xc5e1d7(ut[_0x5fa8('0x36')](_0x5fa8('0x5a')));}else{_0x19e4c0(ut[_0x5fa8('0x36')](_0x5e7733[_0x5fa8('0x36')]));}});};function originate(_0x4956c0,_0x4b8b70,_0x24d305){return new BPromise(function(_0x5148ca,_0x1c3fa1){if(_0x24d305){var _0x287064=util[_0x5fa8('0x5b')]('gs\x20-q\x20-dNOPAUSE\x20-dBATCH\x20-sDEVICE=tiffg4\x20-sPAPERSIZE=letter\x20-sOutputFile=/var/opt/motion2/server/files/attachments/%s.tif\x20\x20%s\x20-c\x20quit',path[_0x5fa8('0x38')](_0x4956c0[_0x5fa8('0x1')])[_0x5fa8('0x25')],_0x4956c0['path']);gs[_0x5fa8('0x5c')](_0x287064)[_0x5fa8('0x3a')](function(){_0x4956c0['path']=util[_0x5fa8('0x5b')](_0x5fa8('0x5d'),path[_0x5fa8('0x38')](_0x4956c0[_0x5fa8('0x1')])['dir'],path[_0x5fa8('0x38')](_0x4956c0[_0x5fa8('0x1')])[_0x5fa8('0x25')]);_0x4b8b70[_0x5fa8('0x5e')]=_0x4956c0[_0x5fa8('0x1')];ut['logger'](_0x5fa8('0x5f'),'');ami['Action'](ut[_0x5fa8('0x60')](_0x4956c0,_0x4b8b70))[_0x5fa8('0x3a')](function(_0x286327){_0x5148ca(_0x286327);})[_0x5fa8('0x3d')](function(_0x284ece){_0x1c3fa1(_0x284ece);});})[_0x5fa8('0x3d')](function(_0x4c5f45){_0x1c3fa1(_0x4c5f45);});}else{ami[_0x5fa8('0x61')](ut[_0x5fa8('0x60')](_0x4956c0,_0x4b8b70))[_0x5fa8('0x3a')](function(_0x2131a7){_0x5148ca(_0x2131a7);})[_0x5fa8('0x3d')](function(_0x28e53b){_0x1c3fa1(_0x28e53b);});}});}Fax[_0x5fa8('0x1e')]['execOriginate']=function(_0x17e349,_0x31f010){var _0x49ebd8=this;return new BPromise(function(_0x47a27c,_0x4e1b39){var _0x28d0c7=uuid['v4']();var _0x47e676=ut[_0x5fa8('0x62')](_0x17e349,_0x31f010);_0x49ebd8['actions'][_0x28d0c7]=new Action(_0x28d0c7,_0x31f010,_0x17e349);var _0x48dc73=_0x49ebd8[_0x5fa8('0xf')][_0x28d0c7];if(path[_0x5fa8('0x38')](_0x17e349[_0x5fa8('0x1')])[_0x5fa8('0x63')]==='.pdf'){originate(_0x48dc73,_0x47e676,!![])['then'](function(_0x1678ad){_0x47a27c(_0x1678ad);})['catch'](function(_0x303131){_0x4e1b39(_0x303131);});}else{originate(_0x48dc73,_0x47e676,![])[_0x5fa8('0x3a')](function(_0x556c69){_0x47a27c(_0x556c69);})[_0x5fa8('0x3d')](function(_0x3f7fb2){_0x4e1b39(_0x3f7fb2);});}});};Fax[_0x5fa8('0x1e')]['isTrunkReachable']=function(_0x2b1f48){return!_[_0x5fa8('0x64')](_0x2b1f48)&&!_[_0x5fa8('0x64')](_0x2b1f48[_0x5fa8('0x25')])&&!_['isNil'](_0x2b1f48['active'])&&_0x2b1f48[_0x5fa8('0x65')]&&!_[_0x5fa8('0x64')](this[_0x5fa8('0x66')][util[_0x5fa8('0x5b')](_0x5fa8('0x67'),_0x2b1f48[_0x5fa8('0x25')])])&&!_[_0x5fa8('0x64')](this[_0x5fa8('0x66')][util[_0x5fa8('0x5b')](_0x5fa8('0x67'),_0x2b1f48[_0x5fa8('0x25')])]['status'])&&(this[_0x5fa8('0x66')][util[_0x5fa8('0x5b')](_0x5fa8('0x67'),_0x2b1f48[_0x5fa8('0x25')])]['status']===_0x5fa8('0x68')||this[_0x5fa8('0x66')][util['format']('SIP/%s',_0x2b1f48[_0x5fa8('0x25')])][_0x5fa8('0x2d')]===_0x5fa8('0x69'));};Fax[_0x5fa8('0x1e')][_0x5fa8('0x6a')]=function(_0x62e4bd,_0x460702){if(!this[_0x5fa8('0x6b')](_0x62e4bd)){ut[_0x5fa8('0x47')]('[Fax][checkTrunk][Trunk\x20not\x20work]',_[_0x5fa8('0x64')](_0x62e4bd)?'':_0x62e4bd[_0x5fa8('0x25')]+'\x20Trunk\x20is\x20not\x20active');return{'isValid':![],'message':_0x5fa8('0x6c')};}if(_[_0x5fa8('0x64')](_0x460702[_0x5fa8('0x3c')])){ut[_0x5fa8('0x47')](_0x5fa8('0x6d'),JSON[_0x5fa8('0x3f')](_0x460702));return{'isValid':![],'message':_0x5fa8('0x6e')};}if(_['isNil'](_0x460702[_0x5fa8('0x1')])){ut[_0x5fa8('0x47')]('[Fax][checkTrunk][Empty\x20path]',JSON[_0x5fa8('0x3f')](_0x460702));return{'isValid':![],'message':_0x5fa8('0x6f')};}return{'isValid':!![],'message':_0x5fa8('0x70')};};module[_0x5fa8('0x71')]=Fax;
\ No newline at end of file
+var _0x85b2=['moment','tiff2pdf','./util/gs','fax','./rpcDb','./util/util','./action','../rpc/faxAccount','../rpc/attachment','../rpc/faxMessage','channels','faxAccounts','trunks','actions','newchannel','bind','syncVarSet','newstate','syncNewState','newexten','faxstatus','syncFaxStatus','syncHangup','originateresponse','syncOriginateResponse','prototype','syncNewchannel','context','from-voip-provider','hasOwnProperty','exten','uniqueid','channel','info','\x20syncNewchannel\x20','variable','channelstate','channelstatedesc','syncNewExten','operation','status','localstationid','filename','\x20syncFaxStatus\x20','syncReceiveFax','remotestationid','pagestransferred','resolution','transferrate','calleridnum','/var/opt/motion2/server/files/attachments/','\x20result\x20conversion\x20file\x20','message','parse','name','.pdf','application/pdf','then','notify','catch','error','stringify','\x20receiveFax\x20','merge','pick','reason','AttachmentId','SENDING\x20FAILED\x20','logger','[Fax][Message][Error][Updated]','[Fax][Message][Error][NoUpdate1]','[Fax][Message][Error][NoUpdate2]','updateStatus','update','[Fax][Message][Updated]','[Fax][Message][NoUpdate1]','finally','[Fax][Message][NoUpdate2]','\x20hangup\x20sendFile\x20','faxstatusstring','send','FaxAccountId','[Fax][execOriginate][failure]','Fax\x20failed','checkTrunk','Trunk','isValid','Trunk\x20Reachable','format','gs\x20-q\x20-dNOPAUSE\x20-dBATCH\x20-sDEVICE=tiffg4\x20-sPAPERSIZE=letter\x20-sOutputFile=/var/opt/motion2/server/files/attachments/%s.tif\x20\x20%s\x20-c\x20quit','path','%s/%s.tif','dir','XMF-PATH','Convert\x20pdf\x20to\x20tif','Action','variablesAction','execOriginate','addVariables','ext','isTrunkReachable','isNil','active','SIP/%s','reachable','unmonitored','[Fax][checkTrunk][Trunk\x20not\x20work]','\x20Trunk\x20is\x20not\x20active','[Fax][checkTrunk][Empty\x20Fax]','Empty\x20Fax','[Fax][checkTrunk][Empty\x20path]','Empty\x20path','Is\x20Valid','exports','util','lodash','uuid'];(function(_0xa47778,_0x3cd87d){var _0x3a8693=function(_0x1c350c){while(--_0x1c350c){_0xa47778['push'](_0xa47778['shift']());}};_0x3a8693(++_0x3cd87d);}(_0x85b2,0x1d1));var _0x285b=function(_0x258b90,_0x4e7b1f){_0x258b90=_0x258b90-0x0;var _0x97b3a2=_0x85b2[_0x258b90];return _0x97b3a2;};'use strict';var util=require(_0x285b('0x0'));var _=require(_0x285b('0x1'));var BPromise=require('bluebird');var uuid=require(_0x285b('0x2'));var moment=require(_0x285b('0x3'));var path=require('path');var tiff2pdf=require(_0x285b('0x4'));var gs=require(_0x285b('0x5'));var logger=require('../../../config/logger')(_0x285b('0x6'));var ami=require('../ami');var rpcDb=require(_0x285b('0x7'));var Channel=require('./channel');var ut=require(_0x285b('0x8'));var Action=require(_0x285b('0x9'));var faxAccount=require(_0x285b('0xa'));var attachment=require(_0x285b('0xb'));var faxMessage=require(_0x285b('0xc'));function Fax(_0x548276){this[_0x285b('0xd')]={};this['faxAccounts']=_0x548276[_0x285b('0xe')];this[_0x285b('0xf')]=_0x548276[_0x285b('0xf')];this[_0x285b('0x10')]={};ami['on'](_0x285b('0x11'),this['syncNewchannel'][_0x285b('0x12')](this));ami['on']('varset',this[_0x285b('0x13')]['bind'](this));ami['on'](_0x285b('0x14'),this[_0x285b('0x15')][_0x285b('0x12')](this));ami['on'](_0x285b('0x16'),this['syncNewExten'][_0x285b('0x12')](this));ami['on'](_0x285b('0x17'),this[_0x285b('0x18')][_0x285b('0x12')](this));ami['on']('receivefax',this['syncReceiveFax'][_0x285b('0x12')](this));ami['on']('hangup',this[_0x285b('0x19')]['bind'](this));ami['on'](_0x285b('0x1a'),this[_0x285b('0x1b')][_0x285b('0x12')](this));}Fax[_0x285b('0x1c')][_0x285b('0x1d')]=function(_0x1ab555){if(_0x1ab555[_0x285b('0x1e')]===_0x285b('0x1f')){for(var _0x27080e in this[_0x285b('0xe')]){if(this[_0x285b('0xe')][_0x285b('0x20')](_0x27080e)){if(_0x1ab555[_0x285b('0x21')]===this[_0x285b('0xe')][_0x27080e]['localstationid']){this[_0x285b('0xd')][_0x1ab555[_0x285b('0x22')]]={};this[_0x285b('0xd')][_0x1ab555['uniqueid']][_0x285b('0x23')]=_0x1ab555['channel'];this['channels'][_0x1ab555[_0x285b('0x22')]]['id']=this[_0x285b('0xe')][_0x27080e]['id'];this[_0x285b('0xd')][_0x1ab555[_0x285b('0x22')]]['name']=this[_0x285b('0xe')][_0x27080e]['name'];logger['info'](_0x1ab555['uniqueid'],'\x20syncNewchannel\x20');}}}}if(this[_0x285b('0x10')][_0x1ab555[_0x285b('0x22')]]){this[_0x285b('0xd')][_0x1ab555['uniqueid']]={};this[_0x285b('0xd')][_0x1ab555[_0x285b('0x22')]][_0x285b('0x23')]=_0x1ab555[_0x285b('0x23')];logger[_0x285b('0x24')](_0x1ab555[_0x285b('0x22')],_0x285b('0x25'));}};Fax['prototype'][_0x285b('0x13')]=function(_0xd8cf42){if(this['channels'][_0xd8cf42[_0x285b('0x22')]]){for(var _0x1ad504 in _0xd8cf42[_0x285b('0x26')]){if(_0xd8cf42[_0x285b('0x26')]['hasOwnProperty'](_0x1ad504)){this['channels'][_0xd8cf42['uniqueid']][_0x1ad504]=_0xd8cf42['value'];}}}};Fax[_0x285b('0x1c')][_0x285b('0x15')]=function(_0x498b16){if(this[_0x285b('0xd')][_0x498b16[_0x285b('0x22')]]){this[_0x285b('0xd')][_0x498b16[_0x285b('0x22')]][_0x285b('0x27')]=_0x498b16[_0x285b('0x27')];this['channels'][_0x498b16[_0x285b('0x22')]][_0x285b('0x28')]=_0x498b16[_0x285b('0x28')];}};Fax[_0x285b('0x1c')][_0x285b('0x29')]=function(_0xc10db1){if(this[_0x285b('0xd')][_0xc10db1[_0x285b('0x22')]]){for(var _0xd7f697 in _0xc10db1[_0x285b('0x26')]){if(_0xc10db1[_0x285b('0x26')][_0x285b('0x20')](_0xd7f697)){this[_0x285b('0xd')][_0xc10db1[_0x285b('0x22')]][_0xd7f697]=_0xc10db1['value'];}}}};Fax['prototype'][_0x285b('0x18')]=function(_0xc6710c){if(this[_0x285b('0xd')][_0xc6710c[_0x285b('0x22')]]){this[_0x285b('0xd')][_0xc6710c[_0x285b('0x22')]][_0x285b('0x2a')]=_0xc6710c[_0x285b('0x2a')];this['channels'][_0xc6710c[_0x285b('0x22')]][_0x285b('0x2b')]=_0xc6710c[_0x285b('0x2b')];this[_0x285b('0xd')][_0xc6710c[_0x285b('0x22')]][_0x285b('0x2c')]=_0xc6710c[_0x285b('0x2c')];this[_0x285b('0xd')][_0xc6710c['uniqueid']][_0x285b('0x2d')]=_0xc6710c[_0x285b('0x2d')];logger[_0x285b('0x24')](_0xc6710c['uniqueid'],_0x285b('0x2e'));}};Fax[_0x285b('0x1c')][_0x285b('0x2f')]=function(_0x37ff4a){var _0x2decc6=this;if(this[_0x285b('0xd')][_0x37ff4a[_0x285b('0x22')]]){var _0x1b0087=this[_0x285b('0xd')][_0x37ff4a[_0x285b('0x22')]]['id'];this[_0x285b('0xd')][_0x37ff4a[_0x285b('0x22')]]['remotestationid']=_0x37ff4a[_0x285b('0x30')];this['channels'][_0x37ff4a[_0x285b('0x22')]]['pagestransferred']=_0x37ff4a[_0x285b('0x31')];this[_0x285b('0xd')][_0x37ff4a[_0x285b('0x22')]]['localstationid']=_0x37ff4a[_0x285b('0x2c')];this[_0x285b('0xd')][_0x37ff4a['uniqueid']][_0x285b('0x32')]=_0x37ff4a['resolution'];this[_0x285b('0xd')][_0x37ff4a['uniqueid']][_0x285b('0x33')]=_0x37ff4a[_0x285b('0x33')];this[_0x285b('0xd')][_0x37ff4a['uniqueid']][_0x285b('0x2d')]=_0x37ff4a['filename'];this['channels'][_0x37ff4a[_0x285b('0x22')]][_0x285b('0x34')]=_0x37ff4a[_0x285b('0x34')];if(this['channels'][_0x37ff4a[_0x285b('0x22')]]['pagestransferred']>0x0){tiff2pdf(_0x37ff4a[_0x285b('0x2d')],_0x285b('0x35'),function(_0x38c3bc){logger[_0x285b('0x24')](_0x37ff4a[_0x285b('0x22')],_0x285b('0x36'),_0x38c3bc[_0x285b('0x37')]);attachment['create']({'name':path[_0x285b('0x38')](_0x37ff4a[_0x285b('0x2d')])[_0x285b('0x39')],'basename':path[_0x285b('0x38')](_0x37ff4a[_0x285b('0x2d')])['name']+_0x285b('0x3a'),'type':_0x285b('0x3b')})[_0x285b('0x3c')](function(_0x298845){faxAccount[_0x285b('0x3d')](_0x1b0087,{'from':_0x37ff4a[_0x285b('0x34')],'mapKey':_0x285b('0x6'),'body':path[_0x285b('0x38')](_0x37ff4a[_0x285b('0x2d')])['name']+_0x285b('0x3a'),'AttachmentId':_0x298845['id']})[_0x285b('0x3e')](function(_0x5447e0){logger[_0x285b('0x3f')](_0x37ff4a['uniqueid'],'\x20notify\x20',JSON[_0x285b('0x40')](_0x5447e0));});})[_0x285b('0x3e')](function(_0x3d8b01){logger['error'](_0x37ff4a[_0x285b('0x22')],_0x285b('0x41'),JSON[_0x285b('0x40')](_0x3d8b01));});});}logger[_0x285b('0x24')](_0x37ff4a[_0x285b('0x22')],_0x285b('0x41'));}};Fax[_0x285b('0x1c')][_0x285b('0x1b')]=function(_0x211927){if(this[_0x285b('0x10')][_0x211927['uniqueid']]){_[_0x285b('0x42')](this['channels'][_0x211927[_0x285b('0x22')]],_[_0x285b('0x43')](_0x211927,['response',_0x285b('0x44')]));}};function updateStatus(_0x1c7ecc){if(_0x1c7ecc[_0x285b('0x45')]){faxMessage['update'](_0x1c7ecc['AttachmentId'],{'failMessage':_0x285b('0x46')})[_0x285b('0x3c')](function(_0x162c23){ut[_0x285b('0x47')](_0x285b('0x48'),_0x162c23);})[_0x285b('0x3e')](function(_0x12e881){ut[_0x285b('0x47')](_0x285b('0x49'),_0x12e881);});}else{ut['logger'](_0x285b('0x4a'));}}Fax[_0x285b('0x1c')][_0x285b('0x4b')]=function(_0x2eec44,_0x91f8a5,_0x54cbd2){var _0x1db6e8=this;var _0x4a9cd7={};if(_0x91f8a5){_0x4a9cd7={'read':_0x91f8a5};}else{_0x4a9cd7={'failMessage':_0x54cbd2};}if(this[_0x285b('0x10')][_0x2eec44]['AttachmentId']){faxMessage[_0x285b('0x4c')](this[_0x285b('0x10')][_0x2eec44]['AttachmentId'],_0x4a9cd7)[_0x285b('0x3c')](function(_0x3f50e4){ut['logger'](_0x285b('0x4d'),_0x3f50e4);})['catch'](function(_0x5d1c72){ut['logger'](_0x285b('0x4e'),_0x5d1c72);})[_0x285b('0x4f')](function(){delete _0x1db6e8['channels'][_0x2eec44];delete _0x1db6e8[_0x285b('0x10')][_0x2eec44];});}else{ut[_0x285b('0x47')](_0x285b('0x50'));delete this[_0x285b('0xd')][_0x2eec44];delete this[_0x285b('0x10')][_0x2eec44];}};Fax[_0x285b('0x1c')]['syncHangup']=function(_0x2305fa){var _0xf95446=this;if(this['channels'][_0x2305fa[_0x285b('0x22')]]){if(this[_0x285b('0x10')][_0x2305fa[_0x285b('0x22')]]){this[_0x285b('0xd')][_0x2305fa['uniqueid']]['id']=this[_0x285b('0x10')][_0x2305fa[_0x285b('0x22')]]['id'];this[_0x285b('0xd')][_0x2305fa['uniqueid']]['name']=this[_0x285b('0x10')][_0x2305fa[_0x285b('0x22')]][_0x285b('0x39')];}logger[_0x285b('0x24')](_0x2305fa[_0x285b('0x22')],this[_0x285b('0x10')][_0x2305fa[_0x285b('0x22')]]?_0x285b('0x51'):'\x20hangup\x20faxRiceive\x20',JSON['stringify'](this[_0x285b('0xd')][_0x2305fa[_0x285b('0x22')]]));if(this[_0x285b('0x10')][_0x2305fa['uniqueid']]){if(this['channels'][_0x2305fa[_0x285b('0x22')]]['faxpages']>0x0&&this[_0x285b('0xd')][_0x2305fa[_0x285b('0x22')]][_0x285b('0x17')]==='SUCCESS'){this[_0x285b('0x4b')](_0x2305fa['uniqueid'],!![]);}else{this[_0x285b('0x4b')](_0x2305fa[_0x285b('0x22')],![],this['channels'][_0x2305fa[_0x285b('0x22')]][_0x285b('0x52')]?'SENDING\x20FAILED:\x20'+this[_0x285b('0xd')][_0x2305fa[_0x285b('0x22')]][_0x285b('0x52')]:'SENDING\x20FAILED');}}}};Fax[_0x285b('0x1c')][_0x285b('0x53')]=function(_0x509744){var _0x27e3c1=this;return new BPromise(function(_0x5bed51,_0x4d3c44){_0x27e3c1['execOriginate'](_0x509744,_0x27e3c1[_0x285b('0xe')][_0x509744[_0x285b('0x54')]])[_0x285b('0x3c')](function(_0x97cad1){ut[_0x285b('0x47')]('[Fax][execOriginate][success]',_0x97cad1);_0x5bed51(ut[_0x285b('0x37')]('Fax\x20received'));})['catch'](function(_0x3c6ff2){ut[_0x285b('0x47')](_0x285b('0x55'),_0x3c6ff2);updateStatus(_0x509744);_0x4d3c44(ut[_0x285b('0x37')](_0x285b('0x56')));});});};Fax[_0x285b('0x1c')]['checkAfterSend']=function(_0x599d92){var _0x10c23b=this;return new BPromise(function(_0x19d233,_0x582b7e){var _0x4eb3c0=_0x10c23b[_0x285b('0x57')](_0x10c23b[_0x285b('0xe')][_0x599d92['FaxAccountId']][_0x285b('0x58')],_0x599d92);if(_0x4eb3c0[_0x285b('0x59')]){_0x19d233(ut['message'](_0x285b('0x5a')));}else{_0x582b7e(ut[_0x285b('0x37')](_0x4eb3c0['message']));}});};function originate(_0x475bf8,_0x466a82,_0x48fcec){return new BPromise(function(_0x377a46,_0x38784b){if(_0x48fcec){var _0x29efc8=util[_0x285b('0x5b')](_0x285b('0x5c'),path['parse'](_0x475bf8[_0x285b('0x5d')])['name'],_0x475bf8[_0x285b('0x5d')]);gs['execute'](_0x29efc8)[_0x285b('0x3c')](function(){_0x475bf8[_0x285b('0x5d')]=util[_0x285b('0x5b')](_0x285b('0x5e'),path[_0x285b('0x38')](_0x475bf8['path'])[_0x285b('0x5f')],path[_0x285b('0x38')](_0x475bf8[_0x285b('0x5d')])[_0x285b('0x39')]);_0x466a82[_0x285b('0x60')]=_0x475bf8['path'];ut[_0x285b('0x47')](_0x285b('0x61'),'');ami[_0x285b('0x62')](ut[_0x285b('0x63')](_0x475bf8,_0x466a82))[_0x285b('0x3c')](function(_0x1f3af3){_0x377a46(_0x1f3af3);})[_0x285b('0x3e')](function(_0x3976d0){_0x38784b(_0x3976d0);});})[_0x285b('0x3e')](function(_0x556d67){_0x38784b(_0x556d67);});}else{ami[_0x285b('0x62')](ut[_0x285b('0x63')](_0x475bf8,_0x466a82))[_0x285b('0x3c')](function(_0x36419a){_0x377a46(_0x36419a);})[_0x285b('0x3e')](function(_0x109b9){_0x38784b(_0x109b9);});}});}Fax[_0x285b('0x1c')][_0x285b('0x64')]=function(_0x4d07d8,_0x1f01a8){var _0x1683f5=this;return new BPromise(function(_0x33baff,_0x5b520a){var _0x36a9c4=uuid['v4']();var _0x56df37=ut[_0x285b('0x65')](_0x4d07d8,_0x1f01a8);_0x1683f5[_0x285b('0x10')][_0x36a9c4]=new Action(_0x36a9c4,_0x1f01a8,_0x4d07d8);var _0x1f8fe3=_0x1683f5[_0x285b('0x10')][_0x36a9c4];if(path[_0x285b('0x38')](_0x4d07d8[_0x285b('0x5d')])[_0x285b('0x66')]===_0x285b('0x3a')){originate(_0x1f8fe3,_0x56df37,!![])[_0x285b('0x3c')](function(_0x464f2c){_0x33baff(_0x464f2c);})[_0x285b('0x3e')](function(_0x4f59c4){_0x5b520a(_0x4f59c4);});}else{originate(_0x1f8fe3,_0x56df37,![])['then'](function(_0x5a6923){_0x33baff(_0x5a6923);})[_0x285b('0x3e')](function(_0x51c9de){_0x5b520a(_0x51c9de);});}});};Fax['prototype'][_0x285b('0x67')]=function(_0x5a0460){return!_[_0x285b('0x68')](_0x5a0460)&&!_[_0x285b('0x68')](_0x5a0460[_0x285b('0x39')])&&!_[_0x285b('0x68')](_0x5a0460[_0x285b('0x69')])&&_0x5a0460[_0x285b('0x69')]&&!_[_0x285b('0x68')](this['trunks'][util['format'](_0x285b('0x6a'),_0x5a0460['name'])])&&!_[_0x285b('0x68')](this[_0x285b('0xf')][util[_0x285b('0x5b')]('SIP/%s',_0x5a0460[_0x285b('0x39')])][_0x285b('0x2b')])&&(this[_0x285b('0xf')][util[_0x285b('0x5b')]('SIP/%s',_0x5a0460['name'])][_0x285b('0x2b')]===_0x285b('0x6b')||this['trunks'][util[_0x285b('0x5b')](_0x285b('0x6a'),_0x5a0460[_0x285b('0x39')])][_0x285b('0x2b')]===_0x285b('0x6c'));};Fax[_0x285b('0x1c')][_0x285b('0x57')]=function(_0x2a288a,_0x339ae9){if(!this['isTrunkReachable'](_0x2a288a)){ut[_0x285b('0x47')](_0x285b('0x6d'),_['isNil'](_0x2a288a)?'':_0x2a288a[_0x285b('0x39')]+_0x285b('0x6e'));return{'isValid':![],'message':'Trunk\x20not\x20working'};}if(_[_0x285b('0x68')](_0x339ae9['fax'])){ut[_0x285b('0x47')](_0x285b('0x6f'),JSON[_0x285b('0x40')](_0x339ae9));return{'isValid':![],'message':_0x285b('0x70')};}if(_['isNil'](_0x339ae9[_0x285b('0x5d')])){ut[_0x285b('0x47')](_0x285b('0x71'),JSON['stringify'](_0x339ae9));return{'isValid':![],'message':_0x285b('0x72')};}return{'isValid':!![],'message':_0x285b('0x73')};};module[_0x285b('0x74')]=Fax;
\ No newline at end of file