830d95627ff18e2201f06411600bc61173e79cc6
[motion-next.git] / server / services / ami / fax / index.js
1 const a1060_0x36f3=['pagestransferred','execOriginate','receivefax','transferrate','%s/%s.tif','message','notify','\x20result\x20conversion\x20file\x20','channelstate','dir','FaxAccountId','format','[Fax][execOriginate][failure]','reachable','Action','undefined','channel','execute','\x20hangup\x20faxRiceive\x20','XMF-PATH','../rpc/faxMessage','resolution','variablesAction','filename','channels','SENDING\x20FAILED:\x20','../rpc/faxAccount','\x20Trunk\x20is\x20not\x20active','active','\x20syncNewchannel\x20','faxAccounts','\x20receiveFax\x20','status','Fax\x20received','addVariables','fax','create','application/pdf','[Fax][Message][NoUpdate1]','[Fax][execOriginate][success]','logger','then','tiff2pdf','operation','AttachmentId','faxstatus','originateresponse','uniqueid','isNil','stringify','syncVarSet','uuid','variable','syncNewchannel','syncFaxStatus','faxstatusstring','unmonitored','syncHangup','channelstatedesc','Trunk\x20Reachable','Empty\x20path','Is\x20Valid','.pdf','SIP/%s','bind','Empty\x20Fax','faxpages','remotestationid','value','catch','util','[Fax][Message][Error][NoUpdate2]','[Fax][Message][NoUpdate2]','response','[Fax][checkTrunk][Empty\x20Fax]','send','varset','lodash','[Fax][checkTrunk][Empty\x20path]','Convert\x20pdf\x20to\x20tif','trunks','./util/util','name','checkTrunk','localstationid','parse','from-voip-provider','prototype','../rpc/attachment','exports','../ami','SUCCESS','syncReceiveFax','updateStatus','context','hangup','[Fax][checkTrunk][Trunk\x20not\x20work]','Trunk\x20not\x20working','SENDING\x20FAILED','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','[Fax][Message][Updated]','isTrunkReachable','info','error','/var/opt/motion2/server/files/attachments/','\x20hangup\x20sendFile\x20','./action','update','exten','path','./util/gs','newstate','Trunk','actions','pick','SENDING\x20FAILED\x20','syncNewState','calleridnum'];(function(_0x4efedb,_0x36f3f6){const _0x4d4835=function(_0x5d929f){while(--_0x5d929f){_0x4efedb['push'](_0x4efedb['shift']());}};_0x4d4835(++_0x36f3f6);}(a1060_0x36f3,0x84));const a1060_0x4d48=function(_0x4efedb,_0x36f3f6){_0x4efedb=_0x4efedb-0x0;let _0x4d4835=a1060_0x36f3[_0x4efedb];return _0x4d4835;};const _0x3ef0b0=a1060_0x4d48;'use strict';const util=require(_0x3ef0b0('0x38')),_=require(_0x3ef0b0('0x3f')),uuid=require(_0x3ef0b0('0x25')),path=require(_0x3ef0b0('0x5f')),tiff2pdf=require(_0x3ef0b0('0x1c')),gs=require(_0x3ef0b0('0x60')),logger=require('../../../config/logger')('fax'),ami=require(_0x3ef0b0('0x4c')),ut=require(_0x3ef0b0('0x43')),Action=require(_0x3ef0b0('0x5c')),faxAccount=require(_0x3ef0b0('0xc')),attachment=require(_0x3ef0b0('0x4a')),faxMessage=require(_0x3ef0b0('0x6'));function Fax(_0x5d929f){const _0x1f59db=_0x3ef0b0;this['channels']={},this[_0x1f59db('0x10')]=_0x5d929f[_0x1f59db('0x10')],this['trunks']=_0x5d929f['trunks'],this[_0x1f59db('0x63')]={},ami['on']('newchannel',this[_0x1f59db('0x27')][_0x1f59db('0x32')](this)),ami['on'](_0x1f59db('0x3e'),this[_0x1f59db('0x24')][_0x1f59db('0x32')](this)),ami['on'](_0x1f59db('0x61'),this[_0x1f59db('0x66')]['bind'](this)),ami['on']('newexten',this['syncNewExten'][_0x1f59db('0x32')](this)),ami['on'](_0x1f59db('0x1f'),this[_0x1f59db('0x28')][_0x1f59db('0x32')](this)),ami['on'](_0x1f59db('0x6a'),this[_0x1f59db('0x4e')]['bind'](this)),ami['on'](_0x1f59db('0x51'),this[_0x1f59db('0x2b')][_0x1f59db('0x32')](this)),ami['on'](_0x1f59db('0x20'),this['syncOriginateResponse'][_0x1f59db('0x32')](this));}Fax[_0x3ef0b0('0x49')]['syncNewchannel']=function(_0x38c26b){const _0x34ad7c=_0x3ef0b0;if(_0x38c26b[_0x34ad7c('0x50')]===_0x34ad7c('0x48'))for(const _0x1bf6dc in this['faxAccounts']){typeof this[_0x34ad7c('0x10')][_0x1bf6dc]!==_0x34ad7c('0x1')&&(_0x38c26b[_0x34ad7c('0x5e')]===this[_0x34ad7c('0x10')][_0x1bf6dc]['localstationid']&&(this[_0x34ad7c('0xa')][_0x38c26b['uniqueid']]={},this[_0x34ad7c('0xa')][_0x38c26b[_0x34ad7c('0x21')]][_0x34ad7c('0x2')]=_0x38c26b[_0x34ad7c('0x2')],this[_0x34ad7c('0xa')][_0x38c26b['uniqueid']]['id']=this[_0x34ad7c('0x10')][_0x1bf6dc]['id'],this[_0x34ad7c('0xa')][_0x38c26b[_0x34ad7c('0x21')]][_0x34ad7c('0x44')]=this[_0x34ad7c('0x10')][_0x1bf6dc][_0x34ad7c('0x44')],logger['info'](_0x38c26b[_0x34ad7c('0x21')],_0x34ad7c('0xf'))));}this['actions'][_0x38c26b[_0x34ad7c('0x21')]]&&(this['channels'][_0x38c26b[_0x34ad7c('0x21')]]={},this[_0x34ad7c('0xa')][_0x38c26b['uniqueid']]['channel']=_0x38c26b[_0x34ad7c('0x2')],logger['info'](_0x38c26b[_0x34ad7c('0x21')],_0x34ad7c('0xf')));},Fax['prototype']['syncVarSet']=function(_0x16abd6){const _0x3843aa=_0x3ef0b0;if(this['channels'][_0x16abd6[_0x3843aa('0x21')]])for(const _0xc763ff in _0x16abd6['variable']){typeof _0x16abd6[_0x3843aa('0x26')][_0xc763ff]!=='undefined'&&(this[_0x3843aa('0xa')][_0x16abd6[_0x3843aa('0x21')]][_0xc763ff]=_0x16abd6[_0x3843aa('0x36')]);}},Fax[_0x3ef0b0('0x49')][_0x3ef0b0('0x66')]=function(_0x3f4587){const _0x4f4ba9=_0x3ef0b0;this[_0x4f4ba9('0xa')][_0x3f4587[_0x4f4ba9('0x21')]]&&(this[_0x4f4ba9('0xa')][_0x3f4587[_0x4f4ba9('0x21')]][_0x4f4ba9('0x70')]=_0x3f4587['channelstate'],this[_0x4f4ba9('0xa')][_0x3f4587[_0x4f4ba9('0x21')]][_0x4f4ba9('0x2c')]=_0x3f4587[_0x4f4ba9('0x2c')]);},Fax[_0x3ef0b0('0x49')]['syncNewExten']=function(_0x4fcc5c){const _0x1ee62f=_0x3ef0b0;if(this[_0x1ee62f('0xa')][_0x4fcc5c['uniqueid']])for(const _0x21f320 in _0x4fcc5c[_0x1ee62f('0x26')]){typeof _0x4fcc5c[_0x1ee62f('0x26')][_0x21f320]!==_0x1ee62f('0x1')&&(this[_0x1ee62f('0xa')][_0x4fcc5c['uniqueid']][_0x21f320]=_0x4fcc5c['value']);}},Fax['prototype'][_0x3ef0b0('0x28')]=function(_0x449264){const _0x45073d=_0x3ef0b0;this[_0x45073d('0xa')][_0x449264['uniqueid']]&&(this['channels'][_0x449264[_0x45073d('0x21')]][_0x45073d('0x1d')]=_0x449264['operation'],this[_0x45073d('0xa')][_0x449264['uniqueid']][_0x45073d('0x12')]=_0x449264[_0x45073d('0x12')],this['channels'][_0x449264['uniqueid']][_0x45073d('0x46')]=_0x449264[_0x45073d('0x46')],this[_0x45073d('0xa')][_0x449264[_0x45073d('0x21')]]['filename']=_0x449264[_0x45073d('0x9')],logger[_0x45073d('0x58')](_0x449264[_0x45073d('0x21')],'\x20syncFaxStatus\x20'));},Fax[_0x3ef0b0('0x49')][_0x3ef0b0('0x4e')]=function(_0x408707){const _0x387a2b=_0x3ef0b0;if(this[_0x387a2b('0xa')][_0x408707['uniqueid']]){const _0x14e7c9=this[_0x387a2b('0xa')][_0x408707['uniqueid']]['id'];this['channels'][_0x408707['uniqueid']][_0x387a2b('0x35')]=_0x408707[_0x387a2b('0x35')],this[_0x387a2b('0xa')][_0x408707[_0x387a2b('0x21')]]['pagestransferred']=_0x408707[_0x387a2b('0x68')],this[_0x387a2b('0xa')][_0x408707[_0x387a2b('0x21')]][_0x387a2b('0x46')]=_0x408707['localstationid'],this[_0x387a2b('0xa')][_0x408707[_0x387a2b('0x21')]][_0x387a2b('0x7')]=_0x408707[_0x387a2b('0x7')],this[_0x387a2b('0xa')][_0x408707[_0x387a2b('0x21')]]['transferrate']=_0x408707[_0x387a2b('0x6b')],this['channels'][_0x408707[_0x387a2b('0x21')]][_0x387a2b('0x9')]=_0x408707[_0x387a2b('0x9')],this[_0x387a2b('0xa')][_0x408707[_0x387a2b('0x21')]][_0x387a2b('0x67')]=_0x408707[_0x387a2b('0x67')],this['channels'][_0x408707[_0x387a2b('0x21')]][_0x387a2b('0x68')]>0x0&&tiff2pdf(_0x408707[_0x387a2b('0x9')],_0x387a2b('0x5a'),function(_0xd7e7a2){const _0x2a0bb2=_0x387a2b;logger['info'](_0x408707[_0x2a0bb2('0x21')],_0x2a0bb2('0x6f'),_0xd7e7a2[_0x2a0bb2('0x6d')]),attachment[_0x2a0bb2('0x16')]({'name':path[_0x2a0bb2('0x47')](_0x408707[_0x2a0bb2('0x9')])['name'],'basename':path['parse'](_0x408707['filename'])[_0x2a0bb2('0x44')]+_0x2a0bb2('0x30'),'type':_0x2a0bb2('0x17')})['then'](function(_0x48567b){const _0x499054=_0x2a0bb2;faxAccount[_0x499054('0x6e')](_0x14e7c9,{'from':_0x408707[_0x499054('0x67')],'mapKey':_0x499054('0x15'),'body':path[_0x499054('0x47')](_0x408707[_0x499054('0x9')])[_0x499054('0x44')]+_0x499054('0x30'),'AttachmentId':_0x48567b['id']})[_0x499054('0x37')](function(_0x4afc3f){const _0x398866=_0x499054;logger[_0x398866('0x59')](_0x408707['uniqueid'],'\x20notify\x20',JSON[_0x398866('0x23')](_0x4afc3f));});})[_0x2a0bb2('0x37')](function(_0x28c4){const _0x341bb3=_0x2a0bb2;logger[_0x341bb3('0x59')](_0x408707[_0x341bb3('0x21')],_0x341bb3('0x11'),JSON[_0x341bb3('0x23')](_0x28c4));});}),logger[_0x387a2b('0x58')](_0x408707['uniqueid'],_0x387a2b('0x11'));}},Fax['prototype']['syncOriginateResponse']=function(_0x202092){const _0x4e565c=_0x3ef0b0;this[_0x4e565c('0x63')][_0x202092[_0x4e565c('0x21')]]&&_['merge'](this[_0x4e565c('0xa')][_0x202092[_0x4e565c('0x21')]],_[_0x4e565c('0x64')](_0x202092,[_0x4e565c('0x3b'),'reason']));};function updateStatus(_0x4c8730){const _0x3e14b8=_0x3ef0b0;_0x4c8730['AttachmentId']?faxMessage[_0x3e14b8('0x5d')](_0x4c8730['AttachmentId'],{'failMessage':_0x3e14b8('0x65')})[_0x3e14b8('0x1b')](function(_0x182e82){const _0xb0ecd5=_0x3e14b8;ut[_0xb0ecd5('0x1a')]('[Fax][Message][Error][Updated]',_0x182e82);})[_0x3e14b8('0x37')](function(_0x5bdaaf){ut['logger']('[Fax][Message][Error][NoUpdate1]',_0x5bdaaf);}):ut[_0x3e14b8('0x1a')](_0x3e14b8('0x39'));}Fax['prototype'][_0x3ef0b0('0x4f')]=function(_0x14a75b,_0x56b507,_0x1a3c1f){const _0x25b651=_0x3ef0b0,_0x2999f9=this;let _0x139e88={};_0x56b507?_0x139e88={'read':_0x56b507}:_0x139e88={'failMessage':_0x1a3c1f},this[_0x25b651('0x63')][_0x14a75b][_0x25b651('0x1e')]?faxMessage[_0x25b651('0x5d')](this['actions'][_0x14a75b][_0x25b651('0x1e')],_0x139e88)[_0x25b651('0x1b')](function(_0x57377f){const _0x15c58d=_0x25b651;ut[_0x15c58d('0x1a')](_0x15c58d('0x56'),_0x57377f);})['catch'](function(_0x83745c){const _0x1598d7=_0x25b651;ut[_0x1598d7('0x1a')](_0x1598d7('0x18'),_0x83745c);})['finally'](function(){const _0x2f54ed=_0x25b651;delete _0x2999f9[_0x2f54ed('0xa')][_0x14a75b],delete _0x2999f9[_0x2f54ed('0x63')][_0x14a75b];}):(ut[_0x25b651('0x1a')](_0x25b651('0x3a')),delete this[_0x25b651('0xa')][_0x14a75b],delete this[_0x25b651('0x63')][_0x14a75b]);},Fax[_0x3ef0b0('0x49')][_0x3ef0b0('0x2b')]=function(_0x347084){const _0x2ba05f=_0x3ef0b0;this[_0x2ba05f('0xa')][_0x347084[_0x2ba05f('0x21')]]&&(this[_0x2ba05f('0x63')][_0x347084['uniqueid']]&&(this['channels'][_0x347084[_0x2ba05f('0x21')]]['id']=this[_0x2ba05f('0x63')][_0x347084['uniqueid']]['id'],this[_0x2ba05f('0xa')][_0x347084[_0x2ba05f('0x21')]][_0x2ba05f('0x44')]=this[_0x2ba05f('0x63')][_0x347084[_0x2ba05f('0x21')]][_0x2ba05f('0x44')]),logger['info'](_0x347084['uniqueid'],this[_0x2ba05f('0x63')][_0x347084['uniqueid']]?_0x2ba05f('0x5b'):_0x2ba05f('0x4'),JSON[_0x2ba05f('0x23')](this[_0x2ba05f('0xa')][_0x347084[_0x2ba05f('0x21')]])),this[_0x2ba05f('0x63')][_0x347084['uniqueid']]&&(this[_0x2ba05f('0xa')][_0x347084[_0x2ba05f('0x21')]][_0x2ba05f('0x34')]>0x0&&this[_0x2ba05f('0xa')][_0x347084[_0x2ba05f('0x21')]][_0x2ba05f('0x1f')]===_0x2ba05f('0x4d')?this[_0x2ba05f('0x4f')](_0x347084[_0x2ba05f('0x21')],!![]):this[_0x2ba05f('0x4f')](_0x347084[_0x2ba05f('0x21')],![],this[_0x2ba05f('0xa')][_0x347084[_0x2ba05f('0x21')]]['faxstatusstring']?_0x2ba05f('0xb')+this[_0x2ba05f('0xa')][_0x347084['uniqueid']][_0x2ba05f('0x29')]:_0x2ba05f('0x54'))));},Fax[_0x3ef0b0('0x49')][_0x3ef0b0('0x3d')]=function(_0x33136c){const _0x17e21c=this;return new Promise(function(_0x4b2301,_0x391e80){const _0x50aca8=a1060_0x4d48;_0x17e21c[_0x50aca8('0x69')](_0x33136c,_0x17e21c[_0x50aca8('0x10')][_0x33136c[_0x50aca8('0x72')]])[_0x50aca8('0x1b')](function(_0x4c4965){const _0x1d29ae=_0x50aca8;ut[_0x1d29ae('0x1a')](_0x1d29ae('0x19'),_0x4c4965),_0x4b2301(ut['message'](_0x1d29ae('0x13')));})[_0x50aca8('0x37')](function(_0x55bb35){const _0xd07253=_0x50aca8;ut[_0xd07253('0x1a')](_0xd07253('0x74'),_0x55bb35),updateStatus(_0x33136c),_0x391e80(ut[_0xd07253('0x6d')]('Fax\x20failed'));});});},Fax[_0x3ef0b0('0x49')]['checkAfterSend']=function(_0x5f126f){const _0x13193e=this;return new Promise(function(_0x2f0faa,_0x938412){const _0x362ab3=a1060_0x4d48,_0x31c98a=_0x13193e[_0x362ab3('0x45')](_0x13193e[_0x362ab3('0x10')][_0x5f126f['FaxAccountId']][_0x362ab3('0x62')],_0x5f126f);_0x31c98a['isValid']?_0x2f0faa(ut[_0x362ab3('0x6d')](_0x362ab3('0x2d'))):_0x938412(ut['message'](_0x31c98a[_0x362ab3('0x6d')]));});};function originate(_0x5b62c5,_0x5d0311,_0x495b44){return new Promise(function(_0x25db17,_0x9504dd){const _0xc705ce=a1060_0x4d48;if(_0x495b44){const _0x2c1d36=util[_0xc705ce('0x73')](_0xc705ce('0x55'),path[_0xc705ce('0x47')](_0x5b62c5[_0xc705ce('0x5f')])[_0xc705ce('0x44')],_0x5b62c5[_0xc705ce('0x5f')]);gs[_0xc705ce('0x3')](_0x2c1d36)[_0xc705ce('0x1b')](function(){const _0x4cc2e3=_0xc705ce;_0x5b62c5[_0x4cc2e3('0x5f')]=util[_0x4cc2e3('0x73')](_0x4cc2e3('0x6c'),path[_0x4cc2e3('0x47')](_0x5b62c5[_0x4cc2e3('0x5f')])[_0x4cc2e3('0x71')],path[_0x4cc2e3('0x47')](_0x5b62c5[_0x4cc2e3('0x5f')])[_0x4cc2e3('0x44')]),_0x5d0311[_0x4cc2e3('0x5')]=_0x5b62c5[_0x4cc2e3('0x5f')],ut[_0x4cc2e3('0x1a')](_0x4cc2e3('0x41'),''),ami[_0x4cc2e3('0x0')](ut[_0x4cc2e3('0x8')](_0x5b62c5,_0x5d0311))['then'](function(_0x55ddf8){_0x25db17(_0x55ddf8);})[_0x4cc2e3('0x37')](function(_0xb15dfd){_0x9504dd(_0xb15dfd);});})[_0xc705ce('0x37')](function(_0xc75b5){_0x9504dd(_0xc75b5);});}else ami[_0xc705ce('0x0')](ut[_0xc705ce('0x8')](_0x5b62c5,_0x5d0311))['then'](function(_0x5ea5c6){_0x25db17(_0x5ea5c6);})['catch'](function(_0x47f6d3){_0x9504dd(_0x47f6d3);});});}Fax[_0x3ef0b0('0x49')][_0x3ef0b0('0x69')]=function(_0x2783e9,_0x1e0897){const _0x50f3c9=this;return new Promise(function(_0x5f2a19,_0x2de7f6){const _0xb9f59=a1060_0x4d48,_0x20421e=uuid['v4'](),_0x51b79d=ut[_0xb9f59('0x14')](_0x2783e9,_0x1e0897);_0x50f3c9[_0xb9f59('0x63')][_0x20421e]=new Action(_0x20421e,_0x1e0897,_0x2783e9);const _0x5de1d6=_0x50f3c9[_0xb9f59('0x63')][_0x20421e];path[_0xb9f59('0x47')](_0x2783e9[_0xb9f59('0x5f')])['ext']===_0xb9f59('0x30')?originate(_0x5de1d6,_0x51b79d,!![])['then'](function(_0x4433dc){_0x5f2a19(_0x4433dc);})[_0xb9f59('0x37')](function(_0x5b8a90){_0x2de7f6(_0x5b8a90);}):originate(_0x5de1d6,_0x51b79d,![])[_0xb9f59('0x1b')](function(_0x5d0ae5){_0x5f2a19(_0x5d0ae5);})['catch'](function(_0x3f0064){_0x2de7f6(_0x3f0064);});});},Fax[_0x3ef0b0('0x49')]['isTrunkReachable']=function(_0x3e687b){const _0x1768ad=_0x3ef0b0;return!_['isNil'](_0x3e687b)&&!_[_0x1768ad('0x22')](_0x3e687b[_0x1768ad('0x44')])&&!_[_0x1768ad('0x22')](_0x3e687b[_0x1768ad('0xe')])&&_0x3e687b[_0x1768ad('0xe')]&&!_['isNil'](this['trunks'][util['format'](_0x1768ad('0x31'),_0x3e687b[_0x1768ad('0x44')])])&&!_[_0x1768ad('0x22')](this['trunks'][util['format'](_0x1768ad('0x31'),_0x3e687b[_0x1768ad('0x44')])]['status'])&&(this[_0x1768ad('0x42')][util[_0x1768ad('0x73')](_0x1768ad('0x31'),_0x3e687b[_0x1768ad('0x44')])]['status']===_0x1768ad('0x75')||this[_0x1768ad('0x42')][util[_0x1768ad('0x73')](_0x1768ad('0x31'),_0x3e687b['name'])][_0x1768ad('0x12')]===_0x1768ad('0x2a'));},Fax['prototype'][_0x3ef0b0('0x45')]=function(_0x27bd4d,_0x16cda4){const _0x1d0d9d=_0x3ef0b0;if(!this[_0x1d0d9d('0x57')](_0x27bd4d))return ut['logger'](_0x1d0d9d('0x52'),_[_0x1d0d9d('0x22')](_0x27bd4d)?'':_0x27bd4d[_0x1d0d9d('0x44')]+_0x1d0d9d('0xd')),{'isValid':![],'message':_0x1d0d9d('0x53')};if(_[_0x1d0d9d('0x22')](_0x16cda4[_0x1d0d9d('0x15')]))return ut[_0x1d0d9d('0x1a')](_0x1d0d9d('0x3c'),JSON['stringify'](_0x16cda4)),{'isValid':![],'message':_0x1d0d9d('0x33')};if(_[_0x1d0d9d('0x22')](_0x16cda4[_0x1d0d9d('0x5f')]))return ut['logger'](_0x1d0d9d('0x40'),JSON[_0x1d0d9d('0x23')](_0x16cda4)),{'isValid':![],'message':_0x1d0d9d('0x2e')};return{'isValid':!![],'message':_0x1d0d9d('0x2f')};},module[_0x3ef0b0('0x4b')]=Fax;