Built motion from commit 82a371561bcdbc7605c801e5e414f4032ba9e7ad. Version 3.0.0...
[motion-next.git] / server / services / ami / fax / index.js
1 const a1060_0x1b5e=['syncNewchannel','from-voip-provider','syncVarSet','resolution','reachable','../rpc/faxAccount','lodash','SENDING\x20FAILED\x20','syncHangup','remotestationid','syncOriginateResponse','path','bind','SENDING\x20FAILED','syncFaxStatus','\x20notify\x20','then','parse','transferrate','checkTrunk','Trunk\x20not\x20working','[Fax][checkTrunk][Trunk\x20not\x20work]','message','ext','XMF-PATH','info','[Fax][checkTrunk][Empty\x20Fax]','pagestransferred','logger','calleridnum','Trunk\x20Reachable','isTrunkReachable','[Fax][Message][NoUpdate1]','receivefax','\x20syncFaxStatus\x20','updateStatus','./util/util','originateresponse','channels','fax','AttachmentId','tiff2pdf','SIP/%s','faxAccounts','syncNewExten','\x20result\x20conversion\x20file\x20','active','context','newexten','faxpages','reason','faxstatus','Action','SUCCESS','variable','merge','syncNewState','send','pick','error','[Fax][Message][Error][NoUpdate1]','channelstatedesc','localstationid','faxstatusstring','../../../config/logger','\x20hangup\x20sendFile\x20','status','%s/%s.tif','value','[Fax][execOriginate][success]','\x20receiveFax\x20','name','update','operation','create','execOriginate','addVariables','channelstate','../rpc/faxMessage','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','trunks','application/pdf','checkAfterSend','uuid','exten','FaxAccountId','/var/opt/motion2/server/files/attachments/','varset','Fax\x20received','actions','prototype','catch','newstate','util','Empty\x20Fax','\x20syncNewchannel\x20','Is\x20Valid','[Fax][Message][Error][NoUpdate2]','Empty\x20path','./action','Trunk','[Fax][checkTrunk][Empty\x20path]','SENDING\x20FAILED:\x20','isNil','channel','stringify','format','uniqueid','.pdf','undefined','\x20hangup\x20faxRiceive\x20','exports','filename','[Fax][execOriginate][failure]','./util/gs','[Fax][Message][Updated]','newchannel'];(function(_0x4cc5b3,_0x1b5ece){const _0x51d983=function(_0x4cf58a){while(--_0x4cf58a){_0x4cc5b3['push'](_0x4cc5b3['shift']());}};_0x51d983(++_0x1b5ece);}(a1060_0x1b5e,0x1a3));const a1060_0x51d9=function(_0x4cc5b3,_0x1b5ece){_0x4cc5b3=_0x4cc5b3-0x0;let _0x51d983=a1060_0x1b5e[_0x4cc5b3];return _0x51d983;};const _0x1d8414=a1060_0x51d9;'use strict';const util=require(_0x1d8414('0x19')),_=require(_0x1d8414('0x37')),uuid=require(_0x1d8414('0xf')),path=require(_0x1d8414('0x3c')),tiff2pdf=require(_0x1d8414('0x5a')),gs=require(_0x1d8414('0x2e')),logger=require(_0x1d8414('0x71'))(_0x1d8414('0x58')),ami=require('../ami'),ut=require(_0x1d8414('0x55')),Action=require(_0x1d8414('0x1f')),faxAccount=require(_0x1d8414('0x36')),attachment=require('../rpc/attachment'),faxMessage=require(_0x1d8414('0xa'));function Fax(_0x4cf58a){const _0x2c814f=_0x1d8414;this[_0x2c814f('0x57')]={},this[_0x2c814f('0x5c')]=_0x4cf58a['faxAccounts'],this[_0x2c814f('0xc')]=_0x4cf58a[_0x2c814f('0xc')],this['actions']={},ami['on'](_0x2c814f('0x30'),this['syncNewchannel'][_0x2c814f('0x3d')](this)),ami['on'](_0x2c814f('0x13'),this[_0x2c814f('0x33')][_0x2c814f('0x3d')](this)),ami['on'](_0x2c814f('0x18'),this['syncNewState'][_0x2c814f('0x3d')](this)),ami['on'](_0x2c814f('0x61'),this[_0x2c814f('0x5d')]['bind'](this)),ami['on'](_0x2c814f('0x64'),this[_0x2c814f('0x3f')][_0x2c814f('0x3d')](this)),ami['on'](_0x2c814f('0x52'),this['syncReceiveFax'][_0x2c814f('0x3d')](this)),ami['on']('hangup',this[_0x2c814f('0x39')]['bind'](this)),ami['on'](_0x2c814f('0x56'),this[_0x2c814f('0x3b')][_0x2c814f('0x3d')](this));}Fax[_0x1d8414('0x16')][_0x1d8414('0x31')]=function(_0x642a75){const _0x57c8e0=_0x1d8414;if(_0x642a75[_0x57c8e0('0x60')]===_0x57c8e0('0x32'))for(const _0x148343 in this[_0x57c8e0('0x5c')]){typeof this[_0x57c8e0('0x5c')][_0x148343]!==_0x57c8e0('0x29')&&(_0x642a75[_0x57c8e0('0x10')]===this[_0x57c8e0('0x5c')][_0x148343][_0x57c8e0('0x6f')]&&(this[_0x57c8e0('0x57')][_0x642a75[_0x57c8e0('0x27')]]={},this[_0x57c8e0('0x57')][_0x642a75[_0x57c8e0('0x27')]][_0x57c8e0('0x24')]=_0x642a75[_0x57c8e0('0x24')],this[_0x57c8e0('0x57')][_0x642a75['uniqueid']]['id']=this[_0x57c8e0('0x5c')][_0x148343]['id'],this[_0x57c8e0('0x57')][_0x642a75['uniqueid']][_0x57c8e0('0x3')]=this[_0x57c8e0('0x5c')][_0x148343][_0x57c8e0('0x3')],logger[_0x57c8e0('0x4a')](_0x642a75[_0x57c8e0('0x27')],_0x57c8e0('0x1b'))));}this[_0x57c8e0('0x15')][_0x642a75['uniqueid']]&&(this['channels'][_0x642a75[_0x57c8e0('0x27')]]={},this['channels'][_0x642a75['uniqueid']][_0x57c8e0('0x24')]=_0x642a75[_0x57c8e0('0x24')],logger[_0x57c8e0('0x4a')](_0x642a75[_0x57c8e0('0x27')],_0x57c8e0('0x1b')));},Fax['prototype'][_0x1d8414('0x33')]=function(_0x5237c0){const _0xcdfaa0=_0x1d8414;if(this[_0xcdfaa0('0x57')][_0x5237c0[_0xcdfaa0('0x27')]])for(const _0x5091a1 in _0x5237c0[_0xcdfaa0('0x67')]){typeof _0x5237c0[_0xcdfaa0('0x67')][_0x5091a1]!==_0xcdfaa0('0x29')&&(this[_0xcdfaa0('0x57')][_0x5237c0['uniqueid']][_0x5091a1]=_0x5237c0['value']);}},Fax['prototype'][_0x1d8414('0x69')]=function(_0x13e67b){const _0x1146ff=_0x1d8414;this[_0x1146ff('0x57')][_0x13e67b['uniqueid']]&&(this[_0x1146ff('0x57')][_0x13e67b[_0x1146ff('0x27')]][_0x1146ff('0x9')]=_0x13e67b[_0x1146ff('0x9')],this[_0x1146ff('0x57')][_0x13e67b[_0x1146ff('0x27')]]['channelstatedesc']=_0x13e67b[_0x1146ff('0x6e')]);},Fax['prototype'][_0x1d8414('0x5d')]=function(_0x753a59){const _0xab2e16=_0x1d8414;if(this[_0xab2e16('0x57')][_0x753a59[_0xab2e16('0x27')]])for(const _0x51acdf in _0x753a59['variable']){typeof _0x753a59['variable'][_0x51acdf]!=='undefined'&&(this[_0xab2e16('0x57')][_0x753a59['uniqueid']][_0x51acdf]=_0x753a59[_0xab2e16('0x0')]);}},Fax['prototype'][_0x1d8414('0x3f')]=function(_0x4bf6d0){const _0x53f0e2=_0x1d8414;this[_0x53f0e2('0x57')][_0x4bf6d0['uniqueid']]&&(this[_0x53f0e2('0x57')][_0x4bf6d0[_0x53f0e2('0x27')]][_0x53f0e2('0x5')]=_0x4bf6d0[_0x53f0e2('0x5')],this[_0x53f0e2('0x57')][_0x4bf6d0[_0x53f0e2('0x27')]][_0x53f0e2('0x73')]=_0x4bf6d0[_0x53f0e2('0x73')],this[_0x53f0e2('0x57')][_0x4bf6d0['uniqueid']][_0x53f0e2('0x6f')]=_0x4bf6d0['localstationid'],this[_0x53f0e2('0x57')][_0x4bf6d0[_0x53f0e2('0x27')]][_0x53f0e2('0x2c')]=_0x4bf6d0[_0x53f0e2('0x2c')],logger[_0x53f0e2('0x4a')](_0x4bf6d0['uniqueid'],_0x53f0e2('0x53')));},Fax[_0x1d8414('0x16')]['syncReceiveFax']=function(_0x189c3b){const _0x58ff5b=_0x1d8414;if(this[_0x58ff5b('0x57')][_0x189c3b[_0x58ff5b('0x27')]]){const _0x3ba33d=this['channels'][_0x189c3b[_0x58ff5b('0x27')]]['id'];this['channels'][_0x189c3b['uniqueid']][_0x58ff5b('0x3a')]=_0x189c3b[_0x58ff5b('0x3a')],this[_0x58ff5b('0x57')][_0x189c3b[_0x58ff5b('0x27')]][_0x58ff5b('0x4c')]=_0x189c3b[_0x58ff5b('0x4c')],this[_0x58ff5b('0x57')][_0x189c3b['uniqueid']]['localstationid']=_0x189c3b[_0x58ff5b('0x6f')],this[_0x58ff5b('0x57')][_0x189c3b['uniqueid']][_0x58ff5b('0x34')]=_0x189c3b[_0x58ff5b('0x34')],this[_0x58ff5b('0x57')][_0x189c3b[_0x58ff5b('0x27')]][_0x58ff5b('0x43')]=_0x189c3b[_0x58ff5b('0x43')],this[_0x58ff5b('0x57')][_0x189c3b['uniqueid']][_0x58ff5b('0x2c')]=_0x189c3b['filename'],this['channels'][_0x189c3b[_0x58ff5b('0x27')]][_0x58ff5b('0x4e')]=_0x189c3b[_0x58ff5b('0x4e')],this[_0x58ff5b('0x57')][_0x189c3b[_0x58ff5b('0x27')]]['pagestransferred']>0x0&&tiff2pdf(_0x189c3b[_0x58ff5b('0x2c')],_0x58ff5b('0x12'),function(_0x37677f){const _0x564465=_0x58ff5b;logger[_0x564465('0x4a')](_0x189c3b[_0x564465('0x27')],_0x564465('0x5e'),_0x37677f['message']),attachment[_0x564465('0x6')]({'name':path[_0x564465('0x42')](_0x189c3b[_0x564465('0x2c')])['name'],'basename':path[_0x564465('0x42')](_0x189c3b[_0x564465('0x2c')])[_0x564465('0x3')]+_0x564465('0x28'),'type':_0x564465('0xd')})[_0x564465('0x41')](function(_0x4c2982){const _0x5dc7c6=_0x564465;faxAccount['notify'](_0x3ba33d,{'from':_0x189c3b[_0x5dc7c6('0x4e')],'mapKey':_0x5dc7c6('0x58'),'body':path[_0x5dc7c6('0x42')](_0x189c3b[_0x5dc7c6('0x2c')])[_0x5dc7c6('0x3')]+_0x5dc7c6('0x28'),'AttachmentId':_0x4c2982['id']})[_0x5dc7c6('0x17')](function(_0x319c75){const _0x41531a=_0x5dc7c6;logger[_0x41531a('0x6c')](_0x189c3b[_0x41531a('0x27')],_0x41531a('0x40'),JSON['stringify'](_0x319c75));});})[_0x564465('0x17')](function(_0x2cb50d){const _0x1955b3=_0x564465;logger[_0x1955b3('0x6c')](_0x189c3b[_0x1955b3('0x27')],_0x1955b3('0x2'),JSON[_0x1955b3('0x25')](_0x2cb50d));});}),logger[_0x58ff5b('0x4a')](_0x189c3b[_0x58ff5b('0x27')],_0x58ff5b('0x2'));}},Fax[_0x1d8414('0x16')][_0x1d8414('0x3b')]=function(_0x770276){const _0x357380=_0x1d8414;this['actions'][_0x770276[_0x357380('0x27')]]&&_[_0x357380('0x68')](this[_0x357380('0x57')][_0x770276[_0x357380('0x27')]],_[_0x357380('0x6b')](_0x770276,['response',_0x357380('0x63')]));};function updateStatus(_0x5a6a9e){const _0x573e8c=_0x1d8414;_0x5a6a9e[_0x573e8c('0x59')]?faxMessage[_0x573e8c('0x4')](_0x5a6a9e[_0x573e8c('0x59')],{'failMessage':_0x573e8c('0x38')})[_0x573e8c('0x41')](function(_0x438a9e){const _0x175729=_0x573e8c;ut[_0x175729('0x4d')]('[Fax][Message][Error][Updated]',_0x438a9e);})['catch'](function(_0x1f1e87){const _0xa6b9a6=_0x573e8c;ut[_0xa6b9a6('0x4d')](_0xa6b9a6('0x6d'),_0x1f1e87);}):ut[_0x573e8c('0x4d')](_0x573e8c('0x1d'));}Fax[_0x1d8414('0x16')]['updateStatus']=function(_0x3e649d,_0x28a3da,_0x1552f9){const _0x3842ea=_0x1d8414,_0x117a13=this;let _0x424f51={};_0x28a3da?_0x424f51={'read':_0x28a3da}:_0x424f51={'failMessage':_0x1552f9},this[_0x3842ea('0x15')][_0x3e649d][_0x3842ea('0x59')]?faxMessage[_0x3842ea('0x4')](this[_0x3842ea('0x15')][_0x3e649d][_0x3842ea('0x59')],_0x424f51)[_0x3842ea('0x41')](function(_0x39e6c9){const _0x10d831=_0x3842ea;ut[_0x10d831('0x4d')](_0x10d831('0x2f'),_0x39e6c9);})['catch'](function(_0x460143){const _0x4e479d=_0x3842ea;ut[_0x4e479d('0x4d')](_0x4e479d('0x51'),_0x460143);})['finally'](function(){const _0x5e98aa=_0x3842ea;delete _0x117a13[_0x5e98aa('0x57')][_0x3e649d],delete _0x117a13[_0x5e98aa('0x15')][_0x3e649d];}):(ut['logger']('[Fax][Message][NoUpdate2]'),delete this[_0x3842ea('0x57')][_0x3e649d],delete this['actions'][_0x3e649d]);},Fax[_0x1d8414('0x16')][_0x1d8414('0x39')]=function(_0x2d1adc){const _0x570ada=_0x1d8414;this['channels'][_0x2d1adc[_0x570ada('0x27')]]&&(this[_0x570ada('0x15')][_0x2d1adc[_0x570ada('0x27')]]&&(this[_0x570ada('0x57')][_0x2d1adc[_0x570ada('0x27')]]['id']=this[_0x570ada('0x15')][_0x2d1adc[_0x570ada('0x27')]]['id'],this[_0x570ada('0x57')][_0x2d1adc[_0x570ada('0x27')]]['name']=this[_0x570ada('0x15')][_0x2d1adc['uniqueid']][_0x570ada('0x3')]),logger['info'](_0x2d1adc[_0x570ada('0x27')],this['actions'][_0x2d1adc[_0x570ada('0x27')]]?_0x570ada('0x72'):_0x570ada('0x2a'),JSON[_0x570ada('0x25')](this['channels'][_0x2d1adc[_0x570ada('0x27')]])),this[_0x570ada('0x15')][_0x2d1adc[_0x570ada('0x27')]]&&(this[_0x570ada('0x57')][_0x2d1adc[_0x570ada('0x27')]][_0x570ada('0x62')]>0x0&&this[_0x570ada('0x57')][_0x2d1adc[_0x570ada('0x27')]][_0x570ada('0x64')]===_0x570ada('0x66')?this[_0x570ada('0x54')](_0x2d1adc['uniqueid'],!![]):this['updateStatus'](_0x2d1adc[_0x570ada('0x27')],![],this[_0x570ada('0x57')][_0x2d1adc[_0x570ada('0x27')]][_0x570ada('0x70')]?_0x570ada('0x22')+this[_0x570ada('0x57')][_0x2d1adc[_0x570ada('0x27')]][_0x570ada('0x70')]:_0x570ada('0x3e'))));},Fax[_0x1d8414('0x16')][_0x1d8414('0x6a')]=function(_0x354883){const _0xda617a=this;return new Promise(function(_0x43c45a,_0x5595b6){const _0x38d2e7=a1060_0x51d9;_0xda617a[_0x38d2e7('0x7')](_0x354883,_0xda617a[_0x38d2e7('0x5c')][_0x354883['FaxAccountId']])[_0x38d2e7('0x41')](function(_0x1b003d){const _0x264950=_0x38d2e7;ut['logger'](_0x264950('0x1'),_0x1b003d),_0x43c45a(ut[_0x264950('0x47')](_0x264950('0x14')));})[_0x38d2e7('0x17')](function(_0x2165c2){const _0x254128=_0x38d2e7;ut[_0x254128('0x4d')](_0x254128('0x2d'),_0x2165c2),updateStatus(_0x354883),_0x5595b6(ut[_0x254128('0x47')]('Fax\x20failed'));});});},Fax['prototype'][_0x1d8414('0xe')]=function(_0x194e70){const _0x31994c=this;return new Promise(function(_0x2bdf77,_0x58d2d7){const _0x4eaead=a1060_0x51d9,_0x4486e1=_0x31994c[_0x4eaead('0x44')](_0x31994c[_0x4eaead('0x5c')][_0x194e70[_0x4eaead('0x11')]][_0x4eaead('0x20')],_0x194e70);_0x4486e1['isValid']?_0x2bdf77(ut[_0x4eaead('0x47')](_0x4eaead('0x4f'))):_0x58d2d7(ut[_0x4eaead('0x47')](_0x4486e1[_0x4eaead('0x47')]));});};function originate(_0x5e4ec0,_0x59a305,_0x1af336){return new Promise(function(_0x5d6791,_0xe94907){const _0x164442=a1060_0x51d9;if(_0x1af336){const _0x351487=util[_0x164442('0x26')](_0x164442('0xb'),path['parse'](_0x5e4ec0['path'])[_0x164442('0x3')],_0x5e4ec0[_0x164442('0x3c')]);gs['execute'](_0x351487)['then'](function(){const _0x4bf5c1=_0x164442;_0x5e4ec0['path']=util[_0x4bf5c1('0x26')](_0x4bf5c1('0x74'),path[_0x4bf5c1('0x42')](_0x5e4ec0['path'])['dir'],path[_0x4bf5c1('0x42')](_0x5e4ec0['path'])[_0x4bf5c1('0x3')]),_0x59a305[_0x4bf5c1('0x49')]=_0x5e4ec0[_0x4bf5c1('0x3c')],ut[_0x4bf5c1('0x4d')]('Convert\x20pdf\x20to\x20tif',''),ami[_0x4bf5c1('0x65')](ut['variablesAction'](_0x5e4ec0,_0x59a305))['then'](function(_0x6ec420){_0x5d6791(_0x6ec420);})[_0x4bf5c1('0x17')](function(_0x541e84){_0xe94907(_0x541e84);});})['catch'](function(_0x3344da){_0xe94907(_0x3344da);});}else ami[_0x164442('0x65')](ut['variablesAction'](_0x5e4ec0,_0x59a305))[_0x164442('0x41')](function(_0x554483){_0x5d6791(_0x554483);})[_0x164442('0x17')](function(_0x1a8b07){_0xe94907(_0x1a8b07);});});}Fax[_0x1d8414('0x16')][_0x1d8414('0x7')]=function(_0x586698,_0x3069db){const _0x574a4c=this;return new Promise(function(_0x168e38,_0x36d9fe){const _0x483cd1=a1060_0x51d9,_0x1b5515=uuid['v4'](),_0x42a01d=ut[_0x483cd1('0x8')](_0x586698,_0x3069db);_0x574a4c[_0x483cd1('0x15')][_0x1b5515]=new Action(_0x1b5515,_0x3069db,_0x586698);const _0x556d3b=_0x574a4c['actions'][_0x1b5515];path[_0x483cd1('0x42')](_0x586698[_0x483cd1('0x3c')])[_0x483cd1('0x48')]===_0x483cd1('0x28')?originate(_0x556d3b,_0x42a01d,!![])[_0x483cd1('0x41')](function(_0x15959f){_0x168e38(_0x15959f);})[_0x483cd1('0x17')](function(_0xfad1ca){_0x36d9fe(_0xfad1ca);}):originate(_0x556d3b,_0x42a01d,![])[_0x483cd1('0x41')](function(_0x5be9b2){_0x168e38(_0x5be9b2);})[_0x483cd1('0x17')](function(_0x10dabd){_0x36d9fe(_0x10dabd);});});},Fax[_0x1d8414('0x16')][_0x1d8414('0x50')]=function(_0x50415e){const _0x364edf=_0x1d8414;return!_[_0x364edf('0x23')](_0x50415e)&&!_['isNil'](_0x50415e[_0x364edf('0x3')])&&!_['isNil'](_0x50415e['active'])&&_0x50415e[_0x364edf('0x5f')]&&!_[_0x364edf('0x23')](this['trunks'][util['format']('SIP/%s',_0x50415e[_0x364edf('0x3')])])&&!_[_0x364edf('0x23')](this[_0x364edf('0xc')][util[_0x364edf('0x26')](_0x364edf('0x5b'),_0x50415e[_0x364edf('0x3')])][_0x364edf('0x73')])&&(this['trunks'][util[_0x364edf('0x26')](_0x364edf('0x5b'),_0x50415e['name'])][_0x364edf('0x73')]===_0x364edf('0x35')||this['trunks'][util[_0x364edf('0x26')]('SIP/%s',_0x50415e['name'])]['status']==='unmonitored');},Fax[_0x1d8414('0x16')][_0x1d8414('0x44')]=function(_0x379ceb,_0x7bd538){const _0x1b7951=_0x1d8414;if(!this[_0x1b7951('0x50')](_0x379ceb))return ut['logger'](_0x1b7951('0x46'),_[_0x1b7951('0x23')](_0x379ceb)?'':_0x379ceb[_0x1b7951('0x3')]+'\x20Trunk\x20is\x20not\x20active'),{'isValid':![],'message':_0x1b7951('0x45')};if(_['isNil'](_0x7bd538[_0x1b7951('0x58')]))return ut[_0x1b7951('0x4d')](_0x1b7951('0x4b'),JSON[_0x1b7951('0x25')](_0x7bd538)),{'isValid':![],'message':_0x1b7951('0x1a')};if(_[_0x1b7951('0x23')](_0x7bd538[_0x1b7951('0x3c')]))return ut['logger'](_0x1b7951('0x21'),JSON[_0x1b7951('0x25')](_0x7bd538)),{'isValid':![],'message':_0x1b7951('0x1e')};return{'isValid':!![],'message':_0x1b7951('0x1c')};},module[_0x1d8414('0x2b')]=Fax;