Built motion from commit 129fb4d95212661e48f0db455e75d668addbaddf. Version 3.0.0...
[motion-next.git] / server / services / ami / fax / index.js
index a68c121..7dc3a42 100644 (file)
@@ -1 +1 @@
-const a1061_0x4ae6=['tiff2pdf','uniqueid','[Fax][Message][NoUpdate1]','syncHangup','unmonitored','SENDING\x20FAILED\x20','Convert\x20pdf\x20to\x20tif','calleridnum','operation','actions','[Fax][execOriginate][failure]','pagestransferred','status','faxstatusstring','newstate','./util/util','update','localstationid','transferrate','isNil','syncFaxStatus','faxstatus','../rpc/attachment','\x20result\x20conversion\x20file\x20','Action','lodash','variable','\x20receiveFax\x20','newexten','varset','syncNewExten','[Fax][checkTrunk][Trunk\x20not\x20work]','trunks','Trunk\x20Reachable','send','response','[Fax][Message][NoUpdate2]','../ami','filename','logger','Fax\x20failed','[Fax][checkTrunk][Empty\x20path]','variablesAction','util','hangup','faxpages','application/pdf','updateStatus','.pdf','channelstatedesc','\x20Trunk\x20is\x20not\x20active','uuid','merge','fax','\x20syncFaxStatus\x20','syncVarSet','/var/opt/motion2/server/files/attachments/','channel','AttachmentId','FaxAccountId','execOriginate','channelstate','path','\x20hangup\x20sendFile\x20','stringify','parse','dir','error','undefined','\x20hangup\x20faxRiceive\x20','info','remotestationid','checkAfterSend','syncNewchannel','SENDING\x20FAILED','value','XMF-PATH','faxAccounts','from-voip-provider','./util/gs','[Fax][checkTrunk][Empty\x20Fax]','checkTrunk','channels','message','[Fax][Message][Updated]','syncReceiveFax','context','format','isTrunkReachable','catch','bind','then','name','reason','resolution','Trunk\x20not\x20working','SENDING\x20FAILED:\x20','create','active','syncOriginateResponse','pick','SUCCESS','ext','SIP/%s','isValid','\x20syncNewchannel\x20','\x20notify\x20','originateresponse','prototype','Fax\x20received'];(function(_0x1d639d,_0x4ae6f2){const _0x488be0=function(_0xb66b){while(--_0xb66b){_0x1d639d['push'](_0x1d639d['shift']());}};_0x488be0(++_0x4ae6f2);}(a1061_0x4ae6,0x139));const a1061_0x488b=function(_0x1d639d,_0x4ae6f2){_0x1d639d=_0x1d639d-0x0;let _0x488be0=a1061_0x4ae6[_0x1d639d];return _0x488be0;};const _0x19cd8c=a1061_0x488b;'use strict';const util=require(_0x19cd8c('0x3c')),_=require(_0x19cd8c('0x2a')),uuid=require(_0x19cd8c('0x44')),path=require(_0x19cd8c('0x4f')),tiff2pdf=require(_0x19cd8c('0x11')),gs=require(_0x19cd8c('0x60')),logger=require('../../../config/logger')('fax'),ami=require(_0x19cd8c('0x36')),ut=require(_0x19cd8c('0x20')),Action=require('./action'),faxAccount=require('../rpc/faxAccount'),attachment=require(_0x19cd8c('0x27')),faxMessage=require('../rpc/faxMessage');function Fax(_0xb66b){const _0x1e9d6c=_0x19cd8c;this[_0x1e9d6c('0x63')]={},this['faxAccounts']=_0xb66b['faxAccounts'],this[_0x1e9d6c('0x31')]=_0xb66b[_0x1e9d6c('0x31')],this[_0x1e9d6c('0x1a')]={},ami['on']('newchannel',this[_0x1e9d6c('0x5a')]['bind'](this)),ami['on'](_0x1e9d6c('0x2e'),this['syncVarSet'][_0x1e9d6c('0x6b')](this)),ami['on'](_0x1e9d6c('0x1f'),this['syncNewState']['bind'](this)),ami['on'](_0x1e9d6c('0x2d'),this['syncNewExten'][_0x1e9d6c('0x6b')](this)),ami['on']('faxstatus',this[_0x1e9d6c('0x25')][_0x1e9d6c('0x6b')](this)),ami['on']('receivefax',this[_0x1e9d6c('0x66')][_0x1e9d6c('0x6b')](this)),ami['on'](_0x1e9d6c('0x3d'),this[_0x1e9d6c('0x14')][_0x1e9d6c('0x6b')](this)),ami['on'](_0x1e9d6c('0xe'),this[_0x1e9d6c('0x6')][_0x1e9d6c('0x6b')](this));}Fax[_0x19cd8c('0xf')][_0x19cd8c('0x5a')]=function(_0xd9e462){const _0x2c4c12=_0x19cd8c;if(_0xd9e462[_0x2c4c12('0x67')]===_0x2c4c12('0x5f'))for(const _0x54819d in this['faxAccounts']){typeof this[_0x2c4c12('0x5e')][_0x54819d]!==_0x2c4c12('0x55')&&(_0xd9e462['exten']===this[_0x2c4c12('0x5e')][_0x54819d][_0x2c4c12('0x22')]&&(this[_0x2c4c12('0x63')][_0xd9e462[_0x2c4c12('0x12')]]={},this[_0x2c4c12('0x63')][_0xd9e462[_0x2c4c12('0x12')]][_0x2c4c12('0x4a')]=_0xd9e462[_0x2c4c12('0x4a')],this[_0x2c4c12('0x63')][_0xd9e462[_0x2c4c12('0x12')]]['id']=this[_0x2c4c12('0x5e')][_0x54819d]['id'],this[_0x2c4c12('0x63')][_0xd9e462[_0x2c4c12('0x12')]][_0x2c4c12('0x6d')]=this[_0x2c4c12('0x5e')][_0x54819d][_0x2c4c12('0x6d')],logger[_0x2c4c12('0x57')](_0xd9e462[_0x2c4c12('0x12')],_0x2c4c12('0xc'))));}this[_0x2c4c12('0x1a')][_0xd9e462['uniqueid']]&&(this[_0x2c4c12('0x63')][_0xd9e462['uniqueid']]={},this[_0x2c4c12('0x63')][_0xd9e462['uniqueid']][_0x2c4c12('0x4a')]=_0xd9e462[_0x2c4c12('0x4a')],logger[_0x2c4c12('0x57')](_0xd9e462[_0x2c4c12('0x12')],_0x2c4c12('0xc')));},Fax[_0x19cd8c('0xf')][_0x19cd8c('0x48')]=function(_0x4c0eda){const _0x58563a=_0x19cd8c;if(this['channels'][_0x4c0eda[_0x58563a('0x12')]])for(const _0x1b7af2 in _0x4c0eda[_0x58563a('0x2b')]){typeof _0x4c0eda[_0x58563a('0x2b')][_0x1b7af2]!==_0x58563a('0x55')&&(this[_0x58563a('0x63')][_0x4c0eda[_0x58563a('0x12')]][_0x1b7af2]=_0x4c0eda[_0x58563a('0x5c')]);}},Fax['prototype']['syncNewState']=function(_0x55e506){const _0x388fbc=_0x19cd8c;this[_0x388fbc('0x63')][_0x55e506[_0x388fbc('0x12')]]&&(this[_0x388fbc('0x63')][_0x55e506[_0x388fbc('0x12')]][_0x388fbc('0x4e')]=_0x55e506[_0x388fbc('0x4e')],this[_0x388fbc('0x63')][_0x55e506[_0x388fbc('0x12')]][_0x388fbc('0x42')]=_0x55e506['channelstatedesc']);},Fax[_0x19cd8c('0xf')][_0x19cd8c('0x2f')]=function(_0x272127){const _0x14d11e=_0x19cd8c;if(this[_0x14d11e('0x63')][_0x272127[_0x14d11e('0x12')]])for(const _0x500908 in _0x272127[_0x14d11e('0x2b')]){typeof _0x272127['variable'][_0x500908]!==_0x14d11e('0x55')&&(this[_0x14d11e('0x63')][_0x272127[_0x14d11e('0x12')]][_0x500908]=_0x272127[_0x14d11e('0x5c')]);}},Fax[_0x19cd8c('0xf')][_0x19cd8c('0x25')]=function(_0x3834a4){const _0x34d776=_0x19cd8c;this['channels'][_0x3834a4[_0x34d776('0x12')]]&&(this['channels'][_0x3834a4[_0x34d776('0x12')]]['operation']=_0x3834a4[_0x34d776('0x19')],this['channels'][_0x3834a4['uniqueid']][_0x34d776('0x1d')]=_0x3834a4[_0x34d776('0x1d')],this['channels'][_0x3834a4['uniqueid']][_0x34d776('0x22')]=_0x3834a4[_0x34d776('0x22')],this['channels'][_0x3834a4[_0x34d776('0x12')]]['filename']=_0x3834a4['filename'],logger[_0x34d776('0x57')](_0x3834a4[_0x34d776('0x12')],_0x34d776('0x47')));},Fax[_0x19cd8c('0xf')][_0x19cd8c('0x66')]=function(_0x56ab06){const _0x488822=_0x19cd8c;if(this[_0x488822('0x63')][_0x56ab06[_0x488822('0x12')]]){const _0x296eda=this[_0x488822('0x63')][_0x56ab06[_0x488822('0x12')]]['id'];this[_0x488822('0x63')][_0x56ab06[_0x488822('0x12')]][_0x488822('0x58')]=_0x56ab06[_0x488822('0x58')],this[_0x488822('0x63')][_0x56ab06[_0x488822('0x12')]]['pagestransferred']=_0x56ab06['pagestransferred'],this['channels'][_0x56ab06[_0x488822('0x12')]][_0x488822('0x22')]=_0x56ab06['localstationid'],this['channels'][_0x56ab06['uniqueid']][_0x488822('0x1')]=_0x56ab06[_0x488822('0x1')],this[_0x488822('0x63')][_0x56ab06[_0x488822('0x12')]][_0x488822('0x23')]=_0x56ab06[_0x488822('0x23')],this[_0x488822('0x63')][_0x56ab06[_0x488822('0x12')]][_0x488822('0x37')]=_0x56ab06[_0x488822('0x37')],this[_0x488822('0x63')][_0x56ab06['uniqueid']][_0x488822('0x18')]=_0x56ab06[_0x488822('0x18')],this[_0x488822('0x63')][_0x56ab06[_0x488822('0x12')]][_0x488822('0x1c')]>0x0&&tiff2pdf(_0x56ab06[_0x488822('0x37')],_0x488822('0x49'),function(_0x1a875c){const _0x181faa=_0x488822;logger['info'](_0x56ab06[_0x181faa('0x12')],_0x181faa('0x28'),_0x1a875c[_0x181faa('0x64')]),attachment[_0x181faa('0x4')]({'name':path[_0x181faa('0x52')](_0x56ab06[_0x181faa('0x37')])['name'],'basename':path[_0x181faa('0x52')](_0x56ab06['filename'])[_0x181faa('0x6d')]+'.pdf','type':_0x181faa('0x3f')})[_0x181faa('0x6c')](function(_0x4e66be){const _0xafbb11=_0x181faa;faxAccount['notify'](_0x296eda,{'from':_0x56ab06[_0xafbb11('0x18')],'mapKey':'fax','body':path['parse'](_0x56ab06[_0xafbb11('0x37')])['name']+_0xafbb11('0x41'),'AttachmentId':_0x4e66be['id']})[_0xafbb11('0x6a')](function(_0x3dfd8f){const _0x39994a=_0xafbb11;logger[_0x39994a('0x54')](_0x56ab06[_0x39994a('0x12')],_0x39994a('0xd'),JSON[_0x39994a('0x51')](_0x3dfd8f));});})['catch'](function(_0x434d8b){const _0x8bd167=_0x181faa;logger[_0x8bd167('0x54')](_0x56ab06['uniqueid'],'\x20receiveFax\x20',JSON[_0x8bd167('0x51')](_0x434d8b));});}),logger['info'](_0x56ab06[_0x488822('0x12')],_0x488822('0x2c'));}},Fax['prototype']['syncOriginateResponse']=function(_0x340f1c){const _0x1e5186=_0x19cd8c;this[_0x1e5186('0x1a')][_0x340f1c[_0x1e5186('0x12')]]&&_[_0x1e5186('0x45')](this[_0x1e5186('0x63')][_0x340f1c[_0x1e5186('0x12')]],_[_0x1e5186('0x7')](_0x340f1c,[_0x1e5186('0x34'),_0x1e5186('0x0')]));};function updateStatus(_0x455d8a){const _0x40787c=_0x19cd8c;_0x455d8a[_0x40787c('0x4b')]?faxMessage[_0x40787c('0x21')](_0x455d8a['AttachmentId'],{'failMessage':_0x40787c('0x16')})[_0x40787c('0x6c')](function(_0x1f002b){const _0x59218c=_0x40787c;ut[_0x59218c('0x38')]('[Fax][Message][Error][Updated]',_0x1f002b);})['catch'](function(_0x3677b5){const _0x36a478=_0x40787c;ut[_0x36a478('0x38')]('[Fax][Message][Error][NoUpdate1]',_0x3677b5);}):ut[_0x40787c('0x38')]('[Fax][Message][Error][NoUpdate2]');}Fax[_0x19cd8c('0xf')]['updateStatus']=function(_0x141f30,_0x2f70bd,_0x5b871c){const _0x34de3a=_0x19cd8c,_0x45ba8f=this;let _0x177477={};_0x2f70bd?_0x177477={'read':_0x2f70bd}:_0x177477={'failMessage':_0x5b871c},this[_0x34de3a('0x1a')][_0x141f30][_0x34de3a('0x4b')]?faxMessage[_0x34de3a('0x21')](this[_0x34de3a('0x1a')][_0x141f30][_0x34de3a('0x4b')],_0x177477)['then'](function(_0x2f952b){const _0x1afe3a=_0x34de3a;ut['logger'](_0x1afe3a('0x65'),_0x2f952b);})['catch'](function(_0x15ff5b){const _0x36794f=_0x34de3a;ut[_0x36794f('0x38')](_0x36794f('0x13'),_0x15ff5b);})['finally'](function(){delete _0x45ba8f['channels'][_0x141f30],delete _0x45ba8f['actions'][_0x141f30];}):(ut[_0x34de3a('0x38')](_0x34de3a('0x35')),delete this[_0x34de3a('0x63')][_0x141f30],delete this['actions'][_0x141f30]);},Fax[_0x19cd8c('0xf')]['syncHangup']=function(_0x3c67de){const _0x350e90=_0x19cd8c;this['channels'][_0x3c67de[_0x350e90('0x12')]]&&(this['actions'][_0x3c67de[_0x350e90('0x12')]]&&(this['channels'][_0x3c67de[_0x350e90('0x12')]]['id']=this[_0x350e90('0x1a')][_0x3c67de[_0x350e90('0x12')]]['id'],this['channels'][_0x3c67de[_0x350e90('0x12')]][_0x350e90('0x6d')]=this[_0x350e90('0x1a')][_0x3c67de[_0x350e90('0x12')]]['name']),logger[_0x350e90('0x57')](_0x3c67de[_0x350e90('0x12')],this[_0x350e90('0x1a')][_0x3c67de[_0x350e90('0x12')]]?_0x350e90('0x50'):_0x350e90('0x56'),JSON[_0x350e90('0x51')](this[_0x350e90('0x63')][_0x3c67de['uniqueid']])),this[_0x350e90('0x1a')][_0x3c67de[_0x350e90('0x12')]]&&(this[_0x350e90('0x63')][_0x3c67de[_0x350e90('0x12')]][_0x350e90('0x3e')]>0x0&&this[_0x350e90('0x63')][_0x3c67de[_0x350e90('0x12')]][_0x350e90('0x26')]===_0x350e90('0x8')?this[_0x350e90('0x40')](_0x3c67de['uniqueid'],!![]):this[_0x350e90('0x40')](_0x3c67de[_0x350e90('0x12')],![],this['channels'][_0x3c67de[_0x350e90('0x12')]][_0x350e90('0x1e')]?_0x350e90('0x3')+this[_0x350e90('0x63')][_0x3c67de['uniqueid']][_0x350e90('0x1e')]:_0x350e90('0x5b'))));},Fax['prototype'][_0x19cd8c('0x33')]=function(_0x51e982){const _0x4dd8ce=this;return new Promise(function(_0xf01fa2,_0x3cc691){const _0x53a342=a1061_0x488b;_0x4dd8ce[_0x53a342('0x4d')](_0x51e982,_0x4dd8ce[_0x53a342('0x5e')][_0x51e982['FaxAccountId']])[_0x53a342('0x6c')](function(_0x53674c){const _0xb5faa2=_0x53a342;ut[_0xb5faa2('0x38')]('[Fax][execOriginate][success]',_0x53674c),_0xf01fa2(ut[_0xb5faa2('0x64')](_0xb5faa2('0x10')));})['catch'](function(_0x32d8dc){const _0x15ddcf=_0x53a342;ut[_0x15ddcf('0x38')](_0x15ddcf('0x1b'),_0x32d8dc),updateStatus(_0x51e982),_0x3cc691(ut['message'](_0x15ddcf('0x39')));});});},Fax[_0x19cd8c('0xf')][_0x19cd8c('0x59')]=function(_0x3800d1){const _0x3f48db=this;return new Promise(function(_0x4f3b14,_0x33856f){const _0x5865cb=a1061_0x488b,_0x2fe4ca=_0x3f48db[_0x5865cb('0x62')](_0x3f48db[_0x5865cb('0x5e')][_0x3800d1[_0x5865cb('0x4c')]]['Trunk'],_0x3800d1);_0x2fe4ca[_0x5865cb('0xb')]?_0x4f3b14(ut[_0x5865cb('0x64')](_0x5865cb('0x32'))):_0x33856f(ut[_0x5865cb('0x64')](_0x2fe4ca['message']));});};function originate(_0x327a96,_0x596ece,_0xc96771){return new Promise(function(_0x5b31a4,_0x14d48c){const _0x421c8e=a1061_0x488b;if(_0xc96771){const _0x4c29b7=util[_0x421c8e('0x68')]('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[_0x421c8e('0x52')](_0x327a96[_0x421c8e('0x4f')])[_0x421c8e('0x6d')],_0x327a96[_0x421c8e('0x4f')]);gs['execute'](_0x4c29b7)[_0x421c8e('0x6c')](function(){const _0x2009a5=_0x421c8e;_0x327a96[_0x2009a5('0x4f')]=util['format']('%s/%s.tif',path['parse'](_0x327a96['path'])[_0x2009a5('0x53')],path['parse'](_0x327a96[_0x2009a5('0x4f')])['name']),_0x596ece[_0x2009a5('0x5d')]=_0x327a96['path'],ut[_0x2009a5('0x38')](_0x2009a5('0x17'),''),ami[_0x2009a5('0x29')](ut[_0x2009a5('0x3b')](_0x327a96,_0x596ece))[_0x2009a5('0x6c')](function(_0x4354b3){_0x5b31a4(_0x4354b3);})['catch'](function(_0x41f390){_0x14d48c(_0x41f390);});})['catch'](function(_0x3b5262){_0x14d48c(_0x3b5262);});}else ami[_0x421c8e('0x29')](ut[_0x421c8e('0x3b')](_0x327a96,_0x596ece))[_0x421c8e('0x6c')](function(_0x5472b5){_0x5b31a4(_0x5472b5);})[_0x421c8e('0x6a')](function(_0x414393){_0x14d48c(_0x414393);});});}Fax[_0x19cd8c('0xf')]['execOriginate']=function(_0x167f92,_0x251d57){const _0x5f173a=this;return new Promise(function(_0x4fadc9,_0x444d25){const _0x1ad8a9=a1061_0x488b,_0x16ebd7=uuid['v4'](),_0x40a253=ut['addVariables'](_0x167f92,_0x251d57);_0x5f173a[_0x1ad8a9('0x1a')][_0x16ebd7]=new Action(_0x16ebd7,_0x251d57,_0x167f92);const _0x30d2b2=_0x5f173a[_0x1ad8a9('0x1a')][_0x16ebd7];path[_0x1ad8a9('0x52')](_0x167f92[_0x1ad8a9('0x4f')])[_0x1ad8a9('0x9')]===_0x1ad8a9('0x41')?originate(_0x30d2b2,_0x40a253,!![])[_0x1ad8a9('0x6c')](function(_0x2f45a0){_0x4fadc9(_0x2f45a0);})[_0x1ad8a9('0x6a')](function(_0x3838cb){_0x444d25(_0x3838cb);}):originate(_0x30d2b2,_0x40a253,![])['then'](function(_0x2dd81b){_0x4fadc9(_0x2dd81b);})[_0x1ad8a9('0x6a')](function(_0x30b96b){_0x444d25(_0x30b96b);});});},Fax['prototype'][_0x19cd8c('0x69')]=function(_0x1a0889){const _0x978732=_0x19cd8c;return!_[_0x978732('0x24')](_0x1a0889)&&!_[_0x978732('0x24')](_0x1a0889[_0x978732('0x6d')])&&!_[_0x978732('0x24')](_0x1a0889[_0x978732('0x5')])&&_0x1a0889[_0x978732('0x5')]&&!_['isNil'](this[_0x978732('0x31')][util['format'](_0x978732('0xa'),_0x1a0889[_0x978732('0x6d')])])&&!_[_0x978732('0x24')](this['trunks'][util[_0x978732('0x68')](_0x978732('0xa'),_0x1a0889[_0x978732('0x6d')])][_0x978732('0x1d')])&&(this[_0x978732('0x31')][util[_0x978732('0x68')](_0x978732('0xa'),_0x1a0889[_0x978732('0x6d')])][_0x978732('0x1d')]==='reachable'||this[_0x978732('0x31')][util['format'](_0x978732('0xa'),_0x1a0889[_0x978732('0x6d')])][_0x978732('0x1d')]===_0x978732('0x15'));},Fax['prototype'][_0x19cd8c('0x62')]=function(_0x231b1a,_0x4ad1ae){const _0x434afc=_0x19cd8c;if(!this[_0x434afc('0x69')](_0x231b1a))return ut[_0x434afc('0x38')](_0x434afc('0x30'),_[_0x434afc('0x24')](_0x231b1a)?'':_0x231b1a['name']+_0x434afc('0x43')),{'isValid':![],'message':_0x434afc('0x2')};if(_['isNil'](_0x4ad1ae[_0x434afc('0x46')]))return ut[_0x434afc('0x38')](_0x434afc('0x61'),JSON[_0x434afc('0x51')](_0x4ad1ae)),{'isValid':![],'message':'Empty\x20Fax'};if(_[_0x434afc('0x24')](_0x4ad1ae['path']))return ut['logger'](_0x434afc('0x3a'),JSON[_0x434afc('0x51')](_0x4ad1ae)),{'isValid':![],'message':'Empty\x20path'};return{'isValid':!![],'message':'Is\x20Valid'};},module['exports']=Fax;
\ No newline at end of file
+const a1225_0x34cd=['from-voip-provider','Is\x20Valid','./util/util','application/pdf','error','pagestransferred','uniqueid','Trunk','faxAccounts','path','SENDING\x20FAILED\x20','bind','create','\x20syncNewchannel\x20','localstationid','syncNewchannel','message','execOriginate','stringify','syncReceiveFax','transferrate','Trunk\x20not\x20working','.pdf','parse','calleridnum','tiff2pdf','XMF-PATH','SENDING\x20FAILED','merge','Empty\x20path','name','fax','[Fax][execOriginate][success]','syncOriginateResponse','./action','[Fax][Message][Error][Updated]','SUCCESS','syncVarSet','[Fax][Message][Updated]','receivefax','exten','addVariables','../rpc/attachment','[Fax][Message][NoUpdate2]','status','notify','channels','isNil','\x20receiveFax\x20','[Fax][Message][Error][NoUpdate1]','actions','operation','variablesAction','../rpc/faxAccount','then','FaxAccountId','update','Fax\x20failed','varset','[Fax][checkTrunk][Trunk\x20not\x20work]','undefined','reachable','AttachmentId','checkTrunk','info','util','updateStatus','SIP/%s','[Fax][Message][NoUpdate1]','channelstate','checkAfterSend','syncNewExten','lodash','newexten','newchannel','faxstatusstring','channelstatedesc','isValid','filename','\x20result\x20conversion\x20file\x20','active','hangup','Convert\x20pdf\x20to\x20tif','format','syncNewState','isTrunkReachable','syncHangup','logger','remotestationid','prototype','../../../config/logger','context','/var/opt/motion2/server/files/attachments/','../ami','syncFaxStatus','reason','channel','Trunk\x20Reachable','catch','response','unmonitored','resolution','trunks','ext','\x20hangup\x20faxRiceive\x20','exports','uuid','\x20hangup\x20sendFile\x20','dir','Action','variable','value','SENDING\x20FAILED:\x20'];(function(_0x528a4f,_0x2c0abc){const _0x34cd6c=function(_0x19a91d){while(--_0x19a91d){_0x528a4f['push'](_0x528a4f['shift']());}};_0x34cd6c(++_0x2c0abc);}(a1225_0x34cd,0x151));const a1225_0x19a9=function(_0x528a4f,_0x2c0abc){_0x528a4f=_0x528a4f-0x1c8;let _0x34cd6c=a1225_0x34cd[_0x528a4f];return _0x34cd6c;};const a1225_0x82ca06=a1225_0x19a9;'use strict';const util=require(a1225_0x82ca06(0x20b)),_=require(a1225_0x82ca06(0x212)),uuid=require(a1225_0x82ca06(0x234)),path=require(a1225_0x82ca06(0x1d3)),tiff2pdf=require(a1225_0x82ca06(0x1e3)),gs=require('./util/gs'),logger=require(a1225_0x82ca06(0x224))(a1225_0x82ca06(0x1e9)),ami=require(a1225_0x82ca06(0x227)),ut=require(a1225_0x82ca06(0x1cc)),Action=require(a1225_0x82ca06(0x1ec)),faxAccount=require(a1225_0x82ca06(0x1ff)),attachment=require(a1225_0x82ca06(0x1f4)),faxMessage=require('../rpc/faxMessage');function Fax(_0x11c319){const _0x6e9787=a1225_0x82ca06;this['channels']={},this[_0x6e9787(0x1d2)]=_0x11c319[_0x6e9787(0x1d2)],this[_0x6e9787(0x230)]=_0x11c319[_0x6e9787(0x230)],this['actions']={},ami['on'](_0x6e9787(0x214),this['syncNewchannel'][_0x6e9787(0x1d5)](this)),ami['on'](_0x6e9787(0x204),this[_0x6e9787(0x1ef)][_0x6e9787(0x1d5)](this)),ami['on']('newstate',this['syncNewState'][_0x6e9787(0x1d5)](this)),ami['on'](_0x6e9787(0x213),this[_0x6e9787(0x211)][_0x6e9787(0x1d5)](this)),ami['on']('faxstatus',this[_0x6e9787(0x228)][_0x6e9787(0x1d5)](this)),ami['on'](_0x6e9787(0x1f1),this[_0x6e9787(0x1dd)][_0x6e9787(0x1d5)](this)),ami['on'](_0x6e9787(0x21b),this['syncHangup'][_0x6e9787(0x1d5)](this)),ami['on']('originateresponse',this[_0x6e9787(0x1eb)][_0x6e9787(0x1d5)](this));}Fax[a1225_0x82ca06(0x223)][a1225_0x82ca06(0x1d9)]=function(_0x4713d2){const _0x1f18ac=a1225_0x82ca06;if(_0x4713d2[_0x1f18ac(0x225)]===_0x1f18ac(0x1ca))for(const _0x665f9e in this[_0x1f18ac(0x1d2)]){typeof this['faxAccounts'][_0x665f9e]!=='undefined'&&(_0x4713d2[_0x1f18ac(0x1f2)]===this['faxAccounts'][_0x665f9e]['localstationid']&&(this['channels'][_0x4713d2[_0x1f18ac(0x1d0)]]={},this[_0x1f18ac(0x1f8)][_0x4713d2['uniqueid']][_0x1f18ac(0x22a)]=_0x4713d2['channel'],this['channels'][_0x4713d2[_0x1f18ac(0x1d0)]]['id']=this[_0x1f18ac(0x1d2)][_0x665f9e]['id'],this['channels'][_0x4713d2['uniqueid']]['name']=this['faxAccounts'][_0x665f9e][_0x1f18ac(0x1e8)],logger[_0x1f18ac(0x20a)](_0x4713d2[_0x1f18ac(0x1d0)],_0x1f18ac(0x1d7))));}this[_0x1f18ac(0x1fc)][_0x4713d2['uniqueid']]&&(this[_0x1f18ac(0x1f8)][_0x4713d2[_0x1f18ac(0x1d0)]]={},this['channels'][_0x4713d2[_0x1f18ac(0x1d0)]][_0x1f18ac(0x22a)]=_0x4713d2[_0x1f18ac(0x22a)],logger['info'](_0x4713d2['uniqueid'],'\x20syncNewchannel\x20'));},Fax[a1225_0x82ca06(0x223)]['syncVarSet']=function(_0x3286c8){const _0x273ebb=a1225_0x82ca06;if(this[_0x273ebb(0x1f8)][_0x3286c8[_0x273ebb(0x1d0)]])for(const _0x3ab1ec in _0x3286c8[_0x273ebb(0x238)]){typeof _0x3286c8[_0x273ebb(0x238)][_0x3ab1ec]!==_0x273ebb(0x206)&&(this[_0x273ebb(0x1f8)][_0x3286c8[_0x273ebb(0x1d0)]][_0x3ab1ec]=_0x3286c8[_0x273ebb(0x1c8)]);}},Fax['prototype'][a1225_0x82ca06(0x21e)]=function(_0x35975e){const _0x4e26a6=a1225_0x82ca06;this[_0x4e26a6(0x1f8)][_0x35975e[_0x4e26a6(0x1d0)]]&&(this['channels'][_0x35975e['uniqueid']][_0x4e26a6(0x20f)]=_0x35975e[_0x4e26a6(0x20f)],this[_0x4e26a6(0x1f8)][_0x35975e[_0x4e26a6(0x1d0)]][_0x4e26a6(0x216)]=_0x35975e[_0x4e26a6(0x216)]);},Fax['prototype']['syncNewExten']=function(_0x252d59){const _0x1a4508=a1225_0x82ca06;if(this['channels'][_0x252d59[_0x1a4508(0x1d0)]])for(const _0x2ae243 in _0x252d59[_0x1a4508(0x238)]){typeof _0x252d59[_0x1a4508(0x238)][_0x2ae243]!==_0x1a4508(0x206)&&(this['channels'][_0x252d59[_0x1a4508(0x1d0)]][_0x2ae243]=_0x252d59['value']);}},Fax[a1225_0x82ca06(0x223)][a1225_0x82ca06(0x228)]=function(_0x37e444){const _0x46186d=a1225_0x82ca06;this[_0x46186d(0x1f8)][_0x37e444[_0x46186d(0x1d0)]]&&(this[_0x46186d(0x1f8)][_0x37e444[_0x46186d(0x1d0)]][_0x46186d(0x1fd)]=_0x37e444[_0x46186d(0x1fd)],this[_0x46186d(0x1f8)][_0x37e444[_0x46186d(0x1d0)]][_0x46186d(0x1f6)]=_0x37e444[_0x46186d(0x1f6)],this[_0x46186d(0x1f8)][_0x37e444[_0x46186d(0x1d0)]][_0x46186d(0x1d8)]=_0x37e444['localstationid'],this[_0x46186d(0x1f8)][_0x37e444[_0x46186d(0x1d0)]][_0x46186d(0x218)]=_0x37e444[_0x46186d(0x218)],logger[_0x46186d(0x20a)](_0x37e444[_0x46186d(0x1d0)],'\x20syncFaxStatus\x20'));},Fax[a1225_0x82ca06(0x223)][a1225_0x82ca06(0x1dd)]=function(_0x29c186){const _0x4469ad=a1225_0x82ca06;if(this[_0x4469ad(0x1f8)][_0x29c186['uniqueid']]){const _0x1c0cfd=this[_0x4469ad(0x1f8)][_0x29c186[_0x4469ad(0x1d0)]]['id'];this[_0x4469ad(0x1f8)][_0x29c186[_0x4469ad(0x1d0)]][_0x4469ad(0x222)]=_0x29c186[_0x4469ad(0x222)],this[_0x4469ad(0x1f8)][_0x29c186['uniqueid']][_0x4469ad(0x1cf)]=_0x29c186[_0x4469ad(0x1cf)],this[_0x4469ad(0x1f8)][_0x29c186[_0x4469ad(0x1d0)]][_0x4469ad(0x1d8)]=_0x29c186[_0x4469ad(0x1d8)],this[_0x4469ad(0x1f8)][_0x29c186['uniqueid']][_0x4469ad(0x22f)]=_0x29c186[_0x4469ad(0x22f)],this[_0x4469ad(0x1f8)][_0x29c186['uniqueid']][_0x4469ad(0x1de)]=_0x29c186[_0x4469ad(0x1de)],this[_0x4469ad(0x1f8)][_0x29c186[_0x4469ad(0x1d0)]][_0x4469ad(0x218)]=_0x29c186[_0x4469ad(0x218)],this[_0x4469ad(0x1f8)][_0x29c186[_0x4469ad(0x1d0)]]['calleridnum']=_0x29c186[_0x4469ad(0x1e2)],this[_0x4469ad(0x1f8)][_0x29c186[_0x4469ad(0x1d0)]][_0x4469ad(0x1cf)]>0x0&&tiff2pdf(_0x29c186[_0x4469ad(0x218)],_0x4469ad(0x226),function(_0x32a7ec){const _0x1e85af=_0x4469ad;logger['info'](_0x29c186['uniqueid'],_0x1e85af(0x219),_0x32a7ec[_0x1e85af(0x1da)]),attachment[_0x1e85af(0x1d6)]({'name':path[_0x1e85af(0x1e1)](_0x29c186['filename'])[_0x1e85af(0x1e8)],'basename':path['parse'](_0x29c186[_0x1e85af(0x218)])[_0x1e85af(0x1e8)]+_0x1e85af(0x1e0),'type':_0x1e85af(0x1cd)})[_0x1e85af(0x200)](function(_0x3af7e6){const _0x2759c2=_0x1e85af;faxAccount[_0x2759c2(0x1f7)](_0x1c0cfd,{'from':_0x29c186[_0x2759c2(0x1e2)],'mapKey':'fax','body':path['parse'](_0x29c186['filename'])[_0x2759c2(0x1e8)]+_0x2759c2(0x1e0),'AttachmentId':_0x3af7e6['id']})[_0x2759c2(0x22c)](function(_0x1ab2ab){const _0xbaab32=_0x2759c2;logger[_0xbaab32(0x1ce)](_0x29c186[_0xbaab32(0x1d0)],'\x20notify\x20',JSON[_0xbaab32(0x1dc)](_0x1ab2ab));});})[_0x1e85af(0x22c)](function(_0x500ecd){const _0x53b12d=_0x1e85af;logger[_0x53b12d(0x1ce)](_0x29c186[_0x53b12d(0x1d0)],_0x53b12d(0x1fa),JSON[_0x53b12d(0x1dc)](_0x500ecd));});}),logger[_0x4469ad(0x20a)](_0x29c186[_0x4469ad(0x1d0)],_0x4469ad(0x1fa));}},Fax[a1225_0x82ca06(0x223)][a1225_0x82ca06(0x1eb)]=function(_0x5e8616){const _0x26d651=a1225_0x82ca06;this['actions'][_0x5e8616[_0x26d651(0x1d0)]]&&_[_0x26d651(0x1e6)](this['channels'][_0x5e8616[_0x26d651(0x1d0)]],_['pick'](_0x5e8616,[_0x26d651(0x22d),_0x26d651(0x229)]));};function updateStatus(_0x53a318){const _0x467912=a1225_0x82ca06;_0x53a318[_0x467912(0x208)]?faxMessage[_0x467912(0x202)](_0x53a318[_0x467912(0x208)],{'failMessage':_0x467912(0x1d4)})[_0x467912(0x200)](function(_0x2ecb78){const _0x2051bf=_0x467912;ut[_0x2051bf(0x221)](_0x2051bf(0x1ed),_0x2ecb78);})[_0x467912(0x22c)](function(_0x32069e){const _0x49d267=_0x467912;ut[_0x49d267(0x221)](_0x49d267(0x1fb),_0x32069e);}):ut[_0x467912(0x221)]('[Fax][Message][Error][NoUpdate2]');}Fax[a1225_0x82ca06(0x223)][a1225_0x82ca06(0x20c)]=function(_0x479dfb,_0x284aaa,_0x3218de){const _0xa9b0e=a1225_0x82ca06,_0x5d0a29=this;let _0x1a63b4={};_0x284aaa?_0x1a63b4={'read':_0x284aaa}:_0x1a63b4={'failMessage':_0x3218de},this[_0xa9b0e(0x1fc)][_0x479dfb][_0xa9b0e(0x208)]?faxMessage[_0xa9b0e(0x202)](this['actions'][_0x479dfb]['AttachmentId'],_0x1a63b4)[_0xa9b0e(0x200)](function(_0x439e0d){const _0x1decb2=_0xa9b0e;ut[_0x1decb2(0x221)](_0x1decb2(0x1f0),_0x439e0d);})[_0xa9b0e(0x22c)](function(_0x4ee722){const _0x5f2a05=_0xa9b0e;ut[_0x5f2a05(0x221)](_0x5f2a05(0x20e),_0x4ee722);})['finally'](function(){const _0x4e069a=_0xa9b0e;delete _0x5d0a29[_0x4e069a(0x1f8)][_0x479dfb],delete _0x5d0a29[_0x4e069a(0x1fc)][_0x479dfb];}):(ut[_0xa9b0e(0x221)](_0xa9b0e(0x1f5)),delete this[_0xa9b0e(0x1f8)][_0x479dfb],delete this[_0xa9b0e(0x1fc)][_0x479dfb]);},Fax['prototype'][a1225_0x82ca06(0x220)]=function(_0xe65381){const _0x22899b=a1225_0x82ca06;this[_0x22899b(0x1f8)][_0xe65381[_0x22899b(0x1d0)]]&&(this['actions'][_0xe65381['uniqueid']]&&(this['channels'][_0xe65381['uniqueid']]['id']=this[_0x22899b(0x1fc)][_0xe65381[_0x22899b(0x1d0)]]['id'],this[_0x22899b(0x1f8)][_0xe65381[_0x22899b(0x1d0)]][_0x22899b(0x1e8)]=this[_0x22899b(0x1fc)][_0xe65381[_0x22899b(0x1d0)]][_0x22899b(0x1e8)]),logger['info'](_0xe65381['uniqueid'],this[_0x22899b(0x1fc)][_0xe65381[_0x22899b(0x1d0)]]?_0x22899b(0x235):_0x22899b(0x232),JSON[_0x22899b(0x1dc)](this['channels'][_0xe65381[_0x22899b(0x1d0)]])),this[_0x22899b(0x1fc)][_0xe65381[_0x22899b(0x1d0)]]&&(this['channels'][_0xe65381[_0x22899b(0x1d0)]]['faxpages']>0x0&&this[_0x22899b(0x1f8)][_0xe65381[_0x22899b(0x1d0)]]['faxstatus']===_0x22899b(0x1ee)?this['updateStatus'](_0xe65381[_0x22899b(0x1d0)],!![]):this[_0x22899b(0x20c)](_0xe65381[_0x22899b(0x1d0)],![],this[_0x22899b(0x1f8)][_0xe65381['uniqueid']][_0x22899b(0x215)]?_0x22899b(0x1c9)+this['channels'][_0xe65381[_0x22899b(0x1d0)]][_0x22899b(0x215)]:_0x22899b(0x1e5))));},Fax[a1225_0x82ca06(0x223)]['send']=function(_0x445c6b){const _0x4452fa=this;return new Promise(function(_0x832966,_0x41a2f6){const _0x12ef3c=a1225_0x19a9;_0x4452fa[_0x12ef3c(0x1db)](_0x445c6b,_0x4452fa[_0x12ef3c(0x1d2)][_0x445c6b['FaxAccountId']])[_0x12ef3c(0x200)](function(_0x297d6b){const _0x1da053=_0x12ef3c;ut[_0x1da053(0x221)](_0x1da053(0x1ea),_0x297d6b),_0x832966(ut['message']('Fax\x20received'));})[_0x12ef3c(0x22c)](function(_0xeac0b7){const _0x5f35e5=_0x12ef3c;ut[_0x5f35e5(0x221)]('[Fax][execOriginate][failure]',_0xeac0b7),updateStatus(_0x445c6b),_0x41a2f6(ut[_0x5f35e5(0x1da)](_0x5f35e5(0x203)));});});},Fax[a1225_0x82ca06(0x223)][a1225_0x82ca06(0x210)]=function(_0x581305){const _0xfbe78f=this;return new Promise(function(_0x284fcd,_0x381812){const _0x717191=a1225_0x19a9,_0x2b6f10=_0xfbe78f['checkTrunk'](_0xfbe78f['faxAccounts'][_0x581305[_0x717191(0x201)]][_0x717191(0x1d1)],_0x581305);_0x2b6f10[_0x717191(0x217)]?_0x284fcd(ut[_0x717191(0x1da)](_0x717191(0x22b))):_0x381812(ut[_0x717191(0x1da)](_0x2b6f10['message']));});};function originate(_0x538259,_0x281f3b,_0x5b2903){return new Promise(function(_0x42b190,_0x40da2f){const _0x58f8c5=a1225_0x19a9;if(_0x5b2903){const _0x407b00=util[_0x58f8c5(0x21d)]('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['parse'](_0x538259['path'])[_0x58f8c5(0x1e8)],_0x538259[_0x58f8c5(0x1d3)]);gs['execute'](_0x407b00)['then'](function(){const _0x83b13=_0x58f8c5;_0x538259[_0x83b13(0x1d3)]=util[_0x83b13(0x21d)]('%s/%s.tif',path[_0x83b13(0x1e1)](_0x538259[_0x83b13(0x1d3)])[_0x83b13(0x236)],path[_0x83b13(0x1e1)](_0x538259[_0x83b13(0x1d3)])[_0x83b13(0x1e8)]),_0x281f3b[_0x83b13(0x1e4)]=_0x538259[_0x83b13(0x1d3)],ut[_0x83b13(0x221)](_0x83b13(0x21c),''),ami[_0x83b13(0x237)](ut[_0x83b13(0x1fe)](_0x538259,_0x281f3b))[_0x83b13(0x200)](function(_0x5cb359){_0x42b190(_0x5cb359);})[_0x83b13(0x22c)](function(_0x57a6ff){_0x40da2f(_0x57a6ff);});})[_0x58f8c5(0x22c)](function(_0xc88ea7){_0x40da2f(_0xc88ea7);});}else ami[_0x58f8c5(0x237)](ut[_0x58f8c5(0x1fe)](_0x538259,_0x281f3b))[_0x58f8c5(0x200)](function(_0x2afa38){_0x42b190(_0x2afa38);})[_0x58f8c5(0x22c)](function(_0x3f9ea1){_0x40da2f(_0x3f9ea1);});});}Fax[a1225_0x82ca06(0x223)][a1225_0x82ca06(0x1db)]=function(_0x127bbf,_0x44ff1f){const _0x229752=this;return new Promise(function(_0x212e7b,_0x3bb376){const _0x655838=a1225_0x19a9,_0x467517=uuid['v4'](),_0x157005=ut[_0x655838(0x1f3)](_0x127bbf,_0x44ff1f);_0x229752[_0x655838(0x1fc)][_0x467517]=new Action(_0x467517,_0x44ff1f,_0x127bbf);const _0x4bc6ad=_0x229752[_0x655838(0x1fc)][_0x467517];path[_0x655838(0x1e1)](_0x127bbf[_0x655838(0x1d3)])[_0x655838(0x231)]===_0x655838(0x1e0)?originate(_0x4bc6ad,_0x157005,!![])[_0x655838(0x200)](function(_0x56b543){_0x212e7b(_0x56b543);})[_0x655838(0x22c)](function(_0x37504a){_0x3bb376(_0x37504a);}):originate(_0x4bc6ad,_0x157005,![])[_0x655838(0x200)](function(_0x4a6680){_0x212e7b(_0x4a6680);})[_0x655838(0x22c)](function(_0x5dfad2){_0x3bb376(_0x5dfad2);});});},Fax[a1225_0x82ca06(0x223)][a1225_0x82ca06(0x21f)]=function(_0x12df55){const _0x1ea3e1=a1225_0x82ca06;return!_['isNil'](_0x12df55)&&!_[_0x1ea3e1(0x1f9)](_0x12df55[_0x1ea3e1(0x1e8)])&&!_['isNil'](_0x12df55[_0x1ea3e1(0x21a)])&&_0x12df55['active']&&!_[_0x1ea3e1(0x1f9)](this[_0x1ea3e1(0x230)][util['format']('SIP/%s',_0x12df55[_0x1ea3e1(0x1e8)])])&&!_[_0x1ea3e1(0x1f9)](this[_0x1ea3e1(0x230)][util['format'](_0x1ea3e1(0x20d),_0x12df55[_0x1ea3e1(0x1e8)])][_0x1ea3e1(0x1f6)])&&(this[_0x1ea3e1(0x230)][util[_0x1ea3e1(0x21d)](_0x1ea3e1(0x20d),_0x12df55[_0x1ea3e1(0x1e8)])]['status']===_0x1ea3e1(0x207)||this[_0x1ea3e1(0x230)][util[_0x1ea3e1(0x21d)](_0x1ea3e1(0x20d),_0x12df55['name'])][_0x1ea3e1(0x1f6)]===_0x1ea3e1(0x22e));},Fax[a1225_0x82ca06(0x223)][a1225_0x82ca06(0x209)]=function(_0x37ed0f,_0x3feb4f){const _0x1f7470=a1225_0x82ca06;if(!this[_0x1f7470(0x21f)](_0x37ed0f))return ut['logger'](_0x1f7470(0x205),_[_0x1f7470(0x1f9)](_0x37ed0f)?'':_0x37ed0f[_0x1f7470(0x1e8)]+'\x20Trunk\x20is\x20not\x20active'),{'isValid':![],'message':_0x1f7470(0x1df)};if(_['isNil'](_0x3feb4f['fax']))return ut[_0x1f7470(0x221)]('[Fax][checkTrunk][Empty\x20Fax]',JSON['stringify'](_0x3feb4f)),{'isValid':![],'message':'Empty\x20Fax'};if(_[_0x1f7470(0x1f9)](_0x3feb4f['path']))return ut[_0x1f7470(0x221)]('[Fax][checkTrunk][Empty\x20path]',JSON['stringify'](_0x3feb4f)),{'isValid':![],'message':_0x1f7470(0x1e7)};return{'isValid':!![],'message':_0x1f7470(0x1cb)};},module[a1225_0x82ca06(0x233)]=Fax;
\ No newline at end of file