Built motion from commit 3d6333b4.|2.6.31
[motion2.git] / server / services / ami / fax / index.js
index 0537f74..1911834 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x7bdd=['actions','newchannel','bind','varset','syncVarSet','newstate','syncNewState','newexten','faxstatus','receivefax','syncReceiveFax','syncHangup','originateresponse','syncOriginateResponse','syncNewchannel','exten','localstationid','uniqueid','channel','name','info','\x20syncNewchannel\x20','prototype','variable','value','channelstate','channelstatedesc','hasOwnProperty','operation','status','filename','\x20syncFaxStatus\x20','remotestationid','pagestransferred','resolution','transferrate','calleridnum','\x20result\x20conversion\x20file\x20','message','parse','.pdf','application/pdf','then','notify','catch','error','stringify','\x20receiveFax\x20','merge','pick','update','AttachmentId','[Fax][Message][Error][Updated]','logger','[Fax][Message][Error][NoUpdate1]','[Fax][Message][Error][NoUpdate2]','updateStatus','finally','[Fax][Message][NoUpdate2]','\x20hangup\x20sendFile\x20','\x20hangup\x20faxRiceive\x20','faxpages','SUCCESS','faxstatusstring','SENDING\x20FAILED:\x20','execOriginate','FaxAccountId','[Fax][execOriginate][success]','Fax\x20received','[Fax][execOriginate][failure]','Fax\x20failed','checkAfterSend','checkTrunk','Trunk','isValid','Trunk\x20Reachable','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','execute','%s/%s.tif','XMF-PATH','Convert\x20pdf\x20to\x20tif','Action','variablesAction','addVariables','ext','isTrunkReachable','isNil','active','format','SIP/%s','reachable','\x20Trunk\x20is\x20not\x20active','Trunk\x20not\x20working\x20correctly','[Fax][checkTrunk][Empty\x20Fax]','[Fax][checkTrunk][Empty\x20path]','Empty\x20path','Is\x20Valid','deleteChannelAfterTimeout','exports','util','lodash','bluebird','uuid','moment','path','tiff2pdf','./util/gs','../../../config/logger','fax','./rpcDb','./channel','./util/util','./action','../rpc/faxAccount','../rpc/attachment','../rpc/faxMessage','channels','faxAccounts','trunks'];(function(_0x12d44c,_0xf11296){var _0x4fde20=function(_0x3c1ad6){while(--_0x3c1ad6){_0x12d44c['push'](_0x12d44c['shift']());}};_0x4fde20(++_0xf11296);}(_0x7bdd,0x151));var _0xd7bd=function(_0x51bf2e,_0x3d2696){_0x51bf2e=_0x51bf2e-0x0;var _0x3f3ff6=_0x7bdd[_0x51bf2e];return _0x3f3ff6;};'use strict';var util=require(_0xd7bd('0x0'));var _=require(_0xd7bd('0x1'));var BPromise=require(_0xd7bd('0x2'));var uuid=require(_0xd7bd('0x3'));var moment=require(_0xd7bd('0x4'));var path=require(_0xd7bd('0x5'));var tiff2pdf=require(_0xd7bd('0x6'));var gs=require(_0xd7bd('0x7'));var logger=require(_0xd7bd('0x8'))(_0xd7bd('0x9'));var ami=require('../ami');var rpcDb=require(_0xd7bd('0xa'));var Channel=require(_0xd7bd('0xb'));var ut=require(_0xd7bd('0xc'));var Action=require(_0xd7bd('0xd'));var faxAccount=require(_0xd7bd('0xe'));var attachment=require(_0xd7bd('0xf'));var faxMessage=require(_0xd7bd('0x10'));function Fax(_0x2dff83){this[_0xd7bd('0x11')]={};this[_0xd7bd('0x12')]=_0x2dff83[_0xd7bd('0x12')];this[_0xd7bd('0x13')]=_0x2dff83['trunks'];this[_0xd7bd('0x14')]={};ami['on'](_0xd7bd('0x15'),this['syncNewchannel'][_0xd7bd('0x16')](this));ami['on'](_0xd7bd('0x17'),this[_0xd7bd('0x18')][_0xd7bd('0x16')](this));ami['on'](_0xd7bd('0x19'),this[_0xd7bd('0x1a')][_0xd7bd('0x16')](this));ami['on'](_0xd7bd('0x1b'),this['syncNewExten'][_0xd7bd('0x16')](this));ami['on'](_0xd7bd('0x1c'),this['syncFaxStatus'][_0xd7bd('0x16')](this));ami['on'](_0xd7bd('0x1d'),this[_0xd7bd('0x1e')][_0xd7bd('0x16')](this));ami['on']('hangup',this[_0xd7bd('0x1f')][_0xd7bd('0x16')](this));ami['on'](_0xd7bd('0x20'),this[_0xd7bd('0x21')]['bind'](this));}Fax['prototype'][_0xd7bd('0x22')]=function(_0x23bdde){if(_0x23bdde['context']==='from-voip-provider'){for(var _0x5deb18 in this['faxAccounts']){if(this[_0xd7bd('0x12')]['hasOwnProperty'](_0x5deb18)){if(_0x23bdde[_0xd7bd('0x23')]===this['faxAccounts'][_0x5deb18][_0xd7bd('0x24')]){this[_0xd7bd('0x11')][_0x23bdde[_0xd7bd('0x25')]]={};this[_0xd7bd('0x11')][_0x23bdde[_0xd7bd('0x25')]][_0xd7bd('0x26')]=_0x23bdde[_0xd7bd('0x26')];this[_0xd7bd('0x11')][_0x23bdde[_0xd7bd('0x25')]]['id']=this['faxAccounts'][_0x5deb18]['id'];this[_0xd7bd('0x11')][_0x23bdde['uniqueid']][_0xd7bd('0x27')]=this[_0xd7bd('0x12')][_0x5deb18][_0xd7bd('0x27')];logger[_0xd7bd('0x28')](_0x23bdde[_0xd7bd('0x25')],_0xd7bd('0x29'));}}}}if(this[_0xd7bd('0x14')][_0x23bdde[_0xd7bd('0x25')]]){this[_0xd7bd('0x11')][_0x23bdde[_0xd7bd('0x25')]]={};this['channels'][_0x23bdde[_0xd7bd('0x25')]][_0xd7bd('0x26')]=_0x23bdde[_0xd7bd('0x26')];logger[_0xd7bd('0x28')](_0x23bdde[_0xd7bd('0x25')],_0xd7bd('0x29'));}};Fax[_0xd7bd('0x2a')][_0xd7bd('0x18')]=function(_0xd2d6e3){if(this[_0xd7bd('0x11')][_0xd2d6e3[_0xd7bd('0x25')]]){for(var _0x261d81 in _0xd2d6e3[_0xd7bd('0x2b')]){if(_0xd2d6e3[_0xd7bd('0x2b')]['hasOwnProperty'](_0x261d81)){this['channels'][_0xd2d6e3[_0xd7bd('0x25')]][_0x261d81]=_0xd2d6e3[_0xd7bd('0x2c')];}}}};Fax[_0xd7bd('0x2a')][_0xd7bd('0x1a')]=function(_0x125eba){if(this[_0xd7bd('0x11')][_0x125eba['uniqueid']]){this[_0xd7bd('0x11')][_0x125eba[_0xd7bd('0x25')]][_0xd7bd('0x2d')]=_0x125eba[_0xd7bd('0x2d')];this[_0xd7bd('0x11')][_0x125eba['uniqueid']][_0xd7bd('0x2e')]=_0x125eba['channelstatedesc'];}};Fax[_0xd7bd('0x2a')]['syncNewExten']=function(_0x32bec3){if(this[_0xd7bd('0x11')][_0x32bec3[_0xd7bd('0x25')]]){for(var _0x16371d in _0x32bec3[_0xd7bd('0x2b')]){if(_0x32bec3['variable'][_0xd7bd('0x2f')](_0x16371d)){this[_0xd7bd('0x11')][_0x32bec3['uniqueid']][_0x16371d]=_0x32bec3[_0xd7bd('0x2c')];}}}};Fax['prototype']['syncFaxStatus']=function(_0x3c5365){if(this[_0xd7bd('0x11')][_0x3c5365[_0xd7bd('0x25')]]){this['channels'][_0x3c5365[_0xd7bd('0x25')]][_0xd7bd('0x30')]=_0x3c5365['operation'];this[_0xd7bd('0x11')][_0x3c5365[_0xd7bd('0x25')]]['status']=_0x3c5365[_0xd7bd('0x31')];this['channels'][_0x3c5365[_0xd7bd('0x25')]]['localstationid']=_0x3c5365[_0xd7bd('0x24')];this[_0xd7bd('0x11')][_0x3c5365['uniqueid']]['filename']=_0x3c5365[_0xd7bd('0x32')];logger[_0xd7bd('0x28')](_0x3c5365[_0xd7bd('0x25')],_0xd7bd('0x33'));}};Fax[_0xd7bd('0x2a')]['syncReceiveFax']=function(_0x8f6fab){var _0x250e0a=this;if(this[_0xd7bd('0x11')][_0x8f6fab['uniqueid']]){var _0x3207f8=this[_0xd7bd('0x11')][_0x8f6fab[_0xd7bd('0x25')]]['id'];this['channels'][_0x8f6fab[_0xd7bd('0x25')]][_0xd7bd('0x34')]=_0x8f6fab['remotestationid'];this[_0xd7bd('0x11')][_0x8f6fab[_0xd7bd('0x25')]]['pagestransferred']=_0x8f6fab[_0xd7bd('0x35')];this[_0xd7bd('0x11')][_0x8f6fab['uniqueid']][_0xd7bd('0x24')]=_0x8f6fab['localstationid'];this[_0xd7bd('0x11')][_0x8f6fab['uniqueid']]['resolution']=_0x8f6fab[_0xd7bd('0x36')];this[_0xd7bd('0x11')][_0x8f6fab[_0xd7bd('0x25')]]['transferrate']=_0x8f6fab[_0xd7bd('0x37')];this[_0xd7bd('0x11')][_0x8f6fab[_0xd7bd('0x25')]][_0xd7bd('0x32')]=_0x8f6fab['filename'];this[_0xd7bd('0x11')][_0x8f6fab[_0xd7bd('0x25')]][_0xd7bd('0x38')]=_0x8f6fab[_0xd7bd('0x38')];if(this['channels'][_0x8f6fab[_0xd7bd('0x25')]][_0xd7bd('0x35')]>0x0){tiff2pdf(_0x8f6fab[_0xd7bd('0x32')],'/var/opt/motion2/server/files/attachments/',function(_0x4fd0dc){logger[_0xd7bd('0x28')](_0x8f6fab['uniqueid'],_0xd7bd('0x39'),_0x4fd0dc[_0xd7bd('0x3a')]);attachment['create']({'name':path[_0xd7bd('0x3b')](_0x8f6fab[_0xd7bd('0x32')])[_0xd7bd('0x27')],'basename':path[_0xd7bd('0x3b')](_0x8f6fab[_0xd7bd('0x32')])[_0xd7bd('0x27')]+_0xd7bd('0x3c'),'type':_0xd7bd('0x3d')})[_0xd7bd('0x3e')](function(_0x5d45fe){faxAccount[_0xd7bd('0x3f')](_0x3207f8,{'from':_0x8f6fab[_0xd7bd('0x38')],'mapKey':_0xd7bd('0x9'),'body':path[_0xd7bd('0x3b')](_0x8f6fab[_0xd7bd('0x32')])[_0xd7bd('0x27')]+_0xd7bd('0x3c'),'AttachmentId':_0x5d45fe['id']})['catch'](function(_0x4d2be4){logger['error'](_0x8f6fab[_0xd7bd('0x25')],'\x20notify\x20',JSON['stringify'](_0x4d2be4));});})[_0xd7bd('0x40')](function(_0x507ef9){logger[_0xd7bd('0x41')](_0x8f6fab[_0xd7bd('0x25')],'\x20receiveFax\x20',JSON[_0xd7bd('0x42')](_0x507ef9));});});}logger['info'](_0x8f6fab[_0xd7bd('0x25')],_0xd7bd('0x43'));}};Fax[_0xd7bd('0x2a')][_0xd7bd('0x21')]=function(_0x5a21c9){if(this[_0xd7bd('0x14')][_0x5a21c9[_0xd7bd('0x25')]]){_[_0xd7bd('0x44')](this[_0xd7bd('0x11')][_0x5a21c9[_0xd7bd('0x25')]],_[_0xd7bd('0x45')](_0x5a21c9,['response','reason']));}};function updateStatus(_0x3b2345){if(_0x3b2345['AttachmentId']){faxMessage[_0xd7bd('0x46')](_0x3b2345[_0xd7bd('0x47')],{'failMessage':'SENDING\x20FAILED\x20'})[_0xd7bd('0x3e')](function(_0x598a33){ut['logger'](_0xd7bd('0x48'),_0x598a33);})[_0xd7bd('0x40')](function(_0x4c361e){ut[_0xd7bd('0x49')](_0xd7bd('0x4a'),_0x4c361e);});}else{ut['logger'](_0xd7bd('0x4b'));}}Fax[_0xd7bd('0x2a')][_0xd7bd('0x4c')]=function(_0x5b4934,_0x12f7cd,_0x2db802){var _0x7a6a5b=this;var _0x293f96={};if(_0x12f7cd){_0x293f96={'read':_0x12f7cd};}else{_0x293f96={'failMessage':_0x2db802};}if(this['actions'][_0x5b4934]['AttachmentId']){faxMessage[_0xd7bd('0x46')](this[_0xd7bd('0x14')][_0x5b4934]['AttachmentId'],_0x293f96)[_0xd7bd('0x3e')](function(_0xf68eb3){ut[_0xd7bd('0x49')]('[Fax][Message][Updated]',_0xf68eb3);})[_0xd7bd('0x40')](function(_0x3f45c1){ut[_0xd7bd('0x49')]('[Fax][Message][NoUpdate1]',_0x3f45c1);})[_0xd7bd('0x4d')](function(){delete _0x7a6a5b[_0xd7bd('0x11')][_0x5b4934];delete _0x7a6a5b[_0xd7bd('0x14')][_0x5b4934];});}else{ut['logger'](_0xd7bd('0x4e'));this['deleteChannelAfterTimeout'](_0x5b4934);delete this[_0xd7bd('0x14')][_0x5b4934];}};Fax[_0xd7bd('0x2a')][_0xd7bd('0x1f')]=function(_0x41cced){var _0x756c91=this;if(this[_0xd7bd('0x11')][_0x41cced[_0xd7bd('0x25')]]){if(this[_0xd7bd('0x14')][_0x41cced[_0xd7bd('0x25')]]){this['channels'][_0x41cced[_0xd7bd('0x25')]]['id']=this['actions'][_0x41cced['uniqueid']]['id'];this[_0xd7bd('0x11')][_0x41cced[_0xd7bd('0x25')]][_0xd7bd('0x27')]=this['actions'][_0x41cced[_0xd7bd('0x25')]][_0xd7bd('0x27')];}logger['info'](_0x41cced[_0xd7bd('0x25')],this['actions'][_0x41cced['uniqueid']]?_0xd7bd('0x4f'):_0xd7bd('0x50'),JSON[_0xd7bd('0x42')](this[_0xd7bd('0x11')][_0x41cced[_0xd7bd('0x25')]]));if(this['actions'][_0x41cced[_0xd7bd('0x25')]]){if(this[_0xd7bd('0x11')][_0x41cced[_0xd7bd('0x25')]][_0xd7bd('0x51')]>0x0&&this['channels'][_0x41cced[_0xd7bd('0x25')]][_0xd7bd('0x1c')]===_0xd7bd('0x52')){this[_0xd7bd('0x4c')](_0x41cced['uniqueid'],!![]);}else{this[_0xd7bd('0x4c')](_0x41cced[_0xd7bd('0x25')],![],this[_0xd7bd('0x11')][_0x41cced[_0xd7bd('0x25')]][_0xd7bd('0x53')]?_0xd7bd('0x54')+this[_0xd7bd('0x11')][_0x41cced[_0xd7bd('0x25')]][_0xd7bd('0x53')]:'SENDING\x20FAILED');}}}};Fax['prototype']['send']=function(_0x3b1a14){var _0x2723cc=this;return new BPromise(function(_0x445461,_0x274cdf){_0x2723cc[_0xd7bd('0x55')](_0x3b1a14,_0x2723cc[_0xd7bd('0x12')][_0x3b1a14[_0xd7bd('0x56')]])['then'](function(_0x42f325){ut[_0xd7bd('0x49')](_0xd7bd('0x57'),_0x42f325);_0x445461(ut[_0xd7bd('0x3a')](_0xd7bd('0x58')));})[_0xd7bd('0x40')](function(_0x8032ce){ut[_0xd7bd('0x49')](_0xd7bd('0x59'),_0x8032ce);updateStatus(_0x3b1a14);_0x274cdf(ut[_0xd7bd('0x3a')](_0xd7bd('0x5a')));});});};Fax[_0xd7bd('0x2a')][_0xd7bd('0x5b')]=function(_0x5c50af){var _0x12af60=this;return new BPromise(function(_0x569693,_0x457a41){var _0x34b385=_0x12af60[_0xd7bd('0x5c')](_0x12af60['faxAccounts'][_0x5c50af[_0xd7bd('0x56')]][_0xd7bd('0x5d')],_0x5c50af);if(_0x34b385[_0xd7bd('0x5e')]){_0x569693(ut[_0xd7bd('0x3a')](_0xd7bd('0x5f')));}else{_0x457a41(ut[_0xd7bd('0x3a')](_0x34b385['message']));}});};function originate(_0x288b15,_0x23ab47,_0x3763d9){return new BPromise(function(_0x2dd344,_0x1e5fbe){if(_0x3763d9){var _0x90acd1=util['format'](_0xd7bd('0x60'),path[_0xd7bd('0x3b')](_0x288b15[_0xd7bd('0x5')])[_0xd7bd('0x27')],_0x288b15[_0xd7bd('0x5')]);gs[_0xd7bd('0x61')](_0x90acd1)[_0xd7bd('0x3e')](function(){_0x288b15[_0xd7bd('0x5')]=util['format'](_0xd7bd('0x62'),path['parse'](_0x288b15[_0xd7bd('0x5')])['dir'],path['parse'](_0x288b15[_0xd7bd('0x5')])['name']);_0x23ab47[_0xd7bd('0x63')]=_0x288b15[_0xd7bd('0x5')];ut[_0xd7bd('0x49')](_0xd7bd('0x64'),'');ami[_0xd7bd('0x65')](ut['variablesAction'](_0x288b15,_0x23ab47))[_0xd7bd('0x3e')](function(_0x5adeff){_0x2dd344(_0x5adeff);})[_0xd7bd('0x40')](function(_0x338889){_0x1e5fbe(_0x338889);});})[_0xd7bd('0x40')](function(_0x49698a){_0x1e5fbe(_0x49698a);});}else{ami[_0xd7bd('0x65')](ut[_0xd7bd('0x66')](_0x288b15,_0x23ab47))[_0xd7bd('0x3e')](function(_0x16716b){_0x2dd344(_0x16716b);})[_0xd7bd('0x40')](function(_0x5d55b1){_0x1e5fbe(_0x5d55b1);});}});}Fax[_0xd7bd('0x2a')][_0xd7bd('0x55')]=function(_0x45d114,_0x197de3){var _0x4a75a7=this;return new BPromise(function(_0x26d79a,_0xb379bf){var _0x21efa0=uuid['v4']();var _0xa4558b=ut[_0xd7bd('0x67')](_0x45d114,_0x197de3);_0x4a75a7[_0xd7bd('0x14')][_0x21efa0]=new Action(_0x21efa0,_0x197de3,_0x45d114);var _0x2971b5=_0x4a75a7['actions'][_0x21efa0];if(path[_0xd7bd('0x3b')](_0x45d114[_0xd7bd('0x5')])[_0xd7bd('0x68')]===_0xd7bd('0x3c')){originate(_0x2971b5,_0xa4558b,!![])[_0xd7bd('0x3e')](function(_0x2ae047){_0x26d79a(_0x2ae047);})[_0xd7bd('0x40')](function(_0x1f2c1e){_0xb379bf(_0x1f2c1e);});}else{originate(_0x2971b5,_0xa4558b,![])['then'](function(_0x31dee6){_0x26d79a(_0x31dee6);})[_0xd7bd('0x40')](function(_0x216430){_0xb379bf(_0x216430);});}});};Fax[_0xd7bd('0x2a')][_0xd7bd('0x69')]=function(_0x46e57e){return!_[_0xd7bd('0x6a')](_0x46e57e)&&!_[_0xd7bd('0x6a')](_0x46e57e['name'])&&!_[_0xd7bd('0x6a')](_0x46e57e[_0xd7bd('0x6b')])&&_0x46e57e[_0xd7bd('0x6b')]&&!_[_0xd7bd('0x6a')](this[_0xd7bd('0x13')][util[_0xd7bd('0x6c')]('SIP/%s',_0x46e57e[_0xd7bd('0x27')])])&&!_[_0xd7bd('0x6a')](this[_0xd7bd('0x13')][util['format'](_0xd7bd('0x6d'),_0x46e57e[_0xd7bd('0x27')])]['status'])&&(this[_0xd7bd('0x13')][util[_0xd7bd('0x6c')](_0xd7bd('0x6d'),_0x46e57e[_0xd7bd('0x27')])][_0xd7bd('0x31')]===_0xd7bd('0x6e')||this[_0xd7bd('0x13')][util['format'](_0xd7bd('0x6d'),_0x46e57e[_0xd7bd('0x27')])][_0xd7bd('0x31')]==='unmonitored');};Fax['prototype'][_0xd7bd('0x5c')]=function(_0x203545,_0x4cc74f){if(!this[_0xd7bd('0x69')](_0x203545)){ut[_0xd7bd('0x49')]('[Fax][checkTrunk][Trunk\x20not\x20working\x20correctly]',_[_0xd7bd('0x6a')](_0x203545)?'':_0x203545[_0xd7bd('0x27')]+_0xd7bd('0x6f'));return{'isValid':![],'message':_0xd7bd('0x70')};}if(_[_0xd7bd('0x6a')](_0x4cc74f[_0xd7bd('0x9')])){ut[_0xd7bd('0x49')](_0xd7bd('0x71'),JSON[_0xd7bd('0x42')](_0x4cc74f));return{'isValid':![],'message':'Empty\x20Fax'};}if(_[_0xd7bd('0x6a')](_0x4cc74f['path'])){ut[_0xd7bd('0x49')](_0xd7bd('0x72'),JSON[_0xd7bd('0x42')](_0x4cc74f));return{'isValid':![],'message':_0xd7bd('0x73')};}return{'isValid':!![],'message':_0xd7bd('0x74')};};Fax[_0xd7bd('0x2a')][_0xd7bd('0x75')]=function(_0x41dfc6,_0x4b697a=0x2710){if(this['channels'][_0x41dfc6]){setTimeout(()=>{delete this['channels'][_0x41dfc6];},_0x4b697a);}};module[_0xd7bd('0x76')]=Fax;
\ No newline at end of file
+var _0x7f07=['[Fax][checkTrunk][Empty\x20Fax]','Empty\x20Fax','[Fax][checkTrunk][Empty\x20path]','Empty\x20path','exports','util','bluebird','moment','path','tiff2pdf','../ami','./action','../rpc/attachment','../rpc/faxMessage','channels','faxAccounts','trunks','actions','newchannel','syncNewchannel','bind','varset','newstate','syncNewState','newexten','syncNewExten','syncFaxStatus','receivefax','syncReceiveFax','syncHangup','originateresponse','prototype','context','from-voip-provider','hasOwnProperty','exten','localstationid','uniqueid','channel','name','\x20syncNewchannel\x20','syncVarSet','variable','channelstate','channelstatedesc','operation','status','filename','remotestationid','pagestransferred','resolution','transferrate','calleridnum','/var/opt/motion2/server/files/attachments/','info','\x20result\x20conversion\x20file\x20','message','create','parse','then','notify','fax','error','stringify','\x20receiveFax\x20','syncOriginateResponse','merge','pick','response','reason','AttachmentId','update','SENDING\x20FAILED\x20','[Fax][Message][Error][Updated]','catch','logger','[Fax][Message][NoUpdate1]','finally','[Fax][Message][NoUpdate2]','deleteChannelAfterTimeout','\x20hangup\x20sendFile\x20','\x20hangup\x20faxRiceive\x20','faxstatus','SUCCESS','updateStatus','SENDING\x20FAILED:\x20','faxstatusstring','SENDING\x20FAILED','FaxAccountId','[Fax][execOriginate][success]','[Fax][execOriginate][failure]','Fax\x20failed','checkAfterSend','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','execute','%s/%s.tif','dir','XMF-PATH','Convert\x20pdf\x20to\x20tif','Action','variablesAction','execOriginate','addVariables','ext','.pdf','isTrunkReachable','isNil','active','SIP/%s','reachable','unmonitored','[Fax][checkTrunk][Trunk\x20not\x20working\x20correctly]','\x20Trunk\x20is\x20not\x20active'];(function(_0x3d59e7,_0xa22d3d){var _0x18f362=function(_0x5a5b5b){while(--_0x5a5b5b){_0x3d59e7['push'](_0x3d59e7['shift']());}};_0x18f362(++_0xa22d3d);}(_0x7f07,0xf1));var _0x77f0=function(_0x424bd3,_0x8760d8){_0x424bd3=_0x424bd3-0x0;var _0x1fdade=_0x7f07[_0x424bd3];return _0x1fdade;};'use strict';var util=require(_0x77f0('0x0'));var _=require('lodash');var BPromise=require(_0x77f0('0x1'));var uuid=require('uuid');var moment=require(_0x77f0('0x2'));var path=require(_0x77f0('0x3'));var tiff2pdf=require(_0x77f0('0x4'));var gs=require('./util/gs');var logger=require('../../../config/logger')('fax');var ami=require(_0x77f0('0x5'));var rpcDb=require('./rpcDb');var Channel=require('./channel');var ut=require('./util/util');var Action=require(_0x77f0('0x6'));var faxAccount=require('../rpc/faxAccount');var attachment=require(_0x77f0('0x7'));var faxMessage=require(_0x77f0('0x8'));function Fax(_0x3e10c8){this[_0x77f0('0x9')]={};this[_0x77f0('0xa')]=_0x3e10c8[_0x77f0('0xa')];this[_0x77f0('0xb')]=_0x3e10c8[_0x77f0('0xb')];this[_0x77f0('0xc')]={};ami['on'](_0x77f0('0xd'),this[_0x77f0('0xe')][_0x77f0('0xf')](this));ami['on'](_0x77f0('0x10'),this['syncVarSet'][_0x77f0('0xf')](this));ami['on'](_0x77f0('0x11'),this[_0x77f0('0x12')][_0x77f0('0xf')](this));ami['on'](_0x77f0('0x13'),this[_0x77f0('0x14')][_0x77f0('0xf')](this));ami['on']('faxstatus',this[_0x77f0('0x15')][_0x77f0('0xf')](this));ami['on'](_0x77f0('0x16'),this[_0x77f0('0x17')][_0x77f0('0xf')](this));ami['on']('hangup',this[_0x77f0('0x18')][_0x77f0('0xf')](this));ami['on'](_0x77f0('0x19'),this['syncOriginateResponse'][_0x77f0('0xf')](this));}Fax[_0x77f0('0x1a')]['syncNewchannel']=function(_0x223f69){if(_0x223f69[_0x77f0('0x1b')]===_0x77f0('0x1c')){for(var _0x387574 in this[_0x77f0('0xa')]){if(this[_0x77f0('0xa')][_0x77f0('0x1d')](_0x387574)){if(_0x223f69[_0x77f0('0x1e')]===this[_0x77f0('0xa')][_0x387574][_0x77f0('0x1f')]){this[_0x77f0('0x9')][_0x223f69[_0x77f0('0x20')]]={};this[_0x77f0('0x9')][_0x223f69[_0x77f0('0x20')]][_0x77f0('0x21')]=_0x223f69['channel'];this[_0x77f0('0x9')][_0x223f69[_0x77f0('0x20')]]['id']=this[_0x77f0('0xa')][_0x387574]['id'];this[_0x77f0('0x9')][_0x223f69[_0x77f0('0x20')]][_0x77f0('0x22')]=this[_0x77f0('0xa')][_0x387574][_0x77f0('0x22')];logger['info'](_0x223f69[_0x77f0('0x20')],_0x77f0('0x23'));}}}}if(this['actions'][_0x223f69[_0x77f0('0x20')]]){this['channels'][_0x223f69[_0x77f0('0x20')]]={};this['channels'][_0x223f69[_0x77f0('0x20')]][_0x77f0('0x21')]=_0x223f69[_0x77f0('0x21')];logger['info'](_0x223f69[_0x77f0('0x20')],_0x77f0('0x23'));}};Fax[_0x77f0('0x1a')][_0x77f0('0x24')]=function(_0x15d85d){if(this[_0x77f0('0x9')][_0x15d85d['uniqueid']]){for(var _0x208095 in _0x15d85d[_0x77f0('0x25')]){if(_0x15d85d['variable']['hasOwnProperty'](_0x208095)){this[_0x77f0('0x9')][_0x15d85d[_0x77f0('0x20')]][_0x208095]=_0x15d85d['value'];}}}};Fax[_0x77f0('0x1a')]['syncNewState']=function(_0x44de94){if(this[_0x77f0('0x9')][_0x44de94[_0x77f0('0x20')]]){this[_0x77f0('0x9')][_0x44de94[_0x77f0('0x20')]][_0x77f0('0x26')]=_0x44de94[_0x77f0('0x26')];this[_0x77f0('0x9')][_0x44de94['uniqueid']]['channelstatedesc']=_0x44de94[_0x77f0('0x27')];}};Fax[_0x77f0('0x1a')]['syncNewExten']=function(_0x2abe83){if(this[_0x77f0('0x9')][_0x2abe83[_0x77f0('0x20')]]){for(var _0x44a297 in _0x2abe83['variable']){if(_0x2abe83[_0x77f0('0x25')][_0x77f0('0x1d')](_0x44a297)){this[_0x77f0('0x9')][_0x2abe83[_0x77f0('0x20')]][_0x44a297]=_0x2abe83['value'];}}}};Fax[_0x77f0('0x1a')][_0x77f0('0x15')]=function(_0xd84b87){if(this['channels'][_0xd84b87['uniqueid']]){this[_0x77f0('0x9')][_0xd84b87[_0x77f0('0x20')]]['operation']=_0xd84b87[_0x77f0('0x28')];this[_0x77f0('0x9')][_0xd84b87[_0x77f0('0x20')]][_0x77f0('0x29')]=_0xd84b87[_0x77f0('0x29')];this[_0x77f0('0x9')][_0xd84b87['uniqueid']]['localstationid']=_0xd84b87[_0x77f0('0x1f')];this[_0x77f0('0x9')][_0xd84b87['uniqueid']][_0x77f0('0x2a')]=_0xd84b87[_0x77f0('0x2a')];logger['info'](_0xd84b87[_0x77f0('0x20')],'\x20syncFaxStatus\x20');}};Fax[_0x77f0('0x1a')][_0x77f0('0x17')]=function(_0x543ca6){var _0x14079d=this;if(this['channels'][_0x543ca6[_0x77f0('0x20')]]){var _0x1760a8=this[_0x77f0('0x9')][_0x543ca6['uniqueid']]['id'];this[_0x77f0('0x9')][_0x543ca6[_0x77f0('0x20')]][_0x77f0('0x2b')]=_0x543ca6[_0x77f0('0x2b')];this[_0x77f0('0x9')][_0x543ca6[_0x77f0('0x20')]][_0x77f0('0x2c')]=_0x543ca6[_0x77f0('0x2c')];this[_0x77f0('0x9')][_0x543ca6[_0x77f0('0x20')]][_0x77f0('0x1f')]=_0x543ca6[_0x77f0('0x1f')];this[_0x77f0('0x9')][_0x543ca6[_0x77f0('0x20')]][_0x77f0('0x2d')]=_0x543ca6[_0x77f0('0x2d')];this[_0x77f0('0x9')][_0x543ca6[_0x77f0('0x20')]]['transferrate']=_0x543ca6[_0x77f0('0x2e')];this[_0x77f0('0x9')][_0x543ca6['uniqueid']]['filename']=_0x543ca6[_0x77f0('0x2a')];this[_0x77f0('0x9')][_0x543ca6[_0x77f0('0x20')]][_0x77f0('0x2f')]=_0x543ca6[_0x77f0('0x2f')];if(this[_0x77f0('0x9')][_0x543ca6['uniqueid']][_0x77f0('0x2c')]>0x0){tiff2pdf(_0x543ca6['filename'],_0x77f0('0x30'),function(_0x1ae1fb){logger[_0x77f0('0x31')](_0x543ca6['uniqueid'],_0x77f0('0x32'),_0x1ae1fb[_0x77f0('0x33')]);attachment[_0x77f0('0x34')]({'name':path[_0x77f0('0x35')](_0x543ca6[_0x77f0('0x2a')])[_0x77f0('0x22')],'basename':path[_0x77f0('0x35')](_0x543ca6[_0x77f0('0x2a')])['name']+'.pdf','type':'application/pdf'})[_0x77f0('0x36')](function(_0x417e90){faxAccount[_0x77f0('0x37')](_0x1760a8,{'from':_0x543ca6[_0x77f0('0x2f')],'mapKey':_0x77f0('0x38'),'body':path[_0x77f0('0x35')](_0x543ca6[_0x77f0('0x2a')])[_0x77f0('0x22')]+'.pdf','AttachmentId':_0x417e90['id']})['catch'](function(_0x4f854e){logger[_0x77f0('0x39')](_0x543ca6[_0x77f0('0x20')],'\x20notify\x20',JSON[_0x77f0('0x3a')](_0x4f854e));});})['catch'](function(_0x566266){logger[_0x77f0('0x39')](_0x543ca6[_0x77f0('0x20')],_0x77f0('0x3b'),JSON[_0x77f0('0x3a')](_0x566266));});});}logger[_0x77f0('0x31')](_0x543ca6['uniqueid'],_0x77f0('0x3b'));}};Fax['prototype'][_0x77f0('0x3c')]=function(_0x246a6e){if(this[_0x77f0('0xc')][_0x246a6e[_0x77f0('0x20')]]){_[_0x77f0('0x3d')](this['channels'][_0x246a6e[_0x77f0('0x20')]],_[_0x77f0('0x3e')](_0x246a6e,[_0x77f0('0x3f'),_0x77f0('0x40')]));}};function updateStatus(_0xa9c00e){if(_0xa9c00e[_0x77f0('0x41')]){faxMessage[_0x77f0('0x42')](_0xa9c00e[_0x77f0('0x41')],{'failMessage':_0x77f0('0x43')})['then'](function(_0xd210e8){ut['logger'](_0x77f0('0x44'),_0xd210e8);})[_0x77f0('0x45')](function(_0x35f0cc){ut[_0x77f0('0x46')]('[Fax][Message][Error][NoUpdate1]',_0x35f0cc);});}else{ut['logger']('[Fax][Message][Error][NoUpdate2]');}}Fax['prototype']['updateStatus']=function(_0x6663d4,_0x52a6e9,_0x3ca1df){var _0x1bb86a=this;var _0x191c54={};if(_0x52a6e9){_0x191c54={'read':_0x52a6e9};}else{_0x191c54={'failMessage':_0x3ca1df};}if(this[_0x77f0('0xc')][_0x6663d4][_0x77f0('0x41')]){faxMessage['update'](this['actions'][_0x6663d4][_0x77f0('0x41')],_0x191c54)[_0x77f0('0x36')](function(_0x5e3d65){ut['logger']('[Fax][Message][Updated]',_0x5e3d65);})[_0x77f0('0x45')](function(_0x259c50){ut[_0x77f0('0x46')](_0x77f0('0x47'),_0x259c50);})[_0x77f0('0x48')](function(){delete _0x1bb86a[_0x77f0('0x9')][_0x6663d4];delete _0x1bb86a[_0x77f0('0xc')][_0x6663d4];});}else{ut[_0x77f0('0x46')](_0x77f0('0x49'));this[_0x77f0('0x4a')](_0x6663d4);delete this[_0x77f0('0xc')][_0x6663d4];}};Fax[_0x77f0('0x1a')][_0x77f0('0x18')]=function(_0xba614f){var _0x470fac=this;if(this[_0x77f0('0x9')][_0xba614f[_0x77f0('0x20')]]){if(this[_0x77f0('0xc')][_0xba614f[_0x77f0('0x20')]]){this[_0x77f0('0x9')][_0xba614f[_0x77f0('0x20')]]['id']=this[_0x77f0('0xc')][_0xba614f[_0x77f0('0x20')]]['id'];this[_0x77f0('0x9')][_0xba614f[_0x77f0('0x20')]][_0x77f0('0x22')]=this[_0x77f0('0xc')][_0xba614f['uniqueid']][_0x77f0('0x22')];}logger[_0x77f0('0x31')](_0xba614f[_0x77f0('0x20')],this['actions'][_0xba614f[_0x77f0('0x20')]]?_0x77f0('0x4b'):_0x77f0('0x4c'),JSON[_0x77f0('0x3a')](this['channels'][_0xba614f[_0x77f0('0x20')]]));if(this[_0x77f0('0xc')][_0xba614f[_0x77f0('0x20')]]){if(this[_0x77f0('0x9')][_0xba614f[_0x77f0('0x20')]]['faxpages']>0x0&&this[_0x77f0('0x9')][_0xba614f[_0x77f0('0x20')]][_0x77f0('0x4d')]===_0x77f0('0x4e')){this[_0x77f0('0x4f')](_0xba614f[_0x77f0('0x20')],!![]);}else{this['updateStatus'](_0xba614f[_0x77f0('0x20')],![],this[_0x77f0('0x9')][_0xba614f[_0x77f0('0x20')]]['faxstatusstring']?_0x77f0('0x50')+this[_0x77f0('0x9')][_0xba614f[_0x77f0('0x20')]][_0x77f0('0x51')]:_0x77f0('0x52'));}}}};Fax[_0x77f0('0x1a')]['send']=function(_0x38b894){var _0x5318ca=this;return new BPromise(function(_0x279499,_0x5bb786){_0x5318ca['execOriginate'](_0x38b894,_0x5318ca['faxAccounts'][_0x38b894[_0x77f0('0x53')]])[_0x77f0('0x36')](function(_0x5052b6){ut[_0x77f0('0x46')](_0x77f0('0x54'),_0x5052b6);_0x279499(ut['message']('Fax\x20received'));})[_0x77f0('0x45')](function(_0x5a35db){ut[_0x77f0('0x46')](_0x77f0('0x55'),_0x5a35db);updateStatus(_0x38b894);_0x5bb786(ut[_0x77f0('0x33')](_0x77f0('0x56')));});});};Fax[_0x77f0('0x1a')][_0x77f0('0x57')]=function(_0x517ae2){var _0x24efae=this;return new BPromise(function(_0x34e6d7,_0x4de34a){var _0x59e07c=_0x24efae[_0x77f0('0x58')](_0x24efae[_0x77f0('0xa')][_0x517ae2[_0x77f0('0x53')]][_0x77f0('0x59')],_0x517ae2);if(_0x59e07c[_0x77f0('0x5a')]){_0x34e6d7(ut[_0x77f0('0x33')](_0x77f0('0x5b')));}else{_0x4de34a(ut[_0x77f0('0x33')](_0x59e07c['message']));}});};function originate(_0x4c65f9,_0x5b3e2b,_0x1886fd){return new BPromise(function(_0x201f43,_0x24dca8){if(_0x1886fd){var _0x444dea=util[_0x77f0('0x5c')](_0x77f0('0x5d'),path[_0x77f0('0x35')](_0x4c65f9[_0x77f0('0x3')])[_0x77f0('0x22')],_0x4c65f9[_0x77f0('0x3')]);gs[_0x77f0('0x5e')](_0x444dea)[_0x77f0('0x36')](function(){_0x4c65f9[_0x77f0('0x3')]=util[_0x77f0('0x5c')](_0x77f0('0x5f'),path[_0x77f0('0x35')](_0x4c65f9['path'])[_0x77f0('0x60')],path[_0x77f0('0x35')](_0x4c65f9['path'])['name']);_0x5b3e2b[_0x77f0('0x61')]=_0x4c65f9[_0x77f0('0x3')];ut[_0x77f0('0x46')](_0x77f0('0x62'),'');ami[_0x77f0('0x63')](ut[_0x77f0('0x64')](_0x4c65f9,_0x5b3e2b))[_0x77f0('0x36')](function(_0x1a2618){_0x201f43(_0x1a2618);})['catch'](function(_0x1ab044){_0x24dca8(_0x1ab044);});})[_0x77f0('0x45')](function(_0x32947a){_0x24dca8(_0x32947a);});}else{ami[_0x77f0('0x63')](ut[_0x77f0('0x64')](_0x4c65f9,_0x5b3e2b))[_0x77f0('0x36')](function(_0x36e858){_0x201f43(_0x36e858);})['catch'](function(_0xc25ef9){_0x24dca8(_0xc25ef9);});}});}Fax[_0x77f0('0x1a')][_0x77f0('0x65')]=function(_0x9ed66d,_0x511223){var _0x43c7f3=this;return new BPromise(function(_0x542b48,_0x47b423){var _0x344cc5=uuid['v4']();var _0x281c3c=ut[_0x77f0('0x66')](_0x9ed66d,_0x511223);_0x43c7f3[_0x77f0('0xc')][_0x344cc5]=new Action(_0x344cc5,_0x511223,_0x9ed66d);var _0x3b5486=_0x43c7f3[_0x77f0('0xc')][_0x344cc5];if(path[_0x77f0('0x35')](_0x9ed66d[_0x77f0('0x3')])[_0x77f0('0x67')]===_0x77f0('0x68')){originate(_0x3b5486,_0x281c3c,!![])[_0x77f0('0x36')](function(_0x3f0ec5){_0x542b48(_0x3f0ec5);})['catch'](function(_0x3db089){_0x47b423(_0x3db089);});}else{originate(_0x3b5486,_0x281c3c,![])[_0x77f0('0x36')](function(_0x3d3e57){_0x542b48(_0x3d3e57);})[_0x77f0('0x45')](function(_0x3164b9){_0x47b423(_0x3164b9);});}});};Fax[_0x77f0('0x1a')][_0x77f0('0x69')]=function(_0x1f7cb7){return!_['isNil'](_0x1f7cb7)&&!_[_0x77f0('0x6a')](_0x1f7cb7[_0x77f0('0x22')])&&!_[_0x77f0('0x6a')](_0x1f7cb7[_0x77f0('0x6b')])&&_0x1f7cb7[_0x77f0('0x6b')]&&!_['isNil'](this[_0x77f0('0xb')][util[_0x77f0('0x5c')](_0x77f0('0x6c'),_0x1f7cb7[_0x77f0('0x22')])])&&!_['isNil'](this[_0x77f0('0xb')][util[_0x77f0('0x5c')](_0x77f0('0x6c'),_0x1f7cb7[_0x77f0('0x22')])]['status'])&&(this[_0x77f0('0xb')][util['format'](_0x77f0('0x6c'),_0x1f7cb7['name'])][_0x77f0('0x29')]===_0x77f0('0x6d')||this[_0x77f0('0xb')][util[_0x77f0('0x5c')](_0x77f0('0x6c'),_0x1f7cb7[_0x77f0('0x22')])]['status']===_0x77f0('0x6e'));};Fax[_0x77f0('0x1a')][_0x77f0('0x58')]=function(_0x239d3f,_0x400c72){if(!this[_0x77f0('0x69')](_0x239d3f)){ut[_0x77f0('0x46')](_0x77f0('0x6f'),_[_0x77f0('0x6a')](_0x239d3f)?'':_0x239d3f[_0x77f0('0x22')]+_0x77f0('0x70'));return{'isValid':![],'message':'Trunk\x20not\x20working\x20correctly'};}if(_[_0x77f0('0x6a')](_0x400c72[_0x77f0('0x38')])){ut[_0x77f0('0x46')](_0x77f0('0x71'),JSON[_0x77f0('0x3a')](_0x400c72));return{'isValid':![],'message':_0x77f0('0x72')};}if(_['isNil'](_0x400c72[_0x77f0('0x3')])){ut['logger'](_0x77f0('0x73'),JSON[_0x77f0('0x3a')](_0x400c72));return{'isValid':![],'message':_0x77f0('0x74')};}return{'isValid':!![],'message':'Is\x20Valid'};};Fax[_0x77f0('0x1a')][_0x77f0('0x4a')]=function(_0x5479f6,_0x22d4ac=0x2710){if(this[_0x77f0('0x9')][_0x5479f6]){setTimeout(()=>{delete this[_0x77f0('0x9')][_0x5479f6];},_0x22d4ac);}};module[_0x77f0('0x75')]=Fax;
\ No newline at end of file